:root {
  --bg: #f5f6f4; --panel: #ffffff; --panel-2: #f9faf8; --line: #e3e6e1; --line-2: #eef0ec;
  --ink: #17201b; --ink-2: #4a544e; --muted: #7c857f;
  --brand: #1b3a63; --brand-ink: #122a4a; --brand-soft: #e9eef6; --gold: #b8954a;
  --blue: #2a6fdb; --amber: #b7791f; --amber-soft: #fbf3e2; --red: #c4423a; --red-soft: #fbeceb; --good: #1d8a54;
  --radius: 12px; --shadow: 0 1px 2px rgba(16,24,20,.05), 0 4px 14px rgba(16,24,20,.05);
  --side: 236px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font-size: 14px; -webkit-text-size-adjust: 100%; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0; letter-spacing: -.01em; }
h2 { font-size: 16px; margin: 0 0 12px; }
h3 { font-size: 14px; margin: 18px 0 8px; }
.muted { color: var(--muted); } .small { font-size: 12px; } .hidden { display: none !important; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.pos { color: var(--good); } .neg { color: var(--red); }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; } .spacer { flex: 1; }
.stack > * + * { margin-top: 12px; }

/* ---- buttons & inputs ---- */
button, .btn { font: inherit; border: 1px solid var(--line); background: var(--panel); color: var(--ink); padding: 8px 14px; border-radius: 9px;
  cursor: pointer; display: inline-flex; align-items: center; gap: 6px; text-decoration: none; line-height: 1.2; }
button:hover, .btn:hover { border-color: #c9cfc9; text-decoration: none; }
button:disabled { opacity: .55; cursor: default; }
.primary { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 600; }
.primary:hover { background: var(--brand-ink); border-color: var(--brand-ink); }
.danger { color: var(--red); border-color: #efc9c6; }
.ghost { background: transparent; border-color: transparent; }
.ghost:hover { background: var(--line-2); border-color: transparent; }
.sm { padding: 5px 10px; font-size: 13px; border-radius: 8px; }
input, select, textarea { font: inherit; color: var(--ink); background: #fff; border: 1px solid var(--line); border-radius: 9px; padding: 8px 10px; min-width: 0; width: 100%; }
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid rgba(27,58,99,.25); border-color: var(--brand); }
input[type=checkbox], input[type=radio] { width: auto; accent-color: var(--brand); }
label.f { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--ink-2); }
label.f .hint { font-size: 11.5px; color: var(--muted); }
label.check { display: flex; gap: 8px; align-items: center; font-size: 13px; color: var(--ink-2); }
.grid { display: grid; gap: 12px 16px; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }

/* ---- layout ---- */
.shell { display: grid; grid-template-columns: var(--side) 1fr; min-height: 100vh; }
.side { background: #0f1f33; color: #d5deea; padding: 14px 10px; position: sticky; top: 0; height: 100vh; overflow-y: auto; display: flex; flex-direction: column; }
.logo { display: flex; gap: 9px; align-items: center; font-weight: 750; font-size: 16px; color: #fff; padding: 4px 8px 14px; }
.logo img { width: 28px; height: 28px; border-radius: 8px; }
.co-pick { margin: 0 4px 12px; }
.co-pick select { background: #17304f; color: #fff; border-color: #2a4a70; font-weight: 600; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 9px; color: #c3cfde; font-weight: 500; text-decoration: none; }
.nav a:hover { background: #18304f; color: #fff; }
.nav a.on { background: #213f66; color: #fff; box-shadow: inset 3px 0 0 var(--gold); }
.nav a .ico { width: 18px; text-align: center; opacity: .9; }
.nav .count { margin-left: auto; background: #f0b429; color: #3a2a00; font-size: 11px; font-weight: 700; padding: 1px 7px; border-radius: 10px; }
.nav .sub { padding: 6px 10px 6px 38px; font-size: 13px; color: #9fb5a8; }
.side .foot { margin-top: auto; padding: 12px 8px 4px; font-size: 12px; color: #8a9bb3; border-top: 1px solid #1f3655; }
.side .foot b { color: #e9eef6; }
main { min-width: 0; }
.top { display: flex; align-items: center; gap: 10px; padding: 12px 24px; background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
.search { position: relative; width: min(420px, 100%); }
.search input { padding-left: 32px; background: var(--panel-2); }
.search .mag { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.results { position: absolute; top: 40px; left: 0; right: 0; background: #fff; border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow); overflow: hidden; z-index: 30; }
.results a { display: flex; gap: 8px; padding: 9px 12px; color: var(--ink); border-bottom: 1px solid var(--line-2); text-decoration: none; }
.results a:hover, .results a.on { background: var(--brand-soft); }
.results .t { color: var(--muted); font-size: 12px; min-width: 64px; }
.view { padding: 22px 24px 120px; max-width: 1280px; }
.head { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.head .sub { color: var(--muted); margin-top: 3px; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; overflow-x: auto; scrollbar-width: none; }
.tabs a { padding: 9px 12px; color: var(--ink-2); border-bottom: 2px solid transparent; white-space: nowrap; text-decoration: none; font-weight: 500; }
.tabs a.on { color: var(--brand-ink); border-bottom-color: var(--brand); }

/* ---- cards, tiles, tables ---- */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); margin-bottom: 16px; }
.card.flat { box-shadow: none; }
.card > h2 .muted { font-weight: 400; font-size: 13px; }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; margin-bottom: 16px; }
.tile { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.tile .l { color: var(--muted); font-size: 12px; font-weight: 500; }
.tile .v { font-size: 24px; font-weight: 700; margin-top: 6px; font-variant-numeric: tabular-nums; letter-spacing: -.01em; }
.tile .s { color: var(--ink-2); font-size: 12px; margin-top: 3px; }
a.tile { color: inherit; text-decoration: none; display: block; }
a.tile:hover { border-color: #bfd7c9; }
.tw { overflow-x: auto; margin: 0 -2px; }
table.t { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
table.t th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; background: var(--panel); position: sticky; top: 0; }
table.t td { padding: 9px 10px; border-bottom: 1px solid var(--line-2); vertical-align: middle; }
table.t tr.click { cursor: pointer; }
table.t tr.click:hover td { background: #f4f7fb; }
table.t tfoot td { font-weight: 700; border-top: 2px solid var(--line); border-bottom: none; }
table.t td.th { font-weight: 700; padding-top: 14px; }
table.t tr.total td { font-weight: 700; border-top: 1px solid var(--line); }
table.t tr.grand td { font-weight: 800; border-top: 2px solid var(--ink); font-size: 15px; }
table.t td.ind { padding-left: 26px; }
.empty { padding: 28px; text-align: center; color: var(--muted); }
.pill { display: inline-block; font-size: 11.5px; font-weight: 600; padding: 2px 9px; border-radius: 99px; background: var(--line-2); color: var(--ink-2); white-space: nowrap; }
.pill.green { background: var(--brand-soft); color: var(--brand-ink); } .pill.amber { background: var(--amber-soft); color: #8a5a0b; }
.pill.red { background: var(--red-soft); color: var(--red); } .pill.blue { background: #e7effc; color: #1f55ab; }
.conf { display: inline-flex; align-items: center; gap: 6px; font-weight: 700; font-size: 12px; }
.conf i { display: block; width: 46px; height: 6px; border-radius: 3px; background: var(--line); overflow: hidden; }
.conf i b { display: block; height: 100%; background: var(--good); }
.conf.mid i b { background: var(--amber); } .conf.low i b { background: var(--red); }
.banner { padding: 12px 14px; border-radius: 10px; border: 1px solid #f1dfb8; background: var(--amber-soft); margin-bottom: 14px; }
.banner.info { border-color: #cfe0f7; background: #eef4fd; }
.banner.good { border-color: #cbe6d7; background: var(--brand-soft); }
.banner.bad { border-color: #efc9c6; background: var(--red-soft); }

/* review queue */
.rv { display: grid; grid-template-columns: 28px 92px 1fr 130px 112px auto; gap: 10px; align-items: center; padding: 12px 6px; border-bottom: 1px solid var(--line-2); }
.rv:last-child { border-bottom: none; }
.rv .amt { font-weight: 700; text-align: right; font-variant-numeric: tabular-nums; }
.rv .desc { font-weight: 600; } .rv .why { color: var(--ink-2); font-size: 12.5px; margin-top: 3px; }
.rv .target { color: var(--brand-ink); font-size: 12.5px; margin-top: 3px; font-weight: 600; }
.rv .acts { display: flex; gap: 6px; justify-content: flex-end; }

/* checklist */
.check-item { display: flex; gap: 12px; align-items: flex-start; padding: 11px 0; border-bottom: 1px solid var(--line-2); }
.check-item .dot { width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; flex: none; font-size: 13px; font-weight: 800; }
.check-item .dot.ok { background: var(--brand-soft); color: var(--good); } .check-item .dot.no { background: var(--amber-soft); color: var(--amber); }

/* chart */
.chart { height: 220px; position: relative; } .chart svg { width: 100%; height: 100%; display: block; }
.chart .ax { fill: var(--muted); font-size: 11px; } .chart .gl { stroke: var(--line-2); }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--ink-2); margin-bottom: 4px; flex-wrap: wrap; }
.sw { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }

/* modal */
.modal-bg { position: fixed; inset: 0; background: rgba(15,25,20,.45); display: grid; place-items: center; z-index: 60; padding: 16px; animation: fade .12s ease-out; }
.modal { background: #fff; border-radius: 14px; width: min(640px, 100%); max-height: calc(100vh - 32px); display: flex; flex-direction: column; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.modal.wide { width: min(980px, 100%); }
.modal .mh { display: flex; align-items: center; gap: 8px; padding: 16px 18px; border-bottom: 1px solid var(--line); }
.modal .mh h2 { margin: 0; }
.modal .mb { padding: 16px 18px; overflow-y: auto; }
.modal .mf { padding: 12px 18px; border-top: 1px solid var(--line); display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }
.err { color: var(--red); font-size: 13px; min-height: 1em; }
@keyframes fade { from { opacity: 0; } }
.toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); background: #0f1f33; color: #fff; padding: 11px 18px; border-radius: 10px; z-index: 80;
  box-shadow: var(--shadow); font-weight: 500; max-width: calc(100vw - 32px); animation: fade .15s; }
.toast.bad { background: var(--red); }
.lines-table td { padding: 4px 4px; } .lines-table input, .lines-table select { padding: 6px 8px; }
.code-input { font-size: 26px; letter-spacing: 8px; text-align: center; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 18px; } .kv dt { color: var(--muted); } .kv dd { margin: 0; }

/* print (reports, stubs, packages) */
.print-only { display: none; }
@media print {
  .side, .top, .no-print, .ava-bubble, .ava-panel, .tabs, .head button, .head .btn { display: none !important; }
  .shell { display: block; } .view { padding: 0; max-width: none; } .card { box-shadow: none; border: none; padding: 0; }
  .print-only { display: block; } body { background: #fff; font-size: 12px; }
  .page-break { page-break-before: always; }
}

/* Ava */
.ava-bubble { position: fixed; right: 20px; bottom: 20px; z-index: 40; display: flex; align-items: center; gap: 8px; padding: 11px 16px 11px 11px; border-radius: 99px;
  background: var(--brand); color: #fff; border: none; font-weight: 600; box-shadow: 0 8px 24px rgba(20,40,74,.35); }
.ava-face { width: 28px; height: 28px; border-radius: 50%; background: #fff; color: var(--brand); display: grid; place-items: center; font-weight: 800; }
.ava-panel { position: fixed; right: 20px; bottom: 20px; z-index: 41; width: min(400px, calc(100vw - 24px)); height: min(600px, calc(100vh - 40px)); display: flex; flex-direction: column;
  background: #fff; border: 1px solid var(--line); border-radius: 16px; box-shadow: 0 18px 50px rgba(0,0,0,.2); overflow: hidden; }
.ava-head { display: flex; gap: 10px; align-items: center; padding: 12px 14px; background: var(--brand); color: #fff; }
.ava-head .ava-face { background: #fff; }
.ava-head button { color: #fff; }
.ava-msgs { flex: 1; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 10px; background: var(--panel-2); }
.am { max-width: 88%; padding: 9px 12px; border-radius: 12px; line-height: 1.45; }
.am.u { align-self: flex-end; background: var(--brand); color: #fff; border-bottom-right-radius: 4px; white-space: pre-wrap; }
.am.b { align-self: flex-start; background: #fff; border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.am p { margin: 0 0 7px; } .am p:last-child { margin: 0; } .am ul, .am ol { margin: 4px 0 6px; padding-left: 20px; }
.ava-chips { display: flex; gap: 6px; flex-wrap: wrap; padding: 8px 12px 0; }
.ava-chips button { font-size: 12px; padding: 5px 10px; border-radius: 99px; }
.ava-form { display: flex; gap: 8px; padding: 10px 12px; border-top: 1px solid var(--line); }
.ava-form textarea { resize: none; }

/* mobile */
.mob-top, .mob-nav { display: none; }
@media (max-width: 900px) {
  .shell { display: block; }
  .side { position: fixed; inset: 0 auto 0 0; width: 270px; transform: translateX(-100%); transition: transform .2s; z-index: 70; padding-top: max(14px, env(safe-area-inset-top)); }
  .side.open { transform: none; box-shadow: 0 0 0 100vmax rgba(0,0,0,.35); }
  .top { padding: 10px 12px; padding-top: max(10px, env(safe-area-inset-top)); }
  .mob-top { display: inline-flex; }
  .view { padding: 16px 12px 130px; }
  .grid.two, .grid.three { grid-template-columns: 1fr; }
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .tile .v { font-size: 19px; }
  input, select, textarea { font-size: 16px; }
  .rv { grid-template-columns: 24px 1fr auto; grid-template-areas: "c d a" "c w w" "c x x"; row-gap: 6px; }
  .rv > :nth-child(1) { grid-area: c; align-self: start; margin-top: 3px; }
  .rv > :nth-child(2) { display: none; }
  .rv > :nth-child(3) { grid-area: d; } .rv > :nth-child(4) { grid-area: a; }
  .rv > :nth-child(5) { grid-area: w; } .rv > :nth-child(6) { grid-area: x; justify-content: flex-start; }
  .mob-nav { display: flex; position: fixed; bottom: 0; left: 0; right: 0; background: #fff; border-top: 1px solid var(--line); z-index: 35; padding-bottom: env(safe-area-inset-bottom); }
  .mob-nav a { flex: 1; text-align: center; padding: 8px 0 7px; font-size: 11px; color: var(--ink-2); text-decoration: none; position: relative; }
  .mob-nav a span { display: block; font-size: 18px; }
  .mob-nav a.on { color: var(--brand); font-weight: 600; }
  .mob-nav .count { position: absolute; top: 3px; left: 55%; background: #f0b429; color: #3a2a00; font-size: 10px; font-weight: 700; padding: 0 5px; border-radius: 8px; }
  .ava-bubble { bottom: calc(70px + env(safe-area-inset-bottom)); right: 12px; padding: 10px; } .ava-bubble .lbl { display: none; }
  .ava-panel { inset: 0; width: 100%; height: 100%; border-radius: 0; padding-top: env(safe-area-inset-top); }
  .modal-bg { padding: 0; place-items: end center; } .modal { border-radius: 16px 16px 0 0; max-height: 92vh; }
  .search { width: auto; flex: 1; }
  .top .spacer { display: none; }
}

/* sign-in, invite, pay pages */
.center { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.auth { width: min(400px, 100%); background: #fff; border: 1px solid var(--line); border-radius: 16px; padding: 28px; box-shadow: var(--shadow); }
.auth .logo { color: var(--ink); padding: 0 0 14px; }
.qr { width: 220px; height: 220px; display: block; margin: 8px auto; }
.paybox { width: min(620px, 100%); }

/* brand mark: Piazza Accounting / Contabilità */
@font-face { font-family: "Lora"; src: url("/static/fonts/Lora.ttf") format("truetype"); font-weight: 400 700; font-display: swap; }
.brandmark { display: flex; gap: 10px; align-items: center; padding: 4px 8px 14px; }
.brandmark img { width: 34px; height: 34px; border-radius: 8px; }
.brandmark b { display: block; font-family: "Lora", Georgia, serif; font-size: 17px; letter-spacing: .01em; line-height: 1.1; }
.brandmark span { display: block; font-family: "Lora", Georgia, serif; font-style: italic; font-size: 12.5px; letter-spacing: .14em; color: var(--gold); opacity: .9; }
.side-brand b { color: #fff; }
.auth .brandmark { padding: 0 0 16px; } .auth .brandmark b { color: var(--ink); }
h1 { font-family: "Lora", Georgia, serif; font-weight: 600; }
