:root {
  --bg: #f7f4ed; --paper: #fffdf8; --ink: #1d2a1f; --muted: #5b6657; --line: #e1dccf;
  --brand: #2f5d3a; --brand-dark: #24492d; --accent: #b5741f; --soft: #e8efe6; --ai: #f3ecdf;
  --ok: #2f5d3a; --warn: #b5741f; --error: #b8382b; --radius: 14px;
  --font: 'Inter', system-ui, sans-serif; --display: 'Fraunces', Georgia, serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141814; --paper: #1c221c; --ink: #eef1ea; --muted: #a6b0a0; --line: #2d352c;
    --brand: #6fae7f; --brand-dark: #5a9469; --accent: #d9a157; --soft: #22302a; --ai: #2b2821;
  }
}
:root[data-theme="dark"] {
  --bg: #141814; --paper: #1c221c; --ink: #eef1ea; --muted: #a6b0a0; --line: #2d352c;
  --brand: #6fae7f; --brand-dark: #5a9469; --accent: #d9a157; --soft: #22302a; --ai: #2b2821;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 16px/1.55 var(--font); color: var(--ink); background: var(--bg); min-height: 100vh; display: flex; flex-direction: column; }
main { flex: 1; }
h1, h2, h3 { font-family: var(--display); font-weight: 650; line-height: 1.15; margin: 0 0 .4em; }
h1 { font-size: clamp(1.7rem, 4vw, 2.3rem); }
h2 { font-size: 1.3rem; margin-top: 1.6em; }
h3 { font-size: 1.05rem; }
p { margin: 0 0 1em; }
a { color: var(--brand); }
code { font-size: .9em; background: var(--soft); padding: .1em .35em; border-radius: 4px; }
.wrap { width: 100%; max-width: 1120px; margin: 0 auto; padding: 0 16px; }
.wrap.narrow { max-width: 720px; }
.wrap.wide { max-width: 1400px; }
.muted { color: var(--muted); }
.small { font-size: .86rem; }
.lead { font-size: 1.08rem; color: var(--muted); max-width: 70ch; }
.eyebrow { font-size: .78rem; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--accent); margin: 0 0 .4em; }
.eyebrow a { color: inherit; text-decoration: none; }
.neg { color: var(--error); }
.strong td, .strong th { font-weight: 600; }
.skip { position: absolute; left: -999px; }
.skip:focus { left: 16px; top: 8px; background: var(--paper); padding: 8px; z-index: 10; }

/* Topp */
header.site { background: var(--paper); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.nav { display: flex; align-items: center; gap: 24px; min-height: 60px; }
.logo { font-family: var(--display); font-weight: 650; font-size: 1.35rem; color: var(--ink); text-decoration: none; }
.logo span { color: var(--brand); }
.logo small { font-family: var(--font); font-weight: 500; font-size: .8rem; color: var(--muted); margin-left: 6px; }
nav ul { display: flex; gap: 4px; list-style: none; margin: 0; padding: 0; }
nav a, nav .linkish { display: block; padding: 8px 12px; border-radius: 999px; text-decoration: none; color: var(--ink); font-weight: 500; font-size: .95rem; }
nav a[aria-current="page"] { background: var(--soft); color: var(--brand); }
nav a:hover { background: var(--soft); }
.nav-actions { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.menu-btn { display: none; }
.only-mobile { display: none; }
.avatar { display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 50%; background: hsl(var(--h, 120) 35% 40%); color: #fff; font-weight: 600; font-size: .8rem; text-decoration: none; flex: none; }
.linkish { background: none; border: 0; padding: 0; color: var(--brand); font: inherit; cursor: pointer; text-decoration: underline; }
.inline-form { display: inline; }
.hidden-form { display: none; }

@media (max-width: 860px) {
  .menu-btn { display: inline-block; }
  .only-mobile { display: block; }
  .only-desktop { display: none; }
  nav { display: none; position: absolute; left: 0; right: 0; top: 60px; background: var(--paper); border-bottom: 1px solid var(--line); padding: 8px 16px 16px; }
  nav.open { display: block; }
  nav ul { flex-direction: column; }
}

/* Knappar och formulär */
.btn { display: inline-block; padding: .6em 1.1em; border-radius: 999px; border: 1px solid var(--line); background: var(--paper); color: var(--ink); font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; line-height: 1.2; }
.btn:hover { border-color: var(--brand); }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-dark); }
.btn-ghost { background: transparent; }
.btn-sm { padding: .45em .9em; font-size: .86rem; }
.btn[disabled] { opacity: .6; cursor: wait; }
input[type="text"], input[type="email"], input[type="password"], input[type="date"], input[type="month"], select, textarea {
  font: inherit; color: var(--ink); background: var(--paper); border: 1px solid var(--line); border-radius: 10px; padding: .55em .75em; width: 100%;
}
textarea { resize: vertical; line-height: 1.5; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); outline-offset: 1px; }
label { display: block; font-weight: 500; font-size: .92rem; }
label input, label select, label textarea { margin-top: 4px; font-weight: 400; }
label.inline { display: inline-flex; align-items: center; gap: 8px; }
label.inline input, label.inline select { width: auto; margin: 0; }
.stack { display: grid; gap: 14px; }
.row { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
.grow { flex: 1; }
.card { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; margin: 16px 0; }
.card h2:first-child, .card h3:first-child { margin-top: 0; }
.flashes { margin-top: 12px; }
.flash { padding: 10px 14px; border-radius: 10px; margin-bottom: 8px; background: var(--soft); border-left: 4px solid var(--ok); }
.flash-error { border-left-color: var(--error); }
.flash-info { border-left-color: var(--accent); }
.pill { display: inline-block; font-size: .75rem; padding: .1em .55em; border-radius: 999px; background: var(--soft); color: var(--brand); font-weight: 600; }
.pill-ai { background: var(--ai); color: var(--accent); }

.auth { padding-top: 48px; }
.page-head { display: flex; flex-wrap: wrap; gap: 24px; align-items: end; justify-content: space-between; padding-top: 28px; }
.progress-box { min-width: 260px; }
.progress { height: 10px; background: var(--line); border-radius: 999px; overflow: hidden; }
.progress span { display: block; height: 100%; background: var(--brand); border-radius: 999px; transition: width .4s; }
.next-step { display: flex; flex-wrap: wrap; gap: 16px; align-items: center; justify-content: space-between; background: var(--soft); border-radius: var(--radius); padding: 16px 20px; margin: 20px 0; }
.next-step .eyebrow { margin-bottom: 2px; }

/* Avsnittskort */
.section-grid { list-style: none; padding: 0; margin: 0; display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); counter-reset: s; }
.section-card a { display: grid; gap: 4px; padding: 16px; background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); text-decoration: none; color: var(--ink); height: 100%; position: relative; }
.section-card a:hover { border-color: var(--brand); }
.section-card .num { font-family: var(--display); font-size: 1.4rem; color: var(--muted); }
.section-card .meta { font-size: .8rem; color: var(--muted); margin-top: 6px; }
.status-badge { position: absolute; top: 14px; right: 14px; font-size: .72rem; font-weight: 600; padding: .15em .6em; border-radius: 999px; background: var(--line); color: var(--muted); }
.status-utkast .status-badge, .status-badge.status-utkast { background: #fbeccd; color: #7a4d0f; }
.status-granskas .status-badge, .status-badge.status-granskas { background: #dbe7f7; color: #24497a; }
.status-klar .status-badge, .status-badge.status-klar { background: #d6ead9; color: #1f4a2a; }
.export table .status-badge { position: static; }
.cols-3 { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.cols-2 { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
table.mini { width: 100%; border-collapse: collapse; font-size: .9rem; }
table.mini td, table.mini th { padding: 6px 8px; border-bottom: 1px solid var(--line); text-align: right; }
table.mini td:first-child, table.mini th:first-child { text-align: left; }
.plain { list-style: none; padding: 0; margin: 0; }
.plain li { padding: 6px 0; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.ms-status { display: inline-block; width: 12px; height: 12px; border-radius: 50%; border: 2px solid var(--muted); flex: none; }
.ms-pagar { border-color: var(--accent); background: var(--accent); }
.ms-klar { border-color: var(--brand); background: var(--brand); }

.feed { list-style: none; padding: 0; margin: 0; }
.feed li { display: flex; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.feed-body { color: var(--muted); font-size: .9rem; white-space: pre-line; }

/* Avsnittssida */
.section-layout { display: grid; grid-template-columns: 220px minmax(0, 1fr) 340px; gap: 28px; padding-top: 28px; align-items: start; }
.side-nav { position: sticky; top: 76px; }
.side-nav ol { list-style: none; padding: 0; margin: 0 0 12px; }
.side-nav a { display: flex; gap: 8px; align-items: center; padding: 6px 8px; border-radius: 8px; text-decoration: none; color: var(--ink); font-size: .9rem; }
.side-nav a[aria-current="page"] { background: var(--soft); font-weight: 600; }
.side-nav .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--line); flex: none; }
.side-nav .status-utkast .dot { background: #e4a94a; }
.side-nav .status-granskas .dot { background: #5b8fd6; }
.side-nav .status-klar .dot { background: var(--brand); }
.guide { background: var(--paper); border: 1px solid var(--line); border-radius: 10px; padding: 8px 14px; margin-bottom: 8px; }
.guide summary { cursor: pointer; font-weight: 600; font-size: .92rem; }
.guide ul { margin: 8px 0; padding-left: 20px; }
.guide li { margin-bottom: 4px; }
.guide .example { font-style: italic; color: var(--muted); margin: 8px 0; }
.editor { margin-top: 16px; }
.editor-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin: 10px 0; }
.editor-bar select { width: auto; }
.editor textarea { min-height: 360px; font-size: 1rem; }
.editor.dirty #save-state::after { content: ' · osparade ändringar'; color: var(--accent); }
.reading h3 { margin-top: 1.2em; }
.reading ul, .reading ol { padding-left: 22px; }
.pager { display: flex; justify-content: space-between; gap: 12px; margin: 28px 0; }
.ms-row { display: grid; grid-template-columns: 14px minmax(0, 2fr) minmax(0, 1fr) 150px 120px auto auto; gap: 8px; align-items: center; padding: 6px 0; border-bottom: 1px solid var(--line); }
.ms-row input, .ms-row select { padding: .4em .6em; font-size: .92rem; }
.ms-new { border-bottom: 0; margin-top: 8px; }

.ai-panel { background: var(--ai); }
.ai-buttons { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.ai-btn { background: var(--paper); }
.suggestion { background: var(--paper); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; margin-top: 12px; }
.suggestion .eyebrow { margin-bottom: 2px; }
.suggestion h3 { margin-bottom: 6px; }
.s-body { font-size: .92rem; max-height: 360px; overflow: auto; }
.s-body ul, .s-body ol { padding-left: 20px; }
.s-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.comments { list-style: none; padding: 0; margin: 12px 0 0; }
.comments li { padding: 10px 0; border-top: 1px solid var(--line); }
.comments .resolved { opacity: .55; }
.comment-head { display: flex; align-items: center; gap: 8px; }
.comment-head .avatar { width: 26px; height: 26px; font-size: .7rem; }
.comment-body { white-space: pre-line; margin: 6px 0; font-size: .95rem; }
.comment-actions { display: flex; gap: 12px; }

@media (max-width: 1080px) { .section-layout { grid-template-columns: minmax(0, 1fr) 320px; } .side-nav { display: none; } }
@media (max-width: 800px) { .section-layout { grid-template-columns: minmax(0, 1fr); } .ms-row { grid-template-columns: 14px minmax(0, 1fr); } .ms-row > *:nth-child(n+3) { grid-column: 2; } }

/* Versioner */
.versions-layout { display: grid; grid-template-columns: 300px minmax(0, 1fr); gap: 24px; }
.version-list { list-style: none; padding: 0; margin: 0; }
.version-list li a { display: block; padding: 10px 12px; border-radius: 10px; text-decoration: none; color: var(--ink); border: 1px solid transparent; }
.version-list li.current a { background: var(--paper); border-color: var(--line); }
@media (max-width: 800px) { .versions-layout { grid-template-columns: 1fr; } }

/* Ekonomi */
.econ-settings { background: var(--paper); border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px; }
.econ-settings .num { width: 120px; text-align: right; }
.year-tabs { display: flex; gap: 4px; margin-left: auto; }
.tab { padding: .45em .9em; border-radius: 999px; border: 1px solid var(--line); background: transparent; font: inherit; font-weight: 500; cursor: pointer; color: var(--ink); }
.tab[aria-selected="true"] { background: var(--brand); border-color: var(--brand); color: #fff; }
.table-scroll { overflow-x: auto; background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); }
.econ-table { border-collapse: collapse; width: 100%; font-size: .85rem; }
.econ-table th, .econ-table td { padding: 4px 6px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.econ-table th { font-weight: 600; text-align: right; color: var(--muted); font-size: .78rem; }
.econ-table th.name, .econ-table td.name { text-align: left; position: sticky; left: 0; background: var(--paper); min-width: 200px; z-index: 1; }
.econ-table .m { display: none; text-align: right; }
.econ[data-year="0"] .y0, .econ[data-year="1"] .y1, .econ[data-year="2"] .y2 { display: table-cell; }
.econ-table td.m { position: relative; }
.econ-table td.m input { width: 86px; text-align: right; padding: .3em .4em; border-radius: 6px; font-size: .85rem; }
.econ-table td.name input { padding: .3em .5em; border-radius: 6px; font-size: .88rem; }
.econ-table .fill { position: absolute; right: 2px; top: 50%; transform: translateY(-50%); border: 0; background: var(--soft); color: var(--brand); border-radius: 4px; font-size: .7rem; padding: 1px 4px; cursor: pointer; opacity: 0; }
.econ-table td.m:hover .fill, .econ-table td.m input:focus + .fill { opacity: 1; }
.econ-table .sum { text-align: right; font-weight: 600; min-width: 100px; }
.econ-table .cell { text-align: right; }
.econ-table tr.group th { text-align: left; background: var(--soft); color: var(--ink); font-size: .85rem; padding: 6px; }
.econ-table tr.subtotal td { font-weight: 600; background: color-mix(in srgb, var(--soft) 50%, transparent); }
.econ-table tr.result td, .econ-table tr.cash td { font-weight: 600; }
.econ-table tr.cash td { border-bottom: 0; }
.econ-table tr.add td { border-bottom: 0; padding: 6px; }

.econ-table tr.computed td.cell { font-weight: 600; }
.econ-table tr.sub td { color: var(--muted); font-size: .8rem; font-style: italic; }
.econ-table tr.sub td.name { padding-left: 18px; }
.staff-row, .staff-head { display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr) 120px 100px 100px 70px 110px auto auto; gap: 8px; align-items: center; padding: 6px 0; border-bottom: 1px solid var(--line); }
.staff-head { border-bottom: 0; padding-bottom: 0; }
.staff-row input, .staff-row select { padding: .4em .6em; font-size: .92rem; }
.staff-row .num { text-align: right; }
.staff-new { border-bottom: 0; margin-top: 8px; }
@media (max-width: 900px) { .staff-head { display: none; } .staff-row { grid-template-columns: 1fr 1fr; } }

/* Export */
.export-grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.export-card { display: grid; gap: 6px; text-decoration: none; color: var(--ink); }
.export-card:hover { border-color: var(--brand); }

/* Admin */
table.users { width: 100%; border-collapse: collapse; font-size: .92rem; }
table.users th, table.users td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.users select { width: auto; padding: .3em .5em; font-size: .88rem; }
tr.inactive { opacity: .5; }
.invite { display: flex; gap: 6px; align-items: center; }
.invite input { font-size: .8rem; padding: .3em .5em; min-width: 220px; }
.materials { list-style: none; padding: 0; }
.materials li { padding: 6px 0; border-bottom: 1px solid var(--line); display: flex; gap: 10px; flex-wrap: wrap; align-items: baseline; }
.people .avatar { width: 28px; height: 28px; font-size: .72rem; }
.site-foot { border-top: 1px solid var(--line); margin-top: 48px; padding: 20px 0; font-size: .85rem; color: var(--muted); }
@media (max-width: 600px) { .wrap { padding: 0 16px; } .row { grid-template-columns: 1fr; } .page-head { padding-top: 16px; } }
@media print { header.site, .site-foot, .toolbar { display: none !important; } body { background: #fff; color: #000; } }
