:root {
  --bg: #f6f1e8;
  --card: #fffdf9;
  --ink: #1f1c18;
  --muted: #6d655b;
  --line: #e6ddcf;
  --accent: #55663a;
  --accent-ink: #ffffff;
  --warm: #b4532a;
  --ok: #2f7a4b;
  --wait: #a06a12;
  --off: #8a8178;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(40, 30, 10, 0.05), 0 8px 24px rgba(40, 30, 10, 0.05);
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { font-family: 'Fraunces', Georgia, serif; font-weight: 600; line-height: 1.2; margin: 0 0 0.4em; }
h1 { font-size: clamp(1.6rem, 4vw, 2.2rem); }
h2 { font-size: 1.25rem; }
a { color: var(--accent); }
.wrap { max-width: 1040px; margin: 0 auto; padding: 0 16px; }
.top { border-bottom: 1px solid var(--line); background: var(--card); }
.top .wrap { display: flex; align-items: center; justify-content: space-between; height: 60px; gap: 12px; }
.brand { font-family: 'Fraunces', Georgia, serif; font-size: 1.25rem; font-weight: 600; letter-spacing: 0.02em; text-decoration: none; color: var(--ink); }
.brand small { font-family: 'Inter', sans-serif; font-size: 0.75rem; color: var(--muted); font-weight: 500; letter-spacing: 0.08em; text-transform: uppercase; margin-left: 8px; }
main.wrap { padding-top: 28px; padding-bottom: 64px; }
.muted { color: var(--muted); }
.small { font-size: 0.875rem; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); }
.stack > * + * { margin-top: 20px; }
.grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
.kpi .label { font-size: 0.8rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }
.kpi .value { font-family: 'Fraunces', Georgia, serif; font-size: 1.8rem; font-weight: 600; margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi.hi { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.kpi.hi .label { color: rgba(255,255,255,0.8); }
.code-row { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.code { font-family: ui-monospace, 'SF Mono', Menlo, monospace; font-size: 1.3rem; font-weight: 700; letter-spacing: 0.06em; background: #f1ead9; border: 1px dashed #cdbf9f; padding: 6px 12px; border-radius: 10px; }
.link { font-family: ui-monospace, Menlo, monospace; font-size: 0.9rem; word-break: break-all; }
button, .btn {
  appearance: none; border: 1px solid var(--accent); background: var(--accent); color: var(--accent-ink);
  font: inherit; font-weight: 600; font-size: 0.95rem; padding: 10px 16px; border-radius: 10px; cursor: pointer; text-decoration: none; display: inline-block;
}
button.ghost, .btn.ghost { background: transparent; color: var(--accent); }
button.small, .btn.small { padding: 6px 10px; font-size: 0.85rem; }
button:disabled { opacity: 0.55; cursor: default; }
input, select {
  font: inherit; width: 100%; padding: 11px 12px; border: 1px solid var(--line); border-radius: 10px; background: #fff; color: var(--ink);
}
input:focus, select:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
label { display: block; font-size: 0.875rem; font-weight: 600; margin-bottom: 6px; }
.field + .field { margin-top: 14px; }
.form-grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.check { display: flex; gap: 8px; align-items: center; font-weight: 500; }
.check input { width: auto; }
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: 0.93rem; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { font-size: 0.75rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; font-weight: 600; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.badge { display: inline-block; font-size: 0.78rem; font-weight: 600; padding: 3px 9px; border-radius: 999px; background: #eee6d6; color: var(--ink); }
.badge.da_pagare { background: #e3efe2; color: var(--ok); }
.badge.pagata { background: var(--accent); color: #fff; }
.badge.in_maturazione { background: #f6ead2; color: var(--wait); }
.badge.in_attesa_pagamento { background: #f3e3dc; color: var(--warm); }
.badge.annullato { background: #ece9e5; color: var(--off); text-decoration: line-through; }
.msg { padding: 10px 12px; border-radius: 10px; font-size: 0.92rem; }
.msg.err { background: #f8e2db; color: #8a2e12; }
.msg.ok { background: #e3efe2; color: #1f5a35; }
.login { max-width: 420px; margin: 8vh auto 0; }
.hidden { display: none !important; }
.rules li + li { margin-top: 6px; }
.empty { padding: 24px 8px; text-align: center; color: var(--muted); }
.actions { display: flex; gap: 6px; flex-wrap: wrap; }
@media (max-width: 560px) {
  .kpi .value { font-size: 1.45rem; }
  .card { padding: 16px; }
  .grid { grid-template-columns: 1fr 1fr; }
  .kpi.hi { grid-column: 1 / -1; order: -1; }
  table.cards thead { display: none; }
  table.cards tr { display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
  table.cards td { border: 0; padding: 0; white-space: normal; text-align: left; }
  table.cards td[data-label]::before { content: attr(data-label) ' '; color: var(--muted); font-size: 0.8rem; }
  table.cards td.empty { grid-column: 1 / -1; }
}

/* v2 */
.tabs { display: flex; gap: 4px; overflow-x: auto; padding-top: 0; padding-bottom: 0; scrollbar-width: none; }
.tabs a { padding: 10px 12px; color: var(--muted); text-decoration: none; font-weight: 600; font-size: 0.92rem; border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs a.active { color: var(--ink); border-bottom-color: var(--accent); }
.admin-bar { background: var(--warm); color: #fff; text-align: center; font-size: 0.85rem; padding: 6px 16px; }
.section-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.chart { width: 100%; height: 150px; display: block; }
.chart .bar { fill: var(--accent); }
.chart .bar.zero { fill: var(--line); }
.chart .dot { fill: var(--warm); }
.chart text { font-size: 10px; fill: var(--muted); font-family: inherit; }
.legend { display: flex; gap: 14px; font-size: 0.8rem; color: var(--muted); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 5px; vertical-align: -1px; }
.progress { height: 10px; background: #eee6d6; border-radius: 999px; overflow: hidden; margin: 8px 0 4px; }
.progress > span { display: block; height: 100%; background: var(--accent); border-radius: 999px; }
.two { display: grid; gap: 20px; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.products { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); }
.product { background: var(--card); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; display: flex; flex-direction: column; }
.product img { width: 100%; aspect-ratio: 1; object-fit: cover; background: #f1ead9; }
.product .body { padding: 10px; display: flex; flex-direction: column; gap: 8px; flex: 1; }
.product .title { font-size: 0.85rem; font-weight: 600; line-height: 1.3; flex: 1; }
.linkbox { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; background: #f1ead9; border: 1px dashed #cdbf9f; border-radius: 10px; padding: 10px 12px; }
.linkbox .link { flex: 1; min-width: 0; }
textarea { font: inherit; width: 100%; padding: 11px 12px; border: 1px solid var(--line); border-radius: 10px; background: #fff; color: var(--ink); min-height: 110px; resize: vertical; }
.note { font-size: 0.85rem; color: var(--muted); }
.warn { background: #fbefd9; color: #7a4b05; border-radius: 10px; padding: 8px 10px; font-size: 0.85rem; }
.pill { display: inline-block; font-size: 0.75rem; padding: 2px 8px; border-radius: 999px; background: #eee6d6; }
.prose h2 { margin-top: 1.4em; }
.prose p, .prose li { color: #3a352f; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row > * { flex: 0 0 auto; }
.row select { width: auto; min-width: 180px; }
.hp { position: absolute; left: -9999px; width: 1px; height: 1px; overflow: hidden; }
details summary { cursor: pointer; font-weight: 600; }

.top .tabs { justify-content: flex-start; height: auto; gap: 4px; }
.prose > h1 + p + h2, .prose h2:first-child { margin-top: 0.8em; }
main.wide, .top .wide { max-width: 1320px; }
td .actions { flex-wrap: wrap; min-width: 200px; }
td.wrap-cell { white-space: normal; }
@media (max-width: 440px) { .brand small { display: none; } }
