:root {
  --bg: #f5f6f8; --panel: #ffffff; --text: #1d2433; --muted: #5f6b7d; --line: #e2e5ea;
  --accent: #2357c9; --accent-soft: #e8eefb; --good: #18794e; --good-soft: #e3f4ea;
  --bad: #b42318; --bad-soft: #fdecea; --warn: #9a6200; --warn-soft: #fdf3dc;
  --side: #1d2433; --side-text: #c9d0dc; --income: #2f6fdf; --cost: #c2cad6;
  color-scheme: light;
}
/* Mörkt läge: automatiskt efter datorns inställning, om inte data-theme anger ljust eller mörkt */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12151b; --panel: #1b1f27; --text: #e6e9ef; --muted: #9aa4b4; --line: #2c323d;
    --accent: #7aa2ff; --accent-soft: #233154; --good: #5fd39a; --good-soft: #17352a;
    --bad: #ff8a80; --bad-soft: #3d1f1d; --warn: #f2c063; --warn-soft: #3a2f16;
    --side: #0d1015; --side-text: #aeb7c6; --income: #7aa2ff; --cost: #4a5363;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
    --bg: #12151b; --panel: #1b1f27; --text: #e6e9ef; --muted: #9aa4b4; --line: #2c323d;
    --accent: #7aa2ff; --accent-soft: #233154; --good: #5fd39a; --good-soft: #17352a;
    --bad: #ff8a80; --bad-soft: #3d1f1d; --warn: #f2c063; --warn-soft: #3a2f16;
    --side: #0d1015; --side-text: #aeb7c6; --income: #7aa2ff; --cost: #4a5363;
    color-scheme: dark;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; font: 14px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif; background: var(--bg); color: var(--text); display: flex; min-height: 100vh; }
a { color: var(--accent); }

.sidebar { color-scheme: dark; scrollbar-width: thin; width: 230px; flex: none; background: var(--side); color: var(--side-text); display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; gap: 10px; align-items: center; padding: 18px 16px; color: #fff; }
.brand small { display: block; color: var(--side-text); font-size: 12px; }
.sidebar nav { display: flex; flex-direction: column; padding: 0 8px; overflow-y: auto; }
.sidebar nav a { color: var(--side-text); text-decoration: none; padding: 7px 10px; border-radius: 6px; }
.sidebar nav a:hover { background: rgba(255,255,255,.06); color: #fff; }
.sidebar nav a.active { background: rgba(255,255,255,.12); color: #fff; font-weight: 600; }
.nav-title { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; margin: 14px 10px 4px; opacity: .6; }
.brand { text-decoration: none; }
.year-picker { padding: 0 16px 12px; display: flex; flex-direction: column; gap: 3px; }
.year-picker label { color: var(--side-text); font-size: 11px; text-transform: uppercase; letter-spacing: .06em; opacity: .7; }
.year-picker select { background: rgba(255,255,255,.08); color: #fff; border-color: rgba(255,255,255,.15); }
.year-picker select option { color: #1d2433; background: #fff; }
.step { display: flex; gap: 14px; padding: 14px 0; border-bottom: 1px solid var(--line); }
.step:last-child { border-bottom: none; }
.step-mark { flex: none; width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; background: var(--warn-soft); color: var(--warn); }
.step.done .step-mark { background: var(--good-soft); color: var(--good); }
.step-body { flex: 1; min-width: 0; }
.step-body h3 { margin: 2px 0 6px; font-size: 15px; }
.step-body p { margin: 4px 0; }
.brand:hover small { color: #fff; }
.sidebar-foot { margin-top: auto; padding: 12px 16px; font-size: 12px; border-top: 1px solid rgba(255,255,255,.08); display: flex; flex-direction: column; gap: 6px; }
.sidebar-foot a { color: var(--side-text); }
.sidebar-foot a:hover { color: #fff; }
.user-row { display: flex; flex-direction: column; gap: 2px; }
.user-row #user-name { color: #fff; font-weight: 600; }

body.auth .sidebar { display: none; }
body.auth main { display: flex; justify-content: center; padding-top: 8vh; }
.auth-card { width: 100%; max-width: 420px; }
.auth-card.wide { max-width: 760px; }
.auth-card h1 { margin-bottom: 4px; }
.auth-card form label { margin-bottom: 10px; }
.auth-card input { width: 100%; }
.checks { display: flex; flex-wrap: wrap; gap: 6px 16px; }
.checks label { flex-direction: row; align-items: center; gap: 6px; color: var(--text); font-size: 14px; }
label.inline { flex-direction: row; align-items: center; gap: 6px; color: var(--text); font-size: 14px; }
.item-list .item { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.item-list .item:last-child { border-bottom: none; }
.item .sub { margin: 0; }

main { flex: 1; min-width: 0; padding: 28px 32px 64px; outline: none; }
h1 { font-size: 22px; margin: 0 0 4px; }
h2 { font-size: 16px; margin: 0 0 12px; }
.sub { color: var(--muted); margin: 0 0 20px; }
.head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; margin-bottom: 8px; }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 18px; margin-bottom: 18px; }
.grid { display: grid; gap: 16px; }
.kpis { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); margin-bottom: 18px; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; }
.kpi > span { color: var(--muted); font-size: 12px; }
.kpi b { display: block; font-size: 22px; font-variant-numeric: tabular-nums; margin-top: 2px; }
.kpi small { color: var(--muted); }
.two { grid-template-columns: repeat(auto-fit, minmax(360px, 1fr)); }

.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; }
th, td { padding: 7px 8px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { font-size: 12px; color: var(--muted); font-weight: 600; white-space: nowrap; }
td.n, th.n { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--accent-soft); }
tr.detail td { background: var(--bg); }
tr.group td { font-weight: 600; background: var(--bg); }
tr.sum td { font-weight: 700; border-top: 2px solid var(--text); }
tr.muted td { color: var(--muted); }
.neg { color: var(--bad); }
.mono { font-family: ui-monospace, "SF Mono", Menlo, monospace; }

.chip { display: inline-block; padding: 1px 8px; border-radius: 99px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.chip.utkast { background: var(--warn-soft); color: var(--warn); }
.chip.bokförd { background: var(--accent-soft); color: var(--accent); }
.chip.betald { background: var(--good-soft); color: var(--good); }
.chip.overdue { background: var(--bad-soft); color: var(--bad); }

button, .btn { font: inherit; border: 1px solid var(--line); background: var(--panel); color: var(--text); border-radius: 6px; padding: 6px 12px; cursor: pointer; text-decoration: none; display: inline-block; }
button:hover, .btn:hover { border-color: var(--accent); }
button.primary, .btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.danger { color: var(--bad); }
button.small, .btn.small { padding: 2px 8px; font-size: 12px; }
button:disabled { opacity: .5; cursor: default; }
.actions { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }

form .row, form.row { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
label { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--muted); }
input, select, textarea { font: inherit; color: var(--text); background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; min-width: 0; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
input.num { text-align: right; width: 120px; font-variant-numeric: tabular-nums; }
textarea { min-height: 60px; }
.lines td { padding: 4px; border: none; }
.lines input, .lines select { width: 100%; }
.balance-ok { color: var(--good); font-weight: 600; }
.balance-bad { color: var(--bad); font-weight: 600; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; flex-wrap: wrap; }
.tabs a { padding: 8px 14px; text-decoration: none; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs a.active { color: var(--text); border-color: var(--accent); font-weight: 600; }

.chart { display: flex; align-items: flex-end; gap: 6px; height: 180px; padding-top: 8px; }
.chart .m { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; height: 100%; justify-content: flex-end; }
.chart .bars { display: flex; gap: 2px; align-items: flex-end; height: 100%; width: 100%; justify-content: center; }
.chart .bar { width: 40%; max-width: 16px; border-radius: 3px 3px 0 0; }
.chart .bar.i { background: var(--income); }
.chart .bar.c { background: var(--cost); }
.chart small { color: var(--muted); font-size: 11px; }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--muted); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 4px; vertical-align: -1px; }

.note { padding: 10px 14px; border-radius: 8px; background: var(--accent-soft); margin-bottom: 14px; }
.note.warn { background: var(--warn-soft); }
.note.bad { background: var(--bad-soft); }
.note.good { background: var(--good-soft); }

#toast { position: fixed; right: 20px; bottom: 20px; max-width: 420px; padding: 12px 16px; border-radius: 8px; color: #fff; background: #1d2433; box-shadow: 0 6px 24px rgba(0,0,0,.25); opacity: 0; transform: translateY(10px); transition: .2s; pointer-events: none; }
#toast.show { opacity: 1; transform: none; }
#toast.error { background: #b42318; }

@media (max-width: 800px) {
  body { flex-direction: column; }
  .sidebar { width: auto; height: auto; position: static; }
  .sidebar nav { flex-direction: row; flex-wrap: wrap; padding-bottom: 8px; }
  .nav-title, .lock-badge { display: none; }
  main { padding: 20px 16px 48px; }
  .two { grid-template-columns: 1fr; }
}

.template-layout { display: grid; grid-template-columns: minmax(320px, 440px) 1fr; gap: 18px; align-items: start; }
.template-preview { position: sticky; top: 16px; }
.template-preview iframe { width: 100%; height: 1100px; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
@media (max-width: 1100px) { .template-layout { grid-template-columns: 1fr; } .template-preview { position: static; } }

.brand-logo { max-height: 30px; max-width: 120px; object-fit: contain; background: #fff; border-radius: 6px; padding: 3px; flex: none; }
.login-logo { display: block; max-height: 70px; max-width: 100%; margin: 0 0 14px; object-fit: contain; }
.logo-preview { max-height: 60px; max-width: 220px; object-fit: contain; border: 1px solid var(--line); border-radius: 6px; padding: 4px; background: #fff; }

details.setup { border: 1px solid var(--line); border-radius: 8px; padding: 10px 14px; margin-bottom: 12px; }
details.setup summary { cursor: pointer; }
.chart-table { max-height: 420px; overflow-y: auto; border: 1px solid var(--line); border-radius: 6px; }
.chart-table td { padding: 3px 8px; vertical-align: middle; }
.chart-table .chart-name { width: 100%; padding: 4px 6px; }
.opening-table { max-height: 520px; overflow-y: auto; }
.opening-table td { vertical-align: middle; }
.opening-table input.num { width: 100%; }
