/* ==========================================================================
   CareCentriq — Design System
   Tablet-first, glove-friendly (primary targets >=48px, all interactive >=44px),
   WCAG 2.1 AA verified (contrast >=4.5:1 for text — see docs in commit message).
   Zero-egress: system fonts + inline SVG only. No CDN, no web fonts.
   ========================================================================== */

/* ---- 1. Design tokens ---------------------------------------------------- */
:root {
  /* Neutral scale */
  --n-0:#ffffff; --n-25:#f8fafb; --n-50:#f4f6f9; --n-100:#eef2f6;
  --n-200:#e2e8ee; --n-300:#d3dce3; --n-400:#b6c2cc; --n-500:#8a97a2;
  --n-600:#56646f; --n-700:#3a454f; --n-800:#232c34; --n-900:#16202b;

  /* Brand — Exentriq green-teal (logic-blue meets life-green). Verified >=4.5:1. */
  --brand-700:#0a4d45; --brand-600:#0a6459; --brand-500:#0c7a6e;
  --brand-100:#cfe9e3; --brand-50:#e9f5f2; --brand-ink:#7fd6c9;

  /* AI advisory (purple family — distinct from actionable brand) */
  --ai-700:#4a2b78; --ai-600:#5a3390; --ai-500:#6b3fa0;
  --ai-100:#efe7f8; --ai-50:#f7f3fc;

  /* Semantic */
  --danger-600:#8e1b16; --danger-500:#b3261e; --danger-100:#fbe9e7; --danger-50:#fdf3f2;
  --warn-600:#6f4a00;   --warn-500:#8a5e00;   --warn-100:#fbeecb;   --warn-50:#fdf6e3;
  --ok-600:#14532d;     --ok-500:#1d6f42;     --ok-100:#dff3e7;      --ok-50:#f2faf5;
  --info-600:#0b6ca8;   --info-100:#e3f1fb;

  /* Triage — Italian numeric convention (DM 70 / linee guida triage 5 codici) */
  --triage-1:#c0271d;  /* Codice 1 Rosso   — emergenza */
  --triage-2:#c25708;  /* Codice 2 Arancione — indifferibile */
  --triage-3:#0b6ca8;  /* Codice 3 Azzurro — differibile */
  --triage-4:#1d6f42;  /* Codice 4 Verde   — minore urgenza */
  --triage-5-ink:#2c3742; /* Codice 5 Bianco — non urgente (bordo) */

  /* Semantic surface roles */
  --bg:var(--n-50); --surface:var(--n-0); --surface-2:var(--n-100);
  --text:var(--n-900); --text-muted:var(--n-600); --text-invert:var(--n-0);
  --border:var(--n-300); --border-strong:var(--n-400);
  --primary:var(--brand-500); --primary-hover:var(--brand-600); --primary-ink:var(--n-0);
  --focus:#0d8577;

  /* Spacing scale (4px base) */
  --s-1:4px; --s-2:8px; --s-3:12px; --s-4:16px; --s-5:20px; --s-6:24px;
  --s-8:32px; --s-10:40px; --s-12:48px; --s-16:64px;

  /* Type scale */
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "SFMono-Regular", "Menlo", "Consolas", monospace;
  --t-xs:12px; --t-sm:13px; --t-base:15px; --t-md:16px; --t-lg:19px;
  --t-xl:23px; --t-2xl:28px;
  --lh:1.5;

  /* Radii */
  --r-sm:6px; --r-md:10px; --r-lg:14px; --r-pill:999px;

  /* Shadows */
  --sh-1:0 1px 2px rgba(16,32,43,.06), 0 1px 1px rgba(16,32,43,.04);
  --sh-2:0 2px 8px rgba(16,32,43,.08), 0 1px 2px rgba(16,32,43,.05);
  --sh-3:0 8px 28px rgba(16,32,43,.14);
  --sh-focus:0 0 0 3px rgba(13,133,119,.45);

  /* Motion */
  --ease:cubic-bezier(.2,.6,.2,1);
  --dur:.16s;
}

/* Dark mode — opt-in via prefers-color-scheme, overridable via [data-theme] */
@media (prefers-color-scheme: dark) {
  :root {
    --bg:#0f151b; --surface:#182029; --surface-2:#1f2932;
    --text:#e6edf3; --text-muted:#9fb0bd; --text-invert:#0f151b;
    --border:#2b3742; --border-strong:#3a4854;
    --primary:#3bb6a2; --primary-hover:#57c8b5; --primary-ink:#08201c;
    --focus:#4fd0bd;
    --brand-700:#0e3b35; --brand-600:#12554c; --brand-500:#3bb6a2;
    --brand-100:#12332e; --brand-50:#102421; --brand-ink:#7fd6c9;
    --ai-500:#c4a5e8; --ai-600:#d5bcf0; --ai-100:#241a33; --ai-50:#1c1526;
    --danger-500:#f2a099; --danger-600:#f7bdb7; --danger-100:#2e1715; --danger-50:#241413;
    --warn-500:#e6c265; --warn-600:#f0d488; --warn-100:#2a2211; --warn-50:#211b0f;
    --ok-500:#67c98d; --ok-600:#8ad9a9; --ok-100:#12291b; --ok-50:#0f2317;
    --info-600:#6fbbe8; --info-100:#132735;
    --triage-3:#2f92cf; --triage-5-ink:#c3ced8;
    --sh-1:0 1px 2px rgba(0,0,0,.4); --sh-2:0 2px 10px rgba(0,0,0,.5);
    --sh-3:0 10px 34px rgba(0,0,0,.6); --sh-focus:0 0 0 3px rgba(79,208,189,.5);
  }
}

/* ---- 2. Reset & base ----------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; font-family: var(--font); background: var(--bg); color: var(--text);
  font-size: var(--t-md); line-height: var(--lh);
  -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
}
main { max-width: 1120px; margin: 0 auto; padding: var(--s-6) var(--s-4) var(--s-16); }
h1 { font-size: var(--t-2xl); line-height: 1.2; margin: 0 0 var(--s-2); letter-spacing: -.01em; }
h2 { font-size: var(--t-xl); line-height: 1.25; margin: var(--s-8) 0 var(--s-3); letter-spacing: -.01em; }
h3 { font-size: var(--t-md); margin: 0 0 var(--s-2); }
p  { margin: var(--s-2) 0; }
a  { color: var(--primary); text-underline-offset: 2px; }
code { font-family: var(--mono); font-size: .92em; background: var(--surface-2);
       padding: 1px 6px; border-radius: var(--r-sm); }
small { font-size: var(--t-sm); }
svg.ico { width: 1.15em; height: 1.15em; fill: none; stroke: currentColor;
          stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
          vertical-align: -.18em; flex: none; }

/* Accessible focus ring everywhere */
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: var(--r-sm); }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
.skip-link { position: absolute; left: -999px; top: 0; z-index: 100;
  background: var(--surface); color: var(--text); padding: var(--s-3) var(--s-4);
  border-radius: 0 0 var(--r-md) 0; box-shadow: var(--sh-2); font-weight: 700; }
.skip-link:focus { left: 0; }

/* ---- 3. App shell / topbar ---------------------------------------------- */
.topbar {
  background: var(--brand-700); color: #fff;
  padding: var(--s-3) var(--s-5); display: flex; align-items: center;
  justify-content: space-between; gap: var(--s-4); flex-wrap: wrap;
  box-shadow: var(--sh-2); position: sticky; top: 0; z-index: 20;
}
/* "Structured intelligence in motion" — a restrained teal flow accent under the
   topbar. Decorative only; no glow on clinical surfaces. */
.topbar::after {
  content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 3px;
  background: linear-gradient(90deg, var(--brand-500), var(--brand-ink) 38%,
              rgba(127,214,201,0) 78%);
}
.brand { display: flex; align-items: center; gap: var(--s-3);
         font-size: var(--t-xl); font-weight: 800; letter-spacing: -.02em; }
.brand .logo { width: 30px; height: 30px; }
.brand b { font-weight: 800; } .brand span { color: var(--brand-ink); }
.brand small { font-weight: 500; opacity: .75; font-size: var(--t-xs);
               border: 1px solid #ffffff40; padding: 2px 7px; border-radius: var(--r-pill); }
.who { display: flex; align-items: center; gap: var(--s-3); flex-wrap: wrap; }
.who .op-id { display: flex; align-items: center; gap: var(--s-2); font-weight: 700; }
.who .op-id svg { width: 20px; height: 20px; }
nav.main-nav { display: flex; gap: 2px; flex-wrap: wrap; }
nav.main-nav a {
  color: #cdeae4; text-decoration: none; font-weight: 600; font-size: var(--t-base);
  display: inline-flex; align-items: center; gap: 6px;
  padding: 10px 12px; min-height: 44px; border-radius: var(--r-md);
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}
nav.main-nav a:hover { background: #ffffff1f; color: #fff; }
nav.main-nav a.exit { color: var(--brand-ink); }

/* ---- 4. Badges & pills --------------------------------------------------- */
.badge { display: inline-flex; align-items: center; gap: 5px; border-radius: var(--r-pill);
  padding: 4px 11px; font-size: var(--t-sm); font-weight: 700; line-height: 1.3; }
.badge.role { background: #ffffff26; color: #fff; }
.badge.dept { background: var(--brand-ink); color: var(--brand-700); }
.pill { display: inline-flex; align-items: center; gap: 5px; border-radius: var(--r-pill);
  padding: 4px 12px; font-weight: 700; font-size: var(--t-sm); line-height: 1.35;
  white-space: nowrap; }
.pill svg { width: 15px; height: 15px; }

/* Triage codes — Italian numeric convention */
.triage-1 { background: var(--triage-1); color: #fff; }
.triage-2 { background: var(--triage-2); color: #fff; }
.triage-3 { background: var(--triage-3); color: #fff; }
.triage-4 { background: var(--triage-4); color: #fff; }
.triage-5 { background: var(--surface); color: var(--triage-5-ink);
            border: 2px solid var(--border-strong); }

/* Risk classes */
.risk-Alto_Rischio, .risk-Stupefacente { background: var(--danger-100); color: var(--danger-600); }
.risk-LASA { background: var(--warn-100); color: var(--warn-600); }
.risk-Standard { background: var(--surface-2); color: var(--text-muted); }
.pill.ai-confirmed { background: var(--ai-100); color: var(--ai-600); }
.pill.nn { background: var(--warn-100); color: var(--warn-600); }
.pill.info { background: var(--info-100); color: var(--info-600); }

/* State labels */
.state { font-weight: 700; }
.state.Bozza, .state.Prescritta { color: var(--warn-600); }
.state.Firmata, .state.Validata, .state.Confermata { color: var(--ok-600); }

/* ---- 5. Cards ------------------------------------------------------------ */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg);
  padding: var(--s-5); margin: var(--s-4) 0; box-shadow: var(--sh-1);
}
.card h2:first-child, .card h3:first-child { margin-top: 0; }
.card.pad-sm { padding: var(--s-4); }
.section-head { display: flex; align-items: center; justify-content: space-between;
  gap: var(--s-3); flex-wrap: wrap; }
.eyebrow { display: inline-flex; align-items: center; gap: 6px; font-size: var(--t-xs);
  font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--text-muted); }

/* ---- 6. Buttons ---------------------------------------------------------- */
button, .btn {
  --btn-bg: var(--primary); --btn-fg: var(--primary-ink); --btn-bd: transparent;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  background: var(--btn-bg); color: var(--btn-fg); border: 2px solid var(--btn-bd);
  border-radius: var(--r-md); padding: 12px 20px; min-height: 48px; min-width: 48px;
  font-family: inherit; font-size: var(--t-md); font-weight: 700; line-height: 1.1;
  cursor: pointer; text-decoration: none; text-align: center;
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease),
              box-shadow var(--dur) var(--ease), transform var(--dur) var(--ease);
}
button:hover, .btn:hover { background: var(--primary-hover); }
button:active, .btn:active { transform: translateY(1px); }
button svg, .btn svg { width: 20px; height: 20px; }

.btn.secondary, button.secondary {
  --btn-bg: var(--surface); --btn-fg: var(--primary); --btn-bd: var(--primary); }
.btn.secondary:hover, button.secondary:hover { background: var(--brand-50); }

.btn.ghost, button.ghost {
  --btn-bg: transparent; --btn-fg: var(--text); --btn-bd: var(--border-strong); }
.btn.ghost:hover, button.ghost:hover { background: var(--surface-2); }

.btn.danger, button.danger {
  --btn-bg: var(--danger-500); --btn-fg: #fff; --btn-bd: transparent; }
.btn.danger:hover, button.danger:hover { background: var(--danger-600); }

.btn.ai, button.ai {
  --btn-bg: var(--ai-500); --btn-fg: #fff; --btn-bd: transparent; }
.btn.ai:hover, button.ai:hover { background: var(--ai-600); }
/* Dark mode: ai-500 lightens to a text tone, so keep the AI button a solid mid
   purple with white text (verified 5.88:1) rather than white on a pale fill. */
@media (prefers-color-scheme: dark) {
  .btn.ai, button.ai { --btn-bg: #7a4fb0; --btn-fg: #fff; }
  .btn.ai:hover, button.ai:hover { background: #8d61c4; }
}

/* Equal-weight decision buttons — accept & reject share size/shape, differ only
   in colour. No dark pattern: rejecting AI is as easy as accepting. */
.btn.accept, button.accept {
  --btn-bg: var(--surface); --btn-fg: var(--ok-600); --btn-bd: var(--ok-500); }
.btn.accept:hover, button.accept:hover { background: var(--ok-50); }
.btn.reject, button.reject {
  --btn-bg: var(--surface); --btn-fg: var(--danger-600); --btn-bd: var(--danger-500); }
.btn.reject:hover, button.reject:hover { background: var(--danger-50); }
.decision-row { display: flex; gap: var(--s-3); flex-wrap: wrap; margin-top: var(--s-3); }
.decision-row button, .decision-row .btn { flex: 1 1 200px; }

.btn-row { display: flex; flex-wrap: wrap; gap: var(--s-3); align-items: center;
           margin: var(--s-4) 0 0; }

/* ---- 7. Forms ------------------------------------------------------------ */
label { display: block; font-weight: 700; margin: var(--s-4) 0 var(--s-2);
        font-size: var(--t-base); color: var(--text); }
input, select, textarea {
  font-family: inherit; font-size: var(--t-md); color: var(--text);
  padding: 12px 14px; border: 1.5px solid var(--border-strong); border-radius: var(--r-md);
  width: 100%; min-height: 48px; background: var(--surface);
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--focus); box-shadow: var(--sh-focus); }
input::placeholder, textarea::placeholder { color: var(--n-500); }
textarea { min-height: 108px; resize: vertical; line-height: 1.5; }
select {
  appearance: none; -webkit-appearance: none; padding-right: 42px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 24 24' fill='none' stroke='%2356646f' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center;
}
.row { display: flex; gap: var(--s-4); flex-wrap: wrap; }
.row > div { flex: 1; min-width: 130px; }
form.inline { display: inline; }

/* Choice controls — checkbox / radio rendered as tappable option rows */
.choice { display: flex; align-items: flex-start; gap: var(--s-3);
  padding: 14px 16px; margin: var(--s-2) 0; border: 1.5px solid var(--border);
  border-radius: var(--r-md); background: var(--surface); font-weight: 600;
  cursor: pointer; min-height: 48px; transition: border-color var(--dur) var(--ease),
  background var(--dur) var(--ease); }
.choice:hover { border-color: var(--border-strong); background: var(--surface-2); }
.choice:focus-within { border-color: var(--focus); box-shadow: var(--sh-focus); }
.choice input { width: 22px; height: 22px; min-height: 22px; flex: none; margin-top: 1px;
  accent-color: var(--primary); cursor: pointer; }
.choice.accept:has(input:checked) { border-color: var(--ok-500); background: var(--ok-50); }
.choice.reject:has(input:checked) { border-color: var(--danger-500); background: var(--danger-50); }
.choice .lead { display: block; }
.choice .sub  { display: block; font-weight: 500; font-size: var(--t-sm); color: var(--text-muted); }

/* ---- 8. Tables ----------------------------------------------------------- */
.table-wrap { overflow-x: auto; border-radius: var(--r-md);
  -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; background: var(--surface); font-size: var(--t-base); }
caption { text-align: left; }
thead th, table > tr:first-child th { position: sticky; top: 0; z-index: 1; }
th {
  text-align: left; padding: 11px 14px; background: var(--surface-2);
  font-size: var(--t-xs); font-weight: 700; text-transform: uppercase;
  letter-spacing: .04em; color: var(--text-muted); white-space: nowrap;
  border-bottom: 1px solid var(--border); }
td { text-align: left; padding: 12px 14px; border-bottom: 1px solid var(--border);
     vertical-align: middle; }
tbody tr:last-child td, table > tr:last-child td { border-bottom: 0; }
tr.clickable:hover { background: var(--brand-50); cursor: pointer; }
tbody tr:hover { background: var(--n-25); }
@media (prefers-color-scheme: dark) { tbody tr:hover { background: var(--surface-2); } }
a.rowlink { color: var(--primary); font-weight: 700; text-decoration: none;
  display: inline-flex; align-items: center; gap: 4px; min-height: 44px; }
a.rowlink:hover { text-decoration: underline; }
a.rowlink svg { width: 16px; height: 16px; }
.mono-time { font-variant-numeric: tabular-nums; color: var(--text-muted); white-space: nowrap; }

/* ---- 9. Alerts / callouts ------------------------------------------------ */
.alert { border: 1px solid var(--border); border-left: 5px solid var(--border-strong);
  border-radius: var(--r-md); padding: var(--s-4) var(--s-5); margin: var(--s-4) 0;
  display: flex; gap: var(--s-3); box-shadow: var(--sh-1); }
.alert svg { flex: none; width: 22px; height: 22px; margin-top: 1px; }
.alert h2, .alert h3 { margin-top: 0; }
.alert.warn { background: var(--warn-50); border-left-color: var(--warn-500); color: var(--warn-600); }
.alert.danger { background: var(--danger-50); border-left-color: var(--danger-500); color: var(--danger-600); }
.alert.ok { background: var(--ok-50); border-left-color: var(--ok-500); color: var(--ok-600); }
.alert.info { background: var(--brand-50); border-left-color: var(--primary); color: var(--text); }
.alert .alert-body { color: var(--text); }
.alert.warn .alert-body strong, .alert.danger .alert-body strong { color: inherit; }

/* Legacy hooks kept for compatibility */
.warn { border-left: 5px solid var(--danger-500); background: var(--danger-50); }
.ok { border-left: 5px solid var(--ok-500); background: var(--ok-50); }
.muted { color: var(--text-muted); font-size: var(--t-base); }
.error { color: var(--danger-500); font-weight: 700; }

/* ---- 10. AI advisory card ------------------------------------------------ */
.ai-card {
  background: linear-gradient(180deg, var(--ai-50), var(--surface) 60%);
  border: 1px solid var(--ai-100); border-left: 5px solid var(--ai-500);
  border-radius: var(--r-lg); padding: var(--s-5); margin: var(--s-4) 0;
  box-shadow: var(--sh-1); }
.ai-card .ai-head { display: flex; align-items: center; gap: var(--s-2);
  color: var(--ai-600); font-weight: 800; font-size: var(--t-md); margin-bottom: var(--s-2); }
.ai-card .ai-head svg { width: 22px; height: 22px; }
.ai-card .ai-tag { margin-left: auto; font-size: var(--t-xs); font-weight: 700;
  text-transform: uppercase; letter-spacing: .05em; background: var(--ai-100);
  color: var(--ai-600); padding: 3px 9px; border-radius: var(--r-pill); }
.ai-card h3 { color: var(--ai-600); }
.ai-card .modello { font-size: var(--t-sm); color: var(--text-muted);
  border-top: 1px dashed var(--ai-100); padding-top: var(--s-3); margin-top: var(--s-3); }
.ai-card .modello code { background: var(--ai-100); color: var(--ai-600); }
.ai-nested { background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-md); padding: var(--s-4); margin: var(--s-3) 0; box-shadow: var(--sh-1); }
.ai-region-label { display: flex; align-items: center; gap: var(--s-2); }

/* ---- 11. Patient identity banner (wrong-patient prevention) ------------- */
.patient-banner {
  display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-4) var(--s-6);
  background: var(--surface); border: 1px solid var(--border);
  border-top: 4px solid var(--primary); border-radius: var(--r-lg);
  padding: var(--s-4) var(--s-5); margin: 0 0 var(--s-5); box-shadow: var(--sh-2); }
.patient-banner .pb-id { display: flex; align-items: center; gap: var(--s-3); }
.patient-banner .avatar { width: 46px; height: 46px; border-radius: 50%;
  background: var(--brand-100); color: var(--brand-500); display: flex;
  align-items: center; justify-content: center; flex: none; }
.patient-banner .avatar svg { width: 26px; height: 26px; }
.patient-banner .pb-name { font-size: var(--t-xl); font-weight: 800; line-height: 1.15;
  letter-spacing: -.01em; }
.patient-banner .pb-facts { display: flex; flex-wrap: wrap; gap: var(--s-2) var(--s-5);
  align-items: center; }
.pb-fact { display: flex; flex-direction: column; line-height: 1.25; }
.pb-fact .k { font-size: var(--t-xs); text-transform: uppercase; letter-spacing: .05em;
  color: var(--text-muted); font-weight: 700; }
.pb-fact .v { font-size: var(--t-base); font-weight: 700; font-variant-numeric: tabular-nums; }
.patient-banner.nn { border-top-color: var(--warn-500); }

/* ---- 12. Ward beds ------------------------------------------------------- */
.bed-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: var(--s-3); }
.bed { border: 1.5px solid var(--border); border-radius: var(--r-md);
  background: var(--surface); padding: var(--s-4); min-height: 118px;
  display: flex; flex-direction: column; gap: var(--s-1); box-shadow: var(--sh-1); }
.bed .bed-loc { display: flex; align-items: center; gap: 7px; font-weight: 800;
  font-size: var(--t-base); }
.bed .bed-loc svg { width: 18px; height: 18px; color: var(--text-muted); }
.bed.occupied { border-color: var(--primary); border-left: 4px solid var(--primary);
  background: var(--brand-50); }
.bed .bed-pt { font-weight: 700; margin-top: 2px; }
.bed .bed-free { color: var(--text-muted); font-weight: 600; margin-top: auto; }
.bed a.rowlink { margin-top: auto; }

/* ---- 13. Empty state ----------------------------------------------------- */
.empty { text-align: center; color: var(--text-muted); padding: var(--s-10) var(--s-4); }
.empty svg { width: 40px; height: 40px; opacity: .5; margin-bottom: var(--s-2); }
td.empty { text-align: center; }

/* ---- 14. Login ----------------------------------------------------------- */
.auth-wrap { position: relative; overflow: hidden;
  min-height: calc(100vh - 64px); display: flex; align-items: center;
  justify-content: center; padding: var(--s-6) var(--s-4);
  background: linear-gradient(165deg, var(--brand-50), var(--bg) 58%); }
/* Soft Exentriq wave — flow motif, entry surface only */
.auth-wave { position: absolute; left: 0; right: 0; bottom: 0; width: 100%;
  height: 46vh; min-height: 260px; color: var(--brand-500); opacity: .12;
  pointer-events: none; z-index: 0; }
.auth-wave.two { color: var(--brand-ink); opacity: .16; height: 34vh; min-height: 190px; }
.login-box { position: relative; z-index: 1; max-width: 440px; width: 100%; }
.login-box .card { padding: var(--s-8) var(--s-6); }
.login-lede { color: var(--text-muted); font-size: var(--t-base); }
.demo-users { display: flex; flex-wrap: wrap; gap: 6px; margin-top: var(--s-2); }
.demo-users code { background: var(--surface-2); }

/* ---- 15. Footer ---------------------------------------------------------- */
.ai-footer { max-width: 1120px; margin: var(--s-10) auto 0; padding: var(--s-5) var(--s-4) var(--s-8);
  font-size: var(--t-sm); color: var(--text-muted); border-top: 1px solid var(--border);
  display: flex; gap: var(--s-3); align-items: flex-start; }
.ai-footer svg { width: 22px; height: 22px; flex: none; color: var(--ai-500); margin-top: 1px; }
.ai-footer code { background: var(--surface-2); }

/* ---- 16. Utilities & layout --------------------------------------------- */
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s-5); align-items: start; }
.stack > * + * { margin-top: var(--s-3); }
.page-head { margin-bottom: var(--s-5); }
.page-head .breadcrumb { margin-bottom: var(--s-3); }
.timeline-entry { border-left: 3px solid var(--border); padding-left: var(--s-4); }
.timeline-entry.signed { border-left-color: var(--ok-500); }
.timeline-entry.draft { border-left-color: var(--warn-500); }
@media (max-width: 820px) { .grid2 { grid-template-columns: 1fr; } }

/* ---- 17. Governance: agent registry & policy ---------------------------- */
.agent-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: var(--s-4); }
.agent-card { border: 1px solid var(--border); border-radius: var(--r-lg);
  background: var(--surface); box-shadow: var(--sh-1); overflow: hidden;
  display: flex; flex-direction: column; }
.agent-card .agent-head { display: flex; align-items: center; gap: var(--s-3);
  flex-wrap: wrap; padding: var(--s-4) var(--s-4) var(--s-3);
  border-bottom: 1px solid var(--border); }
.agent-card .agent-name { font-family: var(--mono); font-weight: 700;
  font-size: var(--t-base); }
.agent-card .agent-body { padding: var(--s-4); display: flex; flex-direction: column;
  gap: var(--s-3); flex: 1; }
.agent-card .finalita { color: var(--text); font-size: var(--t-base); margin: 0; }

/* Tier badge — visually tiered by risk/autonomy */
.tier { display: inline-flex; align-items: center; gap: 5px; border-radius: var(--r-sm);
  padding: 4px 10px; font-size: var(--t-xs); font-weight: 800; text-transform: uppercase;
  letter-spacing: .05em; white-space: nowrap; border: 1.5px solid transparent; }
.tier .n { font-size: var(--t-sm); }
.tier.t0 { background: var(--surface-2); color: var(--text-muted); border-color: var(--border-strong); }
.tier.t1 { background: var(--brand-50); color: var(--info-600); border-color: var(--info-600); }
.tier.t2 { background: var(--warn-50); color: var(--warn-600); border-color: var(--warn-500); }
.tier.t3 { background: var(--danger-50); color: var(--danger-600); border-color: var(--danger-500); }

.stato { display: inline-flex; align-items: center; gap: 5px; border-radius: var(--r-pill);
  padding: 3px 10px; font-size: var(--t-xs); font-weight: 700; margin-left: auto; }
.stato.Attivo { background: var(--ok-100); color: var(--ok-600); }
.stato.Sospeso { background: var(--warn-100); color: var(--warn-600); }
.stato.Ritirato { background: var(--surface-2); color: var(--text-muted); }

/* Envelope — the five control boundaries, scannable definition grid */
.envelope { border: 1px dashed var(--border-strong); border-radius: var(--r-md);
  padding: var(--s-3) var(--s-4); background: var(--surface-2); }
.envelope .env-title { display: flex; align-items: center; gap: 6px;
  font-size: var(--t-xs); font-weight: 800; text-transform: uppercase;
  letter-spacing: .05em; color: var(--text-muted); margin-bottom: var(--s-3); }
.env-row { display: grid; grid-template-columns: 124px 1fr; gap: var(--s-3);
  padding: var(--s-2) 0; border-top: 1px solid var(--border); align-items: baseline; }
.env-row:first-of-type { border-top: 0; }
.env-k { display: flex; align-items: center; gap: 6px; font-size: var(--t-sm);
  font-weight: 700; color: var(--text-muted); }
.env-k svg { width: 15px; height: 15px; flex: none; }
.env-v { font-size: var(--t-base); }
.env-num { font-variant-numeric: tabular-nums; font-weight: 800; }
.class-pills { display: flex; flex-wrap: wrap; gap: 5px; }
.cpill { display: inline-block; border-radius: var(--r-sm); padding: 2px 9px;
  font-size: var(--t-xs); font-weight: 700; background: var(--brand-50);
  color: var(--info-600); border: 1px solid var(--border); }
.cpill.escalate { background: var(--warn-50); color: var(--warn-600); }
.cpill.exec { background: var(--danger-50); color: var(--danger-600); }

/* Policy list */
.policy-list { display: grid; gap: var(--s-3); }
.policy-item { border: 1px solid var(--border); border-left: 4px solid var(--primary);
  border-radius: var(--r-md); padding: var(--s-4); background: var(--surface);
  box-shadow: var(--sh-1); }
.policy-item .policy-head { display: flex; align-items: center; gap: var(--s-3);
  flex-wrap: wrap; margin-bottom: var(--s-2); }
.policy-item .codice { font-family: var(--mono); font-weight: 700; font-size: var(--t-base); }
.policy-item .ver { font-size: var(--t-xs); color: var(--text-muted); font-weight: 700;
  background: var(--surface-2); padding: 2px 8px; border-radius: var(--r-pill); }
.appr { display: inline-flex; align-items: center; gap: 5px; margin-left: auto;
  font-size: var(--t-xs); font-weight: 700; padding: 3px 10px; border-radius: var(--r-pill);
  background: var(--ai-100); color: var(--ai-600); }
.policy-item .regola { margin-top: var(--s-3); font-family: var(--mono); font-size: var(--t-sm);
  color: var(--text-muted); background: var(--surface-2); border-radius: var(--r-sm);
  padding: var(--s-2) var(--s-3); overflow-x: auto; white-space: nowrap; }

/* ---- 18. Motion preferences --------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important; animation-iteration-count: 1 !important;
    transition-duration: .001ms !important; scroll-behavior: auto !important; }
}

/* ---- PRD-006: persistent chat launcher (bottom-right) ------------------- */
.chat-launcher { position: fixed; right: 20px; bottom: 20px; z-index: 40;
  display: inline-flex; align-items: center; gap: 8px; min-height: 48px;
  padding: 12px 18px; border-radius: var(--r-pill); text-decoration: none;
  background: var(--ai-500); color: #fff; font-weight: 700; box-shadow: var(--sh-3); }
.chat-launcher:hover { background: var(--ai-600); }
.chat-launcher svg { width: 20px; height: 20px; }
@media (prefers-color-scheme: dark) { .chat-launcher { color: var(--ai-50); } }

/* ---- PRD-006: right-docked assistant panel ----------------------------- */
/* Scoped to the chat page via :has() so no other page is affected. The panel
   reads as an overlay docked over the workspace; base footer + launcher hidden. */
body:has(.chat-shell) { display: flex; flex-direction: column; min-height: 100vh; }
body:has(.chat-shell) .ai-footer,
body:has(.chat-shell) .chat-launcher { display: none; }
main:has(.chat-shell) { flex: 1 1 auto; max-width: none; width: 100%;
  margin: 0; padding: 0; min-height: 0; display: flex; }
.chat-shell { flex: 1 1 auto; display: flex; width: 100%; min-height: 0; }

/* Left backdrop — makes the panel feel like an overlay over the workspace.
   The whole scrim is a link back to work (click-outside-to-dismiss pattern). */
.chat-scrim { flex: 1 1 auto; position: relative; display: block;
  text-decoration: none; color: var(--text);
  background: linear-gradient(160deg, var(--brand-50), var(--bg) 60%); }
.chat-scrim .scrim-back { position: absolute; top: var(--s-6); left: var(--s-6);
  display: inline-flex; align-items: center; gap: 8px; min-height: 48px;
  padding: 12px 20px; border-radius: var(--r-pill); font-weight: 700;
  color: var(--primary); background: var(--surface);
  border: 1px solid var(--border); box-shadow: var(--sh-2); }
.chat-scrim:hover .scrim-back { background: var(--brand-50); }
.chat-scrim .scrim-hint { position: absolute; left: var(--s-6); bottom: var(--s-8);
  max-width: 380px; color: var(--text-muted); }
.chat-scrim .scrim-hint svg { width: 26px; height: 26px; color: var(--ai-500);
  opacity: .8; margin-bottom: var(--s-2); }

/* The docked panel */
.chat-panel { flex: 0 0 clamp(440px, 34vw, 520px); display: flex; flex-direction: column;
  min-height: 0; background: var(--surface); border-left: 1px solid var(--border);
  box-shadow: -8px 0 28px rgba(16,32,43,.10); }
@media (prefers-color-scheme: dark) { .chat-panel { box-shadow: -8px 0 28px rgba(0,0,0,.5); } }

/* ---- App-wide assistant drawer (overlays the current page) --------------- */
.chat-drawer { position: fixed; inset: 0; z-index: 60; display: flex; }
.chat-drawer[hidden] { display: none; }
.chat-drawer-scrim { flex: 1 1 auto; background: rgba(16,32,43,.30);
  opacity: 0; transition: opacity var(--dur) var(--ease); }
.chat-drawer.open .chat-drawer-scrim { opacity: 1; }
.chat-drawer .chat-panel { flex: 0 0 clamp(420px, 38vw, 560px); height: 100vh;
  transform: translateX(100%); transition: transform .22s var(--ease);
  box-shadow: -12px 0 40px rgba(16,32,43,.22); }
.chat-drawer.open .chat-panel { transform: none; }
.chat-close { margin-left: auto; display: inline-flex; align-items: center; justify-content: center;
  width: 40px; height: 40px; border: 0; border-radius: var(--r-md); background: transparent;
  color: var(--text-muted); cursor: pointer; }
.chat-close:hover { background: var(--surface-2); color: var(--text); }
.chat-close svg { width: 20px; height: 20px; }
body.cce-chat-open .chat-launcher { opacity: 0; pointer-events: none; }
@media (prefers-reduced-motion: reduce) {
  .chat-drawer .chat-panel { transition: none; }
  .chat-drawer-scrim { transition: none; }
}
@media (max-width: 640px) {
  .chat-drawer .chat-panel { flex-basis: 100%; }
  .chat-drawer-scrim { display: none; }
}

/* React island mount fills the panel between header and provenance line */
.aui-mount { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; }

/* Context header — always visible (does not scroll with the log) */
.chat-head { flex: none; display: flex; align-items: center; gap: var(--s-2);
  padding: var(--s-3) var(--s-4) var(--s-2); }
.chat-head .back { display: inline-flex; align-items: center; gap: 6px; min-height: 44px;
  padding: 8px 10px; border-radius: var(--r-md); color: var(--primary); font-weight: 700;
  text-decoration: none; }
.chat-head .back:hover { background: var(--surface-2); }
.chat-title { display: inline-flex; align-items: center; gap: 7px; margin-left: auto;
  font-weight: 700; color: var(--text); }
.chat-title svg { width: 18px; height: 18px; color: var(--ai-500); }
.ctx-chip { display: inline-flex; align-items: center; gap: 7px; margin-left: auto;
  background: var(--brand-50); border: 1px solid var(--brand-100); color: var(--text);
  padding: 6px 10px 6px 12px; border-radius: var(--r-pill); font-size: var(--t-sm); font-weight: 700; }
.ctx-chip svg { width: 16px; height: 16px; color: var(--primary); flex: none; }
.ctx-chip.none { background: var(--surface-2); border-color: var(--border); color: var(--text-muted); }
.ctx-chip .detach { display: inline-flex; align-items: center; justify-content: center;
  width: 24px; height: 24px; margin-left: 3px; border-radius: 50%; border: 0;
  background: transparent; color: var(--text-muted); cursor: pointer; text-decoration: none; }
.ctx-chip .detach:hover { background: var(--brand-100); color: var(--text); }
.ctx-chip .detach svg { width: 14px; height: 14px; color: currentColor; }
/* Plain-language scope banner under the header (safety: which patient the AI sees) */
.chat-scope { flex: none; display: flex; align-items: flex-start; gap: 8px;
  margin: 0 var(--s-4) var(--s-3); padding: 9px 12px; border-radius: var(--r-md);
  background: var(--brand-50); border: 1px solid var(--brand-100);
  font-size: var(--t-sm); color: var(--text); line-height: 1.4; }
.chat-scope.none { background: var(--surface-2); border-color: var(--border); color: var(--text-muted); }
.chat-scope svg { width: 16px; height: 16px; color: var(--primary); flex: none; margin-top: 1px; }
.chat-scope.none svg { color: var(--text-muted); }
.chat-scope strong { font-weight: 700; }

/* Scrolling conversation */
.chat-log { flex: 1 1 auto; overflow-y: auto; padding: var(--s-4);
  display: flex; flex-direction: column; gap: var(--s-4); }
.msg { max-width: 88%; display: flex; flex-direction: column; gap: 4px; }
.msg .bubble { padding: 10px 14px; border-radius: var(--r-lg); white-space: pre-line;
  line-height: 1.5; }
.msg .meta { font-size: var(--t-xs); color: var(--text-muted);
  display: flex; align-items: center; gap: 6px; }
.msg .meta svg { width: 14px; height: 14px; color: var(--ai-500); flex: none; }
.msg .meta code { font-size: 11px; background: var(--surface-2); padding: 0 5px; }
.msg .time { font-variant-numeric: tabular-nums; }
.msg.user { align-self: flex-end; align-items: flex-end; }
.msg.user .bubble { background: var(--primary); color: #fff; border: 1px solid var(--primary);
  border-bottom-right-radius: var(--r-sm); }
.msg.bot { align-self: flex-start; }
.msg.bot .bubble { background: var(--ai-50); border: 1px solid var(--ai-100);
  border-left: 3px solid var(--ai-500);
  border-bottom-left-radius: var(--r-sm); box-shadow: var(--sh-1); }
.chat-empty { margin: auto; text-align: center; color: var(--text-muted); max-width: 340px; }
.chat-empty svg { width: 34px; height: 34px; color: var(--ai-500); opacity: .75; margin-bottom: var(--s-2); }

/* Sticky composer at the bottom of the panel */
.chat-composer { flex: none; border-top: 1px solid var(--border);
  padding: var(--s-3) var(--s-4) var(--s-4); background: var(--surface); }
.chat-composer .composer-row { display: flex; gap: var(--s-2); align-items: flex-end; }
.chat-composer textarea { min-height: 48px; max-height: 168px; }
.chat-composer .composer-row button { flex: none; min-width: 52px; padding: 12px 16px; }
.chat-prov { font-size: var(--t-xs); color: var(--text-muted); margin: var(--s-2) 0 0; }
.chat-prov code { font-size: 11px; }

@media (max-width: 820px) {
  .chat-scrim { display: none; }
  .chat-panel { flex: 1 1 auto; border-left: 0; box-shadow: none; }
}

/* ---- Rendered Markdown inside AI cards / diary --------------------------- */
.md-body { font-size: var(--t-base); line-height: 1.55; }
.md-body > :first-child { margin-top: 0; }
.md-body > :last-child { margin-bottom: 0; }
.md-body p { margin: 0 0 8px; }
.md-body h3, .md-body h4, .md-body h5 { margin: 12px 0 6px; line-height: 1.25; }
.md-body h3 { font-size: var(--t-md); }
.md-body h4 { font-size: var(--t-base); }
.md-body h5 { font-size: var(--t-sm); text-transform: uppercase; letter-spacing: .03em; color: var(--text-muted); }
.md-body ul, .md-body ol { margin: 6px 0 8px; padding-left: 22px; }
.md-body li { margin: 2px 0; }
.md-body hr { border: 0; border-top: 1px solid var(--border); margin: 12px 0; }
.md-body code { font-family: var(--mono); font-size: .9em; background: var(--surface-2); padding: 1px 5px; border-radius: var(--r-sm); }
.md-body strong { font-weight: 700; }
.md-body table { width: 100%; border-collapse: collapse; margin: 8px 0; font-size: var(--t-sm); }
.md-body th, .md-body td { text-align: left; padding: 6px 9px; border: 1px solid var(--border); }
.md-body th { background: var(--surface-2); }

/* ---- Page-wide progress bar + single-submit busy state ------------------- */
#cce-progress {
  position: fixed; top: 0; left: 0; height: 3px; width: 0;
  z-index: 200; pointer-events: none; opacity: 0;
  background: linear-gradient(90deg, var(--brand-500), var(--brand-ink), var(--brand-500));
  background-size: 200% 100%;
  box-shadow: 0 0 8px rgba(12,122,110,.5);
}
#cce-progress.active { opacity: 1;
  animation: cce-load 12s cubic-bezier(.15,.6,.3,1) forwards,
             cce-sheen 1.1s linear infinite; }
#cce-progress.active.done { animation: cce-finish .25s ease forwards; }
@keyframes cce-load { 0% { width: 6%; } 12% { width: 38%; } 40% { width: 68%; }
  100% { width: 92%; } }
@keyframes cce-sheen { 0% { background-position: 0% 0; } 100% { background-position: -200% 0; } }
@keyframes cce-finish { to { width: 100%; opacity: 0; } }
@media (prefers-color-scheme: dark) {
  #cce-progress { background: linear-gradient(90deg, var(--brand-500), var(--brand-ink)); }
}
/* Buttons/links become non-interactive once an action is in flight */
.is-busy, button:disabled { cursor: progress !important; opacity: .75; }
button.is-busy { position: relative; color: transparent !important; }
button.is-busy > * { visibility: hidden; }
button.is-busy::after { content: ""; position: absolute; inset: 0; margin: auto;
  width: 18px; height: 18px; border-radius: 50%;
  border: 2.5px solid rgba(255,255,255,.35); border-top-color: #fff;
  animation: cce-spin .7s linear infinite; }
@keyframes cce-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { #cce-progress { transition: opacity .2s ease; } }

/* Entity deep-links rendered inside AI suggestion cards */
.md-body a.cc-navlink { color: var(--ai-600); font-weight: 600; text-decoration: underline;
  text-underline-offset: 2px; }
.md-body a.cc-navlink:hover { color: var(--ai-700); }

/* Deep-link jump target emphasis (assistant links to a chart section) */
.cce-jump { animation: cce-jump-pulse 2.2s var(--ease); border-radius: var(--r-md); }
@keyframes cce-jump-pulse {
  0% { box-shadow: 0 0 0 3px var(--ai-500), 0 0 0 8px var(--ai-100); background: var(--ai-50); }
  100% { box-shadow: 0 0 0 0 transparent; background: transparent; }
}
@media (prefers-reduced-motion: reduce) { .cce-jump { animation: none; outline: 2px solid var(--ai-500); } }

/* ---- PRD-007: external longitudinal history panel ------------------------ */
.ext-list { list-style: none; margin: 0; padding: 0; }
.ext-list li { display: flex; flex-wrap: wrap; align-items: center; gap: 8px;
  padding: 7px 0; border-bottom: 1px solid var(--border); font-size: var(--t-base); }
.ext-list li:last-child { border-bottom: 0; }
.ext-desc { font-weight: 600; }
.src-badge { display: inline-flex; align-items: center; font-size: var(--t-xs); font-weight: 700;
  background: var(--info-100); color: var(--info-600); padding: 1px 8px; border-radius: var(--r-pill); }
.rel-badge { font-size: var(--t-xs); padding: 1px 7px; border-radius: var(--r-pill); }
.rel-verificata { background: var(--ok-100); color: var(--ok-600); }
.rel-riferita { background: var(--warn-100); color: var(--warn-600); }
.rel-non_verificata { background: var(--surface-2); color: var(--text-muted); }
.allergy-card { border-left: 4px solid var(--danger-500); background: var(--danger-50); }

/* ---- DAT-007 task board -------------------------------------------------- */
.task-card { border-left: 4px solid var(--border); }
.task-card.prio-urgente { border-left-color: var(--danger-500); }
.task-card.prio-alta { border-left-color: var(--warn-500); }
.task-card.prio-media { border-left-color: var(--info-600); }
.task-top { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.prio-badge { font-size: var(--t-xs); font-weight: 700; padding: 1px 8px; border-radius: var(--r-pill); }
.prio-badge.prio-urgente { background: var(--danger-100); color: var(--danger-600); }
.prio-badge.prio-alta { background: var(--warn-100); color: var(--warn-600); }
.prio-badge.prio-media { background: var(--info-100); color: var(--info-600); }
.prio-badge.prio-bassa { background: var(--surface-2); color: var(--text-muted); }

/* ---- UX-005 approval inbox ----------------------------------------------- */
.count-badge { font-size: var(--t-sm); font-weight: 700; background: var(--ai-100); color: var(--ai-600);
  padding: 1px 9px; border-radius: var(--r-pill); vertical-align: middle; }
.inbox-card { border-left: 3px solid var(--ai-500); }
.inbox-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 6px; font-size: var(--t-sm); }
.inbox-meta svg { width: 14px; height: 14px; }
.class-badge { font-size: var(--t-xs); font-weight: 700; padding: 1px 8px; border-radius: var(--r-pill);
  background: var(--surface-2); color: var(--text-muted); }
.class-badge.cls-recommend { background: var(--ai-100); color: var(--ai-600); }
.class-badge.cls-escalate { background: var(--danger-100); color: var(--danger-600); }
.class-badge.cls-prepare { background: var(--info-100); color: var(--info-600); }
.class-badge.cls-inform { background: var(--ok-100); color: var(--ok-600); }
.inbox-actions { margin-top: 10px; }
.inbox-note { width: 100%; margin-bottom: 8px; padding: 8px 12px; border: 1px solid var(--border);
  border-radius: var(--r-md); font: inherit; }
.btn-row button.ghost { background: var(--surface); color: var(--text); border: 1px solid var(--border); }
.btn-row button.ghost:hover { background: var(--surface-2); }
.btn-row button.ghost.danger { color: var(--danger-600); border-color: var(--danger-100);
  background: var(--surface); }
.btn-row button.ghost.danger:hover { background: var(--danger-50); }
.btn-row button.ok { background: var(--primary); }

/* ---- ED cockpit prediction badge + AI hint ------------------------------- */
.ai-hint { font-size: 10px; font-weight: 800; letter-spacing: .04em; background: var(--ai-500);
  color: #fff; padding: 0 5px; border-radius: var(--r-sm); vertical-align: middle; }
.pred-badge { font-weight: 700; font-size: var(--t-sm); padding: 2px 9px; border-radius: var(--r-pill); }
.pred-alta { background: var(--danger-100); color: var(--danger-600); }
.pred-moderata { background: var(--warn-100); color: var(--warn-600); }
.pred-bassa { background: var(--ok-100); color: var(--ok-600); }

/* ---- UX-004 command center ----------------------------------------------- */
.cc-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; margin: 16px 0; }
.cc-tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg);
  padding: 16px 18px; box-shadow: var(--sh-1); }
.cc-tile .cc-k { font-size: var(--t-sm); color: var(--text-muted); }
.cc-tile .cc-v { font-size: var(--t-2xl); font-weight: 800; line-height: 1.1; margin: 4px 0; }
.cc-tile .cc-sub { font-size: var(--t-xs); color: var(--text-muted); }
.cc-crowd.cc-alto { border-left: 5px solid var(--danger-500); }
.cc-crowd.cc-medio { border-left: 5px solid var(--warn-500); }
.cc-crowd.cc-basso { border-left: 5px solid var(--ok-500); }
.cc-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
@media (max-width: 900px) { .cc-cols { grid-template-columns: 1fr; } }
.bed-row { display: flex; align-items: center; gap: 12px; padding: 7px 0; border-bottom: 1px solid var(--border); }
.bed-row:last-child { border-bottom: 0; }
.bed-row > span:first-child { flex: 1; }
.bed-bar { flex: 2; height: 8px; background: var(--surface-2); border-radius: var(--r-pill); overflow: hidden; }
.bed-fill { display: block; height: 100%; background: var(--primary); }
.cc-signals { display: flex; gap: 24px; flex-wrap: wrap; }
.cc-signals .sig-n { font-size: var(--t-xl); font-weight: 800; display: block; }
.cc-signals .sig-esc { color: var(--danger-500); }

/* ---- IMP-016 traceability status badges ---------------------------------- */
.trace-badge { font-size: var(--t-xs); font-weight: 700; padding: 1px 8px; border-radius: var(--r-pill); }
.trace-done { background: var(--ok-100); color: var(--ok-600); }
.trace-partial { background: var(--warn-100); color: var(--warn-600); }
.trace-planned { background: var(--info-100); color: var(--info-600); }
.trace-gap { background: var(--surface-2); color: var(--text-muted); }

/* ---- model cards ---------------------------------------------------------- */
.mcard { display: grid; grid-template-columns: 160px 1fr; gap: 4px 16px; margin: 0; }
.mcard dt { font-weight: 700; color: var(--text-muted); font-size: var(--t-sm); }
.mcard dd { margin: 0; font-size: var(--t-sm); }
@media (max-width: 640px) { .mcard { grid-template-columns: 1fr; } .mcard dt { margin-top: 6px; } }

/* ---- DAMA (CLN-035) workflow box ----------------------------------------- */
.dama-box { margin-top: 10px; border: 1px solid var(--warn-100); border-radius: var(--r-md);
  background: var(--warn-50); padding: 8px 14px; }
.dama-box summary { cursor: pointer; font-weight: 700; color: var(--warn-600); }
.dama-box label { display: block; font-size: var(--t-sm); margin-top: 8px; }
.dama-box input[type=text] { width: 100%; padding: 8px 12px; border: 1px solid var(--border);
  border-radius: var(--r-md); font: inherit; margin-top: 3px; }
.dama-box .chk { display: flex; align-items: center; gap: 8px; }
.btn-row button.danger { background: var(--danger-500); color: #fff; border: 0; }
.btn-row button.danger:hover { background: var(--danger-600); color: #fff; }

/* ---- Patient search + error page ------------------------------------------ */
.search-row { display: flex; gap: 10px; }
.search-row input[type=search] { flex: 1; padding: 12px 16px; border: 1px solid var(--border);
  border-radius: var(--r-md); font: inherit; min-height: 48px; }
.search-row button { flex: none; }
.error-page { text-align: center; padding: 60px 20px; color: var(--text-muted); }
.error-page svg { width: 42px; height: 42px; color: var(--warn-500); }
.error-page h1 { font-size: 56px; margin: 8px 0; color: var(--text); }
.discharge-box { border-left: 4px solid var(--brand-500); margin-top: 12px; }

/* ---- Allergy safety strip under the patient banner ------------------------ */
.allergy-strip { display: flex; flex-wrap: wrap; align-items: center; gap: 8px;
  margin: 10px 0 4px; padding: 9px 14px; border-radius: var(--r-md);
  background: var(--danger-50); border: 1px solid var(--danger-100);
  border-left: 4px solid var(--danger-500); font-size: var(--t-sm); }
.allergy-strip > svg { color: var(--danger-500); width: 17px; height: 17px; }
.allergy-chip { display: inline-flex; align-items: center; gap: 6px; font-weight: 700;
  background: var(--surface); border: 1px solid var(--danger-100);
  padding: 2px 10px; border-radius: var(--r-pill); }

/* ---- Flash toast ----------------------------------------------------------- */
.cce-toast { position: fixed; left: 50%; bottom: 26px; transform: translate(-50%, 16px);
  z-index: 300; display: inline-flex; align-items: center; gap: 8px;
  background: var(--brand-700); color: #fff; font-weight: 600; font-size: var(--t-base);
  padding: 12px 22px; border-radius: var(--r-pill); box-shadow: var(--sh-3);
  opacity: 0; transition: opacity .25s ease, transform .25s ease; pointer-events: none; }
.cce-toast.show { opacity: 1; transform: translate(-50%, 0); }
.cce-toast svg { width: 18px; height: 18px; color: var(--brand-ink); }
@media (prefers-reduced-motion: reduce) { .cce-toast { transition: opacity .25s ease; } }

/* ---- CLN-006 administration timeline -------------------------------------- */
.somm-list { list-style: none; margin: 6px 0 0; padding: 6px 0 0; border-top: 1px dashed var(--border);
  font-size: var(--t-sm); }
.somm-list li { padding: 3px 0; display: flex; flex-wrap: wrap; align-items: center; gap: 7px; }
.somm-badge { font-size: var(--t-xs); font-weight: 700; padding: 1px 8px; border-radius: var(--r-pill); }
.somm-somministrata { background: var(--ok-100); color: var(--ok-600); }
.somm-omessa { background: var(--warn-100); color: var(--warn-600); }
.somm-rifiutata_paziente { background: var(--danger-100); color: var(--danger-600); }
.somm-programmata, .somm-ritardata { background: var(--surface-2); color: var(--text-muted); }
.somm-box { margin-top: 8px; border: 1px solid var(--border); border-radius: var(--r-md);
  padding: 6px 12px; background: var(--surface-2); }
.somm-box summary { cursor: pointer; font-weight: 600; font-size: var(--t-sm); }
.somm-box form { margin-top: 8px; }
.somm-box select, .somm-box input[type=text] { width: 100%; padding: 8px 10px;
  border: 1px solid var(--border); border-radius: var(--r-md); font: inherit; margin-top: 3px; }

/* ---- CLN-007 lab loop ------------------------------------------------------ */
.lab-result-row { display: flex; gap: 8px; margin-top: 8px; flex-wrap: wrap; }
.lab-result-row input[type=text] { flex: 1; min-width: 140px; padding: 9px 12px;
  border: 1px solid var(--border); border-radius: var(--r-md); font: inherit; }
.lab-result-row select { padding: 9px 12px; border: 1px solid var(--border);
  border-radius: var(--r-md); font: inherit; }
.lab-flag { font-size: var(--t-xs); font-weight: 700; padding: 1px 8px; border-radius: var(--r-pill); }
.lab-normale { background: var(--ok-100); color: var(--ok-600); }
.lab-alto, .lab-basso { background: var(--warn-100); color: var(--warn-600); }
.lab-critico_alto, .lab-critico_basso { background: var(--danger-100); color: var(--danger-600); }

/* ---- Top-right user menu ---------------------------------------------------- */
.user-menu { position: relative; }
.user-menu summary { list-style: none; cursor: pointer; display: inline-flex;
  align-items: center; gap: 8px; padding: 6px 12px 6px 6px; border-radius: var(--r-pill);
  background: #ffffff14; border: 1px solid #ffffff2a; color: #fff; font-weight: 700;
  min-height: 44px; }
.user-menu summary::-webkit-details-marker { display: none; }
.user-menu summary:hover { background: #ffffff24; }
.um-avatar { display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 32px; border-radius: 50%; background: var(--brand-500); }
.um-avatar svg { width: 18px; height: 18px; }
.um-caret { width: 14px; height: 14px; transform: rotate(90deg); opacity: .7;
  transition: transform var(--dur) var(--ease); }
.user-menu[open] .um-caret { transform: rotate(-90deg); }
.um-panel { position: absolute; right: 0; top: calc(100% + 8px); z-index: 60;
  min-width: 240px; background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--r-lg); box-shadow: var(--sh-3);
  padding: 14px; }
.um-id strong { font-size: var(--t-md); }
.um-badges { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.um-panel .badge.role { background: var(--surface-2); color: var(--text); }
.um-panel .badge.dept { background: var(--brand-100); color: var(--brand-700); }
.um-exit { display: inline-flex; align-items: center; gap: 8px; margin-top: 12px;
  padding: 10px 14px; width: 100%; border-radius: var(--r-md); text-decoration: none;
  font-weight: 700; color: var(--danger-600); background: var(--danger-50);
  border: 1px solid var(--danger-100); }
.um-exit:hover { background: var(--danger-100); }
@media (prefers-color-scheme: dark) {
  .um-panel .badge.dept { background: var(--brand-100); color: var(--brand-ink); }
}

@media (prefers-color-scheme: dark) {
  .btn-row button.danger { color: #2b0f0d; }
  .btn-row button.danger:hover { color: #2b0f0d; }
}

/* ---- 'La mia giornata' one-screen worklist -------------------------------- */
.day-grid { display: grid; grid-template-columns: 1.2fr 1fr; gap: 24px; }
@media (max-width: 900px) { .day-grid { grid-template-columns: 1fr; } }
a.day-card { display: block; text-decoration: none; color: var(--text);
  margin-bottom: 8px; transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease); }
a.day-card:hover { border-color: var(--brand-500); box-shadow: var(--sh-2); }
a.day-card.ai-edge { border-left: 3px solid var(--ai-500); }
.alert.danger { background: var(--danger-50); border: 1px solid var(--danger-100);
  border-left: 4px solid var(--danger-500); border-radius: var(--r-md);
  display: flex; gap: 10px; padding: 12px 16px; margin-bottom: 14px; }
.alert.danger > svg { color: var(--danger-500); flex: none; width: 20px; height: 20px; }

/* ---- Topbar omnibox + nav badges ------------------------------------------ */
.omnibox { display: inline-flex; align-items: center; gap: 6px; background: #ffffff14;
  border: 1px solid #ffffff2a; border-radius: var(--r-pill); padding: 4px 12px; }
.omnibox svg { width: 15px; height: 15px; color: #cdeae4; }
.omnibox input { background: transparent; border: 0; color: #fff; font: inherit;
  font-size: var(--t-sm); width: 150px; min-height: 34px; outline: none; }
.omnibox input::placeholder { color: #cdeae4aa; }
.omnibox:focus-within { background: #ffffff22; border-color: #ffffff55; }
@media (max-width: 1100px) { .omnibox input { width: 100px; } }
.nav-badge { display: inline-flex; align-items: center; justify-content: center;
  min-width: 18px; height: 18px; padding: 0 5px; margin-left: 5px;
  border-radius: var(--r-pill); background: var(--ai-500); color: #fff;
  font-size: 11px; font-weight: 800; }

/* ---- Clinical trend sparklines --------------------------------------------- */
.trend-strip { display: flex; flex-wrap: wrap; gap: 18px; margin-top: var(--s-4);
  padding: 10px 14px; background: var(--surface-2); border-radius: var(--r-md); }
.trend { display: flex; align-items: center; gap: 8px; }
.trend .k { font-size: var(--t-xs); font-weight: 700; color: var(--text-muted); min-width: 46px; }
.trend .v { font-weight: 800; font-variant-numeric: tabular-nums; }
svg.spark { display: block; }

/* ---- Smart phrases (documentation streamlining) ---------------------------- */
.phrase-row { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0 8px; }
.phrase-chip { font-size: var(--t-xs); font-weight: 600; padding: 5px 10px;
  border-radius: var(--r-pill); border: 1px solid var(--brand-100);
  background: var(--brand-50); color: var(--brand-700); cursor: pointer; min-height: 30px; }
.phrase-chip:hover { background: var(--brand-100); }
@media (prefers-color-scheme: dark) { .phrase-chip { color: var(--brand-ink); } }

/* ---- Printable document sheet ---------------------------------------------- */
.doc-sheet { max-width: 720px; margin: 0 auto; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--r-lg); padding: 36px 44px;
  box-shadow: var(--sh-2); }
.doc-head { display: flex; justify-content: space-between; align-items: flex-start;
  border-bottom: 2px solid var(--brand-500); padding-bottom: 12px; }
.doc-brand { font-weight: 800; font-size: var(--t-lg); display: flex; gap: 8px; align-items: center; }
.doc-title { font-size: var(--t-xl); margin: 18px 0 8px; }
.doc-patient { padding: 10px 0 16px; border-bottom: 1px solid var(--border); margin-bottom: 14px; }
.doc-body { line-height: 1.65; }
.doc-foot { margin-top: 34px; }
.doc-sign { margin: 34px 0 12px; max-width: 280px; margin-left: auto; text-align: center; }
.doc-sign .line { border-bottom: 1px solid var(--text); margin-bottom: 6px; height: 34px; }
.doc-prov { font-size: var(--t-xs); color: var(--text-muted); border-top: 1px dashed var(--border);
  padding-top: 8px; }

@media print {
  .topbar, .chat-launcher, .ai-footer, .no-print, #cce-progress, .chat-drawer { display: none !important; }
  body, main { background: #fff !important; padding: 0 !important; max-width: none !important; }
  .doc-sheet { border: 0; box-shadow: none; padding: 0; max-width: none; }
}

/* --- Idle-session warning (shared workstations) --- */
.session-warn {
  position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%);
  display: flex; align-items: center; gap: 10px;
  background: var(--warn-50, #fff7ed); color: var(--warn-900, #7c2d12);
  border: 1px solid var(--warn-300, #fdba74);
  border-radius: 10px; padding: 10px 16px; z-index: 90;
  box-shadow: 0 8px 24px rgb(0 0 0 / .18); font-weight: 600;
}
.session-warn .ico { width: 18px; height: 18px; flex: none; }
.session-warn button {
  border: 0; border-radius: 8px; padding: 7px 14px; cursor: pointer;
  background: var(--brand-600, #1d4ed8); color: #fff; font-weight: 700;
}

/* --- Profile + user administration --- */
.um-link { display: inline-flex; align-items: center; gap: 8px; margin-top: 8px;
  padding: 8px 10px; border-radius: 8px; color: var(--text); font-weight: 600;
  text-decoration: none; width: 100%; }
.um-link:hover { background: var(--brand-50); }
dl.kv { display: grid; grid-template-columns: max-content 1fr; gap: 8px 18px; margin: 12px 0; }
dl.kv dt { color: var(--text-muted); font-weight: 600; }
dl.kv dd { margin: 0; }
.form-error { color: var(--danger-600); background: var(--danger-50);
  border: 1px solid var(--danger-100); border-radius: 8px;
  padding: 8px 12px; font-weight: 600; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 12px 16px; align-items: end; }
.inline-form { display: inline-flex; gap: 6px; align-items: center; margin: 2px 0; flex-wrap: wrap; }
.inline-form select { max-width: 170px; }
.inline-form button { padding: 5px 10px; font-size: var(--t-sm); }

/* --- Direzione interactive reports --- */
.report-grid { display: grid; grid-template-columns: minmax(0, 2.2fr) minmax(240px, 1fr);
  gap: var(--s-4, 18px); align-items: start; }
@media (max-width: 900px) { .report-grid { grid-template-columns: 1fr; } }
.report-body { line-height: 1.65; }
.kpi-chip { display: inline-flex; align-items: baseline; gap: 6px;
  vertical-align: baseline; padding: 1px 8px 2px; margin: 0 1px;
  border-radius: 8px; background: var(--brand-50);
  border: 1px solid var(--brand-100); white-space: nowrap; line-height: inherit; }
.kpi-chip .kpi-val { font-weight: 800; color: var(--brand-700); }
.kpi-chip .kpi-label { font-size: var(--t-xs); color: var(--text-muted); }
@media (max-width: 640px) { .kpi-chip .kpi-label { display: none; } }
.kpi-chip.kpi-missing { background: var(--danger-50); border-color: var(--danger-100);
  color: var(--danger-600); padding: 4px 10px; font-size: var(--t-sm); }
.wiki-link { font-weight: 700; color: var(--brand-600); text-decoration: none;
  border-bottom: 1px dashed var(--brand-500); }
.wiki-link:hover { background: var(--brand-50); }
.wiki-link.wiki-missing { color: var(--text-muted); border-bottom-style: dotted; cursor: default; }
.kpi-snippet { cursor: pointer; display: inline-block; padding: 2px 6px;
  border-radius: 6px; background: var(--surface-2); font-size: var(--t-xs); }
.kpi-snippet:hover { background: var(--brand-100); }
.canvas-frame { height: 380px; border: 1px solid var(--border); border-radius: var(--r-md);
  overflow: hidden; margin-top: 8px; }
.canvas-frame.canvas-edit { height: 520px; }

/* --- Accept-with-changes panel (chart card + inbox) --- */
.edit-accept { margin-top: 10px; }
.edit-accept summary { display: inline-flex; align-items: center; gap: 6px;
  cursor: pointer; font-weight: 700; color: var(--ai-600);
  padding: 6px 10px; border-radius: 8px; border: 1px dashed var(--ai-500); }
.edit-accept summary:hover { background: var(--ai-50); }
.edit-accept[open] summary { border-bottom-left-radius: 0; border-bottom-right-radius: 0; }
.edit-accept-body { display: grid; gap: 10px; padding: 12px;
  border: 1px solid var(--border); border-radius: 0 8px 8px 8px;
  background: var(--surface-2); }
.edit-accept-body textarea { width: 100%; font-family: var(--font);
  font-size: var(--t-sm); line-height: 1.5; }

/* --- Effective oversight: key-facts chips + attestation --- */
.facts-row { display: flex; flex-wrap: wrap; gap: 6px; align-items: center;
  margin: 10px 0 4px; }
.facts-label { font-size: var(--t-xs); font-weight: 700; letter-spacing: .08em;
  text-transform: uppercase; color: var(--text-muted); }
.fact-chip { font-family: var(--mono); font-size: var(--t-xs); font-weight: 600;
  background: var(--warn-50, #fff7ed); color: var(--warn-900, #7c2d12);
  border: 1px solid var(--warn-300, #fdba74); border-radius: 6px; padding: 2px 8px; }
.facts-box { margin: 14px 0; padding: 14px 16px; border: 1px dashed var(--warn-300, #fdba74);
  border-radius: 8px; background: var(--warn-50, #fff7ed); }
.facts-box h3 { display: flex; gap: 8px; align-items: center; margin: 0 0 8px;
  font-size: var(--t-sm); color: var(--warn-900, #7c2d12); }
label.attest { display: flex; gap: 10px; align-items: flex-start; margin-top: 16px;
  font-weight: 600; max-width: 70ch; cursor: pointer; }
label.attest input { margin-top: 4px; width: 18px; height: 18px; flex: none; }

/* --- HAI: stale-data warning, consequence line, context inspector --- */
.stale-row { display: flex; gap: 8px; align-items: flex-start; margin: 10px 0 4px;
  padding: 8px 12px; border-radius: 8px; font-size: var(--t-sm);
  background: var(--danger-50); border: 1px solid var(--danger-100);
  color: var(--danger-600); }
.stale-row .ico { flex: none; margin-top: 2px; }
p.consequence { display: flex; gap: 8px; align-items: flex-start; margin: 8px 0 2px;
  font-size: var(--t-sm); color: var(--text-muted); }
p.consequence .ico { flex: none; margin-top: 2px; }
.chat-context { margin: 0 14px 8px; font-size: var(--t-sm); }
.chat-context summary { display: inline-flex; gap: 6px; align-items: center;
  cursor: pointer; color: var(--text-muted); font-weight: 600; padding: 4px 0; }
.chat-context summary:hover { color: var(--text); }
.chat-context-body { border: 1px solid var(--border); border-radius: 8px;
  padding: 10px 14px; margin-top: 6px; background: var(--surface-2);
  max-height: 220px; overflow-y: auto; }
.chat-context-body ul { margin: 4px 0; padding-left: 18px; }
.chat-context-body li { margin: 3px 0; }
.chat-context-body code { font-size: var(--t-xs); }
