:root {
    --paper:      #F3F5F2;
    --surface:    #FFFFFF;
    --surface-2:  #EDF0EC;
    --ink:        #14201D;
    --ink-2:      #33423E;
    --muted:      #5C6B66;
    --faint:      #8A9994;
    --line:       #DCE2DD;
    --line-soft:  #E7EBE7;

    --accent:     #196B61;
    --accent-bg:  #E1EEEB;
    --amber:      #A2571C;
    --amber-bg:   #F6EBDF;
    --slate:      #5B5A6E;
    --slate-bg:   #E9E9EE;

    --ok:         #2E7D53;
    --ok-bg:      #E2F0E7;
    --warn:       #A9700F;
    --warn-bg:    #F7EDDA;
    --crit:       #A83E2C;
    --crit-bg:    #F7E6E2;

    --shadow:     0 1px 2px rgba(20,32,29,.06);
    --shadow-lg:  0 12px 34px rgba(20,32,29,.16);

    --avenir:    "Avenir Next", "Avenir", "Nunito Sans", "Segoe UI", Helvetica, Arial, sans-serif;
    --f-display: var(--avenir);
    --f-body:    var(--avenir);
    --f-mono:    var(--avenir);
  }

  @media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
      --paper:      #101614;  --surface:    #18201E;  --surface-2:  #1E2724;
      --ink:        #E6ECE8;  --ink-2:      #C6D2CD;  --muted:      #9AAAA4;
      --faint:      #74847E;  --line:       #2B3733;  --line-soft:  #232E2B;
      --accent:     #62C3B5;  --accent-bg:  #16302D;
      --amber:      #E5A063;  --amber-bg:   #33261A;
      --slate:      #ADACC0;  --slate-bg:   #262631;
      --ok:         #6FC08D;  --ok-bg:      #17301F;
      --warn:       #DCA842;  --warn-bg:    #322715;
      --crit:       #E08770;  --crit-bg:    #331D18;
      --shadow:     0 1px 2px rgba(0,0,0,.35);
      --shadow-lg:  0 12px 34px rgba(0,0,0,.5);
    }
  }
  :root[data-theme="dark"] {
    --paper:      #101614;  --surface:    #18201E;  --surface-2:  #1E2724;
    --ink:        #E6ECE8;  --ink-2:      #C6D2CD;  --muted:      #9AAAA4;
    --faint:      #74847E;  --line:       #2B3733;  --line-soft:  #232E2B;
    --accent:     #62C3B5;  --accent-bg:  #16302D;
    --amber:      #E5A063;  --amber-bg:   #33261A;
    --slate:      #ADACC0;  --slate-bg:   #262631;
    --ok:         #6FC08D;  --ok-bg:      #17301F;
    --warn:       #DCA842;  --warn-bg:    #322715;
    --crit:       #E08770;  --crit-bg:    #331D18;
    --shadow:     0 1px 2px rgba(0,0,0,.35);
    --shadow-lg:  0 12px 34px rgba(0,0,0,.5);
  }

  * { box-sizing: border-box; }

  body {
    background: var(--paper);
    color: var(--ink);
    font-family: var(--f-body);
    font-size: 16px;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
  }

  .num, .tile .value, td.date, .barrow .num, .fact dd, th, .flag .when, footer,
  .filters, .facts, table { font-variant-numeric: tabular-nums; }

  button, input, select, textarea { font: inherit; color: inherit; }
  :focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

  .wrap { max-width: 1120px; margin: 0 auto; padding: 0 24px 90px; }

  /* ---------- top bar ---------- */

  .topbar {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    justify-content: space-between;
    gap: 16px;
    padding: 30px 0 16px;
  }

  .brand .eyebrow {
    font-family: var(--f-mono);
    font-size: 10.5px; letter-spacing: .15em; text-transform: uppercase;
    color: var(--faint); margin: 0 0 6px;
  }
  .brand h1 {
    font-family: var(--f-display); font-weight: 700;
    font-size: 27px; letter-spacing: -.02em; margin: 0;
  }

  .statusline {
    font-family: var(--f-mono); font-size: 11px; color: var(--muted);
    display: flex; align-items: center; gap: 8px;
  }
  .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--faint); }
  .dot.live { background: var(--ok); }
  .dot.local { background: var(--warn); }

  nav.tabs {
    display: flex; gap: 2px; flex-wrap: wrap;
    border-bottom: 1px solid var(--line);
    margin-bottom: 30px;
  }
  nav.tabs button {
    background: none; border: none; cursor: pointer;
    font-family: var(--f-display); font-weight: 600; font-size: 13.5px;
    letter-spacing: .01em;
    padding: 11px 15px; color: var(--muted);
    border-bottom: 2px solid transparent; margin-bottom: -1px;
    border-radius: 2px 2px 0 0;
  }
  nav.tabs button:hover { color: var(--ink); background: var(--surface-2); }
  nav.tabs button[aria-selected="true"] {
    color: var(--ink); border-bottom-color: var(--accent);
  }

  /* ---------- shared bits ---------- */

  h2.sec {
    font-family: var(--f-display); font-weight: 600;
    font-size: 12px; letter-spacing: .13em; text-transform: uppercase;
    color: var(--muted); margin: 0 0 16px;
    padding-bottom: 9px; border-bottom: 1px solid var(--line);
    display: flex; justify-content: space-between; align-items: baseline; gap: 12px;
  }
  h2.sec .hint {
    font-family: var(--f-mono); font-size: 10.5px; letter-spacing: .06em;
    text-transform: none; color: var(--faint);
  }

  section { margin-bottom: 46px; }

  .btn {
    font-family: var(--f-display); font-weight: 600; font-size: 13px;
    padding: 8px 14px; border-radius: 3px; cursor: pointer;
    border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  }
  .btn:hover { background: var(--surface-2); }
  .btn.primary { background: var(--accent); border-color: var(--accent); color: var(--paper); }
  .btn.primary:hover { filter: brightness(1.08); }
  .btn.danger { color: var(--crit); border-color: var(--crit); background: transparent; }
  .btn.small { font-size: 12px; padding: 5px 10px; }

  .tag {
    display: inline-block;
    font-family: var(--f-mono); font-size: 10px; letter-spacing: .08em;
    text-transform: uppercase; padding: 3px 7px; border-radius: 2px;
    white-space: nowrap;
  }
  .tag.ide      { color: var(--muted); background: var(--surface-2); }
  .tag.forfragan{ color: var(--slate); background: var(--slate-bg); }
  .tag.avtal    { color: var(--accent); background: var(--accent-bg); }
  .tag.slappt   { color: var(--amber); background: var(--amber-bg); }
  .tag.spilt   { color: var(--ok); background: var(--ok-bg); }
  .tag.avbokad  { color: var(--crit); background: var(--crit-bg); }
  .tag.c        { color: var(--amber); background: var(--amber-bg); }
  .tag.t        { color: var(--accent); background: var(--accent-bg); }
  .tag.b        { color: var(--slate); background: var(--slate-bg); }

  .banner {
    display: flex; flex-wrap: wrap; align-items: center; gap: 12px;
    background: var(--warn-bg); color: var(--ink);
    border: 1px solid color-mix(in srgb, var(--warn) 32%, transparent);
    border-radius: 3px; padding: 11px 15px; margin-bottom: 24px;
    font-size: 15px;
  }
  .banner .grow { flex: 1 1 240px; }

  .empty {
    border: 1px dashed var(--line); border-radius: 3px;
    padding: 34px 26px; text-align: center; color: var(--muted);
    background: var(--surface);
  }
  .empty p { margin: 0 auto 16px; max-width: 46ch; }

  /* ---------- stat tiles ---------- */

  .tiles {
    display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
    gap: 14px; margin-bottom: 34px;
  }
  .tile {
    background: var(--surface); border: 1px solid var(--line);
    border-radius: 3px; padding: 17px 18px 18px; box-shadow: var(--shadow);
    display: flex; flex-direction: column; gap: 7px;
  }
  .tile .label {
    font-family: var(--f-mono); font-size: 10px; letter-spacing: .12em;
    text-transform: uppercase; color: var(--muted);
  }
  .tile .value {
    font-family: var(--f-display); font-weight: 700;
    font-size: 30px; line-height: 1; letter-spacing: -.025em;
    font-variant-numeric: tabular-nums;
  }
  .tile .sub { font-size: 14px; color: var(--muted); line-height: 1.35; }

  .meter { height: 7px; border-radius: 4px; background: var(--surface-2); overflow: hidden; }
  .meter > span { display: block; height: 100%; background: var(--accent); border-radius: 4px; }
  .meter.warn > span { background: var(--warn); }
  .meter.crit > span { background: var(--crit); }

  /* ---------- chart ---------- */

  svg g.hit rect { transition: fill .12s; }
  svg g.hit:hover rect { fill: color-mix(in srgb, var(--accent) 9%, transparent); }
  @media (prefers-reduced-motion: reduce) { svg g.hit rect { transition: none; } }

  .chartcard {
    background: var(--surface); border: 1px solid var(--line);
    border-radius: 3px; padding: 20px 22px 18px; box-shadow: var(--shadow);
  }
  .barrow {
    display: grid; grid-template-columns: 116px 1fr 96px;
    align-items: center; gap: 14px; padding: 9px 0;
  }
  .barrow .name { font-family: var(--f-display); font-weight: 600; font-size: 14px; }
  .barrow .track { height: 20px; background: var(--surface-2); border-radius: 3px; position: relative; }
  .barrow .fill { height: 100%; background: var(--accent); border-radius: 3px; min-width: 2px; }
  .barrow .num {
    text-align: right; font-family: var(--f-mono); font-size: 13px;
    font-variant-numeric: tabular-nums; color: var(--ink-2);
  }

  /* ---------- tables ---------- */

  .tablewrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 3px; background: var(--surface); }
  table { border-collapse: collapse; width: 100%; min-width: 780px; }
  th {
    font-family: var(--f-mono); font-size: 10px; letter-spacing: .1em;
    text-transform: uppercase; color: var(--muted); font-weight: 400;
    text-align: left; padding: 11px 12px; border-bottom: 1px solid var(--line);
    white-space: nowrap; background: var(--surface-2);
  }
  td {
    padding: 11px 12px; border-bottom: 1px solid var(--line-soft);
    font-size: 15px; vertical-align: middle;
  }
  tbody tr:last-child td { border-bottom: none; }
  tbody tr { cursor: pointer; }
  tbody tr:hover td { background: var(--surface-2); }
  td.num { text-align: right; font-size: 13.5px; font-variant-numeric: tabular-nums; white-space: nowrap; }
  td .place { font-family: var(--f-display); font-weight: 600; font-size: 14.5px; }
  td .sub { font-size: 13px; color: var(--muted); }
  td.date { font-family: var(--f-mono); font-size: 13px; white-space: nowrap; }

  .occ { display: flex; align-items: center; gap: 8px; justify-content: flex-end; }
  .occ .bar { width: 46px; height: 6px; border-radius: 3px; background: var(--surface-2); overflow: hidden; flex: none; }
  .occ .bar > span { display: block; height: 100%; background: var(--ok); }
  .occ .bar.warn > span { background: var(--warn); }
  .occ .bar.crit > span { background: var(--crit); }

  /* ---------- filters ---------- */

  .filters {
    display: flex; flex-wrap: wrap; gap: 9px; align-items: center; margin-bottom: 16px;
  }
  .filters input[type="search"], .filters select {
    background: var(--surface); border: 1px solid var(--line); border-radius: 3px;
    padding: 7px 10px; font-size: 14px; font-family: var(--f-display);
  }
  .filters input[type="search"] { min-width: 190px; flex: 1 1 190px; }
  .filters .spacer { flex: 1 1 auto; }

  .seg { display: inline-flex; border: 1px solid var(--line); border-radius: 3px; overflow: hidden; background: var(--surface); }
  .seg button {
    background: none; border: none; cursor: pointer; padding: 7px 18px;
    font-size: 13.5px; font-weight: 600; color: var(--muted);
  }
  .seg button + button { border-left: 1px solid var(--line); }
  .seg button:hover { background: var(--surface-2); color: var(--ink); }
  .seg button[aria-selected="true"] { background: var(--accent); color: var(--paper); }

  /* ---------- action list ---------- */

  .flags { display: flex; flex-direction: column; gap: 0; }
  .flag {
    display: grid; grid-template-columns: 22px 1fr auto; gap: 12px;
    align-items: baseline; padding: 12px 0; border-top: 1px solid var(--line-soft);
    cursor: pointer;
  }
  .flag:first-child { border-top: none; }
  .flag:hover .what { color: var(--accent); }
  .flag .mark { font-family: var(--f-mono); font-size: 13px; }
  .flag.crit .mark { color: var(--crit); }
  .flag.warn .mark { color: var(--warn); }
  .flag .what { font-family: var(--f-display); font-weight: 600; font-size: 15px; }
  .flag .who { font-size: 14px; color: var(--muted); }
  .flag .when { font-family: var(--f-mono); font-size: 12px; color: var(--muted); white-space: nowrap; }

  /* ---------- modal ---------- */

  .backdrop {
    position: fixed; inset: 0; background: rgba(10,18,16,.45);
    display: flex; align-items: flex-start; justify-content: center;
    padding: 40px 18px; overflow-y: auto; z-index: 50;
  }
  .modal {
    background: var(--surface); border: 1px solid var(--line);
    border-radius: 4px; box-shadow: var(--shadow-lg);
    width: 100%; max-width: 720px; padding: 24px 26px 22px;
  }
  .modal h3 {
    font-family: var(--f-display); font-size: 19px; font-weight: 700;
    margin: 0 0 18px; letter-spacing: -.015em;
  }
  .form { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px 16px; }
  .field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
  .field.wide { grid-column: 1 / -1; }
  .field label {
    font-family: var(--f-mono); font-size: 10px; letter-spacing: .1em;
    text-transform: uppercase; color: var(--muted);
  }
  .field input, .field select, .field textarea {
    background: var(--paper); border: 1px solid var(--line); border-radius: 3px;
    padding: 8px 10px; font-size: 15px; font-family: var(--f-display); width: 100%;
  }
  .field textarea { font-family: var(--f-body); resize: vertical; min-height: 66px; }
  .modal-actions {
    display: flex; gap: 10px; align-items: center;
    margin-top: 22px; padding-top: 18px; border-top: 1px solid var(--line-soft);
  }
  .modal-actions .spacer { flex: 1; }

  /* ---------- ansvar doc ---------- */

  .doc { max-width: 74ch; }
  .doc p { max-width: 68ch; }
  .constraint {
    background: var(--surface); border: 1px solid var(--line);
    border-left: 3px solid var(--amber); border-radius: 2px;
    padding: 18px 22px; box-shadow: var(--shadow); margin-bottom: 30px;
  }
  .constraint h3 { font-family: var(--f-display); font-size: 16px; font-weight: 600; margin: 0 0 6px; }
  .constraint p { margin: 0; }

  .area {
    display: grid; grid-template-columns: 180px 1fr; gap: 0 30px;
    padding: 22px 0; border-top: 1px solid var(--line-soft); align-items: start;
  }
  .area:first-of-type { border-top: 1px solid var(--line); }
  .area-head h3 {
    font-family: var(--f-display); font-size: 16px; font-weight: 600;
    line-height: 1.25; margin: 0 0 8px; text-wrap: balance;
  }
  .split { display: grid; grid-template-columns: 1fr 1fr; gap: 0 28px; }
  .lane { min-width: 0; }
  .lane .who {
    font-family: var(--f-mono); font-size: 10.5px; letter-spacing: .1em;
    text-transform: uppercase; margin: 0 0 6px; padding-bottom: 5px;
    border-bottom: 1px solid var(--line-soft);
  }
  .lane.c .who { color: var(--amber); }
  .lane.t .who { color: var(--accent); }
  .lane p { margin: 0; font-size: 15.5px; line-height: 1.5; }

  .rights { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
  .panel {
    background: var(--surface); border: 1px solid var(--line);
    border-radius: 3px; padding: 20px 22px 22px; box-shadow: var(--shadow);
  }
  .panel.c { border-top: 3px solid var(--amber); }
  .panel.t { border-top: 3px solid var(--accent); }
  .panel h3 { font-family: var(--f-display); font-size: 15.5px; font-weight: 600; margin: 0 0 12px; }
  .panel ul { margin: 0; padding: 0; list-style: none; }
  .panel li {
    font-size: 15.5px; line-height: 1.45; padding: 8px 0 8px 16px;
    border-top: 1px solid var(--line-soft); position: relative;
  }
  .panel li:first-child { border-top: none; padding-top: 0; }
  .panel li::before {
    content: ""; position: absolute; left: 1px; top: 1em;
    width: 5px; height: 5px; border-radius: 50%;
  }
  .panel li:first-child::before { top: .6em; }
  .panel.c li::before { background: var(--amber); }
  .panel.t li::before { background: var(--accent); }

  .plainlist { margin: 0; padding: 0; list-style: none; max-width: 72ch; }
  .plainlist li {
    padding: 10px 0 10px 24px; border-top: 1px solid var(--line-soft);
    position: relative; font-size: 15.5px;
  }
  .plainlist li:first-child { border-top: none; }
  .plainlist li::before {
    content: "→"; position: absolute; left: 0; top: 10px;
    color: var(--muted); font-family: var(--f-mono); font-size: 13px;
  }
  .plainlist.open li::before { content: "?"; color: var(--amber); }

  /* ---------- arkiv ---------- */

  .linkgrid { display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 14px; }
  .linkcard {
    background: var(--surface); border: 1px solid var(--line); border-radius: 3px;
    padding: 17px 18px; box-shadow: var(--shadow);
    display: flex; flex-direction: column; gap: 6px;
  }
  .linkcard .name { font-family: var(--f-display); font-weight: 600; font-size: 15.5px; }
  .linkcard .note { font-size: 14px; color: var(--muted); }
  .linkcard a { color: var(--accent); font-family: var(--f-mono); font-size: 12px; word-break: break-all; }
  .linkcard .row { display: flex; gap: 8px; margin-top: 4px; }

  .dropbox {
    background: var(--surface); border: 1px solid var(--line);
    border-left: 3px solid var(--accent); border-radius: 3px;
    padding: 20px 22px; box-shadow: var(--shadow); margin-bottom: 26px;
  }
  .dropbox h3 { font-family: var(--f-display); font-size: 17px; font-weight: 700; margin: 0 0 6px; }
  .dropbox p { margin: 0 0 14px; color: var(--muted); max-width: 62ch; }
  .dropbox .row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
  .dropbox input {
    flex: 1 1 300px; background: var(--paper); border: 1px solid var(--line);
    border-radius: 3px; padding: 9px 11px; font-family: var(--f-mono); font-size: 13px;
  }
  .dropbox .open {
    display: inline-flex; align-items: center; gap: 8px;
    font-family: var(--f-display); font-weight: 600; font-size: 14px;
    color: var(--paper); background: var(--accent); border-radius: 3px;
    padding: 9px 16px; text-decoration: none;
  }

  footer {
    margin-top: 56px; padding-top: 20px; border-top: 1px solid var(--line);
    font-family: var(--f-mono); font-size: 11px; letter-spacing: .07em;
    text-transform: uppercase; color: var(--faint);
    display: flex; flex-wrap: wrap; gap: 8px 26px;
  }

  @media (max-width: 820px) {
    .wrap { padding: 0 16px 70px; }
    .area { grid-template-columns: 1fr; gap: 12px; }
    .split { grid-template-columns: 1fr; gap: 16px; }
    .rights { grid-template-columns: 1fr; }
    .form { grid-template-columns: 1fr; }
    .barrow { grid-template-columns: 88px 1fr 78px; gap: 10px; }
  }

  @media (prefers-reduced-motion: reduce) {
    * { animation: none !important; transition: none !important; }
  }

/* ---------- server-rendered additions ---------- */

/* The tabs are real links now rather than buttons switching hidden panels, so
   each view has its own address and the back button works. They keep the
   button styling exactly. */
nav.tabs a {
  display: inline-block; text-decoration: none;
  font-family: var(--f-display); font-weight: 600; font-size: 13.5px;
  letter-spacing: .01em;
  padding: 11px 15px; color: var(--muted);
  border-bottom: 2px solid transparent; margin-bottom: -1px;
  border-radius: 2px 2px 0 0;
}
nav.tabs a:hover { color: var(--ink); background: var(--surface-2); }
nav.tabs a[aria-current="page"] { color: var(--ink); border-bottom-color: var(--accent); }

.seg a {
  display: inline-block; text-decoration: none;
  padding: 7px 18px; font-size: 13.5px; font-weight: 600; color: var(--muted);
}
.seg a + a { border-left: 1px solid var(--line); }
.seg a:hover { background: var(--surface-2); color: var(--ink); }
.seg a[aria-current="page"] { background: var(--accent); color: var(--paper); }

/* Row links. Table rows are clickable, and a row has to stay a row: the anchor
   covers the cell without changing how the table lays out. */
td a.rowlink { color: inherit; text-decoration: none; display: block; }

/* Field-level validation messages, which the artifact had no way to show --
   it silently accepted whatever was typed. */
.field .problem { font-size: 13px; color: var(--crit); }
.field.bad input, .field.bad select, .field.bad textarea { border-color: var(--crit); }

/* Who is signed in, and the way out. */
.whoami { display: flex; align-items: center; gap: 10px; }
.whoami .name { font-family: var(--f-mono); font-size: 11px; color: var(--muted); }
.whoami form { display: inline; }
.whoami button {
  background: none; border: none; cursor: pointer; padding: 0;
  font-family: var(--f-mono); font-size: 11px; color: var(--faint);
  text-decoration: underline; text-underline-offset: 2px;
}
.whoami button:hover { color: var(--ink); }

/* The sign-in page: one card, one button, nothing else to get wrong. */
.signin {
  max-width: 460px; margin: 12vh auto 0;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 4px; box-shadow: var(--shadow-lg); padding: 32px 34px 30px;
}
.signin h1 { font-family: var(--f-display); font-size: 22px; margin: 0 0 8px; letter-spacing: -.02em; }
.signin p { margin: 0 0 22px; color: var(--muted); }

/* htmx swaps the list in place; a brief fade keeps a filtered table from
   flickering as it is replaced. */
.htmx-swapping { opacity: .5; }
@media (prefers-reduced-motion: reduce) { .htmx-swapping { opacity: 1; } }

.sumlabel {
  font-family: var(--f-mono); font-size: 11px; letter-spacing: .09em;
  text-transform: uppercase; color: var(--muted);
}

.formhead {
  margin: 26px 0 8px; font-size: 11px; letter-spacing: .1em;
  text-transform: uppercase; color: var(--muted); font-weight: 700;
}
.formhead:first-of-type { margin-top: 0; }

footer .spacer { flex: 1 1 auto; }
footer a { color: var(--faint); text-decoration: none; }
footer a:hover { color: var(--ink); text-decoration: underline; text-underline-offset: 3px; }
