:root {
  /* --- Brand Panetteria Sardà (dai colori del logo) --- */
  --brand: #89291c;          /* marrone-mattone del logo */
  --brand-ink: #6c1f14;      /* piu' scuro (hover/primary hover) */
  --brand-soft: #f6e7e2;     /* tinta chiarissima per stati soft */
  --gold: #b8860b;           /* oro (accento secondario) */
  --cream: #fffccc;          /* crema del logo (usata con parsimonia) */

  /* --- Superfici neutre calde --- */
  --bg: #f5f2ec;
  --surface: #ffffff;
  --surface-2: #faf7f1;
  --border: #ece5da;
  --border-strong: #ddd4c6;
  --text: #2a221c;
  --text-2: #776d62;

  /* --- Sidebar scura (espresso) --- */
  --side-bg: #2a1611;
  --side-bg-2: #3b231b;
  --side-text: #ece0d4;
  --side-muted: #b39c8e;

  --pos: #2f7d5b;
  --neg: #c1492e;

  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(42,22,17,.05), 0 10px 30px rgba(42,22,17,.07);
  --shadow-sm: 0 1px 2px rgba(42,22,17,.05), 0 2px 8px rgba(42,22,17,.04);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --serif: Georgia, "Iowan Old Style", "Times New Roman", serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0; font-family: var(--font); color: var(--text); background: var(--bg);
  font-size: 14.5px; line-height: 1.5; -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -0.01em; }
.muted { color: var(--text-2); }
.num { text-align: right; font-variant-numeric: tabular-nums; }
button { font-family: inherit; cursor: pointer; }

/* ---------- Bottoni ---------- */
.btn {
  border: 1px solid transparent; border-radius: var(--radius-sm);
  padding: .55rem .95rem; font-size: 14px; font-weight: 550;
  transition: background .15s, border-color .15s, color .15s, transform .05s, box-shadow .15s;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--brand); color: #fff; box-shadow: 0 1px 2px rgba(137,41,28,.25); }
.btn-primary:hover { background: var(--brand-ink); }
.btn-ghost { background: transparent; color: var(--text-2); border-color: var(--border-strong); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); border-color: var(--border-strong); }
.btn-sm { padding: .4rem .75rem; font-size: 13px; }

/* ---------- Login ---------- */
.login { min-height: 100%; display: grid; place-items: center; gap: 1rem; padding: 2rem; align-content: center;
  background: radial-gradient(1200px 600px at 50% -10%, #fff 0%, var(--bg) 55%); }
.login-card {
  width: 100%; max-width: 390px; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 2.2rem; display: grid; gap: 1.1rem;
}
.brand { display: flex; align-items: center; gap: 1rem; margin-bottom: .3rem; }
.brand-logo { width: 64px; height: 64px; object-fit: contain; }
.brand h1 { font-family: var(--serif); font-weight: 700; font-size: 1.4rem; color: var(--brand); }
.brand .muted { font-size: .85rem; margin: .12rem 0 0; }
.field { display: grid; gap: .35rem; }
.field span { font-size: .82rem; color: var(--text-2); font-weight: 550; }
.field input, .fld input, .fld select {
  width: 100%; padding: .62rem .72rem; font-size: 15px; color: var(--text);
  background: var(--surface-2); border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm); outline: none; transition: border-color .15s, box-shadow .15s, background .15s;
}
.field input:focus, .fld input:focus, .fld select:focus {
  border-color: var(--brand); background: #fff; box-shadow: 0 0 0 3px var(--brand-soft);
}
.login .btn-primary { padding: .72rem; font-size: 15px; }
.error { color: var(--neg); font-size: .85rem; margin: 0; }
.login-foot { font-size: .8rem; }

/* ---------- App shell: sidebar + main ---------- */
.app-shell { display: grid; grid-template-columns: 252px 1fr; min-height: 100%; transition: grid-template-columns .18s ease; }
.sidebar {
  position: sticky; top: 0; height: 100vh; z-index: 30; overflow: hidden;
  background: var(--surface); color: var(--text);
  display: flex; flex-direction: column; padding: 1rem .7rem;
  border-right: 1px solid var(--border);
}
.side-brand { display: flex; align-items: center; gap: .7rem; padding: .6rem .5rem 1.2rem; min-height: 72px; }
.side-brand .brand-logo { width: 56px; height: 56px; flex-shrink: 0; object-fit: contain; }
.side-brand-txt { display: flex; flex-direction: column; line-height: 1.15; white-space: nowrap; overflow: hidden; }
.side-brand-txt strong { font-family: var(--serif); font-size: 1.14rem; color: var(--brand); letter-spacing: .01em; }
.side-brand-txt span { font-size: .74rem; color: var(--text-2); }
.side-nav { display: flex; flex-direction: column; gap: .2rem; }
.nav-item {
  display: flex; align-items: center; gap: .8rem; width: 100%;
  background: none; border: none; text-align: left;
  padding: .64rem .7rem; border-radius: var(--radius-sm);
  color: var(--text-2); font-size: .93rem; font-weight: 550; white-space: nowrap;
  transition: background .15s, color .15s;
}
.nav-item svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }
.nav-item span { overflow: hidden; }
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active { background: var(--brand-soft); color: var(--brand-ink); font-weight: 650; }
.nav-badge { margin-left: auto; background: var(--neg); color: #fff; font-size: .68rem; font-weight: 700; padding: .06rem .42rem; border-radius: 999px; line-height: 1.5; }
.side-bottom { margin-top: auto; padding-top: .5rem; border-top: 1px solid var(--border); }
.collapse-btn {
  display: flex; align-items: center; gap: .8rem; width: 100%;
  background: none; border: none; text-align: left;
  padding: .55rem .7rem; border-radius: var(--radius-sm);
  color: var(--text-2); font-size: .85rem; font-weight: 550; white-space: nowrap;
  transition: background .15s, color .15s;
}
.collapse-btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; transition: transform .18s ease; }
.collapse-btn:hover { background: var(--surface-2); color: var(--text); }
.side-foot { padding: .55rem .7rem .2rem; font-family: var(--serif); font-style: italic; font-size: .8rem; color: var(--text-2); white-space: nowrap; overflow: hidden; }
.side-backdrop { position: fixed; inset: 0; background: rgba(30,18,12,.4); z-index: 25; }

.main { min-width: 0; display: flex; flex-direction: column; }

/* ---------- Topbar (slim, contestuale) ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20; background: rgba(255,255,255,.82);
  backdrop-filter: saturate(1.4) blur(10px); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: .7rem 1.5rem;
}
.topbar-left { display: flex; align-items: center; gap: .7rem; min-width: 0; }
.topbar-left h1 { font-family: var(--serif); font-size: 1.3rem; font-weight: 700; color: var(--text); letter-spacing: 0; }
.topbar-right { display: flex; align-items: center; gap: .55rem; flex-wrap: wrap; justify-content: flex-end; }
.icon-btn { display: none; background: none; border: none; padding: .35rem; border-radius: 8px; color: var(--text-2); }
.icon-btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; }
.icon-btn:hover { background: var(--surface-2); }
.chip { font-size: .82rem; color: var(--brand-ink); background: var(--brand-soft); border-radius: 999px; padding: .3rem .75rem; font-weight: 550; }

.content { padding: 1.5rem; max-width: 1240px; margin: 0 auto; width: 100%; }
.view { width: 100%; }

/* ---------- Sub-tabs (magazzino) ---------- */
.subtabs { display: flex; gap: .3rem; margin-bottom: 1.2rem; background: var(--surface-2); border: 1px solid var(--border); padding: .25rem; border-radius: 999px; width: fit-content; }
.subtab { background: none; border: none; padding: .4rem 1rem; border-radius: 999px; font-size: .88rem; font-weight: 550; color: var(--text-2); transition: background .15s, color .15s; }
.subtab:hover { color: var(--text); }
.subtab.active { background: var(--surface); color: var(--brand-ink); box-shadow: var(--shadow-sm); }
.chk { display: flex; align-items: center; gap: .4rem; font-size: .85rem; color: var(--text-2); }
.chk input { width: auto; accent-color: var(--brand); }
.mono { font-family: ui-monospace, "Cascadia Code", Consolas, monospace; font-size: .82rem; }
.modal-sm { max-width: 430px; }

/* ---------- KPI ---------- */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 1rem; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.15rem 1.25rem; box-shadow: var(--shadow-sm); position: relative; overflow: hidden; }
.kpi::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--brand); opacity: .0; transition: opacity .15s; }
.kpi:hover::before { opacity: .55; }
.kpi .k-label { font-size: .76rem; color: var(--text-2); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
.kpi .k-value { font-size: 1.7rem; font-weight: 700; letter-spacing: -0.02em; margin-top: .3rem; font-variant-numeric: tabular-nums; color: var(--text); }
.kpi .k-sub { font-size: .8rem; color: var(--text-2); margin-top: .25rem; }
.k-sub.up { color: var(--pos); font-weight: 550; }
.k-sub.down { color: var(--neg); font-weight: 550; }

/* ---------- Pannelli / barlist ---------- */
.panels { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin-top: 1rem; }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.15rem 1.25rem; box-shadow: var(--shadow-sm); }
.panel-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 1rem; }
.panel-head h3 { font-family: var(--serif); font-size: 1.05rem; font-weight: 700; }
.panel-head .muted { font-size: .8rem; }
.barlist { display: grid; gap: .65rem; }
.bar-row { display: grid; grid-template-columns: 116px 1fr auto; align-items: center; gap: .75rem; font-size: .88rem; }
.bar-row .lbl { color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-track { display: block; background: var(--surface-2); border-radius: 999px; height: 9px; overflow: hidden; }
.bar-fill { display: block; height: 100%; min-width: 6px; background: linear-gradient(90deg, var(--brand), #c06a4f); border-radius: 999px; }
.bar-row .val { font-variant-numeric: tabular-nums; color: var(--text-2); font-weight: 600; }

/* ---------- Andamento (vista titolare) ---------- */
.hero .hero-note { max-width: 46%; text-align: right; font-size: .76rem; line-height: 1.35; }
.statrow { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: .9rem; }
.stat { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: .8rem .9rem; background: var(--surface-2); }
.stat .s-label { font-size: .72rem; color: var(--text-2); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
.stat .s-value { font-size: 1.42rem; font-weight: 750; letter-spacing: -0.02em; margin-top: .2rem; font-variant-numeric: tabular-nums; }
.stat .s-sub { font-size: .78rem; color: var(--text-2); margin-top: .15rem; }
.stat .s-sub.up { color: var(--pos); font-weight: 600; }
.stat .s-sub.down { color: var(--neg); font-weight: 600; }

.yoylist { display: grid; gap: .7rem; }
.yoy-row { display: grid; grid-template-columns: 104px 1fr 74px 58px; align-items: center; gap: .7rem; font-size: .88rem; }
.yoy-row .lbl { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.yoy-track { position: relative; background: var(--surface-2); border-radius: 999px; height: 10px; overflow: hidden; }
.yoy-fill { position: absolute; left: 0; top: 0; height: 100%; min-width: 4px; background: linear-gradient(90deg, var(--brand), #c06a4f); border-radius: 999px; }
.yoy-prev { position: absolute; top: -2px; height: 14px; width: 2px; background: var(--text-2); opacity: .55; }
.yoy-row .cur { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
.yoy-row .delta { text-align: right; font-variant-numeric: tabular-nums; font-weight: 650; font-size: .82rem; }

/* mini-chart mensile + previsione */
.mchart { display: flex; align-items: flex-end; gap: 4px; height: 132px; padding-top: 6px; }
.mcol { flex: 1 1 0; display: flex; flex-direction: column; align-items: center; gap: 4px; height: 100%; justify-content: flex-end; }
.mbar { width: 100%; max-width: 26px; border-radius: 4px 4px 0 0; min-height: 3px; background: var(--brand); transition: opacity .15s; }
.mbar.pos { background: var(--pos); }
.mbar.neg { background: var(--brand); }
.mcol.fc .mbar { opacity: .42; background-image: repeating-linear-gradient(45deg, rgba(255,255,255,.45) 0 3px, transparent 3px 6px); }
.mcol .mlabel { font-size: .68rem; color: var(--text-2); font-variant-numeric: tabular-nums; }
.mchart-legend { display: flex; flex-wrap: wrap; gap: .35rem 1rem; margin-top: .7rem; font-size: .74rem; color: var(--text-2); }
.mchart-legend .lg { display: inline-flex; align-items: center; gap: .35rem; }
.mchart-legend .sw { width: 11px; height: 11px; border-radius: 3px; display: inline-block; }
.mchart-legend .sw.pos { background: var(--pos); } .mchart-legend .sw.neg { background: var(--brand); }
.mchart-legend .sw.fc { background: var(--brand); opacity: .42; background-image: repeating-linear-gradient(45deg, rgba(255,255,255,.5) 0 3px, transparent 3px 6px); }

/* ---------- Ordini (magazzino) ---------- */
.qty-col { width: 108px; }
.or-qty { width: 84px; text-align: right; padding: .35rem .5rem; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); font-family: inherit; font-size: 14px; font-variant-numeric: tabular-nums; }
.or-qty:focus { outline: 2px solid var(--brand-soft); border-color: var(--brand); }
.order-foot { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-top: 1rem; flex-wrap: wrap; }
.order-total { font-size: 1rem; }
.order-total b { font-size: 1.25rem; font-weight: 750; color: var(--brand); font-variant-numeric: tabular-nums; margin: 0 .35rem; }
.order-actions { display: flex; gap: .6rem; margin-top: .8rem; }
.order-msg { width: 100%; margin-top: 1rem; padding: .9rem 1rem; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); font-family: ui-monospace, "Cascadia Code", Menlo, Consolas, monospace; font-size: 13.5px; line-height: 1.5; background: var(--surface-2); color: var(--text); resize: vertical; }
a.btn { text-decoration: none; display: inline-flex; align-items: center; }

/* ---------- Scadenzario a calendario ---------- */
.cal-top { display: flex; align-items: center; gap: .55rem; margin-bottom: .9rem; flex-wrap: wrap; }
.cal-title { font-family: var(--serif); font-size: 1.18rem; font-weight: 700; min-width: 168px; text-align: center; }
.cal-spacer { flex: 1; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.cal-wd { font-size: .7rem; font-weight: 650; color: var(--text-2); text-transform: uppercase; letter-spacing: .04em; text-align: center; padding: .15rem 0; }
.cal-cell { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; min-height: 98px; padding: .35rem .4rem .45rem; box-shadow: var(--shadow-sm); }
.cal-cell.off { background: transparent; border-color: transparent; box-shadow: none; }
.cal-cell.today { border-color: var(--brand); box-shadow: 0 0 0 1px var(--brand); background: #fdf6f4; }
.cal-daynum { font-size: .76rem; font-weight: 700; color: var(--text-2); }
.cal-cell.today .cal-daynum { color: var(--brand-ink); }
.cal-dw { display: none; }   /* giorno della settimana: solo nella vista agenda mobile */
.cal-chip { display: block; width: 100%; text-align: left; border: 1px solid var(--border-strong); background: var(--surface-2); color: var(--text); border-radius: 7px; padding: .16rem .4rem; font-size: .68rem; line-height: 1.3; margin-top: 3px; cursor: pointer; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; font-family: inherit; }
.cal-chip:hover { border-color: var(--brand); }
.cal-chip b { font-variant-numeric: tabular-nums; font-weight: 650; }
.cal-chip.due { border-color: #e6cbc2; background: #fdf3f0; color: var(--brand-ink); }
.cal-chip.late { border-color: #f0d5cd; background: #fbeeea; color: var(--neg); font-weight: 600; }
.cal-chip.paid { border-color: #cfe8dd; background: #eef7f2; color: var(--pos); opacity: .85; }
.cal-chip.paid { text-decoration: line-through; text-decoration-thickness: 1px; }
.cal-chip.rec { border-style: dashed; background: var(--surface); color: var(--text-2); }
.cal-note { margin-top: .8rem; font-size: .78rem; }
@media (max-width: 860px) {
  .cal-grid { gap: 3px; }
  .cal-cell { min-height: 64px; padding: .2rem .25rem; border-radius: 7px; }
  .cal-chip { font-size: .58rem; padding: .1rem .25rem; }
}

/* ---------- Lista scadenze (dashboard) ---------- */
.scad-list { display: grid; }
.scad-row { display: grid; grid-template-columns: 92px 1fr auto; align-items: center; gap: .8rem; padding: .5rem .1rem; border-bottom: 1px solid var(--border); font-size: .9rem; }
.scad-row:last-child { border-bottom: none; }
.scad-date { font-variant-numeric: tabular-nums; color: var(--text-2); font-weight: 600; white-space: nowrap; }
.scad-desc { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.scad-imp { font-variant-numeric: tabular-nums; font-weight: 600; }

/* ---------- Filtri ---------- */
.filters { display: flex; flex-wrap: wrap; gap: .8rem; align-items: end; margin-bottom: 1.2rem; }
.fld { display: grid; gap: .3rem; }
.fld span { font-size: .76rem; color: var(--text-2); font-weight: 600; }
.count { margin-left: auto; align-self: center; font-size: .85rem; }

/* ---------- Tabella ---------- */
.table-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-sm); overflow-x: auto; overflow-y: hidden; -webkit-overflow-scrolling: touch; }
.grid { width: 100%; border-collapse: collapse; font-size: 14px; }
.grid thead th { text-align: left; font-weight: 600; font-size: .74rem; letter-spacing: .04em; text-transform: uppercase; color: var(--text-2); padding: .75rem 1rem; background: var(--surface-2); border-bottom: 1px solid var(--border); white-space: nowrap; }
.grid thead th.num { text-align: right; }
.grid tbody td { padding: .65rem 1rem; border-bottom: 1px solid var(--border); }
.grid tbody tr:last-child td { border-bottom: none; }
.grid tbody tr { cursor: pointer; transition: background .1s; }
.grid tbody tr:hover { background: var(--brand-soft); }
.money { font-variant-numeric: tabular-nums; }
.diff-pos { color: var(--pos); font-weight: 550; }
.diff-neg { color: var(--neg); font-weight: 550; }
.diff-zero { color: var(--text-2); }
.badge { font-size: .72rem; font-weight: 600; padding: .16rem .58rem; border-radius: 999px; background: var(--surface-2); color: var(--text-2); border: 1px solid var(--border); }
.badge-in { color: var(--pos); background: #eef7f2; border-color: #cfe8dd; }
.badge-out { color: var(--neg); background: #fbeeea; border-color: #f0d5cd; }
.empty { padding: 2.5rem; text-align: center; color: var(--text-2); }

/* ---------- Drawer dettaglio ---------- */
.backdrop { position: fixed; inset: 0; background: rgba(30,18,12,.34); z-index: 40; animation: fade .15s; }
.drawer { position: fixed; top: 0; right: 0; height: 100%; width: min(500px, 94vw); z-index: 50; background: var(--surface); border-left: 1px solid var(--border); box-shadow: -14px 0 44px rgba(42,22,17,.16); display: flex; flex-direction: column; animation: slide .2s ease; }
@keyframes slide { from { transform: translateX(100%); } to { transform: translateX(0); } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.drawer-head { display: flex; align-items: start; justify-content: space-between; padding: 1.3rem; border-bottom: 1px solid var(--border); }
.drawer-head h2 { font-family: var(--serif); font-size: 1.2rem; font-weight: 700; }
.drawer-head .muted { font-size: .85rem; margin: .25rem 0 0; }
.drawer-body { padding: 1.3rem; overflow-y: auto; }
.drawer-body h3 { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--brand-ink); margin: 1.5rem 0 .7rem; }
.drawer-body h3:first-child { margin-top: 0; }
.totrow { display: grid; grid-template-columns: repeat(2, 1fr); gap: .7rem; }
.totrow .t { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: .7rem .85rem; }
.totrow .t .tl { font-size: .76rem; color: var(--text-2); }
.totrow .t .tv { font-size: 1.12rem; font-weight: 650; font-variant-numeric: tabular-nums; margin-top: .1rem; }
.chips { display: flex; flex-wrap: wrap; gap: .5rem; }
.rchip { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: .4rem .65rem; font-size: .84rem; }
.rchip b { font-variant-numeric: tabular-nums; }
.mini { width: 100%; border-collapse: collapse; }
.mini td { padding: .5rem .3rem; border-bottom: 1px solid var(--border); font-size: .88rem; }
.mini tr:last-child td { border-bottom: none; }
.mini .v-in { color: var(--pos); font-weight: 600; }
.mini .v-out { color: var(--neg); font-weight: 600; }

/* ---------- Modale ---------- */
.modal { position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%); width: min(760px, 94vw); max-height: 92vh; z-index: 50; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: 0 26px 76px rgba(42,22,17,.26); display: flex; flex-direction: column; animation: pop .18s ease; }
@keyframes pop { from { opacity: 0; transform: translate(-50%, -47%) scale(.98); } to { opacity: 1; transform: translate(-50%, -50%) scale(1); } }
.modal-head { display: flex; align-items: start; justify-content: space-between; padding: 1.2rem 1.3rem; border-bottom: 1px solid var(--border); }
.modal-head h2 { font-family: var(--serif); font-size: 1.25rem; font-weight: 700; }
.modal-head .muted { font-size: .82rem; margin: .15rem 0 0; }
.modal-body { padding: .3rem 1.3rem 1rem; overflow-y: auto; }
.modal-body h3 { font-size: .76rem; text-transform: uppercase; letter-spacing: .04em; color: var(--brand-ink); margin: 1.4rem 0 .7rem; display: flex; align-items: center; gap: .8rem; }
.modal-foot { display: flex; align-items: center; justify-content: flex-end; gap: 1rem; padding: 1rem 1.3rem; border-top: 1px solid var(--border); }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: .8rem; }
.form-grid input, .form-grid select { padding: .55rem .6rem; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); background: var(--surface-2); font-size: 14.5px; width: 100%; }
.reparti-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: .55rem; }
.reparti-grid .rep { display: grid; gap: .25rem; }
.reparti-grid .rep span { font-size: .74rem; color: var(--text-2); }
.reparti-grid .rep input { padding: .42rem .5rem; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); background: var(--surface-2); font-size: 13.5px; }
.mov-list { display: grid; gap: .55rem; }
.mov-row { display: grid; grid-template-columns: 96px 1fr 108px 120px 30px; gap: .5rem; align-items: center; }
.mov-row select, .mov-row input { padding: .45rem .5rem; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); background: var(--surface-2); font-size: 13.5px; width: 100%; }
.mov-row .del { border: none; background: none; color: var(--neg); font-size: 1.2rem; line-height: 1; cursor: pointer; padding: 0; }
.quad-live { margin-top: 1.3rem; padding: .85rem 1.1rem; background: var(--brand-soft); border: 1px solid #ecd6cf; border-radius: var(--radius-sm); font-size: .95rem; display: flex; justify-content: space-between; align-items: center; }
.quad-live b { font-variant-numeric: tabular-nums; font-size: 1.05rem; }
.toast { position: fixed; bottom: 1.5rem; left: 50%; transform: translateX(-50%); z-index: 60; background: var(--text); color: #fff; padding: .7rem 1.2rem; border-radius: 999px; font-size: .9rem; box-shadow: var(--shadow); animation: fade .2s; }

/* ---------- Sola consultazione (VIEWER) ---------- */
.readonly #sc-add, .readonly #sc-add2, .readonly #or-gen { display: none !important; }
.readonly .or-qty { pointer-events: none; opacity: .45; }

/* ---------- Assistente AI ---------- */
.ai-fab { position: fixed; right: 1.1rem; bottom: 1.1rem; z-index: 55; width: 54px; height: 54px; border-radius: 50%; border: none; background: var(--brand); color: #fff; box-shadow: 0 6px 22px rgba(137,41,28,.4); display: flex; align-items: center; justify-content: center; cursor: pointer; transition: transform .1s, background .15s; }
.ai-fab:hover { background: var(--brand-ink); }
.ai-fab:active { transform: scale(.95); }
.ai-fab svg { width: 26px; height: 26px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.ai-panel { position: fixed; right: 1.1rem; bottom: 5.4rem; z-index: 56; width: min(380px, calc(100vw - 2.2rem)); height: min(520px, 70vh); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: 0 18px 60px rgba(42,22,17,.28); display: flex; flex-direction: column; animation: pop .18s ease; transform: none; top: auto; left: auto; }
.ai-head { display: flex; align-items: center; justify-content: space-between; padding: .8rem 1rem; border-bottom: 1px solid var(--border); }
.ai-head b { font-family: var(--serif); font-size: 1rem; }
.ai-sub { display: block; font-size: .72rem; }
.ai-msgs { flex: 1; overflow-y: auto; padding: .9rem; display: flex; flex-direction: column; gap: .55rem; }
.ai-m { max-width: 88%; padding: .55rem .8rem; border-radius: 14px; font-size: .88rem; line-height: 1.45; white-space: pre-wrap; }
.ai-bot { background: var(--surface-2); border: 1px solid var(--border); align-self: flex-start; border-bottom-left-radius: 5px; }
.ai-user { background: var(--brand); color: #fff; align-self: flex-end; border-bottom-right-radius: 5px; }
.ai-err { color: var(--neg); }
.ai-form { display: flex; gap: .5rem; padding: .7rem; border-top: 1px solid var(--border); }
.ai-form input { flex: 1; padding: .55rem .7rem; border: 1px solid var(--border-strong); border-radius: 999px; font-size: .9rem; background: var(--surface-2); min-width: 0; }
.ai-form input:focus { outline: 2px solid var(--brand-soft); border-color: var(--brand); }
@media (max-width: 560px) {
  .ai-panel { right: .6rem; left: .6rem; width: auto; bottom: 4.9rem; height: min(560px, 74dvh); }
  .ai-fab { right: .9rem; bottom: .9rem; }
}

/* ---------- Responsive ---------- */
@media (max-width: 860px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: 0; top: 0; width: 250px; transform: translateX(-100%); transition: transform .2s ease; }
  .sidebar.open { transform: translateX(0); }
  .icon-btn { display: inline-flex; }
  .content { padding: 1.1rem; }
}
@media (min-width: 861px) {
  .side-backdrop { display: none !important; }
  /* sidebar compressa a soli icone */
  .app-shell.collapsed { grid-template-columns: 76px 1fr; }
  .app-shell.collapsed .side-brand { justify-content: center; padding-left: 0; padding-right: 0; }
  .app-shell.collapsed .side-brand-txt,
  .app-shell.collapsed .nav-item span,
  .app-shell.collapsed .nav-badge,
  .app-shell.collapsed .collapse-btn span,
  .app-shell.collapsed .side-foot { display: none; }
  .app-shell.collapsed .nav-item,
  .app-shell.collapsed .collapse-btn { justify-content: center; padding-left: 0; padding-right: 0; gap: 0; }
  .app-shell.collapsed .collapse-btn svg { transform: rotate(180deg); }
}
@media (max-width: 620px) { .mov-row { grid-template-columns: 80px 1fr 90px 30px; } .mov-row .m-met { display: none; } }
@media (max-width: 720px) {
  .panels { grid-template-columns: 1fr; }
}

/* ---------- Telefono: colonne secondarie nascoste PER TABELLA ----------
   (le colonne chiave restano; il resto si raggiunge scorrendo la scheda) */
@media (max-width: 640px) {
  /* storico agende: via Contanti, POS */
  #grid th:nth-child(4), #grid td:nth-child(4),
  #grid th:nth-child(5), #grid td:nth-child(5),
  /* fatture: via Numero, P.IVA */
  #ff-grid th:nth-child(3), #ff-grid td:nth-child(3),
  #ff-grid th:nth-child(5), #ff-grid td:nth-child(5),
  /* banche: via Causale */
  #bb-grid th:nth-child(3), #bb-grid td:nth-child(3),
  /* scadenze lista: via Categoria, Ricorrenza */
  #sc-grid th:nth-child(3), #sc-grid td:nth-child(3),
  #sc-grid th:nth-child(4), #sc-grid td:nth-child(4),
  /* dipendenti: via CF, Livello, Reparto */
  #dp-grid th:nth-child(2), #dp-grid td:nth-child(2),
  #dp-grid th:nth-child(3), #dp-grid td:nth-child(3),
  #dp-grid th:nth-child(5), #dp-grid td:nth-child(5),
  /* articoli: via Categoria, UM, Costo lordo */
  #mg-grid th:nth-child(2), #mg-grid td:nth-child(2),
  #mg-grid th:nth-child(4), #mg-grid td:nth-child(4),
  #mg-grid th:nth-child(6), #mg-grid td:nth-child(6),
  /* fornitori: via P.IVA, Zona, Articoli, Stato */
  #mf-grid th:nth-child(3), #mf-grid td:nth-child(3),
  #mf-grid th:nth-child(4), #mf-grid td:nth-child(4),
  #mf-grid th:nth-child(6), #mf-grid td:nth-child(6),
  #mf-grid th:nth-child(7), #mf-grid td:nth-child(7),
  /* ordini: via Categoria, Costo/UM (Quantità e Riga SEMPRE visibili) */
  #or-grid th:nth-child(2), #or-grid td:nth-child(2),
  #or-grid th:nth-child(4), #or-grid td:nth-child(4) { display: none; }
  .grid { font-size: 13.5px; }
  .grid thead th { padding: .6rem .6rem; }
  .grid tbody td { padding: .55rem .6rem; }
  .or-qty { width: 72px; }
}

/* ---------- Telefono: shell, drawer, modali, dashboard ---------- */
@media (max-width: 560px) {
  .content { padding: .8rem; }
  #section-title { font-size: 1.05rem; }
  .topbar-right { gap: .4rem; }
  .chip { display: none; }               /* nome utente: via, resta Esci */
  .drawer { width: 100vw; border-left: none; }
  .modal { top: 0; left: 0; transform: none; width: 100vw; height: 100dvh; max-height: 100dvh; border-radius: 0; border: none; animation: none; }
  .hero .hero-note { max-width: 100%; text-align: left; }
  .statrow { grid-template-columns: repeat(2, 1fr); gap: .6rem; }
  .stat .s-value { font-size: 1.15rem; }
  .kpi-grid { grid-template-columns: repeat(2, 1fr); gap: .7rem; }
  .kpi { padding: .85rem .95rem; }
  .kpi .k-value { font-size: 1.28rem; }
  .yoy-row { grid-template-columns: 82px 1fr 66px 44px; gap: .45rem; font-size: .8rem; }
  .cal-title { min-width: 0; font-size: 1.02rem; }
  .cal-top .btn-sm { padding: .35rem .55rem; }
  /* CALENDARIO -> AGENDA verticale: solo i giorni con scadenze (+ oggi) */
  .cal-grid { display: flex; flex-direction: column; gap: 6px; }
  .cal-wd, .cal-cell.off { display: none; }
  .cal-cell:not(.has-items):not(.today) { display: none; }
  .cal-cell { display: flex; gap: .7rem; align-items: flex-start; min-height: 0; padding: .55rem .65rem; border-radius: 10px; }
  .cal-daynum { flex: 0 0 42px; font-size: 1.05rem; line-height: 1.05; text-align: center; }
  .cal-dw { display: block; font-size: .6rem; font-weight: 650; color: var(--text-2); text-transform: uppercase; letter-spacing: .05em; margin-top: .1rem; }
  .cal-items { flex: 1; min-width: 0; }
  .cal-chip { font-size: .8rem; padding: .32rem .55rem; margin-top: 4px; white-space: normal; line-height: 1.35; }
  .cal-items .cal-chip:first-child { margin-top: 0; }
  .order-msg { font-size: 12.5px; }
  .filters .fld { flex: 1 1 45%; }
  .filters .fld select, .filters .fld input { width: 100%; }
  .filters .btn { flex: 0 0 auto; }
}
