/* Pannello Allacci — tokens y componentes base (compartido por app.css y pratica.css).
   Tema claro siempre: el equipo lo pidio con fondo claro. */
:root {
  color-scheme: light;
  --bg: #F4F6F4;
  --surface: #FFFFFF;
  --surface-2: #F8FAF8;
  --surface-3: #F1F4F1;
  --line: #E2E7E3;
  --line-2: #EDF1EE;
  --ink: #17211B;
  --ink-2: #39463F;
  --muted: #68756D;
  --faint: #98A39C;

  --brand: #2E8B2E;
  --brand-600: #237323;
  --brand-500: #3AAA35;
  --brand-50: #EDF7EB;
  --brand-100: #D6EDD1;
  --sun: #F4C430;
  --sun-50: #FFF8DB;

  --danger: #D92D20;
  --danger-50: #FEF3F2;
  --danger-100: #FEE4E2;
  --warn: #B54708;
  --warn-50: #FFFAEB;
  --warn-100: #FEF0C7;
  --info: #2563EB;
  --info-50: #EFF4FF;
  --ok: #16A34A;
  --ok-50: #ECFDF3;

  /* gestori */
  --doors: #0F766E;
  --doors-50: #E3F4F1;
  --doors-100: #C4E8E2;
  --b2: #4F46E5;
  --b2-50: #ECEDFD;
  --b2-100: #D6D8FB;

  /* tappe (color de identidad de cada etapa; siempre con su etiqueta escrita) */
  --t-avvio: #64748B;       --tb-avvio: #F1F4F8;
  --t-domanda: #2563EB;     --tb-domanda: #EAF1FE;
  --t-tica: #C2620A;        --tb-tica: #FEF3E6;
  --t-lavori: #7C3AED;      --tb-lavori: #F3EEFE;
  --t-terna: #0E7490;       --tb-terna: #E5F5F9;
  --t-rde: #C0267A;         --tb-rde: #FCEBF4;
  --t-attivazione: #0D9488; --tb-attivazione: #E3F7F4;
  --t-allacciato: #15803D;  --tb-allacciato: #E4F6EA;
  --t-ferma: #B54708;       --tb-ferma: #FFF4E0;
  --t-chiusa: #6B7280;      --tb-chiusa: #EFF0F2;

  --r-sm: 7px;
  --r: 11px;
  --r-lg: 16px;
  --shadow-xs: 0 1px 2px rgba(16, 32, 20, .05);
  --shadow: 0 1px 2px rgba(16, 32, 20, .04), 0 4px 14px rgba(16, 32, 20, .06);
  --shadow-lg: 0 24px 64px rgba(10, 25, 14, .22);
  --focus: 0 0 0 3px rgba(58, 170, 53, .22);

  /* fuentes del sistema: sin Google Fonts (ninguna peticion a terceros, revision de seguridad L4) */
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--ink);
  font: 14px/1.5 var(--font); -webkit-font-smoothing: antialiased;
  font-feature-settings: "cv11", "ss01";
}
svg.i { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
a { color: var(--brand); text-decoration: none; cursor: pointer; }
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.num, .tnum { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.small { font-size: 12px; }
.xs { font-size: 11px; }
.mono { font-family: var(--mono); font-size: 12px; }
.nowrap { white-space: nowrap; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row { display: flex; align-items: center; gap: 8px; }
.row.wrap { flex-wrap: wrap; }
.col { display: flex; flex-direction: column; gap: 8px; }
.grow { flex: 1; min-width: 0; }
.sp { flex: 1; }

/* ------------------------------------------------------------------ botones */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  height: 34px; padding: 0 13px; border-radius: 9px; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink-2); cursor: pointer; font-weight: 600; font-size: 13px;
  white-space: nowrap; transition: background .12s, border-color .12s, box-shadow .12s;
}
.btn:hover { background: var(--surface-2); border-color: #CCD5CE; }
.btn:focus-visible { outline: none; box-shadow: var(--focus); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn .i { width: 16px; height: 16px; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-600); border-color: var(--brand-600); }
.btn.danger { color: var(--danger); }
.btn.danger.solid { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--surface-3); }
.btn.sm { height: 28px; padding: 0 10px; font-size: 12px; border-radius: 8px; }
.btn.xs { height: 24px; padding: 0 8px; font-size: 11.5px; border-radius: 7px; gap: 5px; }
.btn.icon { width: 34px; padding: 0; }
.btn.sm.icon { width: 28px; }
.btn.sun { background: var(--sun); border-color: #E2B21F; color: #3D3000; }

/* ------------------------------------------------------------------ formularios */
.input, .select, .textarea {
  width: 100%; height: 36px; padding: 0 11px; border: 1px solid var(--line); border-radius: 9px;
  background: var(--surface); outline: none; transition: border-color .12s, box-shadow .12s;
}
.textarea { height: auto; min-height: 84px; padding: 9px 11px; resize: vertical; line-height: 1.45; }
.select { padding-right: 28px; appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2368756D' stroke-width='2'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 8px center; background-size: 16px; }
.input:focus, .select:focus, .textarea:focus { border-color: var(--brand-500); box-shadow: var(--focus); }
.input.sm, .select.sm { height: 30px; font-size: 13px; }
label.lbl { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin: 0 0 5px; }
.field { display: flex; flex-direction: column; gap: 5px; }
.check { display: inline-flex; align-items: center; gap: 7px; cursor: pointer; user-select: none; }
.check input { width: 16px; height: 16px; accent-color: var(--brand); }

/* ------------------------------------------------------------------ tarjetas */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); box-shadow: var(--shadow-xs); }
.card-h { display: flex; align-items: center; gap: 10px; padding: 14px 18px; border-bottom: 1px solid var(--line-2); }
.card-h h3 { margin: 0; font-size: 14px; font-weight: 650; }
.card-h .sub { color: var(--muted); font-size: 12px; }
.card-b { padding: 16px 18px; }
.empty { padding: 34px 20px; text-align: center; color: var(--muted); }
.empty .i { width: 34px; height: 34px; color: var(--faint); margin-bottom: 6px; }

/* ------------------------------------------------------------------ chips */
.chip {
  display: inline-flex; align-items: center; gap: 5px; height: 22px; padding: 0 9px; border-radius: 999px;
  font-size: 11.5px; font-weight: 600; white-space: nowrap; border: 1px solid transparent; line-height: 1;
  background: var(--surface-3); color: var(--ink-2);
}
.chip .i { width: 13px; height: 13px; }
.chip.fase::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; flex: none; }
.chip.fase { color: var(--tc, var(--t-avvio)); background: var(--tbc, var(--tb-avvio)); }
.chip.fase[data-tappa="avvio"] { --tc: var(--t-avvio); --tbc: var(--tb-avvio); }
.chip.fase[data-tappa="domanda"] { --tc: var(--t-domanda); --tbc: var(--tb-domanda); }
.chip.fase[data-tappa="tica"] { --tc: var(--t-tica); --tbc: var(--tb-tica); }
.chip.fase[data-tappa="lavori"] { --tc: var(--t-lavori); --tbc: var(--tb-lavori); }
.chip.fase[data-tappa="terna"] { --tc: var(--t-terna); --tbc: var(--tb-terna); }
.chip.fase[data-tappa="rde"] { --tc: var(--t-rde); --tbc: var(--tb-rde); }
.chip.fase[data-tappa="attivazione"] { --tc: var(--t-attivazione); --tbc: var(--tb-attivazione); }
.chip.fase[data-tappa="allacciato"] { --tc: var(--t-allacciato); --tbc: var(--tb-allacciato); }
.chip.fase[data-tappa="ferma"] { --tc: var(--t-ferma); --tbc: var(--tb-ferma); }
.chip.fase[data-tappa="chiusa"] { --tc: var(--t-chiusa); --tbc: var(--tb-chiusa); }
.chip.gestore { font-weight: 700; letter-spacing: .02em; }
.chip.gestore.DOORS { background: var(--doors-50); color: var(--doors); border-color: var(--doors-100); }
.chip.gestore.B2 { background: var(--b2-50); color: var(--b2); border-color: var(--b2-100); }
.chip.attesa { background: var(--surface); border-color: var(--line); color: var(--ink-2); }
.chip.attesa::before { content: ""; width: 6px; height: 6px; border-radius: 2px; background: var(--ac, var(--muted)); }
.chip.flag { background: var(--warn-50); color: var(--warn); }
.chip.flag.rosso { background: var(--danger-50); color: var(--danger); }
.chip.iter { background: var(--surface-3); color: var(--muted); font-weight: 600; }
.chip.ok { background: var(--ok-50); color: var(--ok); }
.chip.danger { background: var(--danger-50); color: var(--danger); }
.chip.info { background: var(--info-50); color: var(--info); }

/* barra de documentos ok/totali */
.docbar { display: inline-flex; align-items: center; gap: 7px; min-width: 92px; }
.docbar .track { position: relative; flex: 1; height: 6px; border-radius: 6px; background: var(--line-2); overflow: hidden; min-width: 44px; }
.docbar .fill { position: absolute; inset: 0 auto 0 0; border-radius: 6px; background: var(--warn); }
.docbar.completi .fill { background: var(--ok); }
.docbar .lab { font-size: 11.5px; font-weight: 600; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.docbar.completi .lab { color: var(--ok); }

/* avatar */
.avatar { width: 24px; height: 24px; border-radius: 50%; display: inline-grid; place-items: center; font-size: 10.5px; font-weight: 700; color: #fff; background: var(--muted); flex: none; }
.avatar.lg { width: 32px; height: 32px; font-size: 12.5px; }
.avatar.vuoto { background: var(--surface-3); color: var(--faint); border: 1px dashed var(--line); }

/* ------------------------------------------------------------------ modal / drawer / toast */
.ui-modal-wrap { position: fixed; inset: 0; z-index: 80; display: grid; place-items: center; padding: 24px; }
.ui-modal-bg { position: absolute; inset: 0; background: rgba(18, 28, 22, .42); backdrop-filter: blur(2px); animation: fade .15s; }
.ui-modal { position: relative; width: min(560px, 100%); max-height: calc(100vh - 48px); display: flex; flex-direction: column; background: var(--surface); border-radius: var(--r-lg); box-shadow: var(--shadow-lg); animation: pop .16s ease-out; }
.ui-modal.largo { width: min(920px, 100%); }
.ui-modal.xlargo { width: min(1180px, 100%); }
.ui-modal-h { display: flex; align-items: center; gap: 10px; padding: 16px 20px; border-bottom: 1px solid var(--line-2); }
.ui-modal-h h3 { margin: 0; font-size: 16px; font-weight: 650; }
.ui-modal-b { padding: 18px 20px; overflow: auto; }
.ui-modal-f { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--line-2); background: var(--surface-2); border-radius: 0 0 var(--r-lg) var(--r-lg); }
.ui-drawer-wrap { position: fixed; inset: 0; z-index: 60; }
.ui-drawer-bg { position: absolute; inset: 0; background: rgba(18, 28, 22, .28); animation: fade .15s; }
.ui-drawer { position: absolute; top: 0; right: 0; bottom: 0; width: min(820px, 96vw); background: var(--bg); box-shadow: var(--shadow-lg); display: flex; flex-direction: column; animation: slide .2s ease-out; }
.ui-drawer.largo { width: min(1040px, 98vw); }
.ui-toasts { position: fixed; right: 20px; bottom: 20px; z-index: 120; display: flex; flex-direction: column; gap: 8px; align-items: flex-end; }
.ui-toast { display: flex; align-items: center; gap: 10px; min-width: 240px; max-width: 460px; padding: 11px 14px; border-radius: 11px; background: #1E2A23; color: #fff; box-shadow: var(--shadow-lg); font-size: 13px; animation: pop .16s ease-out; }
.ui-toast.ok .dot { background: #4ADE80; } .ui-toast.errore .dot { background: #F87171; } .ui-toast.info .dot { background: #93C5FD; }
.ui-toast .dot { width: 8px; height: 8px; border-radius: 50%; background: #CBD5E1; flex: none; }
.ui-toast button { margin-left: auto; background: none; border: 0; color: #A7F3D0; font-weight: 700; cursor: pointer; }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: translateY(6px) scale(.985); } }
@keyframes slide { from { transform: translateX(40px); opacity: .4; } }

/* skeleton */
.skel { background: linear-gradient(90deg, var(--line-2) 25%, #F6F8F6 37%, var(--line-2) 63%); background-size: 400% 100%; animation: skel 1.3s ease infinite; border-radius: 6px; min-height: 12px; }
@keyframes skel { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }

/* tablas base */
table.tbl { width: 100%; border-collapse: separate; border-spacing: 0; }
table.tbl th { position: sticky; top: 0; z-index: 2; background: var(--surface-2); text-align: left; font-size: 11.5px; font-weight: 650; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; padding: 9px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.tbl td { padding: 10px 12px; border-bottom: 1px solid var(--line-2); vertical-align: middle; }
table.tbl tbody tr { cursor: pointer; transition: background .08s; }
table.tbl tbody tr:hover { background: #F7FAF7; }
table.tbl tbody tr.sel { background: var(--brand-50); }

/* scrollbars discretas */
* { scrollbar-width: thin; scrollbar-color: #CAD3CC transparent; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: #CAD3CC; border-radius: 10px; border: 2px solid transparent; background-clip: padding-box; }
