:root {
  --bg: #0a0a0c;
  --panel: #131316;
  --panel-2: #1b1b1f;
  --line: #2a2a30;
  --ink: #f0f0f2;
  --muted: #8c8c96;
  --accent: #f0f0f2;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  padding-bottom: 60px;
}
.wrap { max-width: 1040px; margin: 0 auto; padding: 0 16px; }

/* nav */
#nav {
  border-bottom: 1px solid var(--line);
  background: var(--panel);
  margin-bottom: 26px;
}
.nav-inner {
  max-width: 1040px;
  margin: 0 auto;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 16px;
}
.nav-title { font-weight: 700; letter-spacing: .04em; font-size: 13px; color: var(--muted); flex: none; }
.nav-links {
  display: flex;
  gap: 4px;
  flex: 1 1 auto;
  min-width: 0;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.nav-links::-webkit-scrollbar { display: none; }
.nav-links a {
  color: var(--muted);
  text-decoration: none;
  font-size: 13.5px;
  font-weight: 500;
  padding: 10px 14px;
  border-radius: 7px;
  white-space: nowrap;
  flex: none;
}
.nav-links a:hover { color: var(--ink); background: var(--panel-2); }
.nav-links a.active { color: var(--ink); background: var(--panel-2); }

@media (max-width: 560px) {
  .nav-title { display: none; }
}

h1 { font-size: 22px; font-weight: 700; margin: 0 0 4px; letter-spacing: -.01em; }
h1.page-title { margin-bottom: 4px; }
.page-sub { color: var(--muted); font-size: 13.5px; margin: 0 0 22px; }

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 18px 20px;
  margin-bottom: 18px;
}
.card h2 { font-size: 15.5px; font-weight: 700; margin: 0 0 4px; }
.card .hint { color: var(--muted); font-size: 12.5px; margin: 0 0 14px; line-height: 1.5; }

/* summary badges */
.summary-row { display: flex; flex-wrap: wrap; gap: 10px; }
.badge-stat {
  flex: 1 1 130px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.badge-stat .n { font-size: 19px; font-weight: 700; }
.badge-stat .l { font-size: 11px; color: var(--muted); line-height: 1.2; }

/* forms */
label.field-label {
  display: block;
  font-size: 11.5px;
  color: var(--muted);
  margin: 14px 0 6px;
  text-transform: uppercase;
  letter-spacing: .05em;
}
input[type=text], input[type=number], input[type=time], input[type=date], select, textarea {
  width: 100%;
  padding: 11px 12px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--ink);
  /* 16px minimum: below that iOS Safari auto-zooms the page on focus. */
  font-size: 16px;
  font-family: inherit;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--muted); outline-offset: 1px; }
textarea { resize: vertical; min-height: 60px; }

.opt-grid { display: flex; flex-wrap: wrap; gap: 8px; }
.opt { position: relative; }
.opt input { position: absolute; opacity: 0; inset: 0; cursor: pointer; margin: 0; width: 100%; height: 100%; }
.opt span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 40px;
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  font-size: 13.5px;
  color: var(--muted);
  transition: .12s;
  touch-action: manipulation;
}
.opt input:checked + span {
  background: var(--chip-bg, var(--panel-2));
  border-color: var(--chip-c, var(--muted));
  color: var(--ink);
  font-weight: 600;
}
.opt input:focus-visible + span { outline: 2px solid var(--ink); outline-offset: 2px; }

.form-row { display: flex; gap: 12px; flex-wrap: wrap; }
.form-row > * { flex: 1 1 160px; }
.form-actions { display: flex; gap: 10px; margin-top: 16px; flex-wrap: wrap; }
button {
  font-family: inherit;
  font-weight: 600;
  font-size: 14px;
  border: none;
  border-radius: 8px;
  padding: 11px 18px;
  min-height: 42px;
  cursor: pointer;
  transition: .12s;
  touch-action: manipulation;
}
button:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
.btn-primary { background: var(--ink); color: #0a0a0c; }
.btn-primary:hover { filter: brightness(.92); }
.btn-ghost { background: transparent; color: var(--muted); border: 1px solid var(--line); }
.btn-ghost:hover { color: var(--ink); border-color: var(--muted); }
.btn-danger { background: transparent; color: #e2586b; border: 1px solid #e2586b; }
.btn-small { padding: 9px 14px; min-height: 38px; font-size: 12.5px; border-radius: 7px; }

/* matrix */
.matrix-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; border-radius: 10px; }
table.matrix { border-collapse: collapse; width: 100%; min-width: 620px; }
table.matrix th, table.matrix td { padding: 8px 9px; text-align: center; border-bottom: 1px solid var(--line); }
table.matrix th { font-size: 11px; color: var(--ink); font-weight: 700; vertical-align: bottom; background: var(--panel-2); }
table.matrix th.name-col, table.matrix td.name-col { text-align: left; position: sticky; left: 0; background: var(--panel); min-width: 130px; }
table.matrix th.name-col { background: var(--panel-2); }
.stub { display: inline-block; padding: 4px 8px; border-radius: 6px; border: 1px dashed var(--line); font-size: 10.5px; line-height: 1.25; color: var(--muted); }
.cell-dot { width: 13px; height: 13px; border-radius: 50%; margin: 0 auto; }
.name-pill { display: flex; align-items: center; gap: 8px; }
.name-pill .dot { width: 8px; height: 8px; }
tfoot td { font-size: 10.5px; color: var(--muted); padding-top: 10px; }
tfoot .totalbar { height: 5px; border-radius: 4px; overflow: hidden; display: flex; margin-bottom: 4px; background: var(--panel-2); }
tfoot .totalbar span { display: block; height: 100%; }

/* list rows (friends / cars / ledger / bookings) */
.list-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 4px;
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}
.list-row:last-child { border-bottom: none; }
.list-main { display: flex; flex-direction: column; gap: 5px; flex: 1 1 240px; }
.list-title { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; font-weight: 700; }
.tag { font-size: 11px; padding: 4px 10px; border-radius: 999px; font-weight: 600; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex;
  align-items: center;
  font-size: 11.5px;
  min-height: 32px;
  padding: 6px 10px;
  border-radius: 7px;
  background: var(--panel-2);
  color: var(--muted);
  border: 1px solid var(--line);
  touch-action: manipulation;
}
.chip.paid { color: #3ecf8e; border-color: #3ecf8e; }
.row-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* poll-style bars (sondaggio macchina) */
.poll-row { margin-bottom: 12px; }
.poll-row .poll-label { display: flex; justify-content: space-between; font-size: 13px; margin-bottom: 5px; }
.poll-row .poll-label .n { color: var(--muted); font-size: 12px; }
.poll-row .poll-track { height: 8px; border-radius: 4px; background: var(--panel-2); overflow: hidden; }
.poll-row .poll-fill { height: 100%; background: var(--ink); border-radius: 4px; }

.balance-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 4px;
  border-bottom: 1px solid var(--line);
}
.balance-item:last-child { border-bottom: none; }
.balance-item input[type=checkbox] {
  width: 22px;
  height: 22px;
  flex: none;
  accent-color: var(--ink);
  cursor: pointer;
}
.balance-item .desc { flex: 1 1 auto; font-size: 13.5px; }
.balance-item .desc .muted { color: var(--muted); font-size: 11.5px; display: block; margin-top: 2px; }
.balance-item.is-paid .desc { color: var(--muted); text-decoration: line-through; }
.balance-item .amount { font-weight: 700; font-size: 13.5px; white-space: nowrap; }

.empty { text-align: center; color: var(--muted); padding: 26px 10px; font-size: 13.5px; }
.empty b { color: var(--ink); }
.status-msg { font-size: 12px; color: var(--muted); min-height: 16px; margin-top: 8px; }

.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 18px; }
.tab-btn {
  background: var(--panel);
  border: 1px solid var(--line);
  color: var(--muted);
}
.tab-btn.active { background: var(--panel-2); color: var(--ink); border-color: var(--muted); }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

footer.page-footer { text-align: center; color: var(--muted); font-size: 11.5px; margin-top: 30px; }

@media (max-width: 480px) {
  .card { padding: 14px 14px; }
  h1 { font-size: 19px; }
  .form-actions { flex-direction: column; }
  .form-actions button { width: 100%; }
  .row-actions { width: 100%; }
  .row-actions button { flex: 1 1 auto; }
}
