/* DR SOLUTION · DR System Code */
:root {
  --bg: #f4f6f5;
  --surface: #ffffff;
  --surface-2: #eef2f0;
  --border: #dfe5e2;
  --ink: #16211c;
  --ink-2: #4a5a53;
  --ink-3: #7a8a83;
  --brand: #0f6b45;
  --brand-ink: #ffffff;
  --brand-soft: #e3f2ea;
  --pos: #0f7a4a;
  --pos-soft: #e2f4ea;
  --neg: #c0392b;
  --neg-soft: #fbe9e7;
  --warn: #b26a00;
  --warn-soft: #fff3dc;
  --info: #1f5fa8;
  --info-soft: #e5eefa;
  --bar: #2f8f63;
  --grid: #e6ebe8;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 33, 26, .06), 0 4px 16px rgba(16, 33, 26, .05);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1412;
    --surface: #171e1b;
    --surface-2: #1e2723;
    --border: #2a3530;
    --ink: #e8efeb;
    --ink-2: #aebdb6;
    --ink-3: #7f8f88;
    --brand: #34b27b;
    --brand-ink: #06130d;
    --brand-soft: #173026;
    --pos: #4cc991;
    --pos-soft: #16302a;
    --neg: #f07b6c;
    --neg-soft: #3a1e1b;
    --warn: #f0b24a;
    --warn-soft: #3a2c12;
    --info: #7fb1ec;
    --info-soft: #182a40;
    --bar: #46b886;
    --grid: #26302c;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
h1, h2, h3 { line-height: 1.2; margin: 0; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
a { color: var(--brand); }
.muted { color: var(--ink-3); }
.small { font-size: .85rem; }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.pos { color: var(--pos); }
.neg { color: var(--neg); }

/* ---------- Login ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 20px;
  box-shadow: var(--shadow); padding: 36px 28px; width: min(380px, 100%); text-align: center;
}
.login-card img { border-radius: 18px; }
.login-card h1 { margin: 12px 0 4px; font-size: 1.8rem; letter-spacing: .02em; }
.login-card p { color: var(--ink-2); margin: 0 0 24px; }
.login-card small { color: var(--ink-3); display: block; margin-top: 20px; }
.err { color: var(--neg); min-height: 1.2em; margin-top: 12px !important; }

/* ---------- Layout ---------- */
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: 220px; flex: none; background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; padding: 16px 12px;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 1.15rem; padding: 4px 8px 18px; letter-spacing: .03em; }
.brand img { border-radius: 8px; }
#nav { display: flex; flex-direction: column; gap: 2px; }
#nav a {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 10px;
  color: var(--ink-2); text-decoration: none; font-weight: 500;
}
#nav a .ico { width: 22px; text-align: center; font-size: 1.05rem; }
#nav a:hover { background: var(--surface-2); color: var(--ink); }
#nav a.active { background: var(--brand-soft); color: var(--brand); font-weight: 650; }
.user { margin-top: auto; font-size: .85rem; color: var(--ink-2); padding: 8px; border-top: 1px solid var(--border); }
.user button { margin-top: 6px; }
main { flex: 1; min-width: 0; padding: 24px clamp(16px, 3vw, 36px) 40px; max-width: 1200px; }
.banner {
  background: var(--warn-soft); color: var(--warn); border-radius: 10px; padding: 10px 14px;
  margin-bottom: 16px; font-size: .9rem;
}

@media (max-width: 820px) {
  .app { display: block; }
  .sidebar {
    position: fixed; bottom: 0; top: auto; left: 0; right: 0; width: 100%; height: auto; z-index: 20;
    flex-direction: row; padding: 4px 4px calc(4px + env(safe-area-inset-bottom)); border-right: 0; border-top: 1px solid var(--border);
  }
  .brand, .user { display: none; }
  #nav { flex-direction: row; width: 100%; justify-content: space-around; }
  #nav a { flex-direction: column; gap: 2px; padding: 6px 4px; font-size: .68rem; flex: 1; text-align: center; }
  #nav a .ico { font-size: 1.2rem; width: auto; }
  main { padding: 16px 16px calc(84px + env(safe-area-inset-bottom)); }
}

/* ---------- Header di pagina ---------- */
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.page-head .actions { display: flex; gap: 8px; flex-wrap: wrap; }
.tabs { display: flex; gap: 4px; background: var(--surface-2); padding: 4px; border-radius: 12px; margin-bottom: 16px; overflow-x: auto; }
.tabs button {
  border: 0; background: transparent; padding: 8px 14px; border-radius: 9px; font: inherit; color: var(--ink-2);
  cursor: pointer; white-space: nowrap; font-weight: 500;
}
.tabs button.active { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); font-weight: 650; }

/* ---------- Pulsanti e campi ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 1px solid var(--border);
  background: var(--surface); color: var(--ink); padding: 8px 14px; border-radius: 10px; font: inherit; font-weight: 550;
  cursor: pointer; text-decoration: none; min-height: 38px;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.btn.primary:hover { filter: brightness(1.07); }
.btn.danger { color: var(--neg); }
.btn.small { padding: 4px 10px; min-height: 30px; font-size: .85rem; }
.btn.big { padding: 12px 20px; font-size: 1rem; width: 100%; }
.btn.ghost { border-color: transparent; background: transparent; }
.icon-btn { border: 0; background: transparent; cursor: pointer; padding: 6px; border-radius: 8px; color: var(--ink-2); font-size: 1rem; }
.icon-btn:hover { background: var(--surface-2); color: var(--ink); }

label.field { display: flex; flex-direction: column; gap: 4px; font-size: .85rem; color: var(--ink-2); font-weight: 550; }
input, select, textarea {
  font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  padding: 9px 11px; width: 100%; min-height: 40px;
}
textarea { min-height: 70px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); outline-offset: -1px; border-color: transparent; }
label.check { display: flex; gap: 8px; align-items: center; font-size: .9rem; }
label.check input { width: auto; min-height: 0; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.full { grid-column: 1 / -1; }
@media (max-width: 560px) { .grid2, .grid3 { grid-template-columns: 1fr; } }
.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; align-items: center; }
.filters label.check input { min-width: 0; flex: none; }
.filters input:not([type=checkbox]), .filters select { width: auto; min-width: 140px; flex: 1 1 140px; max-width: 260px; }

/* ---------- Card e KPI ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; }
.card + .card { margin-top: 16px; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.kpi .lbl { font-size: .8rem; color: var(--ink-2); font-weight: 550; }
.kpi .val { font-size: 1.45rem; font-weight: 750; margin-top: 2px; font-variant-numeric: tabular-nums; }
.kpi .sub { font-size: .8rem; color: var(--ink-3); margin-top: 2px; }
.cols { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.cols > .card + .card { margin-top: 0; }
.cols.cols-wide { grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); }
@media (max-width: 960px) { .cols, .cols.cols-wide { grid-template-columns: 1fr; } .cols > .card + .card { margin-top: 0; } }

/* ---------- Liste ---------- */
.list { display: flex; flex-direction: column; }
.row {
  display: flex; align-items: center; gap: 12px; padding: 12px 4px; border-bottom: 1px solid var(--border);
}
.row:last-child { border-bottom: 0; }
.row .main { flex: 1; min-width: 0; }
.row .title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; }
.row .meta { font-size: .82rem; color: var(--ink-3); }
.row .amt { text-align: right; font-weight: 650; }
.row .amt .meta { font-weight: 400; }
.row .acts { display: flex; gap: 2px; }
.row.click { cursor: pointer; border-radius: 8px; }
.row.click:hover { background: var(--surface-2); }
.empty { text-align: center; padding: 28px 12px; color: var(--ink-3); }

.pill {
  display: inline-flex; align-items: center; gap: 4px; font-size: .74rem; font-weight: 650; padding: 2px 8px;
  border-radius: 99px; white-space: nowrap; background: var(--surface-2); color: var(--ink-2);
}
.pill.pos { background: var(--pos-soft); color: var(--pos); }
.pill.neg { background: var(--neg-soft); color: var(--neg); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.info { background: var(--info-soft); color: var(--info); }

.progress { height: 6px; background: var(--surface-2); border-radius: 99px; overflow: hidden; margin-top: 6px; }
.progress > i { display: block; height: 100%; background: var(--brand); border-radius: 99px; }

table.t { width: 100%; border-collapse: collapse; font-size: .9rem; }
table.t th { text-align: left; font-size: .78rem; color: var(--ink-2); font-weight: 650; padding: 8px 8px; border-bottom: 1px solid var(--border); }
table.t td { padding: 9px 8px; border-bottom: 1px solid var(--border); }
table.t td.r, table.t th.r { text-align: right; }
table.t tfoot td { font-weight: 700; border-bottom: 0; }
.table-wrap { overflow-x: auto; }

/* ---------- Veicoli ---------- */
.vehicles { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; margin-bottom: 16px; }
.vehicle {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; cursor: pointer;
  box-shadow: var(--shadow); text-align: left; font: inherit; color: inherit;
}
.vehicle.active { outline: 2px solid var(--brand); border-color: transparent; }
.vehicle .plate { font-family: ui-monospace, Consolas, monospace; font-size: .8rem; background: var(--surface-2); padding: 1px 6px; border-radius: 5px; }
.vehicle .name { font-weight: 700; font-size: 1.05rem; margin: 4px 0; }

/* ---------- Grafici ---------- */
.chart { width: 100%; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .axis text { fill: var(--ink-3); font-size: 11px; }
.chart .gridline { stroke: var(--grid); stroke-width: 1; }
.chart .bar { fill: var(--bar); }
.chart .bar.sel { fill: var(--brand); }
.chart .hit { fill: transparent; cursor: pointer; }
.chart .hit:hover + .bar, .chart .bar.hover { filter: brightness(1.12); }
.chart .vlabel { fill: var(--ink-2); font-size: 11px; font-weight: 600; }
.hbars { display: flex; flex-direction: column; gap: 10px; }
.hbar .top { display: flex; justify-content: space-between; gap: 8px; font-size: .88rem; }
.hbar .track { height: 10px; background: var(--surface-2); border-radius: 99px; margin-top: 4px; overflow: hidden; }
.hbar .track i { display: block; height: 100%; background: var(--bar); border-radius: 99px; }
.tip {
  position: fixed; z-index: 100; pointer-events: none; background: var(--ink); color: var(--bg); padding: 6px 10px;
  border-radius: 8px; font-size: .82rem; box-shadow: 0 4px 14px rgba(0,0,0,.2); white-space: nowrap;
}

/* ---------- Modale ---------- */
dialog {
  border: 0; border-radius: 18px; padding: 0; width: min(560px, calc(100vw - 24px)); max-height: calc(100vh - 32px);
  background: var(--surface); color: var(--ink); box-shadow: 0 20px 60px rgba(0,0,0,.3);
}
dialog::backdrop { background: rgba(10, 20, 15, .45); }
dialog form { display: flex; flex-direction: column; max-height: calc(100vh - 32px); }
dialog header { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px 8px; }
dialog .x { border: 0; background: transparent; font-size: 1.1rem; cursor: pointer; color: var(--ink-2); padding: 6px; }
.modal-body { padding: 8px 20px 16px; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; }
dialog footer { display: flex; gap: 8px; justify-content: flex-end; padding: 12px 20px 16px; border-top: 1px solid var(--border); flex-wrap: wrap; }
dialog footer .spacer { flex: 1; }
.hint { font-size: .82rem; color: var(--ink-3); }
.box { background: var(--surface-2); border-radius: 10px; padding: 10px 12px; font-size: .9rem; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px); opacity: 0; transition: .2s;
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 10px; z-index: 200; pointer-events: none; font-size: .9rem;
}
.toast.show { opacity: 1; transform: translateX(-50%); }
@media (max-width: 820px) { .toast { bottom: 90px; } }

/* ---------- Stampa report ---------- */
@media print {
  .sidebar, .page-head .actions, .tabs, .filters, .banner, .icon-btn, .no-print { display: none !important; }
  body { background: #fff; color: #000; }
  main { padding: 0; max-width: none; }
  .card, .kpi { box-shadow: none; break-inside: avoid; }
}

/* ---------- Telefono: righe su due livelli ---------- */
@media (max-width: 560px) {
  .row { flex-wrap: wrap; gap: 6px 10px; }
  .row .main { flex: 1 1 100%; }
  .row .amt { text-align: left; margin-right: auto; }
  .filters input:not([type=checkbox]), .filters select { max-width: none; }
  .card { padding: 14px; }
  .kpi .val { font-size: 1.25rem; }
}
