:root {
  --bg: #f4f6f7;
  --panel: #ffffff;
  --text: #172124;
  --muted: #68777e;
  --line: #dce4e8;
  --brand: #0f766e;
  --brand-dark: #0b5f59;
  --brand-soft: #e6f4f1;
  --warn: #c2410c;
  --warn-soft: #fff7ed;
  --danger: #b91c1c;
  --danger-soft: #fee2e2;
  --blue: #1d4ed8;
  --blue-soft: #dbeafe;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", sans-serif;
  font-size: 14px;
  line-height: 1.45;
}

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

button {
  cursor: pointer;
}

.app-shell {
  display: grid;
  min-height: 100vh;
  grid-template-columns: 232px minmax(0, 1fr);
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  border-right: 1px solid var(--line);
  background: #0c2f2c;
  color: #ffffff;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  height: 84px;
  padding: 0 18px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
}

.brand-mark {
  display: flex;
  width: 40px;
  height: 40px;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  background: #ffffff;
  color: var(--brand);
  font-weight: 800;
}

.brand-name {
  font-size: 18px;
  font-weight: 800;
}

.brand-subtitle {
  margin-top: 2px;
  color: rgba(255, 255, 255, 0.68);
  font-size: 12px;
}

.nav-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 14px;
}

.nav-item {
  display: flex;
  height: 42px;
  align-items: center;
  padding: 0 14px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: rgba(255, 255, 255, 0.78);
  text-align: left;
}

.nav-item.active,
.nav-item:hover {
  background: rgba(255, 255, 255, 0.12);
  color: #ffffff;
}

.main {
  min-width: 0;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 3;
  display: flex;
  min-height: 84px;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 18px 28px;
  border-bottom: 1px solid var(--line);
  background: rgba(244, 246, 247, 0.96);
  backdrop-filter: blur(8px);
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: 24px;
  font-weight: 800;
}

h2 {
  font-size: 18px;
  font-weight: 800;
}

h3 {
  font-size: 15px;
  font-weight: 800;
}

.topbar p {
  margin-top: 4px;
  color: var(--muted);
}

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

.sync-status {
  display: inline-flex;
  min-height: 28px;
  align-items: center;
  justify-content: center;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.sync-status.online {
  border-color: #b7e4d7;
  background: var(--brand-soft);
  color: var(--brand);
}

.sync-status.pending {
  border-color: #bfdbfe;
  background: var(--blue-soft);
  color: var(--blue);
}

.sync-status.offline {
  border-color: #fed7aa;
  background: var(--warn-soft);
  color: var(--warn);
}

.content {
  padding: 24px 28px 42px;
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.toolbar-left,
.toolbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

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

.metric {
  min-height: 108px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.metric-value {
  margin-top: 12px;
  color: var(--brand);
  font-size: 30px;
  font-weight: 850;
}

.metric-label {
  color: var(--muted);
  font-size: 13px;
}

.split-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(360px, 0.8fr);
  gap: 16px;
}

.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.panel-head {
  display: flex;
  min-height: 56px;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}

.panel-body {
  padding: 16px;
}

.table-wrap {
  overflow: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  background: var(--panel);
}

th,
td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
  white-space: nowrap;
}

th {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

tr:last-child td {
  border-bottom: 0;
}

tr.clickable {
  cursor: pointer;
}

tr.clickable:hover {
  background: #f7fafb;
}

.empty {
  padding: 34px 18px;
  color: var(--muted);
  text-align: center;
}

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

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field.full {
  grid-column: 1 / -1;
}

label {
  color: #26363c;
  font-size: 12px;
  font-weight: 800;
}

input,
select,
textarea {
  width: 100%;
  min-height: 38px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  color: var(--text);
  outline: none;
}

textarea {
  min-height: 84px;
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.12);
}

.primary-btn,
.ghost-btn,
.warn-btn,
.danger-btn,
.text-btn,
.icon-btn {
  display: inline-flex;
  min-height: 38px;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 14px;
  border-radius: 8px;
  font-weight: 800;
}

.primary-btn {
  border: 1px solid var(--brand);
  background: var(--brand);
  color: #ffffff;
}

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

.ghost-btn {
  border: 1px solid var(--line);
  background: #ffffff;
  color: var(--text);
}

.warn-btn {
  border: 1px solid #fed7aa;
  background: var(--warn-soft);
  color: var(--warn);
}

.danger-btn {
  border: 1px solid #fecaca;
  background: var(--danger-soft);
  color: var(--danger);
}

.text-btn {
  min-height: 30px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--brand);
}

.icon-btn {
  width: 34px;
  min-height: 34px;
  padding: 0;
  border: 1px solid var(--line);
  background: #ffffff;
}

.badge {
  display: inline-flex;
  min-height: 24px;
  align-items: center;
  justify-content: center;
  padding: 0 8px;
  border-radius: 8px;
  background: var(--brand-soft);
  color: var(--brand);
  font-size: 12px;
  font-weight: 800;
}

.badge.gray {
  background: #eef2f4;
  color: #475569;
}

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

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

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

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

.detail-item {
  min-height: 62px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfd;
}

.detail-label {
  color: var(--muted);
  font-size: 12px;
}

.detail-value {
  margin-top: 6px;
  font-weight: 800;
  word-break: break-word;
}

.timeline {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

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

.timeline-meta {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-size: 12px;
}

.timeline-title {
  margin-top: 8px;
  font-weight: 800;
}

.muted {
  color: var(--muted);
}

.amount {
  color: var(--warn);
  font-weight: 850;
}

.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 20;
  display: none;
  max-width: 360px;
  padding: 12px 14px;
  border-radius: 8px;
  background: #172124;
  color: #ffffff;
  box-shadow: 0 12px 30px rgba(15, 35, 40, 0.22);
}

.toast.show {
  display: block;
}

.modal {
  width: min(720px, calc(100vw - 48px));
  padding: 0;
  border: 0;
  border-radius: 8px;
}

.modal::backdrop {
  background: rgba(15, 23, 42, 0.48);
}

.modal-panel {
  margin: 0;
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
}

.modal-body {
  max-height: min(70vh, 720px);
  overflow: auto;
  padding: 18px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 14px 18px;
  border-top: 1px solid var(--line);
  background: #f7fafb;
}

.course-block {
  margin-bottom: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.course-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px;
  border-bottom: 1px solid var(--line);
}

.course-body {
  padding: 14px;
}

.record-row {
  display: grid;
  grid-template-columns: 120px minmax(0, 1fr) 96px 90px;
  gap: 12px;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}

.record-row:last-child {
  border-bottom: 0;
}

.search-input {
  width: 280px;
}

[hidden] { display: none !important; }
.booking-count { display: inline-flex; width: 26px; height: 26px; flex: 0 0 26px; align-items: center; justify-content: center; border-radius: 50%; background: #dc2626; color: #fff; font-size: 11px; font-weight: 700; line-height: 1; }
.nav-item[data-view="appointments"] { display: flex; align-items: center; justify-content: space-between; }
.message-center { position: relative; flex-shrink: 0; }
.message-bell { position: relative; display: flex; align-items: center; justify-content: center; width: 44px; height: 44px; padding: 10px; background: #fff; border: 1px solid var(--line); border-radius: 6px; overflow: visible; }
.message-bell img { width: 24px; height: 24px; }
.message-unread { position: absolute; top: -7px; right: -7px; display: flex; align-items: center; justify-content: center; min-width: 21px; height: 21px; padding: 0 5px; border-radius: 50%; background: #dc2626; color: #fff; font-size: 11px; font-weight: 700; white-space: nowrap; }
.message-panel { position: absolute; top: 52px; right: 0; z-index: 60; width: min(420px, calc(100vw - 32px)); max-height: 75vh; overflow: auto; background: #fff; border: 1px solid #d7dee2; border-radius: 8px; box-shadow: 0 12px 36px #17212426; }
.message-panel-head { position: sticky; top: 0; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 16px; background: #fff; border-bottom: 1px solid #e3e9ec; z-index: 1; }
.message-panel-head h2 { margin: 0; font-size: 16px; }
.message-panel-head img { width: 20px; height: 20px; }
.message-row { display: flex; flex-direction: column; gap: 7px; width: 100%; padding: 16px; border: 0; border-bottom: 1px solid #e3e9ec; border-radius: 0; background: #fff; color: #172124; text-align: left; white-space: normal; overflow-wrap: anywhere; }
.message-row:hover { background: #f5f7f8; }
.message-row.unread { background: #eff8f5; }
.message-title { font-size: 14px; font-weight: 700; }
.message-copy { font-size: 13px; line-height: 1.6; }
.message-date { color: #6b7b83; font-size: 11px; }
.message-empty { padding: 24px 16px; margin: 0; color: #6b7b83; text-align: center; font-size: 13px; }
.message-error:not(:empty) { padding: 12px 16px; color: #991b1b; font-size: 13px; }
.message-retry, .message-more { display: block; width: 100%; padding: 12px 16px; }
.booking-tabs { display: flex; flex-wrap: wrap; gap: 4px; }
.booking-tab { display: inline-flex; align-items: center; gap: 8px; min-height: 42px; padding: 8px 14px; border: 0; border-bottom: 3px solid transparent; background: transparent; color: var(--muted); border-radius: 0; }
.booking-tab.active { border-bottom-color: var(--brand); color: var(--brand); font-weight: 700; }
.booking-filter { display: flex; align-items: center; gap: 12px; margin: 14px 0 20px; }
.booking-filter select { width: min(360px, 65%); }
.booking-table th { white-space: nowrap; }
.booking-table td { max-width: 300px; vertical-align: top; overflow-wrap: break-word; }
.booking-time-line { margin-bottom: 8px; font-size: 13px; white-space: nowrap; }
.booking-id { margin-top: 8px; color: var(--muted); font-size: 11px; word-break: break-all; }
.booking-row-actions { display: flex; gap: 14px; white-space: nowrap; }
.booking-danger, .booking-error { color: #b91c1c; }
.booking-error { font-size: 13px; overflow-wrap: break-word; }
.booking-block-section { margin-top: 32px; padding-top: 24px; border-top: 1px solid var(--line); }
.booking-rule-list { display: grid; gap: 8px; }
.booking-rule { display: flex; justify-content: space-between; align-items: center; gap: 20px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.booking-calendar-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.booking-calendar-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 6px; }
.booking-weekday { text-align: center; padding: 8px 0; color: var(--muted); font-size: 12px; }
.booking-day { height: 42px; border: 1px solid transparent; border-radius: 4px; background: #eef2f4; color: #9ca3af; }
.booking-day.patient-day { background: #dbeafe; color: #1d4ed8; font-weight: 700; }
.booking-day.selected { border-color: var(--brand); background: #e6f4f1; color: var(--brand); }
.booking-day:disabled { cursor: not-allowed; opacity: 0.6; }
.booking-date-title { font-size: 16px; margin: 20px 0 12px; }
.booking-patient-slots, .booking-range-tabs { display: flex; flex-wrap: wrap; gap: 10px; margin: 12px 0; }
.booking-patient-slots span { color: #1d4ed8; font-size: 13px; }
.booking-range-tabs .selected { border-color: var(--brand); background: var(--brand-soft); }
.booking-wheels { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; margin: 16px 0; }
.booking-wheels label { display: flex; flex-direction: column; gap: 8px; min-width: 0; font-size: 13px; color: var(--muted); }
.booking-wheels select { height: 170px; padding: 0; font-size: 16px; text-align: center; overflow-y: auto; }
.booking-wheels option { padding: 8px; color: var(--text); }
.booking-wheels option:disabled { color: #b5bdc5; background: #f1f3f5; }
.booking-note { margin-top: 18px; }
.booking-week-checks { display: flex; flex-wrap: wrap; gap: 12px; }
.booking-week-checks label, .booking-checkbox { display: flex; align-items: center; gap: 6px; }
.booking-week-checks input, .booking-checkbox input { width: 16px; min-height: 16px; padding: 0; }
button:disabled { cursor: not-allowed; opacity: 0.55; }

@media (max-width: 1180px) {
  .metric-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .split-layout {
    grid-template-columns: 1fr;
  }
}
.field input[type="checkbox"] { width: 18px; height: 18px; min-height: 18px; margin-top: 10px; }
.medical-editor, .medical-summary { width: 100%; margin: 12px 0 0; }
.medical-editor-item { padding: 16px 0; border-bottom: 1px solid var(--line); }
.medical-editor-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.medical-editor-heading h4 { margin: 0; font-size: 14px; }
.medical-binary, .medical-options { display: flex; flex-wrap: wrap; gap: 16px; }
.medical-binary label, .medical-options label { display: flex; align-items: center; gap: 6px; font-size: 14px; }
.medical-binary input, .medical-options input { width: 16px; height: 16px; min-height: 16px; margin: 0; padding: 0; }
.medical-editor-details { margin-top: 14px; }
.medical-fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; margin-top: 12px; }
.medical-fields textarea { min-height: 76px; width: 100%; }
.medical-legacy { margin-top: 12px; color: var(--muted); white-space: pre-wrap; overflow-wrap: anywhere; font-size: 13px; }
.medical-summary-row { display: grid; grid-template-columns: 140px minmax(0, 1fr); gap: 16px; padding: 12px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.medical-summary dt { font-weight: 600; }
.medical-summary dd { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.medical-summary dd div { margin-top: 6px; }
.medical-summary dd span { color: var(--muted); }
.medical-positive { color: #b91c1c; }
.redemption-section { background: #fff; padding: 0 20px 24px; border-bottom: 1px solid var(--line); }
.redemption-heading { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 18px 0; }
.redemption-heading h2 { font-size: 18px; }
.redemption-heading .muted { display: block; margin-top: 4px; font-size: 12px; }
.redemption-form { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; max-width: 820px; }
.redemption-own-family { justify-content: center; }
.redemption-list { margin-top: 20px; }
.redemption-switch { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; font-size: 13px; font-weight: 600; flex-shrink: 0; }
.redemption-switch input { position: absolute; width: 1px; height: 1px; min-height: 1px; opacity: 0; padding: 0; }
.switch-track { width: 36px; height: 20px; flex-shrink: 0; border-radius: 10px; background: #a7b3b9; padding: 2px; }
.switch-track::after { content: ""; display: block; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: transform 0.15s; }
.redemption-switch input:checked + .switch-track { background: var(--brand); }
.redemption-switch input:checked + .switch-track::after { transform: translateX(16px); }
.redemption-switch input:focus-visible + .switch-track { outline: 2px solid var(--blue); outline-offset: 3px; }
.redemption-recognized { display: flex; flex-direction: column; gap: 8px; padding: 14px 0; border-top: 1px solid var(--line); overflow-wrap: anywhere; }
.redemption-table .coupon-benefits { white-space: normal; min-width: 180px; max-width: 340px; overflow-wrap: anywhere; }
.redemption-table .coupon-selected { background: var(--brand-soft); }
.benefit-count { display: flex; flex-direction: column; align-items: flex-start; color: var(--text); text-align: left; }
.benefit-count:hover { border-color: var(--brand); background: var(--brand-soft); }
.benefit-record-family { padding-bottom: 12px; border-bottom: 1px solid var(--line); color: var(--muted); }
.benefit-history-row { padding: 16px 0; border-bottom: 1px solid var(--line); overflow-wrap: anywhere; }
.benefit-history-row > div + div { margin-top: 8px; }
.benefit-history-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
@media (max-width: 900px) { .redemption-form { grid-template-columns: minmax(0, 1fr); } .redemption-heading { flex-wrap: wrap; } }
.medical-editor [hidden], .medical-fields [hidden] { display: none; }
@media (max-width: 600px) { .medical-fields { grid-template-columns: minmax(0, 1fr); } .medical-summary-row { grid-template-columns: 110px minmax(0, 1fr); } }
