/* MePAnet Gare — stile unico per area cliente e pannello amministratore */
:root {
  --brand: #9E1B22;
  --brand-ink: #7d141a;
  --brand-soft: #f8e9ea;
  --ink: #1c1b1a;
  --ink-2: #45423f;
  --muted: #75706b;
  --line: #e6e2dd;
  --bg: #f5f3f0;
  --card: #ffffff;
  --amber: #8a4b06;
  --amber-soft: #fdf0d8;
  --green: #1f6b43;
  --green-soft: #e3f3e9;
  --blue: #1d4f8c;
  --blue-soft: #e5eef9;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(28, 27, 26, .06), 0 2px 8px rgba(28, 27, 26, .04);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --brand: #e0575e;
    --brand-ink: #f08a8f;
    --brand-soft: #3a1c1e;
    --ink: #f2efec;
    --ink-2: #d4cfca;
    --muted: #a39d97;
    --line: #34302d;
    --bg: #161412;
    --card: #211e1c;
    --amber: #f2b45c;
    --amber-soft: #3a2a12;
    --green: #7fd1a1;
    --green-soft: #15291e;
    --blue: #8db8ee;
    --blue-soft: #16243a;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; font-family: var(--font); font-size: 16px; line-height: 1.45;
  color: var(--ink); background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .5em; letter-spacing: -.01em; }
h1 { font-size: 1.45rem; }
h2 { font-size: 1.12rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 .8em; }
.muted { color: var(--muted); }
.small { font-size: .86rem; }
.num { font-variant-numeric: tabular-nums; }
.hidden { display: none !important; }

/* ---------- Header e navigazione ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: var(--card); border-bottom: 1px solid var(--line);
  padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top));
}
.topbar-in { max-width: 760px; margin: 0 auto; display: flex; align-items: center; gap: 12px; }
.admin .topbar-in { max-width: 1180px; }
.brand { display: flex; align-items: center; gap: 10px; color: var(--ink); font-weight: 700; }
.brand:hover { text-decoration: none; }
.brand-mark {
  width: 34px; height: 34px; border-radius: 9px; background: var(--brand); color: #fff;
  display: grid; place-items: center; font-weight: 800; font-size: 1.05rem; letter-spacing: -.02em;
}
.brand small { display: block; font-weight: 500; color: var(--muted); font-size: .75rem; line-height: 1.1; }
.topbar .spacer { flex: 1; }
.topnav { display: none; gap: 4px; }
.topnav a { padding: 8px 12px; border-radius: 9px; color: var(--ink-2); font-weight: 600; font-size: .92rem; }
.topnav a:hover { background: var(--bg); text-decoration: none; }
.topnav a.on { background: var(--brand-soft); color: var(--brand); }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: grid; grid-template-columns: repeat(3, 1fr);
  background: var(--card); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar a {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 8px 4px 9px; color: var(--muted); font-size: .72rem; font-weight: 600;
}
.tabbar a:hover { text-decoration: none; }
.tabbar a.on { color: var(--brand); }
.tabbar svg { width: 23px; height: 23px; }
@media (min-width: 900px) {
  .tabbar { display: none; }
  .topnav { display: flex; }
}

.page { max-width: 760px; margin: 0 auto; padding: 16px 16px 96px; }
.admin .page { max-width: 1180px; padding-bottom: 48px; }
@media (min-width: 900px) { .page { padding-bottom: 48px; } }

/* ---------- Componenti ---------- */
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px;
}
.card + .card, .section + .section { margin-top: 14px; }
.section { margin-top: 20px; }
.section-title { font-size: .78rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 700; margin: 0 0 8px 2px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 1px solid var(--line); background: var(--card); color: var(--ink);
  font: inherit; font-weight: 600; font-size: .95rem;
  padding: 10px 16px; border-radius: 11px; cursor: pointer; min-height: 44px;
}
.btn:hover { text-decoration: none; border-color: var(--muted); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-ink); border-color: var(--brand-ink); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.danger { color: var(--brand); }
.btn.sm { min-height: 34px; padding: 6px 12px; font-size: .86rem; border-radius: 9px; }
.btn.block { display: flex; width: 100%; }
.btn svg { width: 18px; height: 18px; flex: none; }

.chip {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 9px; border-radius: 999px; font-size: .76rem; font-weight: 700;
  background: var(--bg); color: var(--ink-2); border: 1px solid var(--line); white-space: nowrap;
}
.chip.urgente { background: var(--brand); color: #fff; border-color: var(--brand); }
.chip.presto { background: var(--amber-soft); color: var(--amber); border-color: transparent; }
.chip.nuova { background: var(--blue-soft); color: var(--blue); border-color: transparent; }
.chip.ok { background: var(--green-soft); color: var(--green); border-color: transparent; }
.chip.ko { background: var(--brand-soft); color: var(--brand); border-color: transparent; }
.chip.scaduta { background: var(--bg); color: var(--muted); }
.chip.cat { font-weight: 600; white-space: normal; text-align: left; }

.alert { padding: 12px 14px; border-radius: 11px; margin: 0 0 14px; font-size: .94rem; border: 1px solid transparent; }
.alert.ok { background: var(--green-soft); color: var(--green); }
.alert.err { background: var(--brand-soft); color: var(--brand); }
.alert.info { background: var(--blue-soft); color: var(--blue); }
.alert.warn { background: var(--amber-soft); color: var(--amber); }

/* ---------- Form ---------- */
label { display: block; font-weight: 600; font-size: .9rem; color: var(--ink-2); }
input[type=text], input[type=email], input[type=password], input[type=search], input[type=date], input[type=number], select, textarea {
  display: block; width: 100%; margin-top: 6px;
  font: inherit; color: var(--ink); background: var(--card);
  border: 1px solid var(--line); border-radius: 11px; padding: 11px 12px; min-height: 44px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); outline-offset: 1px; border-color: transparent; }
.stack > * + * { margin-top: 14px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: end; }
.row > * { flex: 1 1 160px; }
.check { display: flex; gap: 10px; align-items: flex-start; font-weight: 500; }
.check input { width: 18px; height: 18px; margin-top: 2px; accent-color: var(--brand); }

/* ---------- Login ---------- */
body.auth { display: grid; place-items: center; min-height: 100vh; padding: 20px; }
.auth-box { width: 100%; max-width: 380px; }
.auth-box .brand-mark { width: 52px; height: 52px; font-size: 1.5rem; border-radius: 14px; margin-bottom: 18px; }
.auth-box h1 { font-size: 1.6rem; }
.auth-foot { margin-top: 22px; font-size: .86rem; color: var(--muted); }

/* ---------- Elenco gare ---------- */
.summary { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; margin: 4px 2px 14px; }
.summary strong { font-size: 1.6rem; letter-spacing: -.02em; }
.segmented { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 2px; margin-bottom: 12px; scrollbar-width: none; }
.segmented a {
  flex: none; padding: 8px 14px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--card); color: var(--ink-2); font-weight: 600; font-size: .88rem;
}
.segmented a:hover { text-decoration: none; }
.segmented a.on { background: var(--ink); border-color: var(--ink); color: var(--card); }
.segmented .n { font-variant-numeric: tabular-nums; opacity: .7; margin-left: 4px; }

.filters { display: grid; grid-template-columns: 1fr auto; gap: 8px; margin-bottom: 14px; }
.filters input[type=search] { margin: 0; }
.filters details { grid-column: 1 / -1; }
.filters summary { cursor: pointer; color: var(--muted); font-size: .88rem; font-weight: 600; padding: 2px; }
.filters .row { margin-top: 10px; }

.gara {
  display: block; position: relative; color: inherit;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 14px 14px 13px 16px;
}
.gara:hover { text-decoration: none; border-color: #cfc9c2; }
.gara + .gara { margin-top: 10px; }
.gara.unread::before {
  content: ""; position: absolute; left: 0; top: 14px; bottom: 14px; width: 3px; border-radius: 0 3px 3px 0; background: var(--brand);
}
.gara-top { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; margin-bottom: 8px; padding-right: 36px; }
.gara-title {
  font-weight: 650; font-size: 1rem; line-height: 1.35; color: var(--ink);
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
}
.gara.read .gara-title { font-weight: 500; color: var(--ink-2); }
.gara-meta { margin-top: 6px; font-size: .86rem; color: var(--muted); }
.gara-foot { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-top: 10px; }
.gara-amount { font-weight: 700; font-variant-numeric: tabular-nums; }
.gara-rdo { font-size: .78rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.star {
  position: absolute; top: 8px; right: 8px; width: 40px; height: 40px;
  display: grid; place-items: center; border: 0; background: transparent; cursor: pointer; color: var(--muted); border-radius: 10px;
}
.star svg { width: 22px; height: 22px; }
.star.on { color: #d49b00; }
.star.on svg { fill: currentColor; }
.empty { text-align: center; padding: 40px 16px; color: var(--muted); }
.empty svg { width: 44px; height: 44px; opacity: .5; }

/* ---------- Dettaglio ---------- */
.back { display: inline-flex; align-items: center; gap: 4px; font-weight: 600; font-size: .92rem; margin-bottom: 12px; }
.detail-head h1 { font-size: 1.25rem; margin-top: 10px; }
.kv { display: grid; grid-template-columns: minmax(110px, 38%) 1fr; gap: 9px 14px; margin: 0; font-size: .93rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-weight: 550; overflow-wrap: anywhere; }
.lotti { width: 100%; border-collapse: collapse; font-size: .9rem; }
.lotti th, .lotti td { text-align: left; padding: 9px 6px; border-bottom: 1px solid var(--line); vertical-align: top; }
.lotti th { color: var(--muted); font-weight: 600; font-size: .8rem; }
.lotti td.num { text-align: right; white-space: nowrap; }
.cta { display: grid; gap: 8px; }
@media (min-width: 560px) { .cta { grid-template-columns: 1fr 1fr; } }
.prose { white-space: pre-line; color: var(--ink-2); font-size: .94rem; }

/* ---------- Profilo ---------- */
.list { list-style: none; margin: 0; padding: 0; }
.list li { padding: 9px 0; border-bottom: 1px solid var(--line); font-size: .94rem; }
.list li:last-child { border-bottom: 0; }

/* ---------- Pannello amministratore ---------- */
.admin .tabbar { display: none; }
.admin .topnav { display: flex; overflow-x: auto; }
@media (max-width: 899px) {
  .admin .topbar-in { flex-wrap: wrap; }
  .admin .topnav { order: 3; width: 100%; }
}
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.kpi .v { font-size: 1.8rem; font-weight: 750; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.kpi .l { color: var(--muted); font-size: .85rem; font-weight: 600; }
.kpi.alert-kpi .v { color: var(--brand); }
.grid2 { display: grid; gap: 14px; }
@media (min-width: 960px) { .grid2 { grid-template-columns: 1fr 1fr; } .grid2.wide-left { grid-template-columns: 1.4fr 1fr; } }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--card); }
table.data { width: 100%; border-collapse: collapse; font-size: .9rem; }
table.data th, table.data td { padding: 10px 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
table.data th { font-size: .78rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; background: var(--bg); position: sticky; top: 0; }
table.data tr:last-child td { border-bottom: 0; }
table.data td.num, table.data th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.data tr:hover td { background: color-mix(in srgb, var(--bg) 50%, transparent); }
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: end; margin-bottom: 14px; }
.toolbar > form { display: contents; }
.toolbar .grow { flex: 1 1 240px; }
.pick { max-height: 360px; overflow-y: auto; border: 1px solid var(--line); border-radius: 11px; padding: 6px 10px; margin-top: 8px; }
.pick label { font-weight: 500; padding: 6px 0; border-bottom: 1px solid var(--line); }
.pick label:last-child { border-bottom: 0; }
.regioni-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 4px 12px; margin-top: 8px; }
.copybox { display: flex; gap: 8px; }
.copybox input { margin: 0; font-family: ui-monospace, Menlo, monospace; font-size: .82rem; }
.report ul { margin: 6px 0 0; padding-left: 20px; }
.pager { display: flex; gap: 6px; justify-content: center; margin-top: 14px; }
.gara .star { z-index: 2; }
.gara > a:first-child { z-index: 1; }
.summary-l { font-weight: 600; color: var(--ink-2); }
.gara-meta { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.grid2 { align-items: start; }

.auth-box.wide { max-width: 640px; }
body.auth:has(.auth-box.wide) { place-items: start center; }
.fs { border: 1px solid var(--line); border-radius: var(--radius); background: var(--card); padding: 14px 16px 16px; margin: 0; }
.fs legend { font-weight: 700; padding: 0 6px; }

/* Logo MePAnet */
.brand-logo { height: 30px; width: auto; display: block; }
.brand-sub { display: block; font-weight: 700; font-size: .95rem; padding-left: 10px; border-left: 1px solid var(--line); }
.auth-logo { display: block; width: 220px; max-width: 70%; height: auto; margin: 0 0 22px; }
@media (max-width: 380px) { .brand-sub small { display: none; } }
@media (prefers-color-scheme: dark) {
  .brand-logo, .auth-logo { background: #fff; border-radius: 8px; padding: 4px 8px; box-sizing: content-box; }
}
