/* KontoBlick — theme tokens follow the validated reference palette. */

:root {
  --surface-1: #fcfcfb;
  --page: #f9f9f7;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --grid: #e1e0d9;
  --baseline: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --series-income: #2a78d6;   /* categorical slot: blue  */
  --series-expense: #eb6834;  /* categorical slot: orange */
  --series-mono: #2a78d6;     /* single-measure bars      */
  --delta-good: #006300;
  --delta-bad: #d03b3b;
  --accent: #2a78d6;
  --accent-ink: #ffffff;
}

:root[data-theme="dark"] {
  --surface-1: #1a1a19;
  --page: #0d0d0d;
  --text-primary: #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted: #898781;
  --grid: #2c2c2a;
  --baseline: #383835;
  --border: rgba(255, 255, 255, 0.10);
  --series-income: #3987e5;
  --series-expense: #d95926;
  --series-mono: #3987e5;
  --delta-good: #0ca30c;
  --delta-bad: #e66767;
  --accent: #3987e5;
  --accent-ink: #ffffff;
}

* { box-sizing: border-box; }

/* display rules below would otherwise beat the UA stylesheet's [hidden] */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--page);
  color: var(--text-primary);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.45;
}

.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.brand { font-weight: 700; font-size: 1.25rem; letter-spacing: -0.02em; }
.brand span { color: var(--accent); }
.muted { color: var(--text-secondary); }
.small { font-size: 0.85rem; }
.error { color: var(--delta-bad); }

/* ------------------------------------------------------------ layout */
.topbar {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  padding: 0.7rem 1.2rem;
  background: var(--surface-1);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 5;
}

.nav { display: flex; gap: 0.25rem; flex: 1; flex-wrap: wrap; }
.nav a {
  color: var(--text-secondary);
  text-decoration: none;
  padding: 0.35rem 0.8rem;
  border-radius: 8px;
  font-weight: 500;
}
.nav a:hover { background: var(--page); color: var(--text-primary); }
.nav a.active { background: var(--accent); color: var(--accent-ink); }

.topbar-actions { display: flex; gap: 0.4rem; }

.main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 1.2rem;
  display: flex;
  flex-direction: column;
  gap: 1.2rem;
}
.main section { display: flex; flex-direction: column; gap: 1.2rem; }

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.2rem;
}
@media (max-width: 860px) { .grid-2 { grid-template-columns: 1fr; } }

.card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 1.1rem 1.2rem;
}
.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.6rem;
}
.card-head h2 { margin: 0; font-size: 1.02rem; font-weight: 600; }
.card-tools { display: flex; gap: 0.5rem; align-items: center; }

/* ------------------------------------------------------------- tiles */
.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 1.2rem;
}
.tile { padding: 1rem 1.2rem; }
.tile .label { color: var(--text-secondary); font-size: 0.85rem; }
.tile .value {
  font-size: 1.6rem;
  font-weight: 600;
  margin-top: 0.15rem;
  overflow-wrap: anywhere;
}
.tile.hero .value { font-size: 1.9rem; }
.tile .delta { font-size: 0.85rem; margin-top: 0.15rem; }
.delta.up { color: var(--delta-good); }
.delta.down { color: var(--delta-bad); }

/* ------------------------------------------------------------ charts */
.chart { width: 100%; }
.chart svg { display: block; width: 100%; height: auto; }
.chart .gridline { stroke: var(--grid); stroke-width: 1; }
.chart .baseline { stroke: var(--baseline); stroke-width: 1; }
.chart .tick, .chart .axis-label {
  fill: var(--text-muted);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}
.chart .direct-label { fill: var(--text-secondary); font-size: 11px; }
.chart .bar-income { fill: var(--series-income); }
.chart .bar-expense { fill: var(--series-expense); }
.chart .bar-mono { fill: var(--series-mono); }
.chart .proj-line {
  stroke: var(--series-mono);
  stroke-width: 2;
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.chart .proj-line.assumption { stroke-dasharray: 5 5; }
.chart .marker { fill: var(--series-mono); stroke: var(--surface-1); stroke-width: 2; }

.legend { display: flex; gap: 1rem; margin: 0.2rem 0 0.4rem; flex-wrap: wrap; }
.legend .key {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  color: var(--text-secondary);
  font-size: 0.85rem;
}
.legend .swatch { width: 12px; height: 12px; border-radius: 4px; display: inline-block; }

.tooltip {
  position: fixed;
  pointer-events: none;
  background: var(--surface-1);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.18);
  padding: 0.45rem 0.65rem;
  font-size: 0.85rem;
  z-index: 20;
  max-width: 260px;
}
.tooltip .tt-title { font-weight: 600; margin-bottom: 0.15rem; }
.tooltip .tt-row { display: flex; gap: 0.6rem; justify-content: space-between; }

/* ------------------------------------------------------------ tables */
table.data {
  width: 100%;
  border-collapse: collapse;
  margin-top: 0.6rem;
  font-size: 0.9rem;
}
table.data th, table.data td {
  text-align: right;
  padding: 0.35rem 0.6rem;
  border-bottom: 1px solid var(--grid);
  font-variant-numeric: tabular-nums;
}
table.data th:first-child, table.data td:first-child { text-align: left; }
table.data th { color: var(--text-secondary); font-weight: 600; }

/* ------------------------------------------------------------- forms */
.btn {
  font: inherit;
  border: 1px solid var(--border);
  background: var(--surface-1);
  color: var(--text-primary);
  border-radius: 8px;
  padding: 0.4rem 0.9rem;
  cursor: pointer;
}
.btn:hover { border-color: var(--accent); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn-ghost { border-color: transparent; color: var(--text-secondary); }
.btn-ghost:hover { color: var(--text-primary); }

select, input[type="password"], textarea {
  font: inherit;
  color: var(--text-primary);
  background: var(--page);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.4rem 0.6rem;
}
textarea { resize: vertical; }

/* -------------------------------------------------------------- login */
.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1rem;
}
.login-card {
  width: min(360px, 92vw);
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
}

/* --------------------------------------------------------------- chat */
.chat-card { display: flex; flex-direction: column; gap: 0.8rem; }
.chat-messages {
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
  min-height: 280px;
  max-height: 60vh;
  overflow-y: auto;
  padding: 0.2rem;
}
.msg { max-width: 85%; padding: 0.6rem 0.85rem; border-radius: 12px; white-space: pre-wrap; }
.msg.user { align-self: flex-end; background: var(--accent); color: var(--accent-ink); }
.msg.assistant { align-self: flex-start; background: var(--page); border: 1px solid var(--border); }
.msg.pending { color: var(--text-muted); font-style: italic; }
.msg .tools { margin-top: 0.4rem; display: flex; gap: 0.3rem; flex-wrap: wrap; }
.msg .tool-chip {
  font-size: 0.72rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.05rem 0.5rem;
  color: var(--text-secondary);
  background: var(--surface-1);
}
.chat-input { display: flex; gap: 0.6rem; align-items: flex-end; }
.chat-input textarea { flex: 1; }

/* --------------------------------------------------------------- sync */
.sync-card h3 { margin: 0 0 0.3rem; font-size: 1rem; text-transform: capitalize; }
.phase {
  display: inline-block;
  font-size: 0.78rem;
  border-radius: 999px;
  padding: 0.1rem 0.6rem;
  border: 1px solid var(--border);
  color: var(--text-secondary);
}
.phase.success { color: var(--delta-good); border-color: var(--delta-good); }
.phase.error { color: var(--delta-bad); border-color: var(--delta-bad); }
.phase.busy { color: var(--accent); border-color: var(--accent); }
.banner-2fa {
  background: var(--accent);
  color: var(--accent-ink);
  border-radius: 14px;
  padding: 1rem 1.2rem;
  font-weight: 600;
}
.banner-ok {
  background: var(--delta-good);
  color: #ffffff;
  border-radius: 14px;
  padding: 1rem 1.2rem;
  font-weight: 600;
  margin-bottom: 1rem;
}

.list-row {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.55rem 0;
  border-bottom: 1px solid var(--grid);
}
.list-row:last-child { border-bottom: none; }
.list-row .primary { font-weight: 500; }
.list-row .right { text-align: right; white-space: nowrap; }

/* --------------------------------------- manual entries (Merkposten) */
.manual-form {
  display: grid;
  grid-template-columns: auto 1fr auto 1fr auto;
  gap: 0.5rem;
  margin: 0.75rem 0;
}
.manual-form input, .manual-form select {
  min-width: 0;
}
@media (max-width: 720px) {
  .manual-form { grid-template-columns: 1fr 1fr; }
  .manual-form button { grid-column: 1 / -1; }
}
.kind-badge {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 0.08rem 0.45rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  margin-right: 0.35rem;
  vertical-align: middle;
}
.kind-badge.debt { color: var(--delta-bad); border-color: var(--delta-bad); }
.kind-badge.extra { color: var(--delta-good); border-color: var(--delta-good); }
.manual-right { display: flex; align-items: center; gap: 0.5rem; }
.manual-right .pos { color: var(--delta-good); }
.manual-right .neg { color: var(--delta-bad); }
.manual-actions { display: flex; gap: 0.15rem; }
.btn-small { padding: 0.1rem 0.4rem; font-size: 0.85rem; }
.manual-totals {
  margin-top: 0.6rem;
  padding-top: 0.6rem;
  border-top: 1px solid var(--border);
  color: var(--text-secondary);
  font-size: 0.9rem;
}
