:root {
  --ink: #0B1220;
  --muted: #667085;
  --bg: #EEF1F8;
  --surface: rgba(255,255,255,0.68);
  --surface-solid: #FFFFFF;
  --surface-2: rgba(238,242,249,0.9);
  --border: rgba(11,18,32,0.08);
  --glass-border: rgba(255,255,255,0.7);
  --accent: #2A5BFF;
  --accent-dark: #1B3FCC;
  --accent-soft: #EAF0FF;
  --navy: #0B1224;
  --navy-2: #16204A;
  --success: #16A34A;
  --success-soft: #E7F7ED;
  --amber: #B4740E;
  --amber-soft: #FDF3E0;
  --danger: #D0342C;
  --danger-soft: #FBEAEA;
  --font-display: 'Sora', sans-serif;
  --font-body: 'Inter', sans-serif;
  --font-mono: 'IBM Plex Mono', monospace;
  --radius: 20px;
  --shadow: 0 1px 2px rgba(11,18,32,0.04), 0 14px 34px -18px rgba(11,18,32,0.22);
  --blur: blur(20px) saturate(160%);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4 { font-family: var(--font-display); margin: 0 0 4px; letter-spacing: -0.01em; }
h1 { font-size: 1.55rem; font-weight: 700; }
h2 { font-size: 1.4rem; font-weight: 700; }
h3 { font-size: 1.02rem; font-weight: 700; }
p { margin: 0; }
.muted { color: var(--muted); font-size: 0.9rem; }
.hidden { display: none !important; }
a { color: var(--accent); text-decoration: none; }
button { font-family: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.eyebrow {
  display: block; font-size: 0.72rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.08em; color: var(--accent); margin-bottom: 6px;
}

input, select, textarea {
  font-family: var(--font-body);
  font-size: 0.95rem;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-solid);
  color: var(--ink);
  width: 100%;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
label { display: flex; flex-direction: column; gap: 6px; font-size: 0.85rem; font-weight: 600; margin-bottom: 12px; }
.checkbox-label { flex-direction: row; align-items: center; gap: 8px; font-weight: 500; }
.checkbox-label input { width: auto; }

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: 8px;
  padding: 11px 20px;
  border-radius: 12px;
  border: none;
  font-weight: 700;
  font-size: 0.92rem;
  cursor: pointer;
  transition: transform 0.08s ease, background 0.15s ease, box-shadow 0.15s ease;
}
.btn:active { transform: scale(0.98); }
.btn-primary { background: var(--accent); color: #fff; box-shadow: 0 8px 20px -10px rgba(42,91,255,0.55); }
.btn-primary:hover { background: var(--accent-dark); }
.btn-secondary { background: rgba(11,18,32,0.06); color: var(--ink); }
.btn-secondary:hover { background: rgba(11,18,32,0.1); }
.btn-ghost { background: transparent; color: var(--muted); }
.btn-ghost:hover { color: var(--ink); }
.btn-block { width: 100%; }
.btn-link { background: none; border: none; color: var(--accent); font-size: 0.85rem; font-weight: 600; cursor: pointer; padding: 0; }

.error { color: var(--danger); font-size: 0.85rem; min-height: 1.1em; }
.success { color: var(--success); font-size: 0.85rem; }
.badge {
  display: inline-block; font-size: 0.72rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.03em; background: var(--accent-soft); color: var(--accent-dark); padding: 3px 9px; border-radius: 100px;
}

/* ---------- Decorative gradient backdrop (visible through glass) ---------- */
.bg-decor {
  position: fixed; inset: 0; z-index: -1; pointer-events: none;
  background:
    radial-gradient(60% 45% at 12% 8%, rgba(42,91,255,0.16) 0%, transparent 60%),
    radial-gradient(55% 40% at 90% 18%, rgba(22,32,74,0.12) 0%, transparent 60%),
    radial-gradient(50% 40% at 50% 95%, rgba(42,91,255,0.10) 0%, transparent 60%);
}
.auth-view .bg-decor,
.auth-view {
  background:
    radial-gradient(60% 50% at 15% 10%, rgba(42,91,255,0.14) 0%, transparent 60%),
    radial-gradient(55% 45% at 85% 90%, rgba(22,32,74,0.12) 0%, transparent 60%),
    var(--bg);
}

/* ---------- Glass surface (cards, forms, modal) ---------- */
.card, .receipt-form, .dash-card, .dash-breakdown, .auth-card, .modal, .receipt-stub {
  background: var(--surface);
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
  border: 1px solid var(--glass-border);
  box-shadow: var(--shadow);
}

/* ---------- Auth ---------- */
.auth-view {
  min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px;
}
.auth-card {
  width: 100%; max-width: 380px; border-radius: 24px;
  padding: 36px 30px;
}
.brand { text-align: center; margin-bottom: 26px; }
.brand-mark {
  width: 50px; height: 50px; margin: 0 auto 14px; border-radius: 14px;
  background: linear-gradient(145deg, var(--accent), var(--navy-2)); color: #fff; font-family: var(--font-display); font-weight: 800;
  display: flex; align-items: center; justify-content: center; font-size: 1.35rem;
  box-shadow: 0 10px 24px -10px rgba(42,91,255,0.5);
}

/* ---------- App shell ---------- */
.app-shell { display: none; min-height: 100vh; }
.app-shell.active { display: block; position: relative; }

.main-content { width: 100%; padding: 28px 16px 120px; max-width: 760px; margin: 0 auto; }

.page-header { margin-bottom: 22px; }

/* ---------- Topbar (Brand + Haushalt-Switcher) ---------- */
.topbar {
  position: sticky; top: 0; z-index: 25;
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px;
  background: rgba(238,241,248,0.7);
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
  border-bottom: 1px solid rgba(11,18,32,0.06);
}
.topbar-brand { display: flex; align-items: center; gap: 8px; font-family: var(--font-display); font-weight: 700; font-size: 0.92rem; }
.brand-mark-sm { width: 26px; height: 26px; font-size: 0.8rem; border-radius: 8px; }
.household-switcher {
  display: flex; align-items: center; gap: 6px;
  background: rgba(255,255,255,0.7); border: 1px solid rgba(11,18,32,0.08);
  border-radius: 100px; padding: 6px 12px; font-size: 0.82rem; font-weight: 600; color: var(--accent-dark);
  max-width: 60vw;
}
.household-icon { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 2; flex-shrink: 0; }
#household-name-display { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#household-switcher {
  border: none; background: transparent; padding: 0; font-size: 0.82rem; font-weight: 600; color: var(--accent-dark);
  width: auto; max-width: 40vw;
}
#household-switcher:focus { box-shadow: none; }

/* ---------- Dock navigation (mobile + desktop) ---------- */
.dock {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  display: flex; gap: 2px; padding: 7px;
  background: rgba(255,255,255,0.55);
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
  border: 1px solid rgba(255,255,255,0.75);
  border-radius: 100px;
  box-shadow: 0 10px 36px -10px rgba(11,18,32,0.28), inset 0 1px 0 rgba(255,255,255,0.85);
  z-index: 30;
  max-width: calc(100vw - 24px);
}
.dock-link {
  position: relative;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 9px 16px 11px; border-radius: 100px; color: var(--muted); font-size: 0.66rem; font-weight: 600;
  transition: background 0.15s ease, color 0.15s ease;
}
.dock-link:hover { background: rgba(11,18,32,0.05); color: var(--ink); }
.dock-link.active { color: var(--accent); }
.dock-link svg { width: 21px; height: 21px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.dock-dot { display: block; width: 4px; height: 4px; border-radius: 50%; background: var(--accent); margin-top: 2px; opacity: 0; transition: opacity 0.15s ease; }
.dock-link.active .dock-dot { opacity: 1; }

/* ---------- Scan view ---------- */
.capture-zone { display: flex; gap: 12px; flex-wrap: wrap; }
.capture-btn {
  flex: 1; min-width: 140px; display: flex; flex-direction: column; align-items: center; gap: 8px;
  padding: 30px 16px; border: 1.5px dashed rgba(11,18,32,0.18); border-radius: var(--radius);
  background: var(--surface); backdrop-filter: var(--blur); -webkit-backdrop-filter: var(--blur);
  cursor: pointer; color: var(--accent-dark); font-weight: 700; font-size: 0.9rem;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.capture-btn:hover { border-color: var(--accent); background: var(--accent-soft); }
.capture-btn svg { width: 28px; height: 28px; fill: none; stroke: currentColor; stroke-width: 1.6; }
.capture-btn-secondary { color: var(--muted); }

.scan-preview { margin-top: 16px; position: relative; border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.scan-preview img { width: 100%; display: block; max-height: 360px; object-fit: cover; }
.ocr-progress {
  position: absolute; inset: 0; background: rgba(11,18,32,0.78); color: #fff;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; font-size: 0.85rem;
}
.spinner { width: 28px; height: 28px; border: 3px solid rgba(255,255,255,0.3); border-top-color: #fff; border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.receipt-form { margin-top: 16px; border-radius: var(--radius); padding: 22px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.raw-text-details { margin-bottom: 16px; }
.raw-text-details summary { cursor: pointer; font-size: 0.85rem; color: var(--muted); font-weight: 600; }
.raw-text-details pre { font-family: var(--font-mono); font-size: 0.75rem; white-space: pre-wrap; color: var(--muted); background: rgba(11,18,32,0.05); padding: 10px; border-radius: 8px; margin-top: 8px; max-height: 140px; overflow-y: auto; }
.form-actions { display: flex; gap: 10px; justify-content: flex-end; }
.field-hint { color: var(--amber); font-size: 0.75rem; font-weight: 600; margin-top: 2px; }

/* ---------- List view ---------- */
.filter-bar { margin-bottom: 20px; display: flex; flex-direction: column; gap: 10px; }
.filter-row { display: flex; gap: 10px; flex-wrap: wrap; }
.filter-field { flex: 1; min-width: 130px; font-size: 0.75rem; }
#filter-category { flex: 1; min-width: 150px; }

.receipt-list { display: flex; flex-direction: column; gap: 10px; }

.receipt-stub {
  position: relative;
  border-radius: 16px;
  padding: 14px 18px 14px 20px;
  cursor: pointer;
  border-left: 4px solid var(--accent);
  display: flex; justify-content: space-between; align-items: flex-start; gap: 12px;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}
.receipt-stub:hover { transform: translateY(-2px); }
.stub-main { min-width: 0; }
.stub-merchant { font-weight: 700; font-size: 0.98rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stub-meta { font-size: 0.8rem; color: var(--muted); margin-top: 2px; }
.stub-amount { font-family: var(--font-mono); font-weight: 700; font-size: 1.05rem; white-space: nowrap; }
.stub-category { display: inline-block; font-size: 0.68rem; font-weight: 600; color: var(--accent-dark); background: var(--accent-soft); padding: 2px 8px; border-radius: 100px; margin-top: 6px; }

.empty-state { text-align: center; padding: 60px 20px; color: var(--muted); display: flex; flex-direction: column; align-items: center; gap: 14px; }

/* ---------- Avatars ---------- */
.avatar {
  width: 22px; height: 22px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center;
  font-size: 0.68rem; font-weight: 700; color: #fff; flex-shrink: 0;
}
.avatar-lg { width: 34px; height: 34px; font-size: 0.9rem; }
.stub-attribution { display: flex; align-items: center; gap: 6px; margin-top: 8px; }

/* ---------- Dashboard ---------- */
.dashboard { display: flex; flex-direction: column; gap: 14px; margin-bottom: 22px; }
.dashboard-cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.dash-card { border-radius: 16px; padding: 16px 18px; }
.dash-card .dash-value { font-family: var(--font-display); font-weight: 800; font-size: 1.35rem; letter-spacing: -0.01em; }
.dash-card .dash-label { font-size: 0.72rem; color: var(--muted); margin-top: 4px; font-weight: 500; }
.dash-breakdown { border-radius: 16px; padding: 16px 18px; }
.dash-breakdown h4 { margin: 0 0 12px; font-family: var(--font-display); font-size: 0.82rem; font-weight: 700; }
.dash-row { display: flex; align-items: center; gap: 10px; margin-bottom: 9px; font-size: 0.8rem; }
.dash-row:last-child { margin-bottom: 0; }
.dash-row-label { width: 92px; flex-shrink: 0; color: var(--ink); font-weight: 500; }
.dash-bar-track { flex: 1; height: 7px; background: rgba(11,18,32,0.08); border-radius: 100px; overflow: hidden; }
.dash-bar-fill { height: 100%; background: var(--accent); border-radius: 100px; }
.dash-row-value { font-family: var(--font-mono); width: 64px; text-align: right; flex-shrink: 0; }

@media (max-width: 480px) {
  .dashboard-cards { grid-template-columns: 1fr 1fr; }
  .dashboard-cards .dash-card:last-child { grid-column: 1 / -1; }
}

/* ---------- Cards / lists (Settings, Admin) ---------- */
.card { border-radius: var(--radius); padding: 22px; margin-bottom: 16px; }
.card h3 { margin-bottom: 14px; }
.card form { margin-top: 14px; }
.inline-form { display: flex; gap: 10px; margin-top: 14px; }
.inline-form input { flex: 1; }

.member-list, .admin-list { display: flex; flex-direction: column; gap: 10px; margin-top: 14px; }
.member-row, .admin-row {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 10px 0; border-bottom: 1px solid var(--border); font-size: 0.88rem;
}
.member-row:last-child, .admin-row:last-child { border-bottom: none; }
.member-row .member-name, .admin-row-name { font-weight: 700; }
.member-row .member-role, .admin-row-meta { color: var(--muted); font-size: 0.76rem; }
.admin-row-left { display: flex; align-items: center; gap: 10px; min-width: 0; }
.admin-row-actions { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.admin-row-actions select { width: auto; padding: 6px 8px; font-size: 0.8rem; }
.admin-row-user { align-items: flex-start; }
.admin-row-user .admin-row-left { align-items: flex-start; }
.hh-badges { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.hh-badge {
  display: inline-flex; align-items: center; gap: 6px; font-size: 0.72rem; font-weight: 600;
  background: var(--accent-soft); color: var(--accent-dark); padding: 3px 6px 3px 10px; border-radius: 100px;
}
.hh-badge-remove {
  background: rgba(11,18,32,0.1); border: none; width: 16px; height: 16px; border-radius: 50%;
  color: var(--accent-dark); font-size: 0.75rem; line-height: 1; cursor: pointer; padding: 0;
}
.hh-add-row { display: flex; gap: 8px; margin-top: 8px; align-items: center; }
.hh-add-row select { width: auto; padding: 5px 8px; font-size: 0.78rem; }

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(11,18,32,0.45); z-index: 50;
  display: flex; align-items: flex-end; justify-content: center;
}
.modal {
  border-radius: 22px 22px 0 0; width: 100%; max-width: 560px;
  max-height: 88vh; overflow-y: auto; padding: 24px; position: relative;
}
.modal-close { position: absolute; top: 16px; right: 16px; background: rgba(11,18,32,0.08); border: none; width: 32px; height: 32px; border-radius: 50%; font-size: 1.1rem; cursor: pointer; color: var(--muted); }
.modal img { width: 100%; border-radius: 12px; margin-bottom: 16px; }

.toast {
  position: fixed; bottom: 92px; left: 50%; transform: translateX(-50%);
  background: var(--navy); color: #fff; padding: 10px 20px; border-radius: 100px;
  font-size: 0.85rem; font-weight: 600; z-index: 60; box-shadow: var(--shadow);
}

@media (min-width: 860px) {
  .main-content { padding: 48px 24px 130px; max-width: 820px; }
  .modal-overlay { align-items: center; }
  .modal { border-radius: 22px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

@supports not (backdrop-filter: blur(1px)) {
  .card, .receipt-form, .dash-card, .dash-breakdown, .auth-card, .modal, .receipt-stub, .dock {
    background: var(--surface-solid);
  }
}
