:root {
  --bg: #f5f6fb;
  --card: #ffffff;
  --text: #1c1f2e;
  --muted: #6b7088;
  --line: #e6e8f0;
  --accent: #4f46e5;
  --accent-soft: #eceafe;
  --ok: #16a34a;
  --ok-soft: #dcfce7;
  --warn: #c2410c;
  --warn-soft: #ffedd5;
  --gift: #b45309;
  --gift-soft: #fef3c7;
  --danger: #dc2626;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(20, 22, 40, .06), 0 4px 14px rgba(20, 22, 40, .05);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1117;
    --card: #1a1d27;
    --text: #eceef5;
    --muted: #9a9fb5;
    --line: #2a2e3c;
    --accent: #8b85ff;
    --accent-soft: #26244a;
    --ok: #4ade80;
    --ok-soft: #143222;
    --warn: #fb923c;
    --warn-soft: #3a2414;
    --gift: #fbbf24;
    --gift-soft: #3a2f12;
    --danger: #f87171;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
main {
  max-width: 640px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 20px) 16px calc(env(safe-area-inset-bottom) + 96px);
}
h1 { font-size: 1.7rem; margin: 0 0 2px; letter-spacing: -.02em; }
h2 { font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 26px 4px 8px; font-weight: 600; }
p { margin: 0 0 12px; }
.sub { color: var(--muted); margin-bottom: 8px; }
.splash { text-align: center; color: var(--muted); padding-top: 30vh; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.center { text-align: center; }
.row { display: flex; gap: 8px; align-items: center; }
.grow { flex: 1; min-width: 0; }
.stack > * + * { margin-top: 10px; }

/* Kort og lister */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }
.list { display: flex; flex-direction: column; gap: 10px; }
.task { display: flex; align-items: center; gap: 12px; background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 14px 14px 16px; }
.task.done { opacity: .75; }
.task .title { font-weight: 600; overflow-wrap: anywhere; }
.task .desc { color: var(--muted); font-size: .88rem; margin-top: 2px; overflow-wrap: anywhere; }
.task .meta { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.task.overdue { box-shadow: inset 4px 0 0 var(--warn), var(--shadow); }

.chip { display: inline-flex; align-items: center; gap: 4px; font-size: .78rem; font-weight: 600; padding: 3px 9px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); white-space: nowrap; }
.chip.money { background: var(--ok-soft); color: var(--ok); }
.chip.gift { background: var(--gift-soft); color: var(--gift); }
.chip.warn { background: var(--warn-soft); color: var(--warn); }
.chip.plain { background: var(--bg); color: var(--muted); }

.check {
  flex: none; width: 48px; height: 48px; border-radius: 50%;
  border: 2.5px solid var(--line); background: transparent; color: transparent;
  display: grid; place-items: center; cursor: pointer; transition: transform .15s, background .2s, border-color .2s;
}
.check svg { width: 24px; height: 24px; }
.check:active { transform: scale(.9); }
.check:hover { border-color: var(--ok); }
.check.on { background: var(--ok); border-color: var(--ok); color: #fff; }
.check.busy { opacity: .5; pointer-events: none; }

.progress { height: 8px; background: var(--line); border-radius: 99px; overflow: hidden; margin-top: 8px; }
.progress > i { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), #a855f7); border-radius: 99px; }

.hero { background: linear-gradient(135deg, var(--accent), #7c3aed); color: #fff; border-radius: 20px; padding: 20px; }
.hero .big { font-size: 2.2rem; font-weight: 700; letter-spacing: -.02em; }
.empty { text-align: center; color: var(--muted); padding: 28px 12px; }
.empty .emoji { font-size: 2.4rem; display: block; margin-bottom: 6px; }

/* Knapper og skjema */
button, .btn {
  font: inherit; font-weight: 600; border: 0; border-radius: 12px; padding: 12px 16px; cursor: pointer;
  background: var(--accent); color: #fff; display: inline-flex; align-items: center; justify-content: center; gap: 6px; text-decoration: none;
}
button.secondary { background: var(--accent-soft); color: var(--accent); }
button.ghost { background: transparent; color: var(--accent); padding: 8px 10px; }
button.danger { background: transparent; color: var(--danger); }
button.small { padding: 7px 12px; font-size: .88rem; border-radius: 10px; }
button.block { width: 100%; }
button:disabled { opacity: .5; cursor: default; }

label { display: block; font-weight: 600; font-size: .9rem; margin-bottom: 6px; }
.field { margin-bottom: 16px; }
.hint { font-weight: 400; color: var(--muted); font-size: .82rem; margin-top: 4px; }
input[type=text], input[type=email], input[type=number], input[type=date], input[type=time], input[inputmode], textarea, select {
  width: 100%; font: inherit; color: var(--text); background: var(--card);
  border: 1.5px solid var(--line); border-radius: 12px; padding: 11px 12px; min-height: 46px;
}
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--accent); }
textarea { min-height: 70px; resize: vertical; }
.code-input { font-size: 1.8rem !important; letter-spacing: .4em; text-align: center; font-variant-numeric: tabular-nums; }

.seg { display: flex; background: var(--line); border-radius: 12px; padding: 3px; gap: 3px; }
.seg button { flex: 1; background: transparent; color: var(--muted); padding: 9px 6px; border-radius: 9px; font-size: .9rem; }
.seg button.on { background: var(--card); color: var(--text); box-shadow: var(--shadow); }

.pills { display: flex; flex-wrap: wrap; gap: 8px; }
.pill { position: relative; }
.pill input { position: absolute; opacity: 0; pointer-events: none; }
.pill span { display: inline-block; padding: 8px 14px; border-radius: 999px; border: 1.5px solid var(--line); font-weight: 600; font-size: .9rem; cursor: pointer; user-select: none; background: var(--card); }
.pill input:checked + span { background: var(--accent); border-color: var(--accent); color: #fff; }
.pill input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

.switch { display: flex; align-items: center; justify-content: space-between; gap: 12px; font-weight: 600; }
.switch input { width: 46px; height: 28px; appearance: none; background: var(--line); border-radius: 99px; position: relative; cursor: pointer; transition: background .2s; flex: none; }
.switch input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; transition: transform .2s; box-shadow: 0 1px 3px rgba(0,0,0,.2); }
.switch input:checked { background: var(--accent); }
.switch input:checked::after { transform: translateX(18px); }

.admin-nav { position: sticky; top: env(safe-area-inset-top); z-index: 5; margin: 0 -16px 8px; padding: 8px 16px; background: var(--bg); }

.person { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-top: 1px solid var(--line); }
.person:first-child { border-top: 0; }
.avatar { width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; color: #fff; flex: none; }
.thumb { width: 64px; height: 64px; object-fit: cover; border-radius: 10px; background: var(--line); flex: none; cursor: zoom-in; }

/* Bunnmeny */
#tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; justify-content: center;
  background: color-mix(in srgb, var(--card) 88%, transparent);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
#tabs a {
  flex: 1; max-width: 160px; display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 9px 0 8px; color: var(--muted); text-decoration: none; font-size: .72rem; font-weight: 600;
}
#tabs a svg { width: 24px; height: 24px; }
#tabs a.on { color: var(--accent); }
.tab-icon { position: relative; display: inline-flex; }
.badge {
  position: absolute; top: -4px; right: -10px; min-width: 18px; height: 18px; padding: 0 5px;
  border-radius: 99px; background: var(--danger); color: #fff; font-size: .68rem; font-weight: 700;
  display: grid; place-items: center; border: 2px solid var(--card);
}

/* Sjekkliste på oppgavekort */
.checklist { display: flex; flex-direction: column; gap: 2px; margin-top: 10px; }
.ci { display: flex; align-items: center; gap: 10px; font-weight: 500; font-size: .92rem; margin: 0; padding: 6px 0; cursor: pointer; }
.ci input { width: 22px; height: 22px; accent-color: var(--ok); flex: none; margin: 0; }
.ci input:checked + span { text-decoration: line-through; color: var(--muted); }

/* Bunnark */
.sheet-bg { position: fixed; inset: 0; z-index: 40; background: rgba(10, 12, 20, .45); display: flex; align-items: flex-end; justify-content: center; animation: fade .2s; }
.sheet {
  width: 100%; max-width: 560px; max-height: 88vh; overflow: auto; background: var(--card);
  border-radius: 22px 22px 0 0; padding: 20px 16px calc(env(safe-area-inset-bottom) + 16px);
  animation: slideup .25s ease-out;
}
.sheet-title { font-size: 1.2rem; text-transform: none; letter-spacing: 0; color: var(--text); margin: 0 0 16px; }
.preview { display: block; width: 100%; max-height: 240px; object-fit: cover; border-radius: 12px; margin-top: 10px; }
@keyframes fade { from { opacity: 0; } }
@keyframes slideup { from { transform: translateY(40px); opacity: .5; } }

/* Statistikk-fliser */
.stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-top: 12px; }
.stats.tight { grid-template-columns: repeat(3, minmax(0, 1fr)); margin-top: 0; }
.stat { background: var(--card); border-radius: 14px; padding: 12px; box-shadow: var(--shadow); min-width: 0; }
.stats.tight .stat { background: var(--bg); box-shadow: none; padding: 10px; }
.stat-v { font-size: 1.25rem; font-weight: 700; letter-spacing: -.01em; overflow-wrap: anywhere; }
.stats.tight .stat-v { font-size: 1.05rem; }
.stat-l { color: var(--muted); font-size: .8rem; font-weight: 600; }
.stat-s { font-size: .75rem; color: var(--muted); margin-top: 2px; }
.warn-text { color: var(--warn); font-weight: 600; }

.seg.compact { overflow-x: auto; scrollbar-width: none; }
.seg.compact button { font-size: .8rem; padding: 8px 4px; white-space: nowrap; min-width: max-content; flex: 1 0 auto; }
.form-h { margin: 22px 0 10px; }
.notif { color: inherit; text-decoration: none; }
.notif.unread { box-shadow: inset 3px 0 0 var(--accent); padding-left: 10px; }
.notif.unread b::after { content: " •"; color: var(--accent); }

#toast {
  position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 84px); transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 12px 18px; border-radius: 14px; font-weight: 600;
  z-index: 20; max-width: calc(100% - 32px); text-align: center; box-shadow: 0 8px 24px rgba(0,0,0,.2);
  animation: pop .25s ease-out;
}
@keyframes pop { from { opacity: 0; transform: translate(-50%, 10px); } }

.overlay { position: fixed; inset: 0; background: rgba(0,0,0,.85); z-index: 30; display: grid; place-items: center; padding: 16px; }
.overlay img { max-width: 100%; max-height: 90vh; border-radius: 12px; }

.celebrate { position: fixed; inset: 0; pointer-events: none; z-index: 25; display: grid; place-items: center; font-size: 5rem; animation: burst 1s ease-out forwards; }
@keyframes burst { 0% { transform: scale(.3); opacity: 0; } 30% { transform: scale(1.1); opacity: 1; } 100% { transform: scale(1.4); opacity: 0; } }
