/* AZ Gestionale 2 — interfaccia */
:root {
  --brand: #b80000;
  --brand-dark: #8f0000;
  --brand-soft: #fbeaea;
  --ink: #16181d;
  --ink-2: #2b2f36;
  --muted: #5d6470;
  --faint: #8a909b;
  --line: #e2e4e8;
  --line-2: #d3d6db;
  --bg: #f4f5f7;
  --panel: #ffffff;
  --side: #17191e;
  --side-2: #22252b;
  --side-text: #c9ccd2;
  --ok: #12703a;
  --ok-soft: #e6f4ec;
  --warn: #9a5800;
  --warn-soft: #fdf1df;
  --err: #b42318;
  --err-soft: #fdecea;
  --info: #1d5aa6;
  --info-soft: #e8f0fb;
  --radius: 8px;
  --shadow: 0 1px 2px rgba(16, 18, 23, .06), 0 1px 1px rgba(16, 18, 23, .04);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "Cascadia Mono", "Segoe UI Mono", Consolas, monospace;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body { font-family: var(--font); font-size: 14px; line-height: 1.45; color: var(--ink); background: var(--bg); }
a { color: var(--info); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 22px; font-weight: 650; letter-spacing: -.01em; }
h2 { font-size: 16px; font-weight: 650; }
h3 { font-size: 14px; font-weight: 650; }
small, .small { font-size: 12px; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.mono { font-family: var(--mono); font-size: 12.5px; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.center { text-align: center; }
.strong { font-weight: 650; }
.red { color: var(--err); }
.green { color: var(--ok); }
.hidden { display: none !important; }

/* ---------- layout */
.app { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.side { background: var(--side); color: var(--side-text); position: sticky; top: 0; height: 100vh; overflow-y: auto;
        display: flex; flex-direction: column; }
.side .logo { display: flex; align-items: center; gap: 10px; padding: 16px 16px 12px; color: #fff; font-weight: 650; }
.side .logo img { width: 30px; height: 30px; }
.side .logo small { display: block; color: var(--faint); font-weight: 400; font-size: 11px; }
.side nav { padding: 4px 8px 16px; }
.side .sec { font-size: 10.5px; text-transform: uppercase; letter-spacing: .08em; color: #7d828c; padding: 14px 10px 4px; }
.side a { display: flex; align-items: center; gap: 9px; color: var(--side-text); padding: 6px 10px; border-radius: 6px;
          font-size: 13.5px; text-decoration: none; }
.side a:hover { background: var(--side-2); color: #fff; }
.side a.on { background: var(--brand); color: #fff; }
.side a .cnt { margin-left: auto; background: #3a3e46; color: #fff; border-radius: 10px; font-size: 11px; padding: 0 7px; }
.side a.on .cnt { background: rgba(255,255,255,.25); }
.side svg { width: 16px; height: 16px; flex: none; opacity: .85; }
.side .foot { margin-top: auto; padding: 12px 16px; font-size: 11.5px; color: #7d828c; border-top: 1px solid #2a2d33; }

.main { min-width: 0; display: flex; flex-direction: column; }
.top { position: sticky; top: 0; z-index: 20; background: rgba(255,255,255,.96); backdrop-filter: blur(6px);
       border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 12px; padding: 10px 24px; }
.top form.search { flex: 1; max-width: 560px; position: relative; }
.top form.search input { width: 100%; padding: 8px 12px 8px 34px; border-radius: 8px; border: 1px solid var(--line-2);
                         background: var(--bg); font-size: 14px; }
.top form.search svg { position: absolute; left: 10px; top: 9px; width: 16px; height: 16px; color: var(--faint); }
.top .quick { display: flex; gap: 6px; }
.top .user { margin-left: auto; display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 13px; }
.menu-toggle { display: none; }
.content { padding: 22px 24px 60px; max-width: 1480px; width: 100%; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 16px; flex-wrap: wrap; }
.page-head .sub { color: var(--muted); margin-top: 4px; }
.page-head .actions { display: flex; gap: 8px; flex-wrap: wrap; }
.crumbs { font-size: 12.5px; color: var(--muted); margin-bottom: 6px; }
.crumbs a { color: var(--muted); }

/* ---------- elementi */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card + .card { margin-top: 16px; }
.card .hd { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 16px;
            border-bottom: 1px solid var(--line); }
.card .bd { padding: 16px; }
.card .bd.flush { padding: 0; }
.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.g-main { grid-template-columns: minmax(0, 1fr) 340px; align-items: start; }
.stack > * + * { margin-top: 16px; }

.btn { display: inline-flex; align-items: center; gap: 6px; padding: 7px 13px; border-radius: 7px; border: 1px solid var(--line-2);
       background: #fff; color: var(--ink); font: inherit; font-size: 13.5px; font-weight: 550; cursor: pointer; text-decoration: none;
       white-space: nowrap; line-height: 1.3; }
.btn:hover { background: var(--bg); text-decoration: none; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-dark); }
.btn.dark { background: var(--ink); border-color: var(--ink); color: #fff; }
.btn.danger { color: var(--err); border-color: #f0c8c4; }
.btn.danger:hover { background: var(--err-soft); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--muted); }
.btn.ghost:hover { background: var(--bg); color: var(--ink); }
.btn.sm { padding: 4px 9px; font-size: 12.5px; }
.btn[disabled] { opacity: .5; pointer-events: none; }
.btn svg { width: 15px; height: 15px; }
.inline { display: inline; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 20px; font-size: 11.5px; font-weight: 600; white-space: nowrap;
         background: var(--bg); color: var(--muted); border: 1px solid var(--line); }
.badge.ok { background: var(--ok-soft); color: var(--ok); border-color: #c4e5d1; }
.badge.warn { background: var(--warn-soft); color: var(--warn); border-color: #f2d9b3; }
.badge.err { background: var(--err-soft); color: var(--err); border-color: #f3c7c2; }
.badge.info { background: var(--info-soft); color: var(--info); border-color: #c6d8f2; }
.badge.dark { background: var(--ink); color: #fff; border-color: var(--ink); }
.badge.brand { background: var(--brand-soft); color: var(--brand); border-color: #f1c4c4; }

.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; border: 1px solid; white-space: pre-line; }
.flash.ok { background: var(--ok-soft); border-color: #c4e5d1; color: #0d5a2e; }
.flash.error { background: var(--err-soft); border-color: #f3c7c2; color: #8e1b12; }
.flash.info { background: var(--info-soft); border-color: #c6d8f2; color: #16457f; }
.note { padding: 10px 14px; border-radius: 8px; background: var(--warn-soft); border: 1px solid #f2d9b3; color: #6d4100; font-size: 13px; }
.note.info { background: var(--info-soft); border-color: #c6d8f2; color: #16457f; }
.note.err { background: var(--err-soft); border-color: #f3c7c2; color: #8e1b12; }
.note.ok { background: var(--ok-soft); border-color: #c4e5d1; color: #0d5a2e; }

/* tabelle */
.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl th { text-align: left; font-weight: 600; color: var(--muted); font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em;
          padding: 8px 10px; border-bottom: 1px solid var(--line); background: #fafbfc; white-space: nowrap; }
.tbl td { padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl tbody tr:hover td { background: #fafbfc; }
.tbl tr.link { cursor: pointer; }
.tbl tr.muted td { color: var(--faint); }
.tbl tr.group td { background: #f4f5f7; font-weight: 600; }
.tbl tfoot td { font-weight: 650; border-top: 1px solid var(--line-2); background: #fafbfc; }
.tbl .num { text-align: right; }
.tbl th.num { text-align: right; }
.tbl-wrap { overflow-x: auto; }
.empty { padding: 30px; text-align: center; color: var(--muted); }

/* moduli */
label { display: block; font-size: 12px; font-weight: 600; color: var(--ink-2); margin-bottom: 4px; }
input, select, textarea { font: inherit; font-size: 14px; color: var(--ink); width: 100%; padding: 7px 9px; border: 1px solid var(--line-2);
                          border-radius: 6px; background: #fff; }
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(184,0,0,.18); border-color: var(--brand); }
input[type=checkbox], input[type=radio] { width: auto; padding: 0; margin: 0 6px 0 0; vertical-align: middle; accent-color: var(--brand); }
input[readonly] { background: var(--bg); }
textarea { min-height: 70px; resize: vertical; }
.fg { display: grid; gap: 12px 14px; grid-template-columns: repeat(12, minmax(0, 1fr)); }
.fg > .f { grid-column: span 3; }
.fg > .s2 { grid-column: span 2; } .fg > .s4 { grid-column: span 4; } .fg > .s5 { grid-column: span 5; }
.fg > .s6 { grid-column: span 6; } .fg > .s8 { grid-column: span 8; } .fg > .s12 { grid-column: span 12; }
.fg > .s1 { grid-column: span 1; } .fg > .s9 { grid-column: span 9; } .fg > .s7 { grid-column: span 7; }
.check { display: flex; align-items: center; gap: 4px; font-weight: 500; font-size: 13.5px; margin: 0; }
.hint { font-size: 12px; color: var(--muted); margin-top: 4px; }
.form-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; flex-wrap: wrap; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.filters input, .filters select { width: auto; min-width: 160px; padding: 6px 9px; font-size: 13.5px; }
.filters input[type=search] { min-width: 260px; }
.seg { display: inline-flex; border: 1px solid var(--line-2); border-radius: 7px; overflow: hidden; }
.seg a { padding: 6px 11px; font-size: 13px; color: var(--muted); border-right: 1px solid var(--line-2); text-decoration: none; }
.seg a:last-child { border-right: 0; }
.seg a.on { background: var(--ink); color: #fff; }
.seg a:hover:not(.on) { background: var(--bg); }

/* KPI */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; margin-bottom: 18px; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 13px 15px; box-shadow: var(--shadow);
       text-decoration: none; color: inherit; display: block; }
a.kpi:hover { border-color: var(--line-2); text-decoration: none; background: #fcfcfd; }
.kpi .l { font-size: 12px; color: var(--muted); font-weight: 600; }
.kpi .v { font-size: 22px; font-weight: 650; margin-top: 4px; font-variant-numeric: tabular-nums; letter-spacing: -.01em; }
.kpi .s { font-size: 12px; color: var(--muted); margin-top: 2px; }
.kpi.alert .v { color: var(--err); }

/* totali documento */
.totals { width: 100%; max-width: 380px; margin-left: auto; border-collapse: collapse; font-size: 14px; }
.totals td { padding: 4px 0; }
.totals td.num { padding-left: 20px; }
.totals tr.tot td { font-weight: 700; font-size: 16px; border-top: 1px solid var(--ink); padding-top: 7px; }
.totals tr.due td { font-weight: 700; font-size: 17px; color: var(--brand); border-top: 2px solid var(--brand); padding-top: 7px; }
.totals tr.cred td { color: var(--ok); }

/* dettaglio documento */
.meta { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px 18px; }
.meta .k { font-size: 11.5px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.meta .v { font-size: 14px; margin-top: 2px; }
.kv { display: grid; grid-template-columns: 140px 1fr; gap: 6px 12px; font-size: 13.5px; }
.kv .k { color: var(--muted); }
.timeline { list-style: none; margin: 0; padding: 0; font-size: 12.5px; }
.timeline li { padding: 6px 0; border-bottom: 1px dashed var(--line); }
.timeline li:last-child { border: 0; }

/* editor righe */
.lines { width: 100%; border-collapse: collapse; }
.lines th { font-size: 11.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; text-align: left; padding: 6px 4px;
            border-bottom: 1px solid var(--line); background: #fafbfc; }
.lines td { padding: 3px 4px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.lines input, .lines select { padding: 6px 7px; font-size: 13.5px; }
.lines .c-code { width: 150px; } .lines .c-qty { width: 78px; } .lines .c-price { width: 100px; } .lines .c-dc { width: 104px; }
.lines .c-pct { width: 70px; } .lines .c-vat { width: 80px; } .lines .c-net { width: 104px; } .lines .c-act { width: 64px; }
.lines td.net { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; padding-right: 8px; }
.lines tr.kind-gruppo td, .lines tr.kind-testo td { background: #fafbfc; }
.lines tr.locked input { background: var(--bg); }
.lines .stock { font-size: 11px; color: var(--muted); display: block; margin-top: 1px; }
.lines .stock.low { color: var(--err); }
.ac-wrap { position: relative; }
.ac-list { position: absolute; z-index: 50; left: 0; top: calc(100% + 2px); min-width: 460px; max-width: 680px; background: #fff;
           border: 1px solid var(--line-2); border-radius: 8px; box-shadow: 0 8px 28px rgba(0,0,0,.14); max-height: 360px; overflow-y: auto; }
.ac-list div { padding: 7px 10px; cursor: pointer; border-bottom: 1px solid var(--line); font-size: 13px; display: flex; gap: 10px; }
.ac-list div:last-child { border: 0; }
.ac-list div.on, .ac-list div:hover { background: var(--brand-soft); }
.ac-list .c { font-weight: 650; min-width: 110px; }
.ac-list .p { margin-left: auto; color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.ac-list .empty { color: var(--muted); cursor: default; }
.sticky-bar { position: sticky; bottom: 0; background: rgba(255,255,255,.97); border-top: 1px solid var(--line); padding: 12px 16px;
              display: flex; gap: 10px; align-items: center; justify-content: space-between; z-index: 10; border-radius: 0 0 8px 8px; flex-wrap: wrap; }
.sticky-bar .tot { font-size: 18px; font-weight: 700; font-variant-numeric: tabular-nums; }
.keys { font-size: 11.5px; color: var(--faint); }
kbd { font-family: var(--mono); font-size: 11px; border: 1px solid var(--line-2); border-bottom-width: 2px; border-radius: 4px; padding: 0 4px; background: #fff; }

/* dialog */
dialog { border: 0; border-radius: 12px; padding: 0; width: min(560px, 94vw); box-shadow: 0 20px 60px rgba(0,0,0,.25); }
dialog::backdrop { background: rgba(16,18,23,.45); }
dialog .hd { padding: 14px 18px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; }
dialog .bd { padding: 18px; }
dialog .ft { padding: 12px 18px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 8px; background: #fafbfc; }

/* bacheca */
.board .item { padding: 12px 16px; border-bottom: 1px solid var(--line); }
.board .item:last-child { border-bottom: 0; }
.board .item.urg { border-left: 3px solid var(--brand); background: #fffafa; }
.board .item.done { opacity: .6; }
.board .meta-line { font-size: 12px; color: var(--muted); display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.board .text { margin: 4px 0 6px; white-space: pre-wrap; }
.board .reply { margin: 6px 0 0 14px; padding: 6px 10px; border-left: 2px solid var(--line-2); font-size: 13px; }

.pager { display: flex; gap: 6px; align-items: center; justify-content: flex-end; padding: 10px 16px; border-top: 1px solid var(--line); font-size: 13px; }
.login { min-height: 100vh; display: grid; place-items: center; background: var(--side); }
.login .box { width: min(400px, 92vw); background: #fff; border-radius: 12px; padding: 28px; box-shadow: 0 20px 60px rgba(0,0,0,.35); }
.login .box img { width: 46px; }
.photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
.photos figure { margin: 0; position: relative; }
.photos img { width: 100%; aspect-ratio: 4/3; object-fit: cover; border-radius: 6px; border: 1px solid var(--line); }
.photos form { position: absolute; top: 4px; right: 4px; }
.thumb { width: 64px; height: 48px; object-fit: cover; border-radius: 4px; border: 1px solid var(--line); }
.pre { white-space: pre-wrap; }

@media (max-width: 1100px) {
  .g-main { grid-template-columns: 1fr; }
  .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .side { position: fixed; left: -260px; width: 240px; z-index: 60; transition: left .2s; }
  .side.open { left: 0; }
  .menu-toggle { display: inline-flex; }
  .top { padding: 8px 12px; }
  .top .quick { display: none; }
  .content { padding: 14px 12px 50px; }
  .g2, .g3, .g4 { grid-template-columns: 1fr; }
  .fg > * { grid-column: span 12 !important; }

}
@media print {
  .side, .top, .actions, .btn, .filters, .pager, .sticky-bar { display: none !important; }
  .app { display: block; }
  .content { padding: 0; }
  .card { box-shadow: none; }
}
