:root {
  --bg: #f4f5f2;
  --surface: #ffffff;
  --ink: #14211c;
  --ink-2: #3d4b45;
  --muted: #6b7772;
  --line: #e2e6e3;
  --brand: #1f4d3f;
  --brand-2: #2f6e5a;
  --brand-soft: #e5efeb;
  --accent: #c8862a;
  --accent-soft: #fbf1e2;
  --neg: #c0492f;
  --neg-soft: #fbe7e2;
  --pos: #2d7a4f;
  --pos-soft: #e1f2e7;
  --fact: #2b5c8a; --fact-soft: #e3edf6;
  --stat: #6b4f9c; --stat-soft: #ece6f5;
  --tip: #b2622a; --tip-soft: #f8e8db;
  --nav-bg: #1f4d3f;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(20, 33, 28, .05), 0 4px 16px rgba(20, 33, 28, .04);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101614; --surface: #18201d; --ink: #e8eeeb; --ink-2: #c3ccc8; --muted: #8d9894; --line: #2a3430;
    --brand: #5fb393; --brand-2: #7cc6a9; --brand-soft: #1d3029; --accent: #e0a24c; --accent-soft: #2e2617;
    --neg: #ec7a5f; --neg-soft: #3a2019; --pos: #6cc391; --pos-soft: #18301f;
    --fact: #86b4e0; --fact-soft: #1b2a38; --stat: #b39ae0; --stat-soft: #2a2238; --tip: #e7a06a; --tip-soft: #36261a;
    --nav-bg: #12241d;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { font-family: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif; background: var(--bg); color: var(--ink); font-size: 14px; line-height: 1.45; }
h1, h2, h3 { margin: 0; }
h1 { font-family: Georgia, "Times New Roman", serif; font-size: 26px; font-weight: 600; letter-spacing: -.3px; }
h2 { font-size: 15px; font-weight: 600; }
h3 { font-size: 14px; font-weight: 600; }
a { color: inherit; }
button, input, select, textarea { font: inherit; color: inherit; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.eyebrow { font-size: 11.5px; text-transform: uppercase; letter-spacing: 1.2px; color: var(--accent); font-weight: 700; margin-bottom: 2px; }

/* Layout */
.app { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.sidebar { background: var(--nav-bg); color: #fff; padding: 22px 14px; display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
.logo { display: flex; align-items: center; gap: 10px; padding: 0 8px 22px; }
.logo b { font-family: Georgia, serif; font-size: 20px; display: block; line-height: 1; }
.logo small { opacity: .7; font-size: 11px; }
.logo-mark { width: 34px; height: 34px; border-radius: 9px; background: var(--accent); color: #fff; display: grid; place-items: center; font-family: Georgia, serif; font-weight: 700; font-size: 18px; }
#nav { display: flex; flex-direction: column; gap: 2px; }
#nav a, .bottom-nav a { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 9px; text-decoration: none; color: rgba(255,255,255,.82); font-weight: 500; }
#nav a:hover { background: rgba(255,255,255,.08); }
#nav a.active { background: rgba(255,255,255,.14); color: #fff; }
#nav svg, .bottom-nav svg { width: 18px; height: 18px; fill: currentColor; flex: none; }
.side-foot { margin-top: auto; padding: 0 8px; }
.side-foot .link { color: rgba(255,255,255,.7); }
.demo-tag { font-size: 11.5px; background: rgba(255,255,255,.1); border-radius: 8px; padding: 8px 10px; margin-bottom: 8px; color: rgba(255,255,255,.85); }
.content { min-width: 0; }
.topbar { display: flex; align-items: center; gap: 12px; padding: 12px 28px; border-bottom: 1px solid var(--line); background: var(--surface); position: sticky; top: 0; z-index: 5; }
.topbar select { border: 1px solid var(--line); background: var(--bg); border-radius: 8px; padding: 7px 10px; max-width: 100%; }
.user { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.user span { color: var(--muted); font-size: 13px; }
main { padding: 26px 28px 60px; max-width: 1280px; }
.mobile-only { display: none; }
.bottom-nav { display: none; }

.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 6px; flex-wrap: wrap; }
.head-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.head-actions select { border: 1px solid var(--line); background: var(--surface); border-radius: 8px; padding: 8px 10px; }

/* Controls */
.seg { display: inline-flex; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 3px; }
.seg button { border: 0; background: none; padding: 6px 14px; border-radius: 7px; cursor: pointer; color: var(--muted); font-weight: 500; }
.seg button.on { background: var(--brand); color: #fff; }
@media (prefers-color-scheme: dark) { .seg button.on { color: #0d1512; } }
.seg.full { display: flex; margin: 14px 0; }
.seg.full button { flex: 1; padding: 10px; }
.btn { border: 1px solid var(--brand); background: var(--brand); color: #fff; padding: 9px 16px; border-radius: 9px; cursor: pointer; font-weight: 600; text-decoration: none; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
@media (prefers-color-scheme: dark) { .btn { color: #0d1512; } }
.btn.ghost { background: transparent; color: var(--brand); }
.btn.small { padding: 5px 10px; font-size: 12.5px; }
.btn.primary { background: var(--brand); }
.btn.rec { background: var(--neg); border-color: var(--neg); color: #fff; }
.link { background: none; border: 0; padding: 0; color: var(--brand); cursor: pointer; text-decoration: none; font-weight: 500; }

/* Panels */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow); margin-top: 16px; min-width: 0; }
.panel-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.grid-main { display: grid; grid-template-columns: 2fr 1fr; gap: 16px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-main > .panel, .grid-2 > .panel { margin-top: 16px; }
.chart-box { height: 280px; position: relative; }
.method { font-size: 11.5px; color: var(--muted); margin: 12px 0 0; border-top: 1px dashed var(--line); padding-top: 8px; }
.empty { color: var(--muted); font-style: italic; }

/* KPI */
.kpis { display: grid; grid-template-columns: repeat(6, 1fr); gap: 12px; margin-top: 14px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); min-width: 0; }
.kpi-label { font-size: 12px; color: var(--muted); font-weight: 600; display: flex; align-items: center; gap: 6px; }
.kpi-value { font-size: 23px; font-weight: 650; margin: 4px 0 6px; letter-spacing: -.4px; font-variant-numeric: tabular-nums; }
.kpi-sub { display: flex; flex-wrap: wrap; gap: 4px 8px; }
.delta { font-size: 11.5px; color: var(--muted); font-variant-numeric: tabular-nums; }
.delta.up { color: var(--pos); font-weight: 600; }
.delta.down { color: var(--neg); font-weight: 600; }
.info { width: 15px; height: 15px; border-radius: 50%; border: 1px solid var(--muted); font-size: 10px; display: inline-grid; place-items: center; cursor: help; font-style: italic; font-family: Georgia, serif; }

/* Split pranzo/cena */
.split { display: flex; flex-direction: column; gap: 18px; }
.split-top { display: flex; justify-content: space-between; margin-bottom: 6px; font-variant-numeric: tabular-nums; }
.bar { height: 8px; background: var(--bg); border-radius: 4px; overflow: hidden; }
.bar span { display: block; height: 100%; border-radius: 4px; }
.bar .pranzo { background: var(--accent); }
.bar .cena { background: var(--brand); }
.split dl { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 12px; margin: 10px 0 0; }
.split dt { font-size: 11.5px; color: var(--muted); }
.split dd { margin: 0; font-weight: 600; font-variant-numeric: tabular-nums; }
dd.neg, .neg-text { color: var(--neg); font-weight: 600; }
dd.pos { color: var(--pos); }

/* Lists */
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); align-items: flex-start; }
.list li:last-child { border-bottom: 0; }
.badge { flex: none; min-width: 52px; text-align: center; font-size: 12px; font-weight: 700; padding: 4px 6px; border-radius: 7px; font-variant-numeric: tabular-nums; }
.badge.neg { background: var(--neg-soft); color: var(--neg); }
.badge.pos { background: var(--pos-soft); color: var(--pos); }
.badge.net { background: var(--stat-soft); color: var(--stat); }
.badge.rec { background: var(--accent-soft); color: var(--accent); }
.context { margin-top: 3px; color: var(--ink-2); border-left: 2px solid var(--accent); padding-left: 8px; }
.mini-kpis { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 8px; }
.mini-kpis div { background: var(--bg); border-radius: 9px; padding: 10px 12px; }
.mini-kpis b { font-size: 22px; display: block; }
.mini-kpis span { font-size: 12px; color: var(--muted); }
.mini-kpis .warn b { color: var(--neg); }

/* Table */
.table-wrap { overflow-x: auto; }
.tbl { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.tbl th { text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); font-weight: 600; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.tbl td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
.tbl .r { text-align: right; }
.tbl tr.clickable { cursor: pointer; }
.tbl tr.clickable:hover td { background: var(--bg); }
.chip { display: inline-block; font-size: 11.5px; padding: 2px 8px; border-radius: 20px; background: var(--bg); color: var(--ink-2); font-weight: 600; white-space: nowrap; }
.chip.neg { background: var(--neg-soft); color: var(--neg); }
.chip.pos { background: var(--pos-soft); color: var(--pos); }
.chip.cat { background: var(--brand-soft); color: var(--brand); }
.chip.prio-alta { background: var(--neg-soft); color: var(--neg); }
.chip.prio-media { background: var(--accent-soft); color: var(--accent); }
.chip.st-aperta { background: var(--accent-soft); color: var(--accent); }
.chip.st-incorso { background: var(--fact-soft); color: var(--fact); }
.chip.st-chiusa { background: var(--pos-soft); color: var(--pos); }

/* Pills AI */
.pill { display: inline-block; font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .5px; padding: 3px 8px; border-radius: 20px; white-space: nowrap; }
.pill.fact { background: var(--fact-soft); color: var(--fact); }
.pill.stat { background: var(--stat-soft); color: var(--stat); }
.pill.tip { background: var(--tip-soft); color: var(--tip); }
.pill.ai { background: var(--accent-soft); color: var(--accent); }
.ai-rows { display: flex; flex-direction: column; }
.ai-row { display: grid; grid-template-columns: 110px 1fr; gap: 12px; padding: 9px 0; border-bottom: 1px dashed var(--line); }
.ai-row:last-child { border-bottom: 0; }
.ai-row > .pill { justify-self: start; align-self: start; }
.src { color: var(--muted); font-size: 12px; }
.summary h2 { display: flex; gap: 8px; align-items: center; }

/* Chiusura */
.closing { max-width: 640px; }
.timer { font-variant-numeric: tabular-nums; background: var(--brand-soft); color: var(--brand); padding: 6px 12px; border-radius: 20px; font-weight: 600; }
.timer.late { background: var(--neg-soft); color: var(--neg); }
.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.fields { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.fld { display: flex; flex-direction: column; gap: 4px; }
.fld > span { font-size: 12px; color: var(--muted); font-weight: 600; }
.fld input, .fld select, .fld textarea, .dictate textarea { border: 1px solid var(--line); background: var(--bg); border-radius: 9px; padding: 10px 12px; width: 100%; }
.fld input:focus, .fld textarea:focus, .dictate textarea:focus, .fld select:focus { outline: 2px solid var(--brand); outline-offset: -1px; }
.inp { position: relative; }
.inp input { font-size: 17px; font-variant-numeric: tabular-nums; padding-right: 34px; }
.inp em { position: absolute; right: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); font-style: normal; }
.import-row { display: flex; align-items: center; gap: 14px; margin-top: 14px; flex-wrap: wrap; }
.stars { display: flex; gap: 6px; margin-top: 8px; }
.stars button { font-size: 30px; line-height: 1; background: none; border: 0; cursor: pointer; color: var(--line); padding: 0 2px; }
.stars button.on { color: var(--accent); }
.stars.sm { font-size: 15px; color: var(--accent); margin: 0; letter-spacing: 1px; }
.stars.sm span { color: var(--line); }
.dictate textarea { resize: vertical; min-height: 110px; margin-top: 6px; }
.dictate-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 8px; flex-wrap: wrap; }
.structured { margin-top: 16px; display: flex; flex-direction: column; gap: 10px; border-top: 1px solid var(--line); padding-top: 14px; }
.ai-note { font-size: 12.5px; color: var(--ink-2); }
.proposals { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 6px; }
.proposals label { display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; background: var(--bg); padding: 8px 10px; border-radius: 8px; }
.sticky-save { position: sticky; bottom: 0; display: flex; justify-content: flex-end; gap: 10px; padding: 14px 0; background: linear-gradient(transparent, var(--bg) 35%); margin-top: 8px; }
.sticky-save .btn { padding: 12px 22px; }

/* Diario */
.diary-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 14px; margin-top: 16px; }
.diary { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); }
.diary header { display: flex; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.diary p { margin: 0 0 8px; color: var(--ink-2); }
.dfields { margin: 0; display: flex; flex-direction: column; gap: 6px; }
.dfields dt { font-size: 11px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); font-weight: 600; }
.dfields dd { margin: 0; color: var(--ink-2); }
.seg-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }

/* Criticità */
.rec-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; }
.rec-card { border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; }
.rec-card.rete { border-color: var(--stat); }
.rec-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.rec-card h3 { font-size: 15px; }
.rec-card .dates { margin-top: 6px; color: var(--ink-2); }
.board { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.col { background: var(--bg); border-radius: 10px; padding: 10px; min-width: 0; }
.col-head { font-weight: 600; font-size: 13px; margin: 2px 4px 10px; display: flex; justify-content: space-between; }
.col-head span { color: var(--muted); }
.act { background: var(--surface); border: 1px solid var(--line); border-radius: 9px; padding: 10px 12px; margin-bottom: 8px; display: flex; flex-direction: column; gap: 3px; }
.act.overdue { border-left: 3px solid var(--neg); }
.act-top { display: flex; gap: 6px; margin-bottom: 2px; }
.act .btn { align-self: flex-start; margin-top: 6px; }
.inline-form td { background: var(--brand-soft); }
.act-form { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }
.act-form .grow { flex: 1 1 280px; }
.act-form-btns { display: flex; gap: 6px; }

/* Report */
.report-doc { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 28px 32px; margin-top: 16px; box-shadow: var(--shadow); max-width: 900px; }
.rep-head { display: flex; justify-content: space-between; gap: 18px; flex-wrap: wrap; border-bottom: 1px solid var(--line); padding-bottom: 16px; }
.rep-head h2 { font-family: Georgia, serif; font-size: 22px; font-weight: 600; margin: 2px 0 4px; }
.legend { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; font-size: 12px; color: var(--muted); }
.rep-kpis { display: grid; grid-template-columns: repeat(5, 1fr); gap: 10px; margin: 18px 0 8px; }
.rep-kpis div { background: var(--bg); border-radius: 9px; padding: 10px 12px; display: flex; flex-direction: column; }
.rep-kpis span { font-size: 11.5px; color: var(--muted); }
.rep-kpis b { font-size: 18px; font-variant-numeric: tabular-nums; }
.rep-kpis em { font-style: normal; font-size: 12px; color: var(--muted); }
.rep-kpis em.neg { color: var(--neg); font-weight: 600; }
.rep-kpis em.pos { color: var(--pos); font-weight: 600; }
.report-doc h3 { font-family: Georgia, serif; font-size: 17px; margin: 22px 0 6px; color: var(--brand); }
.rep-summary { font-size: 15px; color: var(--ink-2); margin: 0; }
.rep-foot { margin-top: 24px; padding-top: 12px; border-top: 1px solid var(--line); font-size: 12px; color: var(--muted); }

/* Toast */
.toast { position: fixed; left: 50%; bottom: 28px; transform: translate(-50%, 20px); background: var(--ink); color: var(--bg); padding: 11px 18px; border-radius: 10px; opacity: 0; pointer-events: none; transition: .25s; z-index: 50; max-width: calc(100vw - 32px); }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* Responsive */
@media (max-width: 1200px) { .kpis { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 980px) {
  .grid-main, .grid-2 { grid-template-columns: 1fr; }
  .grid-main > .panel, .grid-2 > .panel { margin-top: 0; }
  .grid-main, .grid-2 { gap: 0; }
  .grid-main > .panel, .grid-2 > .panel { margin-top: 16px; }
  .rep-kpis { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .mobile-only { display: flex; }
  .desktop-only { display: none; }
  .topbar { padding: 10px 16px; flex-wrap: wrap; }
  .topbar .logo { padding: 0; }
  .topbar .logo b { font-size: 18px; }
  .topbar #scopeSel { order: 3; flex: 1 1 100%; }
  main { padding: 18px 16px 90px; }
  h1 { font-size: 22px; }
  .kpis { grid-template-columns: 1fr 1fr; gap: 10px; }
  .kpi { padding: 12px; }
  .kpi-value { font-size: 19px; }
  .seg { width: 100%; }
  .seg button { flex: 1; padding: 6px 4px; }
  .board { grid-template-columns: 1fr; }
  .diary-list { grid-template-columns: 1fr; }
  .fields, .row-2 { grid-template-columns: 1fr 1fr; }
  .ai-row { grid-template-columns: 1fr; gap: 4px; }
  .report-doc { padding: 18px 16px; }
  .rep-kpis { grid-template-columns: 1fr 1fr; }
  .bottom-nav { display: flex; position: fixed; bottom: 0; left: 0; right: 0; background: var(--nav-bg); z-index: 10; padding: 4px 4px calc(4px + env(safe-area-inset-bottom)); }
  .bottom-nav a { flex: 1; flex-direction: column; gap: 2px; padding: 6px 2px; font-size: 10px; text-align: center; }
  .bottom-nav a.active { color: #fff; background: rgba(255,255,255,.14); }
  .sticky-save { bottom: 60px; }
}

@media print {
  .sidebar, .topbar, .bottom-nav, .no-print, .toast { display: none !important; }
  .app { display: block; }
  body { background: #fff; }
  main { padding: 0; }
  .report-doc { border: 0; box-shadow: none; padding: 0; max-width: none; }
}
