:root {
  --pine: #23473b;
  --pine-deep: #173329;
  --pine-mid: #416f60;
  --pine-soft: #e5efeb;
  --amber: #c7430b;
  --amber-deep: #9e3207;
  --amber-soft: #fceade;
  --paper: #faf8f2;
  --paper-deep: #eeeae0;
  --ink: #17221e;
  --muted: #5c6964;
  --line: #cbd2cc;
  --line-strong: #798d84;
  --danger: #a52a22;
  --radius: 10px;
  --shadow: 0 16px 42px rgba(16, 42, 33, .15);
}

*, *::before, *::after { box-sizing: border-box; }
html { min-width: 320px; background: var(--paper-deep); }
body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: var(--paper-deep);
  font: 16px/1.55 "Noto Sans SC", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  font-variant-numeric: tabular-nums;
}
button, input, select, textarea { color: inherit; font: inherit; }
button, select { cursor: pointer; }
button:disabled, input:disabled, select:disabled, textarea:disabled { cursor: not-allowed; opacity: .62; }
h1, h2, h3, p { margin-top: 0; }
h1, h2, h3 { line-height: 1.18; }
h1 { margin-bottom: 8px; font-size: clamp(1.6rem, 3vw, 2.45rem); }
h2 { margin-bottom: 8px; font-size: clamp(1.45rem, 2.5vw, 2rem); }
h3 { margin-bottom: 8px; }
a { color: var(--pine); }
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid var(--amber); outline-offset: 3px; }

.skip-link {
  position: fixed;
  z-index: 100;
  top: 8px;
  left: 8px;
  padding: 10px 14px;
  color: #fff;
  background: var(--amber);
  transform: translateY(-160%);
}
.skip-link:focus { transform: none; }
.sr-only {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}
.eyebrow {
  margin-bottom: 7px;
  color: var(--pine-mid);
  font-size: .72rem;
  font-weight: 800;
  letter-spacing: .16em;
}
.on-dark .eyebrow, .login-brand .eyebrow { color: #c8d9d2; }
.muted { color: var(--muted); }
.wayfind {
  display: block;
  width: 48px;
  height: 6px;
  margin-bottom: 13px;
  border-radius: 2px;
  background: var(--pine);
}
.wayfind-light { background: var(--paper); }
.section-rule { height: 1px; margin: 24px 0; background: var(--line); }

.button {
  display: inline-flex;
  min-height: 44px;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 9px 17px;
  border: 0;
  border-radius: var(--radius);
  font-weight: 800;
  transition: background-color .15s ease, border-color .15s ease, transform .15s ease;
}
.button:active { transform: translateY(1px); }
.button.primary { color: #fff; background: var(--amber); }
.button.primary:hover { background: var(--amber-deep); }
.button.dark { color: #fff; background: var(--pine); }
.button.dark:hover { background: var(--pine-deep); }
.button.secondary { color: var(--pine); border: 2px solid var(--pine); background: transparent; }
.button.secondary:hover { background: var(--pine-soft); }
.button.tertiary { color: var(--pine); border: 1px solid var(--line-strong); background: transparent; }
.button.tertiary:hover { background: var(--paper-deep); }
.button.quiet-dark { color: #fff; border: 1px solid rgba(255,255,255,.44); background: transparent; }
.button.quiet-dark:hover { background: rgba(255,255,255,.12); }
.button.danger { color: var(--danger); border: 1px solid #d6a49f; background: #fff; }
.button.danger:hover { background: #fff2f0; }
.button.small { min-height: 36px; padding: 6px 11px; font-size: .875rem; }
.button.full { width: 100%; margin-top: 5px; }
.icon { width: 18px; height: 18px; flex: 0 0 18px; }

.login-page {
  display: grid;
  min-height: 100vh;
  grid-template-columns: minmax(280px, .9fr) minmax(390px, 1.1fr);
}
.login-brand {
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: clamp(34px, 7vw, 104px);
  color: #fff;
  background: var(--pine);
}
.login-brand p:last-child { max-width: 520px; color: #d8e3df; }
.login-panel {
  width: min(520px, calc(100% - 48px));
  align-self: center;
  justify-self: center;
  padding: clamp(28px, 5vw, 54px);
  border-top: 6px solid var(--pine);
  background: var(--paper);
  box-shadow: var(--shadow);
}
label { display: block; margin: 15px 0 6px; font-size: .875rem; font-weight: 800; }
input, select, textarea {
  width: 100%;
  min-height: 48px;
  padding: 11px 13px;
  border: 1.5px solid var(--line-strong);
  border-radius: 8px;
  background: var(--paper-deep);
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--pine); background: #fff; outline: 3px solid var(--pine-soft); }
.form-error {
  margin: 12px 0 4px;
  padding: 10px 12px;
  color: var(--amber-deep);
  border-left: 5px solid var(--amber);
  background: var(--amber-soft);
  font-weight: 700;
}
.staging-access { margin-top: 24px; }
.staging-buttons { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.staging-buttons .button { min-width: 0; padding-inline: 8px; }
.security-note {
  display: grid;
  gap: 3px;
  margin-top: 24px;
  padding: 15px;
  color: var(--pine-deep);
  background: var(--pine-soft);
}

.topbar {
  position: sticky;
  z-index: 20;
  top: 0;
  display: flex;
  min-height: 88px;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 17px clamp(20px, 4vw, 54px);
  color: #fff;
  background: var(--pine-deep);
}
.topbar h1 { margin-bottom: 0; font-size: 1.45rem; }
.account-box { display: flex; align-items: center; gap: 18px; text-align: right; }
.account-box span, .account-box small { display: block; }
.account-box span { font-weight: 800; }
.account-box small { color: #c8d9d2; }
.topbar-company { margin: 3px 0 0; color: #c8d9d2; font-size: .78rem; }
.account-box .role-pill { width: max-content; margin: 4px 0 0 auto; padding: 3px 9px; color: var(--pine-deep); border-radius: 999px; background: var(--paper); font-size: .72rem; font-weight: 800; }
.scope-banner {
  display: flex;
  min-height: 45px;
  align-items: center;
  gap: 10px;
  padding: 10px clamp(20px, 4vw, 54px);
  color: var(--amber-deep);
  background: var(--amber-soft);
  font-size: .9rem;
  font-weight: 700;
}
.scope-icon { color: var(--amber); }
.workspace { display: grid; min-height: calc(100vh - 133px); grid-template-columns: 230px 1fr; }
.sidebar { padding: 24px 16px; background: var(--pine); }
.sidebar nav { position: sticky; top: 112px; display: grid; gap: 7px; }
.nav-item {
  display: flex;
  width: 100%;
  min-height: 46px;
  align-items: center;
  gap: 10px;
  padding: 10px 13px;
  color: #d9e5e0;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  font-weight: 700;
  text-align: left;
}
.nav-item:hover { color: #fff; background: rgba(255,255,255,.1); }
.nav-item[aria-current="page"] { color: var(--pine); border-color: var(--paper); background: var(--paper); }
.mobile-tabs { display: none; }
main { min-width: 0; padding: clamp(24px, 4vw, 54px); background: var(--paper); }
.view { max-width: 1320px; margin: 0 auto; }
.heading-row { display: flex; align-items: end; justify-content: space-between; gap: 20px; margin-bottom: 28px; }
.heading-row .muted { max-width: 720px; margin-bottom: 0; }

.filter-bar {
  display: grid;
  grid-template-columns: minmax(170px, 1.1fr) minmax(160px, .8fr) auto;
  align-items: end;
  gap: 14px;
  padding: 0;
  border: 0;
  background: transparent;
}
.filter-bar label { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
.filter-actions { display: flex; gap: 8px; }
.summary-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin: 30px 0 20px;
  border-block: 1px solid var(--line);
}
.summary-item { min-width: 0; padding: 19px 18px; border-right: 1px solid var(--line); }
.summary-item:last-child { border-right: 0; }
.summary-item strong { display: block; overflow: hidden; font-size: clamp(1.45rem, 3vw, 2.2rem); line-height: 1.1; text-overflow: ellipsis; }
.summary-item span { color: var(--muted); font-size: .84rem; font-weight: 700; }
.summary-scope { margin: -8px 0 20px; color: var(--muted); font-size: .84rem; }
.content-state {
  margin: 18px 0;
  padding: 20px;
  color: var(--muted);
  border: 1px dashed var(--line-strong);
  background: var(--paper-deep);
  text-align: center;
}
.content-state:empty { display: none; }
.content-state.error { color: var(--amber-deep); border-color: var(--amber); background: var(--amber-soft); }
.table-wrap { overflow: auto; border-top: 5px solid var(--pine); }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { padding: 14px 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
th { color: var(--pine-deep); background: var(--paper-deep); white-space: nowrap; }
#orders-table-wrap th:nth-child(2),
#orders-table-wrap td:nth-child(2) { min-width: 104px; }
#orders-table-wrap th:nth-child(8),
#orders-table-wrap td:nth-child(8) { min-width: 124px; }
#orders-table-wrap td:nth-child(1) { font-size: .82rem; white-space: nowrap; }
#orders-table-wrap td:nth-child(8) .button { white-space: nowrap; }
tbody tr:hover { background: #f2f4ed; }
.stack-list { display: none; }
.mobile-order { padding: 16px 0; border-bottom: 1px solid var(--line); }
.mobile-order-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.mobile-order dl { display: grid; grid-template-columns: 82px 1fr; gap: 6px; margin: 12px 0; }
.mobile-order dt { color: var(--muted); }
.mobile-order dd { margin: 0; font-weight: 700; }
.status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  color: #fff;
  border-radius: 4px;
  background: var(--pine-mid);
  font-size: .78rem;
  font-weight: 800;
  white-space: nowrap;
}
.status-icon { width: 14px; height: 14px; flex-basis: 14px; }
.status.pending { background: var(--amber); }
.status.complete { background: #65736d; }
.status.disabled { background: #777; }
.patient-cell { min-width: 132px; }
.patient-cell span { display: block; }
.patient-cell small { color: var(--muted); }

.ruled-list { border-top: 5px solid var(--pine); }
.service-list { overflow: hidden; border: 1px solid var(--line); border-radius: 14px; }
.service-row { display: flex; min-height: 74px; align-items: center; justify-content: space-between; gap: 22px; padding: 15px 17px; border-bottom: 1px solid var(--line); }
.service-row:last-child { border-bottom: 0; }
.service-row.is-disabled { opacity: .58; }
.service-copy { min-width: 0; flex: 1; }
.service-copy h3 { margin-bottom: 4px; font-size: 1.02rem; }
.service-copy p { margin-bottom: 0; }
.service-price { margin-left: 5px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.service-switch { position: relative; width: 48px; height: 28px; flex: 0 0 48px; padding: 0; border: 0; border-radius: 999px; background: var(--line); transition: background-color .15s ease; }
.service-switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(16,42,33,.22); transition: transform .15s ease; }
.service-switch[aria-checked="true"] { background: var(--pine); }
.service-switch[aria-checked="true"]::after { transform: translateX(20px); }
.managed-row {
  display: grid;
  grid-template-columns: minmax(170px, 1.2fr) minmax(150px, 1fr) minmax(120px, .7fr) auto;
  align-items: center;
  gap: 18px;
  padding: 18px 8px;
  border-bottom: 1px solid var(--line);
}
.managed-row h3 { margin-bottom: 4px; font-size: 1.02rem; }
.row-actions { display: flex; justify-content: flex-end; gap: 7px; }
.qr-grid { display: grid; grid-template-columns: repeat(3, minmax(220px, 1fr)); gap: 0; border-top: 5px solid var(--pine); }
.qr-item { min-width: 0; padding: 22px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.qr-item:nth-child(3n) { border-right: 0; }
.qr-placeholder {
  display: grid;
  width: 120px;
  height: 120px;
  place-items: center;
  margin: 17px 0;
  color: var(--pine);
  border: 8px double var(--pine);
  background: repeating-linear-gradient(45deg, var(--paper), var(--paper) 5px, var(--pine-soft) 5px, var(--pine-soft) 10px);
  font-weight: 900;
  letter-spacing: .15em;
}
.qr-image { display: block; width: 140px; height: 140px; margin: 17px 0; object-fit: contain; background: #fff; }
.scene-code { display: block; max-width: 100%; overflow: hidden; color: var(--muted); text-overflow: ellipsis; white-space: nowrap; }

dialog {
  width: min(680px, calc(100% - 30px));
  max-height: min(88vh, 900px);
  padding: 0;
  color: var(--ink);
  border: 0;
  border-radius: 12px;
  background: var(--paper);
  box-shadow: var(--shadow);
}
dialog::backdrop { background: rgba(10, 26, 21, .63); }
.dialog-head { display: flex; align-items: start; justify-content: space-between; gap: 18px; padding: 22px 24px; color: #fff; background: var(--pine); }
.dialog-head h2 { margin-bottom: 0; }
.dialog-head .eyebrow { margin-bottom: 5px; }
.dialog-head .wayfind { margin-bottom: 8px; }
.icon-button { width: 42px; height: 42px; color: #fff; border: 1px solid rgba(255,255,255,.5); border-radius: 8px; background: transparent; font-size: 1.6rem; line-height: 1; }
.dialog-body, .dialog-form, .annotation-form { padding: 22px 24px; }
.dialog-form, .annotation-form { border-top: 1px solid var(--line); }
.detail-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0; margin: 0; border-top: 1px solid var(--line); }
.detail-grid > div { min-width: 0; padding: 13px 10px; border-bottom: 1px solid var(--line); }
.detail-grid dt { color: var(--muted); font-size: .78rem; font-weight: 700; }
.detail-grid dd { margin: 4px 0 0; overflow-wrap: anywhere; font-weight: 700; }
.annotation-list { margin-top: 22px; }
.annotation-item { padding: 12px 0; border-bottom: 1px solid var(--line); }
.annotation-item p { white-space: pre-wrap; overflow-wrap: anywhere; }
.annotation-item small { color: var(--muted); }
.review-panel { margin-top: 22px; padding: 18px; border-radius: 10px; background: var(--pine-soft); }
.review-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.review-heading h3 { margin-bottom: 0; }
.review-heading time { color: var(--muted); font-size: .78rem; white-space: nowrap; }
.review-rating { display: flex; align-items: center; gap: 12px; margin-top: 12px; color: var(--pine-deep); }
.review-stars { display: inline-flex; gap: 3px; }
.review-star { width: 21px; height: 21px; fill: transparent; stroke: var(--line-strong); stroke-width: 1.5; }
.review-star.is-active { fill: var(--amber); stroke: var(--amber); }
.review-tags { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 12px; }
.review-tags span { padding: 4px 9px; color: var(--pine-deep); border: 1px solid var(--pine-mid); border-radius: 999px; background: var(--paper); font-size: .78rem; font-weight: 700; }
.review-comment { margin: 13px 0 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.review-empty p { margin-bottom: 0; }

.toast {
  position: fixed;
  z-index: 80;
  right: 22px;
  bottom: 22px;
  max-width: min(420px, calc(100% - 44px));
  padding: 13px 18px;
  color: #fff;
  border-radius: 8px;
  background: var(--pine-deep);
  box-shadow: var(--shadow);
  font-weight: 700;
}
.toast.error { background: var(--amber-deep); }

@media (max-width: 1040px) {
  .workspace { grid-template-columns: 190px 1fr; }
  .filter-bar { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .filter-actions { align-self: stretch; }
  .filter-actions .button { flex: 1; }
  .qr-grid { grid-template-columns: repeat(2, minmax(220px, 1fr)); }
  .qr-item:nth-child(3n) { border-right: 1px solid var(--line); }
  .qr-item:nth-child(2n) { border-right: 0; }
  .managed-row { grid-template-columns: minmax(170px, 1fr) minmax(120px, .7fr) auto; }
  .managed-row .secondary-detail { grid-column: 1 / 3; }
}

@media (max-width: 760px) {
  .login-page { display: block; background: var(--paper); }
  .login-brand { min-height: 250px; padding: 36px 24px; }
  .login-panel { width: 100%; padding: 30px 22px 42px; box-shadow: none; }
  .staging-buttons { grid-template-columns: 1fr; }
  .topbar { position: static; min-height: 78px; padding: 14px 16px; }
  .account-box { gap: 9px; }
  .account-box small { max-width: 120px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .scope-banner { padding: 10px 16px; }
  .workspace { display: block; }
  .sidebar { display: none; }
  .mobile-tabs {
    position: sticky;
    z-index: 15;
    top: 0;
    display: flex;
    overflow-x: auto;
    border-bottom: 1px solid var(--line);
    background: var(--paper);
  }
  .mobile-tabs button { flex: 0 0 auto; min-height: 46px; padding: 8px 13px; border: 0; border-bottom: 3px solid transparent; background: transparent; font-size: .8rem; font-weight: 700; }
  .mobile-tabs button[aria-current="page"] { color: var(--pine); border-bottom-color: var(--pine); }
  main { padding: 28px 16px 52px; }
  .heading-row { align-items: flex-start; }
  .heading-row .button { flex: 0 0 auto; }
  .filter-bar { grid-template-columns: 1fr; padding: 15px; }
  .summary-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .summary-item:nth-child(2) { border-right: 0; }
  .summary-item:nth-child(-n+2) { border-bottom: 1px solid var(--line); }
  .table-wrap { display: none !important; }
  .stack-list:not([hidden]) { display: block; }
  .managed-row { grid-template-columns: 1fr; gap: 10px; }
  .managed-row .secondary-detail { grid-column: auto; }
  .row-actions { justify-content: flex-start; flex-wrap: wrap; }
  .service-row { align-items: flex-start; gap: 12px; }
  .service-row .row-actions { flex: 0 0 auto; }
  .qr-grid { grid-template-columns: 1fr; }
  .qr-item, .qr-item:nth-child(2n), .qr-item:nth-child(3n) { border-right: 0; }
  .detail-grid { grid-template-columns: 1fr; }
  .review-heading { display: block; }
  .review-heading time { display: block; margin-top: 5px; }
}

@media (max-width: 460px) {
  .heading-row { display: block; }
  .heading-row > .button { width: 100%; margin-top: 15px; }
  .account-box > div { display: none; }
  .summary-item { padding: 15px 11px; }
  .dialog-head, .dialog-body, .dialog-form, .annotation-form { padding-inline: 17px; }
}

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