/* JARVIS OS — interfaccia
   Palette: inchiostro ardesia + calce. I colori dei campi riprendono la regola dei fogli:
   giallo = si compila, grigio = calcolato, verde = calcolato ma correggibile. */
:root {
  --ink: #1d3b53;
  --ink-2: #2a4d69;
  --ink-soft: #c9d6e0;
  --paper: #eef1ee;
  --surface: #ffffff;
  --line: #d6ddd8;
  --line-2: #e6eae7;
  --text: #17222c;
  --muted: #5d6a72;
  --gold: #f3dc8a;
  --edit: #fff7d9;
  --edit-line: #e9d48a;
  --calc: #eceff0;
  --corr: #e4f1e5;
  --corr-line: #a9cfae;
  --red: #b3261e;   --red-bg: #fbe4e1;
  --amber: #8a5a00; --amber-bg: #fcefc9;
  --blue: #1d3b53;  --blue-bg: #e1eaf1;
  --violet: #6b3fa0; --violet-bg: #efe7f8;
  --green: #2e6b3f; --green-bg: #e2f0e4;
  --grey-bg: #eceeef;
  --radius: 6px;
  --font: "Schibsted Grotesk", system-ui, -apple-system, "Segoe UI", sans-serif;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font-family: var(--font); font-size: 14px; line-height: 1.45; color: var(--text); background: var(--paper); }
a { color: var(--ink); }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
.num, td.n, th.n, .grid td.n, .grid th.n { font-variant-numeric: tabular-nums; text-align: right; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
code { background: var(--calc); padding: 1px 5px; border-radius: 4px; font-size: 12.5px; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h1 { font-size: 22px; font-weight: 700; letter-spacing: -0.01em; }
h2 { font-size: 16px; font-weight: 650; }
h3 { font-size: 14px; font-weight: 650; }

/* ---------- layout */
#app { display: grid; grid-template-columns: 228px 1fr; min-height: 100vh; }
.side { background: var(--ink); color: #e9eff3; display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand-lockup { display: flex; align-items: center; gap: 10px; padding: 18px 18px 14px; }
.brand-mark { width: 34px; height: 34px; border-radius: 8px; background: var(--gold); color: var(--ink); display: grid; place-items: center; font-weight: 700; font-size: 19px; flex: none; }
.brand-lockup strong { display: block; font-size: 15px; letter-spacing: 0.01em; }
.brand-lockup div span { display: block; font-size: 12px; opacity: .72; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 150px; }
#nav { padding: 6px 10px; flex: 1; }
.nav-group { margin: 14px 8px 4px; font-size: 11.5px; color: var(--ink-soft); opacity: .8; }
.nav-item { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 7px 10px; border-radius: var(--radius); color: #e9eff3; text-decoration: none; font-weight: 500; }
.nav-item:hover { background: var(--ink-2); }
.nav-item.on { background: #f4f6f4; color: var(--ink); }
.nav-item .badge { font-size: 11.5px; padding: 0 7px; border-radius: 10px; background: var(--red); color: #fff; font-weight: 600; font-variant-numeric: tabular-nums; }
.nav-item.on .badge { background: var(--red); }
.side-foot { padding: 12px 18px 18px; font-size: 12.5px; border-top: 1px solid var(--ink-2); }
.side-foot a { color: var(--gold); text-decoration: none; margin-right: 10px; }
.side-foot .who { font-weight: 600; }
.main { min-width: 0; display: flex; flex-direction: column; }
.top { display: flex; align-items: center; gap: 12px; padding: 14px 28px; border-bottom: 1px solid var(--line); background: var(--paper); position: sticky; top: 0; z-index: 5; }
.top-title { flex: 1; min-width: 0; }
.top-tools { display: flex; gap: 8px; align-items: center; }
#view { padding: 22px 28px 60px; outline: none; }
.only-mobile { display: none; }
.loading { color: var(--muted); }

/* ---------- controls */
.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--surface); padding: 7px 13px; border-radius: var(--radius); cursor: pointer; font-weight: 550; text-decoration: none; color: var(--text); white-space: nowrap; }
.btn:hover { border-color: var(--ink-2); }
.btn.primary { background: var(--ink); border-color: var(--ink); color: #fff; }
.btn.primary:hover { background: var(--ink-2); }
.btn.danger { color: var(--red); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.sm { padding: 4px 9px; font-size: 12.5px; }
.btn:disabled { opacity: .5; cursor: default; }
.icon-btn { border: 1px solid var(--line); background: var(--surface); width: 34px; height: 34px; border-radius: var(--radius); cursor: pointer; font-size: 16px; }
input[type=text], input[type=search], input[type=email], input[type=tel], input[type=number], input[type=date], input[type=datetime-local], input[type=password], input[type=url], input:not([type]), select, textarea {
  width: 100%; padding: 7px 9px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); min-height: 34px;
}
textarea { min-height: 70px; resize: vertical; }
select { padding-right: 24px; }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 14px; }
.toolbar input[type=search] { max-width: 260px; }
.toolbar select { width: auto; max-width: 190px; }
.toolbar .spacer { flex: 1; }
.check { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; cursor: pointer; white-space: nowrap; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; background: var(--surface); }
.seg button { border: 0; background: transparent; padding: 6px 12px; cursor: pointer; font-weight: 550; color: var(--muted); }
.seg button.on { background: var(--ink); color: #fff; }
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 18px; overflow-x: auto; }
.tabs button { border: 0; background: none; padding: 9px 14px; cursor: pointer; font-weight: 600; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tabs button.on { color: var(--ink); border-bottom-color: var(--ink); }

/* ---------- tables */
.table-wrap { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: auto; max-height: calc(100vh - 210px); }
table.grid { border-collapse: separate; border-spacing: 0; width: 100%; font-size: 13.5px; }
.grid th { position: sticky; top: 0; z-index: 1; background: #f6f8f6; text-align: left; font-weight: 600; color: var(--muted); font-size: 12.5px; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; cursor: default; user-select: none; }
.grid th.sortable { cursor: pointer; }
.grid th.sortable:hover { color: var(--ink); }
.grid th .arr { font-size: 10px; margin-left: 3px; }
.grid td { padding: 7px 10px; border-bottom: 1px solid var(--line-2); white-space: nowrap; max-width: 280px; overflow: hidden; text-overflow: ellipsis; vertical-align: middle; }
.grid tbody tr { cursor: pointer; }
.grid tbody tr:hover td { background: #f7f9fb; }
.grid tbody tr:last-child td { border-bottom: 0; }
.grid td.wrap { white-space: normal; min-width: 200px; }
.grid td.code { font-weight: 600; color: var(--ink); font-variant-numeric: tabular-nums; }
.grid td.calc { background: #f8f9f9; }
.grid tr.dim td { color: var(--muted); }
.grid select.inline { min-height: 28px; padding: 3px 6px; font-size: 12.5px; width: auto; max-width: 200px; }
.count-line { font-size: 12.5px; color: var(--muted); margin: 8px 2px 0; }
.empty { padding: 28px; text-align: center; color: var(--muted); }
.empty strong { display: block; color: var(--text); margin-bottom: 4px; }

/* ---------- pills */
.pill { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: 11.5px; font-weight: 650; white-space: nowrap; line-height: 18px; }
.pill.SCADUTA { color: var(--red); background: var(--red-bg); }
.pill.OGGI { color: var(--amber); background: var(--amber-bg); }
.pill.PROGRAMMATA { color: var(--blue); background: var(--blue-bg); }
.pill.DATA-AZIONE-MANCANTE, .pill.AZIONE-MANCANTE, .pill.DA-VERIFICARE { color: var(--violet); background: var(--violet-bg); }
.pill.CHIUSA, .pill.SOSPESA { color: var(--muted); background: var(--grey-bg); }
.pill.ALTA { color: var(--green); background: var(--green-bg); }
.pill.MEDIA { color: var(--amber); background: var(--amber-bg); }
.pill.BASSA { color: var(--muted); background: var(--grey-bg); }
.pill.stato { color: var(--text); background: var(--calc); font-weight: 550; }
.pill.warn { color: var(--red); background: var(--red-bg); }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; vertical-align: 1px; }

/* ---------- figures (KPI strip: numeri separati da filetti, non card) */
.figures { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 22px; }
.figure { padding: 14px 18px; border-left: 1px solid var(--line-2); }
.figure:first-child { border-left: 0; }
.figure .v { font-size: 26px; font-weight: 700; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; color: var(--ink); }
.figure .v.alarm { color: var(--red); }
.figure .l { font-size: 13px; font-weight: 600; margin-top: 2px; }
.figure .s { font-size: 12px; color: var(--muted); }
.figure.link { cursor: pointer; }
.figure.link:hover { background: #f7f9fb; }

.cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 22px; margin-bottom: 26px; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.panel > header { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; padding: 12px 16px; border-bottom: 1px solid var(--line-2); }
.panel > .body { padding: 12px 16px; }
.panel table.grid tbody tr { cursor: default; }
.section-title { display: flex; align-items: baseline; gap: 12px; margin: 30px 0 12px; }
.section-title p { margin: 0; }

.bars { display: grid; gap: 7px; }
.bar-row { display: grid; grid-template-columns: 170px 1fr 44px; align-items: center; gap: 10px; font-size: 13px; }
.bar-row .track { height: 12px; background: var(--line-2); border-radius: 3px; overflow: hidden; }
.bar-row .fill { height: 100%; background: var(--ink); border-radius: 3px; }
.bar-row .lab { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.meter { display: inline-block; vertical-align: middle; width: 90px; height: 8px; background: var(--line-2); border-radius: 4px; overflow: hidden; min-width: 70px; }
.meter > i { display: block; height: 100%; background: var(--ink); }
.meter.good > i { background: var(--green); }
.score { display: inline-flex; align-items: center; gap: 8px; font-variant-numeric: tabular-nums; font-weight: 700; }
.score .meter { width: 60px; }

/* ---------- agenda */
.today-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; flex-wrap: wrap; margin-bottom: 22px; }
.today-date { line-height: 1; }
.today-date .dow { font-size: 15px; color: var(--muted); font-weight: 600; }
.today-date .day { font-size: 52px; font-weight: 700; letter-spacing: -0.035em; color: var(--ink); }
.today-date .day span { color: var(--muted); font-weight: 500; }
.today-sum { display: flex; gap: 22px; }
.today-sum div { font-size: 13px; color: var(--muted); }
.today-sum b { display: block; font-size: 24px; color: var(--ink); font-variant-numeric: tabular-nums; }
.today-sum b.red { color: var(--red); }
.agenda-group { margin-bottom: 22px; }
.agenda-group > h2 { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; font-size: 14px; }
.agenda-group > h2 .n { color: var(--muted); font-weight: 500; }
.agenda-list { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.ag-item { display: grid; grid-template-columns: 86px minmax(0, 1.4fr) minmax(0, 1.3fr) minmax(0, 1fr) auto; gap: 14px; align-items: center; padding: 10px 14px; border-top: 1px solid var(--line-2); cursor: pointer; }
.ag-item:first-child { border-top: 0; }
.ag-item:hover { background: #f7f9fb; }
.ag-item .when { font-variant-numeric: tabular-nums; font-weight: 600; font-size: 13px; }
.ag-item .who b { display: block; font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ag-item .who span, .ag-item .what span { font-size: 12.5px; color: var(--muted); }
.ag-item .what b { display: block; font-weight: 550; font-size: 13px; }
.ag-item .tel a { text-decoration: none; font-variant-numeric: tabular-nums; }
.ag-item .acts { display: flex; gap: 6px; }
.area-tag { font-size: 11px; font-weight: 650; color: var(--muted); }

/* ---------- opportunità */
.opp { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 14px; }
.opp-head { display: flex; flex-wrap: wrap; gap: 6px 18px; align-items: baseline; padding: 12px 16px; border-bottom: 1px solid var(--line-2); }
.opp-head h3 { font-size: 15px; cursor: pointer; }
.opp-head .req { font-size: 13px; color: var(--muted); }
.opp-head .req b { color: var(--text); font-weight: 600; }
.opp-row { display: grid; grid-template-columns: 30px minmax(0, 1.6fr) 120px 140px minmax(0, 1.6fr) auto; gap: 14px; align-items: center; padding: 9px 16px; border-top: 1px solid var(--line-2); }
.opp-row:first-of-type { border-top: 0; }
.opp-row .pos { color: var(--muted); font-weight: 650; font-variant-numeric: tabular-nums; }
.opp-row .imm b { display: block; cursor: pointer; }
.opp-row .imm span { font-size: 12.5px; color: var(--muted); }
.opp-row .diff { font-size: 12.5px; color: var(--muted); }
.opp-none { padding: 12px 16px; color: var(--muted); font-size: 13px; }

/* ---------- drawer & forms */
.drawer { position: fixed; inset: 0; z-index: 30; display: flex; justify-content: flex-end; background: rgba(23, 34, 44, .32); }
.drawer[hidden] { display: none; }
.drawer-panel { width: min(760px, 100%); height: 100%; background: var(--paper); display: flex; flex-direction: column; box-shadow: -8px 0 30px rgba(23, 34, 44, .18); animation: slidein .18s ease-out; }
@keyframes slidein { from { transform: translateX(24px); opacity: .6; } to { transform: none; opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .drawer-panel { animation: none; } }
.drawer-head { display: flex; align-items: center; gap: 12px; padding: 16px 22px; border-bottom: 1px solid var(--line); background: var(--surface); }
.drawer-head .t { flex: 1; min-width: 0; }
.drawer-head .t small { display: block; color: var(--muted); font-size: 12.5px; }
.drawer-body { flex: 1; overflow-y: auto; padding: 18px 22px 30px; }
.drawer-foot { display: flex; gap: 8px; padding: 12px 22px; border-top: 1px solid var(--line); background: var(--surface); }
.drawer-foot .spacer { flex: 1; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--muted); margin-bottom: 14px; }
.legend i { display: inline-block; width: 14px; height: 10px; border-radius: 2px; margin-right: 5px; vertical-align: -1px; border: 1px solid var(--line); }
.legend .e { background: var(--edit); border-color: var(--edit-line); }
.legend .c { background: var(--calc); }
.legend .g { background: var(--corr); border-color: var(--corr-line); }
.fsec { margin-bottom: 18px; }
.fsec > h3 { margin-bottom: 8px; color: var(--ink); }
.fsec > p { margin: -4px 0 10px; font-size: 12.5px; color: var(--muted); }
.fgrid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px 12px; }
.f { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.f > span { font-size: 12px; font-weight: 600; color: var(--muted); }
.f.w2 { grid-column: span 2; }
.f.w3 { grid-column: 1 / -1; }
.f input, .f select, .f textarea { background: var(--edit); border-color: var(--edit-line); }
.f input:focus, .f select:focus, .f textarea:focus { background: #fff; }
.f .calcv { min-height: 34px; padding: 7px 9px; border-radius: var(--radius); background: var(--calc); border: 1px solid transparent; font-variant-numeric: tabular-nums; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.f.corr input, .f.corr select { background: var(--corr); border-color: var(--corr-line); }
.f .hint { font-size: 11.5px; color: var(--muted); }
.f .notinlist { font-size: 11.5px; color: var(--red); }
.guide { background: var(--blue-bg); border-radius: var(--radius); padding: 10px 12px; font-size: 12.5px; margin-bottom: 14px; }
.guide b { color: var(--ink); }
.history { border-top: 1px solid var(--line); padding-top: 14px; }
.hist-item { display: grid; grid-template-columns: 112px 1fr; gap: 10px; padding: 7px 0; border-bottom: 1px solid var(--line-2); font-size: 13px; }
.hist-item .d { color: var(--muted); font-variant-numeric: tabular-nums; }

/* ---------- misc */
.toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%) translateY(20px); background: var(--ink); color: #fff; padding: 10px 18px; border-radius: var(--radius); opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 50; max-width: 90vw; }
.toast.on { opacity: 1; transform: translateX(-50%); }
.toast.err { background: var(--red); }
.flash { padding: 10px 12px; border-radius: var(--radius); margin: 10px 0; font-size: 13.5px; }
.flash.err { background: var(--red-bg); color: var(--red); }
.flash.ok { background: var(--green-bg); color: var(--green); }
.flash.info { background: var(--blue-bg); color: var(--ink); }
.callout { background: var(--surface); border: 1px solid var(--line); border-left: 3px solid var(--gold); border-radius: var(--radius); padding: 12px 16px; margin-bottom: 16px; }
.callout h3 { margin-bottom: 6px; }
.chk-list { display: grid; gap: 0; }
.chk { display: grid; grid-template-columns: 1fr 60px 1.3fr; gap: 12px; padding: 10px 16px; border-top: 1px solid var(--line-2); align-items: center; cursor: pointer; }
.chk:first-child { border-top: 0; }
.chk .n { font-size: 20px; font-weight: 700; text-align: right; font-variant-numeric: tabular-nums; }
.chk .n.zero { color: var(--green); }
.chk .n.bad { color: var(--red); }
.chk-detail { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 6px; padding-top: 4px; }
.list-editor { display: grid; gap: 6px; }
.le-row { display: grid; grid-template-columns: 22px 1fr 180px 30px; gap: 6px; align-items: center; }
.le-row.noextra { grid-template-columns: 22px 1fr 30px; }
.le-row .h { cursor: grab; color: var(--muted); text-align: center; }
.settings-lists { display: grid; grid-template-columns: 240px 1fr; gap: 20px; }
.settings-lists nav { display: flex; flex-direction: column; gap: 2px; }
.settings-lists nav button { text-align: left; border: 0; background: none; padding: 6px 10px; border-radius: var(--radius); cursor: pointer; color: var(--text); }
.settings-lists nav button.on { background: var(--ink); color: #fff; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-grid fieldset { border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px 14px; display: grid; gap: 10px; margin: 0; }
.form-grid legend { font-weight: 650; padding: 0 4px; }
.form-grid label, .stack label { display: grid; gap: 4px; font-size: 13px; font-weight: 600; color: var(--muted); }
.form-grid label.radio { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; color: var(--text); font-weight: 500; }
.form-grid label.radio input[name=agenzia] { flex: 1; min-width: 200px; }
.span2 { grid-column: 1 / -1; }
.stack { display: grid; gap: 12px; }
pre.code { background: var(--calc); padding: 10px; border-radius: var(--radius); overflow: auto; font-size: 12px; }
.pager { display: flex; gap: 8px; align-items: center; margin-top: 10px; font-size: 13px; color: var(--muted); }
.kbd-hint { font-size: 12px; color: var(--muted); }

/* ---------- auth pages */
body.auth { display: grid; place-items: center; min-height: 100vh; padding: 20px; background: var(--ink); }
.auth-card { background: var(--paper); border-radius: 10px; padding: 26px 28px 30px; width: min(400px, 100%); box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.auth-card.wide { width: min(760px, 100%); }
.auth-card .brand-lockup { padding: 0 0 18px; color: var(--ink); }
.auth-card .brand-lockup .brand-mark { background: var(--ink); color: var(--gold); }
.auth-card h1 { margin-bottom: 14px; }
.auth-card .btn.primary { justify-content: center; padding: 10px; }

/* ---------- responsive */
@media (max-width: 960px) {
  #app { grid-template-columns: 1fr; }
  .side { position: fixed; left: 0; top: 0; bottom: 0; width: 250px; z-index: 40; transform: translateX(-100%); transition: transform .2s; }
  .side.open { transform: none; box-shadow: 0 0 40px rgba(0,0,0,.3); }
  .only-mobile { display: inline-grid; place-items: center; }
  .top { padding: 10px 16px; }
  #view { padding: 16px 16px 60px; }
  .fgrid { grid-template-columns: 1fr 1fr; }
  .ag-item { grid-template-columns: 70px 1fr auto; }
  .ag-item .what, .ag-item .tel { grid-column: 2 / 3; }
  .ag-item .acts { grid-row: 1; grid-column: 3; }
  .opp-row { grid-template-columns: 22px 1fr auto; }
  .opp-row .diff, .opp-row .price { grid-column: 2 / -1; }
  .settings-lists { grid-template-columns: 1fr; }
  .settings-lists nav { flex-direction: row; overflow-x: auto; }
  .form-grid { grid-template-columns: 1fr; }
  .bar-row { grid-template-columns: 120px 1fr 36px; }
  .today-date .day { font-size: 40px; }
  .table-wrap { max-height: none; }
}
@media (max-width: 560px) {
  .fgrid { grid-template-columns: 1fr; }
  .f.w2 { grid-column: auto; }
  .top-tools .btn span.lbl { display: none; }
  .chk { grid-template-columns: 1fr 50px; }
  .chk .cosa { grid-column: 1 / -1; }
  .le-row { grid-template-columns: 1fr 110px 30px; }
  .le-row .h { display: none; }
}
@media print {
  .side, .top-tools, .drawer, .toolbar { display: none !important; }
  #app { display: block; }
  .table-wrap { max-height: none; overflow: visible; border: 0; }
}
.stack label.check { display: flex; align-items: center; gap: 8px; }
