/* ============================================================================
   Checklist Studio Odontoiatrico — style.css
   Design clinico, lineare, ad alta leggibilità. Mobile-first.
   Niente font o risorse esterne (funziona offline in LAN, anche su Safari datati).
   Evitato l'uso di "gap" sul flexbox per compatibilità con Safari < 14.
   ============================================================================ */

:root {
  --brand-primary: #0E7C86;   /* sovrascritto dalle impostazioni studio */
  --brand-accent:  #F2994A;   /* sovrascritto dalle impostazioni studio */

  --bg:        #eef2f3;
  --surface:   #ffffff;
  --ink:       #16242b;
  --ink-soft:  #5a6b72;
  --line:      #d9e1e3;
  --line-soft: #e9eef0;
  --ok:        #2e9e5b;
  --danger:    #c0392b;

  --radius:    14px;
  --radius-sm: 9px;
  --shadow:    0 1px 2px rgba(16,40,48,.06), 0 6px 20px rgba(16,40,48,.07);
  --shadow-sm: 0 1px 2px rgba(16,40,48,.08);

  --maxw: 880px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 17px;
  line-height: 1.45;
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--brand-primary); }

/* ----------------------------------------------------------------- layout */

.wrap {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 0 16px 48px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  box-shadow: var(--shadow-sm);
}
.topbar-inner {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 10px 16px;
  display: flex;
  align-items: center;
}
.brand {
  display: flex;
  align-items: center;
  min-width: 0;
  text-decoration: none;
  color: inherit;
}
.brand img {
  height: 38px;
  width: auto;
  max-width: 150px;
  margin-right: 12px;
  object-fit: contain;
  display: none;            /* mostrato via JS solo se logo presente */
}
.brand-text { min-width: 0; }
.brand-name {
  font-weight: 700;
  font-size: 18px;
  line-height: 1.1;
  letter-spacing: -.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.brand-sub {
  font-size: 12.5px;
  color: var(--ink-soft);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.topbar-spacer { flex: 1 1 auto; }

.topbar .btn-link {
  font-size: 14px;
  color: var(--ink-soft);
  text-decoration: none;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  white-space: nowrap;
}
.topbar .btn-link:hover { background: var(--line-soft); }

/* ----------------------------------------------------------------- stepper */

.steps {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-gap: 8px;
  margin: 18px 0 4px;
}
.step {
  text-align: center;
  font-size: 11.5px;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--ink-soft);
  padding-top: 12px;
  border-top: 3px solid var(--line);
  font-weight: 600;
}
.step.active { color: var(--brand-primary); border-top-color: var(--brand-primary); }
.step.done   { color: var(--ok); border-top-color: var(--ok); }

/* ----------------------------------------------------------------- panels */

.panel { animation: fade .18s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.eyebrow {
  text-transform: uppercase;
  letter-spacing: .09em;
  font-size: 12px;
  font-weight: 700;
  color: var(--brand-primary);
  margin: 24px 0 4px;
}
h1.title {
  font-size: 23px;
  font-weight: 700;
  letter-spacing: -.02em;
  margin: 0 0 16px;
}
.subtle { color: var(--ink-soft); }

/* griglia di scelta (operatori/medici/prestazioni) */
.choices {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  grid-gap: 12px;
  margin-top: 8px;
}
.choice {
  -webkit-appearance: none;
  appearance: none;
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: var(--radius);
  padding: 18px 16px;
  text-align: left;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: border-color .12s, transform .05s;
  font: inherit;
  color: inherit;
  display: block;
  width: 100%;
}
.choice:hover { border-color: var(--brand-primary); }
.choice:active { transform: scale(.99); }
.choice.selected {
  border-color: var(--brand-primary);
  box-shadow: 0 0 0 2px var(--brand-primary) inset, var(--shadow-sm);
}
.choice-name { display: block; font-weight: 650; font-size: 17px; overflow-wrap: anywhere; }
.choice-meta { display: block; font-size: 13px; color: var(--ink-soft); margin-top: 3px; line-height: 1.3; overflow-wrap: anywhere; }

/* ----------------------------------------------------------------- checklist */

.summary-bar {
  display: flex;
  flex-wrap: wrap;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px;
  box-shadow: var(--shadow-sm);
  margin-top: 8px;
}
.summary-item { margin-right: 22px; padding: 2px 0; }
.summary-item .k { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-soft); }
.summary-item .v { font-weight: 650; }

.checklist {
  list-style: none;
  margin: 16px 0 0;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  overflow: hidden;
  box-shadow: var(--shadow);
}
.cl-item {
  display: flex;
  align-items: center;
  padding: 4px 6px;
  border-bottom: 1px solid var(--line-soft);
}
.cl-item:last-child { border-bottom: 0; }
.cl-item label {
  display: flex;
  align-items: center;
  width: 100%;
  padding: 12px 10px;
  cursor: pointer;
  min-height: 30px;
}
.cl-check {
  width: 26px; height: 26px;
  margin-right: 14px;
  flex: 0 0 auto;
  accent-color: var(--brand-primary);
  transform: scale(1.05);
}
.cl-body { min-width: 0; flex: 1 1 auto; }
.cl-name { font-weight: 600; }
.cl-cat  { font-size: 12px; color: var(--ink-soft); }
.cl-qty {
  margin-left: 10px;
  flex: 0 0 auto;
  font-weight: 700;
  color: var(--brand-primary);
  background: var(--line-soft);
  border-radius: 999px;
  padding: 3px 11px;
  font-size: 13.5px;
}
.cl-item.checked .cl-name { color: var(--ink-soft); text-decoration: line-through; }

.cl-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 14px 2px 0;
  font-size: 14px;
  color: var(--ink-soft);
}

.note-box {
  margin-top: 14px;
  background: #fff8ef;
  border: 1px solid #f3dcc0;
  border-left: 4px solid var(--brand-accent);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-size: 15px;
}
.note-box .k { font-weight: 700; color: #9a6a2b; display: block; margin-bottom: 2px; font-size: 12px; text-transform: uppercase; letter-spacing: .05em; }

/* ----------------------------------------------------------------- buttons */

.actions { display: flex; flex-wrap: wrap; margin-top: 22px; }
.actions > * { margin-right: 10px; margin-bottom: 10px; }

.btn {
  -webkit-appearance: none;
  appearance: none;
  font: inherit;
  font-weight: 650;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 13px 20px;
  cursor: pointer;
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow-sm);
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--brand-primary); color: #fff; }
.btn-primary:hover { filter: brightness(1.05); }
.btn-ghost { background: var(--surface); border-color: var(--line); }
.btn-ghost:hover { border-color: var(--brand-primary); color: var(--brand-primary); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-block { width: 100%; justify-content: center; text-align: center; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-sm { padding: 8px 13px; font-size: 14px; }

/* ----------------------------------------------------------------- states */

.empty {
  text-align: center;
  padding: 40px 20px;
  color: var(--ink-soft);
  background: var(--surface);
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  margin-top: 16px;
}
.empty strong { color: var(--ink); }

.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%) translateY(20px);
  background: #16242b;
  color: #fff;
  padding: 12px 20px;
  border-radius: 999px;
  box-shadow: 0 10px 30px rgba(0,0,0,.25);
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
  z-index: 60;
  font-size: 15px;
  max-width: 90%;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.err { background: var(--danger); }

.done-screen { text-align: center; padding: 30px 10px; }
.done-mark {
  width: 76px; height: 76px;
  border-radius: 50%;
  background: var(--ok);
  color: #fff;
  font-size: 42px;
  line-height: 76px;
  margin: 0 auto 16px;
}

/* ----------------------------------------------------------------- gestione */

.tabs {
  display: flex;
  overflow-x: auto;
  border-bottom: 1px solid var(--line);
  margin: 14px 0 18px;
  -webkit-overflow-scrolling: touch;
}
.tab {
  -webkit-appearance: none; appearance: none;
  font: inherit; font-weight: 600;
  background: none; border: none;
  padding: 11px 15px;
  color: var(--ink-soft);
  cursor: pointer;
  border-bottom: 3px solid transparent;
  white-space: nowrap;
}
.tab.active { color: var(--brand-primary); border-bottom-color: var(--brand-primary); }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 16px;
  margin-bottom: 16px;
}

.row { display: flex; flex-wrap: wrap; align-items: flex-end; margin: 0 -6px; }
.row > .field { padding: 0 6px; margin-bottom: 12px; flex: 1 1 200px; }
.field label {
  display: block; font-size: 12.5px; font-weight: 650;
  color: var(--ink-soft); margin-bottom: 5px;
  text-transform: uppercase; letter-spacing: .04em;
}
.field input[type=text],
.field input[type=password],
.field input[type=number],
.field select,
.field textarea {
  width: 100%;
  font: inherit;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: #fff;
  color: var(--ink);
}
.field textarea { resize: vertical; min-height: 64px; }
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none; border-color: var(--brand-primary);
  box-shadow: 0 0 0 3px rgba(14,124,134,.15);
}

table.grid { width: 100%; border-collapse: collapse; }
table.grid th, table.grid td {
  text-align: left; padding: 11px 10px;
  border-bottom: 1px solid var(--line-soft);
  vertical-align: middle;
}
table.grid th {
  font-size: 12px; text-transform: uppercase; letter-spacing: .05em;
  color: var(--ink-soft); font-weight: 700;
}
table.grid tr:last-child td { border-bottom: 0; }
.tag {
  display: inline-block; font-size: 12px; font-weight: 600;
  padding: 2px 9px; border-radius: 999px;
  background: var(--line-soft); color: var(--ink-soft);
}
.tag.on  { background: #e3f5ea; color: var(--ok); }
.tag.off { background: #fdecea; color: var(--danger); }
.cell-actions { text-align: right; white-space: nowrap; }
.icon-btn {
  -webkit-appearance: none; appearance: none;
  border: 1px solid var(--line); background: #fff;
  border-radius: var(--radius-sm); padding: 6px 11px;
  cursor: pointer; font: inherit; font-size: 14px; margin-left: 6px;
  color: var(--ink-soft);
}
.icon-btn:hover { border-color: var(--brand-primary); color: var(--brand-primary); }
.icon-btn.del:hover { border-color: var(--danger); color: var(--danger); }

/* color picker compatto */
.color-field { display: flex; align-items: center; }
.color-field input[type=color] {
  width: 46px; height: 40px; padding: 0; border: 1px solid var(--line);
  border-radius: var(--radius-sm); background: #fff; cursor: pointer; margin-right: 8px;
}
.color-field input[type=text] { width: 120px; }

.help { font-size: 13px; color: var(--ink-soft); margin-top: 6px; }

.section-title {
  font-size: 18px; font-weight: 700; margin: 4px 0 12px;
  display: flex; align-items: center; justify-content: space-between;
}

/* lista materiali nella checklist editor */
.mat-pick {
  max-height: 60vh; overflow: auto;
  border: 1px solid var(--line); border-radius: var(--radius-sm);
}
.mat-row {
  display: flex; align-items: center;
  padding: 8px 10px; border-bottom: 1px solid var(--line-soft);
}
.mat-row:last-child { border-bottom: 0; }
.mat-row input[type=checkbox] { width: 22px; height: 22px; margin-right: 12px; accent-color: var(--brand-primary); flex: 0 0 auto; }
.mat-row .mat-name { flex: 1 1 auto; }
.mat-row .mat-name small { color: var(--ink-soft); }
.mat-row input.qty {
  width: 92px; flex: 0 0 auto; font: inherit;
  padding: 6px 9px; border: 1px solid var(--line); border-radius: var(--radius-sm);
}
.mat-row input.qty:disabled { background: #f4f6f7; }

.modal-back {
  position: fixed; inset: 0; background: rgba(16,36,43,.45);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 24px 14px; z-index: 50; overflow: auto;
}
.modal {
  background: var(--surface); border-radius: var(--radius);
  width: 100%; max-width: 560px; box-shadow: var(--shadow);
  padding: 20px; margin: auto;
}
.modal h3 { margin: 0 0 14px; }

.muted-link {
  background: none; border: none; color: var(--ink-soft);
  text-decoration: underline; cursor: pointer; font: inherit; padding: 0;
}

/* ----------------------------------------------------------------- print */

@media print {
  .topbar, .steps, .actions, .no-print { display: none !important; }
  body { background: #fff; }
  .wrap { max-width: none; padding: 0; }
  .checklist, .card, .summary-bar { box-shadow: none; border-color: #bbb; }
  .print-head { display: block !important; }
}
.print-head { display: none; margin-bottom: 14px; }
.print-head .ph-name { font-size: 22px; font-weight: 800; }
.print-head .ph-sub  { color: #444; }
.print-head hr { border: none; border-top: 2px solid var(--brand-primary); margin: 8px 0; }

/* ----------------------------------------------------------------- responsive */

@media (max-width: 560px) {
  body { font-size: 16px; }
  .brand-sub { display: none; }
  .choices { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); }
  .summary-item { margin-right: 16px; }
  h1.title { font-size: 20px; }
}

/* ---- login, admin bar, avvisi, statistiche, import/export (aggiunte) ---- */

.login-card { max-width: 380px; margin: 48px auto; }

#adminbar { display: inline-flex; align-items: center; }
#adminbar .admin-user {
  color: #fff; opacity: .9; font-size: 13px; font-weight: 600;
  margin-right: 12px; padding: 3px 10px; border-radius: 999px;
  background: rgba(255,255,255,.15);
}
#adminbar .btn-link { margin-right: 14px; }

.alert-warn {
  background: #FFF7E6; border: 1px solid #F0C36D; color: #7A5200;
  border-radius: 10px; padding: 10px 14px; margin-bottom: 14px; font-size: 14px;
}
.alert-warn a { color: #7A5200; font-weight: 700; }

/* statistiche */
.stat-total { display: flex; align-items: baseline; }
.stat-num { font-size: 38px; font-weight: 800; color: var(--brand-primary); line-height: 1; }
.stat-lbl { margin-left: 12px; color: var(--muted, #667); font-size: 15px; }

.stat-grid {
  display: block;
}
@media (min-width: 760px) {
  .stat-grid { display: grid; grid-template-columns: 1fr 1fr; column-gap: 16px; }
}

.barrow { display: flex; align-items: center; margin: 7px 0; }
.barlbl {
  flex: 0 0 38%; max-width: 38%; font-size: 13px; padding-right: 8px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.bartrack {
  flex: 1 1 auto; height: 16px; background: #EEF1F3;
  border-radius: 8px; overflow: hidden;
}
.barfill { height: 100%; background: var(--brand-primary); border-radius: 8px; min-width: 2px; }
.barfill.alt { background: var(--brand-accent); }
.barval { flex: 0 0 auto; width: 38px; text-align: right; font-size: 13px; font-weight: 700; }

textarea { width: 100%; padding: 10px; border: 1px solid var(--line); border-radius: 9px; font: inherit; resize: vertical; }

/* ---- captcha + toggle sicurezza (aggiunte) ---- */
.captcha-row { display: flex; align-items: center; margin-bottom: 6px; }
.captcha-img { height: 50px; width: 150px; border: 1px solid var(--line); border-radius: 8px; margin-right: 8px; image-rendering: pixelated; }
.captcha-math { font-size: 18px; font-weight: 700; margin-bottom: 6px; }
.switch-row { display: flex; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line); cursor: pointer; }
.switch-row:last-of-type { border-bottom: none; }
.switch-row input { width: 20px; height: 20px; margin-right: 12px; flex: 0 0 auto; }
.switch-row span { font-size: 15px; }

/* ---- flusso operatore: barra operatore, esiti, riepilogo (aggiunte) ---- */
.op-bar {
  display: flex; align-items: center; justify-content: space-between;
  background: #EFF5F6; border: 1px solid var(--line); border-radius: 10px;
  padding: 8px 12px; margin-bottom: 14px; font-size: 14px;
}
.op-bar .muted-link { white-space: nowrap; }

.esito-ok, .esito-warn {
  border-radius: 10px; padding: 10px 14px; margin: 12px 0; font-weight: 600;
}
.esito-ok { background: #E7F6EC; border: 1px solid #9BD9AE; color: #1E6B38; }
.esito-warn { background: #FFF4E5; border: 1px solid #F0C36D; color: #8A5300; }

.riga-mancante { background: #FFF7EE; }
.riga-mancante td { color: #8A5300; }

.done-mark.warn { background: var(--brand-accent, #F2994A); }

/* ---- grafici: torte SVG, legende, barre impilate, stampa PDF (aggiunte) ---- */
.pie-grid { display: block; }
@media (min-width: 760px) { .pie-grid { display: grid; grid-template-columns: 1fr 1fr; column-gap: 16px; } }

.pie-card .pie-wrap { display: flex; align-items: center; flex-wrap: wrap; }
.pie-svg { flex: 0 0 auto; margin-right: 14px; }
.pie-legend { flex: 1 1 160px; min-width: 150px; }
.leg-row { display: flex; align-items: center; padding: 3px 0; font-size: 13px; }
.leg-dot { width: 12px; height: 12px; border-radius: 3px; flex: 0 0 auto; margin-right: 8px; }
.leg-lbl { flex: 1 1 auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.leg-val { flex: 0 0 auto; font-weight: 700; margin-left: 8px; color: #555; }

.stack-row { display: flex; align-items: center; margin: 8px 0; }
.stack-lbl { flex: 0 0 28%; max-width: 28%; font-size: 13px; padding-right: 8px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stack-track { flex: 1 1 auto; background: #EEF1F3; border-radius: 8px; height: 18px; overflow: hidden; }
.stack-inner { display: flex; height: 100%; }
.stack-seg { height: 100%; display: inline-block; }
.stack-tot { flex: 0 0 auto; width: 40px; text-align: right; font-size: 13px; font-weight: 700; }

.only-print { display: none; }

@media print {
  .topbar, .tabs, .no-print, #adminbar { display: none !important; }
  .only-print { display: block; }
  .pie-grid { display: block; }
  .pie-card { page-break-inside: avoid; }
  .card { box-shadow: none; border: 1px solid #ddd; }
  * { -webkit-print-color-adjust: exact !important; print-color-adjust: exact !important; }
}

/* ---- casella "ricordami" verifica operatore (aggiunta) ---- */
.ricorda-row { display: flex; align-items: flex-start; margin: 4px 0 14px; max-width: 420px; cursor: pointer; }
.ricorda-row input { width: 20px; height: 20px; margin-right: 10px; flex: 0 0 auto; margin-top: 2px; }
.ricorda-row span { font-size: 14px; line-height: 1.35; }
.ricorda-row small { color: var(--ink-soft); }
