:root {
  color-scheme: light;
  --bg: #f4f4f2;
  --surface: #fcfcfb;
  --surface-2: #f0efec;
  --border: #e3e2de;
  --text: #0b0b0b;
  --text-2: #52514e;
  --text-3: #7b7a76;
  --accent: #2a78d6;
  --accent-ink: #ffffff;
  --series-ios: #2a78d6;
  --series-android: #eb6834;
  --series-ads: #1baf7a;
  --good: #0a7d2c;
  --good-bg: #e5f4e9;
  --warn: #9a5b00;
  --warn-bg: #fdf1dc;
  --bad: #b42323;
  --bad-bg: #fbe7e7;
  --neutral-bg: #ecebe8;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 2px 8px rgba(0,0,0,.04);
  --mono: ui-monospace, "Cascadia Mono", "SF Mono", Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #111110;
    --surface: #1a1a19;
    --surface-2: #232321;
    --border: #2f2f2c;
    --text: #f0efec;
    --text-2: #c3c2b7;
    --text-3: #8f8e86;
    --accent: #3987e5;
    --series-ios: #3987e5;
    --series-android: #d95926;
    --series-ads: #199e70;
    --good: #4cc26a;
    --good-bg: #16301e;
    --warn: #e6a640;
    --warn-bg: #33270f;
    --bad: #f07070;
    --bad-bg: #3a1a1a;
    --neutral-bg: #2a2a27;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111110; --surface: #1a1a19; --surface-2: #232321; --border: #2f2f2c;
  --text: #f0efec; --text-2: #c3c2b7; --text-3: #8f8e86; --accent: #3987e5;
  --series-ios: #3987e5; --series-android: #d95926; --series-ads: #199e70;
  --good: #4cc26a; --good-bg: #16301e; --warn: #e6a640; --warn-bg: #33270f;
  --bad: #f07070; --bad-bg: #3a1a1a; --neutral-bg: #2a2a27; --shadow: none;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input, select { font: inherit; color: inherit; }
a { color: var(--accent); }
.hidden { display: none !important; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--text-3); }
.small { font-size: 13px; }
code, .mono { font-family: var(--mono); font-size: .92em; }

/* ---------- Controlli ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 14px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); cursor: pointer; text-decoration: none; color: var(--text);
  white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--bad); }
.btn:disabled { opacity: .55; cursor: default; }
.btn.small { padding: 5px 10px; font-size: 13px; }
input[type=text], input[type=password], select {
  width: 100%; padding: 10px 12px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface);
}
input:focus-visible, select:focus-visible, button:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px;
}
label { display: block; font-size: 13px; color: var(--text-2); margin: 0 0 6px; }
.field { margin-bottom: 14px; }
.error { color: var(--bad); font-size: 14px; min-height: 20px; margin: 4px 0 10px; }
.segmented { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; background: var(--surface); }
.segmented button { border: 0; background: transparent; padding: 6px 12px; cursor: pointer; color: var(--text-2); }
.segmented button[aria-pressed="true"] { background: var(--surface-2); color: var(--text); font-weight: 600; }
.switch { display: inline-flex; align-items: center; gap: 8px; color: var(--text-2); font-size: 14px; cursor: pointer; }

/* ---------- Login ---------- */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.auth-card {
  width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 28px; box-shadow: var(--shadow);
}
.auth-card h1 { font-size: 20px; margin: 0 0 4px; }
.auth-card p { color: var(--text-2); margin: 0 0 20px; font-size: 14px; }
.auth-card .btn.primary { width: 100%; padding: 11px; }
.code-input { font-family: var(--mono); font-size: 22px !important; letter-spacing: .3em; text-align: center; }
.qr { display: block; margin: 0 auto 12px; width: 200px; height: 200px; image-rendering: pixelated; border-radius: 8px; background: #fff; padding: 8px; }
.secret-key { text-align: center; font-family: var(--mono); font-size: 13px; color: var(--text-2); margin-bottom: 18px; word-spacing: 4px; }
.codes { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 16px; font-family: var(--mono); background: var(--surface-2); padding: 14px; border-radius: 8px; margin: 0 0 16px; }
.linklike { background: none; border: 0; color: var(--accent); cursor: pointer; padding: 0; font-size: 14px; }

/* ---------- Layout console ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10; background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px); border-bottom: 1px solid var(--border);
}
.topbar-inner { max-width: 1240px; margin: 0 auto; padding: 10px 16px; display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.brand { font-weight: 700; letter-spacing: -.01em; }
.tabs { display: flex; gap: 2px; }
.tabs button { border: 0; background: none; padding: 8px 12px; border-radius: 8px; cursor: pointer; color: var(--text-2); }
.tabs button[aria-selected="true"] { background: var(--surface); color: var(--text); font-weight: 600; box-shadow: var(--shadow); }
.spacer { flex: 1; }
.live { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text-3); }
.live::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--good); }
.live.stale::before { background: var(--warn); }
main { max-width: 1240px; margin: 0 auto; padding: 20px 16px 48px; }
.toolbar { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin-bottom: 16px; }
.toolbar h2 { margin: 0; font-size: 18px; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 18px 0; flex-wrap: wrap; }
.card-head h3 { margin: 0; font-size: 15px; }
.card-body { padding: 14px 18px 18px; }

.kpis { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; margin-bottom: 14px; }
.kpi { padding: 16px 18px; }
.kpi .label { color: var(--text-2); font-size: 13px; }
.kpi .value { font-size: 30px; font-weight: 700; letter-spacing: -.02em; margin: 2px 0 2px; }
.delta { font-size: 13px; font-weight: 600; display: inline-flex; align-items: center; gap: 4px; }
.delta.up { color: var(--good); }
.delta.down { color: var(--bad); }
.delta.flat { color: var(--text-3); }
.split { display: flex; gap: 14px; flex-wrap: wrap; margin-top: 10px; font-size: 13px; color: var(--text-2); }
.split span { display: inline-flex; align-items: center; gap: 6px; }
.dot { width: 9px; height: 9px; border-radius: 3px; display: inline-block; flex: none; }
.dot.ios { background: var(--series-ios); }
.dot.android { background: var(--series-android); }
.dot.ads { background: var(--series-ads); }
.counts { margin-top: 8px; font-size: 13px; color: var(--text-3); }

.chart-box { position: relative; height: 300px; }
.legend { display: flex; gap: 16px; font-size: 13px; color: var(--text-2); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }

.grid-2 { display: grid; grid-template-columns: 1.35fr 1fr; gap: 14px; margin-top: 14px; }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; font-weight: 600; color: var(--text-3); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; padding: 8px 10px; border-bottom: 1px solid var(--border); }
td { padding: 9px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
th.r, td.r { text-align: right; }
.table-wrap { overflow-x: auto; }
tbody tr.clickable { cursor: pointer; }
tbody tr.clickable:hover td { background: var(--surface-2); }

.feed { list-style: none; margin: 0; padding: 0; }
.feed li { display: grid; grid-template-columns: auto 1fr auto; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--border); align-items: start; }
.feed li:last-child { border-bottom: 0; }
.feed .what { font-size: 14px; }
.feed .meta { font-size: 12px; color: var(--text-3); }
.feed .amt { font-variant-numeric: tabular-nums; font-weight: 600; font-size: 14px; text-align: right; }
.amt.neg { color: var(--bad); }

.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.badge.Purchase, .badge.Renewal { background: var(--good-bg); color: var(--good); }
.badge.Refund { background: var(--bad-bg); color: var(--bad); }
.badge.Problem { background: var(--warn-bg); color: var(--warn); }
.badge.Cancel, .badge.Info, .badge.Test { background: var(--neutral-bg); color: var(--text-2); }
.store-tag { font-size: 11px; color: var(--text-3); border: 1px solid var(--border); border-radius: 4px; padding: 0 5px; }

.notice { padding: 12px 14px; border-radius: 8px; background: var(--warn-bg); color: var(--warn); font-size: 14px; margin-bottom: 14px; }
.notice.ok { background: var(--good-bg); color: var(--good); }
.empty { text-align: center; color: var(--text-3); padding: 28px 0; font-size: 14px; }

.settings { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; }
.status-row { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; font-size: 14px; }
.state { font-weight: 600; }
.state.on { color: var(--good); }
.state.off { color: var(--text-3); }
.state.err { color: var(--bad); }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.form-narrow { max-width: 360px; }

dialog { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text); padding: 0; width: min(720px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(0,0,0,.4); }
dialog pre { margin: 0; padding: 16px 18px; max-height: 60vh; overflow: auto; font-family: var(--mono); font-size: 12px; background: var(--surface-2); }

@media (max-width: 980px) {
  .grid-2, .settings { grid-template-columns: 1fr; }
}
@media (max-width: 720px) {
  .kpis { grid-template-columns: 1fr; }
  .kpi .value { font-size: 26px; }
  .chart-box { height: 240px; }
  .tabs { order: 3; width: 100%; overflow-x: auto; }
  .hide-sm { display: none; }
}

.auth-card p.alt-action { margin: 16px 0 0; text-align: center; }
.codes-actions { margin: 0 0 14px; }

.settings h3 { margin: 0 0 10px; font-size: 15px; }
#logins-card { margin-top: 14px; }
.feed li.empty { display: block; }
.linklike.small { font-size: 13px; }
.feed .badge { min-width: 96px; justify-content: flex-start; }
.settings .error:empty { min-height: 0; margin: 0; }
.toolbar select { width: auto; min-width: 150px; padding: 7px 10px; }

/* ---------- App ---------- */
.intro { margin: -4px 0 14px; max-width: 760px; }
.form-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0 14px; }
.apps-list { display: grid; gap: 10px; }
.app-card { padding: 14px 18px; }
.app-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.app-name { font-weight: 700; font-size: 16px; }
.app-name-input { max-width: 280px; padding: 6px 10px; }
.app-total { margin-left: auto; font-variant-numeric: tabular-nums; font-weight: 600; }
.badge.new { background: var(--warn-bg); color: var(--warn); }
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin: 10px 0 0; }
.chip { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--border); border-radius: 999px; padding: 3px 4px 3px 10px; font-size: 13px; background: var(--surface-2); }
.chip .kind { font-size: 11px; font-weight: 700; color: var(--text-3); text-transform: uppercase; letter-spacing: .04em; }
.chip code { font-size: 12px; }
.chip button { border: 0; background: none; cursor: pointer; color: var(--text-3); width: 22px; height: 22px; border-radius: 50%; line-height: 1; }
.chip button:hover { background: var(--border); color: var(--bad); }
.app-tools { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-top: 12px; }
.app-tools select, .app-tools input { width: auto; padding: 6px 10px; font-size: 13px; }
.app-tools input { min-width: 220px; }

/* ---------- Impostazioni ---------- */
.settings .wide { grid-column: 1 / -1; }
.copy-row { display: grid; grid-template-columns: 260px 1fr auto; gap: 10px; align-items: center; margin-bottom: 8px; }
.copy-row code { background: var(--surface-2); padding: 6px 10px; border-radius: 6px; overflow-x: auto; white-space: nowrap; }
.copy-label { font-size: 13px; color: var(--text-2); }
.checks { border: 0; padding: 0; margin: 0 0 6px; display: flex; flex-wrap: wrap; gap: 6px 16px; }
.checks legend { font-size: 13px; color: var(--text-2); margin-bottom: 6px; padding: 0; }
.checks label { display: inline-flex; gap: 6px; align-items: center; margin: 0; font-size: 14px; color: var(--text); }
.field.narrow select { width: 120px; }
input.dirty, select.dirty { border-color: var(--accent); }
.msg { font-size: 14px; min-height: 0; margin-top: 8px; }
.msg.err { color: var(--bad); }
.msg.ok { color: var(--good); }
.savebar { position: sticky; bottom: 12px; margin-top: 16px; display: flex; gap: 10px; align-items: center; padding: 12px 16px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--accent); box-shadow: 0 6px 24px rgba(0,0,0,.18); flex-wrap: wrap; }
.small-code { width: 150px !important; font-size: 16px !important; padding: 8px !important; }

@media (max-width: 980px) {
  .form-grid { grid-template-columns: 1fr 1fr; }
  .copy-row { grid-template-columns: 1fr auto; }
  .copy-label { grid-column: 1 / -1; }
}
@media (max-width: 720px) {
  .form-grid { grid-template-columns: 1fr; }
}

.auth-card .remember { margin: 0 0 6px; font-size: 13px; }
#revoke-card { margin-top: 14px; }
