/* Admin panel. Same palette and house rules as the app (public/css/app.css):
   flat fills, surfaces separated by borders rather than shadows, one
   near-black text colour with a purple undertone.

   The one colour added is --series, the chart violet. The brand purple reads
   as grey at bar sizes (it fails the chroma floor), so charts use a more
   saturated step of the same hue, checked for contrast against white. */

:root {
  --primary: #7B5E9B;
  --primary-dark: #6A5185;
  --primary-50: #F4F2F7;
  --primary-100: #EAE5EF;
  --series: #7048B8;
  --series-soft: #E6DEF6;

  --bg: #F6F9FD;
  --surface: #FFFFFF;
  --surface2: #EDF2FA;
  --border: #D9E4F5;
  --hairline: #E9EEF7;
  --text: #2B2438;
  --muted: #6E6482;

  --good: #377366;  --good-bg: #F1F8F6;  --good-line: #C3E0DA;
  --warn: #9D6507;  --warn-bg: #FEF8EE;  --warn-line: #FCE0B1;
  --bad: #B42318;   --bad-bg: #FEF2F2;   --bad-line: #FECACA;
  --info: #56426C;  --info-bg: #F4F2F7;  --info-line: #D2C8DD;

  --radius: 14px;
  color-scheme: light;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, p { margin: 0; }
a { color: inherit; }
button, input, select, textarea { font: inherit; color: inherit; }

.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; }
.nowrap { white-space: nowrap; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.link { color: var(--primary); text-decoration: none; font-weight: 600; }
.link:hover { text-decoration: underline; }
.link-btn { border: none; background: none; padding: 0; color: var(--primary); font-weight: 600; cursor: pointer; }
.link-btn:hover { text-decoration: underline; }

/* ── Buttons ── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--border); background: var(--surface2); color: var(--text);
  padding: 8px 14px; border-radius: 10px; font-weight: 600; font-size: 13px;
  cursor: pointer; white-space: nowrap; text-decoration: none;
}
.btn:hover { border-color: #BCCFEE; }
.btn:disabled { opacity: .55; cursor: default; }
.btn:focus-visible, .input:focus-visible, .link:focus-visible, a:focus-visible, button:focus-visible {
  outline: 2px solid var(--series); outline-offset: 2px;
}
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }
.btn-danger { background: var(--bad-bg); border-color: var(--bad-line); color: var(--bad); }
.btn-danger:hover { border-color: var(--bad); }
.btn-warn { background: var(--warn-bg); border-color: var(--warn-line); color: var(--warn); }
.btn-sm { padding: 5px 10px; font-size: 12px; border-radius: 8px; }
.btn-block { width: 100%; }
.icon-btn {
  border: none; background: transparent; width: 32px; height: 32px; border-radius: 8px;
  cursor: pointer; color: var(--muted); font-size: 16px;
}
.icon-btn:hover { background: var(--surface2); }

/* ── Form controls ── */
.input {
  width: 100%; border: 1px solid var(--border); background: var(--surface);
  border-radius: 10px; padding: 8px 11px; font-size: 14px; min-height: 36px;
}
.input:focus { border-color: var(--primary); outline: none; }
.input:disabled { background: var(--surface2); color: var(--muted); }
textarea.input { resize: vertical; min-height: 60px; }
select.input { padding-right: 28px; }
.input-sm { min-height: 30px; padding: 4px 8px; font-size: 12.5px; width: auto; }
.field { margin-bottom: 14px; }
.field-label { display: block; font-size: 12px; font-weight: 700; color: var(--muted); margin-bottom: 5px; }
.field-hint { font-size: 12px; color: var(--muted); margin-top: 5px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); column-gap: 14px; }
.form-error {
  color: var(--bad); background: var(--bad-bg); border: 1px solid var(--bad-line);
  border-radius: 10px; padding: 9px 11px; font-size: 13px; margin-top: 4px;
}
.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-size: 13.5px; }
.check input { width: 16px; height: 16px; accent-color: var(--primary); margin: 0; }
.check-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 8px; }
.secret { display: flex; gap: 8px; margin: 8px 0; }
.callout { border-radius: 10px; padding: 10px 12px; font-size: 13px; margin: 4px 0 12px; }
.callout.warn { background: var(--warn-bg); border: 1px solid var(--warn-line); color: var(--warn); }

/* ── Sign-in ── */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.login-card {
  width: 100%; max-width: 380px; background: var(--surface);
  border: 1px solid var(--border); border-radius: 18px; padding: 26px;
}
.login-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 22px; }
.login-title { font-weight: 800; font-size: 16px; }
.login-sub { color: var(--muted); font-size: 13px; }
.login-note { border-radius: 10px; padding: 9px 11px; font-size: 13px; margin-bottom: 14px; background: var(--info-bg); border: 1px solid var(--info-line); color: var(--info); }
.login-note.bad { background: var(--bad-bg); border-color: var(--bad-line); color: var(--bad); }
.login-foot { color: var(--muted); font-size: 12px; text-align: center; margin-top: 14px; }
.brand-mark {
  width: 34px; height: 34px; border-radius: 50%; flex: none;
  border: 3px solid var(--primary); background:
    linear-gradient(var(--primary), var(--primary)) 9px 12px / 3px 8px no-repeat,
    linear-gradient(var(--primary), var(--primary)) 14px 7px / 3px 18px no-repeat,
    linear-gradient(var(--primary), var(--primary)) 19px 10px / 3px 12px no-repeat,
    var(--primary-50);
}

/* ── Layout ── */
.shell { display: grid; grid-template-columns: 236px minmax(0, 1fr); min-height: 100vh; }
.side {
  position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column;
  background: var(--surface); border-right: 1px solid var(--border); padding: 18px 12px;
}
.side-brand { display: flex; align-items: center; gap: 10px; padding: 0 8px 18px; }
.side-title { font-weight: 800; font-size: 13.5px; line-height: 1.2; }
.side-sub { color: var(--muted); font-size: 12px; }
.menu-btn { display: none; margin-left: auto; }
.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; overflow-y: auto; }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 9px;
  text-decoration: none; color: var(--text); font-weight: 600; font-size: 13.5px;
}
.nav a:hover { background: var(--surface2); }
.nav a.active { background: var(--primary-50); color: var(--info); box-shadow: inset 3px 0 0 var(--primary); }
.nav-ico { width: 18px; text-align: center; color: var(--muted); }
.nav a.active .nav-ico { color: var(--primary); }
.side-foot { border-top: 1px solid var(--border); padding: 14px 8px 0; margin-top: 12px; }
.me-name { font-weight: 700; font-size: 13px; }
.me-email { color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side-links { display: flex; justify-content: space-between; margin-top: 10px; font-size: 13px; }

.main { padding: 28px 32px 48px; min-width: 0; outline: none; transition: opacity .15s; }
.main.loading { opacity: .6; }
.view { max-width: 1280px; }

@media (max-width: 900px) {
  .shell { display: block; }
  .side { position: sticky; height: auto; z-index: 20; padding: 10px 12px; border-right: none; border-bottom: 1px solid var(--border); }
  .side-brand { padding: 0; }
  .menu-btn { display: inline-block; }
  .nav, .side-foot { display: none; }
  body.nav-open .nav { display: flex; margin-top: 10px; }
  body.nav-open .side-foot { display: block; }
  .main { padding: 18px 16px 40px; }
}

/* ── Page furniture ── */
.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; margin-bottom: 18px; }
.page-head h1 { font-size: 22px; font-weight: 800; letter-spacing: -.2px; }
.page-sub { color: var(--muted); margin-top: 4px; max-width: 70ch; }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.view > .page-actions { margin-bottom: 12px; }
.crumbs { margin-bottom: 10px; font-size: 13px; }
.action-row { display: flex; flex-wrap: wrap; gap: 8px; margin: 14px 0 18px; }
.badges { display: inline-flex; flex-wrap: wrap; gap: 5px; align-items: center; }
.badges.spaced { margin-top: -8px; }
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 14px; }
.filters .input { width: auto; min-width: 150px; }
.filters .input[type="search"] { flex: 1 1 240px; }
.chip { display: inline-flex; gap: 6px; align-items: center; background: var(--primary-50); border: 1px solid var(--info-line); border-radius: 999px; padding: 4px 10px; font-size: 12.5px; }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px; margin-bottom: 16px; min-width: 0;
}
.card-title { font-size: 14px; font-weight: 700; margin-bottom: 14px; }
.card-foot { margin-top: 14px; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 16px; }
.grid-2 > .card, .grid-3 > .card, .stack > .card { margin-bottom: 0; }
.grid-2, .grid-3 { margin-bottom: 16px; }
.stack { display: flex; flex-direction: column; gap: 16px; }
.note { color: var(--muted); font-size: 13px; margin-bottom: 12px; }
.note.warn { color: var(--warn); margin: 12px 0 0; }
.empty { color: var(--muted); text-align: center; padding: 28px 12px; font-size: 13.5px; }
.error-state { padding: 60px 20px; text-align: center; display: grid; gap: 12px; justify-items: center; }

/* ── Tabs ── */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; overflow-x: auto; }
.tab {
  padding: 9px 12px; text-decoration: none; color: var(--muted); font-weight: 600; font-size: 13.5px;
  border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--text); border-bottom-color: var(--primary); }

/* ── Badges ── */
.badge {
  display: inline-flex; align-items: center; border-radius: 999px; padding: 2px 9px;
  font-size: 11.5px; font-weight: 700; border: 1px solid; white-space: nowrap;
}
.badge-neutral { background: var(--surface2); border-color: var(--border); color: var(--muted); }
.badge-good { background: var(--good-bg); border-color: var(--good-line); color: var(--good); }
.badge-warn { background: var(--warn-bg); border-color: var(--warn-line); color: var(--warn); }
.badge-bad { background: var(--bad-bg); border-color: var(--bad-line); color: var(--bad); }
.badge-info { background: var(--info-bg); border-color: var(--info-line); color: var(--info); }

/* ── Tables ── */
.table-wrap { overflow-x: auto; margin: 0 -4px; }
.table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.table th {
  text-align: left; font-size: 11.5px; font-weight: 700; color: var(--muted); text-transform: uppercase;
  letter-spacing: .4px; padding: 8px 10px; border-bottom: 1px solid var(--border); white-space: nowrap;
}
.table td { padding: 10px; border-bottom: 1px solid var(--hairline); vertical-align: top; }
.table tr:last-child td { border-bottom: none; }
.table tr.clickable { cursor: pointer; }
.table tr.clickable:hover td, .table tr.clickable:focus-visible td { background: #FAFBFE; }
.table tr.clickable:focus-visible { outline: 2px solid var(--series); outline-offset: -2px; }
.table.compact td, .table.compact th { padding: 6px 8px; }
.who { display: flex; flex-direction: column; gap: 1px; }
.pager { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-top: 14px; flex-wrap: wrap; }

/* ── Facts ── */
.facts { display: grid; grid-template-columns: minmax(120px, max-content) 1fr; gap: 8px 16px; margin: 0; }
.facts dt { color: var(--muted); font-size: 13px; }
.facts dd { margin: 0; font-size: 13.5px; overflow-wrap: anywhere; }
.facts + .table-wrap { margin-top: 14px; }

/* ── Stat tiles ── */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; margin-bottom: 16px; }
.stats.compact { grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 10px; margin: 0; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; }
.stats.compact .stat { padding: 12px; background: var(--bg); }
.stat-label { color: var(--muted); font-size: 12.5px; font-weight: 600; }
.stat-value { font-size: 28px; font-weight: 700; letter-spacing: -.5px; margin-top: 4px; }
.stats.compact .stat-value { font-size: 22px; }
.stat-sub { color: var(--muted); font-size: 12px; margin-top: 2px; }
.stat-warn { border-color: var(--warn-line); background: var(--warn-bg); }
.stat-warn .stat-value { color: var(--warn); }
@media (max-width: 640px) {
  .stats { grid-template-columns: 1fr 1fr; gap: 10px; }
  .stat { padding: 12px 14px; }
  .stat-value { font-size: 24px; }
}

/* ── Charts ── */
.chart { position: relative; }
.chart-plot { width: 100%; min-height: 170px; }
.chart svg { display: block; overflow: visible; }
.chart .bar { fill: var(--series); transition: fill .12s; }
.chart .bar.on { fill: #8D6BD0; }
.chart .grid { stroke: var(--hairline); stroke-width: 1; shape-rendering: crispEdges; }
.chart .axis { stroke: var(--border); stroke-width: 1; shape-rendering: crispEdges; }
.chart .tick { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .hit { fill: transparent; cursor: default; outline: none; }
.chart .hit:focus-visible { fill: rgba(112, 72, 184, .08); }
.chart-tip {
  position: absolute; transform: translate(-50%, -100%); pointer-events: none;
  background: var(--text); color: #fff; border-radius: 8px; padding: 6px 9px; font-size: 12px;
  white-space: nowrap; z-index: 2;
}
.chart-tip strong { font-size: 14px; }
.tip-sub { color: #D2C8DD; font-size: 11.5px; }
.chart-table { margin-top: 8px; font-size: 12.5px; }
.chart-table summary { color: var(--muted); cursor: pointer; font-weight: 600; }
.chart-table .table-wrap { max-height: 220px; overflow-y: auto; margin-top: 6px; }

.barlist { display: flex; flex-direction: column; gap: 9px; }
.barlist-row { display: grid; grid-template-columns: minmax(120px, 190px) 1fr; gap: 12px; align-items: center; }
.barlist-label { font-size: 13px; display: flex; gap: 6px; align-items: center; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.barlist-ico { width: 18px; text-align: center; flex: none; }
.barlist-track { display: flex; align-items: center; gap: 8px; min-width: 0; }
.barlist-bar { height: 14px; background: var(--series); border-radius: 0 4px 4px 0; transition: background .12s; }
.barlist-row:hover .barlist-bar { background: #8D6BD0; }
.barlist-val { font-size: 12.5px; font-variant-numeric: tabular-nums; color: var(--text); font-weight: 600; }

.meter-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 8px; }
.meter-label { font-weight: 600; font-size: 13px; }
.meter-value { font-size: 22px; font-weight: 700; }
.meter-track { height: 10px; border-radius: 999px; background: var(--series-soft); overflow: hidden; }
.meter-fill { height: 100%; background: var(--series); border-radius: 999px; }
.meter-sub { color: var(--muted); font-size: 12.5px; margin-top: 8px; }

/* ── Person record ── */
.convo { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
.bubble { max-width: 78%; border-radius: 14px; padding: 9px 12px; border: 1px solid var(--border); }
.bubble.ai { align-self: flex-start; background: var(--surface2); }
.bubble.me { align-self: flex-end; background: var(--primary-50); border-color: var(--info-line); }
.bubble-text { white-space: pre-wrap; overflow-wrap: anywhere; }
.bubble-meta { color: var(--muted); font-size: 11.5px; margin-top: 4px; }
.qa-group + .qa-group { margin-top: 18px; }
.qa-group h3 { font-size: 13px; margin-bottom: 8px; color: var(--info); }
.qa { border-left: 3px solid var(--border); padding: 4px 0 4px 12px; margin-bottom: 10px; }
.qa-q { color: var(--muted); font-size: 13px; }
.qa-a { font-weight: 600; margin: 2px 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.letter {
  white-space: pre-wrap; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px;
  background: var(--bg); border: 1px solid var(--border); border-radius: 10px; padding: 14px;
  max-height: 55vh; overflow: auto; margin-top: 14px;
}

/* ── Content ── */
details.practitioner summary { display: flex; align-items: center; gap: 10px; cursor: pointer; list-style: none; flex-wrap: wrap; }
details.practitioner summary::-webkit-details-marker { display: none; }
details.practitioner summary::after { content: '›'; margin-left: auto; color: var(--muted); transition: transform .15s; }
details.practitioner[open] summary::after { transform: rotate(90deg); }
.pr-ico { font-size: 20px; }
.pr-name { font-weight: 700; }
.pr-body { margin-top: 14px; display: grid; gap: 10px; }
.pr-body h3 { font-size: 13px; margin-top: 6px; }
.plain-list { margin: 0; padding-left: 20px; display: grid; gap: 4px; }
.clip { width: 100%; max-height: 300px; border-radius: 10px; background: #111; margin-bottom: 14px; }

/* ── Settings & system ── */
.setting { display: grid; grid-template-columns: 1fr minmax(180px, 320px); gap: 16px; padding: 14px 0; border-bottom: 1px solid var(--hairline); align-items: start; }
.setting:first-child { padding-top: 0; }
.setting-name { font-weight: 700; margin-bottom: 2px; }
@media (max-width: 640px) { .setting { grid-template-columns: 1fr; } }
.service-list { display: flex; flex-direction: column; }
.service { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--hairline); }
.service:last-child { border-bottom: none; }

/* ── Dialogs & toasts ── */
.dialog {
  border: 1px solid var(--border); border-radius: 18px; padding: 0; width: min(560px, calc(100vw - 32px));
  max-height: calc(100vh - 48px); color: var(--text); background: var(--surface);
}
.dialog.wide { width: min(820px, calc(100vw - 32px)); }
.dialog::backdrop { background: rgba(43, 36, 56, .45); }
.dialog-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 16px 18px 0; }
.dialog-head h2 { font-size: 17px; font-weight: 800; }
.dialog-body { padding: 14px 18px; overflow-y: auto; max-height: calc(100vh - 190px); }
.dialog-text { margin-bottom: 14px; color: var(--muted); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 18px 16px; border-top: 1px solid var(--hairline); flex-wrap: wrap; }
.dialog-actions .btn-danger:first-child { margin-right: auto; }

.toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 1000; }
.toast {
  background: var(--text); color: #fff; padding: 10px 14px; border-radius: 10px; font-size: 13px; font-weight: 600;
  max-width: 380px; transition: opacity .3s, transform .3s; border-left: 4px solid #95C8BE;
}
.toast-bad { border-left-color: #F87171; }
.toast-warn, .toast-neutral { border-left-color: #F9C771; }
.toast.out { opacity: 0; transform: translateY(6px); }
.noscript { padding: 40px; text-align: center; }
