:root {
  --bg: #0a0e14;
  --surface: #121a24;
  --surface-2: #182230;
  --border: rgba(100, 140, 180, 0.2);
  --text: #e6edf5;
  --muted: #8b9cb0;
  --accent: #3d9eff;
  --accent-2: #00c896;
  --danger: #ff6b6b;
  --radius: 10px;
  --font: "Segoe UI", system-ui, sans-serif;
  --sidebar-w: 240px;
}

* { box-sizing: border-box; }
.lr-live-banner {
  position: sticky;
  top: 0;
  z-index: 9999;
  margin: 0;
  padding: 0.65rem 1rem;
  text-align: center;
  font-weight: 700;
  font-size: 0.95rem;
  color: #041018;
  background: linear-gradient(90deg, #00c896, #3dffa8);
  border-bottom: 2px solid #00ffaa;
  box-shadow: 0 4px 20px rgba(0, 200, 150, 0.45);
}
.lr-live-banner a { color: #003322; text-decoration: underline; }

.lr-toast {
  position: fixed;
  left: 50%;
  bottom: calc(4.5rem + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  z-index: 10000;
  max-width: min(92vw, 520px);
  padding: 0.75rem 1rem;
  border-radius: 10px;
  background: #1a3d2e;
  color: #b8ffd8;
  border: 1px solid var(--accent-2);
  font-size: 0.88rem;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
}
.lr-toast.err {
  background: #3d1a1a;
  color: #ffc8c8;
  border-color: var(--danger);
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  background: radial-gradient(1000px 500px at 0% 0%, #152238 0%, var(--bg) 50%);
  color: var(--text);
  font-size: 15px;
  line-height: 1.45;
}

.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  border-right: 1px solid var(--border);
  background: rgba(10, 14, 20, 0.95);
  padding: 1rem 0.85rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.brand { display: flex; align-items: center; gap: 0.75rem; padding: 0 0.25rem; }
.brand-mark {
  width: 40px; height: 40px; border-radius: 10px;
  display: grid; place-items: center; font-weight: 700;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #041018;
}
.brand h1 { margin: 0; font-size: 1.05rem; font-weight: 600; }
.tagline { margin: 0.1rem 0 0; color: var(--muted); font-size: 0.72rem; }

.side-nav { display: flex; flex-direction: column; gap: 0.25rem; }
.nav-item {
  text-align: left; border: none; background: transparent;
  color: var(--muted); padding: 0.55rem 0.75rem; border-radius: 8px;
  cursor: pointer; font-size: 0.9rem;
}
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active {
  background: rgba(61, 158, 255, 0.12);
  color: #b8dcff;
  font-weight: 500;
}

.status-panel { margin-top: auto; padding: 0.75rem !important; }
.status-panel h3 { margin: 0 0 0.5rem; font-size: 0.78rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }
.status-panel dl { margin: 0; font-size: 0.8rem; }
.status-panel dt { color: var(--muted); margin-top: 0.35rem; }
.status-panel dd { margin: 0.1rem 0 0; }
.mono { font-family: ui-monospace, monospace; font-size: 0.7rem; word-break: break-all; }

.main-col { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar {
  display: flex; align-items: end; justify-content: space-between;
  padding: 0.85rem 1.25rem; border-bottom: 1px solid var(--border);
}
.month-bar { display: flex; align-items: end; gap: 0.5rem; }
.container { flex: 1; padding: 1rem 1.25rem 2rem; max-width: 1200px; }
.view[hidden] { display: none !important; }

label { display: flex; flex-direction: column; gap: 0.25rem; font-size: 0.8rem; color: var(--muted); }
input, select {
  background: var(--surface-2); border: 1px solid var(--border);
  color: var(--text); border-radius: 8px; padding: 0.45rem 0.6rem; font-size: 0.92rem;
}
input:focus, select:focus { outline: 2px solid rgba(61, 158, 255, 0.4); border-color: var(--accent); }

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 0.75rem;
  margin-bottom: 1rem;
}
.card, .panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.9rem 1rem;
}
.card h2, .panel h2 { margin: 0 0 0.5rem; font-size: 0.82rem; color: var(--muted); font-weight: 500; }
.metric { margin: 0; font-size: 1.5rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.card.inntekt .metric, .card:not(.utgift):not(.netto):first-child .metric { color: var(--accent-2); }
.card.utgift .metric { color: var(--danger); }
.card.netto .metric { color: #ffd166; }

.dash-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.85rem;
}
.dash-grid .span-2 { grid-column: 1 / -1; }
.chart-panel canvas { width: 100%; max-height: 160px; }

.quick-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.recent-list, .simple-list { list-style: none; margin: 0; padding: 0; }
.recent-list li, .simple-list li {
  padding: 0.45rem 0; border-bottom: 1px solid var(--border);
  font-size: 0.88rem;
}
.recent-list a { color: var(--accent); cursor: pointer; text-decoration: none; }
.recent-list a:hover { text-decoration: underline; }

table.compact { width: 100%; font-size: 0.88rem; }
table.compact th, table.compact td { padding: 0.4rem 0.35rem; border-bottom: 1px solid var(--border); }

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 8px; padding: 0.45rem 0.85rem; font-size: 0.88rem;
  text-decoration: none; cursor: pointer; border: 1px solid var(--border);
  color: var(--text); background: var(--surface-2);
}
.btn.primary { background: linear-gradient(135deg, #2d7fd4, var(--accent)); border-color: transparent; color: #fff; font-weight: 600; }
.btn.secondary { border-color: rgba(0, 200, 150, 0.35); color: #9ef0d4; }
.btn.danger { border-color: rgba(255, 107, 107, 0.5); color: #ffb0b0; }
.btn.ghost { background: transparent; }
.btn.sm { padding: 0.25rem 0.5rem; font-size: 0.78rem; }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; }
.span-2 { grid-column: 1 / -1; }
.form-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: 0.75rem; }
.form-msg { margin-top: 0.5rem; font-size: 0.88rem; }
.form-msg.ok { color: var(--accent-2); }
.form-msg.err { color: var(--danger); }
.hint { color: var(--muted); font-size: 0.85rem; }

.filters { display: flex; flex-wrap: wrap; align-items: end; gap: 0.75rem; margin-bottom: 0.75rem; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
th, td { padding: 0.5rem 0.4rem; border-bottom: 1px solid var(--border); text-align: left; }
th { color: var(--muted); font-weight: 500; font-size: 0.75rem; text-transform: uppercase; cursor: pointer; }
th[data-sort] { user-select: none; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tfoot td { font-weight: 600; border-top: 2px solid var(--border); }
.type-inntekt { color: var(--accent-2); }
.type-utgift { color: var(--danger); }
.muted { color: var(--muted); }

.ai-box { margin-top: 1rem; padding: 1rem; border: 1px dashed var(--accent); border-radius: var(--radius); }
.ai-badge { display: inline-block; background: rgba(61, 158, 255, 0.2); color: #b8dcff; padding: 0.2rem 0.5rem; border-radius: 4px; font-size: 0.75rem; margin: 0 0 0.5rem; }

.footer {
  display: flex; justify-content: space-between; padding: 0.6rem 1.25rem;
  border-top: 1px solid var(--border); color: var(--muted); font-size: 0.75rem;
}
#health-badge.ok { color: var(--accent-2); }
#health-badge.err { color: var(--danger); }

.pin-overlay {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(0, 0, 0, 0.85);
  display: grid; place-items: center;
}
.pin-card { max-width: 320px; width: 90%; text-align: center; }
.pin-card input { font-size: 1.5rem; letter-spacing: 0.3em; text-align: center; width: 100%; margin: 0.75rem 0; }

.modal {
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); color: var(--text);
  max-width: 520px; width: 95%; padding: 0;
}
.modal::backdrop { background: rgba(0, 0, 0, 0.6); }

.nav-toggle { display: none; min-height: 44px; min-width: 44px; }

.bottom-nav { display: none; }

.form-msg.warn { color: #f0c040; background: rgba(240, 192, 64, 0.12); padding: 0.5rem 0.75rem; border-radius: 8px; }

.receipt-thumb {
  width: 48px; height: 48px; object-fit: cover; border-radius: 6px;
  border: 1px solid var(--border); vertical-align: middle;
}

@media (max-width: 900px) {
  body { padding-bottom: calc(64px + env(safe-area-inset-bottom, 0)); }
  .app-shell { flex-direction: column; }
  .nav-toggle { display: inline-flex; }
  .sidebar {
    width: 100%;
    flex-direction: column;
    max-height: 0;
    overflow: hidden;
    padding-top: 0;
    padding-bottom: 0;
    transition: max-height 0.25s ease;
    pointer-events: none;
    visibility: hidden;
  }
  .app-shell.nav-open .sidebar {
    max-height: 520px;
    padding-top: 1rem;
    padding-bottom: 1rem;
    pointer-events: auto;
    visibility: visible;
    position: relative;
    z-index: 200;
  }
  .side-nav { flex-direction: column; }
  .nav-item { min-height: 44px; font-size: 1rem; }
  .btn, input, select { min-height: 44px; }
  .topbar { flex-wrap: wrap; gap: 0.5rem; padding-left: max(1rem, env(safe-area-inset-left)); }
  .container { padding-left: max(1rem, env(safe-area-inset-left)); padding-right: max(1rem, env(safe-area-inset-right)); }
  .status-panel { display: none; }
  .dash-grid { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .span-2 { grid-column: auto; }
  .cards { grid-template-columns: 1fr 1fr; }
  table { font-size: 0.82rem; }
  .bottom-nav {
    display: flex;
    position: fixed;
    left: 0; right: 0; bottom: 0;
    z-index: 100;
    background: rgba(10, 14, 20, 0.96);
    border-top: 1px solid var(--border);
    padding: 0.35rem 0.25rem calc(0.35rem + env(safe-area-inset-bottom, 0));
    justify-content: space-around;
    gap: 0.15rem;
  }
  .bottom-nav-item {
    flex: 1;
    min-height: 48px;
    border: none;
    background: transparent;
    color: var(--muted);
    font-size: 0.72rem;
    border-radius: 8px;
    cursor: pointer;
  }
  .bottom-nav-item.active {
    color: var(--accent);
    background: rgba(61, 158, 255, 0.1);
  }
}

.load-error-banner {
  margin: 0 0 1rem;
  padding: 0.75rem 1rem;
  border-radius: 8px;
  background: rgba(255, 107, 107, 0.15);
  border: 1px solid rgba(255, 107, 107, 0.45);
  color: #ffb4b4;
  font-size: 0.92rem;
}
.mer-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(9.5rem, 1fr));
  gap: 0.5rem;
  margin-top: 0.75rem;
}
.mer-grid .btn { width: 100%; min-height: 44px; }

.tg-mini-stats, .tg-status-dl {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.25rem 0.75rem;
  font-size: 0.88rem;
  margin: 0.5rem 0 0.75rem;
}
.tg-mini-stats dt, .tg-status-dl dt { color: var(--muted); margin: 0; }
.tg-mini-stats dd, .tg-status-dl dd { margin: 0; }
.telegram-teaser { border-color: rgba(61, 158, 255, 0.35); }
.roadmap { display: flex; flex-direction: column; gap: 0.75rem; }
.roadmap-sprint h3 { margin: 0 0 0.35rem; font-size: 0.95rem; }
.roadmap-sprint.roadmap-live h3 { color: var(--accent-2); }
.roadmap-check { display: inline-block; width: 1.1rem; }
.roadmap-live .roadmap-check { color: var(--accent-2); }
.roadmap-planned { color: var(--muted); }

.badge-dup {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 0.12rem 0.45rem;
  border-radius: 999px;
  background: rgba(255, 107, 107, 0.2);
  color: #ff8a8a;
  border: 1px solid rgba(255, 107, 107, 0.45);
  margin-left: 0.35rem;
  vertical-align: middle;
}
.dup-detail {
  margin: 0.35rem 0 0.5rem;
  padding: 0.45rem 0.6rem;
  font-size: 0.82rem;
  background: rgba(255, 107, 107, 0.06);
  border-left: 3px solid rgba(255, 107, 107, 0.5);
  border-radius: 0 var(--radius) var(--radius) 0;
}
.receipt-inbox-item.duplicate-flag { border-color: rgba(255, 107, 107, 0.35); }

.subhead { margin: 1.25rem 0 0.5rem; font-size: 0.95rem; color: var(--muted); }
.bank-match-list { list-style: none; padding: 0; margin: 1rem 0 0; display: flex; flex-direction: column; gap: 0.5rem; }
.bank-match-item {
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 0.65rem 0.85rem;
  background: var(--surface-2);
}
.bank-match-item.match-matched { border-color: rgba(0, 200, 150, 0.45); background: rgba(0, 200, 150, 0.08); }
.bank-match-item.match-suggested { border-color: rgba(240, 192, 64, 0.45); background: rgba(240, 192, 64, 0.08); }
.bank-match-item.match-unmatched { border-color: rgba(255, 107, 107, 0.35); background: rgba(255, 107, 107, 0.06); }
.bank-match-meta { font-size: 0.82rem; color: var(--muted); margin-top: 0.25rem; }
.bank-match-actions { margin-top: 0.5rem; display: flex; flex-wrap: wrap; gap: 0.35rem; }
.bank-match-item.match-ignored { opacity: 0.65; border-style: dashed; }
.bank-summary { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 0.5rem; margin: 0.75rem 0; }
.bank-summary div { padding: 0.5rem 0.65rem; background: var(--surface-2); border-radius: var(--radius); border: 1px solid var(--border); }
.bank-summary strong { display: block; font-size: 1.1rem; margin-top: 0.15rem; }
.bank-filters { margin-bottom: 0.5rem; }
.bank-import-row { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; }
.bank-tabs { display: flex; flex-wrap: wrap; gap: 0.35rem; margin: 0.75rem 0 0.5rem; }
.bank-tab { padding: 0.35rem 0.75rem; border-radius: 999px; border: 1px solid var(--border); background: var(--surface-2); color: var(--text); cursor: pointer; font-size: 0.85rem; }
.bank-tab.active { background: var(--accent); border-color: var(--accent); color: #fff; }
