:root {
  color-scheme: light;
  --bg: #f1f5f9;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e2e8f0;
  --text: #0f172a;
  --text-2: #334155;
  --muted: #64748b;
  --accent: #0f766e;
  --accent-2: #14b8a6;
  --accent-soft: #ccfbf1;
  --good: #15803d;
  --bad: #b91c1c;
  --warn: #b45309;
  --grid: #e2e8f0;
  --shadow: 0 1px 2px rgba(15, 23, 42, .05), 0 1px 3px rgba(15, 23, 42, .06);
  --radius: 12px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0b1120; --surface: #111827; --surface-2: #0f172a; --border: #1f2a3c;
    --text: #e5e7eb; --text-2: #cbd5e1; --muted: #94a3b8;
    --accent: #2dd4bf; --accent-2: #14b8a6; --accent-soft: #134e4a;
    --good: #4ade80; --bad: #f87171; --warn: #fbbf24; --grid: #1f2a3c;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0b1120; --surface: #111827; --surface-2: #0f172a; --border: #1f2a3c;
  --text: #e5e7eb; --text-2: #cbd5e1; --muted: #94a3b8;
  --accent: #2dd4bf; --accent-2: #14b8a6; --accent-soft: #134e4a;
  --good: #4ade80; --bad: #f87171; --warn: #fbbf24; --grid: #1f2a3c;
  --shadow: none;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 14px/1.45 "Inter", -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input, select { font: inherit; color: inherit; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.num { font-variant-numeric: tabular-nums; }

/* ---------- login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 16px; padding: 28px; box-shadow: var(--shadow); }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 18px; }
.brand-mark { width: 32px; height: 32px; border-radius: 9px; background: var(--accent); display: grid; place-items: center; }
.brand-mark svg { width: 18px; height: 18px; fill: #fff; }
.field { display: flex; flex-direction: column; gap: 6px; margin-top: 14px; }
.field label { font-size: 12px; color: var(--muted); font-weight: 600; }
input[type=text], input[type=email], input[type=password], input[type=date], input[type=number], select, textarea {
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 9px 11px; width: 100%;
}
textarea { font: 12px/1.4 ui-monospace, Menlo, monospace; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

.btn { border: 1px solid var(--border); background: var(--surface); border-radius: 8px; padding: 8px 14px;
  cursor: pointer; font-weight: 600; white-space: nowrap; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
:root[data-theme="dark"] .btn.primary { color: #042f2e; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .btn.primary { color: #042f2e; } }
.btn.small { padding: 5px 10px; font-size: 12px; }
.btn.danger { color: var(--bad); }
.btn:disabled { opacity: .5; cursor: default; }
.error { color: var(--bad); font-size: 13px; margin-top: 10px; min-height: 18px; }

/* ---------- layout ---------- */
.topbar { position: sticky; top: 0; z-index: 20; background: var(--surface); border-bottom: 1px solid var(--border); }
.topbar-inner { max-width: 1280px; margin: 0 auto; padding: 10px 16px; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.topbar .spacer { flex: 1; }
.store-select { max-width: 260px; font-weight: 600; }
.user-chip { font-size: 12px; color: var(--muted); }

.tabs { max-width: 1280px; margin: 0 auto; padding: 0 16px; display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab { border: 0; background: none; padding: 10px 12px; cursor: pointer; color: var(--muted); font-weight: 600;
  border-bottom: 2px solid transparent; white-space: nowrap; }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }

main { max-width: 1280px; margin: 0 auto; padding: 16px; }

.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 14px; }
.seg { display: inline-flex; background: var(--surface); border: 1px solid var(--border); border-radius: 9px; padding: 3px; flex-wrap: wrap; }
.seg button { border: 0; background: none; padding: 6px 10px; border-radius: 6px; cursor: pointer; font-weight: 600; color: var(--muted); font-size: 13px; }
.seg button.active { background: var(--accent-soft); color: var(--accent); }
.range-inputs { display: inline-flex; gap: 6px; align-items: center; }
.range-inputs input { width: 150px; padding: 6px 8px; }
.range-label { font-weight: 600; color: var(--text-2); margin-left: auto; }

.grid { display: grid; gap: 12px; }
.kpis { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); margin-bottom: 12px; }
.cols-2 { grid-template-columns: repeat(auto-fit, minmax(360px, 1fr)); }
.cols-3 { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
@media (max-width: 420px) { .cols-2, .cols-3 { grid-template-columns: 1fr; } }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); min-width: 0; }
.card h3 { margin: 0 0 4px; font-size: 14px; }
.card .sub { font-size: 12px; color: var(--muted); margin-bottom: 10px; }
.card-head { display: flex; align-items: flex-start; gap: 8px; justify-content: space-between; flex-wrap: wrap; }

.kpi .label { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; }
.kpi .value { font-size: 24px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi .delta { font-size: 12px; margin-top: 2px; font-weight: 600; }
.delta.up { color: var(--good); } .delta.down { color: var(--bad); } .delta.flat { color: var(--muted); }
.kpi.hero { background: linear-gradient(135deg, var(--accent), #115e59); color: #fff; border: 0; }
.kpi.hero .label, .kpi.hero .delta { color: rgba(255,255,255,.85); }

.chart-box { position: relative; height: 260px; }
.chart-box.tall { height: 340px; }

/* tabelle */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data thead th { position: sticky; top: 0; background: var(--surface); z-index: 1; }
table.data th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted);
  padding: 8px 8px; border-bottom: 1px solid var(--border); white-space: nowrap; cursor: default; user-select: none; }
table.data th.sortable { cursor: pointer; }
table.data th.sortable:hover { color: var(--accent); }
table.data td { padding: 7px 8px; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.data td.r, table.data th.r { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
table.data tr:last-child td { border-bottom: 0; }
table.data tfoot td { font-weight: 700; border-top: 2px solid var(--border); }
.bar-cell { position: relative; min-width: 90px; }
.bar-cell .bar { height: 8px; background: var(--accent); border-radius: 4px; opacity: .85; }

.pill { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; padding: 2px 8px; border-radius: 999px; font-weight: 600; background: var(--surface-2); border: 1px solid var(--border); }
.pill.ok { color: var(--good); } .pill.err { color: var(--bad); } .pill.warn { color: var(--warn); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; }

/* heatmap */
.heat { display: grid; grid-template-columns: 44px repeat(24, minmax(18px, 1fr)); gap: 2px; font-size: 10px; min-width: 560px; }
.heat .h { color: var(--muted); text-align: center; }
.heat .d { color: var(--muted); display: flex; align-items: center; font-weight: 600; }
.heat .c { height: 26px; border-radius: 4px; background: var(--surface-2); position: relative; }
.heat .c:hover { outline: 2px solid var(--text); }

/* calendario */
.cal-head { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.cal-head .title { font-weight: 700; font-size: 16px; min-width: 170px; text-align: center; text-transform: capitalize; }
.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.cal .wd { font-size: 11px; color: var(--muted); text-transform: uppercase; text-align: center; font-weight: 600; }
.cal .day { min-height: 74px; border: 1px solid var(--border); border-radius: 10px; padding: 6px 8px; background: var(--surface); cursor: pointer; display: flex; flex-direction: column; justify-content: space-between; }
.cal .day:hover { border-color: var(--accent); }
.cal .day.empty { background: transparent; border: 0; cursor: default; }
.cal .day .n { font-size: 12px; font-weight: 700; color: var(--text-2); }
.cal .day .v { font-size: 13px; font-weight: 700; font-variant-numeric: tabular-nums; }
.cal .day .s { font-size: 11px; color: var(--muted); }
.cal .day.today { outline: 2px solid var(--accent); }
@media (max-width: 600px) { .cal .day { min-height: 56px; padding: 4px; } .cal .day .v { font-size: 11px; } .cal .day .s { display: none; } }

/* monitoraggio */
.dev { display: flex; gap: 12px; align-items: flex-start; }
.dev .status { width: 12px; height: 12px; border-radius: 50%; margin-top: 5px; flex: none; }
.dev .status.on { background: var(--good); box-shadow: 0 0 0 4px color-mix(in srgb, var(--good) 20%, transparent); }
.dev .status.off { background: var(--bad); box-shadow: 0 0 0 4px color-mix(in srgb, var(--bad) 20%, transparent); }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 3px 12px; font-size: 12px; margin-top: 6px; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; word-break: break-word; }

.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.search { max-width: 240px; padding: 6px 10px; }
.empty-state { padding: 40px 16px; text-align: center; color: var(--muted); }
.loading { opacity: .55; transition: opacity .2s; pointer-events: none; }
.code-box { font: 12px/1.4 ui-monospace, Menlo, monospace; background: var(--surface-2); border: 1px dashed var(--accent); border-radius: 8px; padding: 10px; word-break: break-all; }

dialog { border: 1px solid var(--border); border-radius: 14px; background: var(--surface); color: var(--text); padding: 0; width: min(760px, 94vw); }
dialog::backdrop { background: rgba(15, 23, 42, .5); }
dialog .dlg-head { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--border); font-weight: 700; }
dialog .dlg-body { padding: 16px; max-height: 75vh; overflow: auto; }
dialog iframe { width: 100%; height: 70vh; border: 0; background: #f1f5f9; border-radius: 8px; }

.toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--surface); padding: 10px 16px; border-radius: 10px; font-weight: 600; z-index: 100; box-shadow: 0 8px 24px rgba(0,0,0,.2); }
.demo-banner { background: #fef3c7; color: #92400e; text-align: center; font-size: 12px; padding: 4px; font-weight: 600; }
@media (max-width: 600px) {
  .user-chip, .brand-name { display: none; }
  .store-select { flex: 1 1 100%; max-width: none; order: 10; }
  .kpis { grid-template-columns: repeat(2, 1fr); }
  .kpi .value { font-size: 20px; }
  .topbar .spacer { display: none; }
  .range-label { margin-left: 0; width: 100%; }
  .range-inputs input { width: 140px; }
}
