:root {
  --bg: #f4f5f7; --card: #fff; --text: #172b4d; --muted: #6b778c; --line: #dfe1e6;
  --accent: #4d6ee2; --accent-hover: #3b5cc5; --accent-text: #fff; --accent-soft: #edf1fd;
  --danger: #c0352b; --ok: #1d7a46; --chart: #4d6ee2;
  --side: #1a2a44; --side-text: #c5cede; --side-active: #2b3f63;
  --radius: 8px; --shadow: 0 1px 2px rgba(23, 43, 77, .06);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12151a; --card: #1b2028; --text: #e6e9ee; --muted: #98a2b3; --line: #2e3540;
    --accent: #6a88f0; --accent-hover: #8aa2f5; --accent-text: #0d1220; --accent-soft: #232c45;
    --danger: #ff7b70; --ok: #5fd08f; --chart: #6a88f0;
    --side: #0e1420; --side-text: #aab4c5; --side-active: #1f2a40; --shadow: none;
  }
}
* { box-sizing: border-box; }
body { margin: 0; font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, sans-serif; background: var(--bg); color: var(--text); }
h1 { font-size: 22px; margin: 0; }
h2 { font-size: 15px; margin: 0; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ---------- struttura ---------- */
.shell { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.shell[hidden] { display: none; }
.sidebar { background: var(--side); color: var(--side-text); display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; padding: 16px 12px; }
.brand { display: flex; align-items: center; gap: 10px; color: #fff; font-weight: 600; font-size: 16px; padding: 4px 8px 20px; }
.brand-mark { height: 30px; width: auto; color: #fff; }
.sidebar nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.sidebar nav a, .side-btn { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 6px; color: var(--side-text); text-decoration: none; font-weight: 500; }
.sidebar nav a:hover, .side-btn:hover { background: var(--side-active); color: #fff; }
.sidebar nav a.active { background: var(--accent); color: #fff; }
.ico { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.sidebar-foot { border-top: 1px solid rgba(255, 255, 255, .12); padding-top: 10px; display: grid; gap: 4px; }
#whoami { padding: 0 10px; font-size: 12px; opacity: .75; overflow: hidden; text-overflow: ellipsis; }
.side-btn { border: 0; background: none; cursor: pointer; font: inherit; font-weight: 500; width: 100%; }
.content { min-width: 0; }
main { max-width: 1120px; margin: 0 auto; padding: 20px 24px 60px; }
.page-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.page-head h1 { flex: 1; }

/* ---------- timer ---------- */
.timer { position: sticky; top: 0; z-index: 5; background: var(--card); border-bottom: 1px solid var(--line); padding: 10px 24px; }
.timer form, .timer .running { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; max-width: 1072px; margin: 0 auto; }
.timer select, .timer input { flex: 1; min-width: 150px; }
.timer .what { flex: 1; min-width: 160px; }
.clock { font-size: 24px; font-weight: 600; font-variant-numeric: tabular-nums; min-width: 104px; }
.pulse { width: 10px; height: 10px; border-radius: 50%; background: var(--ok); animation: pulse 1.6s infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .3; } }
@media (prefers-reduced-motion: reduce) { .pulse { animation: none; } }

/* ---------- elementi ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin-bottom: 16px; box-shadow: var(--shadow); }
.card-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.card-head h2 { flex: 1; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: end; }
.row > .grow { flex: 1; min-width: 170px; }
label { display: grid; gap: 4px; font-size: 12px; font-weight: 600; color: var(--muted); }
label.check { display: flex; align-items: center; gap: 8px; font-weight: 500; font-size: 14px; color: var(--text); }
input, select, button, textarea { font: inherit; color: var(--text); }
input, select { padding: 8px 10px; border: 1px solid var(--line); border-radius: 6px; background: var(--card); min-width: 0; }
input:focus, select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 2px rgba(77, 110, 226, .2); }
input[type=checkbox] { width: 16px; height: 16px; accent-color: var(--accent); }
button { padding: 8px 14px; border: 1px solid var(--line); border-radius: 6px; background: var(--card); cursor: pointer; font-weight: 500; white-space: nowrap; }
button:hover:not(:disabled) { border-color: var(--accent); }
button.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
button.primary:hover:not(:disabled) { background: var(--accent-hover); border-color: var(--accent-hover); }
button.stop { background: var(--danger); border-color: var(--danger); color: #fff; }
button.link { border: 0; background: none; color: var(--accent); padding: 2px 6px; font-weight: 500; }
button.link.danger { color: var(--danger); }
button.icon { display: inline-flex; align-items: center; justify-content: center; padding: 5px; border-radius: 50%; color: var(--accent); }
button:disabled { opacity: .5; cursor: default; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chips button { padding: 5px 12px; border-radius: 16px; font-size: 13px; }
.chips button.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.tag { font-size: 12px; padding: 1px 8px; border-radius: 10px; border: 1px solid var(--line); color: var(--muted); white-space: nowrap; }
.tag.ok { color: var(--ok); border-color: var(--ok); }
.tag.todo { color: var(--accent); border-color: var(--accent); }
td.sel { width: 28px; padding-right: 0; }
.selbar { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin: 14px 0 8px; padding: 8px 10px; background: var(--accent-soft); border-radius: 6px; }
.selbar .grow { flex: 1; font-weight: 600; }
.notice { background: var(--accent-soft); border-radius: 6px; padding: 9px 12px; margin: 12px 0 0; }
.empty { color: var(--muted); padding: 18px 4px; text-align: center; }
code { background: var(--bg); padding: 2px 6px; border-radius: 4px; word-break: break-all; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; }
th.num { text-align: right; }
tbody tr:last-child td { border-bottom: 0; }
tr.day td { background: var(--bg); font-weight: 600; padding: 7px 10px; }
tr.archived td { opacity: .55; }
td.actions { text-align: right; white-space: nowrap; }
.sub { display: block; color: var(--muted); font-size: 12.5px; }
.totals { display: flex; gap: 24px; flex-wrap: wrap; align-items: center; margin-top: 14px; }
.totals b { font-size: 18px; font-variant-numeric: tabular-nums; }
.totals .grow { flex: 1; }

/* ---------- panoramica ---------- */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.tile { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.tile .label { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.tile .value { font-size: 26px; font-weight: 600; font-variant-numeric: tabular-nums; line-height: 1.3; }
.tile .hint { font-size: 12.5px; color: var(--muted); }
.two { display: grid; grid-template-columns: 1.4fr 1fr; gap: 16px; align-items: start; }
.chart { position: relative; height: 170px; display: flex; align-items: stretch; gap: 2px; padding-top: 18px; border-bottom: 1px solid var(--line); }
.chart .max { position: absolute; top: 0; left: 0; right: 0; border-top: 1px dashed var(--line); font-size: 11px; color: var(--muted); line-height: 16px; }
.chart .col { flex: 1; display: flex; align-items: flex-end; position: relative; min-width: 0; }
.chart .bar { width: 100%; max-width: 30px; margin: 0 auto; background: var(--chart); border-radius: 4px 4px 0 0; min-height: 0; }
.chart .col:hover .bar { filter: brightness(1.15); }
.chart .col:hover::after { content: attr(data-tip); position: absolute; bottom: calc(100% - 14px); left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); font-size: 12px; padding: 3px 8px; border-radius: 4px; white-space: nowrap; z-index: 2; pointer-events: none; }
.chart-x { display: flex; gap: 2px; margin-top: 4px; }
.chart-x span { flex: 1; text-align: center; font-size: 11px; color: var(--muted); min-width: 0; overflow: hidden; }
.chart-x span.today { color: var(--text); font-weight: 600; }
.recent { display: grid; gap: 2px; }
.recent button { display: flex; align-items: center; gap: 10px; text-align: left; border: 0; padding: 8px; border-radius: 6px; white-space: normal; }
.recent button:hover { background: var(--accent-soft); }
.recent .ico { color: var(--accent); }
.meter { height: 6px; border-radius: 3px; background: var(--line); overflow: hidden; min-width: 80px; }
.meter i { display: block; height: 100%; background: var(--chart); border-radius: 3px; }
.meter.over i { background: var(--danger); }

/* ---------- dialog ---------- */
dialog { border: 1px solid var(--line); border-radius: 10px; padding: 0; background: var(--card); color: var(--text); width: min(520px, calc(100vw - 24px)); box-shadow: 0 12px 40px rgba(0, 0, 0, .25); }
dialog::backdrop { background: rgba(9, 16, 30, .5); }
.dialog-form { padding: 20px; display: grid; gap: 16px; }
.dialog-body { display: grid; gap: 12px; }
.dialog-body .pair { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.dialog-body .three { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }
.picklist { display: grid; gap: 2px; max-height: 180px; overflow: auto; border: 1px solid var(--line); border-radius: 6px; padding: 4px; }
.picklist button { border: 0; text-align: left; white-space: normal; padding: 6px 8px; }
.picklist button:hover { background: var(--accent-soft); }

/* ---------- login ---------- */
.login-box { max-width: 360px; margin: 80px auto; padding: 0 16px; text-align: center; }
.brand-logo { height: 50px; width: auto; margin-bottom: 12px; color: #393738; }
@media (prefers-color-scheme: dark) { .brand-logo { color: #e6e9ee; } }
.login-subtitle { color: var(--muted); font-size: 14px; margin: 0 0 24px; }
.login-card { text-align: left; padding: 20px; border-radius: 6px; display: grid; gap: 16px; }
.login-card label { gap: 6px; text-transform: uppercase; letter-spacing: .3px; }
.login-card input { width: 100%; padding: 8px 12px; }
.login-card button { width: 100%; margin-top: 8px; padding: 9px 14px; }

#toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 8px; max-width: 90vw; z-index: 50; }
#toast.error { background: var(--danger); color: #fff; }

/* ---------- schermi stretti: il menu diventa una barra in basso ---------- */
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; top: auto; bottom: 0; left: 0; right: 0; height: auto; flex-direction: row; padding: 4px; z-index: 20; }
  .brand, #whoami { display: none; }
  .sidebar nav { flex-direction: row; justify-content: space-around; }
  .sidebar nav a, .side-btn { flex-direction: column; gap: 2px; font-size: 10.5px; padding: 6px 4px; flex: 1; }
  .sidebar-foot { border: 0; padding: 0; display: flex; }
  main { padding: 16px 12px 90px; }
  .timer { padding: 10px 12px; }
  .two { grid-template-columns: 1fr; }
  .dialog-body .three { grid-template-columns: 1fr 1fr; }
}

/* ---------- spese, righe fattura, settimana, preferiti ---------- */
.tag.bad { color: var(--danger); border-color: var(--danger); }
table.lines input { width: 100%; padding: 6px 8px; }
table.lines input.desc { margin-top: 4px; font-size: 12.5px; color: var(--muted); }
table.lines input.narrow { width: 92px; text-align: right; }
table.lines td { vertical-align: top; }
.star { border: 0; background: none; padding: 2px 4px; font-size: 17px; line-height: 1; color: var(--line); }
.star.on { color: #e5a50a; }
.star:hover { color: #e5a50a; }
.budget-row { display: grid; grid-template-columns: 1fr 1.2fr; gap: 12px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line); }
.budget-row:last-child { border-bottom: 0; }
.day-card { border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 10px; display: grid; gap: 8px; }
.day-card.short { border-left: 4px solid var(--danger); }
.day-card.today { background: var(--accent-soft); }
.day-head { display: flex; align-items: center; gap: 10px; }
.day-head .grow, .day-entry .grow { flex: 1; }
.day-head b:first-child { text-transform: capitalize; }
.day-entry { display: flex; gap: 12px; align-items: baseline; text-align: left; border: 0; padding: 4px 6px; background: none; white-space: normal; font-weight: 400; width: 100%; }
.day-entry:hover:not(:disabled) { background: var(--bg); }
.gaps { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.gap { border: 1px dashed var(--danger); color: var(--danger); background: none; padding: 5px 10px; font-size: 13px; }
.gap:hover { background: var(--card); }
[hidden] { display: none !important; }
@media (max-width: 860px) {
  .sidebar nav { overflow-x: auto; justify-content: flex-start; }
  .sidebar nav a { min-width: 62px; }
}
