/* Magic Peter — interfaccia ispirata al design system "Lachi Solutions".
   Del brand teniamo font (Archivo), palette quasi monocroma e l'unico accento rosso.
   Per lo schermo: più aria, pesi più leggeri, superfici bianche con bordi sottili,
   raggi contenuti. Le regole "da stampa" (angoli vivi, regole 2px) restano nei PDF. */
@font-face { font-family: "Archivo"; font-weight: 300; src: url("fonts/Archivo-Light.ttf") format("truetype"); }
@font-face { font-family: "Archivo"; font-weight: 400; src: url("fonts/Archivo-Regular.ttf") format("truetype"); }
@font-face { font-family: "Archivo"; font-weight: 600; src: url("fonts/Archivo-SemiBold.ttf") format("truetype"); }
@font-face { font-family: "Archivo"; font-weight: 800; src: url("fonts/Archivo-ExtraBold.ttf") format("truetype"); }

:root {
  --ls-ink: #201e1d; --ls-ground: #f3f2f2; --ls-white: #ffffff;
  --ls-accent: #ec3013; --ls-accent-deep: #ae1800; --ls-accent-tint: #ffe0d9;
  --ls-grey-600: #605d5d; --ls-grey-500: #7d7979; --ls-grey-300: #bab6b6;
  --line: #e7e5e4; --line-strong: #d6d3d1; --hover: #f8f7f7;
  --ok: #2f7a50; --ok-tint: #e7f2eb;
  --r-sm: 6px; --r: 10px; --r-lg: 14px;
  --shadow: 0 1px 2px rgba(32, 30, 29, .04), 0 2px 8px rgba(32, 30, 29, .04);
  --font: "Archivo", system-ui, -apple-system, sans-serif;
}
* { box-sizing: border-box; }
::selection { background: var(--ls-accent-tint); }
html, body { background: var(--ls-ground); }
body { margin: 0; font: 400 14px/1.6 var(--font); color: var(--ls-ink); -webkit-font-smoothing: antialiased; }
a { color: inherit; text-decoration: none; transition: color .12s; }
a:hover { color: var(--ls-accent-deep); }
.ic { flex: none; vertical-align: -3px; }

/* ---------- layout ---------- */
.layout { display: grid; grid-template-columns: 236px minmax(0, 1fr); min-height: 100vh; }
nav.side { position: sticky; top: 0; height: 100vh; padding: 28px 16px 20px; background: var(--ls-ground); display: flex; flex-direction: column; overflow-y: auto; }
.brand { padding: 0 12px 28px; }
.logo { display: flex; flex-direction: column; gap: 5px; width: 112px; }
.logo-word { display: flex; align-items: baseline; gap: 4px; font-size: 23px; font-weight: 800; letter-spacing: -0.04em; line-height: .9; }
.logo-dot { width: 7px; height: 7px; background: var(--ls-accent); display: inline-block; }
.logo-bar { height: 1.5px; background: var(--ls-ink); }
.logo-sub { font-size: 12px; font-weight: 300; line-height: 1; }
.brand .owner { margin-top: 14px; font-size: 12px; color: var(--ls-grey-500); }
nav.side a { display: flex; gap: 11px; align-items: center; padding: 8px 12px; margin-bottom: 2px; color: var(--ls-grey-600); border-radius: var(--r-sm); }
nav.side a .ic { color: var(--ls-grey-500); }
nav.side a:hover { background: rgba(255, 255, 255, .7); color: var(--ls-ink); }
nav.side a.on { background: var(--ls-white); color: var(--ls-ink); font-weight: 600; box-shadow: var(--shadow); }
nav.side a.on .ic { color: var(--ls-accent); }
nav.side .linkbtn { display: flex; gap: 11px; align-items: center; width: 100%; padding: 8px 12px; margin-bottom: 2px; background: none; border: 0; font: inherit; color: var(--ls-grey-600); border-radius: var(--r-sm); cursor: pointer; text-align: left; }
nav.side .linkbtn .ic { color: var(--ls-grey-500); }
nav.side .linkbtn:hover { background: rgba(255, 255, 255, .7); color: var(--ls-ink); }
nav.side .sep { height: 1px; background: var(--line); margin: 14px 12px; }
nav.side .foot { margin-top: auto; padding: 14px 12px 0; font-size: 11px; color: var(--ls-grey-500); display: flex; justify-content: space-between; align-items: center; }
nav.side .foot .sq { width: 7px; height: 7px; background: var(--ls-accent); }
main { padding: 36px 48px 80px; max-width: 1180px; width: 100%; min-width: 0; box-sizing: border-box; }
.scrollx { overflow-x: auto; }

/* ---------- type ---------- */
.kicker { font-size: 11px; font-weight: 600; letter-spacing: .14em; text-transform: uppercase; color: var(--ls-accent); margin-bottom: 6px; }
h1 { font-size: 28px; font-weight: 600; letter-spacing: -0.02em; line-height: 1.15; margin: 0 0 24px; }
h2 { font-size: 15px; font-weight: 600; letter-spacing: -0.005em; margin: 0 0 14px; }
.topbar { display: flex; justify-content: space-between; align-items: center; gap: 14px; flex-wrap: wrap; margin-bottom: 28px; }
.topbar h1 { margin: 0; }
.muted { color: var(--ls-grey-600); }
.small { font-size: 12.5px; }
.right { text-align: right; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; background: var(--ls-ground); padding: 1px 5px; border-radius: 4px; }

/* ---------- surfaces ---------- */
.card { background: var(--ls-white); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 22px 24px; margin-bottom: 20px; box-shadow: var(--shadow); }
.card > h2:first-child { margin-top: 0; }
.card.step { margin-bottom: 14px; }
.card.step > h2 { display: flex; align-items: center; gap: 10px; }
.card.step .num { display: inline-flex; width: 22px; height: 22px; align-items: center; justify-content: center; border-radius: 50%; background: var(--ls-ink); color: var(--ls-white); font-size: 12px; font-weight: 600; }
.card.step > p.small { margin: -6px 0 14px; }
.savebar { position: sticky; bottom: 0; padding: 14px 0; margin-top: 4px; background: var(--ls-ground); border-top: 1px solid var(--line); }
.grid { display: grid; gap: 0 20px; }
.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)); }
.card .grid { gap: 0 18px; }
.kpi { background: var(--ls-white); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 18px 20px; margin-bottom: 20px; box-shadow: var(--shadow); }
.kpi .l { font-size: 12px; color: var(--ls-grey-500); }
.kpi .v { font-size: 26px; font-weight: 600; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; margin-top: 6px; line-height: 1.1; }
.kpi .s { color: var(--ls-grey-500); font-size: 12px; margin-top: 6px; }

/* ---------- tables ---------- */
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th { text-align: left; font-size: 12px; font-weight: 400; color: var(--ls-grey-500); padding: 0 12px 10px 0; border-bottom: 1px solid var(--line-strong); }
td { padding: 12px 12px 12px 0; border-bottom: 1px solid var(--line); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
td:last-child, th:last-child { padding-right: 0; }
td.n, th.n { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
tr.click { cursor: pointer; transition: background .12s; }
tr.click:hover td { background: var(--hover); }
tfoot td { font-weight: 600; border-top: 1px solid var(--line-strong); border-bottom: 0; padding-top: 14px; }

/* ---------- status pills ---------- */
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 2px 10px; font-size: 12px; font-weight: 400; border-radius: 999px; background: var(--ls-ground); color: var(--ls-grey-600); white-space: nowrap; }
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .8; }
.pill.sent { color: var(--ls-ink); }
.pill.paid, .pill.accepted, .pill.invoiced { background: var(--ok-tint); color: var(--ok); }
.pill.overdue, .pill.rejected { background: var(--ls-accent-tint); color: var(--ls-accent-deep); }
.pill.partial { background: #fbf0e3; color: #8a5a1c; }
.pill.draft, .pill.cancelled { background: var(--ls-ground); color: var(--ls-grey-500); }
.tag { font-size: 11px; color: var(--ls-grey-600); background: var(--ls-ground); padding: 1px 7px; border-radius: 999px; }

/* ---------- buttons & forms ---------- */
.btn, button { display: inline-flex; align-items: center; gap: 7px; padding: 8px 15px; border: 1px solid var(--line-strong); border-radius: var(--r-sm); background: var(--ls-white); color: var(--ls-ink); font: 400 13.5px/1.25 var(--font); cursor: pointer; transition: background .12s, border-color .12s, color .12s; }
.btn:hover, button:hover { border-color: var(--ls-grey-500); color: var(--ls-ink); background: var(--hover); }
.btn.primary, button.primary { background: var(--ls-ink); border-color: var(--ls-ink); color: var(--ls-white); font-weight: 600; }
.btn.primary:hover, button.primary:hover { background: #3a3735; border-color: #3a3735; color: var(--ls-white); }
.btn.danger, button.danger { color: var(--ls-accent-deep); border-color: var(--line); }
.btn.danger:hover, button.danger:hover { background: var(--ls-accent-tint); border-color: var(--ls-accent-tint); color: var(--ls-accent-deep); }
.btn.sm, button.sm { padding: 4px 10px; font-size: 12.5px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
form.inline { display: inline; }
label { display: block; font-size: 12.5px; color: var(--ls-grey-600); margin-bottom: 6px; }
label a { color: var(--ls-accent-deep); }
input, select, textarea { width: 100%; padding: 9px 12px; border: 1px solid var(--line-strong); border-radius: var(--r-sm); background: var(--ls-white); color: var(--ls-ink); font: 400 14px/1.4 var(--font); transition: border-color .12s, box-shadow .12s; }
input:hover, select:hover, textarea:hover { border-color: var(--ls-grey-300); }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--ls-ink); box-shadow: 0 0 0 3px rgba(32, 30, 29, .07); }
input[type=file] { border: 0; padding: 4px 0; font-size: 12.5px; background: transparent; }
input[type=checkbox] { accent-color: var(--ls-ink); width: 15px; height: 15px; }
input[type=color] { padding: 2px; height: 40px; }
textarea { min-height: 64px; resize: vertical; }
.field { margin-bottom: 18px; }
.check { display: flex; gap: 9px; align-items: center; font-size: 14px; color: var(--ls-ink); }
.check input { width: auto; }

/* ---------- messages ---------- */
.flash { padding: 11px 16px; margin-bottom: 20px; background: var(--ok-tint); color: var(--ok); border-radius: var(--r); }
.flash.err { background: var(--ls-accent-tint); color: var(--ls-accent-deep); }
.note { background: var(--ls-white); border: 1px solid var(--line); border-left: 3px solid var(--ls-accent); border-radius: var(--r-sm); padding: 11px 16px; font-size: 13.5px; margin-bottom: 20px; }

/* ---------- filters ---------- */
.filters { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.filters a { padding: 5px 12px; border-radius: 999px; font-size: 12.5px; color: var(--ls-grey-600); background: var(--ls-ground); }
.filters a:hover { color: var(--ls-ink); background: var(--line); }
.filters a.on { background: var(--ls-ink); color: var(--ls-white); }
.filters input, .filters select { width: auto; padding: 6px 10px; }

/* ---------- invoice editor ---------- */
#lines td { padding: 8px 10px 8px 0; }
#lines input[name=l_qty] { width: 76px; }
#lines input[name=l_price] { width: 116px; }
#lines td:nth-child(2), #lines td:nth-child(4) { width: 1%; }
#lines textarea { min-height: 40px; }
.hourly input { padding: 5px 8px; font-size: 13px; }
.kindbtn.primary { background: var(--ls-ink); }
.totals { margin-left: auto; width: 340px; margin-top: 14px; }
.totals div { display: flex; justify-content: space-between; padding: 4px 0; font-variant-numeric: tabular-nums; }
.totals .grand { font-weight: 600; font-size: 17px; border-top: 1px solid var(--line-strong); padding-top: 10px; margin-top: 6px; }

/* ---------- dashboard ---------- */
.chart { width: 100%; height: 190px; }
.chart .inc { fill: var(--ls-ink); }
.chart .exp { fill: var(--ls-accent); opacity: .85; }
.chart text { fill: var(--ls-grey-500); font: 400 10px var(--font); }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--ls-grey-600); }
.legend i { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 6px; vertical-align: 0; }
.bar { height: 6px; background: var(--ls-ground); border-radius: 999px; overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--ls-ink); border-radius: 999px; }

/* ---------- trips ---------- */
tr.hid { display: none; }
tr.tripgroup .ic { transition: transform .12s; color: var(--ls-grey-500); }
tr.tripgroup.open .ic { transform: rotate(90deg); }
tr.tripmember td { background: var(--hover); }
#lines td { padding: 8px 8px 8px 0; }
#lines input[name=l_km] { width: 86px; }
#lines input[name=l_label] { min-width: 170px; }
#lines input[name=l_amount] { width: 104px; }
#lines input[type=date] { width: 150px; }
#lines input[type=file] { width: 190px; }
#lines select[name=l_kind] { min-width: 170px; }
#lines select[name=l_currency] { width: 78px; }
#lines tr:not(.iskm) input[name=l_km], #lines tr.iskm input[name=l_receipt] { visibility: hidden; }
.quick-actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.quick-actions label { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; min-height: 120px; margin: 0; border: 1.5px dashed var(--line-strong); border-radius: var(--r-lg); background: var(--ls-white); color: var(--ls-ink); font-size: 14px; cursor: pointer; }
.quick-actions label:hover { border-color: var(--ls-ink); }
.quick-actions label .ic { color: var(--ls-accent); }
.quick-actions input { display: none; }

/* ---------- misc ---------- */
.drop { border: 1.5px dashed var(--line-strong); border-radius: var(--r-lg); padding: 26px; text-align: center; background: var(--ls-white); transition: background .12s, border-color .12s; }
.drop.over { background: var(--ls-accent-tint); border-color: var(--ls-accent); }
.receipt-preview { max-width: 100%; max-height: 520px; border: 1px solid var(--line); border-radius: var(--r); }
.suggest select { min-width: 260px; }

/* ---------- responsive ---------- */
nav.side .morebtn { display: none; }
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  nav.side { position: static; height: auto; flex-direction: row; flex-wrap: wrap; gap: 2px; padding: 10px; }
  nav.side .brand, nav.side .sep, nav.side .foot { display: none; }
  nav.side form.inline { display: contents; }
  nav.side .linkbtn { width: auto; }
  main { padding: 22px 16px; }
  .g3, .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .g2 { grid-template-columns: 1fr; }
  .totals { width: 100%; }
}

/* Phones: bottom bar with the pages used on the road, "Altro" opens the rest; tables become cards. */
@media (max-width: 700px) {
  html { -webkit-text-size-adjust: 100%; }
  body { padding-bottom: calc(62px + env(safe-area-inset-bottom)); }
  main { padding: 18px 16px 24px; }
  h1 { font-size: 23px; margin-bottom: 18px; }
  .topbar { margin-bottom: 18px; }
  .topbar .actions { width: 100%; }
  .g3, .g4 { grid-template-columns: 1fr; }
  .grid > * { grid-column: auto !important; }   /* "span 2" fields of the desktop grids */
  .card { padding: 16px; border-radius: var(--r); }
  input, select, textarea { font-size: 16px; padding: 10px 12px; }   /* 16px: no auto-zoom on iOS */
  button, .btn { min-height: 44px; padding: 10px 16px; }
  button.sm, .btn.sm { min-height: 36px; padding: 6px 12px; }
  .filters input, .filters select { font-size: 14px; padding: 7px 10px; }
  .drop { padding: 18px 14px; }
  .savebar { bottom: calc(62px + env(safe-area-inset-bottom)); padding: 10px 0; }
  .savebar .btn, .savebar button { flex: 1 1 auto; }

  nav.side { position: fixed; left: 0; right: 0; top: auto; bottom: 0; z-index: 20; height: auto; margin: 0; padding: 4px 4px calc(4px + env(safe-area-inset-bottom));
    background: var(--ls-white); border-top: 1px solid var(--line); box-shadow: 0 -4px 16px rgba(32, 30, 29, .06); gap: 0; flex-wrap: wrap; justify-content: space-around; overflow: visible; }
  nav.side a, nav.side .linkbtn { flex: 1 1 0; flex-direction: column; gap: 3px; padding: 7px 2px 5px; margin: 0; font-size: 10.5px; line-height: 1.1; text-align: center; min-height: 0; width: auto; justify-content: center; }
  nav.side a.on { box-shadow: none; background: none; }
  nav.side a:not(.m), nav.side form.inline { display: none; }
  nav.side .morebtn { display: flex; }
  nav.side.open { padding-top: 10px; }
  nav.side.open a, nav.side.open .linkbtn { flex: 1 1 30%; }
  nav.side.open a:not(.m), nav.side.open form.inline { display: flex; }
  nav.side.open .morebtn { color: var(--ls-accent-deep); }

  main table, main table tbody, main table tfoot { display: block; }
  main table thead { display: none; }
  main table tr { display: block; border: 1px solid var(--line); border-radius: var(--r); padding: 10px 12px; margin-bottom: 10px; background: var(--ls-white); }
  main table tr.click:hover td { background: none; }
  main table td { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; padding: 3px 0; border: 0; text-align: right; }
  main table td[data-label]::before { content: attr(data-label); color: var(--ls-grey-500); font-size: 12px; flex: none; text-align: left; }
  main table td:not([data-label]) { justify-content: flex-end; }
  main table td:has(> b), main table td:has(> a > b), main table td:has(> .ic + b) { display: block; text-align: left; }
  main table td:has(> b)::before, main table td:has(> a > b)::before, main table td:has(> .ic + b)::before { display: block; margin-bottom: 1px; }
  main table td:empty { display: none; }
  main table tfoot tr { background: var(--ls-ground); }
  main table tfoot td { padding: 3px 0; border: 0; }
  main table tr.hid { display: none; }
  main table td.n { white-space: normal; }
  #lines input, #lines select { width: 100% !important; min-width: 0; }
  #lines td, #lines td:nth-child(n) { display: block; width: auto; text-align: left; padding: 4px 0; }
  #lines td[data-label]::before { display: block; margin-bottom: 3px; }
  #lines tr.iskm td[data-label=Importo], #lines tr.iskm td[data-label=Valuta], #lines tr.iskm td[data-label=Allegati] { display: none; }
  #lines tr:not(.iskm) td[data-label=Km] { display: none; }
  #lines input[type=file] { width: 100%; }
  .receipt-preview { max-height: 300px; }
}
