/* Selvhostede fonter (variable fonts, kun latin-delmengden - daekker aeoeaa)
   i stedet for Google Fonts-CDN, saa app-skallet ser riktig ut selv naar
   det lastes fra service worker-cachen uten nett. */
@font-face {
  font-family: 'Inter';
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
  src: url('/fonts/inter-var.woff2') format('woff2-variations'), url('/fonts/inter-var.woff2') format('woff2');
}
@font-face {
  font-family: 'Sora';
  font-style: normal;
  font-weight: 400 800;
  font-display: swap;
  src: url('/fonts/sora-var.woff2') format('woff2-variations'), url('/fonts/sora-var.woff2') format('woff2');
}

/* ============================================================
   TEMAER
   Alle farger styres av variablene under. Et tema settes ved at
   <html> faar attributtet data-theme="...".
   ============================================================ */
:root,
[data-theme="midnatt"] {
  --bg-0: #0a0f1c;
  --bg-1: #131b2e;
  --bg-glow: #1c2947;
  --card: #1a2438;
  --card-hi: #202c46;
  --border: rgba(255,255,255,0.07);
  --border-hover: rgba(255,255,255,0.16);
  --track: rgba(255,255,255,0.08);
  --overlay: rgba(5,8,16,0.6);
  --bar-bg: rgba(10,15,28,0.75);
  --text: #f2f4f8;
  --muted: #8b96ac;
  --gold: #e8b84b;
  --gold-dark: #c98f2e;
  --gold-dim: rgba(232,184,75,0.15);
  --gold-edge: rgba(232,184,75,0.35);
  --gold-glow: rgba(232,184,75,0.55);
  --on-accent: #1a1206;
  --green: #5fd39a;
  --red: #ff6b6b;
  --radius: 18px;
  --font-display: 'Sora', sans-serif;
  --font-body: 'Inter', sans-serif;
}

/* Skog - dyp gronn med kobber */
[data-theme="skog"] {
  --bg-0: #0a1410;
  --bg-1: #10201a;
  --bg-glow: #16311f;
  --card: #16271f;
  --card-hi: #1d3328;
  --border: rgba(255,255,255,0.07);
  --border-hover: rgba(255,255,255,0.16);
  --track: rgba(255,255,255,0.08);
  --overlay: rgba(4,10,7,0.6);
  --bar-bg: rgba(10,20,16,0.75);
  --text: #eff5f0;
  --muted: #85a091;
  --gold: #d9a05b;
  --gold-dark: #a9743a;
  --gold-dim: rgba(217,160,91,0.15);
  --gold-edge: rgba(217,160,91,0.35);
  --gold-glow: rgba(217,160,91,0.5);
  --on-accent: #1a1005;
  --green: #6ed39a;
  --red: #ff7a7a;
}

/* Plomme - morkt lilla med rosa */
[data-theme="plomme"] {
  --bg-0: #120b1c;
  --bg-1: #1c1230;
  --bg-glow: #2b1a47;
  --card: #221636;
  --card-hi: #2c1d45;
  --border: rgba(255,255,255,0.08);
  --border-hover: rgba(255,255,255,0.18);
  --track: rgba(255,255,255,0.09);
  --overlay: rgba(8,4,14,0.62);
  --bar-bg: rgba(18,11,28,0.75);
  --text: #f4f0fa;
  --muted: #9c8bb8;
  --gold: #e879a8;
  --gold-dark: #b85480;
  --gold-dim: rgba(232,121,168,0.15);
  --gold-edge: rgba(232,121,168,0.35);
  --gold-glow: rgba(232,121,168,0.5);
  --on-accent: #230d18;
  --green: #6ad3a8;
  --red: #ff6b8a;
}

/* Karbon - nesten svart, hoy kontrast */
[data-theme="karbon"] {
  --bg-0: #0b0b0d;
  --bg-1: #141417;
  --bg-glow: #1e1e23;
  --card: #17171b;
  --card-hi: #1f1f25;
  --border: rgba(255,255,255,0.10);
  --border-hover: rgba(255,255,255,0.22);
  --track: rgba(255,255,255,0.10);
  --overlay: rgba(0,0,0,0.68);
  --bar-bg: rgba(11,11,13,0.8);
  --text: #fafafa;
  --muted: #9a9aa2;
  --gold: #5ac8fa;
  --gold-dark: #2f93bd;
  --gold-dim: rgba(90,200,250,0.15);
  --gold-edge: rgba(90,200,250,0.35);
  --gold-glow: rgba(90,200,250,0.45);
  --on-accent: #04222e;
  --green: #4ade80;
  --red: #f87171;
}

/* Dagslys - lyst tema */
[data-theme="dagslys"] {
  --bg-0: #eef1f6;
  --bg-1: #ffffff;
  --bg-glow: #dde5f2;
  --card: #ffffff;
  --card-hi: #f6f8fc;
  --border: rgba(15,25,45,0.10);
  --border-hover: rgba(15,25,45,0.24);
  --track: rgba(15,25,45,0.09);
  --overlay: rgba(20,28,45,0.45);
  --bar-bg: rgba(255,255,255,0.85);
  --text: #14203a;
  --muted: #66738c;
  --gold: #c08a1e;
  --gold-dark: #9a6c14;
  --gold-dim: rgba(192,138,30,0.13);
  --gold-edge: rgba(192,138,30,0.35);
  --gold-glow: rgba(192,138,30,0.35);
  --on-accent: #1a1206;
  --green: #17945f;
  --red: #cf3b3b;
}

/* Sand - lyst og varmt */
[data-theme="sand"] {
  --bg-0: #f4efe6;
  --bg-1: #fffdf9;
  --bg-glow: #eae0cf;
  --card: #fffdf9;
  --card-hi: #f9f4ea;
  --border: rgba(60,45,25,0.12);
  --border-hover: rgba(60,45,25,0.26);
  --track: rgba(60,45,25,0.10);
  --overlay: rgba(40,30,18,0.42);
  --bar-bg: rgba(255,253,249,0.85);
  --text: #2f2617;
  --muted: #7d7059;
  --gold: #8c5220;
  --gold-dark: #6f3f18;
  --gold-dim: rgba(140,82,32,0.13);
  --gold-edge: rgba(140,82,32,0.38);
  --gold-glow: rgba(140,82,32,0.35);
  --on-accent: #fffdf9;
  --green: #4f7a3a;
  --red: #b5402f;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: radial-gradient(120% 140% at 15% -10%, var(--bg-glow) 0%, var(--bg-0) 55%);
  color: var(--text);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
}

button, input, select { font-family: inherit; }

.hidden { display: none !important; }

.screen { min-height: 100vh; min-height: 100dvh; }

/* ---------- Login ---------- */
#login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  padding: calc(24px + env(safe-area-inset-top)) calc(24px + env(safe-area-inset-right)) calc(24px + env(safe-area-inset-bottom)) calc(24px + env(safe-area-inset-left));
}
.login-card {
  width: 100%;
  max-width: 360px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 24px;
  padding: 40px 32px;
  text-align: center;
  box-shadow: 0 30px 60px -20px rgba(0,0,0,0.6);
}
.login-mark {
  width: 56px; height: 56px;
  border-radius: 16px;
  background: linear-gradient(145deg, var(--gold), var(--gold-dark));
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 26px;
  color: var(--on-accent);
  margin: 0 auto 20px;
}
.login-card h1 {
  font-family: var(--font-display);
  font-size: 24px;
  font-weight: 700;
  margin: 0 0 8px;
}
.muted { color: var(--muted); font-size: 14px; margin: 0 0 24px; }
#login-form { display: flex; flex-direction: column; gap: 12px; }
#pin-input {
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
  color: var(--text);
  font-size: 18px;
  letter-spacing: 4px;
  text-align: center;
  outline: none;
}
#pin-input:focus { border-color: var(--gold); }
.error-text { color: var(--red); font-size: 13px; min-height: 18px; margin-top: 12px; }

button { cursor: pointer; }

.primary-btn {
  background: linear-gradient(145deg, var(--gold), var(--gold-dark));
  color: var(--on-accent);
  border: none;
  border-radius: 12px;
  padding: 14px;
  font-weight: 700;
  font-size: 15px;
  font-family: var(--font-display);
}
.primary-btn:active { transform: translateY(1px); }

/* ---------- Topbar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 24px;
  /* Skyver toppbaren ned under hakket/dynamic island paa iPhone naar appen
     kjoerer i fullskjerm (standalone), siden den er festet til toppen. */
  padding-top: calc(18px + env(safe-area-inset-top));
  padding-left: calc(24px + env(safe-area-inset-left));
  padding-right: calc(24px + env(safe-area-inset-right));
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 10;
  backdrop-filter: blur(14px);
  background: var(--bar-bg);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark {
  width: 30px; height: 30px;
  border-radius: 9px;
  background: linear-gradient(145deg, var(--gold), var(--gold-dark));
  color: var(--on-accent);
  font-family: var(--font-display);
  font-weight: 800;
  display: flex; align-items: center; justify-content: center;
  font-size: 15px;
}
.brand-name { font-family: var(--font-display); font-weight: 700; font-size: 16px; letter-spacing: 0.2px; }

.month-switcher {
  display: flex; align-items: center; gap: 14px;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 15px;
  color: var(--text);
}
.month-switcher button {
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--text);
  width: 30px; height: 30px;
  border-radius: 9px;
  font-size: 16px;
  line-height: 1;
}
#month-label { min-width: 130px; text-align: center; }

.topbar-actions { display: flex; gap: 8px; }

.ghost-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  padding: 8px 14px;
  border-radius: 10px;
  font-size: 13px;
}
.ghost-btn:hover { color: var(--text); border-color: var(--gold); }

/* ---------- Content ---------- */
.content {
  max-width: 900px;
  margin: 0 auto;
  padding: 24px 24px 100px;
  padding-left: calc(24px + env(safe-area-inset-left));
  padding-right: calc(24px + env(safe-area-inset-right));
  padding-bottom: calc(100px + env(safe-area-inset-bottom));
}

.balance-card {
  display: flex;
  flex-direction: column;
  background: linear-gradient(150deg, var(--card-hi), var(--card));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 26px 20px;
  margin-bottom: 24px;
  box-shadow: 0 20px 40px -25px rgba(0,0,0,0.7);
}
.balance-row { display: flex; }
.rollover-banner {
  font-size: 12px;
  font-weight: 600;
  text-align: center;
  padding: 8px 12px;
  border-radius: 10px;
  margin-bottom: 18px;
}
.rollover-banner.positive { background: rgba(95,211,154,0.12); color: var(--green); }
.rollover-banner.negative { background: rgba(255,107,107,0.12); color: var(--red); }
.balance-block { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; }
.balance-block.main { border-left: 1px solid var(--border); border-right: 1px solid var(--border); }
.balance-label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.6px; }
.balance-value { font-family: var(--font-display); font-weight: 700; font-size: 22px; }
.balance-value.income { color: var(--green); }
.balance-value.expense { color: var(--red); }
.balance-value.negative-total { color: var(--red); }

.members-row {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding-bottom: 4px;
  margin-bottom: 28px;
}
.member-chip {
  display: flex; align-items: center; gap: 8px;
  background: var(--card);
  border: 1px solid var(--border);
  padding: 8px 14px 8px 8px;
  border-radius: 999px;
  white-space: nowrap;
  font-size: 13px;
  font-weight: 600;
}
.member-avatar {
  width: 24px; height: 24px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 11px;
  font-weight: 800;
  color: var(--on-accent);
}
.member-add {
  background: transparent;
  border: 1px dashed var(--border);
  color: var(--muted);
  border-radius: 999px;
  padding: 8px 16px;
  font-size: 13px;
}

.section-head {
  display: flex; align-items: center; justify-content: space-between;
  margin: 8px 0 14px;
}
.section-head h2 {
  font-family: var(--font-display);
  font-size: 16px;
  font-weight: 700;
  margin: 0;
  color: var(--text);
}
.pill-btn {
  background: var(--gold-dim);
  color: var(--gold);
  border: 1px solid var(--gold-edge);
  border-radius: 999px;
  padding: 7px 14px;
  font-size: 13px;
  font-weight: 600;
}

.category-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 14px;
  margin-bottom: 32px;
}
.category-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  display: flex;
  gap: 14px;
  align-items: center;
  position: relative;
  transition: border-color 0.15s ease, transform 0.1s ease;
  width: 100%;
  text-align: left;
  font: inherit;
  color: inherit;
  cursor: pointer;
}
.category-card:hover { border-color: var(--border-hover); }
.category-card:active { transform: scale(0.985); }
.cat-edit-hint {
  position: absolute; top: 12px; right: 14px;
  color: var(--muted); font-size: 13px;
  opacity: 0; transition: opacity 0.15s;
}
.category-card:hover .cat-edit-hint { opacity: 1; }
.ring-wrap { position: relative; width: 56px; height: 56px; flex-shrink: 0; }
.ring-wrap svg { transform: rotate(-90deg); }
.ring-icon {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px;
}
.cat-info { flex: 1; min-width: 0; }
.cat-name { font-weight: 700; font-size: 14px; margin-bottom: 2px; }
.cat-amounts { font-size: 12px; color: var(--muted); }
.cat-amounts .spent { color: var(--text); font-weight: 600; }
.cat-delete {
  position: absolute; top: 10px; right: 10px;
  background: none; border: none; color: var(--muted);
  font-size: 13px; opacity: 0; transition: opacity 0.15s;
}
.category-card:hover .cat-delete { opacity: 1; }
.cat-delete:hover { color: var(--red); }

.tx-search-row { margin-bottom: 10px; }
.tx-search-input {
  width: 100%;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  color: var(--text);
  font-size: 16px;
  outline: none;
  box-sizing: border-box;
}
.tx-search-input:focus { border-color: var(--gold); }
.tx-search-hint {
  font-size: 13px;
  color: var(--muted);
  margin: -2px 0 10px 2px;
}

.tx-list { display: flex; flex-direction: column; gap: 8px; }
.tx-row {
  display: flex; align-items: center; gap: 14px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px 14px;
}
.tx-icon {
  width: 38px; height: 38px; border-radius: 11px;
  display: flex; align-items: center; justify-content: center;
  font-size: 17px; flex-shrink: 0;
}
.tx-main { flex: 1; min-width: 0; }
.tx-desc { font-weight: 600; font-size: 14px; }
.tx-meta { font-size: 12px; color: var(--muted); }
.tx-amount { font-family: var(--font-display); font-weight: 700; font-size: 14px; white-space: nowrap; }
.tx-amount.income { color: var(--green); }
.tx-amount.expense { color: var(--red); }
.tx-delete {
  background: none; border: none; color: var(--muted); font-size: 15px; padding: 4px;
}
.tx-delete:hover { color: var(--red); }
.empty-state {
  text-align: center; color: var(--muted); font-size: 13px;
  padding: 30px 10px; border: 1px dashed var(--border); border-radius: 14px;
}

#fab {
  position: fixed;
  bottom: calc(28px + env(safe-area-inset-bottom)); right: calc(28px + env(safe-area-inset-right));
  width: 58px; height: 58px;
  border-radius: 50%;
  background: linear-gradient(145deg, var(--gold), var(--gold-dark));
  color: var(--on-accent);
  border: none;
  font-size: 28px;
  font-weight: 400;
  box-shadow: 0 14px 30px -8px var(--gold-glow);
  z-index: 20;
}
#fab:active { transform: scale(0.95); }

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0;
  background: var(--overlay);
  backdrop-filter: blur(4px);
  display: flex; align-items: flex-end;
  justify-content: center;
  z-index: 30;
}
@media (min-width: 640px) {
  .modal-backdrop { align-items: center; }
}
.modal {
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: 22px 22px 0 0;
  width: 100%;
  max-width: 420px;
  padding: 22px 22px 30px;
  max-height: 88vh;
  overflow-y: auto;
}
@media (min-width: 640px) {
  .modal { border-radius: 22px; }
}
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.modal-head h3 { font-family: var(--font-display); font-size: 17px; margin: 0; }
.icon-btn { background: var(--card); border: 1px solid var(--border); color: var(--muted); width: 30px; height: 30px; border-radius: 9px; }

#tx-form, #cat-form { display: flex; flex-direction: column; gap: 14px; }
label { display: flex; flex-direction: column; gap: 6px; font-size: 12px; color: var(--muted); font-weight: 600; }
input, select {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  color: var(--text);
  /* 16px, ikke mindre - under det zoomer Safari paa iPhone inn naar feltet faar fokus */
  font-size: 16px;
  outline: none;
}
input:focus, select:focus { border-color: var(--gold); }

.seg-control { display: flex; background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 4px; }
.seg-btn { flex: 1; background: none; border: none; padding: 10px; border-radius: 9px; color: var(--muted); font-weight: 700; font-size: 13px; }
.seg-btn.active { background: var(--gold); color: var(--on-accent); }

.color-picker { display: flex; flex-wrap: wrap; gap: 10px; margin-top: -4px; }
.color-swatch {
  width: 30px; height: 30px; border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
}
.color-swatch.selected { border-color: #fff; }

.settings-section {
  padding: 16px 0;
  border-bottom: 1px solid var(--border);
}
.settings-section:last-child { border-bottom: none; padding-bottom: 0; }
.settings-section h4 {
  font-family: var(--font-display);
  font-size: 13px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin: 0 0 12px;
}
.small { font-size: 12px; margin: 0 0 14px; }

.inline-form { display: flex; gap: 8px; }
.inline-form input { flex: 1; }

.settings-user-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 14px; }
.settings-user-row {
  display: flex; align-items: center; gap: 10px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 12px;
}
.settings-user-row .member-avatar { width: 28px; height: 28px; font-size: 12px; }
.settings-user-name { font-weight: 600; font-size: 13px; }
.settings-user-username { font-size: 11px; color: var(--muted); }
.settings-user-row .tx-delete { margin-left: auto; }
.admin-badge {
  font-size: 10px; font-weight: 700; color: var(--gold);
  background: var(--gold-dim); padding: 2px 8px; border-radius: 999px;
}

.pref-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.danger-zone form { display: flex; flex-direction: column; gap: 12px; }
.danger-btn {
  background: rgba(255,107,107,0.12);
  color: var(--red);
  border: 1px solid rgba(255,107,107,0.35);
  border-radius: 12px;
  padding: 13px;
  font-weight: 700;
  font-size: 14px;
}

.toast {
  position: fixed;
  bottom: 100px; left: 50%; transform: translateX(-50%);
  background: var(--card-hi);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 13px;
  z-index: 40;
  box-shadow: 0 10px 30px rgba(0,0,0,0.4);
}

@media (max-width: 560px) {
  .topbar {
    padding: 14px 16px;
    padding-top: calc(14px + env(safe-area-inset-top));
    padding-left: calc(16px + env(safe-area-inset-left));
    padding-right: calc(16px + env(safe-area-inset-right));
    flex-wrap: wrap;
  }
  .brand-name { display: none; }
  .content {
    padding: 18px 16px 100px;
    padding-left: calc(16px + env(safe-area-inset-left));
    padding-right: calc(16px + env(safe-area-inset-right));
    padding-bottom: calc(100px + env(safe-area-inset-bottom));
  }
  .balance-value { font-size: 18px; }

  /* Fem faner presses ikke lenger inn i én rad her - de blir da for smale
     til aa treffe med fingeren, og kan skyve seg utenfor skjermen. I
     stedet fordeles de over to rader med jevn bredde, som alltid holder
     seg innenfor skjermbredden uansett hvor mange faner det blir. */
  .app-tabs {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 4px;
    padding: 4px;
  }
  .app-tabs .seg-btn {
    padding: 9px 4px;
    font-size: 12px;
  }
}

/* ---------- Kvitteringer ---------- */
.receipt-block {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
}
.receipt-label {
  font-size: 12px;
  color: var(--muted);
  font-weight: 600;
}
.receipt-actions { display: flex; gap: 8px; }
.receipt-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 11px 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
  text-align: center;
}
.receipt-btn:hover { border-color: var(--gold); }
#receipt-preview-wrap { position: relative; }
#receipt-preview {
  width: 100%;
  max-height: 220px;
  object-fit: contain;
  border-radius: 10px;
  background: var(--bg-0);
  cursor: zoom-in;
  display: block;
}
.receipt-remove {
  position: absolute; top: 8px; right: 8px;
  width: 28px; height: 28px;
  border-radius: 50%;
  background: var(--bar-bg);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 13px;
  line-height: 1;
}
.receipt-status {
  font-size: 12px;
  color: var(--muted);
  margin: 0;
  line-height: 1.45;
}
.receipt-status.hidden { display: none; }

.receipt-progress {
  height: 6px;
  background: var(--track);
  border-radius: 999px;
  overflow: hidden;
  margin-top: 6px;
}
.receipt-progress.hidden { display: none; }
.receipt-progress-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--gold), #d9a13c);
  border-radius: 999px;
  transition: width 0.25s ease;
}

.tx-receipt {
  background: none;
  border: none;
  font-size: 17px;
  padding: 4px 2px;
  opacity: 0.75;
}
.tx-receipt:hover { opacity: 1; }

.receipt-viewer {
  position: relative;
  max-width: 92vw;
  max-height: 92vh;
  display: flex;
  align-items: center;
  justify-content: center;
}
#receipt-full {
  max-width: 92vw;
  max-height: 92vh;
  border-radius: 12px;
  box-shadow: 0 24px 60px rgba(0,0,0,0.6);
}
.receipt-viewer-close {
  position: absolute;
  top: -14px; right: -14px;
  z-index: 2;
  background: var(--card-hi);
}
#receipt-modal { align-items: center; }

/* ---------- Budsjettoppsummering ---------- */
.budget-summary {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  margin-bottom: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.budget-summary-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
}
.budget-summary-label {
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.6px;
  font-weight: 600;
}
.budget-summary-value {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 20px;
}
.budget-summary-row.sub {
  font-size: 12px;
  color: var(--muted);
}
#budget-remaining-label.over { color: var(--red); font-weight: 600; }
.budget-bar {
  height: 7px;
  background: var(--track);
  border-radius: 999px;
  overflow: hidden;
}
.budget-bar-fill {
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--gold), #d9a13c);
  border-radius: 999px;
  transition: width 0.35s ease;
}
.budget-bar-fill.over {
  background: linear-gradient(90deg, #ff8a8a, var(--red));
}

/* ---------- Temavelger ---------- */
.theme-picker {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}
.theme-option {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 7px;
  cursor: pointer;
  font: inherit;
  color: var(--text);
  transition: border-color 0.15s ease;
}
.theme-option:hover { border-color: var(--border-hover); }
.theme-option.selected { border-color: var(--gold); }
.theme-swatch {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid var(--border);
  display: flex;
  align-items: flex-end;
  justify-content: flex-end;
  padding: 4px;
}
.theme-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  display: block;
}
.theme-name {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
}
.theme-option.selected .theme-name { color: var(--text); }

/* Lyse temaer trenger mykere skygger enn de morke */
[data-theme="dagslys"] .balance-card,
[data-theme="sand"] .balance-card {
  box-shadow: 0 14px 30px -22px rgba(20,32,58,0.5);
}
[data-theme="dagslys"] .login-card,
[data-theme="sand"] .login-card {
  box-shadow: 0 20px 45px -25px rgba(20,32,58,0.4);
}

/* ---------- Klikkbare transaksjonsrader ---------- */
.tx-row.clickable {
  cursor: pointer;
  transition: border-color 0.15s ease, transform 0.1s ease;
}
.tx-row.clickable:hover { border-color: var(--border-hover); }
.tx-row.clickable:active { transform: scale(0.99); }
.tx-edit-hint {
  color: var(--muted);
  font-size: 13px;
  opacity: 0;
  transition: opacity 0.15s;
  padding: 4px 2px;
}
.tx-row.clickable:hover .tx-edit-hint { opacity: 1; }

/* ---------- Handleliste ---------- */
.shopping-block { margin-bottom: 32px; }
.shopping-add {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}
.shopping-add input {
  flex: 1;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  color: var(--text);
  font-size: 16px;
  outline: none;
}
.shopping-add input:focus { border-color: var(--gold); }
.shopping-add .pill-btn { padding: 10px 18px; white-space: nowrap; }

.shopping-list { display: flex; flex-direction: column; gap: 8px; }
.shopping-item {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 11px 14px;
  transition: opacity 0.15s ease;
}
.shopping-check {
  width: 26px;
  height: 26px;
  flex-shrink: 0;
  border-radius: 8px;
  border: 2px solid var(--border-hover);
  background: transparent;
  color: var(--on-accent);
  font-size: 14px;
  font-weight: 700;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}
.shopping-check:hover { border-color: var(--gold); }
.shopping-item.done .shopping-check {
  background: var(--gold);
  border-color: var(--gold);
}
.shopping-main { flex: 1; min-width: 0; }
.shopping-text { font-size: 14px; font-weight: 600; word-break: break-word; }
.shopping-item.done .shopping-text {
  text-decoration: line-through;
  color: var(--muted);
  font-weight: 500;
}
.shopping-meta { font-size: 11px; color: var(--muted); margin-top: 2px; }
.shopping-delete {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 14px;
  padding: 4px;
  opacity: 0;
  transition: opacity 0.15s;
}
.shopping-item:hover .shopping-delete { opacity: 1; }
.shopping-delete:hover { color: var(--red); }
.shopping-summary {
  font-size: 12px;
  color: var(--muted);
  text-align: center;
  padding: 8px 0 2px;
}

/* Slett-knappen maa alltid vaere synlig paa touch, der hover ikke finnes */
@media (hover: none) {
  .shopping-delete { opacity: 0.6; }
  .tx-edit-hint, .cat-edit-hint { opacity: 0.6; }
}

/* ---------- Faste poster ---------- */
.recurring-row { cursor: default; }
.recurring-info { flex: 1; min-width: 0; cursor: pointer; }
.recurring-icon {
  width: 28px; height: 28px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; font-weight: 700;
  flex-shrink: 0;
}
.recurring-icon.income { background: rgba(95,211,154,0.16); color: var(--green); }
.recurring-icon.expense { background: rgba(255,107,107,0.16); color: var(--red); }
.recurring-badge {
  color: var(--gold);
  font-weight: 600;
  white-space: nowrap;
}
#recurring-list { margin-bottom: 14px; }
#recurring-list .empty-state { padding: 18px 10px; }

/* ---------- Annonseplass ---------- */
.ad-slot {
  margin: 0 0 28px;
  min-height: 0;
  overflow: hidden;
  border-radius: var(--radius);
}
.ad-slot:empty { display: none; }
#ads-form { display: flex; flex-direction: column; gap: 12px; }
#ads-form .pill-btn { align-self: flex-start; }

.head-actions { display: flex; gap: 8px; align-items: center; }
.link-btn { text-decoration: none; display: inline-block; }

/* ---------- Fanevelger ---------- */
.app-tabs { margin-bottom: 24px; }
.app-tabs .seg-btn { white-space: nowrap; }

/* ---------- Trening ---------- */
.training-block { margin-bottom: 32px; }
.training-controls {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  margin: 4px 0 20px;
}
.training-days-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--muted);
  font-weight: 600;
}
.training-days-label select { padding: 8px 10px; width: auto; }

.training-days { display: flex; flex-direction: column; gap: 14px; margin-bottom: 18px; }
.training-day-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
}
.training-day-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}
.training-day-head .day-name {
  flex: 1;
  /* Uten denne vil input-feltet aldri krympe under sin egen "naturlige"
     bredde, uansett hvor lite flex:1 egentlig gir det - da dytter det
     slette-knappen ut over kortets kant. */
  min-width: 0;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 15px;
}
.exercise-list { display: flex; flex-direction: column; gap: 12px; margin-bottom: 10px; }
.exercise-item { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.exercise-row {
  display: grid;
  grid-template-columns: 1.6fr 55px 80px 1fr 1.2fr 30px;
  gap: 8px;
  align-items: center;
  min-width: 0;
}
/* Grid-/flex-elementer har "min-width: auto" som standard, som for et
   <input> betyr at nettleseren aldri lar det bli smalere enn sin egen
   naturlige minstebredde - selv om kolonnen den star i er langt smalere.
   Resultatet er at senere felt (notat, slette-knapp) dyttes ut over
   kortets bakgrunn. min-width: 0 sier at feltet faktisk skal krympe til
   den bredden grid-en har satt av til det. */
.exercise-row input { padding: 9px 10px; font-size: 14px; min-width: 0; box-sizing: border-box; width: 100%; }
@media (max-width: 640px) {
  .exercise-row { grid-template-columns: 1fr 1fr; }
  .exercise-row .ex-delete { grid-column: 1 / -1; justify-self: end; }
}
.add-exercise-btn { font-size: 13px; padding: 7px 14px; }

/* Sett-telling: kun en visuell hjelp der og da, ingenting lagres */
.exercise-tally {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  padding-left: 2px;
}
.tally-label { font-size: 11px; color: var(--muted); font-weight: 600; margin-right: 2px; }
.tally-dot {
  width: 22px; height: 22px;
  border-radius: 50%;
  border: 1.5px solid var(--border-hover);
  background: transparent;
}
.tally-dot.done {
  background: var(--gold);
  border-color: var(--gold);
}
.tally-reset {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 14px;
  padding: 0 4px;
}
.tally-reset:hover { color: var(--text); }

.training-readonly-note {
  font-size: 13px;
  color: var(--muted);
  margin: -8px 0 16px;
}
.training-day-card.readonly h3 {
  font-family: var(--font-display);
  font-size: 15px;
  margin: 0 0 10px;
}
.exercise-readonly-list { list-style: none; margin: 0; padding: 0; }
.exercise-readonly-list li { padding: 8px 0; border-bottom: 1px solid var(--border); }
.exercise-readonly-list li:last-child { border-bottom: none; }
.ex-readonly-row { display: flex; justify-content: space-between; gap: 12px; font-size: 14px; }
.ex-readonly-name { font-weight: 600; }
.ex-readonly-detail { color: var(--muted); white-space: nowrap; }
.ex-readonly-note { font-size: 12px; color: var(--muted); margin-top: 3px; }

.training-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.training-actions .primary-btn { flex: 1; min-width: 160px; }

/* ---------- Oppskrifter (fane i appen) ----------
   Samme klasser og regler som public/landing.css bruker for den offentlige
   /oppskrifter-siden - selve oppskriftene er felles data
   (public/recipes-data.js), men CSS-en er kopiert hit i stedet for aa laste
   hele landing.css inn i appen, siden den ogsaa har generelle
   markedsføringssideregler (f.eks. en uskalert "main"-selector) som ikke
   bor paavirke resten av appen. */
.recipe-filter {
  display: flex;
  gap: 8px;
  margin-bottom: 28px;
  flex-wrap: wrap;
}
.filter-btn {
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 999px;
  padding: 9px 20px;
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
}
.filter-btn:hover { border-color: var(--border-hover); color: var(--text); }
.filter-btn.active {
  background: var(--gold);
  border-color: var(--gold);
  color: var(--on-accent);
}

.recipe-disclaimer {
  font-size: 13px;
  line-height: 1.6;
  color: var(--muted);
  max-width: 68ch;
  margin: 0 0 24px;
}

.recipe-list { display: flex; flex-direction: column; gap: 20px; margin-bottom: 24px; }
.recipe {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 26px;
}
.recipe-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}
.recipe-head h2 {
  font-family: var(--font-display);
  font-size: 20px;
  margin: 0;
}
.recipe-price {
  font-size: 13px;
  font-weight: 700;
  color: var(--gold);
  background: var(--gold-dim);
  border: 1px solid var(--gold-edge);
  padding: 5px 13px;
  border-radius: 999px;
  white-space: nowrap;
}
.recipe-intro {
  font-size: 15px;
  line-height: 1.65;
  color: var(--muted);
  margin: 0 0 20px;
  max-width: 68ch;
}
.recipe-nutrition-label {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--muted);
  margin: -8px 0 8px;
}
.recipe-nutrition {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  list-style: none;
  margin: 0 0 20px;
  padding: 0;
}
.recipe-nutrition li {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  background: var(--bg-1);
  border: 1px solid var(--border);
  padding: 4px 11px;
  border-radius: 999px;
  white-space: nowrap;
}
.recipe-cols {
  display: grid;
  grid-template-columns: minmax(200px, 1fr) 2fr;
  gap: 26px;
}
.recipe-cols h3 {
  font-family: var(--font-display);
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--muted);
  margin: 0 0 10px;
}
.recipe-cols ul, .recipe-cols ol {
  margin: 0;
  padding-left: 20px;
  font-size: 14px;
  line-height: 1.75;
}
.recipe-cols ul { list-style: none; padding-left: 0; }
.recipe-cols ul li {
  padding: 3px 0;
  border-bottom: 1px solid var(--border);
}
.recipe-cols ul li:last-child { border-bottom: none; }
.recipe-cols ol li { padding-left: 4px; margin-bottom: 6px; }
.recipe-cols ol li::marker { color: var(--gold); font-weight: 700; }

.recipe-swap {
  margin: 20px 0 0;
  padding: 13px 16px;
  background: var(--bg-1);
  border-left: 3px solid var(--gold);
  border-radius: 0 10px 10px 0;
  font-size: 14px;
  line-height: 1.6;
  color: var(--muted);
}
.recipe-swap strong { color: var(--text); }

@media (max-width: 640px) {
  .recipe { padding: 20px; }
  .recipe-cols { grid-template-columns: 1fr; gap: 20px; }
}

.add-to-list-btn {
  margin-top: 14px;
  width: 100%;
  background: var(--gold-dim);
  color: var(--gold);
  border: 1px solid var(--gold-edge);
  border-radius: 10px;
  padding: 11px 14px;
  font-family: var(--font-display);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}
.add-to-list-btn:hover:not(:disabled) {
  background: var(--gold);
  color: var(--on-accent);
}
.add-to-list-btn:disabled { opacity: 0.65; cursor: default; }

/* ---------- Kalender ---------- */
.calendar-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 14px; }
.calendar-day-header {
  font-family: var(--font-display);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--muted);
  margin: 14px 0 2px;
}
.calendar-day-header:first-child { margin-top: 0; }
.calendar-day-header.today { color: var(--gold); }
.event-row.past { opacity: 0.65; }
#toggle-past-events-btn { margin-bottom: 14px; }
