/* CareGrow Super Admin — premium, responsive, theme-aware */
:root {
  --bg: #f4f6fa; --surface: #ffffff; --surface-2: #eef2f8;
  --ink: #131a26; --ink-soft: #434d5e; --ink-faint: #6b7586;
  --line: #d9dfe9; --primary: #1d5fd1; --primary-deep: #154aa8; --primary-wash: #e6eefc;
  --amber: #c8791b; --amber-wash: #f8ecd9; --red: #c0392b; --green: #1d5fd1;
  --shadow: 0 1px 2px rgba(17,26,43,.06), 0 10px 30px rgba(17,26,43,.08);
  --radius: 14px;
  --f-display: "Bricolage Grotesque", "Trebuchet MS", sans-serif;
  --f-body: "IBM Plex Sans", system-ui, sans-serif;
  --f-mono: "IBM Plex Mono", ui-monospace, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b1120; --surface: #111a2b; --surface-2: #172338;
    --ink: #e6ecf5; --ink-soft: #aab6c8; --ink-faint: #7a879b;
    --line: #24314a; --primary: #5b9bff; --primary-deep: #8cb8ff; --primary-wash: #13233f;
    --amber: #d99a4e; --amber-wash: #2c2214; --red: #e07a6f;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 10px 30px rgba(0,0,0,.35); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0b1120; --surface: #111a2b; --surface-2: #172338;
  --ink: #e6ecf5; --ink-soft: #aab6c8; --ink-faint: #7a879b;
  --line: #24314a; --primary: #5b9bff; --primary-deep: #8cb8ff; --primary-wash: #13233f;
  --amber: #d99a4e; --amber-wash: #2c2214; --red: #e07a6f;
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 10px 30px rgba(0,0,0,.35); color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--f-body); line-height: 1.5; }
h1, h2, h3 { font-family: var(--f-display); margin: 0; }
button { font-family: var(--f-body); cursor: pointer; }
input, select { font-family: var(--f-body); }

.brand { font-family: var(--f-display); font-weight: 800; font-size: 20px; display: flex; align-items: center; gap: 9px; letter-spacing: -.01em; }
.brand-dot { width: 12px; height: 12px; border-radius: 4px; background: var(--primary); }

/* buttons */
.primary { background: var(--primary); color: #fff; border: none; padding: 10px 16px; border-radius: 10px; font-weight: 600; font-size: 14px; }
.primary:hover { background: var(--primary-deep); }
.primary:disabled { opacity: .55; cursor: default; }
.ghost { background: transparent; border: 1px solid var(--line); color: var(--ink-soft); padding: 7px 12px; border-radius: 9px; font-size: 13px; }
.ghost:hover { border-color: var(--primary); color: var(--primary-deep); }
.error { color: var(--red); font-size: 13px; margin: 0; }

/* ─── login ─── */
.login { min-height: 100%; display: grid; place-items: center; padding: 24px; }
.login-card { background: var(--surface); border: 1px solid var(--line); border-radius: 18px; box-shadow: var(--shadow); padding: 32px; width: 100%; max-width: 380px; display: flex; flex-direction: column; gap: 14px; }
.login-card .brand { font-size: 24px; }
.login-sub { font-family: var(--f-mono); font-size: 12px; text-transform: uppercase; letter-spacing: .12em; color: var(--ink-faint); margin: -6px 0 8px; }
.login-card label, .modal-card label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--ink-soft); font-weight: 500; }
.login-card input, .modal-card input, .modal-card select { background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; font-size: 14px; color: var(--ink); }
input:focus, select:focus { outline: 2px solid var(--primary); outline-offset: 1px; border-color: var(--primary); }

/* ─── shell ─── */
.shell { display: grid; grid-template-columns: 240px 1fr; min-height: 100%; }
.sidebar { background: var(--surface); border-right: 1px solid var(--line); padding: 22px 16px; display: flex; flex-direction: column; gap: 22px; }
.sidebar nav { display: flex; flex-direction: column; gap: 4px; }
.nav-item { padding: 9px 12px; border-radius: 9px; font-size: 14px; font-weight: 500; color: var(--ink-soft); cursor: pointer; }
.nav-item:hover { background: var(--surface-2); }
.nav-item.active { background: var(--primary-wash); color: var(--primary-deep); }
.side-foot { margin-top: auto; display: flex; flex-direction: column; gap: 12px; }
.me { display: flex; flex-direction: column; gap: 6px; font-size: 12px; color: var(--ink-faint); font-family: var(--f-mono); word-break: break-all; }

.content { padding: 26px clamp(16px, 3vw, 34px); min-width: 0; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 22px; flex-wrap: wrap; }
.topbar h1 { font-size: 26px; letter-spacing: -.02em; }

/* kpis */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 14px; margin-bottom: 24px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); }
.kpi .k { font-family: var(--f-mono); font-size: 11px; text-transform: uppercase; letter-spacing: .07em; color: var(--ink-faint); }
.kpi .v { font-family: var(--f-display); font-weight: 800; font-size: 30px; margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi.amber .v { color: var(--amber); }

/* panel + table */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 18px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.panel-head h2 { font-size: 16px; }
.search { background: var(--bg); border: 1px solid var(--line); border-radius: 9px; padding: 8px 12px; font-size: 13px; color: var(--ink); min-width: 180px; }
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; min-width: 640px; font-size: 14px; }
table.data th, table.data td { padding: 13px 18px; text-align: left; border-bottom: 1px solid var(--line); }
table.data th { font-family: var(--f-mono); font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-faint); font-weight: 500; }
table.data tbody tr:last-child td { border-bottom: none; }
table.data .clinic-name { font-weight: 600; }
table.data .slug { font-family: var(--f-mono); font-size: 12px; color: var(--ink-faint); }
.empty { text-align: center; color: var(--ink-faint); padding: 28px; }

.pill { font-family: var(--f-mono); font-size: 10px; text-transform: uppercase; letter-spacing: .04em; padding: 3px 9px; border-radius: 999px; display: inline-block; }
.pill.starter { background: var(--amber-wash); color: var(--amber); }
.pill.growth, .pill.pro, .pill.enterprise { background: var(--primary-wash); color: var(--primary-deep); }
.pill.active { background: var(--primary-wash); color: var(--primary-deep); }
.pill.suspended { background: var(--amber-wash); color: var(--amber); }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; }
.row-actions select { background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 5px 8px; font-size: 12px; color: var(--ink); }

/* modal */
.modal { position: fixed; inset: 0; background: rgba(8,12,22,.55); display: grid; place-items: center; padding: 20px; z-index: 50; }
.modal-card { background: var(--surface); border: 1px solid var(--line); border-radius: 18px; box-shadow: var(--shadow); padding: 26px; width: 100%; max-width: 560px; display: flex; flex-direction: column; gap: 16px; max-height: 90vh; overflow-y: auto; }
.modal-sub { color: var(--ink-soft); font-size: 13.5px; margin: -8px 0 0; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 4px; }

/* toast */
.toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 11px 18px; border-radius: 10px; font-size: 14px; box-shadow: var(--shadow); z-index: 60; }
.toast.err { background: var(--red); color: #fff; }

.topbar-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.mini { background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 5px 8px; font: 500 12px var(--f-body); color: var(--ink); text-transform: capitalize; }
.mini.status-active { color: var(--primary-deep); border-color: var(--primary); }
.mini.status-hold { color: var(--amber); border-color: var(--amber); }
.mini.status-blocked { color: var(--red); border-color: var(--red); }
.ghost.xs { padding: 5px 10px; font-size: 12px; }
.modal-card textarea { background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; font: 14px var(--f-body); color: var(--ink); resize: vertical; }

.url-row { display: flex; flex-direction: column; gap: 6px; }
.url-label { font-size: 12px; color: var(--ink-faint); font-weight: 500; }
.url-box { display: flex; align-items: center; gap: 8px; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; }
.url-box code { font-family: var(--f-mono); font-size: 13px; color: var(--primary-deep); flex: 1 1 auto; overflow-x: auto; white-space: nowrap; }
.copy { background: var(--primary-wash); color: var(--primary-deep); border: none; border-radius: 7px; padding: 5px 11px; font: 600 12px var(--f-body); cursor: pointer; flex: 0 0 auto; }

.loc-list { display: flex; flex-direction: column; gap: 8px; max-height: 320px; overflow-y: auto; }
.loc-item { display: grid; grid-template-columns: 1.2fr 1.6fr .9fr auto; gap: 8px; align-items: center; }
.loc-item input { background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; font: 13px var(--f-body); color: var(--ink); min-width: 0; }
@media (max-width: 560px) { .loc-item { grid-template-columns: 1fr 1fr; } }

/* ───────── Phones & small tablets ───────── */
html { -webkit-text-size-adjust: 100%; }
button, a, select, input, label { -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { flex-direction: row; align-items: center; flex-wrap: wrap; gap: 10px 14px; position: sticky; top: env(safe-area-inset-top, 0px); z-index: 10; padding: 12px 16px; }
  .sidebar nav { flex-direction: row; }
  .side-foot { margin: 0 0 0 auto; flex-direction: row; align-items: center; gap: 8px; }
  .me { flex-direction: row; align-items: center; }
  .grid2 { grid-template-columns: 1fr; }
  .content { padding: 18px 14px 28px; }
  .topbar h1 { font-size: 22px; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .kpi { padding: 12px 14px; } .kpi .v { font-size: 24px; }
  .panel-head { padding: 12px 14px; }
  .search { min-width: 0; width: 100%; }

  /* 16px inputs stop iPhone auto-zoom; 44px tap targets */
  input, select, textarea, .search, .mini { font-size: 16px !important; }
  .primary, .ghost { min-height: 42px; }
  .ghost.xs { min-height: 36px; padding: 6px 12px; }

  /* tables become stacked cards */
  .table-wrap { overflow: visible; }
  table.data { min-width: 0; }
  table.data thead { display: none; }
  table.data, table.data tbody, table.data tr, table.data td { display: block; width: 100%; }
  table.data tr { border-bottom: 1px solid var(--line); padding: 10px 14px; }
  table.data tbody tr:last-child { border-bottom: none; }
  table.data td { border: none; padding: 5px 0; display: flex; justify-content: space-between; align-items: center; gap: 12px; text-align: right; min-height: 30px; }
  table.data td::before { content: attr(data-label); font-family: var(--f-mono); font-size: 10px; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-faint); text-align: left; flex: 0 0 auto; }
  table.data td:first-child { font-size: 16px; }
  table.data td[data-label=""]::before, table.data td:not([data-label])::before { content: none; }
  table.data td.empty { display: block; text-align: center; }
  table.data td.empty::before { content: none; }
  .row-actions { flex-wrap: wrap; justify-content: flex-end; }

  /* pop-ups become full-width bottom sheets */
  .modal { padding: 0; place-items: end stretch; }
  .modal-card { max-width: none !important; width: 100%; border-radius: 20px 20px 0 0; max-height: 92dvh; padding: 20px 16px calc(20px + env(safe-area-inset-bottom, 0px)); animation: sheetUp .22s ease; }
  .modal-actions { position: sticky; bottom: calc(-20px - env(safe-area-inset-bottom, 0px)); background: var(--surface); padding: 12px 0 0; margin-bottom: -4px; flex-wrap: wrap; }
  .modal-actions .primary { flex: 1 1 auto; }
  .toast { left: 16px; right: 16px; transform: none; bottom: calc(80px + env(safe-area-inset-bottom, 0px)); text-align: center; }
  .login { padding: 16px; align-items: start; padding-top: 12vh; }
  .login-card { padding: 26px 20px; }
}
@keyframes sheetUp { from { transform: translateY(24px); opacity: .6; } to { transform: none; opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .modal-card { animation: none !important; } }

.legal { font-size: 11px; line-height: 1.5; color: var(--ink-faint); }
.check-row { flex-direction: row !important; align-items: center; gap: 8px; grid-column: 1 / -1; }
.switch { position: relative; display: inline-block; width: 40px; height: 22px; cursor: pointer; vertical-align: middle; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: var(--line); border-radius: 999px; transition: background .15s; }
.switch span::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.25); transition: transform .15s; }
.switch input:checked + span { background: var(--primary); }
.switch input:checked + span::after { transform: translateX(18px); }
.switch input:focus-visible + span { outline: 2px solid var(--primary); outline-offset: 2px; }

/* ── software update control ── */
.upd-box { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.upd-line { font-size: 14px; color: var(--ink-soft); }
.upd-side { flex-direction: column; align-items: stretch; margin-bottom: 12px; }
.upd-side .upd-line { font-size: 12px; }
.hint { font-size: 13px; color: var(--ink-soft); margin: 0; }
