:root {
  color-scheme: light;
  --bg: #f4f7f6;
  --surface: #ffffff;
  --surface-soft: #edf4f2;
  --line: #dce5e2;
  --text: #172522;
  --muted: #65736f;
  --primary: #16786f;
  --primary-dark: #0f5e57;
  --primary-pale: #def0ec;
  --amber: #b96f11;
  --amber-pale: #fff0d9;
  --red: #b84b45;
  --red-pale: #fbe7e5;
  --blue: #386f9e;
  --blue-pale: #e5f0f8;
  --shadow: 0 10px 30px rgba(26, 50, 45, 0.08);
  --radius: 8px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  letter-spacing: 0;
}

button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
a { color: inherit; text-decoration: none; }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2px solid #e0b85a;
  outline-offset: 2px;
}

.app-shell { min-height: 100vh; }

.sidebar {
  display: none;
  position: fixed;
  inset: 0 auto 0 0;
  width: 224px;
  padding: 28px 18px;
  background: #143e3a;
  color: #fff;
  z-index: 20;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 8px 30px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  flex: 0 0 42px;
  border-radius: 8px;
  background: #fff;
  color: var(--primary-dark);
  font-weight: 800;
}

.brand strong, .brand small { display: block; }
.brand strong { font-size: 17px; }
.brand small { margin-top: 3px; color: #b7d1cc; font-size: 11px; }

.desktop-nav { display: grid; gap: 6px; }

.nav-item {
  border: 0;
  background: transparent;
  color: inherit;
}

.desktop-nav .nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 46px;
  padding: 0 14px;
  border-radius: 7px;
  color: #c6d9d5;
  text-align: left;
}

.desktop-nav .nav-item.is-active {
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
}

.nav-icon {
  display: inline-grid;
  place-items: center;
  width: 24px;
  height: 24px;
  font-size: 20px;
  line-height: 1;
}

.privacy-note {
  position: absolute;
  bottom: 28px;
  left: 26px;
  display: flex;
  align-items: center;
  gap: 8px;
  color: #a8c4bf;
  font-size: 12px;
}

.privacy-note span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #79cfb4;
  box-shadow: 0 0 0 4px rgba(121, 207, 180, 0.12);
}

.main-content {
  min-height: 100vh;
  padding: max(20px, env(safe-area-inset-top)) 16px calc(90px + var(--safe-bottom));
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  max-width: 1160px;
  margin: 0 auto 22px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 12px;
}

h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: 24px; line-height: 1.25; }
h2 { font-size: 18px; }
h3 { font-size: 15px; }

.primary-button, .secondary-button, .ghost-button, .danger-button, .icon-button {
  min-height: 42px;
  border: 1px solid transparent;
  border-radius: 7px;
  padding: 0 15px;
  font-weight: 650;
}

.primary-button {
  background: var(--primary);
  color: #fff;
  box-shadow: 0 6px 16px rgba(22, 120, 111, 0.18);
}

.primary-button:hover { background: var(--primary-dark); }
.primary-button span { margin-right: 5px; font-size: 18px; }

.secondary-button {
  background: var(--surface-soft);
  border-color: var(--line);
  color: var(--primary-dark);
}

.ghost-button { background: transparent; color: var(--primary); }
.danger-button { background: var(--red-pale); color: var(--red); }
.icon-button { width: 42px; padding: 0; background: var(--surface-soft); color: var(--text); }
.secondary-button, a.secondary-button { display: inline-flex; align-items: center; justify-content: center; }

.view { max-width: 1160px; margin: 0 auto; }

.hero-strip {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 16px;
  padding: 20px;
  border-left: 4px solid var(--primary);
  background: var(--surface);
  box-shadow: 0 2px 12px rgba(22, 44, 40, 0.05);
}

.hero-strip h2 { margin-bottom: 5px; }
.hero-strip p { margin-bottom: 0; color: var(--muted); font-size: 13px; line-height: 1.6; }
.hero-strip .primary-button { flex: 0 0 auto; align-self: center; }

.metric-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 24px;
}

.metric-card {
  position: relative;
  min-height: 112px;
  padding: 15px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  text-align: left;
  transition: transform 150ms ease, box-shadow 150ms ease;
}

.metric-card:hover { transform: translateY(-1px); box-shadow: var(--shadow); }
.metric-card::after {
  content: "›";
  position: absolute;
  right: 14px;
  bottom: 11px;
  color: #9aaaa6;
  font-size: 22px;
}

.metric-label { display: block; color: var(--muted); font-size: 13px; }
.metric-value { display: block; margin-top: 10px; font-size: 29px; font-weight: 760; line-height: 1; }
.metric-card.is-urgent { border-top: 3px solid var(--red); }
.metric-card.is-today { border-top: 3px solid var(--primary); }
.metric-card.is-active { border-top: 3px solid var(--blue); }
.metric-card.is-paused { border-top: 3px solid var(--amber); }

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

.section-head h2 { margin: 0; }
.section-head p { margin: 3px 0 0; color: var(--muted); font-size: 12px; }
.text-button { border: 0; background: none; color: var(--primary); font-weight: 650; }

.task-list, .patient-list, .timeline, .course-list { display: grid; gap: 9px; }

.task-row, .patient-row, .course-card {
  display: grid;
  align-items: center;
  gap: 12px;
  min-width: 0;
  padding: 15px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.task-row { grid-template-columns: auto minmax(0, 1fr) auto; }
.patient-row { grid-template-columns: 44px minmax(0, 1fr) auto; }

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--primary);
  box-shadow: 0 0 0 5px var(--primary-pale);
}

.status-dot.overdue { background: var(--red); box-shadow: 0 0 0 5px var(--red-pale); }
.status-dot.upcoming { background: var(--amber); box-shadow: 0 0 0 5px var(--amber-pale); }

.row-main { min-width: 0; }
.row-main strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }
.row-main p { margin: 5px 0 0; overflow: hidden; color: var(--muted); font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }

.row-actions { display: flex; align-items: center; gap: 6px; }
.row-actions button, .small-button {
  min-height: 34px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--primary-dark);
  font-size: 12px;
  font-weight: 650;
}

.row-chevron { color: #93a29e; font-size: 21px; }

.avatar {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--surface-soft);
  color: var(--primary-dark);
  font-weight: 760;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  background: var(--surface-soft);
  color: var(--primary-dark);
  font-size: 11px;
  white-space: nowrap;
}

.badge.red { background: var(--red-pale); color: var(--red); }
.badge.amber { background: var(--amber-pale); color: var(--amber); }
.badge.blue { background: var(--blue-pale); color: var(--blue); }

.toolbar {
  display: flex;
  gap: 9px;
  margin-bottom: 15px;
}

.search-wrap { position: relative; flex: 1; }
.search-wrap::before {
  content: "⌕";
  position: absolute;
  top: 50%;
  left: 13px;
  transform: translateY(-50%);
  color: var(--muted);
  font-size: 19px;
}

.search-input, .filter-select {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface);
  color: var(--text);
  outline: 0;
}

.search-input { padding: 0 14px 0 40px; }
.filter-select { width: auto; min-width: 120px; padding: 0 34px 0 12px; }
.search-input:focus, .filter-select:focus, input:focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(22, 120, 111, 0.1); }

.empty-state {
  padding: 42px 20px;
  border: 1px dashed #cbd8d5;
  background: rgba(255, 255, 255, 0.6);
  text-align: center;
}

.empty-symbol {
  display: grid;
  place-items: center;
  width: 52px;
  height: 52px;
  margin: 0 auto 12px;
  border-radius: 50%;
  background: var(--surface-soft);
  color: var(--primary);
  font-size: 25px;
}

.empty-state h3 { margin-bottom: 6px; }
.empty-state p { max-width: 340px; margin: 0 auto 16px; color: var(--muted); font-size: 13px; line-height: 1.6; }

.data-grid { display: grid; gap: 12px; }
.settings-panel {
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.settings-panel h2 { margin-bottom: 6px; }
.settings-panel > p { color: var(--muted); font-size: 13px; line-height: 1.6; }
.settings-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }
.data-summary { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 16px; }
.data-summary div { padding: 14px; background: var(--surface-soft); }
.data-summary strong, .data-summary small { display: block; }
.data-summary strong { font-size: 21px; }
.data-summary small { margin-top: 4px; color: var(--muted); }
.warning-box { margin-top: 14px; padding: 12px; background: var(--amber-pale); color: #775016; font-size: 12px; line-height: 1.6; }

.mobile-nav {
  position: fixed;
  inset: auto 0 0;
  z-index: 30;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  height: calc(64px + var(--safe-bottom));
  padding: 5px 10px var(--safe-bottom);
  border-top: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(14px);
}

.mobile-nav .nav-item {
  display: grid;
  justify-items: center;
  align-content: center;
  gap: 2px;
  color: #72807d;
}

.mobile-nav .nav-item.is-active { color: var(--primary); }
.mobile-nav .nav-icon { font-size: 22px; }
.mobile-nav small { font-size: 10px; }

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0;
  background: rgba(16, 31, 28, 0.46);
  backdrop-filter: blur(2px);
}

.modal {
  width: 100%;
  max-height: 92vh;
  overflow: auto;
  border-radius: 12px 12px 0 0;
  background: var(--surface);
  box-shadow: 0 -12px 40px rgba(16, 31, 28, 0.18);
}

.modal.medium { max-width: 720px; }
.modal.large { max-width: 900px; }
.modal-header {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 18px 13px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(10px);
}

.modal-header h2 { margin: 0; }
.close-button {
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 50%;
  background: var(--surface-soft);
  color: var(--text);
  font-size: 21px;
}

.modal-body { padding: 18px; }
.modal-footer {
  position: sticky;
  bottom: 0;
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 13px 18px calc(13px + var(--safe-bottom));
  border-top: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.97);
}

.form-section { margin-bottom: 22px; }
.form-section:last-child { margin-bottom: 0; }
.form-section h3 { margin-bottom: 12px; color: #334743; }
.form-grid { display: grid; grid-template-columns: 1fr; gap: 13px; }
.form-grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.field { display: grid; gap: 6px; min-width: 0; }
.field.full { grid-column: 1 / -1; }
.field label { color: #52635f; font-size: 12px; font-weight: 650; }
.required { color: var(--red); }
.field input, .field select, .field textarea {
  width: 100%;
  min-height: 43px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 9px 11px;
  background: #fff;
  color: var(--text);
  outline: 0;
}
.field textarea { min-height: 82px; resize: vertical; }
.field-hint { color: var(--muted); font-size: 11px; }

.patient-hero {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--line);
}
.patient-identity { display: flex; align-items: center; gap: 13px; }
.patient-identity .avatar { width: 54px; height: 54px; font-size: 18px; }
.patient-identity h2 { margin: 0 0 5px; }
.patient-identity p { margin: 0; color: var(--muted); font-size: 12px; }
.detail-actions { display: flex; gap: 7px; }
.info-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 22px; }
.info-item { min-width: 0; padding: 11px; background: var(--surface-soft); }
.info-item small, .info-item strong { display: block; }
.info-item small { margin-bottom: 5px; color: var(--muted); font-size: 11px; }
.info-item strong { overflow-wrap: anywhere; font-size: 13px; }

.detail-section { margin-top: 24px; }
.course-card { grid-template-columns: minmax(0, 1fr) auto; }
.course-card h3 { margin: 0 0 5px; }
.course-card p { margin: 0; color: var(--muted); font-size: 12px; line-height: 1.5; }
.course-meta { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 9px; }

.timeline-item {
  position: relative;
  display: grid;
  grid-template-columns: 78px minmax(0, 1fr);
  gap: 13px;
  padding: 0 0 18px 16px;
  border-left: 2px solid var(--line);
}
.timeline-item::before {
  content: "";
  position: absolute;
  top: 2px;
  left: -6px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--primary);
}
.timeline-date { color: var(--muted); font-size: 11px; }
.timeline-content strong { display: block; margin-bottom: 4px; font-size: 13px; }
.timeline-content p { margin: 0; color: var(--muted); font-size: 12px; line-height: 1.55; }

.segmented {
  display: flex;
  gap: 3px;
  margin-bottom: 15px;
  padding: 3px;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #eaf0ee;
}
.segmented button {
  flex: 1;
  min-width: max-content;
  min-height: 35px;
  border: 0;
  border-radius: 5px;
  padding: 0 11px;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
}
.segmented button.is-active { background: #fff; color: var(--text); font-weight: 650; box-shadow: 0 1px 4px rgba(20, 50, 44, 0.08); }

.welcome {
  max-width: 520px;
  padding: 28px;
  text-align: center;
}
.welcome-mark {
  display: grid;
  place-items: center;
  width: 64px;
  height: 64px;
  margin: 0 auto 17px;
  border-radius: 14px;
  background: var(--primary);
  color: #fff;
  font-size: 25px;
  font-weight: 800;
}
.welcome h2 { font-size: 23px; }
.welcome p { color: var(--muted); font-size: 13px; line-height: 1.7; }
.welcome-actions { display: grid; gap: 8px; margin-top: 20px; }
.welcome-actions button { width: 100%; }
.welcome small { display: block; margin-top: 12px; color: #84918e; line-height: 1.5; }

.toast-region {
  position: fixed;
  z-index: 200;
  top: max(16px, env(safe-area-inset-top));
  right: 16px;
  left: 16px;
  display: grid;
  justify-items: center;
  pointer-events: none;
}
.toast {
  max-width: 430px;
  padding: 11px 15px;
  border-radius: 7px;
  background: #173e39;
  color: #fff;
  box-shadow: var(--shadow);
  font-size: 13px;
  animation: toast-in 180ms ease-out;
}
.toast.error { background: #7e312d; }
@keyframes toast-in { from { transform: translateY(-8px); opacity: 0; } }

.hide-mobile { display: none; }

@media (min-width: 700px) {
  .main-content { padding: 30px 28px 90px; }
  .metric-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .data-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .modal-backdrop { align-items: center; padding: 24px; }
  .modal { border-radius: 10px; }
  .form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .form-grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .info-grid { grid-template-columns: repeat(4, 1fr); }
  .hide-mobile { display: initial; }
}

@media (min-width: 980px) {
  .sidebar { display: block; }
  .main-content { margin-left: 224px; padding: 36px 38px 54px; }
  .mobile-nav { display: none; }
  .metric-grid { grid-template-columns: repeat(5, minmax(0, 1fr)); }
  .metric-card { min-height: 122px; padding: 18px; }
  .modal-footer { padding-bottom: 13px; }
}

@media (max-width: 500px) {
  .topbar .primary-button { width: 44px; padding: 0; font-size: 0; }
  .topbar .primary-button span { margin: 0; font-size: 23px; }
  .hero-strip { display: block; }
  .hero-strip .primary-button { width: 100%; margin-top: 15px; }
  .task-row { grid-template-columns: auto minmax(0, 1fr); }
  .task-row .row-actions { grid-column: 2; }
  .toolbar { flex-wrap: wrap; }
  .filter-select { width: 100%; }
  .form-grid.two { grid-template-columns: 1fr; }
  .patient-hero { display: block; }
  .detail-actions { margin-top: 14px; }
  .course-card { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
