:root {
  color-scheme: light;
  --bg: #f6f8f7;
  --surface: #ffffff;
  --surface-2: #eef3f1;
  --ink: #17201c;
  --muted: #65736f;
  --line: #dbe4e1;
  --primary: #176c63;
  --primary-dark: #0f514b;
  --accent: #a85f2a;
  --danger: #b73838;
  --warning: #d18a00;
  --shadow: 0 16px 38px rgba(23, 32, 28, 0.10);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--ink);
  font-family: "Microsoft JhengHei", "Noto Sans TC", system-ui, -apple-system, sans-serif;
  letter-spacing: 0;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.hidden {
  display: none !important;
}

.app {
  display: grid;
  grid-template-columns: 260px 1fr;
  min-height: 100vh;
  min-height: 100dvh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 24px 18px;
  background: #102621;
  color: #f4fbf8;
  display: flex;
  flex-direction: column;
  gap: 28px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: #d7eee8;
  color: #102621;
  font-weight: 800;
}

.brand strong,
.brand small {
  display: block;
}

.brand small,
.sidebar-footer small {
  color: #b8cbc6;
}

.nav {
  display: grid;
  gap: 8px;
}

.nav-item,
.ghost-button,
.primary-button,
.danger-button,
.icon-button {
  border: 0;
  border-radius: 8px;
  min-height: 42px;
}

.nav-item {
  width: 100%;
  text-align: left;
  padding: 10px 12px;
  background: transparent;
  color: #d8e6e2;
}

.nav-item.active,
.nav-item:hover {
  background: #1d3d36;
  color: #ffffff;
}

.sidebar-footer {
  margin-top: auto;
  display: grid;
  gap: 10px;
}

.main {
  min-width: 0;
  padding: 28px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 22px;
}

.topbar h1,
.lock-panel h1,
.panel h2,
.dialog-head h2 {
  margin: 0;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--primary);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.top-actions {
  display: flex;
  gap: 10px;
  align-items: center;
}

.top-actions input {
  width: min(40vw, 420px);
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 10px 12px;
  min-height: 42px;
}

textarea {
  resize: vertical;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
}

.primary-button {
  padding: 0 16px;
  background: var(--primary);
  color: #fff;
  font-weight: 800;
}

.primary-button:hover {
  background: var(--primary-dark);
}

.ghost-button {
  padding: 0 14px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  font-weight: 700;
}

.sidebar .ghost-button {
  background: transparent;
  color: #f4fbf8;
  border-color: #34554e;
}

.danger-button {
  padding: 0 14px;
  background: #ffe9e9;
  color: var(--danger);
  font-weight: 800;
}

.icon-button {
  width: 40px;
  background: var(--surface-2);
  color: var(--ink);
  font-size: 24px;
  line-height: 1;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 16px;
}

.metrics article,
.panel,
.case-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.metrics article {
  padding: 18px;
}

.metrics span {
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
}

.metrics strong {
  display: block;
  margin-top: 8px;
  font-size: 32px;
}

.dashboard-grid,
.split {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(360px, 0.7fr);
  gap: 16px;
}

.split.wide-left {
  grid-template-columns: minmax(560px, 1fr) minmax(360px, 0.62fr);
}

.panel {
  padding: 18px;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.panel h2 {
  font-size: 18px;
}

.case-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 14px;
}

.case-card {
  padding: 18px;
  text-align: left;
}

.case-card header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.case-card h3 {
  margin: 0 0 4px;
  font-size: 20px;
}

.case-card p {
  margin: 8px 0 0;
  color: var(--muted);
  line-height: 1.5;
}

.badge-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 12px;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.badge.high,
.badge.urgent {
  background: #ffeaea;
  color: var(--danger);
}

.badge.medium {
  background: #fff5dc;
  color: #8a5b00;
}

.form-panel {
  display: grid;
  gap: 12px;
  align-content: start;
}

.form-section {
  display: grid;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdfc;
}

.form-section h3 {
  margin: 0;
  color: var(--ink);
  font-size: 16px;
}

.fare-box {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.fare-box div {
  padding: 12px;
  border: 1px solid #b9ddd5;
  border-radius: 8px;
  background: #f0faf7;
}

.fare-box span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.fare-box strong {
  display: block;
  margin-top: 4px;
  font-size: 18px;
}

.inline-note {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.section-head,
.repeat-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.form-row,
.vitals-grid {
  display: grid;
  gap: 12px;
}

.form-row {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

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

.adl-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.adl-column {
  display: grid;
  gap: 12px;
  align-content: start;
}

.score-badge,
.pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 30px;
  padding: 4px 10px;
  border-radius: 999px;
  background: #d7eee8;
  color: var(--primary-dark);
  font-size: 13px;
}

.repeat-list {
  display: grid;
  gap: 12px;
}

.repeat-card {
  display: grid;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.photo-input input {
  padding: 8px;
  min-height: 48px;
}

.photo-preview {
  width: 100%;
  max-height: 260px;
  object-fit: contain;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
}

.small-button {
  min-height: 32px;
  padding: 0 10px;
}

.sticky-submit {
  position: sticky;
  bottom: 12px;
  z-index: 2;
  box-shadow: var(--shadow);
}

.stack-list,
.timeline,
.task-list {
  display: grid;
  gap: 10px;
}

.list-item,
.timeline-item,
.task-item {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdfc;
}

.route-summary {
  display: grid;
  gap: 6px;
  padding: 12px;
  border: 1px solid #b9ddd5;
  border-radius: 8px;
  background: #f0faf7;
}

.route-summary span,
.route-summary small {
  color: var(--muted);
  line-height: 1.5;
}

.route-stop {
  display: grid;
  grid-template-columns: 72px minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdfc;
}

.route-time {
  display: grid;
  justify-items: center;
  gap: 4px;
}

.route-time strong {
  margin: 0;
  font-size: 20px;
}

.route-time span {
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--primary);
  color: #ffffff;
  font-weight: 800;
}

.map-link {
  width: fit-content;
  min-height: 34px;
  display: inline-flex;
  align-items: center;
  padding: 0 12px;
  border-radius: 8px;
  background: var(--primary);
  color: #ffffff;
  font-weight: 800;
  text-decoration: none;
}

.detail-block {
  display: grid;
  gap: 3px;
  margin-top: 8px;
  padding: 8px;
  border-radius: 8px;
  background: var(--surface-2);
}

.detail-block strong {
  margin: 0;
  font-size: 13px;
}

.detail-block span {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.photo-strip {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 10px;
  margin-top: 10px;
}

.photo-strip figure {
  margin: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: #ffffff;
}

.photo-strip img,
.photo-missing {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  display: grid;
  place-items: center;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 13px;
}

.photo-strip figcaption {
  padding: 8px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.list-item strong,
.timeline-item strong,
.task-item strong {
  display: block;
  margin-bottom: 4px;
}

.meta {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.task-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: start;
}

.task-actions {
  display: flex;
  gap: 8px;
}

.task-actions button {
  min-height: 34px;
  padding: 0 10px;
}

.empty-state {
  color: var(--muted);
  min-height: 80px;
  place-items: center;
}

dialog {
  width: min(1040px, calc(100vw - 28px));
  border: 0;
  border-radius: 8px;
  padding: 0;
  box-shadow: var(--shadow);
}

dialog::backdrop {
  background: rgba(16, 38, 33, 0.55);
}

.case-form {
  max-height: min(88vh, 980px);
  overflow: auto;
  padding: 20px;
  display: grid;
  gap: 12px;
}

.dialog-head,
.dialog-actions {
  display: grid;
  gap: 12px;
  align-items: center;
}

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

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

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  max-width: min(420px, calc(100vw - 44px));
  padding: 12px 14px;
  border-radius: 8px;
  background: #102621;
  color: #fff;
  box-shadow: var(--shadow);
  font-weight: 700;
}

.lock {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 20px;
  background: #102621;
}

.lock-panel {
  width: min(420px, 100%);
  display: grid;
  gap: 14px;
  padding: 28px;
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
}

.form-error {
  color: var(--danger);
  min-height: 20px;
  margin: 0;
}

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

  .sidebar {
    position: static;
    height: auto;
  }

  .nav,
  .sidebar-footer {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .dashboard-grid,
  .split {
    grid-template-columns: 1fr;
  }

  .split.wide-left {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 760px) {
  body {
    font-size: 16px;
  }

  .main {
    padding: 14px;
    padding-bottom: calc(18px + env(safe-area-inset-bottom));
  }

  .sidebar {
    padding: 14px;
    gap: 14px;
  }

  .brand {
    align-items: center;
  }

  .brand-mark {
    width: 38px;
    height: 38px;
  }

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

  .nav-item {
    min-height: 48px;
    text-align: center;
    padding: 10px 8px;
  }

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

  .topbar,
  .top-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .top-actions input {
    width: 100%;
  }

  .metrics,
  .form-row,
  .vitals-grid,
  .adl-grid,
  .fare-box,
  .sidebar-footer {
    grid-template-columns: 1fr;
  }

  .metrics {
    gap: 10px;
  }

  .metrics article {
    padding: 14px;
  }

  .metrics strong {
    font-size: 28px;
  }

  .panel,
  .case-card,
  .form-section {
    padding: 14px;
  }

  input,
  select,
  textarea,
  .primary-button,
  .ghost-button,
  .danger-button {
    min-height: 48px;
  }

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

  .route-stop {
    grid-template-columns: 1fr;
  }

  dialog {
    width: 100vw;
    max-width: 100vw;
    height: 100dvh;
    max-height: 100dvh;
    border-radius: 0;
  }

  .case-form {
    max-height: 100dvh;
    padding: 14px;
    padding-bottom: calc(20px + env(safe-area-inset-bottom));
  }

  .sticky-submit {
    bottom: calc(8px + env(safe-area-inset-bottom));
  }

  .lock-panel {
    padding: 22px;
  }
}
