/* REFRESH Gestione — light theme, reference dataviz palette */
:root {
  --surface: #fcfcfb;
  --page: #f4f4f1;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --baseline: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --s1: #2a78d6;   /* entrate */
  --s2: #eb6834;   /* costi */
  --good-text: #006300;
  --good: #0ca30c;
  --warn: #fab219;
  --serious: #ec835a;
  --critical: #d03b3b;
  --radius: 10px;
  font-size: 15px;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--page);
  color: var(--ink);
}
.hidden { display: none !important; }

/* ---------- login ---------- */
#login-view {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
}
.login-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
  padding: 40px 36px; width: 340px; display: flex; flex-direction: column; gap: 12px;
  box-shadow: 0 8px 30px rgba(11,11,11,.06);
}
.login-logo { font-size: 26px; font-weight: 800; letter-spacing: 2px; text-align: center; }
.login-sub { color: var(--muted); text-align: center; margin-bottom: 12px; }
.login-error {
  color: var(--critical); font-size: 13.5px; text-align: center; min-height: 18px;
  line-height: 1.45;
}
.login-error:not(:empty) {
  background: #fbe3e3; border-radius: 7px; padding: 9px 11px; margin-top: 2px;
}

/* ---------- layout ---------- */
#app-view { display: flex; min-height: 100vh; }
.sidebar {
  width: 210px; flex-shrink: 0; background: var(--ink); color: #fff;
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh;
}
.brand { padding: 22px 20px 16px; font-weight: 800; letter-spacing: 2px; font-size: 18px; }
.brand span { display: block; font-weight: 400; letter-spacing: 4px; font-size: 11px; color: #a5a49d; text-transform: uppercase; }
.sidebar nav { display: flex; flex-direction: column; padding: 8px; gap: 2px; flex: 1; }
.sidebar nav a {
  color: #d8d7d0; text-decoration: none; padding: 10px 12px; border-radius: 8px; font-size: 14.5px;
}
.sidebar nav a:hover { background: rgba(255,255,255,.08); }
.sidebar nav a.active { background: rgba(255,255,255,.14); color: #fff; font-weight: 600; }
.sidebar-footer { padding: 12px; }
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 26px; border-bottom: 1px solid var(--grid); background: var(--surface);
  position: sticky; top: 0; z-index: 20;
}
#page-title { font-size: 19px; font-weight: 700; }
.year-picker { display: flex; align-items: center; gap: 4px; }
#year-label { font-weight: 700; font-size: 16px; min-width: 52px; text-align: center; }
#content { padding: 24px 26px 60px; display: flex; flex-direction: column; gap: 20px; }

/* ---------- componenti ---------- */
.btn {
  border: 1px solid var(--border); background: var(--surface); color: var(--ink);
  border-radius: 8px; padding: 8px 14px; font-size: 14px; cursor: pointer; font-family: inherit;
}
.btn:hover { background: #f1f0ec; }
.btn-primary { background: var(--ink); color: #fff; border-color: var(--ink); }
.btn-primary:hover { background: #2b2b2a; }
.btn-ghost { background: transparent; border-color: transparent; color: inherit; }
.btn-ghost:hover { background: rgba(11,11,11,.06); }
.sidebar .btn-ghost { color: #d8d7d0; border: 1px solid rgba(255,255,255,.18); }
.sidebar .btn-ghost:hover { background: rgba(255,255,255,.08); }
.btn-block { width: 100%; }
.btn-danger { color: var(--critical); }
.btn-sm { padding: 4px 9px; font-size: 12.5px; }

input, select, textarea {
  font-family: inherit; font-size: 14px; color: var(--ink);
  border: 1px solid var(--border); border-radius: 7px; padding: 8px 10px; background: #fff;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--s1); outline-offset: -1px; }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px 20px;
}
.card h2 { font-size: 15px; margin-bottom: 14px; display: flex; align-items: center; gap: 8px; justify-content: space-between; }
.card h2 .h2-actions { display: flex; gap: 8px; }

/* stat tiles */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.tile .t-label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; }
.tile .t-value { font-size: 22px; font-weight: 700; margin-top: 4px; }
.tile .t-sub { font-size: 12px; color: var(--ink-2); margin-top: 2px; }
.pos { color: var(--good-text); }
.neg { color: var(--critical); }

/* tabelle */
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: 13.5px; }
th, td { padding: 7px 9px; text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
th { color: var(--muted); font-weight: 600; font-size: 12px; border-bottom: 1px solid var(--baseline); }
td { border-bottom: 1px solid var(--grid); }
th:first-child, td:first-child { text-align: left; }
tr.total-row td { font-weight: 700; border-top: 2px solid var(--baseline); }
tr:hover td { background: #f5f4f0; }
td a { color: var(--s1); text-decoration: none; font-weight: 600; }
td a:hover { text-decoration: underline; }
.sect-row td { font-weight: 700; color: var(--ink-2); background: #f7f6f2; text-align: left; }

/* griglie editabili */
.grid-input { width: 74px; text-align: right; padding: 5px 7px; font-size: 13px; }
.grid-input.wide { width: 130px; text-align: left; }
td.cell-auto { color: var(--ink-2); }
select.status-sel { padding: 4px 6px; font-size: 12px; border-radius: 6px; width: 100%; }
.st-attesa { background: #f1f0ec; }
.st-fattura_inviata { background: #e3edfa; }
.st-parziale { background: #fdeadd; }
.st-incassato { background: #e2f3e2; }

/* badge */
.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 11.5px; font-weight: 600; }
.b-attesa { background: #f1f0ec; color: var(--ink-2); }
.b-fattura { background: #e3edfa; color: #1c5cab; }
.b-parziale { background: #fdeadd; color: #a34413; }
.b-incassato { background: #e2f3e2; color: var(--good-text); }
.b-scad-soon { background: #fdeadd; color: #a34413; }
.b-scad-past { background: #fbe3e3; color: var(--critical); }

/* chart */
.chart-legend { display: flex; gap: 18px; font-size: 12.5px; color: var(--ink-2); margin-bottom: 8px; }
.chart-legend .sw { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: baseline; }
.chart-box { position: relative; }
.chart-tip {
  position: absolute; pointer-events: none; background: var(--ink); color: #fff;
  font-size: 12px; padding: 7px 10px; border-radius: 7px; z-index: 30; white-space: nowrap;
  transform: translate(-50%, calc(-100% - 10px)); display: none; line-height: 1.5;
}
svg text { font-family: inherit; }

/* scheda cliente */
.client-info-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; }
.field label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.field input, .field select, .field textarea { width: 100%; }
textarea { min-height: 80px; resize: vertical; }
.card > textarea { width: 100%; }
.back-link { color: var(--s1); text-decoration: none; font-size: 14px; }
.month-table th, .month-table td { padding: 5px 5px; }
.month-table input { width: 68px; }
.act-table input { width: 100%; min-width: 34px; padding: 4px 5px; font-size: 12.5px; text-align: center; }
.act-table input.a-name { min-width: 170px; text-align: left; }
.act-table input.a-small { min-width: 70px; text-align: left; }

.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.toolbar input[type=search] { min-width: 220px; }
.spacer { flex: 1; }

.toast {
  position: fixed; bottom: 24px; right: 24px; background: var(--ink); color: #fff;
  padding: 11px 18px; border-radius: 9px; font-size: 14px; z-index: 100;
  box-shadow: 0 6px 20px rgba(0,0,0,.25);
}
.muted { color: var(--muted); }
.small { font-size: 12.5px; }

@media (max-width: 900px) {
  #app-view { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; flex-direction: row; align-items: center; }
  .sidebar nav { flex-direction: row; overflow-x: auto; }
  .brand span { display: none; }
  .sidebar-footer { padding: 8px; }
}
