/* Clinic Agent design system ("Neon Metal"). Spec: docs/DESIGN_SYSTEM.md
   Dark is the default theme (from the brand art); light is a full theme, not an inversion.
   --accent comes from the partner's primary color at runtime (ds.js applyBrand). */

/* ---------- Tokens ---------- */
:root, [data-theme="dark"] {
  color-scheme: dark;
  /* Brand */
  --accent: #7ED321;            /* partner primary; neon green by default */
  --accent-hover: #93E63A;
  /* Everything below follows --accent, so a clinic's own color (applyBrand) recolors the whole UI */
  --accent-text: color-mix(in srgb, var(--accent) 70%, white);  /* accent as text/icon on dark surfaces */
  --accent-soft: color-mix(in srgb, var(--accent) 12%, transparent);
  --accent-ring: color-mix(in srgb, var(--accent) 45%, transparent);
  --on-accent: #0A1003;
  --glow: 0 0 0 1px color-mix(in srgb, var(--accent) 35%, transparent), 0 0 22px color-mix(in srgb, var(--accent) 22%, transparent);
  --metal: linear-gradient(180deg, #F4F6F7 0%, #C3C9CE 48%, #7F878D 100%);

  /* Surfaces: near-black with a green tint, stepped up for elevation */
  --bg: #070907;
  --bg-art: radial-gradient(1200px 600px at -10% 110%, color-mix(in srgb, var(--accent) 16%, transparent), transparent 60%),
            radial-gradient(800px 400px at 110% -10%, color-mix(in srgb, var(--accent) 5%, transparent), transparent 60%);
  --surface-1: #0D100C;
  --surface-2: #131711;
  --surface-3: #1A1F17;
  --border: #242A20;
  --border-strong: #353D30;

  /* Text */
  --text: #EDF2E8;
  --text-2: #B3BBAB;
  --text-3: #7D8676;

  /* Status (always with icon + label, never color alone) */
  --success: #5EE08F; --success-soft: rgba(94, 224, 143, .12);
  --warning: #F5B544; --warning-soft: rgba(245, 181, 68, .13);
  --danger:  #FF7466; --danger-soft:  rgba(255, 116, 102, .13);
  --info:    #6CC3FF; --info-soft:    rgba(108, 195, 255, .12);

  --shadow-1: 0 1px 0 rgba(255, 255, 255, .03) inset, 0 1px 2px rgba(0, 0, 0, .5);
  --shadow-pop: 0 20px 60px rgba(0, 0, 0, .6), 0 0 0 1px var(--border-strong);
  --chat-bg: #0A0D09;
  --bubble-in: #1F3A12;
}

[data-theme="light"] {
  color-scheme: light;
  --accent-text: color-mix(in srgb, var(--accent) 55%, black);  /* darker, for contrast on white */
  --accent-soft: color-mix(in srgb, var(--accent) 16%, transparent);
  --glow: 0 0 0 1px color-mix(in srgb, var(--accent) 45%, transparent), 0 0 16px color-mix(in srgb, var(--accent) 25%, transparent);
  --metal: linear-gradient(180deg, #5C646A 0%, #2B3135 100%);
  --bg: #F3F5F0;
  --bg-art: radial-gradient(1200px 600px at -10% 110%, color-mix(in srgb, var(--accent) 14%, transparent), transparent 60%);
  --surface-1: #FFFFFF;
  --surface-2: #F6F8F3;
  --surface-3: #ECF0E7;
  --border: #DFE4D9;
  --border-strong: #C9D0C1;
  --text: #12160F;
  --text-2: #475043;
  --text-3: #6E7768;
  --success: #1E7B3E; --success-soft: #E5F5EA;
  --warning: #9A5B00; --warning-soft: #FDF0DC;
  --danger:  #B42318; --danger-soft:  #FDECEA;
  --info:    #0B6BB0; --info-soft:    #E3F1FB;
  --shadow-1: 0 1px 2px rgba(16, 24, 12, .06);
  --shadow-pop: 0 20px 50px rgba(16, 24, 12, .18), 0 0 0 1px var(--border);
  --chat-bg: #EEF1EA;
  --bubble-in: #DDF6C6;
}

:root {
  /* Type */
  --font-display: "Exo 2", "Segoe UI", system-ui, sans-serif;
  --font-body: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
  --font-mono: ui-monospace, "Cascadia Mono", Consolas, monospace;
  --fs-xs: 11px; --fs-sm: 12px; --fs-md: 14px; --fs-lg: 16px; --fs-xl: 20px; --fs-2xl: 26px; --fs-3xl: 32px;

  /* Space (4px grid) and shape */
  --s-1: 4px; --s-2: 8px; --s-3: 12px; --s-4: 16px; --s-5: 20px; --s-6: 24px; --s-8: 32px;
  --r-sm: 6px; --r-md: 10px; --r-lg: 14px; --r-full: 999px;
  --ease: cubic-bezier(.2, .7, .2, 1);
}

/* ---------- Base ---------- */
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: var(--fs-md)/1.5 var(--font-body);
  color: var(--text);
  background: var(--bg-art), var(--bg);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { font-family: var(--font-display); margin: 0; letter-spacing: .01em; }
h1 { font-size: var(--fs-2xl); font-weight: 700; }
h2 { font-size: var(--fs-lg); font-weight: 600; }
h3 { font-size: var(--fs-md); font-weight: 600; }
a { color: var(--accent-text); }
code { font-family: var(--font-mono); font-size: var(--fs-sm); background: var(--surface-3); padding: 1px 6px; border-radius: var(--r-sm); }
::selection { background: var(--accent-soft); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }
.icon { width: 18px; height: 18px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; }
.icon-lg { width: 24px; height: 24px; }
.muted { color: var(--text-3); }
.text-2 { color: var(--text-2); }

/* Wordmark: brushed-metal headline like the logo */
.metal { background: var(--metal); -webkit-background-clip: text; background-clip: text; color: transparent; }

/* Section label (uppercase, tracked) */
.label-caps { font-size: var(--fs-xs); font-weight: 700; letter-spacing: .1em; text-transform: uppercase; color: var(--text-3); margin: var(--s-6) 0 var(--s-3); display: flex; align-items: center; gap: var(--s-3); }
.label-caps::after { content: ""; flex: 1; height: 1px; background: var(--border); }

/* ---------- Buttons ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: var(--s-2); height: 38px; padding: 0 var(--s-4);
  border-radius: var(--r-md); border: 1px solid transparent; font: 600 var(--fs-md)/1 var(--font-body); cursor: pointer;
  transition: background .15s var(--ease), box-shadow .15s var(--ease), border-color .15s var(--ease); white-space: nowrap; }
.btn-primary { background: var(--accent); color: var(--on-accent); }
.btn-primary:hover { background: var(--accent-hover); box-shadow: var(--glow); }
.btn-secondary { background: var(--surface-3); color: var(--text); border-color: var(--border-strong); }
.btn-secondary:hover { border-color: var(--accent-ring); }
.btn-ghost { background: transparent; color: var(--text-2); }
.btn-ghost:hover { background: var(--surface-3); color: var(--text); }
.btn-danger { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.btn-danger:hover { border-color: var(--danger); }
.btn-sm { height: 30px; padding: 0 var(--s-3); font-size: var(--fs-sm); }
.btn-icon { width: 34px; height: 34px; padding: 0; }
.btn:disabled { opacity: .5; cursor: not-allowed; box-shadow: none; }

/* ---------- Form ---------- */
.field { display: grid; gap: var(--s-1); margin-bottom: var(--s-4); }
.field > label, .field-label { font-size: var(--fs-sm); font-weight: 600; color: var(--text-2); }
.hint { font-size: var(--fs-sm); color: var(--text-3); }
.input, .select, .textarea { width: 100%; font: var(--fs-md)/1.4 var(--font-body); color: var(--text);
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r-md); padding: 9px 12px;
  transition: border-color .15s var(--ease), box-shadow .15s var(--ease); }
.input:hover, .select:hover, .textarea:hover { border-color: var(--border-strong); }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.textarea { resize: vertical; min-height: 96px; }
.select { appearance: none; padding-right: 34px; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none' stroke='%237D8676' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m4 6 4 4 4-4'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center; }
.input:disabled, .select:disabled, .textarea:disabled { opacity: .6; cursor: not-allowed; }
.grid-fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 0 var(--s-4); }

/* Switch (toggle) */
.switch { position: relative; display: inline-flex; align-items: center; gap: var(--s-3); cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch .track { width: 36px; height: 20px; border-radius: var(--r-full); background: var(--border-strong); position: relative; transition: background .15s var(--ease); flex: none; }
.switch .track::after { content: ""; position: absolute; top: 3px; left: 3px; width: 14px; height: 14px; border-radius: 50%; background: var(--text-2); transition: transform .15s var(--ease), background .15s; }
.switch input:checked + .track { background: var(--accent); }
.switch input:checked + .track::after { transform: translateX(16px); background: var(--on-accent); }
.switch input:focus-visible + .track { outline: 2px solid var(--accent); outline-offset: 2px; }
.switch input:disabled + .track { opacity: .5; }

/* ---------- Layout ---------- */
.app { display: grid; grid-template-columns: 248px minmax(0, 1fr); min-height: 100vh; }
/* One scroll for the whole page: a sidebar taller than the window scrolls with the page until its bottom
   shows, then stays (top = window height − sidebar height, set by ds.js). A short one stays pinned. */
.sidebar { position: sticky; top: min(0px, calc(100vh - var(--sidebar-h, 100vh))); align-self: start; min-height: 100vh;
  display: flex; flex-direction: column; gap: 2px;
  padding: var(--s-4) var(--s-3); background: color-mix(in srgb, var(--surface-1) 88%, transparent); border-right: 1px solid var(--border); backdrop-filter: blur(8px); }
.brand { display: flex; align-items: center; gap: var(--s-3); padding: var(--s-1) var(--s-2) var(--s-4); }
.brand img { width: 36px; height: 36px; object-fit: contain; filter: drop-shadow(0 0 8px var(--accent-soft)); }
.brand-name { font: 700 var(--fs-lg)/1.1 var(--font-display); }
.nav { display: grid; gap: 2px; }
.nav-item { display: flex; align-items: center; gap: var(--s-3); height: 36px; padding: 0 var(--s-3); border-radius: var(--r-md);
  color: var(--text-2); background: none; border: 0; font: 500 var(--fs-md) var(--font-body); cursor: pointer; text-align: left; width: 100%; position: relative; }
.nav-item:hover { background: var(--surface-3); color: var(--text); }
.nav-item[aria-current="page"] { background: var(--accent-soft); color: var(--accent-text); font-weight: 600; }
.nav-item[aria-current="page"]::before { content: ""; position: absolute; left: -12px; top: 8px; bottom: 8px; width: 3px; border-radius: 0 3px 3px 0; background: var(--accent); box-shadow: var(--glow); }
.sidebar-foot { margin-top: auto; padding: var(--s-3) var(--s-2) 0; border-top: 1px solid var(--border); display: grid; gap: var(--s-2); }
.user { display: flex; align-items: center; gap: var(--s-3); font-size: var(--fs-sm); color: var(--text-3); }
.avatar { width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; background: var(--surface-3); color: var(--accent-text); font-weight: 700; border: 1px solid var(--border-strong); }
.user strong { display: block; color: var(--text); font-size: var(--fs-md); }

.main { min-width: 0; padding: var(--s-6) var(--s-8) var(--s-8); }
.page-head { display: flex; align-items: flex-end; gap: var(--s-4); flex-wrap: wrap; margin-bottom: var(--s-6); }
.page-head .titles { margin-right: auto; }
.page-head p { margin: var(--s-1) 0 0; color: var(--text-3); }

.card { background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--r-lg); padding: var(--s-5); box-shadow: var(--shadow-1); }
.card-head { display: flex; align-items: center; gap: var(--s-3); margin-bottom: var(--s-4); }
.card-head h2 { margin-right: auto; }
.split { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr); gap: var(--s-5); align-items: start; }
.stack { display: grid; gap: var(--s-5); }

@media (max-width: 1080px) { .split { grid-template-columns: 1fr; } .main { padding: var(--s-5); } }
@media (max-width: 760px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .sidebar { position: static; height: auto; min-height: 0; flex-direction: row; flex-wrap: wrap; align-items: center; padding: var(--s-2) var(--s-3); min-width: 0; }
  .brand { padding: var(--s-1); }
  .nav { display: flex; overflow-x: auto; width: 100%; min-width: 0; }
  .nav-item { width: auto; white-space: nowrap; }
  .nav-item[aria-current="page"]::before { display: none; }
  .sidebar-foot { display: none; }
  .main { padding: var(--s-4); }
}

/* ---------- Tabs (underline, like the reference settings screen) ---------- */
.tabs { display: flex; gap: var(--s-1); border-bottom: 1px solid var(--border); margin-bottom: var(--s-5); overflow-x: auto; overflow-y: hidden; scrollbar-width: none; }
.tab { display: inline-flex; align-items: center; gap: var(--s-2); padding: var(--s-3) var(--s-4); background: none; border: 0;
  border-bottom: 2px solid transparent; margin-bottom: -1px; color: var(--text-2); font: 500 var(--fs-md) var(--font-body); cursor: pointer; white-space: nowrap; }
.tab:hover { color: var(--text); }
.tab[aria-selected="true"] { color: var(--accent-text); border-bottom-color: var(--accent); font-weight: 600; }

/* ---------- Badges ---------- */
.badge { display: inline-flex; align-items: center; gap: 5px; height: 22px; padding: 0 9px; border-radius: var(--r-full);
  font-size: var(--fs-xs); font-weight: 700; letter-spacing: .02em; background: var(--surface-3); color: var(--text-2); white-space: nowrap; }
.badge .icon { width: 13px; height: 13px; stroke-width: 2.25; }
.badge-accent { background: var(--accent-soft); color: var(--accent-text); }
.badge-success { background: var(--success-soft); color: var(--success); }
.badge-warning { background: var(--warning-soft); color: var(--warning); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }

/* ---------- Stat tiles ---------- */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: var(--s-4); margin-bottom: var(--s-5); }
.tile { background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--r-lg); padding: var(--s-4) var(--s-5); box-shadow: var(--shadow-1); }
.tile-label { display: flex; align-items: center; gap: var(--s-2); font-size: var(--fs-sm); font-weight: 600; color: var(--text-2); }
.tile-label .icon { color: var(--accent-text); width: 16px; height: 16px; }
.tile-value { font: 700 var(--fs-3xl)/1.15 var(--font-display); font-variant-numeric: tabular-nums; margin: var(--s-2) 0 2px; }
.tile-sub { font-size: var(--fs-sm); color: var(--text-3); }

/* ---------- Segmented control ---------- */
.segmented { display: inline-flex; padding: 3px; gap: 2px; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r-md); }
.segmented button { border: 0; background: none; color: var(--text-2); font: 500 var(--fs-sm) var(--font-body); padding: 6px 12px; border-radius: 7px; cursor: pointer; }
.segmented button[aria-pressed="true"] { background: var(--surface-3); color: var(--text); font-weight: 600; box-shadow: 0 0 0 1px var(--border-strong); }

/* ---------- Table ---------- */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: var(--fs-md); }
.table th { text-align: left; font-size: var(--fs-xs); font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--text-3); padding: var(--s-2) var(--s-3); border-bottom: 1px solid var(--border); white-space: nowrap; }
.table td { padding: var(--s-3); border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr:hover td { background: var(--surface-2); }
.table .num { text-align: right; font-variant-numeric: tabular-nums; color: var(--text-2); white-space: nowrap; }

/* ---------- Entity cards (agents) ---------- */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: var(--s-4); }
.entity { display: flex; flex-direction: column; gap: var(--s-3); background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--r-lg); padding: var(--s-5); box-shadow: var(--shadow-1); transition: border-color .15s var(--ease); }
.entity:hover { border-color: var(--border-strong); }
.entity.is-default { border-color: var(--accent-ring); box-shadow: var(--glow); }
.entity-head { display: flex; align-items: flex-start; gap: var(--s-3); }
.entity-icon { width: 44px; height: 44px; border-radius: var(--r-md); display: grid; place-items: center; flex: none; background: var(--accent-soft); color: var(--accent-text); border: 1px solid var(--accent-ring); }
.entity-title { min-width: 0; }
.entity-title h3 { font-size: var(--fs-lg); overflow-wrap: anywhere; }
.entity-badges { display: flex; gap: var(--s-1); flex-wrap: wrap; margin-top: var(--s-1); }
.entity p { margin: 0; color: var(--text-2); font-size: var(--fs-md); }
.entity-meta { display: flex; gap: var(--s-4); flex-wrap: wrap; font-size: var(--fs-sm); color: var(--text-3); }
.entity-meta span { display: inline-flex; align-items: center; gap: 6px; }
.entity-meta .icon { width: 14px; height: 14px; }
.entity-actions { display: flex; gap: var(--s-2); margin-top: auto; padding-top: var(--s-2); flex-wrap: wrap; }

/* Picker tiles (template chooser, like the reference "agent type" dialog) */
.picker { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: var(--s-3); }
.pick { display: flex; flex-direction: column; align-items: center; text-align: center; gap: var(--s-2); padding: var(--s-5) var(--s-3);
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r-lg); color: var(--text); cursor: pointer; font: inherit; transition: border-color .15s, box-shadow .15s, transform .15s; }
.pick:hover { border-color: var(--accent-ring); box-shadow: var(--glow); transform: translateY(-1px); }
.pick .icon { width: 28px; height: 28px; color: var(--accent-text); }
.pick strong { font: 600 var(--fs-md) var(--font-display); }
.pick .cat { font-size: var(--fs-xs); font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--text-3); }
.pick .desc { font-size: var(--fs-sm); color: var(--text-2); }
.pick.dashed { border-style: dashed; }

/* ---------- Dialog ---------- */
dialog.modal { width: min(760px, calc(100vw - 32px)); max-height: calc(100vh - 48px); padding: 0; border: 0; border-radius: var(--r-lg); background: var(--surface-1); color: var(--text); box-shadow: var(--shadow-pop); }
dialog.modal.sm { width: min(440px, calc(100vw - 32px)); }
dialog.modal::backdrop { background: rgba(3, 5, 3, .7); backdrop-filter: blur(3px); }
.modal-head { display: flex; align-items: center; gap: var(--s-3); padding: var(--s-5) var(--s-5) var(--s-3); }
.modal-head h2 { margin-right: auto; font-size: var(--fs-xl); }
.modal-body { padding: 0 var(--s-5) var(--s-5); overflow-y: auto; }
.modal-foot { display: flex; justify-content: flex-end; gap: var(--s-2); padding: var(--s-4) var(--s-5); border-top: 1px solid var(--border); }

/* ---------- Toast ---------- */
.toasts { position: fixed; right: var(--s-5); bottom: var(--s-5); display: grid; gap: var(--s-2); z-index: 50; }
.toast { display: flex; align-items: center; gap: var(--s-2); padding: var(--s-3) var(--s-4); border-radius: var(--r-md); background: var(--surface-3); border: 1px solid var(--border-strong); box-shadow: var(--shadow-pop); font-weight: 500; animation: toast-in .2s var(--ease); }
.toast.success .icon { color: var(--success); } .toast.danger .icon { color: var(--danger); }
@keyframes toast-in { from { opacity: 0; transform: translateY(6px); } }

/* ---------- Empty state ---------- */
.empty { text-align: center; padding: var(--s-8) var(--s-4); color: var(--text-3); }
.empty .icon { width: 32px; height: 32px; color: var(--accent-text); margin-bottom: var(--s-2); }

/* ---------- Chat ---------- */
.chat-log { height: 54vh; min-height: 320px; overflow-y: auto; display: flex; flex-direction: column; gap: var(--s-2); padding: var(--s-4); background: var(--chat-bg); border: 1px solid var(--border); border-radius: var(--r-md); }
.bubble { max-width: 78%; padding: 8px 12px; border-radius: 12px; white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.45; }
.bubble.in { align-self: flex-end; background: var(--bubble-in); border-bottom-right-radius: 4px; }
.bubble.out { align-self: flex-start; background: var(--surface-3); border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.chat-note { align-self: center; display: inline-flex; gap: 6px; align-items: center; font-size: var(--fs-sm); color: var(--warning); background: var(--warning-soft); padding: 3px 10px; border-radius: var(--r-full); }
.steps details { border-bottom: 1px solid var(--border); padding: var(--s-2) 0; }
.steps summary { cursor: pointer; display: flex; align-items: center; gap: var(--s-2); font-size: var(--fs-sm); list-style: none; }
.steps summary::-webkit-details-marker { display: none; }
.steps pre { white-space: pre-wrap; overflow-wrap: anywhere; background: var(--surface-2); border: 1px solid var(--border); padding: var(--s-3); border-radius: var(--r-md); font: var(--fs-sm)/1.5 var(--font-mono); margin: var(--s-2) 0 0; max-height: 360px; overflow: auto; }
pre.code { white-space: pre-wrap; overflow-wrap: anywhere; background: var(--surface-2); border: 1px solid var(--border); padding: var(--s-4); border-radius: var(--r-md); font: var(--fs-sm)/1.6 var(--font-mono); margin: 0; max-height: 70vh; overflow: auto; color: var(--text-2); }

/* Tool toggles list */
.toggle-list { display: grid; gap: 2px; }
.toggle-row { display: flex; align-items: center; gap: var(--s-4); padding: var(--s-3) var(--s-2); border-bottom: 1px solid var(--border); }
.toggle-row:last-child { border-bottom: 0; }
.toggle-row .text { flex: 1; min-width: 0; }
.toggle-row code { font-size: var(--fs-sm); }
.toggle-row p { margin: 2px 0 0; font-size: var(--fs-sm); color: var(--text-3); }

/* Sticky save bar */
.savebar { position: sticky; bottom: 0; display: flex; align-items: center; gap: var(--s-3); padding: var(--s-3) 0; margin-top: var(--s-4); background: linear-gradient(transparent, var(--surface-1) 30%); }

/* ---------- Auth screen (uses the brand background art) ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: var(--s-4);
  background: radial-gradient(1000px 600px at 0% 100%, color-mix(in srgb, var(--accent) 18%, transparent), transparent 60%),
    linear-gradient(rgba(7, 9, 7, .35), rgba(7, 9, 7, .55)), var(--auth-art, none) center / cover no-repeat, var(--brand-bg, var(--bg)); }
.auth-card { width: min(400px, 100%); background: color-mix(in srgb, var(--surface-1) 86%, transparent); border: 1px solid var(--border-strong); border-radius: var(--r-lg); padding: var(--s-8) var(--s-6); box-shadow: var(--shadow-pop); backdrop-filter: blur(10px); }
.auth-card img { display: block; width: 120px; height: 120px; object-fit: contain; margin: 0 auto var(--s-3); filter: drop-shadow(0 0 18px var(--accent-soft)); }
.auth-card h1 { text-align: center; font-size: var(--fs-xl); margin-bottom: var(--s-6); }

/* ---------- Panel additions (Step 7) ---------- */
.nav-group { font-size: var(--fs-xs); font-weight: 700; letter-spacing: .1em; text-transform: uppercase; color: var(--text-3); padding: var(--s-3) var(--s-3) 2px; }
.nav-group:first-child { padding-top: 0; }
@media (max-width: 760px) { .nav-group { display: none; } }
dialog.modal.md { width: min(640px, calc(100vw - 32px)); }
.modal-form { display: flex; flex-direction: column; max-height: calc(100vh - 48px); }
.toolbar { display: flex; align-items: center; gap: var(--s-4); flex-wrap: wrap; margin-bottom: var(--s-4); }
.legend { display: flex; gap: var(--s-4); flex-wrap: wrap; margin-left: auto; font-size: var(--fs-sm); color: var(--text-2); }
.legend-item { display: inline-flex; align-items: center; gap: 6px; }
.dot { width: 10px; height: 10px; border-radius: 50%; flex: none; display: inline-block; box-shadow: 0 0 0 2px var(--surface-1); }
.name-cell { display: flex; align-items: center; gap: var(--s-3); }
.row-actions { display: inline-flex; gap: var(--s-1); justify-content: flex-end; flex-wrap: wrap; }
.action-row { display: flex; gap: var(--s-2); flex-wrap: wrap; }
.clamp { max-width: 340px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Appointment detail */
.appt-detail-head { display: flex; align-items: center; gap: var(--s-3); margin-bottom: var(--s-3); }
.appt-detail-head h3 { font-size: var(--fs-xl); margin-right: auto; }
.appt-detail dl { display: grid; grid-template-columns: max-content 1fr; gap: var(--s-2) var(--s-5); margin: 0; }
.appt-detail dt { color: var(--text-3); font-size: var(--fs-sm); }
.appt-detail dd { margin: 0; }

/* Client picker (search + quick registration) */
.picker-results { display: grid; gap: 2px; margin-top: var(--s-1); }
.picker-results .result { display: flex; justify-content: space-between; gap: var(--s-3); padding: var(--s-2) var(--s-3); border-radius: var(--r-md);
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text); cursor: pointer; font: inherit; text-align: left; }
.picker-results .result:hover { border-color: var(--accent-ring); }
.chosen { display: flex; align-items: center; gap: var(--s-2); flex-wrap: wrap; }
.quick-client { margin-top: var(--s-3); padding: var(--s-3); border: 1px dashed var(--border-strong); border-radius: var(--r-md); display: grid; gap: var(--s-2); }

/* Weekly hours editor */
.hours-grid { display: grid; gap: var(--s-2); }
.hours-row { display: grid; grid-template-columns: 150px 110px auto 110px auto 110px auto 110px; align-items: center; gap: var(--s-2); }
.hours-row .day { min-width: 70px; }
.hours-row .input { padding: 6px 8px; }
@media (max-width: 760px) { .hours-row { grid-template-columns: 1fr 1fr; } .hours-row .muted { display: none; } .hours-row .switch { grid-column: 1 / -1; } }

/* ---------- Calendar (FullCalendar themed with the tokens) ---------- */
.calendar-card { padding: var(--s-4); }
.fc {
  --fc-border-color: var(--border);
  --fc-page-bg-color: var(--surface-1);
  --fc-neutral-bg-color: var(--surface-2);
  --fc-neutral-text-color: var(--text-3);
  --fc-list-event-hover-bg-color: var(--surface-2);
  --fc-today-bg-color: color-mix(in srgb, var(--accent) 6%, transparent);
  --fc-now-indicator-color: var(--accent);
  --fc-non-business-color: color-mix(in srgb, var(--bg) 55%, transparent);
  --fc-bg-event-color: var(--danger);
  --fc-bg-event-opacity: .14;
  --fc-highlight-color: var(--accent-soft);
  --fc-button-bg-color: var(--surface-3);
  --fc-button-border-color: var(--border-strong);
  --fc-button-text-color: var(--text);
  --fc-button-hover-bg-color: var(--surface-2);
  --fc-button-hover-border-color: var(--accent-ring);
  --fc-button-active-bg-color: var(--accent-soft);
  --fc-button-active-border-color: var(--accent);
  font-family: var(--font-body);
}
.fc .fc-toolbar-title { font: 600 var(--fs-xl) var(--font-display); }
.fc .fc-button { font-weight: 600; font-size: var(--fs-sm); border-radius: var(--r-md); text-transform: capitalize; box-shadow: none !important; }
.fc .fc-button-primary:not(:disabled).fc-button-active, .fc .fc-button-primary:not(:disabled):active { color: var(--accent-text); }
.fc .fc-col-header-cell-cushion, .fc .fc-daygrid-day-number, .fc .fc-list-day-cushion a { color: var(--text-2); text-decoration: none; font-weight: 600; }
.fc .fc-timegrid-slot-label-cushion { color: var(--text-3); font-size: var(--fs-sm); }
.fc .fc-timegrid-slot { height: 2.6em; }
.fc .fc-day-today .fc-col-header-cell-cushion { color: var(--accent-text); }
.fc-theme-standard .fc-list { border-color: var(--border); }
.fc .fc-list-event-dot { border-color: var(--accent); }

/* Appointment events: professional color as a left bar; status as icon + word */
.fc .fc-event.appt { background: color-mix(in srgb, var(--pro, var(--accent)) 20%, var(--surface-2)); border: 0; border-radius: var(--r-sm); padding: 0; cursor: pointer; box-shadow: none; }
.fc .fc-event.appt:hover { box-shadow: var(--glow); }
.fc .fc-event.appt .fc-event-main { color: var(--text); padding: 0; }
.appt-inner { --pro: var(--accent); height: 100%; padding: 3px 6px 3px 8px; border-left: 3px solid var(--pro); border-radius: var(--r-sm); overflow: hidden; font-size: var(--fs-sm); line-height: 1.3; }
.appt-time { color: var(--text-2); font-size: var(--fs-xs); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.appt-title { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.appt-sub { color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.appt-status { display: inline-flex; align-items: center; gap: 3px; font-size: var(--fs-xs); font-weight: 700; color: var(--text-2); }
.appt-status .icon { width: 11px; height: 11px; stroke-width: 2.5; }
.fc .st-requested .appt-inner { outline: 1px dashed var(--warning); outline-offset: -1px; }
.fc .st-requested .appt-status { color: var(--warning); }
.fc .st-confirmed .appt-status { color: var(--success); }
.fc .st-completed { opacity: .7; }
.fc .st-no_show .appt-title, .fc .st-cancelled .appt-title { text-decoration: line-through; }
.fc .st-no_show .appt-status { color: var(--danger); }
.fc .st-cancelled { opacity: .45; }
.fc .fc-daygrid-event.appt .appt-sub, .fc .fc-daygrid-event.appt .appt-status { display: none; }
.fc .fc-list-event.appt { background: none; }
.fc .fc-list-event.appt .appt-inner { border-left-width: 3px; }
.fc .fc-bg-event.block { background: repeating-linear-gradient(135deg, var(--danger-soft) 0 6px, transparent 6px 12px); opacity: 1; }
.block-label { font-size: var(--fs-xs); font-weight: 700; color: var(--danger); padding: 2px 6px; }

/* ---------- Clinics (platform/partner admins) ---------- */
.clinic-logo { width: 36px; height: 36px; border-radius: var(--r-md); object-fit: contain; background: var(--surface-3); border: 1px solid var(--border); flex: none; }
.clinic-logo.placeholder { display: inline-block; opacity: .8; }
.clinic-logo.lg { width: 72px; height: 72px; }
.logo-field { display: flex; align-items: center; gap: var(--s-4); }
.credentials { display: grid; gap: var(--s-3); justify-items: start; }
.credentials pre { width: 100%; }

/* ---------- Logo picker + live brand preview (clinic form) ---------- */
.logo-field { align-items: flex-start; }
.logo-controls { display: grid; gap: var(--s-2); justify-items: start; flex: 1; min-width: 0; }
.logo-empty { display: grid; place-items: center; color: var(--text-3); }
.clinic-logo.loading { opacity: .4; animation: pulse 1s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .15; } }

/* The preview re-derives the accent tokens locally, so it can show a color different from the page's */
.brand-preview {
  --accent-text: color-mix(in srgb, var(--accent) 70%, white);
  --accent-soft: color-mix(in srgb, var(--accent) 14%, transparent);
  --brand-bg: var(--bg);
  display: grid; grid-template-columns: 1.6fr 1fr; gap: var(--s-3);
}
[data-theme="light"] .brand-preview { --accent-text: color-mix(in srgb, var(--accent) 55%, black); }
@media (max-width: 760px) { .brand-preview { grid-template-columns: 1fr; } }
.bp-frame { position: relative; border: 1px solid var(--border-strong); border-radius: var(--r-md); overflow: hidden; background: var(--bg); min-height: 190px; }
.bp-caption { position: absolute; right: 6px; bottom: 6px; z-index: 1; font-size: 10px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--text-3); background: var(--surface-2); padding: 2px 6px; border-radius: var(--r-full); }
.bp-app { display: grid; grid-template-columns: 38% 1fr; height: 100%; min-height: 190px; font-size: 10px; }
.bp-side { background: var(--surface-1); border-right: 1px solid var(--border); padding: 8px 6px; display: grid; align-content: start; gap: 3px; }
.bp-brand { display: flex; align-items: center; gap: 5px; padding: 2px 2px 8px; min-width: 0; }
.bp-logo { width: 22px; height: 22px; object-fit: contain; flex: none; }
.bp-name { font: 700 11px var(--font-display); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bp-nav { display: flex; align-items: center; gap: 5px; padding: 4px 5px; border-radius: 5px; color: var(--text-2); }
.bp-nav.active { background: var(--accent-soft); color: var(--accent-text); font-weight: 700; }
.bp-dot { width: 7px; height: 7px; border-radius: 2px; background: currentColor; opacity: .7; }
.bp-main { padding: 8px; display: grid; align-content: start; gap: 8px; }
.bp-head { display: flex; justify-content: space-between; align-items: center; gap: 6px; }
.bp-head strong { font: 700 12px var(--font-display); }
.bp-btn { background: var(--accent); color: var(--on-accent); border-radius: 5px; padding: 3px 6px; font-weight: 700; white-space: nowrap; }
.bp-btn.wide { text-align: center; padding: 5px; }
.bp-cal { display: grid; gap: 4px; padding: 6px; border: 1px solid var(--border); border-radius: 6px; background: var(--surface-1); min-height: 100px; align-content: start; }
.bp-event { border-left: 3px solid var(--accent); background: var(--accent-soft); padding: 3px 5px; border-radius: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bp-event.alt { border-left-color: var(--info); background: var(--info-soft); }
.bp-login { height: 100%; min-height: 190px; display: grid; place-items: center; padding: 12px;
  background: radial-gradient(120% 90% at 0% 100%, color-mix(in srgb, var(--accent) 22%, transparent), transparent 60%), var(--brand-bg); }
.bp-login-card { width: 100%; max-width: 150px; display: grid; justify-items: center; gap: 5px; padding: 10px; border-radius: 8px; background: color-mix(in srgb, var(--surface-1) 88%, transparent); border: 1px solid var(--border-strong); }
.bp-login-card .bp-logo { width: 48px; height: 48px; }
.bp-login-title { font: 700 11px var(--font-display); text-align: center; }
.bp-input { width: 100%; height: 10px; border-radius: 3px; background: var(--surface-2); border: 1px solid var(--border); }
.bp-login .bp-btn { width: 100%; font-size: 10px; }

/* ---------- Reports ---------- */
.sidebar-stats { margin-top: var(--s-3); padding: var(--s-2) var(--s-2) var(--s-3); border: 1px solid var(--border); border-radius: var(--r-md); background: var(--surface-2); display: grid; gap: 4px; }
.sidebar-stats .nav-group { padding: 0 0 var(--s-1); }
.sidebar-stats .btn { margin-top: var(--s-2); width: 100%; }
.mini-stat { display: flex; justify-content: space-between; gap: var(--s-2); font-size: var(--fs-sm); color: var(--text-2); }
.mini-stat strong { color: var(--text); font-variant-numeric: tabular-nums; }
@media (max-width: 760px) { .sidebar-stats { display: none; } }
.date-range { display: flex; align-items: center; gap: var(--s-2); }
.date-range .input { width: auto; padding: 6px 8px; }
.share-cell { width: 22%; min-width: 80px; }
.share { display: block; height: 8px; border-radius: 0 4px 4px 0; background: var(--accent); opacity: .85; min-width: 2px; }
.chart-wrap { position: relative; }
.day-chart { width: 100%; height: auto; display: block; overflow: visible; }
.day-chart .grid { stroke: var(--border); stroke-width: 1; }
.day-chart .axis { fill: var(--text-3); font: 10px var(--font-body); }
.day-chart .bar { fill: var(--accent); opacity: .85; }
.day-chart .bar.on { opacity: 1; filter: drop-shadow(0 0 6px var(--accent-ring)); }
.day-chart .hit { fill: transparent; cursor: default; }
.chart-tip { position: absolute; top: 0; transform: translateX(-50%); display: grid; gap: 2px; padding: 6px 10px; border-radius: var(--r-md);
  background: var(--surface-3); border: 1px solid var(--border-strong); box-shadow: var(--shadow-pop); font-size: var(--fs-sm); pointer-events: none; white-space: nowrap; }
dialog.modal.report-modal { width: min(920px, calc(100vw - 32px)); }
.report-frame { width: 100%; height: 70vh; border: 1px solid var(--border); border-radius: var(--r-md); background: #fff; }
.danger-box { border: 1px solid color-mix(in srgb, var(--danger) 45%, transparent); background: var(--danger-soft); border-radius: var(--r-md); padding: var(--s-3) var(--s-4); }
.danger-box p { margin: 0 0 var(--s-2); } .danger-box ul { margin: 0 0 var(--s-2); padding-left: var(--s-5); color: var(--text-2); }

/* ---------- WhatsApp QR ---------- */
.qr-box { display: grid; justify-items: center; gap: var(--s-3); text-align: center; }
.qr { width: 264px; height: 264px; background: #fff; padding: 8px; border-radius: var(--r-md); image-rendering: pixelated; }
.qr-steps { text-align: left; color: var(--text-2); font-size: var(--fs-sm); margin: 0; padding-left: var(--s-5); }

/* ---------- Client's appointment page (Step 9, /agendamento/<token>): public, no login ---------- */
.public-card { width: min(440px, 100%); }
.public-card h1 { margin-bottom: var(--s-4); }
.public-card .appt-detail { margin-bottom: var(--s-5); }
.public-card .appt-detail-head h3 { font-size: var(--fs-lg); }
.public-actions { display: grid; gap: var(--s-3); }
.public-actions .btn { width: 100%; height: 44px; }
.public-cancel summary { list-style: none; cursor: pointer; }
.public-cancel summary::-webkit-details-marker { display: none; }
.public-cancel[open] summary { display: none; }
.public-cancel form { display: grid; gap: var(--s-3); }
.notice { border-radius: var(--r-md); padding: var(--s-3) var(--s-4); margin-bottom: var(--s-4); font-size: var(--fs-sm); background: var(--surface-3); color: var(--text); }
.notice-success { background: var(--success-soft); color: var(--success); }
.notice-danger { background: var(--danger-soft); color: var(--danger); }
.notif-list { display: grid; gap: var(--s-2); }
.notif-row { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--s-3); padding: var(--s-2) 0; border-bottom: 1px solid var(--border); }
.notif-row:last-child { border-bottom: 0; }
.public-whatsapp { width: 100%; height: 44px; margin-top: var(--s-4); text-decoration: none; }

/* ---------- Conversations (Step 10) ---------- */
.inbox { display: grid; grid-template-columns: minmax(260px, 340px) minmax(0, 1fr); gap: var(--s-5); align-items: start; }
.inbox-list { display: grid; gap: var(--s-3); padding: var(--s-4); }
.inbox-list .segmented { justify-self: start; flex-wrap: wrap; }
.conv-items { display: grid; gap: 2px; max-height: 66vh; overflow-y: auto; margin: 0 calc(-1 * var(--s-2)); }
.conv-item { display: grid; gap: 4px; text-align: left; width: 100%; padding: var(--s-3); border: 1px solid transparent; border-radius: var(--r-md); background: none; color: var(--text); font: inherit; cursor: pointer; }
.conv-item:hover { background: var(--surface-2); }
.conv-item.active { background: var(--accent-soft); border-color: var(--accent-ring); }
.conv-top { display: flex; justify-content: space-between; gap: var(--s-2); }
.conv-top strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-preview { color: var(--text-2); font-size: var(--fs-sm); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-badges { display: flex; gap: var(--s-2); flex-wrap: wrap; }
.inbox-thread { display: grid; gap: var(--s-3); min-height: 60vh; }
.thread-head { display: flex; justify-content: space-between; align-items: flex-start; gap: var(--s-3); flex-wrap: wrap; }
.thread-actions { display: flex; align-items: center; gap: var(--s-2); flex-wrap: wrap; }
.thread-log { height: 54vh; min-height: 300px; overflow-y: auto; display: flex; flex-direction: column; gap: var(--s-2); padding: var(--s-4); background: var(--chat-bg); border: 1px solid var(--border); border-radius: var(--r-md); }
.msg { max-width: 78%; padding: 8px 12px 6px; border-radius: 12px; line-height: 1.45; }
.msg.from-client { align-self: flex-start; background: var(--surface-3); border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.msg.from-us { align-self: flex-end; background: var(--bubble-in); border-bottom-right-radius: 4px; }
.msg.from-us.staff { box-shadow: inset 0 0 0 1px var(--accent-ring); }
.msg.from-us.system { background: var(--surface-2); border: 1px dashed var(--border-strong); }
.msg-who { font-size: var(--fs-xs); font-weight: 700; color: var(--accent-text); margin-bottom: 2px; }
.msg-body { white-space: pre-wrap; overflow-wrap: anywhere; }
.msg-time { font-size: var(--fs-xs); color: var(--text-3); text-align: right; margin-top: 2px; }
.chat-day { align-self: center; font-size: var(--fs-xs); color: var(--text-3); text-transform: capitalize; padding: var(--s-2) 0; }
.ai-steps { align-self: flex-end; max-width: 78%; font-size: var(--fs-sm); color: var(--text-2); }
.ai-steps > summary { cursor: pointer; display: inline-flex; align-items: center; gap: var(--s-2); list-style: none; }
.ai-steps > summary::-webkit-details-marker { display: none; }
.ai-steps .steps { margin-top: var(--s-2); padding: var(--s-2) var(--s-3); background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--r-md); }
.composer { display: flex; gap: var(--s-2); align-items: flex-end; }
.composer .textarea { min-height: 44px; }
.composer .btn { height: 44px; }
.nav-count { margin-left: auto; min-width: 20px; height: 20px; padding: 0 6px; border-radius: var(--r-full); background: var(--warning); color: #111; font-size: var(--fs-xs); font-weight: 700; display: inline-grid; place-items: center; }
.table tr.clickable { cursor: pointer; }
.audit-detail td { background: var(--surface-2); }
.audit-detail .steps { margin-bottom: var(--s-3); }
@media (max-width: 900px) { .inbox { grid-template-columns: 1fr; } .conv-items { max-height: 40vh; } }
.conv-item { grid-template-columns: auto minmax(0, 1fr); align-items: start; column-gap: var(--s-3); }
.conv-text { display: grid; gap: 4px; min-width: 0; }
.avatar-photo { width: 36px; height: 36px; border-radius: 50%; object-fit: cover; flex: none; display: inline-grid; place-items: center; background: var(--surface-3); color: var(--text-2); font-weight: 700; border: 1px solid var(--border); }
.avatar-photo.lg { width: 48px; height: 48px; font-size: var(--fs-lg); }
.thread-who { display: flex; align-items: center; gap: var(--s-3); min-width: 0; }

/* ---------- Meta message templates (WhatsApp → Modelos) ---------- */
.tpl-list { display: grid; gap: var(--s-2); margin-top: var(--s-3); }
.tpl-row { border: 1px solid var(--border); border-radius: var(--r-md); padding: var(--s-2) var(--s-3); }
.tpl-row summary { display: flex; align-items: center; gap: var(--s-2); cursor: pointer; list-style: none; flex-wrap: wrap; }
.tpl-row summary::-webkit-details-marker { display: none; }
.tpl-body { white-space: pre-wrap; font: var(--fs-sm)/1.5 var(--font-body); background: var(--surface-2); border-radius: var(--r-md); padding: var(--s-3); margin: var(--s-2) 0 0; }
