/* ── Reset & tokens ──────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #f8fafc;
  --surface: #ffffff;
  --surface2: #f1f5f9;
  --border: #e2e8f0;
  --text: #0f172a;
  --text-muted: #64748b;
  --accent: #0ea5e9;
  --accent-hover: #0284c7;
  --danger: #ef4444;
  --danger-hover: #dc2626;
  --success: #22c55e;
  --warning: #f59e0b;
  --radius: 0.5rem;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
  --shadow-lg: 0 4px 16px rgba(0,0,0,.12);
}

body {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 0.9375rem;
  line-height: 1.5;
  min-height: 100vh;
}

/* ── Layout ──────────────────────────────────────────────────────────── */
#app { display: flex; flex-direction: column; min-height: 100vh; }

nav {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 1rem;
  height: 3.25rem;
  gap: 0.25rem;
  box-shadow: var(--shadow);
}

nav .brand {
  font-weight: 800;
  font-size: 1.05rem;
  color: var(--accent);
  margin-right: auto;
  letter-spacing: -0.02em;
}

nav a {
  color: var(--text-muted);
  text-decoration: none;
  padding: 0.35rem 0.65rem;
  border-radius: var(--radius);
  font-size: 0.875rem;
  font-weight: 500;
  transition: background 0.12s, color 0.12s;
}
nav a:hover, nav a.active { background: var(--surface2); color: var(--text); }

#btn-logout {
  background: none; border: none; cursor: pointer;
  color: var(--text-muted); font-size: 0.875rem; font-weight: 500;
  padding: 0.35rem 0.65rem; border-radius: var(--radius);
  transition: background 0.12s, color 0.12s;
}
#btn-logout:hover { background: var(--surface2); color: var(--danger); }

main { flex: 1; padding: 1.5rem 1rem; max-width: 52rem; width: 100%; margin: 0 auto; }
main.wide { max-width: 80rem; }

/* ── Cards ───────────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow);
}
.card + .card, .card + form, form + .card { margin-top: 1rem; }

.card-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; margin-bottom: 1rem; }
.stat-card { text-align: center; }
.stat-card .num { font-size: 2rem; font-weight: 800; color: var(--accent); }
.stat-card .lbl { color: var(--text-muted); font-size: 0.8rem; margin-top: 0.15rem; }

/* ── Typography ──────────────────────────────────────────────────────── */
h1 { font-size: 1.3rem; font-weight: 700; margin-bottom: 1rem; }
h2 { font-size: 1.05rem; font-weight: 600; margin-bottom: 0.75rem; }

/* ── Forms ───────────────────────────────────────────────────────────── */
.field { display: flex; flex-direction: column; gap: 0.3rem; margin-bottom: 0.75rem; }
label { font-size: 0.82rem; font-weight: 500; color: var(--text-muted); }
input, select, textarea {
  padding: 0.5rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font: inherit;
  font-size: 0.875rem;
  background: var(--surface);
  color: var(--text);
  transition: border-color 0.12s;
  width: 100%;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(14,165,233,.12);
}
textarea { resize: vertical; min-height: 4rem; }

/* ── Buttons ─────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 0.4rem;
  padding: 0.5rem 1rem; border-radius: var(--radius);
  font: inherit; font-size: 0.875rem; font-weight: 600;
  cursor: pointer; border: none; transition: background 0.12s, opacity 0.12s;
  white-space: nowrap;
}
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn-ghost { background: var(--surface2); color: var(--text); border: 1px solid var(--border); }
.btn-ghost:hover:not(:disabled) { background: var(--border); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { background: var(--danger-hover); }
.btn-sm { padding: 0.3rem 0.65rem; font-size: 0.8rem; }

/* ── Table ───────────────────────────────────────────────────────────── */
.tbl-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
th { text-align: left; padding: 0.5rem 0.75rem; color: var(--text-muted); font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.04em; border-bottom: 1px solid var(--border); }
td { padding: 0.6rem 0.75rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--surface2); }

/* ── Badges / status ─────────────────────────────────────────────────── */
.badge { display: inline-block; padding: 0.15rem 0.5rem; border-radius: 9999px; font-size: 0.72rem; font-weight: 600; }
.badge-ok { background: #dcfce7; color: #15803d; }
.badge-err { background: #fee2e2; color: #b91c1c; }
.badge-type { background: #e0f2fe; color: #0369a1; }
.badge-cat  { background: #f3e8ff; color: #7e22ce; }

/* ── Alerts ──────────────────────────────────────────────────────────── */
.alert { padding: 0.7rem 1rem; border-radius: var(--radius); font-size: 0.875rem; margin-bottom: 0.75rem; }
.alert-err { background: #fee2e2; color: #991b1b; border: 1px solid #fca5a5; }
.alert-ok  { background: #dcfce7; color: #166534; border: 1px solid #86efac; }

/* ── Spinner ─────────────────────────────────────────────────────────── */
.spinner { display: inline-block; width: 1rem; height: 1rem; border: 2px solid rgba(255,255,255,.4); border-top-color: #fff; border-radius: 50%; animation: spin 0.7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Login / Register pages ──────────────────────────────────────────── */
#page-login { display: flex; justify-content: center; align-items: center; min-height: calc(100vh - 3.25rem); }
.login-box { width: 100%; max-width: 22rem; }
.login-box h1 { text-align: center; margin-bottom: 1.25rem; }
.auth-switch { text-align: center; font-size: 0.82rem; color: var(--text-muted); margin-top: 1rem; }
.auth-switch a { color: var(--accent); text-decoration: none; font-weight: 500; }
.auth-switch a:hover { text-decoration: underline; }

/* ── Row utilities ───────────────────────────────────────────────────── */
.row { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; }
.row .grow { flex: 1; min-width: 0; }
.mt { margin-top: 1rem; }

/* ── Toggle ──────────────────────────────────────────────────────────── */
.toggle-wrap { display: flex; align-items: center; gap: 0.5rem; }
.toggle { position: relative; display: inline-block; width: 2.25rem; height: 1.25rem; }
.toggle input { opacity: 0; width: 0; height: 0; }
.slider { position: absolute; inset: 0; background: var(--border); border-radius: 9999px; transition: background 0.2s; cursor: pointer; }
.slider::before { content: ''; position: absolute; left: 0.2rem; top: 0.2rem; width: 0.85rem; height: 0.85rem; background: #fff; border-radius: 50%; transition: transform 0.2s; }
input:checked + .slider { background: var(--accent); }
input:checked + .slider::before { transform: translateX(1rem); }

/* ── Modal ───────────────────────────────────────────────────────────── */
.modal-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: flex; align-items: center; justify-content: center; z-index: 100; padding: 1rem; }
.modal { background: var(--surface); border-radius: calc(var(--radius) * 1.5); padding: 1.5rem; width: 100%; max-width: 26rem; box-shadow: var(--shadow-lg); }
.modal h2 { margin-bottom: 1rem; }
.modal-close { float: right; background: none; border: none; font-size: 1.2rem; cursor: pointer; color: var(--text-muted); line-height: 1; margin-top: -0.15rem; }

/* ── Events modal ─────────────────────────────────────────────────────── */
.modal-wide { max-width: 52rem; }
.events-table td { vertical-align: top; font-size: .82rem; }
.ev-desc { color: var(--text-muted); font-size: .78rem; margin-top: .2rem; line-height: 1.4; }
.ev-link { font-size: .75rem; color: var(--accent); text-decoration: none; display: inline-block; margin-top: .2rem; }
.src-url { font-size: .72rem; color: var(--text-muted); margin-top: .15rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 22rem; }
.ev-link:hover { text-decoration: underline; }
.ev-date          { white-space: nowrap; color: var(--text-muted); }
.ev-location-link { color: var(--accent); text-decoration: none; font-size: .82rem; }
.ev-location-link:hover { text-decoration: underline; }

/* ── Subscribe box ───────────────────────────────────────────────────── */
.sub-url { font-size: 0.75rem; word-break: break-all; padding: 0.5rem; background: var(--surface2); border-radius: var(--radius); border: 1px solid var(--border); margin-bottom: 0.5rem; }
#qrcode { margin: 0.75rem auto; width: fit-content; }
.steps { padding-left: 1.2rem; font-size: 0.85rem; color: var(--text-muted); }
.steps li { margin-bottom: 0.3rem; }

/* ── Web / JSON-source extra fields ──────────────────────────────────── */
.tooltip-wrap { position: relative; display: inline-flex; align-items: center; }
.tooltip-icon { cursor: help; color: var(--text-muted); font-size: 0.8rem; margin-left: 0.3rem; }
.tooltip-text { display: none; position: absolute; left: 1.4rem; top: 50%; transform: translateY(-50%); background: var(--text); color: #fff; font-size: 0.75rem; padding: 0.35rem 0.6rem; border-radius: var(--radius); width: 14rem; z-index: 10; line-height: 1.4; }
.tooltip-wrap:hover .tooltip-text, .tooltip-wrap:focus-within .tooltip-text { display: block; }

/* ── Chips ───────────────────────────────────────────────────────────── */
.chips { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.chip { display: inline-flex; align-items: center; gap: 0.3rem; background: var(--surface2); border: 1px solid var(--border); border-radius: 9999px; padding: 0.2rem 0.6rem; font-size: 0.78rem; }
.chip-del { background: none; border: none; cursor: pointer; color: var(--text-muted); font-size: 0.85rem; line-height: 1; padding: 0 0.1rem; }
.chip-del:hover { color: var(--danger); }

/* ── Responsive ──────────────────────────────────────────────────────── */
@media (max-width: 500px) {
  .card-grid { grid-template-columns: 1fr 1fr; }
  table { font-size: 0.78rem; }
  td, th { padding: 0.45rem 0.5rem; }
}
