:root {
  --bg: #0e0f12;
  --bg-2: #15171c;
  --card: #1b1e24;
  --card-2: #21252c;
  --line: #2c313a;
  --text: #f2f4f7;
  --muted: #8b929b;
  --accent: #ff5a00;
  --accent-2: #ff7a18;
  --ok: #2ec28a;
  --radius: 22px;
  --radius-sm: 14px;
  --shadow: 0 10px 30px rgba(0,0,0,.45);
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  font-family: -apple-system, "Segoe UI", Roboto, Inter, system-ui, sans-serif;
  background: radial-gradient(120% 80% at 100% 0%, #2a1405 0%, var(--bg) 45%);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input, select { font-family: inherit; }

/* ============ LOGIN ============ */
.login-screen {
  min-height: 100dvh; display: grid; place-items: center; padding: 24px;
}
.login-card {
  width: 100%; max-width: 380px; background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 34px 26px; box-shadow: var(--shadow); text-align: center;
}
.login-logo { width: 200px; max-width: 80%; filter: invert(1); margin-bottom: 14px; }
.login-card h1 { font-size: 26px; font-weight: 800; }
.login-card p { margin-top: 4px; font-size: 13px; }
#loginForm { margin-top: 24px; display: grid; gap: 14px; text-align: left; }
#loginForm label { font-size: 12px; color: var(--muted); display: grid; gap: 6px; }
#loginForm input {
  background: var(--bg-2); border: 1px solid var(--line); color: var(--text);
  padding: 14px 16px; border-radius: var(--radius-sm); font-size: 16px;
}
#loginForm input:focus { outline: 2px solid var(--accent); border-color: transparent; }
.login-error { color: #ff6b6b; font-size: 13px; min-height: 18px; text-align: center; }

.btn-primary {
  background: linear-gradient(135deg, var(--accent-2), var(--accent));
  color: #fff; font-weight: 700; font-size: 16px; padding: 15px; border-radius: 999px;
  display: flex; align-items: center; justify-content: center; gap: 10px;
  box-shadow: 0 8px 20px rgba(255,90,0,.35);
}
.btn-primary span { opacity: .8; letter-spacing: -2px; }

/* ============ APP SHELL ============ */
.app { min-height: 100dvh; }
#view { padding: 0 18px calc(110px + var(--safe-b)); max-width: 720px; margin: 0 auto; }

.topbar { display: flex; align-items: center; gap: 14px; padding: 22px 2px 10px; }
.topbar .avatar {
  width: 46px; height: 46px; border-radius: 50%; background: var(--card-2);
  display: grid; place-items: center; font-weight: 800; color: var(--accent); font-size: 18px;
  border: 1px solid var(--line);
}
.topbar h2 { font-size: 15px; font-weight: 700; line-height: 1.2; }
.topbar .sub { font-size: 12px; color: var(--muted); }
.topbar .spacer { flex: 1; }
.icon-btn {
  width: 44px; height: 44px; border-radius: 50%; background: var(--card-2);
  display: grid; place-items: center; border: 1px solid var(--line);
}
.icon-btn svg { width: 20px; height: 20px; fill: none; stroke: var(--text); stroke-width: 2; }

/* ============ HOME ============ */
.hero { padding: 8px 2px 0; }
.hero .kicker { color: var(--muted); font-size: 14px; max-width: 260px; line-height: 1.5; }
.hero h1 { font-size: 46px; line-height: 1.02; font-weight: 800; margin-top: 14px; letter-spacing: -1px; }
.hero h1 .accent { color: var(--accent); }
.hero-photo {
  position: relative; margin: 14px 0 18px; border-radius: var(--radius);
  overflow: hidden; border: 1px solid var(--line);
  box-shadow: 0 18px 40px rgba(0,0,0,.5), 0 0 0 1px rgba(255,90,0,.08);
  background: #000;
}
.hero-photo::before {
  content: ""; position: absolute; inset: -2px; z-index: 0;
  background: radial-gradient(60% 50% at 50% 100%, rgba(255,90,0,.35), transparent 70%);
}
.hero-photo img {
  display: block; width: 100%; max-height: 360px; object-fit: cover; object-position: center;
  position: relative; z-index: 1;
  /* tuning digitale: contrasto/saturazione realistici */
  filter: contrast(1.09) saturate(1.16) brightness(1.03);
}
/* vignettatura sui bordi */
.hero-photo::after {
  content: ""; position: absolute; inset: 0; z-index: 2; pointer-events: none;
  box-shadow: inset 0 0 75px 22px rgba(0,0,0,.55);
  background: radial-gradient(120% 90% at 50% 38%, transparent 55%, rgba(0,0,0,.45) 100%);
}
.hero-photo-grad {
  position: absolute; left: 0; right: 0; bottom: 0; height: 60%; z-index: 2;
  /* luce arancione che sale dal basso + fusione col fondo scuro */
  background:
    linear-gradient(to top, var(--bg) 2%, rgba(14,15,18,.35) 45%, transparent),
    linear-gradient(to top, rgba(255,90,0,.32) 0%, rgba(255,122,24,.12) 16%, transparent 38%);
  pointer-events: none;
}
.hero-badge {
  position: absolute; left: 16px; bottom: 14px; z-index: 3; line-height: 1.1;
}
.hero-badge b { display: block; font-size: 26px; font-weight: 800; letter-spacing: 1px;
  text-shadow: 0 2px 10px rgba(0,0,0,.7); }
.hero-badge span { font-size: 12px; color: var(--muted); }
.photo-edit {
  position: absolute; top: 12px; right: 12px; z-index: 3;
  width: 40px; height: 40px; border-radius: 50%; background: rgba(0,0,0,.55);
  backdrop-filter: blur(6px); border: 1px solid rgba(255,255,255,.15); display: grid; place-items: center;
}
.photo-edit svg { width: 18px; height: 18px; stroke: #fff; fill: none; stroke-width: 2; }

.hero-empty {
  width: 100%; margin: 14px 0 18px; padding: 40px 20px; border-radius: var(--radius);
  border: 2px dashed var(--line); background: var(--card); color: var(--muted);
  display: flex; flex-direction: column; align-items: center; gap: 8px; text-align: center;
}
.hero-empty svg { width: 38px; height: 38px; stroke: var(--accent); fill: none; stroke-width: 1.6; }
.hero-empty span { font-size: 15px; font-weight: 700; color: var(--text); }
.hero-empty small { font-size: 12px; }
.hero-actions { display: flex; gap: 12px; align-items: center; }
.round-btn {
  width: 56px; height: 56px; border-radius: 50%; background: var(--card-2);
  border: 1px solid var(--line); display: grid; place-items: center; flex: none;
}
.round-btn svg { width: 22px; height: 22px; stroke: var(--text); fill: none; stroke-width: 2; }

.stat-grid { display: grid; grid-template-columns: repeat(2,1fr); gap: 12px; margin-top: 22px; }
.stat {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 16px;
}
.stat .v { font-size: 30px; font-weight: 800; }
.stat .l { font-size: 12px; color: var(--muted); margin-top: 2px; }
.stat.accent { background: linear-gradient(135deg, var(--accent-2), var(--accent)); border: none; }
.stat.accent .l { color: rgba(255,255,255,.85); }

/* ============ FOGLIO ============ */
.week-bar {
  display: flex; align-items: center; gap: 8px; margin: 6px 0 14px;
  background: var(--card); border: 1px solid var(--line); border-radius: 999px; padding: 6px;
}
.week-bar .nav { width: 40px; height: 40px; border-radius: 50%; background: var(--card-2); display:grid; place-items:center; font-size:20px; }
.week-bar .label { flex: 1; text-align: center; }
.week-bar .label b { display: block; font-size: 15px; }
.week-bar .label small { color: var(--muted); font-size: 12px; }

.day-tabs { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 14px; scrollbar-width: none; }
.day-tabs::-webkit-scrollbar { display: none; }
.day-tab {
  flex: none; padding: 10px 16px; border-radius: 14px; background: var(--card);
  border: 1px solid var(--line); text-align: center; min-width: 72px;
}
.day-tab b { display: block; font-size: 14px; }
.day-tab small { color: var(--muted); font-size: 11px; }
.day-tab.active { background: linear-gradient(135deg, var(--accent-2), var(--accent)); border: none; }
.day-tab.active small { color: rgba(255,255,255,.85); }
.day-tab.has-data::after { content: ""; display:block; width:6px; height:6px; border-radius:50%; background: var(--ok); margin: 5px auto 0; }
.day-tab.active.has-data::after { background:#fff; }

.km-row { display: grid; grid-template-columns: repeat(3,1fr); gap: 10px; margin-bottom: 16px; }
.km-row .field { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 10px 12px; }
.km-row .field label { font-size: 11px; color: var(--muted); }
.km-row .field input { width: 100%; background: none; border: none; color: var(--text); font-size: 18px; font-weight: 700; padding: 2px 0; }
.km-row .field input:focus { outline: none; }
.km-row .field.tot { background: var(--card-2); }
.km-row .field.tot .v { font-size: 18px; font-weight: 800; color: var(--accent); }

.viaggio {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; margin-bottom: 16px;
}
.viaggio-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.viaggio-head h3 { font-size: 18px; font-weight: 800; }
.viaggio-head .badge { font-size: 11px; padding: 5px 12px; border-radius: 999px; border: 1px solid var(--accent); color: var(--accent); }

.tipo-chips { display: flex; gap: 8px; margin-bottom: 14px; }
.tipo-chip {
  flex: 1; padding: 9px; border-radius: 12px; background: var(--card-2);
  border: 1px solid var(--line); font-size: 13px; font-weight: 600; color: var(--muted);
}
.tipo-chip.on { background: linear-gradient(135deg, var(--accent-2), var(--accent)); color:#fff; border:none; }

.km-input-wrap { margin-bottom: 14px; }
.km-input-wrap label { font-size: 12px; color: var(--muted); }
.km-input-wrap input {
  width: 100%; background: var(--card-2); border: 1px solid var(--line); color: var(--text);
  padding: 12px 14px; border-radius: 12px; font-size: 16px; font-weight: 700; margin-top: 5px;
}
.km-input-wrap input:focus { outline: 2px solid var(--accent); border-color: transparent; }

.list-block { margin-top: 6px; }
.list-block .lh { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.list-block .lh span { font-size: 12px; font-weight: 700; letter-spacing: 1px; color: var(--muted); }
.add-btn { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--accent); font-weight: 700; }
.add-btn svg { width: 16px; height: 16px; stroke: var(--accent); fill: none; stroke-width: 2.5; }

.line-item { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.line-item .num { width: 22px; text-align: center; color: var(--muted); font-size: 13px; font-weight: 700; flex: none; }
.line-item input {
  flex: 1; background: var(--bg-2); border: 1px solid var(--line); color: var(--text);
  padding: 11px 12px; border-radius: 10px; font-size: 15px;
}
.line-item input:focus { outline: 2px solid var(--accent); border-color: transparent; }
.line-item .del { width: 34px; height: 38px; border-radius: 10px; display:grid; place-items:center; color: var(--muted); flex:none; }
.line-item .del svg { width: 16px; height: 16px; stroke: #ff6b6b; fill:none; stroke-width:2; }
.empty-hint { color: var(--muted); font-size: 13px; font-style: italic; padding: 4px 0 8px; }

.divider { height: 1px; background: var(--line); margin: 14px 0; }

/* weekly summary */
.summary { margin-top: 8px; }
.summary h3 { font-size: 14px; letter-spacing: 1px; color: var(--muted); margin-bottom: 10px; }
.summary-grid { display: grid; grid-template-columns: repeat(2,1fr); gap: 10px; }
.summary-cell { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 14px; }
.summary-cell .v { font-size: 26px; font-weight: 800; }
.summary-cell .l { font-size: 12px; color: var(--muted); }
.summary-cell.km { grid-column: span 2; background: linear-gradient(135deg, var(--accent-2), var(--accent)); border:none; }
.summary-cell.km .l { color: rgba(255,255,255,.85); }

.saved-pill { font-size: 12px; color: var(--ok); display:flex; align-items:center; gap:6px; }

/* ============ CALCOLATRICE ============ */
.calc-card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 22px; margin-top: 8px; }
.calc-card label { font-size: 12px; color: var(--muted); display:block; margin-bottom: 6px; }
.calc-card input {
  width: 100%; background: var(--bg-2); border: 1px solid var(--line); color: var(--text);
  padding: 16px; border-radius: var(--radius-sm); font-size: 22px; font-weight: 700; margin-bottom: 16px;
}
.calc-card input:focus { outline: 2px solid var(--accent); border-color: transparent; }
.calc-result { text-align:center; padding: 22px; border-radius: var(--radius-sm); background: var(--card-2); margin-top: 4px; }
.calc-result .big { font-size: 46px; font-weight: 800; color: var(--accent); }
.calc-result .big.neg { color: #ff6b6b; }
.calc-result .big.pos { color: var(--ok); }
.calc-result .sub { color: var(--muted); font-size: 13px; margin-top: 4px; }

/* ============ PRINT VIEW (screen preview wrapper) ============ */
.print-intro { margin-top: 8px; }
.print-intro p { color: var(--muted); font-size: 14px; line-height: 1.5; margin-bottom: 16px; }
.preview-scroll {
  overflow-x: auto; background: #fff; border-radius: 12px; border: 1px solid var(--line);
  padding: 10px; margin-bottom: 16px;
}
.preview-scroll .sheet { transform-origin: top left; }

/* ============ TABBAR ============ */
.tabbar {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(16px + var(--safe-b));
  display: flex; align-items: center; gap: 6px; background: rgba(27,30,36,.9);
  backdrop-filter: blur(14px); border: 1px solid var(--line); border-radius: 999px;
  padding: 8px; box-shadow: var(--shadow); z-index: 50;
}
.tab { width: 54px; height: 54px; border-radius: 50%; display:grid; place-items:center; }
.tab svg { width: 22px; height: 22px; fill:none; stroke: var(--muted); stroke-width: 2; }
.tab.active { background: linear-gradient(135deg, var(--accent-2), var(--accent)); }
.tab.active svg { stroke: #fff; }

/* ============ THE PAPER SHEET (used in screen preview + print) ============ */
.sheet {
  width: 1120px; background: #fff; color: #000; padding: 14px 18px;
  font-family: Arial, Helvetica, sans-serif; font-size: 11px;
}
.sheet * { box-sizing: border-box; }
.sheet-header { display: flex; align-items: center; border-bottom: 3px solid #000; padding-bottom: 8px; }
.sheet-header .logo { width: 230px; }
.sheet-header .meta { display: flex; gap: 26px; margin-left: 26px; flex: 1; font-size: 13px; }
.sheet-header .meta .lbl { color: #444; font-size: 10px; letter-spacing: 1px; }
.sheet-header .meta .val { font-weight: 800; font-size: 16px; }
.sheet-header .meta .line { display:inline-block; min-width: 120px; border-bottom: 1px solid #000; }

.km-table, .trip-table { width: 100%; border-collapse: collapse; margin-top: 8px; table-layout: fixed; }
.km-table col.cfirst, .trip-table col.cfirst { width: 86px; }
.km-table td, .trip-table td, .trip-table th { border: 1px solid #000; padding: 3px 6px; vertical-align: top; overflow: hidden; }
.cell-line .t, .sat-it { word-break: break-word; }
.km-table td:first-child { font-weight: 700; background: #fff; }
.day-th { background: #fff; color: #000; font-weight: 800; text-align: center; padding: 5px; letter-spacing: 1px; border-bottom: 2.5px solid #000; }
.km-table td { height: 22px; }

.trip-label { background: #fff; color: #000; font-weight: 800; writing-mode: horizontal-tb; text-align:center; letter-spacing: 1px; border: 2px solid #000; }
.cell-sec-title { font-weight: 800; font-size: 10px; letter-spacing: 1px; }
.cell-line { display: flex; gap: 4px; align-items: center; padding: 1px 0; }
.cell-line .n { width: 12px; color: #555; }
.cell-line .t { flex: 1; border-bottom: 1px solid #999; min-height: 13px; padding-left: 2px; }
.tipo-print { display:flex; gap: 8px; font-size: 10px; margin-top: 3px; }
.tipo-print .box { display:inline-flex; align-items:center; gap: 3px; }
.tipo-print .sq { width: 11px; height: 11px; border: 1.5px solid #000; display:inline-grid; place-items:center; font-weight:900; line-height:1; }
.ritiri-sec { border-top: 1px dashed #000; margin-top: 4px; padding-top: 4px; }

.sheet-foot { display: flex; justify-content: space-between; align-items: flex-end; margin-top: 10px; gap: 16px; }
.foot-totals { display: flex; gap: 10px; flex-wrap: wrap; }
.foot-totals .ft { border: 2px solid #000; padding: 6px 12px; text-align:center; }
.foot-totals .ft b { display:block; font-size: 20px; }
.foot-totals .ft span { font-size: 9px; letter-spacing: 1px; }
.km-week-box { border: 2px solid #000; padding: 10px 18px; font-size: 14px; }
.km-week-box b { font-size: 22px; }

/* Sabato toggle (app) */
.sat-toggle {
  width: 100%; padding: 13px; border-radius: 14px; margin-bottom: 12px;
  background: var(--card); border: 1px dashed var(--line); color: var(--accent);
  font-weight: 700; font-size: 14px;
}
.sat-toggle.on { background: linear-gradient(135deg, var(--accent-2), var(--accent)); color: #fff; border: none; }

/* Sabato block (print, orizzontale, ink-friendly) */
.sat-block { border: 2px solid #000; margin-top: 8px; padding: 6px 10px; }
.sat-head { display: flex; align-items: center; gap: 18px; border-bottom: 1.5px solid #000; padding-bottom: 4px; margin-bottom: 5px; }
.sat-title { font-weight: 800; letter-spacing: 1px; font-size: 13px; }
.sat-date { font-weight: 700; }
.sat-km { margin-left: auto; font-size: 11px; }
.sat-km b { font-size: 12px; }
.sat-trip { display: flex; align-items: flex-start; gap: 10px; padding: 4px 0; border-bottom: 1px dashed #000; flex-wrap: wrap; }
.sat-trip:last-child { border-bottom: none; padding-bottom: 0; }
.sat-trip-label { font-weight: 800; width: 78px; flex: none; }
.sat-trip .tipo-print { margin: 0; flex: none; }
.sat-lists { display: flex; flex-direction: column; gap: 4px; flex: 1; min-width: 320px; }
.sat-list { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.sat-list b { font-size: 10px; letter-spacing: 1px; flex: none; width: 62px; }
.sat-it { display: inline-flex; align-items: center; gap: 3px; border-bottom: 1px solid #999; min-width: 135px; padding: 0 3px; min-height: 13px; }
.sat-it i { font-style: normal; color: #555; font-size: 9px; }

#printArea { display: none; }

/* ============ PRINT ============ */
@media print {
  @page { size: A4 landscape; margin: 6mm; }
  html, body { background: #fff; height: auto; }
  #login, #app { display: none !important; }
  #printArea { display: block !important; }
  #printArea .sheet {
    width: 100%; padding: 0; font-size: 9px;
  }
  .sheet, .sheet * { color: #000 !important; background: #fff !important; }
  .day-th { border-bottom: 2.5px solid #000 !important; }
  .trip-label { border: 2px solid #000 !important; }
  /* compressione verticale per stare in 1 pagina A4 landscape */
  #printArea .sheet-header { padding-bottom: 5px; }
  #printArea .km-table, #printArea .trip-table { margin-top: 5px; }
  #printArea .km-table td { height: 16px; padding: 1px 5px; }
  #printArea .trip-table td, #printArea .trip-table th { padding: 2px 5px; }
  #printArea .cell-line { padding: 0; }
  #printArea .cell-line .t { min-height: 11px; }
  #printArea .ritiri-sec { margin-top: 3px; padding-top: 3px; }
  #printArea .sheet-foot { margin-top: 6px; }
  #printArea .foot-totals .ft { padding: 4px 10px; }
  #printArea .foot-totals .ft b { font-size: 16px; }
  #printArea .km-week-box { padding: 6px 14px; }
  #printArea .sat-block { margin-top: 6px; padding: 4px 8px; }
  #printArea .sat-it { min-height: 11px; }
  #printArea .sheet > *:last-child { page-break-after: avoid; }
}
