/* ============================================================
   Antigone — Gestionale studio dentistico
   Design system + layout shell
   ============================================================ */

:root {
  /* superfici */
  --bg: #F6F5F1;
  --surface: #FFFFFF;
  --surface-2: #FBFAF7;
  --border: oklch(0.92 0.005 200);
  --border-strong: oklch(0.86 0.008 200);
  --text: oklch(0.21 0.015 240);
  --text-muted: oklch(0.52 0.012 240);
  --text-subtle: oklch(0.68 0.01 240);

  /* accent — teal medico */
  --accent: oklch(0.55 0.085 195);
  --accent-soft: oklch(0.94 0.03 195);
  --accent-ink: oklch(0.32 0.07 195);

  /* stato (stessa croma) */
  --pos:  oklch(0.62 0.11 155);
  --pos-soft: oklch(0.94 0.04 155);
  --warn: oklch(0.72 0.12 75);
  --warn-soft: oklch(0.95 0.05 75);
  --neg:  oklch(0.58 0.13 25);
  --neg-soft: oklch(0.95 0.04 25);

  /* sidebar — light di default */
  --sb-bg: var(--surface);
  --sb-text: var(--text);
  --sb-muted: var(--text-muted);
  --sb-hover: oklch(0.96 0.005 200);
  --sb-active-bg: var(--accent-soft);
  --sb-active-text: var(--accent-ink);
  --sb-border: var(--border);

  /* layout */
  --sb-width: 248px;
  --sb-collapsed: 72px;
  --header-h: 64px;
  --footer-h: 44px;
  --radius: 10px;
  --radius-sm: 6px;
  --radius-lg: 14px;

  --shadow-sm: 0 1px 2px oklch(0.2 0.02 240 / 0.04);
  --shadow-md: 0 4px 18px oklch(0.2 0.02 240 / 0.06), 0 1px 3px oklch(0.2 0.02 240 / 0.04);
}

body[data-sidebar="dark"] {
  --sb-bg: oklch(0.21 0.015 240);
  --sb-text: oklch(0.95 0.005 240);
  --sb-muted: oklch(0.68 0.012 240);
  --sb-hover: oklch(0.26 0.018 240);
  --sb-active-bg: oklch(0.30 0.04 195);
  --sb-active-text: oklch(0.95 0.02 195);
  --sb-border: oklch(0.27 0.015 240);
}

body[data-density="compact"] {
  --header-h: 56px;
  --footer-h: 38px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text); }
body {
  font-family: "Plus Jakarta Sans", system-ui, -apple-system, sans-serif;
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
button { font-family: inherit; cursor: pointer; }
a { color: inherit; text-decoration: none; }

/* ---------- App shell ---------- */
.app {
  display: grid;
  grid-template-columns: var(--sb-width) 1fr;
  grid-template-rows: var(--header-h) 1fr var(--footer-h);
  grid-template-areas:
    "sidebar header"
    "sidebar main"
    "sidebar footer";
  min-height: 100vh;
  transition: grid-template-columns .25s ease;
}
body[data-collapsed="true"] .app { grid-template-columns: var(--sb-collapsed) 1fr; }

/* ---------- Sidebar ---------- */
.sidebar {
  grid-area: sidebar;
  background: var(--sb-bg);
  border-right: 1px solid var(--sb-border);
  display: flex; flex-direction: column;
  overflow: hidden;
  position: sticky; top: 0; height: 100vh;
  transition: background-color .2s ease, color .2s ease;
}
.sb-brand {
  display: flex; align-items: center; gap: 10px;
  padding: 0 20px;
  height: var(--header-h);
  border-bottom: 1px solid var(--sb-border);
  color: var(--sb-text);
  flex-shrink: 0;
}
.sb-logo {
  width: 32px; height: 32px; border-radius: 8px;
  background: linear-gradient(135deg, var(--accent), oklch(0.45 0.1 220));
  display: grid; place-items: center; color: white;
  flex-shrink: 0;
  box-shadow: inset 0 1px 0 oklch(1 0 0 / 0.25);
}
.sb-wordmark {
  font-weight: 800; font-size: 17px; letter-spacing: -0.01em;
  white-space: nowrap; overflow: hidden;
}
.sb-wordmark small {
  display: block; font-weight: 500; font-size: 10.5px;
  letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--sb-muted); margin-top: -2px;
}

.sb-nav { padding: 14px 12px; overflow-y: auto; overflow-x: hidden; flex: 1; }
.sb-group-title {
  font-size: 10.5px; letter-spacing: 0.1em; text-transform: uppercase;
  color: var(--sb-muted); padding: 14px 12px 6px;
  white-space: nowrap; overflow: hidden;
}
.sb-item {
  display: flex; align-items: center; gap: 12px;
  padding: 9px 12px; margin: 2px 0;
  border-radius: var(--radius-sm);
  color: var(--sb-text);
  font-weight: 500; font-size: 13.5px;
  cursor: pointer; user-select: none;
  border: 1px solid transparent;
  position: relative;
  transition: background-color .15s ease, color .15s ease;
  width: 100%; text-align: left; background: transparent;
  text-decoration: none;
}
.sb-item:hover { background: var(--sb-hover); }
.sb-item.active {
  background: var(--sb-active-bg);
  color: var(--sb-active-text);
  font-weight: 600;
}
.sb-item.active::before {
  content: ""; position: absolute; left: -12px; top: 6px; bottom: 6px;
  width: 3px; border-radius: 0 3px 3px 0;
  background: var(--accent);
}
.sb-item .ico { width: 20px; height: 20px; flex-shrink: 0; }
.sb-item .label { white-space: nowrap; overflow: hidden; flex: 1; }
.sb-item .badge {
  background: var(--accent); color: white;
  font-size: 11px; font-weight: 600;
  padding: 1px 7px; border-radius: 999px;
  margin-left: auto;
}
.sb-item.active .badge { background: var(--accent-ink); }

/* stato collassato */
body[data-collapsed="true"] .sb-wordmark,
body[data-collapsed="true"] .sb-group-title,
body[data-collapsed="true"] .sb-item .label,
body[data-collapsed="true"] .sb-item .badge {
  display: none;
}
body[data-collapsed="true"] .sb-brand { justify-content: center; padding: 0; }
body[data-collapsed="true"] .sb-item { justify-content: center; padding: 9px; }

/* ---------- Login ---------- */
.login-bg {
  min-height: 100vh;
  background-size: cover;
  background-position: center center;
  background-repeat: no-repeat;
  background-attachment: fixed;
}
.login-shell {
  min-height: 100vh;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  padding: 2rem 1rem;
  gap: 28px;
}
.login-logo {
  width: 100%; max-width: 300px;
  height: auto;
}
.login-card {
  width: 100%; max-width: 440px;
  box-shadow: var(--shadow-md);
}
.login-card-head { justify-content: center; }
.login-card-head h3 {
  font-size: 16px;
  font-weight: 500;
  letter-spacing: -0.01em;
  color: var(--text);
}
.login-error {
  background: var(--neg-soft);
  border: 1px solid color-mix(in oklch, var(--neg) 35%, white);
  color: var(--neg);
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  margin-bottom: 14px;
}
.login-form { display: flex; flex-direction: column; gap: 12px; }
.login-field {
  position: relative;
  display: block;
}
.login-field input {
  width: 100%;
  height: 42px;
  padding: 0 42px 0 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font: inherit;
  font-size: 14px;
  color: var(--text);
  transition: border-color .15s, background .15s, box-shadow .15s;
}
.login-field input::placeholder { color: var(--text-subtle); }
.login-field input::-ms-reveal,
.login-field input::-ms-clear { display: none; }
.login-field input:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--surface);
  box-shadow: 0 0 0 3px color-mix(in oklch, var(--accent) 18%, transparent);
}
.login-field-icon {
  position: absolute;
  right: 12px; top: 50%;
  transform: translateY(-50%);
  color: var(--text-subtle);
  pointer-events: none;
  display: flex;
}
.login-field input:focus + .login-field-icon,
.login-field:focus-within .login-field-icon { color: var(--accent); }
.login-field-toggle {
  pointer-events: auto;
  background: transparent;
  border: 0;
  padding: 4px;
  margin: 0;
  cursor: pointer;
  color: var(--text-subtle);
  border-radius: 6px;
  transition: color .15s, background .15s;
}
.login-field-toggle:hover { color: var(--text); }
.login-field-toggle:focus-visible {
  outline: none;
  color: var(--accent);
  box-shadow: 0 0 0 2px color-mix(in oklch, var(--accent) 35%, transparent);
}
.login-submit {
  height: 44px;
  width: 100%;
  margin-top: 6px;
  justify-content: center;
  font-size: 14px;
  font-weight: 600;
}
.login-foot {
  margin-top: 22px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  text-align: center;
  font-size: 12.5px;
  color: var(--text-muted);
  display: flex; flex-direction: column; gap: 4px;
}
.login-foot .mono { font-size: 12px; }

/* ---------- Header ---------- */
.header {
  grid-area: header;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 14px;
  padding: 0 22px;
  position: sticky; top: 0; z-index: 20;
}
.hamburger {
  width: 36px; height: 36px; border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  display: grid; place-items: center;
  color: var(--text);
  transition: background-color .15s, border-color .15s;
}
.hamburger:hover { background: var(--surface-2); border-color: var(--border-strong); }

.crumbs { display: flex; align-items: center; gap: 8px; color: var(--text-muted); font-size: 13px; }
.crumbs strong { color: var(--text); font-weight: 600; }
.crumbs .sep { opacity: 0.4; }

.search {
  flex: 1; max-width: 460px; margin-left: 8px;
  position: relative;
}
.search input {
  width: 100%; height: 38px; padding: 0 12px 0 38px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 9px;
  font: inherit; font-size: 13.5px; color: var(--text);
  outline: none;
  transition: border-color .15s, background-color .15s;
}
.search input:focus { border-color: var(--accent); background: white; }
.search input::placeholder { color: var(--text-subtle); }
.search .si {
  position: absolute; left: 12px; top: 50%; transform: translateY(-50%);
  color: var(--text-subtle); pointer-events: none;
}
.search kbd {
  position: absolute; right: 10px; top: 50%; transform: translateY(-50%);
  font: inherit; font-family: "JetBrains Mono", monospace; font-size: 11px;
  background: white; border: 1px solid var(--border);
  padding: 2px 6px; border-radius: 5px; color: var(--text-muted);
}

.h-actions { display: flex; align-items: center; gap: 8px; margin-left: auto; }
.icon-btn {
  width: 38px; height: 38px; border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--surface);
  display: grid; place-items: center;
  color: var(--text-muted);
  position: relative;
  transition: all .15s ease;
}
.icon-btn:hover { color: var(--text); background: var(--surface-2); border-color: var(--border-strong); }
.icon-btn .dot {
  position: absolute; top: 9px; right: 9px;
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--neg); border: 2px solid var(--surface);
}

.h-btn-primary {
  height: 38px; padding: 0 14px;
  background: var(--accent); color: white;
  border: none; border-radius: 9px;
  font-weight: 600; font-size: 13.5px;
  display: inline-flex; align-items: center; gap: 6px;
  box-shadow: 0 1px 2px oklch(0.55 0.085 195 / 0.3), inset 0 1px 0 oklch(1 0 0 / 0.2);
  transition: filter .15s;
}
.h-btn-primary:hover { filter: brightness(1.06); }

/* ---------- Header user menu ---------- */
.h-user { position: relative; }
.h-user-btn {
  display: flex; align-items: center; gap: 10px;
  height: 42px; padding: 0 10px 0 6px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; cursor: pointer;
  transition: background-color .15s, border-color .15s;
}
.h-user-btn:hover { background: var(--surface-2); border-color: var(--border-strong); }
.h-user-avatar {
  width: 30px; height: 30px; border-radius: 50%;
  background: linear-gradient(135deg, oklch(0.7 0.12 30), oklch(0.55 0.13 350));
  color: white; display: grid; place-items: center;
  font-weight: 700; font-size: 12px; flex-shrink: 0;
}
.h-user-info { display: flex; flex-direction: column; line-height: 1.15; min-width: 0; }
.h-user-name { font-weight: 600; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 160px; }
.h-user-role { color: var(--text-muted); font-size: 11px; }
.h-user-chevron { display: grid; place-items: center; color: var(--text-muted); transition: transform .15s; }
.h-user-btn.open .h-user-chevron { transform: rotate(180deg); }

.h-user-menu {
  position: absolute;
  top: calc(100% + 6px); right: 0;
  min-width: 180px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  padding: 6px;
  opacity: 0;
  transform: translateY(-4px);
  pointer-events: none;
  transition: opacity .12s ease, transform .12s ease;
  z-index: 30;
}
.h-user-menu.open {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}
.h-user-menu-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 13px; font-weight: 500;
  background: transparent; border: 0;
  width: 100%; text-align: left;
  cursor: pointer;
}
.h-user-menu-item:hover { background: var(--surface-2); color: var(--neg); }
@media (max-width: 640px) { .h-user-info { display: none; } }

/* ---------- Main ---------- */
.main { grid-area: main; overflow-y: auto; background: var(--bg); }
.main-inner { max-width: 1480px; padding: 28px 32px; }
body[data-density="compact"] .main-inner { padding: 18px 22px; }

.page-head {
  display: flex; align-items: flex-end; justify-content: space-between;
  gap: 24px; margin-bottom: 24px;
  flex-wrap: wrap;
}
.page-title {
  font-size: 26px; font-weight: 700; letter-spacing: -0.02em;
  margin: 0; line-height: 1.1;
}
.page-subtitle { color: var(--text-muted); font-size: 14px; margin-top: 6px; }
.page-actions { display: flex; gap: 8px; align-items: center; }

/* ---------- Footer ---------- */
.footer {
  grid-area: footer;
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 22px;
  font-size: 12px;
  color: var(--text-muted);
}
.footer .ft-meta { display: flex; gap: 16px; align-items: center; }
.footer .ft-meta span { display: inline-flex; align-items: center; gap: 6px; }
.footer .ft-status::before {
  content: ""; width: 7px; height: 7px; border-radius: 50%;
  background: var(--pos); display: inline-block;
  box-shadow: 0 0 0 3px oklch(0.62 0.11 155 / 0.18);
}

/* ---------- Cards & shared ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}
.card-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--border);
}
.card-head h3 { margin: 0; font-size: 14.5px; font-weight: 700; letter-spacing: -0.005em; }
.card-head .head-actions { display: flex; gap: 6px; color: var(--text-muted); font-size: 13px; }
.card-body { padding: 18px 20px; }
.card-body.tight { padding: 0; }

.btn-ghost {
  height: 32px; padding: 0 10px;
  background: transparent; border: 1px solid transparent;
  border-radius: 7px; color: var(--text-muted);
  font-size: 13px; font-weight: 500;
  display: inline-flex; align-items: center; gap: 6px;
}
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }

.btn-secondary {
  height: 34px; padding: 0 12px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; color: var(--text);
  font-size: 13px; font-weight: 500;
  display: inline-flex; align-items: center; gap: 6px;
  text-decoration: none;
}
.btn-secondary:hover { background: var(--surface-2); border-color: var(--border-strong); }
.btn-secondary.is-primary {
  background: var(--accent); color: white; border-color: transparent;
}

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0;
  background: color-mix(in oklch, black 45%, transparent);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 4vh 24px;
  z-index: 100;
  overflow-y: auto;
  backdrop-filter: blur(2px);
}
.modal-backdrop[hidden] { display: none; }
.modal {
  width: 100%; max-width: 600px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: 0 24px 60px -16px rgba(0,0,0,.35);
  margin: auto 0;
  animation: modalIn .14s ease-out;
}
@keyframes modalIn {
  from { opacity: 0; transform: translateY(-8px); }
  to   { opacity: 1; transform: translateY(0); }
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 22px; border-bottom: 1px solid var(--border);
  background: var(--surface);
  border-top-left-radius: var(--radius-lg);
  border-top-right-radius: var(--radius-lg);
}
.modal-head h3 { margin: 0; font-size: 15px; font-weight: 700; }
.modal-body { padding: 20px 22px; }
.modal-foot {
  display: flex; justify-content: flex-end; gap: 10px;
  padding: 12px 22px; border-top: 1px solid var(--border);
  background: var(--surface-2);
  border-bottom-left-radius: var(--radius-lg);
  border-bottom-right-radius: var(--radius-lg);
}

/* Required-field asterisk (Symfony adds .required to <label> automatically) */
label.required::after {
  content: ' *';
  color: var(--neg, oklch(0.55 0.18 25));
  font-weight: 700;
}

/* Form error messages */
.modal-body ul, .card-body ul {
  list-style: none; padding: 0; margin: 4px 0 0;
}
.modal-body ul li, .card-body ul li {
  color: var(--neg, oklch(0.55 0.18 25));
  font-size: 12px; margin-top: 2px;
}

/* Row action menu (3-dot dropdown) */
.row-menu-wrap { position: relative; display: inline-block; }
.row-menu {
  position: fixed;
  min-width: 150px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 7px;
  box-shadow: 0 8px 24px -4px rgba(0,0,0,.15);
  z-index: 1000;
  padding: 4px;
  text-align: left;
}
.row-menu[hidden] { display: none; }
.row-menu-item {
  display: flex; align-items: center; gap: 8px;
  width: 100%;
  padding: 8px 10px;
  background: transparent;
  border: 0;
  cursor: pointer;
  border-radius: 5px;
  font-size: 13px;
  color: var(--text);
  text-decoration: none;
  text-align: left;
}
.row-menu-item:hover { background: var(--surface-2); }
.row-menu-item.is-danger { color: #c0392b; }
.row-menu-item.is-danger:hover { background: #fdecec; }

/* Lightweight autocomplete (text input + suggestion list) */
.autocomplete { position: relative; }
.autocomplete-results {
  position: absolute; top: 100%; left: 0; right: 0;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 6px; margin-top: 2px;
  max-height: 240px; overflow-y: auto;
  z-index: 10;
  box-shadow: 0 6px 18px -4px rgba(0,0,0,.15);
}
.autocomplete-results[hidden] { display: none; }
.ac-item {
  padding: 8px 10px; cursor: pointer; font-size: 13.5px;
  display: flex; justify-content: space-between; gap: 8px;
}
.ac-item:hover, .ac-item.is-active { background: var(--accent-soft, #e8f5f1); }
.ac-prov { color: var(--text-muted); font-size: 12px; }
.ac-empty { padding: 8px 10px; color: var(--text-muted); font-size: 12.5px; }

.pill {
  display: inline-flex; align-items: center; gap: 5px;
  height: 22px; padding: 0 9px;
  border-radius: 999px;
  font-size: 11.5px; font-weight: 600;
  background: var(--surface-2); color: var(--text-muted);
  border: 1px solid var(--border);
  white-space: nowrap;
}
.pill.pos { background: var(--pos-soft); color: oklch(0.35 0.1 155); border-color: oklch(0.85 0.06 155); }
.pill.warn { background: var(--warn-soft); color: oklch(0.42 0.12 60); border-color: oklch(0.88 0.07 75); }
.pill.neg { background: var(--neg-soft); color: oklch(0.42 0.13 25); border-color: oklch(0.88 0.07 25); }
.pill.accent { background: var(--accent-soft); color: var(--accent-ink); border-color: oklch(0.85 0.05 195); }

.mono { font-family: "JetBrains Mono", monospace; }

/* tabella standard */
.data-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.data-table thead tr { background: var(--surface-2); border-bottom: 1px solid var(--border); }
.data-table th {
  text-align: left; padding: 12px 16px;
  font-weight: 600; font-size: 11.5px; letter-spacing: 0.04em;
  color: var(--text-muted); text-transform: uppercase;
}
.data-table th.num { text-align: right; }
.data-table td { padding: 12px 16px; border-bottom: 1px solid var(--border); }
.data-table tr:last-child td { border-bottom: none; }
.data-table td.num { text-align: right; }

/* avatar generato dalle iniziali */
.avatar {
  border-radius: 50%;
  color: white; display: inline-grid; place-items: center;
  font-weight: 700; letter-spacing: 0;
  box-shadow: inset 0 1px 0 oklch(1 0 0 / 0.18);
  flex-shrink: 0;
}

/* Page-enter fade.
   NOTE: do NOT add `transform` here. A transformed ancestor creates a
   containing block for descendants with `position: fixed`, breaking any
   fixed top-of-viewport UI (e.g. prestazioni filter bar). Opacity-only. */
.page-enter { animation: fade-in .28s cubic-bezier(.2,.7,.3,1) both; }
@keyframes fade-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

/* scrollbar */
.main::-webkit-scrollbar, .sb-nav::-webkit-scrollbar { width: 10px; }
.main::-webkit-scrollbar-thumb, .sb-nav::-webkit-scrollbar-thumb {
  background: oklch(0.85 0.005 240); border-radius: 10px;
  border: 3px solid transparent; background-clip: padding-box;
}
.main::-webkit-scrollbar-thumb:hover, .sb-nav::-webkit-scrollbar-thumb:hover {
  background: oklch(0.78 0.008 240); background-clip: padding-box;
}

/* ============================================================
   Refactor — component classes pulled out of inline templates
   ============================================================ */

/* Pazienti list toolbar */
.pazienti-toolbar {
  padding: 12px;
  margin-bottom: 14px;
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}
.pazienti-search-field {
  max-width: 360px;
  margin: 0;
  flex: 1;
  position: relative;
}
.pazienti-search-field input[type="search"] {
  padding-right: 34px;
}
.pazienti-toolbar-actions {
  margin-left: auto;
  display: flex;
  gap: 8px;
}

/* Spinner shown next to the search input while a search is in flight */
.pz-search-spinner {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  width: 16px;
  height: 16px;
  border: 2px solid var(--border);
  border-top-color: var(--accent, #4a7);
  border-radius: 50%;
  animation: pz-spin .7s linear infinite;
}
@keyframes pz-spin { to { transform: translateY(-50%) rotate(360deg); } }

/* Operatore card — "no account" warning badge */
.op-no-account {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #fff;
  color: #b08900;
  border: 1px solid #e6c350;
  display: grid;
  place-items: center;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
  z-index: 2;
  cursor: help;
  font-weight: 700;
  font-size: 13px;
}

/* Styled file picker (hides the native <input type="file">) */
.file-picker {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.file-picker-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border: 1px dashed var(--border-strong);
  border-radius: 6px;
  background: var(--surface-2);
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background .15s, border-color .15s, color .15s;
}
.file-picker-btn:hover {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent-ink);
}
.file-picker-name {
  color: var(--text-muted);
  font-size: 13px;
  font-style: italic;
}
.file-picker-name.has-file {
  color: var(--text);
  font-style: normal;
  font-weight: 500;
}
.file-picker-clear {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  cursor: pointer;
  padding: 0;
}
.file-picker-clear:hover {
  background: #fdecec;
  color: #c0392b;
  border-color: #f3c0c0;
}
.file-picker-clear[hidden] { display: none; }

/* Prestazioni cascading picker (operatore form) */
.prestazioni-hidden-select { display: none !important; }

.prestazioni-picker-bar {
  display: flex;
  gap: 8px;
  margin: 8px 0 10px;
}
.prestazioni-genere-select {
  flex: 1;
  height: 38px;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  font-size: 13px;
  font-family: inherit;
}

.prestazioni-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  max-height: 220px;
  overflow: auto;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface-2);
  margin-bottom: 10px;
}
.prestazione-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  font-size: 12.5px;
  font-family: inherit;
  cursor: pointer;
  transition: background .15s, border-color .15s, color .15s;
}
.prestazione-item:hover:not(:disabled) {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent-ink);
}
.prestazione-item:disabled,
.prestazione-item.is-selected {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent-ink);
  cursor: default;
}
.prestazione-item-check {
  font-weight: 700;
}

.prestazioni-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-height: 32px;
}
.prestazioni-chips-empty {
  color: var(--text-muted);
  font-size: 13px;
  font-style: italic;
  padding: 6px 0;
}
.prestazione-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 4px 4px 10px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  font-size: 12.5px;
  line-height: 1.2;
}
.prestazione-chip-genere {
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  background: var(--surface-2);
  padding: 2px 6px;
  border-radius: 999px;
}
.prestazione-chip-label { color: var(--text); }
.prestazione-chip-remove {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: none;
  background: var(--surface-2);
  color: var(--text-muted);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  font-size: 14px;
}
.prestazione-chip-remove:hover {
  background: #fdecec;
  color: #c0392b;
}

/* Detail-card edit/readonly layout (Pazienti/Operatori/Sedi show) */
.paziente-details-card {
  max-width: 900px;
  margin: 0 auto;
}
.paziente-details-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.paziente-details-actions {
  justify-content: flex-end;
  gap: 12px;
  border-top: 1px solid var(--border);
  padding-top: 20px;
  margin-top: 8px;
}

/* ==========================================================
   Prestazioni — stacked fixed bars (page-head + chip bar + indicator)
   All three are position:fixed and stacked flush, no gaps between them.
   Row filtering is driven by the global header search box.
   ========================================================== */
:root {
  --prest-bar-h: 52px;
  --prest-page-head-h: 60px;
}

.prest-filterbar {
  /* Fixed below the fixed page-head. */
  position: fixed;
  top: calc(var(--header-h) + var(--prest-page-head-h));
  left: var(--sb-width);
  right: 0;
  z-index: 15;
  height: var(--prest-bar-h);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 32px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  transition: left .25s ease;
}
body[data-collapsed="true"] .prest-filterbar { left: var(--sb-collapsed); }
body[data-density="compact"] .prest-filterbar { padding: 0 22px; }

/* Spacer is no longer needed — main-inner's top padding pushes the page-head
   below the fixed bars (see :has() rule further down). Kept hidden for safety. */
.prest-filterbar-spacer { display: none; }

/* The page-head, filter bar, and current-section indicator are ALL fixed
   (removed from flow). main-inner's first in-flow child (the body block)
   must start exactly where the indicator ends, so its top padding matches
   the total stacked height — no gap between the indicator and the first
   group's inline title. */
body:has(.prest-filterbar) .main-inner {
  padding-top: calc(var(--prest-page-head-h) + var(--prest-bar-h) + 40px);
}

/* Fixed "you are here" section indicator — updated by JS on scroll. */
.prest-current-section {
  position: fixed;
  top: calc(var(--header-h) + var(--prest-page-head-h) + var(--prest-bar-h));
  left: var(--sb-width);
  right: 0;
  z-index: 14;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  height: 40px;
  padding: 0 32px;
  background: var(--surface);
  border-bottom: 1px solid var(--border-strong);
  box-shadow: 0 4px 12px oklch(0.2 0.02 240 / 0.05);
  font-size: 12.5px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text);
  transition: left .25s ease, opacity .15s ease, transform .2s ease;
}
.prest-current-section::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 3px;
  background: var(--accent);
}
body[data-collapsed="true"] .prest-current-section { left: var(--sb-collapsed); }
body[data-density="compact"] .prest-current-section { padding: 0 22px; }
.prest-current-section[hidden] { display: none; }
.prest-current-section .prest-current-count {
  font-family: "JetBrains Mono", monospace;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 0;
  text-transform: none;
  background: var(--surface-2);
  padding: 3px 9px;
  border-radius: 999px;
}

/* Fixed page-head above the filter bar — compact, inline title + subtitle. */
body:has(.prest-filterbar) .page-head {
  position: fixed;
  top: var(--header-h);
  left: var(--sb-width);
  right: 0;
  z-index: 16;
  margin: 0;
  padding: 0 32px;
  background: var(--bg);
  height: var(--prest-page-head-h);
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: nowrap;
  transition: left .25s ease;
}
body[data-collapsed="true"]:has(.prest-filterbar) .page-head { left: var(--sb-collapsed); }
body[data-density="compact"]:has(.prest-filterbar) .page-head { padding: 0 22px; }

body:has(.prest-filterbar) .page-head > div:first-child {
  display: flex;
  flex-direction: row;
  align-items: baseline;
  gap: 14px;
  flex: 1;
  min-width: 0;
}
body:has(.prest-filterbar) .page-title {
  font-size: 20px;
  margin: 0;
  white-space: nowrap;
  letter-spacing: -0.015em;
}
body:has(.prest-filterbar) .page-subtitle {
  font-size: 13px;
  margin: 0;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Servizio chips — single row, horizontal scroll when they overflow. */
.prest-chips {
  display: flex;
  flex: 1;
  flex-wrap: nowrap;
  gap: 6px;
  min-width: 0;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: thin;
  scroll-behavior: smooth;
  /* Subtle fade hint at the right edge when there's more to scroll. */
  mask-image: linear-gradient(to right, black calc(100% - 24px), transparent);
}
.prest-chips::-webkit-scrollbar { height: 4px; }
.prest-chips::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 4px; }
.prest-chip { flex-shrink: 0; }

.prest-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 32px;
  padding: 0 11px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text);
  font-size: 12.5px;
  font-weight: 600;
  letter-spacing: 0.02em;
  white-space: nowrap;
  cursor: pointer;
  transition: background .12s ease, border-color .12s ease, color .12s ease;
}
.prest-chip:hover {
  background: var(--surface-2);
  border-color: var(--border-strong);
}
.prest-chip.is-active {
  background: var(--accent);
  border-color: transparent;
  color: white;
  box-shadow: 0 1px 2px oklch(0.55 0.085 195 / 0.3), inset 0 1px 0 oklch(1 0 0 / 0.2);
}

.prest-chip-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 22px;
  height: 18px;
  padding: 0 6px;
  background: var(--surface-2);
  border-radius: 999px;
  font-family: "JetBrains Mono", monospace;
  font-size: 10.5px;
  font-weight: 600;
  color: var(--text-muted);
}
.prest-chip.is-active .prest-chip-count {
  background: oklch(0.42 0.07 195);
  color: white;
}

/* Group sections with sticky title sitting just below the bar */
.prest-group { margin-bottom: 24px; }

.prest-group-title {
  /* No longer sticky — the fixed .prest-current-section provides the always-visible label. */
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 0 0 10px 0;
  padding: 10px 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: 6px;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text);
  box-shadow: var(--shadow-sm);
}
.prest-group-title .prest-group-servizio {
  color: var(--text-muted);
  font-weight: 600;
  margin-right: 4px;
}
.prest-group-count {
  font-family: "JetBrains Mono", monospace;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 0;
  text-transform: none;
}

.prest-empty { margin-top: 12px; }

/* Collapse toggle inside group table header */
.prest-collapse-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 28px; height: 28px;
  background: transparent; border: 0; border-radius: 6px;
  color: var(--text-muted);
  cursor: pointer;
  transition: background .15s, color .15s;
}
.prest-collapse-btn:hover {
  background: var(--surface-2);
  color: var(--text);
}
.prest-collapse-ico { display: inline-flex; }
.prest-collapse-ico-down { display: none; }
.prest-group.is-collapsed .prest-collapse-ico-up { display: none; }
.prest-group.is-collapsed .prest-collapse-ico-down { display: inline-flex; }
.prest-group.is-collapsed tbody { display: none; }

@media (max-width: 700px) {
  /* On very narrow screens, hide the search to give chips room (search can be
     re-added below the bar in a future iteration if needed). */
  .prest-search { display: none; }
}
