:root {
  --bg: #f4f6f8;
  --panel: #ffffff;
  --ink: #14212b;
  --muted: #5b6b79;
  --line: #dfe5ea;
  --soft: #eef2f5;
  --accent: #0b6b6b;
  --accent-ink: #ffffff;
  --accent-soft: #e2f1f0;
  --warn: #9a5b00;
  --warn-soft: #fdf2dc;
  --bad: #a8261c;
  --bad-soft: #fbe6e3;
  --good: #1a6e45;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(20, 33, 43, 0.06), 0 4px 14px rgba(20, 33, 43, 0.05);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f161c;
    --panel: #18222b;
    --ink: #e7edf2;
    --muted: #98a8b6;
    --line: #2a3742;
    --soft: #212d37;
    --accent: #4fc2bd;
    --accent-ink: #06201f;
    --accent-soft: #17383a;
    --warn: #f0b860;
    --warn-soft: #3a2e17;
    --bad: #f08b80;
    --bad-soft: #3d201d;
    --good: #6fd0a0;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

[hidden] { display: none !important; }

a { color: var(--accent); }

h1 { font-size: 1.5rem; line-height: 1.25; margin: 0; letter-spacing: -0.01em; }
h2 { font-size: 1.05rem; margin: 0 0 0.75rem; }
h3 { font-size: 0.95rem; margin: 0 0 0.5rem; }
p { margin: 0 0 0.75rem; }

.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.mono { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 0.9em; white-space: nowrap; }
.nowrap { white-space: nowrap; }

/* Struttura */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.7rem 1.1rem;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 5;
}

.brand { font-weight: 700; font-size: 1.1rem; color: var(--ink); text-decoration: none; letter-spacing: -0.02em; }
.brand span { color: var(--accent); }

.topnav { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; justify-content: flex-end; }
.topnav .who { color: var(--muted); font-size: 0.85rem; }

.container { max-width: 1120px; margin: 0 auto; padding: 1.25rem 1rem 4rem; }

.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.page-head .sub { color: var(--muted); font-size: 0.9rem; margin-top: 0.2rem; }

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.1rem;
  margin-bottom: 1rem;
}

.grid { display: grid; gap: 1rem; }
.grid.shops { grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }

/* Accesso */

.auth { max-width: 380px; margin: 9vh auto 0; }
.auth .brand { display: block; font-size: 1.7rem; margin-bottom: 0.25rem; }
.auth .card { margin-top: 1.1rem; }

/* Moduli */

label { display: block; font-size: 0.85rem; font-weight: 600; margin-bottom: 0.3rem; }
.field { margin-bottom: 0.85rem; }
.field .hint { color: var(--muted); font-size: 0.8rem; margin-top: 0.25rem; }

input, select {
  width: 100%;
  font: inherit;
  color: var(--ink);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.55rem 0.65rem;
  min-height: 2.5rem;
}

input:focus-visible, select:focus-visible, button:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

input[type="checkbox"] { width: auto; min-height: 0; margin-right: 0.4rem; }
.check { display: flex; align-items: center; font-weight: 500; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  font: inherit;
  font-weight: 600;
  color: var(--ink);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.5rem 0.9rem;
  min-height: 2.5rem;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
}

.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.07); }
.btn.quiet { border-color: transparent; background: transparent; color: var(--muted); }
.btn.small { min-height: 2.1rem; padding: 0.3rem 0.65rem; font-size: 0.88rem; }
.btn[disabled] { opacity: 0.55; cursor: default; }

.row { display: flex; gap: 0.6rem; flex-wrap: wrap; align-items: center; }
.row.end { justify-content: flex-end; }
.row > .grow { flex: 1 1 160px; }

/* Avvisi */

.notice {
  border: 1px solid var(--line);
  border-left-width: 4px;
  border-radius: 8px;
  padding: 0.7rem 0.85rem;
  margin-bottom: 0.85rem;
  background: var(--panel);
  font-size: 0.92rem;
}

.notice.warn { border-left-color: var(--warn); background: var(--warn-soft); }
.notice.bad { border-left-color: var(--bad); background: var(--bad-soft); }
.notice.info { border-left-color: var(--accent); background: var(--accent-soft); }
.notice p:last-child { margin-bottom: 0; }

.badge {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 700;
  line-height: 1;
  padding: 0.28rem 0.5rem;
  border-radius: 999px;
  background: var(--soft);
  color: var(--muted);
  white-space: nowrap;
}

.badge.good { background: var(--accent-soft); color: var(--accent); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }

/* Periodo e numeri chiave */

.toolbar { display: flex; gap: 0.6rem; flex-wrap: wrap; align-items: flex-end; margin-bottom: 1rem; }
.toolbar .field { margin: 0; }
.toolbar input[type="date"] { width: 10.5rem; }

.kpis { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0.75rem; margin-bottom: 1rem; }

@media (min-width: 760px) {
  .kpis { grid-template-columns: repeat(4, 1fr); }
}

.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 0.85rem 0.95rem; box-shadow: var(--shadow); }
.kpi .label { color: var(--muted); font-size: 0.8rem; font-weight: 600; }
.kpi .value { font-size: 1.35rem; font-weight: 700; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; margin-top: 0.15rem; }
.kpi .note { color: var(--muted); font-size: 0.78rem; margin-top: 0.1rem; }
.kpi.accent .value { color: var(--good); }

/* Schede */

.tabs {
  display: flex;
  gap: 0.25rem;
  overflow-x: auto;
  border-bottom: 1px solid var(--line);
  margin-bottom: 1rem;
  scrollbar-width: thin;
}

.tab {
  font: inherit;
  font-weight: 600;
  color: var(--muted);
  background: none;
  border: 0;
  border-bottom: 3px solid transparent;
  padding: 0.6rem 0.75rem;
  cursor: pointer;
  white-space: nowrap;
  display: inline-flex;
  gap: 0.4rem;
  align-items: center;
}

.tab[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--accent); }

.section-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 0.75rem; flex-wrap: wrap; margin-bottom: 0.75rem; }
.section-head p { margin: 0.2rem 0 0; color: var(--muted); font-size: 0.9rem; max-width: 60ch; }

/* Tabelle */

.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 10px; }

table { width: 100%; border-collapse: collapse; font-size: 0.92rem; font-variant-numeric: tabular-nums; }
th, td { padding: 0.5rem 0.7rem; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.03em; color: var(--muted); background: var(--soft); white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; white-space: nowrap; }
tfoot td { font-weight: 700; background: var(--soft); border-top: 1px solid var(--line); border-bottom: 0; }

.empty { color: var(--muted); text-align: center; padding: 1.75rem 1rem; border: 1px dashed var(--line); border-radius: 10px; }

.grid-table th, .grid-table td { padding: 0.3rem 0.45rem; }
.grid-table td:first-child { white-space: nowrap; padding-left: 0.7rem; }
.grid-table input { min-height: 2.1rem; padding: 0.3rem 0.5rem; min-width: 5.5rem; }
.grid-table th input { font-weight: 600; min-width: 7.5rem; }
form[data-form="rate-table"] .row { margin-top: 0.9rem; }

.rate-form { display: flex; gap: 0.4rem; align-items: center; min-width: 11rem; }
.rate-form input { width: 5.2rem; min-height: 2.1rem; padding: 0.3rem 0.5rem; }

/* Elenco file */

.files { list-style: none; margin: 0; padding: 0; }
.files li { display: flex; justify-content: space-between; align-items: center; gap: 1rem; padding: 0.7rem 0; border-bottom: 1px solid var(--line); }
.files li:last-child { border-bottom: 0; }
.files .desc { color: var(--muted); font-size: 0.87rem; }

/* Negozi */

.shop-card h2 { margin-bottom: 0.2rem; }
.shop-card .meta { color: var(--muted); font-size: 0.87rem; margin-bottom: 0.75rem; overflow-wrap: anywhere; }
.shop-card .status { display: flex; gap: 0.4rem; flex-wrap: wrap; margin-bottom: 0.85rem; }

.progress { height: 6px; background: var(--soft); border-radius: 999px; overflow: hidden; margin: 0.5rem 0; }
.progress i { display: block; height: 100%; background: var(--accent); width: 0; transition: width 0.2s; }
.progress i.w10 { width: 10%; } .progress i.w20 { width: 20%; } .progress i.w30 { width: 30%; }
.progress i.w40 { width: 40%; } .progress i.w50 { width: 50%; } .progress i.w60 { width: 60%; }
.progress i.w70 { width: 70%; } .progress i.w80 { width: 80%; } .progress i.w90 { width: 90%; }
.progress i.w100 { width: 100%; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 1.25rem;
  transform: translateX(-50%);
  background: var(--ink);
  color: var(--bg);
  padding: 0.65rem 1rem;
  border-radius: 10px;
  font-weight: 600;
  font-size: 0.92rem;
  max-width: min(92vw, 520px);
  z-index: 20;
}

.toast.bad { background: var(--bad); color: #fff; }

@media (max-width: 520px) {
  .container { padding: 1rem 0.75rem 4rem; }
  h1 { font-size: 1.3rem; }
  .toolbar input[type="date"] { width: 100%; }
  .toolbar .field { flex: 1 1 9rem; }
}
