/* ---------- Tokens ---------- */
:root {
  --bg: #f5f5f8;
  --surface: #ffffff;
  --surface-2: #eeeef3;
  --border: #e1e1e9;
  --text: #121218;
  --muted: #676779;
  --accent: #d6194f;
  --accent-soft: rgba(214, 25, 79, 0.1);
  --on-accent: #ffffff;
  --danger: #c62828;
  --gold: #a86f00;
  --gold-soft: rgba(212, 150, 20, 0.14);
  --st-idee: #676779;
  --st-freitag: #d6194f;
  --st-gedreht: #2563eb;
  --st-gepostet: #15803d;
  --shadow: 0 6px 24px rgba(20, 20, 40, 0.14);
  --radius: 16px;
  --tabbar-h: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b0b10;
    --surface: #16161e;
    --surface-2: #20202b;
    --border: #2a2a37;
    --text: #f1f1f5;
    --muted: #9b9bae;
    --accent: #ff4d7d;
    --accent-soft: rgba(255, 77, 125, 0.14);
    --on-accent: #ffffff;
    --danger: #ff6b6b;
    --gold: #f2c14e;
    --gold-soft: rgba(242, 193, 78, 0.12);
    --st-idee: #9b9bae;
    --st-freitag: #ff4d7d;
    --st-gedreht: #6ea8ff;
    --st-gepostet: #4ade80;
    --shadow: 0 8px 30px rgba(0, 0, 0, 0.5);
    color-scheme: dark;
  }
}

/* ---------- Basis ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  min-height: 100dvh;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); }
svg { display: block; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
[hidden] { display: none !important; }

/* ---------- Layout ---------- */
#views { max-width: 640px; margin: 0 auto; padding: calc(env(safe-area-inset-top, 0px) + 12px) 16px calc(var(--tabbar-h) + var(--safe-b) + 96px); }
.view-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin: 8px 0 14px; }
.view-head h1 { margin: 0; font-size: 28px; letter-spacing: -0.02em; }
.view-head .sub { color: var(--muted); font-size: 14px; }
.section-title { display: flex; align-items: baseline; justify-content: space-between; margin: 28px 0 10px; font-size: 18px; font-weight: 650; }
.section-title .muted { font-size: 14px; font-weight: 400; }

/* ---------- Tab-Leiste ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: grid; grid-auto-flow: column; grid-auto-columns: 1fr;
  height: calc(var(--tabbar-h) + var(--safe-b)); padding-bottom: var(--safe-b);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid var(--border);
}
.tabbar button {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  border: 0; background: none; color: var(--muted); font-size: 12px; font-weight: 600;
}
.tabbar svg { width: 26px; height: 26px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tabbar button[aria-current="page"] { color: var(--accent); }

/* ---------- Schwebender Button ---------- */
.fab {
  position: fixed; z-index: 21; right: max(16px, calc(50vw - 304px));
  bottom: calc(var(--tabbar-h) + var(--safe-b) + 16px);
  width: 60px; height: 60px; border-radius: 50%; border: 0;
  background: var(--accent); color: var(--on-accent); box-shadow: var(--shadow);
  display: grid; place-items: center; transition: transform 0.12s;
}
.fab:active { transform: scale(0.92); }
.fab svg { width: 28px; height: 28px; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; fill: none; }

/* ---------- Buttons ---------- */
.btn {
  min-height: 48px; padding: 0 18px; border-radius: 12px; border: 1px solid var(--border);
  background: var(--surface-2); font-weight: 600; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
}
.btn.primary { background: var(--accent); border-color: transparent; color: var(--on-accent); }
.btn.danger { background: transparent; border-color: transparent; color: var(--danger); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--accent); }
.btn.block { width: 100%; }
.btn.sm { min-height: 40px; padding: 0 14px; font-size: 14px; border-radius: 10px; }
.btn:disabled { opacity: 0.55; }
.icon-btn {
  width: 44px; height: 44px; flex: none; border-radius: 12px; border: 1px solid var(--border);
  background: var(--surface); display: grid; place-items: center; color: var(--muted);
}
.icon-btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn.on { color: var(--gold); border-color: var(--gold); background: var(--gold-soft); }
.icon-btn.on svg { fill: currentColor; }

/* ---------- Formularfelder ---------- */
.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 6px; }
.field small { display: block; color: var(--muted); font-size: 12px; margin-top: 4px; }
input[type="text"], input[type="search"], input[type="password"], input[type="date"], input[type="number"], input[inputmode], select, textarea {
  width: 100%; min-height: 48px; padding: 12px 14px; border-radius: 12px;
  border: 1px solid var(--border); background: var(--surface); outline: none; -webkit-appearance: none; appearance: none;
  font-size: 16px; /* verhindert Zoom auf iOS */
}
input[type="date"] { display: block; }
select {
  padding-right: 36px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23888' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center; background-size: 18px;
}
textarea { resize: vertical; min-height: 96px; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }

/* Segment-Auswahl (Ort, Status) */
.segmented { display: flex; gap: 4px; padding: 4px; border-radius: 12px; background: var(--surface-2); }
.segmented label { flex: 1; position: relative; }
.segmented input { position: absolute; opacity: 0; inset: 0; }
.segmented span {
  display: flex; align-items: center; justify-content: center; min-height: 42px; padding: 0 4px; border-radius: 9px;
  font-size: 14px; font-weight: 600; color: var(--muted); text-align: center; line-height: 1.15;
}
.segmented input:checked + span { background: var(--surface); color: var(--text); box-shadow: 0 1px 4px rgba(0, 0, 0, 0.15); }
.segmented input:focus-visible + span { outline: 2px solid var(--accent); }

/* Schalter (Favorit) */
.switch-row { display: flex; align-items: center; justify-content: space-between; min-height: 52px; margin-bottom: 14px; font-weight: 600; }
.switch { position: relative; width: 52px; height: 32px; flex: none; }
.switch input { position: absolute; inset: 0; opacity: 0; margin: 0; }
.switch span { position: absolute; inset: 0; border-radius: 16px; background: var(--surface-2); border: 1px solid var(--border); transition: 0.15s; pointer-events: none; }
.switch span::after { content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.3); transition: 0.15s; }
.switch input:checked + span { background: var(--gold); border-color: var(--gold); }
.switch input:checked + span::after { transform: translateX(20px); }

/* ---------- Filter ---------- */
.toolbar { display: grid; gap: 10px; margin-bottom: 14px; }
.chips { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; margin: 0 -16px; padding: 2px 16px; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; min-height: 40px; padding: 0 14px; border-radius: 20px; border: 1px solid var(--border);
  background: var(--surface); font-size: 14px; font-weight: 600; color: var(--muted); white-space: nowrap;
}
.chip .n { opacity: 0.7; font-weight: 500; margin-left: 4px; }
.chip[aria-pressed="true"] { background: var(--text); color: var(--bg); border-color: var(--text); }
.chip.friday { color: var(--accent); border-color: var(--accent); }
.chip.friday[aria-pressed="true"] { background: var(--accent); color: var(--on-accent); }
.filter-row { display: flex; gap: 8px; }
.filter-row select { flex: 1; min-width: 0; min-height: 44px; padding-top: 8px; padding-bottom: 8px; font-size: 15px; }

/* ---------- Karten ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }
.list { display: grid; gap: 10px; }
.empty { text-align: center; color: var(--muted); padding: 40px 16px; }
.empty strong { display: block; color: var(--text); font-size: 17px; margin-bottom: 4px; }

.idea { display: grid; grid-template-columns: 1fr auto; gap: 6px 10px; cursor: pointer; padding: 14px 10px 14px 16px; }
.idea:active { background: var(--surface-2); }
.idea h3 { margin: 0; font-size: 17px; line-height: 1.3; font-weight: 650; word-break: break-word; }
.idea .hook { grid-column: 1; margin: 0; color: var(--muted); font-size: 14px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.idea .meta { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 4px; }
.idea .star { grid-row: 1 / span 2; grid-column: 2; align-self: start; border: 0; background: none; width: 44px; height: 44px; margin: -10px -2px 0 0; display: grid; place-items: center; color: var(--muted); }
.idea .star svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linejoin: round; }
.idea .star.on { color: var(--gold); }
.idea .star.on svg { fill: currentColor; }
.tag { display: inline-flex; align-items: center; gap: 4px; height: 26px; padding: 0 10px; border-radius: 13px; background: var(--surface-2); font-size: 13px; color: var(--muted); font-weight: 500; }
.tag svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
a.tag { text-decoration: none; }
.status {
  display: inline-flex; align-items: center; gap: 6px; height: 30px; padding: 0 12px; border-radius: 15px;
  border: 1px solid color-mix(in srgb, var(--c) 45%, transparent); background: color-mix(in srgb, var(--c) 12%, transparent);
  color: var(--c); font-size: 13px; font-weight: 650;
}
.status::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
button.status::after { content: "›"; font-size: 16px; line-height: 1; margin-left: 2px; opacity: 0.8; }
.status.idee { --c: var(--st-idee); }
.status.freitag { --c: var(--st-freitag); }
.status.gedreht { --c: var(--st-gedreht); }
.status.gepostet { --c: var(--st-gepostet); }

/* ---------- Zahlen ---------- */
.followers-card { display: grid; gap: 14px; }
.followers-top { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; }
.big-number { font-size: 44px; font-weight: 750; letter-spacing: -0.03em; line-height: 1; font-variant-numeric: tabular-nums; }
.label { font-size: 13px; color: var(--muted); font-weight: 600; margin-bottom: 6px; }
.progress { height: 10px; border-radius: 5px; background: var(--surface-2); overflow: hidden; }
.progress > div { height: 100%; border-radius: 5px; background: var(--accent); min-width: 4px; transition: width 0.4s; }
.progress-legend { display: flex; justify-content: space-between; font-size: 13px; color: var(--muted); margin-top: 6px; }
.progress-legend b { color: var(--text); font-weight: 650; }
.pace { font-size: 14px; color: var(--muted); }
.pace b { color: var(--text); }

.chart-card { margin-top: 12px; padding: 16px 12px 10px; }
.chart-card .card-head { display: flex; justify-content: space-between; align-items: center; padding: 0 4px 6px; }
.chart-card h2 { margin: 0; font-size: 15px; }
.chart-wrap { position: relative; touch-action: pan-y; }
.chart-wrap svg { width: 100%; overflow: visible; }
.chart-wrap .grid line { stroke: var(--border); stroke-width: 1; }
.chart-wrap .axis text { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart-wrap .line { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart-wrap .area { fill: var(--accent-soft); }
.chart-wrap .dot { fill: var(--accent); stroke: var(--surface); stroke-width: 2; }
.chart-wrap .cross { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 3 3; }
.chart-tip {
  position: absolute; top: 0; transform: translateX(-50%); pointer-events: none; white-space: nowrap;
  background: var(--text); color: var(--bg); font-size: 12px; font-weight: 600; padding: 5px 9px; border-radius: 8px;
}
.chart-empty { color: var(--muted); font-size: 14px; padding: 28px 8px; text-align: center; }

.video { cursor: pointer; display: grid; gap: 10px; }
.video:active { background: var(--surface-2); }
.video-head { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; }
.video-head h3 { margin: 2px 0 0; font-size: 16px; font-weight: 650; line-height: 1.3; word-break: break-word; }
.video-date { font-size: 13px; color: var(--muted); font-weight: 600; }
.views { text-align: right; flex: none; }
.views b { display: block; font-size: 22px; font-weight: 750; letter-spacing: -0.02em; line-height: 1.1; font-variant-numeric: tabular-nums; }
.views span { font-size: 12px; color: var(--muted); }
.metrics { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 14px; color: var(--muted); font-variant-numeric: tabular-nums; }
.metrics span { display: inline-flex; align-items: center; gap: 5px; }
.metrics svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.metrics .plus { color: var(--st-gepostet); font-weight: 650; }
.video .note { margin: 0; font-size: 14px; color: var(--muted); border-left: 2px solid var(--border); padding-left: 10px; white-space: pre-line; }
.video.best { border-color: var(--gold); background: linear-gradient(var(--gold-soft), var(--gold-soft)), var(--surface); }
.best-badge { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; font-weight: 700; color: var(--gold); margin-left: 8px; white-space: nowrap; vertical-align: top; }
.best-badge svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.history { display: grid; gap: 0; margin: 0 0 8px; padding: 0; list-style: none; }
.history li { display: flex; align-items: center; justify-content: space-between; min-height: 52px; border-bottom: 1px solid var(--border); gap: 12px; }
.history li b { font-variant-numeric: tabular-nums; }

/* ---------- Bottom-Sheet & Dialoge ---------- */
dialog { color: var(--text); }
dialog::backdrop { background: rgba(0, 0, 0, 0.5); }
.sheet {
  margin: auto 0 0; width: 100%; max-width: 640px; max-height: 92dvh; padding: 0;
  border: 0; border-radius: 22px 22px 0 0; background: var(--bg);
  margin-left: auto; margin-right: auto;
}
.sheet[open] { animation: slide-up 0.22s ease-out; }
@keyframes slide-up { from { transform: translateY(40px); opacity: 0; } }
.sheet-head {
  position: sticky; top: 0; z-index: 1; display: flex; align-items: center; justify-content: space-between;
  padding: 10px 8px 10px 20px; background: var(--bg); border-bottom: 1px solid var(--border);
}
.sheet-head h2 { margin: 0; font-size: 18px; }
.sheet-body { padding: 18px 20px calc(24px + var(--safe-b)); }
.sheet-actions { display: grid; gap: 8px; margin-top: 8px; }

.confirm { width: min(340px, calc(100% - 32px)); border: 0; border-radius: 18px; padding: 22px 20px 16px; background: var(--surface); text-align: center; }
.confirm p { margin: 0 0 6px; font-size: 17px; font-weight: 650; }
.confirm .muted { font-size: 14px; font-weight: 400; margin-bottom: 16px; }
.confirm input { margin: 6px 0 16px; }
.confirm .row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

.cat-row { display: flex; align-items: center; gap: 8px; min-height: 56px; border-bottom: 1px solid var(--border); }
.cat-row .name { flex: 1; font-weight: 600; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.cat-row .count { color: var(--muted); font-size: 14px; }
.add-row { display: flex; gap: 8px; margin-top: 16px; }
.add-row input { flex: 1; min-width: 0; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + var(--safe-b) + 90px); z-index: 50;
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none; transition: 0.2s;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 14px; font-weight: 600;
  max-width: calc(100% - 32px); text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: var(--danger); color: #fff; }

/* ---------- Login ---------- */
.login-page { display: grid; place-items: center; padding: 24px 16px; }
.login-card { width: 100%; max-width: 360px; text-align: center; }
.login-card img { margin: 0 auto 12px; border-radius: 16px; }
.login-card h1 { margin: 0 0 4px; font-size: 26px; }
.login-card .muted { margin: 0 0 20px; }
.login-card .small { margin-top: 16px; }
.error { color: var(--danger); min-height: 1.4em; margin: -4px 0 10px; font-size: 14px; }

.loading { text-align: center; color: var(--muted); padding: 60px 0; }
