:root {
  --bg: #f4f2ee; --surface: #ffffff; --surface-2: #f8f7f4; --ink: #1d232b; --muted: #6a717b;
  --line: #e1ddd5; --brand: #1f4e79; --accent: var(--brand); --accent-ink: #ffffff;
  --accent-soft: color-mix(in srgb, var(--brand) 12%, #ffffff);
  --ok: #2e7d4f; --ok-soft: #e4f2e9; --danger: #b3261e; --danger-soft: #fbe9e7; --warn-soft: #fff4d6;
  --gold: #c9a227; --silver: #9aa3ad; --bronze: #b0703b;
  --radius: 12px; --shadow: 0 1px 2px rgba(0,0,0,.05), 0 4px 16px rgba(0,0,0,.04);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14181d; --surface: #1c2229; --surface-2: #232a32; --ink: #e8eaed; --muted: #9aa3ad;
    --line: #313a44; --accent: color-mix(in srgb, var(--brand) 50%, #ffffff); --accent-ink: #0d1620;
    --accent-soft: color-mix(in srgb, var(--brand) 35%, #1c2229);
    --ok: #6cc28f; --ok-soft: #1c3326; --danger: #f08b82; --danger-soft: #3a2220; --warn-soft: #3a3320;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
body { margin: 0; font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--ink); min-height: 100vh; display: flex; flex-direction: column; }
a { color: var(--accent); }
h1 { font-size: 1.8rem; line-height: 1.2; margin: .2em 0 .5em; letter-spacing: -.01em; }
h2 { font-size: 1.15rem; margin: 0 0 .75em; }
h3 { margin: 0 0 .3em; font-size: 1.05rem; }
.container { width: 100%; max-width: 980px; margin: 0 auto; padding: 20px 16px 48px; flex: 1; }
.muted { color: var(--muted); font-size: .9em; }
.small { font-size: .85em; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.lead { color: var(--muted); margin-top: -.25em; }
.hint { color: var(--muted); font-size: .88rem; margin: .5em 0 0; }
code { font-family: ui-monospace, Consolas, monospace; background: var(--surface-2); padding: 1px 6px; border-radius: 6px; letter-spacing: .05em; }

/* Topp */
.topbar { background: var(--surface); border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 16px; padding: 10px 16px; flex-wrap: wrap; position: sticky; top: 0; z-index: 10; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink); font-weight: 700; line-height: 1.1; }
.brand small { display: block; font-weight: 500; color: var(--muted); font-size: .75rem; }
.brand-mark { flex: none; overflow: hidden; background: var(--brand); color: #fff; border-radius: 8px; width: 36px; height: 36px; display: grid; place-items: center; font-size: .9rem; letter-spacing: .02em; }
#nav { display: flex; gap: 4px; margin-left: auto; flex-wrap: wrap; }
#nav a { text-decoration: none; color: var(--ink); padding: 6px 10px; border-radius: 8px; font-size: .95rem; }
#nav a.active, #nav a:hover { background: var(--accent-soft); color: var(--accent); }
.demo-banner { background: var(--warn-soft); text-align: center; padding: 6px 16px; font-size: .88rem; }
.footer { display: flex; justify-content: space-between; padding: 16px; color: var(--muted); font-size: .85rem; border-top: 1px solid var(--line); }
.footer a { color: var(--muted); }

/* Forside */
.hero { padding: 24px 0 8px; }
.hero h1 { font-size: clamp(2rem, 6vw, 3rem); margin: 0 0 .3em; }
.eyebrow { text-transform: uppercase; letter-spacing: .1em; font-size: .78rem; color: var(--muted); margin: 0; }
.status-row { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 20px; }
.pill { border: 1px solid var(--line); border-radius: 99px; padding: 3px 12px; font-size: .85rem; color: var(--muted); background: var(--surface); }
.pill.on { border-color: var(--ok); color: var(--ok); background: var(--ok-soft); }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 14px; margin-bottom: 20px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); position: relative; }
.card.link { text-decoration: none; color: var(--ink); transition: transform .12s, border-color .12s; }
.card.link:hover { transform: translateY(-2px); border-color: var(--accent); }
.card p { margin: 0; color: var(--muted); font-size: .93rem; padding-right: 20px; }
.card.primary { border-color: var(--accent); background: linear-gradient(180deg, var(--accent-soft), var(--surface)); }
.arrow { position: absolute; right: 16px; bottom: 14px; color: var(--accent); font-size: 1.2rem; }
.note { background: var(--surface); border-radius: var(--radius); border: 1px solid var(--line); padding: 16px 20px; }
.note ol { margin: .3em 0 0; padding-left: 1.2em; }
.note li { margin: .3em 0; }

/* Skjema */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin: 0 0 16px; box-shadow: var(--shadow); min-width: 0; }
fieldset.panel { margin: 0; }
legend { font-weight: 700; padding: 0 6px; }
.narrow { max-width: 460px; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.row { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; margin-bottom: 12px; }
label { display: flex; flex-direction: column; gap: 4px; font-size: .88rem; font-weight: 600; color: var(--ink); }
input, select { font: inherit; font-weight: 400; padding: 9px 11px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--ink); width: 100%; min-width: 0; }
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent); }
input[type=checkbox] { width: 18px; height: 18px; accent-color: var(--accent); }
label.check { flex-direction: row; align-items: center; gap: 8px; font-weight: 500; margin-top: 8px; }
.inline { display: flex; gap: 8px; }
.code-input { font-family: ui-monospace, Consolas, monospace; font-size: 1.4rem; letter-spacing: .2em; text-transform: uppercase; text-align: center; }
.model-list { display: flex; flex-direction: column; gap: 10px; margin-bottom: 12px; }
.model-row { display: grid; grid-template-columns: 2fr 1.3fr .7fr 1fr auto; gap: 8px; align-items: end; padding: 10px; background: var(--surface-2); border-radius: 10px; }
@media (max-width: 680px) {
  .model-row { grid-template-columns: 1fr 1fr; }
  .model-row .f-name, .model-row .f-class { grid-column: 1 / -1; }
  .model-row .remove { grid-column: 1 / -1; justify-self: end; }
}
.actions { display: flex; gap: 8px; justify-content: space-between; flex-wrap: wrap; }

/* Knapper */
.btn { font: inherit; font-weight: 600; font-size: .95rem; border: 1px solid var(--line); background: var(--surface); color: var(--ink); padding: 9px 16px; border-radius: 9px; cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; justify-content: center; gap: 6px; white-space: nowrap; }
.btn:hover { border-color: var(--accent); }
.btn:disabled { opacity: .6; cursor: wait; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.1); }
.btn.ghost { background: transparent; }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.small { padding: 5px 10px; font-size: .85rem; }
.btn.big { padding: 13px 22px; font-size: 1.05rem; }
.btn.block { display: flex; width: 100%; margin-bottom: 16px; }
.icon-btn { border: none; background: transparent; color: var(--muted); cursor: pointer; font-size: 1rem; padding: 6px 9px; border-radius: 8px; }
.icon-btn:hover { background: var(--danger-soft); color: var(--danger); }

/* Meldinger */
.alert { padding: 12px 16px; border-radius: 10px; background: var(--warn-soft); margin-bottom: 16px; }
.alert.error { background: var(--danger-soft); color: var(--danger); }
.alert.success { background: var(--ok-soft); }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 40px); opacity: 0; background: var(--ink); color: var(--bg); padding: 10px 18px; border-radius: 10px; transition: .2s; pointer-events: none; z-index: 50; max-width: calc(100% - 32px); box-shadow: 0 6px 20px rgba(0,0,0,.2); }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: var(--danger); color: #fff; }

/* Min side */
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.code-card { background: var(--accent); color: var(--accent-ink); border-radius: var(--radius); padding: 18px 20px; margin-bottom: 16px; display: flex; flex-direction: column; }
.code-card strong { font-family: ui-monospace, Consolas, monospace; font-size: 2.4rem; letter-spacing: .25em; line-height: 1.2; }
.code-card small { opacity: .85; }
.tag { display: inline-block; min-width: 2.4em; text-align: center; font-weight: 700; background: var(--accent-soft); color: var(--accent); border-radius: 6px; padding: 2px 6px; }

/* Tabeller */
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.table { width: 100%; border-collapse: collapse; font-size: .93rem; }
.table th { text-align: left; font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; padding: 10px; border-bottom: 1px solid var(--line); background: var(--surface-2); }
.table td { padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tr:last-child td { border-bottom: none; }
.table th.right { text-align: right; }
.table .num { font-variant-numeric: tabular-nums; font-weight: 600; width: 1%; white-space: nowrap; }
.panel .table td:first-child, .panel .table th:first-child { padding-left: 0; }
.results tr.class-break td { border-top: 2px solid var(--line); }
.results tr.p1 td, .results tr.p2 td, .results tr.p3 td { background: var(--surface-2); }
.medal { display: inline-grid; place-items: center; width: 26px; height: 26px; border-radius: 50%; font-weight: 700; font-size: .85rem; color: #fff; }
.m1 { background: var(--gold); } .m2 { background: var(--silver); } .m3 { background: var(--bronze); }
.badge { display: inline-block; font-size: .72rem; font-weight: 700; padding: 1px 6px; border-radius: 5px; background: var(--accent-soft); color: var(--accent); vertical-align: middle; }
.badge.danger { background: var(--danger-soft); color: var(--danger); }
.cell { padding: 6px 8px; font-size: .92rem; }
.cell.short { width: 80px; } .cell.tiny { width: 80px; }
.winners { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px; margin-bottom: 20px; }
.winner { background: var(--surface); border: 1px solid var(--line); border-left: 4px solid var(--gold); border-radius: 10px; padding: 10px 12px; display: flex; flex-direction: column; font-size: .9rem; }
.winner .cls { color: var(--muted); font-size: .78rem; font-weight: 700; }

/* Avstemning */
.progress { margin-bottom: 14px; font-size: .9rem; color: var(--muted); }
.progress .bar { height: 6px; background: var(--line); border-radius: 99px; overflow: hidden; margin-top: 6px; }
.progress .bar i { display: block; height: 100%; background: var(--ok); transition: width .2s; }
.vote-class header { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.vote-class h2 span { font-weight: 500; color: var(--muted); }
.vote-class.done { border-color: var(--ok); }
.vote-class.done h2::after { content: " ✓"; color: var(--ok); }
.vote { display: grid; grid-template-columns: 44px 80px 1fr; align-items: center; gap: 8px; margin-top: 8px; font-weight: 600; }
.vote .pts { background: var(--accent); color: var(--accent-ink); text-align: center; border-radius: 6px; padding: 4px 0; font-size: .85rem; }
.vote.second .pts { background: var(--accent-soft); color: var(--accent); }
@media (max-width: 480px) { .vote { grid-template-columns: 44px 1fr; } .vote select { grid-column: 1 / -1; } }
.sticky-save { position: sticky; bottom: 0; padding: 12px 0; background: linear-gradient(transparent, var(--bg) 35%); display: flex; justify-content: center; }
.sticky-save .btn { width: 100%; max-width: 420px; }

/* Admin */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 18px; overflow-x: auto; }
.tabs a { padding: 8px 14px; text-decoration: none; color: var(--muted); border-bottom: 2px solid transparent; white-space: nowrap; font-weight: 600; font-size: .93rem; }
.tabs a.active { color: var(--accent); border-color: var(--accent); }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; display: flex; flex-direction: column; }
.stat b { font-size: 1.9rem; line-height: 1.1; }
.stat small { color: var(--muted); }
.switch { flex-direction: row; align-items: center; gap: 12px; cursor: pointer; font-weight: 400; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch .slider { flex: none; width: 44px; height: 26px; border-radius: 99px; background: var(--line); position: relative; transition: .15s; }
.switch .slider::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; transition: .15s; box-shadow: 0 1px 3px rgba(0,0,0,.2); }
.switch input:checked + .slider { background: var(--ok); }
.switch input:checked + .slider::after { left: 21px; }
.switch input:focus-visible + .slider { outline: 2px solid var(--accent); outline-offset: 2px; }
.switch small { display: block; color: var(--muted); }
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.toolbar input, .toolbar select { width: auto; flex: 1 1 200px; max-width: 320px; }
.spacer { flex: 1; }
.danger-zone { border-color: var(--danger); }

#print-area { display: none; }
@media print {
  body { background: #fff; color: #000; display: block; }
  .no-print, #app, .toast { display: none !important; }
  #print-area { display: block; }
  #print-area h1 { font-size: 20pt; text-align: center; }
  #print-area .table { font-size: 9.5pt; }
  #print-area .table th, #print-area .table td { border: 1px solid #999; padding: 3px 6px; background: none; color: #000; }
  #print-area .medal { color: #000; background: none; width: auto; height: auto; }
  #print-area .badge { background: none; color: #000; border: 1px solid #999; }
  #print-area .summary { width: auto; margin-top: 16px; }
  .cards-print { display: grid; grid-template-columns: 1fr 1fr; gap: 0; }
  .mcard { border: 1px dashed #888; padding: 14px; height: 6.2cm; display: flex; flex-direction: column; justify-content: center; align-items: center; text-align: center; break-inside: avoid; }
  .mnum { font-size: 48pt; font-weight: 800; line-height: 1; }
  .mnum.code { font-size: 30pt; font-family: Consolas, monospace; letter-spacing: .15em; margin: 4px 0; }
  .mname { font-size: 15pt; font-weight: 700; margin: 6px 0; }
  .mcls { font-size: 11pt; }
  .mev { font-size: 9pt; color: #555; margin-top: 4px; }
}

/* Arkiv, historikk og manuelle stemmer */
details.year { border-top: 1px solid var(--line); padding: 10px 0; }
details.year:first-of-type { border-top: none; }
details.year summary { cursor: pointer; padding: 4px 0; }
details.year .table { margin-top: 8px; }
.chip { display: inline-block; padding: 3px 10px; margin: 2px; border-radius: 99px; background: var(--accent-soft); color: var(--accent); text-decoration: none; font-size: .88rem; }
.chip:hover { background: var(--accent); color: var(--accent-ink); }
.inline-label { flex-direction: row; align-items: center; gap: 8px; }
.inline-label select { width: auto; }
#vb h2 { margin-top: 8px; }
.page-head h1 .muted { font-size: 1.1rem; font-weight: 500; }

/* Flere arrangører */
.brand-mark.logo { background: var(--surface); border: 1px solid var(--line); }
.brand-mark img { width: 100%; height: 100%; object-fit: contain; }
.org-card .org-head { display: flex; gap: 12px; align-items: center; margin-bottom: 8px; }
.org-card h3 { margin: 0; }
.org-card p { margin: 2px 0 0; }
.org-card:hover { border-color: var(--brand); }
.org-list { display: flex; flex-direction: column; gap: 8px; }
.org-row { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; text-decoration: none; color: var(--ink); }
.org-row:hover { border-color: var(--accent); background: var(--surface-2); }
.org-row small { display: block; color: var(--muted); }
.org-row > span:nth-child(2) { flex: 1; min-width: 0; }
.arrow-inline { color: var(--accent); white-space: nowrap; font-size: .9rem; }
.brand-preview { display: flex; align-items: center; gap: 10px; padding: 10px 12px; background: var(--surface-2); border-radius: 10px; line-height: 1.15; }
.brand-preview small { display: block; color: var(--muted); }
.inline.prefix span { color: var(--muted); white-space: nowrap; align-self: center; }
input.color { width: 48px; padding: 2px; height: 40px; flex: none; }
