/* Purser — farger og kortform fra ezWallet, men standard web-samhandling.
   Tettere layout, sentrerte modaler, vanlige knapper. */

:root {
  --radius: 12px;
  --gap: 12px;

  --bg: #f2f2f7;
  --card: #ffffff;
  --card-border: rgba(60,60,67,0.10);
  --card-shadow: 0 1px 2px rgba(0,0,0,0.05);
  --shadow-lg: 0 12px 40px rgba(0,0,0,0.18);

  --accent: #007aff;
  --green: #34c759;
  --red: #ff3b30;

  --text: #1c1c1e;
  --secondary: rgba(60,60,67,0.65);
  --tertiary: rgba(60,60,67,0.35);
  --separator: rgba(60,60,67,0.12);
  --track: rgba(60,60,67,0.10);
  --field: #ffffff;
  --hover: rgba(60,60,67,0.05);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #131315;
    --card: #1c1c1e;
    --card-border: rgba(255,255,255,0.08);
    --card-shadow: none;
    --shadow-lg: 0 12px 40px rgba(0,0,0,0.6);

    --accent: #0a84ff;
    --green: #30d158;
    --red: #ff453a;

    --text: #f2f2f7;
    --secondary: rgba(235,235,245,0.62);
    --tertiary: rgba(235,235,245,0.35);
    --separator: rgba(235,235,245,0.12);
    --track: rgba(235,235,245,0.12);
    --field: #2c2c2e;
    --hover: rgba(255,255,255,0.05);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

/* --- Toppmeny --- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  background: var(--card);
  border-bottom: 1px solid var(--separator);
}
.topbar .spacer { flex: 1; }

.brand {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.01em;
  margin-right: 8px;
}

button, .btn {
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: 7px;
  padding: 5px 11px;
  cursor: pointer;
  white-space: nowrap;
}
button:hover { background: var(--hover); }
button:focus-visible, input:focus-visible, select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}
button.primary:hover { filter: brightness(1.08); background: var(--accent); }
button.quiet { border-color: transparent; background: none; color: var(--secondary); }
button.quiet:hover { background: var(--hover); color: var(--text); }
button.danger { color: var(--red); }
button.icon { padding: 5px 8px; }
button[disabled] { opacity: 0.5; cursor: default; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-weight: 600;
}

.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--tertiary); }
.dot.live { background: var(--green); }
.dot.down { background: var(--red); }

/* Pa telefon far ikke alt plass pa en linje -- da brytes den i to. */
@media (max-width: 44rem) {
  .topbar { flex-wrap: wrap; padding: 8px 10px; gap: 6px; }
  .brand { display: none; }
  .topbar .spacer { display: none; }
  #period-chip { flex: 1; justify-content: center; }
  .topbar button { font-size: 12px; padding: 5px 9px; }
}

/* --- Flate --- */

.scroll {
  max-width: 68rem;
  margin: 0 auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: var(--gap);
}

.card {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  box-shadow: var(--card-shadow);
  padding: 12px 14px;
}

/* Budsjetter i rutenett pa brede skjermer */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(19rem, 1fr));
  gap: var(--gap);
}

.section-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 2px 0;
}
.section-head .label {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--secondary);
}
.section-head .spacer { flex: 1; }

/* --- Sammendrag --- */

.summary { display: flex; align-items: center; gap: 24px; flex-wrap: wrap; }
.summary .item { min-width: 8rem; }
.hero-label { font-size: 12px; color: var(--secondary); }
.hero {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}
.hero.pos { color: var(--green); }
.hero.neg { color: var(--red); }

.sub { font-size: 13px; color: var(--secondary); }
.amount { font-variant-numeric: tabular-nums; font-weight: 600; }
.amount.pos { color: var(--green); }
.amount.neg { color: var(--red); }

/* --- Budsjettkort --- */

.card-head { display: flex; align-items: baseline; gap: 8px; margin-bottom: 6px; }
.card-title { font-size: 14px; font-weight: 600; }
.card-head .spacer { flex: 1; }

.track {
  position: relative;
  height: 6px;
  background: var(--track);
  border-radius: 999px;
  margin-top: 8px;
}
.fill { height: 100%; border-radius: 999px; background: var(--accent);
  transition: width 0.4s ease; }
.fill.over { background: var(--red); }
.fill.income { background: var(--green); }
.tide {
  position: absolute; top: -3px; bottom: -3px;
  width: 2px; border-radius: 2px;
  background: var(--text); opacity: 0.35;
}
.foot {
  display: flex; justify-content: space-between; gap: 8px;
  margin-top: 6px; font-size: 12px; color: var(--secondary);
}

/* --- Transaksjonstabell --- */

.day-head {
  font-size: 12px;
  font-weight: 600;
  color: var(--secondary);
  padding: 10px 2px 4px;
}

.tx-card { padding: 0; overflow: hidden; }

.tx {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 12px;
  cursor: pointer;
  border-top: 1px solid var(--separator);
}
.tx:first-child { border-top: none; }
.tx:hover { background: var(--hover); }

.tx-icon {
  width: 24px; height: 24px;
  border-radius: 6px;
  flex: none;
  display: grid; place-items: center;
  color: #fff; font-size: 11px; font-weight: 700;
}

.tx-body { flex: 1; min-width: 0; display: flex; align-items: baseline; gap: 8px; }
.tx-name { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tx-meta { font-size: 12px; color: var(--secondary);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tx-amount { font-size: 14px; font-weight: 600; font-variant-numeric: tabular-nums; }

@media (max-width: 34rem) {
  .tx-body { flex-direction: column; gap: 0; }
}

/* --- Modaler --- */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(0,0,0,0.35);
}
.overlay.open { display: flex; }

.sheet {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 30rem;
  max-height: 86vh;
  overflow-y: auto;
  padding: 0 16px 16px;
}

/* Tittel til venstre, knapper til hoyre -- DOM-rekkefolgen snus med order. */
.sheet-bar {
  position: sticky;
  top: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 14px 0 12px;
  margin-bottom: 4px;
  background: var(--card);
  border-bottom: 1px solid var(--separator);
}
.sheet-bar .title {
  order: -1;
  flex: 1;
  font-size: 15px;
  font-weight: 600;
}
.sheet-bar button { order: 1; }
.sheet-bar button.strong {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}
.sheet-bar button.strong:hover { filter: brightness(1.08); }

/* --- Skjema --- */

.field { margin-bottom: 10px; }
.field label { display: block; font-size: 12px; color: var(--secondary); margin-bottom: 3px; }

input, select {
  width: 100%;
  padding: 6px 9px;
  border: 1px solid var(--card-border);
  border-radius: 7px;
  background: var(--field);
  color: var(--text);
  font: inherit;
  font-size: 14px;
}

.row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.picker {
  max-height: 15rem;
  overflow-y: auto;
  border: 1px solid var(--card-border);
  border-radius: 7px;
  padding: 4px 10px;
  background: var(--field);
}
.group-head {
  font-size: 11px; font-weight: 600; letter-spacing: 0.04em;
  text-transform: uppercase; color: var(--secondary);
  padding: 10px 0 2px;
}
.check { display: flex; align-items: center; gap: 8px; padding: 3px 0; }
.check input { width: auto; accent-color: var(--accent); }
.check label { margin: 0; font-size: 13px; color: var(--text); }

.empty { text-align: center; color: var(--secondary); padding: 20px 12px; font-size: 13px; }
.error { color: var(--red); font-size: 12px; min-height: 1.1em; }

.more { width: 100%; padding: 7px; color: var(--accent); font-weight: 600; }

/* --- Massredigering --- */

.tx-check { flex: none; accent-color: var(--accent); width: auto; margin: 0; }
.tx.picked { background: color-mix(in srgb, var(--accent) 10%, transparent); }

.bulkbar {
  position: sticky;
  top: 52px;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  box-shadow: var(--card-shadow);
}
.bulkbar .count { font-size: 13px; font-weight: 600; }
.bulkbar .spacer { flex: 1; }

/* --- Tokolonners layout pa brede skjermer --- */

.layout { display: flex; flex-direction: column; gap: var(--gap); }
.col { display: flex; flex-direction: column; gap: var(--gap); min-width: 0; }

@media (min-width: 60rem) {
  .scroll { max-width: 80rem; }
  .layout {
    display: grid;
    grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr);
    align-items: start;
  }
  /* Transaksjonene ruller i egen kolonne sa diagrammene blir staende. */
  .col.side {
    position: sticky;
    top: 60px;
    max-height: calc(100vh - 76px);
    overflow-y: auto;
    padding-right: 2px;
  }
}

/* --- Diagrammer --- */

.chart-card { min-height: 12rem; }
.chart-body { display: flex; align-items: center; gap: 20px; flex-wrap: wrap; }
.chart-body.column { display: block; }

.dots { display: inline-flex; gap: 5px; margin-right: 6px; }
.pip {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--tertiary); cursor: pointer;
}
.pip.on { background: var(--accent); }

.legend-list { flex: 1; min-width: 14rem; }
.legend { display: flex; align-items: center; gap: 8px; padding: 5px 0; font-size: 13px; }
.legend + .legend { border-top: 1px solid var(--separator); }
.legend .swatch { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.legend .spacer { flex: 1; }
.legend .pct { color: var(--tertiary); font-variant-numeric: tabular-nums; }

.bar-row { display: flex; align-items: center; gap: 10px; padding: 3px 0; font-size: 13px; }
.bar-label { width: 8rem; flex: none; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap; }
.bar-track { flex: 1; height: 8px; background: var(--track);
  border-radius: 999px; overflow: hidden; }
.bar-fill { display: block; height: 100%; border-radius: 999px; }
.bar-value { width: 6rem; text-align: right; flex: none; }

.trend { display: flex; align-items: flex-end; gap: 4px; height: 9rem; }
.trend-col { display: flex; flex-direction: column; justify-content: flex-end;
  height: 100%; gap: 4px; }
.trend-bars { flex: 1; display: flex; align-items: flex-end;
  justify-content: center; gap: 3px; }
.trend-bar { width: 40%; border-radius: 3px 3px 0 0; min-height: 2px; }
.trend-bar.income { background: var(--green); }
.trend-bar.expense { background: var(--red); }
.trend-label { font-size: 11px; color: var(--secondary); text-align: center;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

@media (max-width: 34rem) {
  .bar-label { width: 5.5rem; }
  .bar-value { width: 4.5rem; }
}

/* --- Palogging --- */

.login {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--bg);
}
.login.open { display: flex; }

.login-card { width: 100%; max-width: 20rem; padding: 20px; }
.login-title {
  font-size: 18px;
  font-weight: 700;
  margin: 0 0 14px;
  letter-spacing: -0.01em;
}

@media (prefers-reduced-motion: reduce) { .fill { transition: none; } }
