:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --text: #1c2330;
  --muted: #6b7280;
  --border: #dde1e7;
  --grid: #e6e9ee;
  --head: #f0f2f5;
  --accent: #1f7a4d;
  --accent-text: #ffffff;
  --pos: #15803d;
  --neg: #b91c1c;
  --pending: #b45309;
  --pending-bg: #fff7e6;
  --disputed-bg: #fdecec;
  --focus: #2563eb;
  --radius: 8px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12151b;
    --surface: #1b1f27;
    --text: #e6e9ef;
    --muted: #9aa3b2;
    --border: #2d333e;
    --grid: #272c36;
    --head: #222731;
    --accent: #2f9e66;
    --pos: #4ade80;
    --neg: #f87171;
    --pending: #fbbf24;
    --pending-bg: #2a2416;
    --disputed-bg: #2e1a1c;
    --focus: #60a5fa;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

button, input, select { font: inherit; color: inherit; }

button {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 6px;
  padding: 6px 10px;
  cursor: pointer;
}
button:hover { border-color: var(--muted); }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
button.danger { color: var(--neg); }
button.icon { border: none; background: none; padding: 4px 6px; }
button:disabled { opacity: .45; cursor: not-allowed; }

input, select {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 6px;
  padding: 6px 8px;
  min-width: 0;
}

:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }

.muted { color: var(--muted); }
.small { font-size: 12px; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.pos { color: var(--pos); }
.neg { color: var(--neg); }
code { background: var(--head); padding: 1px 4px; border-radius: 4px; }

/* --- Toppfält --- */

.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  padding: 10px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.brand { font-weight: 700; font-size: 16px; }
.tabs { display: flex; gap: 4px; flex-wrap: wrap; flex: 1; }
.tab { border: none; background: none; padding: 6px 12px; border-radius: 6px; white-space: nowrap; }
.tab.active { background: var(--head); font-weight: 600; }
.badge { background: var(--neg); color: #fff; border-radius: 10px; padding: 0 6px; font-size: 12px; }
.who { display: flex; align-items: center; gap: 6px; }

.avatar {
  display: inline-grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--c);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  vertical-align: middle;
  flex: none;
}
.avatar.lg { width: 36px; height: 36px; font-size: 16px; }
.avatar.small { width: 18px; height: 18px; font-size: 10px; }
.avatar.waiting { opacity: .3; }
.avatar.rejected { box-shadow: 0 0 0 2px var(--neg); }
.avatar.approved { box-shadow: 0 0 0 2px var(--pos); }

main { padding: 16px; max-width: 1500px; margin: 0 auto; }

/* --- Verktygsrad --- */

.toolbar { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.quick { display: flex; gap: 6px; flex: 1 1 420px; }
.quick input { flex: 1; }
.mic { font-size: 16px; padding: 4px 10px; }
.mic.listening { background: var(--neg); color: #fff; animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .6; } }
.filters { display: flex; gap: 6px; flex-wrap: wrap; }

/* --- Kalkylarket --- */

.grid-wrap {
  overflow-x: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.grid { border-collapse: collapse; width: 100%; white-space: nowrap; }
.grid th, .grid td { border: 1px solid var(--grid); padding: 5px 8px; }
.grid thead th { background: var(--head); font-weight: 600; text-align: left; position: sticky; top: 0; }
.grid tr.letters th { font-weight: 400; color: var(--muted); text-align: center; font-size: 11px; padding: 2px; }
.grid .rownum { background: var(--head); color: var(--muted); text-align: center; width: 36px; font-size: 12px; }
.grid .member-col { background: color-mix(in srgb, var(--head) 45%, transparent); }
.grid td.cell { cursor: cell; }
.grid td.cell:focus { outline: 2px solid var(--focus); outline-offset: -2px; }
.grid td.editing { padding: 0; position: relative; }
.grid td.editing > input, .grid td.editing > select { width: 100%; border: 2px solid var(--focus); border-radius: 0; }
.grid tr.row.pending td:not(.rownum) { background: var(--pending-bg); }
.grid tr.row.disputed td:not(.rownum) { background: var(--disputed-bg); }
.grid .empty { color: var(--muted); text-align: center; padding: 24px; }
.fx { font-size: 10px; color: var(--muted); margin-right: 4px; font-style: italic; }

.grid tbody.draft td { background: var(--surface); padding: 3px; }
.grid tbody.draft input, .grid tbody.draft select { width: 100%; }
.grid tbody.draft td.preview { color: var(--muted); }
.grid tbody.draft tr.flash td { animation: flash 1.2s; }
@keyframes flash { from { background: color-mix(in srgb, var(--accent) 30%, transparent); } }

.chips { display: flex; gap: 4px; flex-wrap: wrap; }
.chip { padding: 2px 8px; border-radius: 12px; font-size: 12px; opacity: .55; }
.chip.on { opacity: 1; background: var(--c); border-color: var(--c); color: #fff; }

.grid tfoot td { background: var(--head); font-weight: 600; }
.grid tfoot tr.net td { border-top: 2px solid var(--muted); }

.weights-editor {
  position: absolute;
  z-index: 5;
  top: 100%;
  left: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 6px 24px rgb(0 0 0 / .18);
  padding: 10px;
  display: grid;
  gap: 6px;
  min-width: 220px;
}
.weights-editor label { display: flex; align-items: center; gap: 6px; }
.weights-editor input { width: 60px; margin-left: auto; }
.weights-editor p { margin: 0; }

.approval { display: flex; align-items: center; gap: 6px; }
.approval .dots { display: flex; gap: 3px; }
.approval .ok, .approval .no { padding: 1px 7px; }
.approval .ok { color: var(--pos); }
.approval .no { color: var(--neg); }
.status { font-size: 12px; font-weight: 600; min-width: 70px; }
.status.approved { color: var(--pos); }
.status.pending { color: var(--pending); }
.status.disputed { color: var(--neg); }

.hint { color: var(--muted); font-size: 12px; }

/* --- Kort och listor --- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
}
.card h2 { margin: 0 0 8px; font-size: 16px; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; margin-bottom: 16px; }
.cards .card { margin: 0; }
.balance .who { margin-bottom: 8px; }
.balance .amount { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }

.list { list-style: none; margin: 0 0 12px; padding: 0; }
.list li {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  padding: 8px 0;
  border-bottom: 1px solid var(--grid);
}
.list li:last-child { border-bottom: none; }
.list .amount { font-weight: 600; font-variant-numeric: tabular-nums; }
.list .date { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }

.inline-form { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; margin-bottom: 8px; }
.inline-form input[name="amount"] { width: 110px; }

/* --- Inloggning --- */

.login { max-width: 420px; margin: 48px auto; text-align: center; }
.login h1 { margin-top: 0; }
.login-list { display: grid; gap: 8px; margin-top: 16px; }
.login-btn { display: flex; align-items: center; gap: 12px; padding: 10px 14px; font-size: 16px; }

/* --- Dialog och notiser --- */

dialog {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  width: min(480px, calc(100vw - 32px));
}
dialog::backdrop { background: rgb(0 0 0 / .4); }
.settings label { display: grid; gap: 4px; }
.settings h3 { margin: 16px 0 6px; font-size: 14px; }
.dialog-actions { display: flex; justify-content: space-between; margin-top: 16px; }

#toasts { position: fixed; bottom: 16px; right: 16px; display: grid; gap: 8px; z-index: 50; max-width: calc(100vw - 32px); }
.toast { background: var(--text); color: var(--bg); padding: 10px 14px; border-radius: var(--radius); box-shadow: 0 4px 16px rgb(0 0 0 / .2); }
.toast.error { background: var(--neg); color: #fff; }

@media (max-width: 640px) {
  .topbar { gap: 8px; justify-content: space-between; }
  .tabs { order: 3; flex: 1 0 100%; flex-wrap: nowrap; overflow-x: auto; }
  main { padding: 12px; }
  .quick { flex-basis: 100%; }
}

/* ALnasserkassa 0.2: a calm shared ledger, readable on desktop and phone. */
:root {
  --bg: #f7f8f5;
  --surface: #ffffff;
  --text: #233b33;
  --muted: #64736c;
  --border: #e1e7e0;
  --grid: #e9eee8;
  --head: #f3f6f1;
  --accent: #176b56;
  --accent-text: #fff;
  --focus: #147d64;
  --pending-bg: #fffcf3;
  --disputed-bg: #fff3f0;
  --radius: 14px;
}
body { font-size: 14px; line-height: 1.55; }
button { border-radius: 9px; padding: 9px 14px; font-weight: 550; transition: background .15s, border-color .15s; }
button:hover { background: var(--head); border-color: #aabcb0; }
button.primary:hover { background: #105441; }
input, select { border-radius: 8px; padding: 9px 11px; }
input::placeholder { color: #87918b; }
a { color: var(--accent); text-underline-offset: 3px; }
.topbar { padding: 17px max(24px, calc((100vw - 1400px) / 2)); gap: 30px; background: #ffffffed; backdrop-filter: blur(14px); }
.brand { display: flex; align-items: center; gap: 10px; font-size: 17px; letter-spacing: -.4px; }
.brand img { flex: none; }
.brand small { display: block; font-size: 10px; font-weight: 500; letter-spacing: .8px; color: var(--muted); text-transform: uppercase; line-height: 1.2; }
.tabs { gap: 6px; justify-content: center; }
.tab { padding: 9px 15px; color: var(--muted); font-size: 13px; }
.tab.active { color: var(--accent); background: #edf4ed; }
.sync-label { font-size: 11px; color: var(--muted); margin-right: 8px; }
.who select { border: 0; background: transparent; padding: 5px 2px; font-size: 13px; max-width: 130px; }
button.icon { font-size: 20px; border-radius: 8px; padding: 1px 7px; color: var(--muted); }
main { max-width: 1450px; padding: 26px 24px 45px; min-height: calc(100vh - 160px); }
.demo-note { display: flex; align-items: center; gap: 8px; color: #69734f; background: #eef1e6; border: 1px solid #e2e7d5; border-radius: 8px; padding: 9px 13px; font-size: 12px; margin-bottom: 25px; }
.live-dot { width: 7px; height: 7px; border-radius: 50%; background: #839256; flex: none; }
.intro { display: flex; gap: 20px; align-items: center; justify-content: space-between; margin: 12px 0 28px; }
.eyebrow { color: var(--muted); font-size: 10px; letter-spacing: 1.7px; font-weight: 650; text-transform: uppercase; margin: 0 0 10px; }
.intro h1 { font-family: Georgia, 'Times New Roman', serif; font-size: clamp(28px, 3vw, 40px); line-height: 1.2; font-weight: 500; letter-spacing: -1.4px; margin: 0 0 10px; }
.intro-copy { color: var(--muted); margin: 0; font-size: 14px; }
.add-expense { padding: 12px 20px; white-space: nowrap; box-shadow: 0 3px 7px #176b5617; }
.add-expense span { margin-right: 7px; }
.overview { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 17px; margin: 0 0 32px; }
.metric { padding: 20px 23px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; }
.metric-label { display: flex; justify-content: space-between; gap: 12px; color: var(--muted); font-size: 12px; margin-bottom: 11px; }
.metric-label > span { font-size: 19px; color: #729184; line-height: 1; }
.metric strong { display: block; font-size: clamp(21px, 2.2vw, 30px); font-weight: 550; letter-spacing: -.9px; font-variant-numeric: tabular-nums; line-height: 1.3; }
.metric small { display: block; font-size: 11px; color: var(--muted); margin-top: 9px; }
.metric.personal { background: #eaf2e9; border-color: #dce8da; }
.ledger-heading { display: flex; justify-content: space-between; gap: 15px; align-items: center; margin-bottom: 18px; }
.ledger-heading h2 { font-size: 17px; font-weight: 650; letter-spacing: -.3px; margin: 0; }
.ledger-heading p { font-size: 12px; color: var(--muted); margin: 4px 0 0; }
.ledger-heading button { font-size: 12px; }
.count { display: inline-block; font-size: 10px; background: #e9eee7; color: var(--muted); padding: 1px 7px; border-radius: 6px; margin-left: 5px; vertical-align: middle; }
.toolbar { padding: 14px 0; border-top: 1px solid var(--border); gap: 12px; margin-bottom: 12px; }
.quick { flex: 1 1 350px; }
.quick input { font-size: 12px; width: 180px; }
.quick button { font-size: 12px; }
.quick .mic { font-size: 16px; }
.filters { gap: 7px; }
.filters select, .filters input { font-size: 12px; }
.filters input { width: 155px; }
.grid-wrap { border-radius: 12px; background: #fff; box-shadow: 0 3px 10px #233b3303; }
.grid { font-size: 12px; }
.grid th { color: #60736a; font-weight: 600; }
.grid td, .grid th { padding: 12px 10px; }
.grid thead tr.letters th { padding: 4px 10px; font-size: 9px; color: #8b978f; background: #f8faf7; }
.grid td.cell[data-c="1"] { min-width: 150px; font-weight: 550; color: #233b33; }
.grid td.cell[data-c="2"] { color: var(--muted); }
.grid td.cell[data-c="3"] { font-weight: 600; }
.grid tbody.draft td { padding: 6px; background: #f8faf6; }
.grid tbody.draft input, .grid tbody.draft select { min-height: 34px; padding: 5px 7px; font-size: 12px; background: #fff; }
.grid tbody.draft input[name="date"] { min-width: 120px; }
.grid tbody.draft input[name="description"] { min-width: 150px; }
.grid tbody.draft input[name="category"] { min-width: 95px; }
.grid tbody.draft input[name="amountExpr"] { min-width: 125px; }
.grid tfoot td { font-size: 11px; padding: 9px 10px; font-weight: 500; }
.grid tfoot tr.net td { border-top: 1px solid #becdc0; font-weight: 650; }
.grid tr.row.pending td:not(.rownum) { background: #fffdf7; }
.grid tr.row.disputed td:not(.rownum) { background: #fff4f0; }
.grid tbody tr.row:hover td { background: #f0f5ef; }
.grid .chips { display: table-cell; min-width: 150px; }
.chip { margin: 2px; font-size: 10px; padding: 3px 7px; font-weight: 500; }
.avatar { width: 24px; height: 24px; font-size: 10px; }
.status { font-size: 10px; border-radius: 5px; padding: 3px 6px; min-width: auto; white-space: nowrap; }
.status.approved { background: #edf6ed; color: #306c3c; }
.status.pending { background: #faf1dc; color: #88642c; }
.status.disputed { background: #fbe7e1; color: #a54135; }
.approval .dots { display: none; }
.approval .ok, .approval .no { font-size: 12px; padding: 2px 6px; }
.hint { font-size: 11px; max-width: 980px; margin-top: 16px; line-height: 1.8; }
.card { padding: 23px; }
.card h2 { font-size: 17px; margin-bottom: 12px; }
.cards { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 17px; }
.balance .amount { font-size: 27px; font-weight: 550; margin: 17px 0 4px; }
.list li { padding: 13px 0; gap: 11px; }
.balance .who { font-size: 14px; }
.settings .inline-form input { width: 100%; }
.settings .inline-form { margin-top: 15px; }
.settings h2 { margin-top: 0; }
.site-footer { display: flex; justify-content: space-between; gap: 20px; max-width: 1450px; margin: 0 auto; padding: 20px 24px; color: #86948b; font-size: 11px; border-top: 1px solid var(--border); }
.site-footer > :first-child { font-weight: 650; color: #738478; }
.connection { background: #fff0d0; color: #795518; padding: 12px 24px; text-align: center; font-size: 12px; }
[hidden] { display: none !important; }
dialog { padding: 24px; max-height: 90vh; }
@media (max-width: 1000px) {
  .topbar { gap: 16px; padding: 15px 20px; }
  .sync-label { display: none; }
  .tab { padding: 9px 10px; }
  .toolbar .quick { flex-basis: 100%; }
  .filters { flex-wrap: wrap; display: flex; }
}
@media (max-width: 640px) {
  .topbar { gap: 14px; padding: 13px 16px 0; }
  .brand { font-size: 16px; }
  .brand img { width: 33px; height: 33px; }
  .who { gap: 2px; }
  .who .avatar { display: none; }
  .tabs { justify-content: flex-start; padding-bottom: 9px; gap: 3px; }
  .tab { flex: 1; font-size: 12px; padding: 8px 10px; }
  main { padding: 18px 15px 30px; }
  .demo-note { font-size: 11px; margin-bottom: 24px; padding: 9px 11px; }
  .intro { flex-wrap: wrap; gap: 15px; margin-bottom: 22px; }
  .intro h1 { font-size: 31px; letter-spacing: -.9px; }
  .intro-copy { font-size: 13px; }
  .add-expense { padding: 9px 15px; font-size: 12px; }
  .overview { grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 25px; }
  .metric { padding: 15px; }
  .metric-label { font-size: 10px; gap: 6px; }
  .metric strong { font-size: 20px; letter-spacing: -.6px; }
  .metric small { font-size: 10px; }
  .metric.personal { grid-column: 1 / -1; }
  .metric.personal strong { font-size: 25px; }
  .ledger-heading { align-items: flex-start; }
  .ledger-heading h2 { font-size: 16px; }
  .ledger-heading p { font-size: 11px; max-width: 180px; }
  .ledger-heading button { padding: 7px 10px; font-size: 10px; white-space: nowrap; }
  .quick { min-width: 0; }
  .quick input { min-width: 0; width: 100px; }
  .filters { width: 100%; gap: 7px; }
  .filters select { flex: 1; width: 45%; }
  .filters input { width: 100%; }
  .cards { grid-template-columns: 1fr; }
  .site-footer { padding: 18px 15px; font-size: 10px; }
  .card { padding: 18px; }
  .inline-form select, .inline-form input { max-width: 100%; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; animation: none !important; }
}

