:root {
  --bg: #f5f2ec;
  --surface: #ffffff;
  --ink: #1d2420;
  --muted: #69716c;
  --line: #e4ded3;
  --accent: #1f4d3a;
  --accent-ink: #ffffff;
  --accent-soft: #e3ece6;
  --gold: #e0a93b;
  --danger: #b3261e;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(29, 36, 32, .06), 0 6px 20px rgba(29, 36, 32, .06);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

body.theme-christmas {
  --bg: #f7f1e8;
  --accent: #9e2a2b;
  --accent-soft: #f6e3df;
  --gold: #d9a441;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 17px/1.5 var(--font);
  min-height: 100vh;
}
body.theme-christmas {
  background:
    radial-gradient(circle at 10% 0%, rgba(158, 42, 43, .08), transparent 40%),
    radial-gradient(circle at 90% 10%, rgba(31, 77, 58, .10), transparent 45%),
    var(--bg);
}

h1, h2, h3 { line-height: 1.2; margin: 0; letter-spacing: -.01em; }
h1 { font-size: 1.75rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1.05rem; margin-top: .5rem; }
p { margin: 0; }
a { color: var(--accent); }

/* ---- Layout ---- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px max(16px, env(safe-area-inset-left)) 10px max(16px, env(safe-area-inset-right));
  background: rgba(255, 255, 255, .85);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; color: var(--ink); text-decoration: none; font-size: 1.05rem; }
.brand-star {
  display: grid; place-items: center; width: 30px; height: 30px; border-radius: 9px;
  background: var(--accent); color: var(--gold); font-size: 17px;
}
.topnav { display: flex; align-items: center; gap: 10px; font-size: .9rem; }
.whoami { color: var(--muted); max-width: 30vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.navlink { font-weight: 600; text-decoration: none; }

.page { max-width: 760px; margin: 0 auto; padding: 24px 16px calc(48px + env(safe-area-inset-bottom)); }
.stack { display: flex; flex-direction: column; gap: 12px; }
.stack-lg { display: flex; flex-direction: column; gap: 22px; }
.center-wrap { display: flex; flex-direction: column; gap: 16px; max-width: 440px; margin: 6vh auto 0; }
.loading { color: var(--muted); text-align: center; padding: 40px 0; }

/* ---- Cards ---- */
.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; }
.card.empty { text-align: center; display: flex; flex-direction: column; gap: 14px; align-items: center; color: var(--muted); }
.hero { text-align: center; display: flex; flex-direction: column; gap: 14px; align-items: center; padding: 32px 24px; }
.hero-icon { font-size: 52px; line-height: 1; }
.lead { color: var(--muted); font-size: 1.05rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.pre { white-space: pre-line; }
.hint { display: block; color: var(--muted); font-size: .82rem; font-weight: 400; }
.notice { background: #fff6dd; border: 1px solid #f0dca2; padding: 10px 14px; border-radius: 12px; font-size: .92rem; }
.error { color: var(--danger); font-size: .92rem; min-height: 0; }
.error:empty { display: none; }
.back { text-decoration: none; font-weight: 600; font-size: .95rem; align-self: flex-start; }
.title-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }

/* ---- Tiles & lists ---- */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; }
.tile {
  display: flex; flex-direction: column; justify-content: flex-end; gap: 6px; min-height: 140px;
  padding: 20px; border-radius: var(--radius); text-decoration: none; color: #fff;
  background: linear-gradient(140deg, #1f4d3a, #2f6f55); box-shadow: var(--shadow);
  transition: transform .15s ease;
}
.tile:active { transform: scale(.98); }
.tile-christmas { background: linear-gradient(140deg, #7d1f22 0%, #9e2a2b 45%, #1f4d3a 130%); }
.tile-title { font-size: 1.25rem; font-weight: 700; }
.tile-text { opacity: .85; font-size: .92rem; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

.list { display: flex; flex-direction: column; gap: 10px; }
.row-card {
  display: flex; align-items: center; gap: 12px; padding: 16px 18px;
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
  text-decoration: none; color: var(--ink);
}
a.row-card:active { transform: scale(.99); }
.row-card.person { flex-wrap: wrap; }
.row-card.is-disabled { opacity: .65; }
.row-main { display: flex; flex-direction: column; gap: 2px; flex: 1; min-width: 0; }
.row-title { font-weight: 600; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.row-sub { color: var(--muted); font-size: .85rem; }
.row-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.chev { color: var(--muted); font-size: 1.5rem; }

.badge {
  display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: .78rem; font-weight: 600; white-space: nowrap;
  background: var(--accent-soft); color: var(--accent);
}
.badge-closed { background: #eceae6; color: var(--muted); }
.badge-draft { background: #fff1cc; color: #8a6400; }

/* ---- Forms ---- */
label { display: flex; flex-direction: column; gap: 6px; font-weight: 600; font-size: .92rem; }
input[type="text"], input[type="password"], select, textarea {
  font: inherit; font-weight: 400; color: var(--ink); width: 100%;
  padding: 11px 13px; border: 1.5px solid var(--line); border-radius: 12px; background: #fff;
}
textarea { resize: vertical; line-height: 1.45; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.inline-form { display: flex; gap: 8px; flex-wrap: wrap; }
.inline-form > input, .inline-form > select { flex: 1 1 180px; width: auto; }
.checks { display: flex; flex-direction: column; gap: 4px; }
.check { flex-direction: row; align-items: center; gap: 10px; font-weight: 500; font-size: 1rem; padding: 6px 0; }
.check input { width: 20px; height: 20px; accent-color: var(--accent); }
.actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }

.btn, .btn-ghost, .btn-danger {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 0 18px; border-radius: 12px; border: 0;
  font: inherit; font-weight: 600; font-size: .95rem; cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn { background: var(--accent); color: var(--accent-ink); }
.btn-ghost { background: transparent; color: var(--ink); border: 1.5px solid var(--line); }
.btn-danger { background: transparent; color: var(--danger); border: 1.5px solid #efc9c6; }
.btn.small, .btn-ghost.small, .btn-danger.small { min-height: 36px; padding: 0 12px; font-size: .85rem; border-radius: 10px; }
.btn.big { min-height: 56px; padding: 0 36px; font-size: 1.1rem; border-radius: 16px; width: 100%; }
button:disabled { opacity: .45; cursor: default; }
.btn:hover:not(:disabled) { filter: brightness(1.08); }
.btn-ghost:hover:not(:disabled) { background: rgba(0, 0, 0, .03); }

.admin-login summary { cursor: pointer; color: var(--muted); font-weight: 600; }
.admin-login[open] summary { margin-bottom: 14px; }

/* ---- Admin: Module ---- */
.module-list { display: flex; flex-direction: column; gap: 10px; }
.module-item { border: 1.5px solid var(--line); border-radius: 14px; overflow: hidden; }
.module-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 12px 14px; }
.module-row .status-select { width: auto; flex: 0 0 auto; padding: 7px 10px; font-size: .88rem; font-weight: 600; }
.status-select.status-open { border-color: #a9cbb7; background: var(--accent-soft); }
.status-select.status-draft { border-color: #f0dca2; background: #fff8e3; }
.module-editor { padding: 14px; background: #faf8f4; border-top: 1.5px solid var(--line); }
.danger-zone { display: flex; justify-content: flex-end; padding-top: 8px; }

/* ---- Rich text ---- */
.rich { display: flex; flex-direction: column; gap: 12px; }
.rich ul { margin: 0; padding-left: 1.2em; display: flex; flex-direction: column; gap: 4px; }
.rich a { word-break: break-word; }

/* ---- QR-Dialog ---- */
.qr-dialog {
  border: 0; border-radius: 20px; padding: 24px; width: min(420px, calc(100vw - 32px));
  box-shadow: 0 20px 60px rgba(0, 0, 0, .25);
}
.qr-dialog::backdrop { background: rgba(20, 24, 22, .55); }
.qr-dialog .actions { margin-top: 14px; justify-content: center; }
.qr-card { text-align: center; display: flex; flex-direction: column; align-items: center; gap: 10px; }
.qr { width: 240px; max-width: 100%; }
.qr svg { width: 100%; height: auto; display: block; }
.url { font-size: .78rem; color: var(--muted); word-break: break-all; text-align: center; margin-top: 10px; }
.qr-dialog .hint { text-align: center; margin-top: 6px; }

@media (min-width: 640px) {
  h1 { font-size: 2rem; }
  .page { padding-top: 36px; }
}

@media print {
  body > *:not(dialog) { display: none !important; }
  .qr-dialog { box-shadow: none; position: static; }
  .qr-dialog > :not(.print-area) { display: none !important; }
  .qr { width: 7cm; }
}
