:root {
  --bg: #f6f6f7;
  --card: #ffffff;
  --text: #16171a;
  --muted: #6b6f76;
  --line: #e4e5e8;
  --accent: #d62f6c;
  --accent-ink: #ffffff;
  --ok: #18794e;
  --ok-bg: #e7f6ee;
  --warn: #9a5b00;
  --warn-bg: #fff4df;
  --err: #b42318;
  --err-bg: #fdecea;
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111214; --card: #1b1c20; --text: #ececef; --muted: #9a9ca3; --line: #2c2e33;
    --accent: #f0588f; --ok: #4cc38a; --ok-bg: #12291f; --warn: #f5b74e; --warn-bg: #2e2412;
    --err: #ff8a80; --err-bg: #3a1714;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
}
a { color: var(--accent); text-decoration: none; }
img { max-width: 100%; display: block; }
h1 { font-size: 1.35rem; margin: 0 0 4px; }
h2 { font-size: 1.05rem; margin: 0 0 10px; }
h3 { font-size: .95rem; margin: 16px 0 8px; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.center { text-align: center; }
[hidden] { display: none !important; }

.topbar {
  position: sticky; top: 0; z-index: 10; background: var(--card); border-bottom: 1px solid var(--line);
  padding: calc(env(safe-area-inset-top) + 8px) 16px 0;
}
.brand { font-weight: 700; padding-bottom: 6px; }
.tabs { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; }
.tabs a {
  padding: 10px 12px; color: var(--muted); font-weight: 600; border-bottom: 2px solid transparent; white-space: nowrap;
}
.tabs a.active { color: var(--text); border-color: var(--accent); }

main { max-width: 880px; margin: 0 auto; padding: 16px; }
#banner { max-width: 880px; margin: 0 auto; padding: 0 16px; }
#banner:empty { display: none; }
#banner .alert { margin-top: 12px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }

.alert { border-radius: 10px; padding: 10px 12px; font-size: .9rem; margin-bottom: 12px; }
.alert.ok { background: var(--ok-bg); color: var(--ok); }
.alert.warn { background: var(--warn-bg); color: var(--warn); }
.alert.err { background: var(--err-bg); color: var(--err); }

button, .btn {
  font: inherit; font-weight: 600; border-radius: 10px; border: 1px solid var(--line); background: var(--card);
  color: var(--text); padding: 10px 14px; cursor: pointer; min-height: 42px;
}
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
button:disabled { opacity: .55; cursor: default; }
button.link { border: 0; background: none; color: var(--accent); padding: 4px 0; min-height: 0; }

label { display: block; font-weight: 600; font-size: .9rem; margin: 14px 0 6px; }
.hint { font-weight: 400; color: var(--muted); font-size: .82rem; }
input[type=text], input[type=password], input[type=datetime-local], textarea {
  width: 100%; font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--line);
  border-radius: 10px; padding: 10px 12px; font-size: 16px; /* niente zoom su iOS */
}
textarea { min-height: 110px; resize: vertical; }
input:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.counter { text-align: right; font-size: .8rem; color: var(--muted); margin-top: 4px; }
.counter.over { color: var(--err); font-weight: 700; }

.check { display: flex; gap: 10px; align-items: flex-start; font-weight: 500; margin: 14px 0; }
.check input { width: 20px; height: 20px; margin-top: 1px; accent-color: var(--accent); }

/* interruttore */
.switch { position: relative; display: inline-flex; align-items: center; gap: 10px; font-weight: 600; margin: 0; cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch .track { width: 48px; height: 28px; border-radius: 99px; background: var(--line); position: relative; transition: .2s; flex: none; }
.switch .track::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; transition: .2s; box-shadow: 0 1px 2px rgba(0,0,0,.25); }
.switch input:checked + .track { background: var(--accent); }
.switch input:checked + .track::after { transform: translateX(20px); }
.switch input:focus-visible + .track { outline: 2px solid var(--accent); outline-offset: 2px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  border: 1px solid var(--line); border-radius: 99px; padding: 6px 12px; font-size: .88rem; font-weight: 600;
  background: var(--card); min-height: 34px; color: var(--text);
}
.chip.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.chip.off { text-decoration: line-through; color: var(--muted); }

/* elenco Reel */
.reel-list { display: grid; gap: 12px; }
.reel { display: flex; gap: 12px; align-items: center; color: var(--text); }
.thumb { width: 64px; aspect-ratio: 9/16; border-radius: 8px; background: var(--line) center/cover no-repeat; flex: none; overflow: hidden; }
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.reel .caption { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.meta { display: flex; gap: 10px; flex-wrap: wrap; color: var(--muted); font-size: .82rem; margin-top: 4px; }
.badge { display: inline-block; font-size: .75rem; font-weight: 700; border-radius: 99px; padding: 2px 8px; background: var(--line); color: var(--muted); }
.badge.on { background: var(--ok-bg); color: var(--ok); }
.badge.err { background: var(--err-bg); color: var(--err); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }

.detail-head { display: flex; gap: 14px; align-items: flex-start; }
.detail-head .thumb { width: 90px; }

/* tabelle / elenchi DM */
.list { display: grid; gap: 0; }
.list .item { padding: 10px 0; border-top: 1px solid var(--line); }
.list .item:first-child { border-top: 0; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 10px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px; }
.stat .v { font-size: 1.3rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat .l { color: var(--muted); font-size: .8rem; }

.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: .88rem; }
th, td { text-align: right; padding: 8px 6px; border-top: 1px solid var(--line); white-space: nowrap; font-variant-numeric: tabular-nums; }
th:first-child, td:first-child { text-align: left; white-space: normal; min-width: 150px; }
th { color: var(--muted); font-weight: 600; border-top: 0; }

.scopes { display: flex; flex-wrap: wrap; gap: 6px; }
.events { font-size: .82rem; max-height: 320px; overflow: auto; }
.events div { padding: 6px 0; border-top: 1px solid var(--line); }

.login { max-width: 360px; margin: 12vh auto 0; }
.sticky-save {
  position: sticky; bottom: 0; background: var(--bg); padding: 12px 0 calc(12px + env(safe-area-inset-bottom));
  display: flex; gap: 10px; border-top: 1px solid var(--line); margin-top: 8px;
}
.sticky-save button { flex: 1; }

#toast {
  position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); transform: translateX(-50%) translateY(20px);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-weight: 600;
  opacity: 0; pointer-events: none; transition: .2s; max-width: calc(100% - 32px); z-index: 50;
}
#toast.show { opacity: 1; transform: translateX(-50%); }
#toast.err { background: var(--err); color: #fff; }
