:root {
  color-scheme: light;
  --bg: #f4f6f3;
  --panel: #ffffff;
  --panel-soft: #eef4f1;
  --text: #18201c;
  --muted: #66706a;
  --border: #d7ded8;
  --green: #116a4c;
  --green-dark: #0d4e3a;
  --green-soft: #dceee6;
  --red: #b42318;
  --red-soft: #f8dedb;
  --amber: #9a6700;
  --amber-soft: #f4e7c5;
  --blue: #2457a6;
  --blue-soft: #dde9fb;
  --shadow: 0 10px 28px rgba(24, 32, 28, 0.08);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--text);
}

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
}

.app-shell {
  width: min(1180px, 100%);
  margin: 0 auto;
  padding: 18px;
}

.topbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 0 18px;
}

.top-actions {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 8px;
}

.operator-pill {
  border: 1px solid #abd4c2;
  border-radius: 999px;
  background: var(--green-soft);
  color: var(--green-dark);
  padding: 8px 12px;
  font-size: 0.85rem;
  font-weight: 800;
  white-space: nowrap;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--green);
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(1.65rem, 5vw, 2.35rem);
  line-height: 1.05;
  letter-spacing: 0;
}

.source-line {
  max-width: 760px;
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 700;
  line-height: 1.35;
}

h2 {
  margin-bottom: 0;
  font-size: 1.05rem;
  line-height: 1.2;
  letter-spacing: 0;
}

.sync-pill {
  flex: 0 0 auto;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--panel);
  color: var(--muted);
  padding: 8px 12px;
  font-size: 0.85rem;
  font-weight: 700;
  white-space: nowrap;
}

.compact-button {
  min-height: 38px;
  padding: 0 11px;
  font-size: 0.82rem;
}

.access-panel {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(280px, 420px);
  gap: 18px;
  align-items: start;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  padding: 18px;
}

.access-panel[hidden] {
  display: none;
}

.access-panel h2 {
  font-size: 1.35rem;
}

.access-copy {
  max-width: 520px;
  margin: 10px 0 0;
  color: var(--muted);
  font-weight: 700;
  line-height: 1.4;
}

.access-form {
  display: grid;
  gap: 12px;
}

.form-message {
  min-height: 20px;
  margin: -2px 0 0;
  color: var(--red);
  font-size: 0.88rem;
  font-weight: 800;
}

.sync-pill.is-online {
  border-color: #abd4c2;
  background: var(--green-soft);
  color: var(--green-dark);
}

.sync-pill.has-pending {
  border-color: #e2c36a;
  background: var(--amber-soft);
  color: var(--amber);
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.metric {
  text-align: left;
  min-height: 82px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
  padding: 12px;
  box-shadow: var(--shadow);
}

.metric-button {
  width: 100%;
}

.metric-button:hover,
.metric-button.is-active {
  border-color: #8bc5ad;
  box-shadow: 0 0 0 3px rgba(17, 106, 76, 0.12), var(--shadow);
}

.metric-value {
  display: block;
  font-size: 2rem;
  font-weight: 850;
  line-height: 1;
  letter-spacing: 0;
}

.metric-label {
  display: block;
  margin-top: 8px;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 700;
}

.metric-danger .metric-value {
  color: var(--red);
}

.metric-warn .metric-value {
  color: var(--amber);
}

.metric-ok .metric-value {
  color: var(--green);
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 14px;
  align-items: start;
}

.task-panel,
.activity-panel {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.task-panel {
  min-width: 0;
}

.toolbar {
  display: grid;
  gap: 12px;
  padding: 14px;
  border-bottom: 1px solid var(--border);
}

.device-filter-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border: 1px solid #abd4c2;
  border-radius: 8px;
  background: var(--green-soft);
  color: var(--green-dark);
  padding: 10px 12px;
}

.device-filter-banner[hidden] {
  display: none;
}

.device-filter-banner > div {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.device-filter-label {
  font-size: 0.75rem;
  font-weight: 850;
  text-transform: uppercase;
}

.device-filter-banner strong {
  overflow-wrap: anywhere;
  font-size: 1rem;
  line-height: 1.25;
}

.search-wrap label,
.field span {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 750;
}

.search-wrap input,
.field input,
.field textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  padding: 12px;
  outline: none;
}

.search-wrap input:focus,
.field input:focus,
.field textarea:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(17, 106, 76, 0.14);
}

.field input[readonly] {
  background: var(--panel-soft);
  color: var(--muted);
}

.pin-input {
  min-height: 56px;
  text-align: center;
  font-size: 1.45rem;
  font-weight: 850;
}

.segment {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel-soft);
}

.segment-button {
  min-height: 42px;
  border: 0;
  border-right: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  padding: 0 8px;
  font-size: 0.9rem;
  font-weight: 800;
}

.segment-button:last-child {
  border-right: 0;
}

.segment-button.is-active {
  background: var(--green);
  color: #fff;
}

.task-list {
  display: grid;
  gap: 10px;
  padding: 14px;
}

.device-group {
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
}

.device-toggle {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 10px;
  align-items: center;
  width: 100%;
  border: 0;
  background: #fff;
  color: var(--text);
  padding: 14px;
  text-align: left;
}

.device-toggle:hover {
  background: #f9faf9;
}

.device-title {
  display: grid;
  gap: 3px;
  min-width: 0;
}

.device-title strong {
  font-size: 1.05rem;
  line-height: 1.25;
}

.device-title small {
  color: var(--muted);
  font-weight: 800;
}

.device-status {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 7px;
}

.device-action {
  border-radius: 999px;
  background: var(--panel-soft);
  color: var(--green-dark);
  padding: 7px 10px;
  font-size: 0.8rem;
  font-weight: 850;
  white-space: nowrap;
}

.device-task-list {
  display: grid;
  gap: 10px;
  border-top: 1px solid var(--border);
  background: #f8faf8;
  padding: 10px;
}

.device-task-list[hidden] {
  display: none;
}

.task-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  padding: 14px;
}

.task-card.is-done-today {
  border-color: #9ccdb8;
  background: #f4fbf8;
}

.task-main {
  min-width: 0;
}

.task-equipment {
  margin: 0 0 4px;
  font-size: 1.05rem;
  font-weight: 850;
  line-height: 1.25;
}

.task-name {
  margin: 0 0 10px;
  color: var(--muted);
  line-height: 1.35;
}

.task-note {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.35;
}

.meta-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.tag {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  border-radius: 999px;
  padding: 4px 9px;
  background: var(--panel-soft);
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.tag-danger {
  background: var(--red-soft);
  color: var(--red);
}

.tag-warn {
  background: var(--amber-soft);
  color: var(--amber);
}

.tag-ok {
  background: var(--green-soft);
  color: var(--green-dark);
}

.tag-blue {
  background: var(--blue-soft);
  color: var(--blue);
}

.primary-button,
.ghost-button,
.task-action {
  min-height: 44px;
  border-radius: 8px;
  padding: 0 14px;
  font-weight: 850;
}

.primary-button,
.task-action {
  border: 1px solid var(--green);
  background: var(--green);
  color: #fff;
}

.primary-button:hover,
.task-action:hover {
  background: var(--green-dark);
}

.ghost-button {
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
}

.ghost-button:hover {
  border-color: #b8c3bb;
  background: #f9faf9;
}

.activity-panel {
  padding: 14px;
}

.activity-dialog {
  width: min(560px, calc(100vw - 24px));
  max-height: min(760px, calc(100vh - 24px));
  border: 0;
  border-radius: 8px;
  padding: 0;
  background: transparent;
}

.activity-dialog::backdrop {
  background: rgba(24, 32, 28, 0.48);
}

.activity-modal-panel {
  max-height: min(760px, calc(100vh - 24px));
  overflow: auto;
}

.activity-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.activity-header .ghost-button {
  min-height: 38px;
  padding: 0 10px;
  font-size: 0.82rem;
}

.retry-wide {
  width: 100%;
  margin-bottom: 12px;
}

.activity-list {
  display: grid;
  gap: 10px;
}

.activity-item {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  background: #fff;
}

.activity-item p {
  margin: 0 0 5px;
  line-height: 1.3;
}

.activity-item small {
  color: var(--muted);
  font-weight: 700;
}

.activity-note {
  border-left: 3px solid var(--green);
  background: var(--panel-soft);
  border-radius: 6px;
  margin: 8px 0;
  padding: 8px 10px;
  color: var(--text);
  font-size: 0.9rem;
  font-weight: 700;
  line-height: 1.35;
}

.activity-status {
  margin-top: 8px;
}

.empty-state {
  border: 1px dashed #b8c3bb;
  border-radius: 8px;
  padding: 20px 14px;
  color: var(--muted);
  text-align: center;
  line-height: 1.4;
}

.complete-dialog {
  width: min(520px, calc(100vw - 24px));
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0;
  box-shadow: 0 20px 80px rgba(24, 32, 28, 0.24);
}

.complete-dialog::backdrop {
  background: rgba(24, 32, 28, 0.48);
}

.complete-dialog form {
  display: grid;
  gap: 14px;
  padding: 18px;
}

.dialog-header h2 {
  font-size: 1.3rem;
}

.selected-task {
  border-left: 4px solid var(--green);
  background: var(--panel-soft);
  border-radius: 8px;
  padding: 10px 12px;
  line-height: 1.35;
}

.check-row {
  display: grid;
  grid-template-columns: 20px minmax(0, 1fr);
  gap: 10px;
  align-items: start;
  color: var(--text);
  font-weight: 700;
  line-height: 1.35;
}

.check-row input {
  width: 18px;
  height: 18px;
  margin-top: 2px;
  accent-color: var(--green);
}

.dialog-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 18px;
  z-index: 20;
  max-width: min(520px, calc(100vw - 24px));
  transform: translateX(-50%) translateY(120px);
  border-radius: 8px;
  background: #18201c;
  color: #fff;
  padding: 12px 14px;
  font-weight: 750;
  opacity: 0;
  transition: transform 180ms ease, opacity 180ms ease;
}

.toast.is-visible {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

@media (max-width: 880px) {
  .app-shell {
    padding: 14px;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .top-actions {
    justify-content: flex-start;
  }

  .access-panel {
    grid-template-columns: 1fr;
  }

  .workspace {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 620px) {
  .summary-grid {
    grid-template-columns: 1fr;
  }

  .metric {
    min-height: 66px;
  }

  .metric-value {
    font-size: 1.55rem;
  }

  .segment {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .device-filter-banner {
    align-items: stretch;
    flex-direction: column;
  }

  .device-filter-banner .ghost-button {
    width: 100%;
  }

  .segment-button:nth-child(2) {
    border-right: 0;
  }

  .segment-button:nth-child(-n + 2) {
    border-bottom: 1px solid var(--border);
  }

  .task-card {
    grid-template-columns: 1fr;
  }

  .device-toggle {
    grid-template-columns: 1fr;
  }

  .device-status {
    justify-content: flex-start;
  }

  .device-action {
    width: fit-content;
  }

  .task-action {
    width: 100%;
  }

  .dialog-actions {
    grid-template-columns: 1fr;
  }
}
