:root {
  /* Groundley design tokens (groundley.com) */
  --olive: hsl(93 33% 27%);
  --olive-light: hsl(93 27% 39%);
  --olive-pale: hsl(90 30% 92%);
  --olive-mid: hsl(78 25% 75%);
  --amber: hsl(27 52% 46%);
  --amber-pale: hsl(33 85% 95%);
  --charcoal: hsl(90 7% 10%);
  --stone: hsl(36 17% 95%);
  --warm-white: hsl(40 20% 97%);
  --text-muted: hsl(60 5% 40%);
  --line: hsl(38 15% 84%);
  --card: #fff;
  --destructive: hsl(0 84% 60%);
  --radius: 0.5rem;
  --display: "Manrope", "Segoe UI", sans-serif;
  --sans: "Inter", "Segoe UI", sans-serif;
  --mono: "Fragment Mono", Consolas, monospace;
  --shadow-sm: 0 1px 2px rgba(26, 27, 24, 0.05);
  --shadow-md: 0 4px 16px rgba(26, 27, 24, 0.07);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 15px; }

html { height: 100%; overscroll-behavior: none; }

body {
  font-family: var(--sans);
  background: var(--warm-white);
  color: var(--charcoal);
  height: 100vh;
  height: 100dvh; /* track the iOS dynamic viewport so nothing hangs off-screen */
  overflow: hidden; /* the rail and results scroll independently, not the page */
  overscroll-behavior: none; /* no page rubber-banding on iOS */
  display: flex;
  flex-direction: column;
}

/* ── Masthead ─────────────────────────────── */

.masthead {
  flex: none;
  background: var(--card);
  border-bottom: 1px solid var(--line);
}
.masthead-inner {
  max-width: 1380px;
  margin: 0 auto;
  padding: 1.3rem 2rem;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 2rem;
  flex-wrap: wrap;
}
.masthead-title {
  display: flex;
  align-items: baseline;
  gap: 0.75rem;
}
.wordmark {
  font-family: var(--display);
  font-weight: 700;
  font-size: 1.45rem;
  letter-spacing: -0.02em;
  color: var(--olive);
}
.masthead h1 {
  font-family: var(--display);
  font-weight: 700;
  font-size: 1.45rem;
  letter-spacing: -0.02em;
  color: var(--charcoal);
}
.masthead h1::before {
  content: "·";
  margin-right: 0.75rem;
  color: var(--line);
  font-weight: 400;
}
.masthead-right {
  display: flex;
  align-items: center;
  gap: 1.1rem;
}
.lang-toggle {
  display: inline-flex;
  border: 1px solid var(--line);
  border-radius: 999px;
  overflow: hidden;
}
.lang-toggle button {
  font-family: var(--sans);
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  padding: 0.3rem 0.7rem;
  border: none;
  background: var(--card);
  color: var(--text-muted);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.lang-toggle button:hover { background: var(--stone); }
.lang-toggle button.active {
  background: var(--olive);
  color: #fff;
}
.masthead-sub {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.13em;
  color: var(--text-muted);
}
.live-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--olive-light);
  box-shadow: 0 0 0 3px var(--olive-pale);
}

/* ── Layout ───────────────────────────────── */

.layout {
  max-width: 1380px;
  width: 100%;
  margin: 0 auto;
  padding: 1.8rem 2rem;
  display: grid;
  grid-template-columns: 290px 1fr;
  gap: 1.8rem;
  flex: 1 1 auto;
  min-height: 0; /* allow children to own their scroll */
  align-items: stretch;
}

/* filter toggle + drawer backdrop only appear on mobile */
.filter-toggle { display: none; }
.rail-backdrop { display: none; }

@media (max-width: 820px) {
  .masthead-inner { padding: 0.9rem 1rem; gap: 0.5rem; }
  .masthead-title { gap: 0.55rem; }
  .masthead h1 { font-size: 1.15rem; }
  .masthead h1::before { margin-right: 0.55rem; }
  .wordmark { font-size: 1.15rem; }
  .masthead-sub { display: none; }

  .filter-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 34px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--card);
    color: var(--charcoal);
    cursor: pointer;
    flex: none;
  }
  .filter-toggle:active { background: var(--stone); }

  .layout {
    grid-template-columns: 1fr;
    padding: 0.8rem;
    gap: 0;
  }

  /* rail becomes a slide-in drawer */
  .rail {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: min(330px, 86vw);
    z-index: 60;
    border-radius: 0;
    border-left: none;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
  }
  .rail.open { transform: none; box-shadow: 6px 0 24px rgba(26, 27, 24, 0.25); }
  .rail { overscroll-behavior: none; touch-action: pan-y; }
  .rail-backdrop { display: block; position: fixed; inset: 0; background: rgba(26, 27, 24, 0.45); z-index: 55; touch-action: none; overscroll-behavior: none; }
  .rail-backdrop[hidden] { display: none; }

  .results-meta { margin-bottom: 0.6rem; }
  .meta-count { font-size: 1.05rem; }

  /* the results column scrolls vertically only — never sideways */
  .results-scroll { overflow-x: hidden; padding-right: 0; }
  .table-wrap { overflow: hidden; }

  /* fit the table to the screen width instead of overflowing */
  .ledger { table-layout: fixed; width: 100%; font-size: 0.82rem; }
  .ledger thead th, .ledger tbody td { padding: 0.5rem 0.5rem; }
  /* scope column widths to the data rows so the colspan detail cell isn't affected */
  .ledger th:nth-child(1), .ledger tr.company-row td:nth-child(1) { width: 4.7rem; }  /* CVR */
  .ledger th:nth-child(4), .ledger tr.company-row td:nth-child(4) { width: 9rem; }    /* Branche (tablet) */
  .ledger th:nth-child(6), .ledger tr.company-row td:nth-child(6) { width: 5rem; }    /* Status */
  .ledger th:nth-child(8), .ledger tr.company-row td:nth-child(8) { width: 4rem; }    /* Ansatte (tablet) */
  .ledger td.fin-cell { width: auto; }
  .cell-name { overflow-wrap: anywhere; }
  .cell-name .site-link { max-width: 100%; }
  .badge { white-space: normal; }

  /* trim lower-value columns: hide Form (3), Kommune (5), Stiftet (7) */
  .ledger th:nth-child(3), .ledger td:nth-child(3),
  .ledger th:nth-child(5), .ledger td:nth-child(5),
  .ledger th:nth-child(7), .ledger td:nth-child(7) { display: none; }
}

@media (max-width: 480px) {
  /* very narrow: also hide Branche (4) and Ansatte (8) — keep CVR, Virksomhed, Status */
  .ledger th:nth-child(4), .ledger td:nth-child(4),
  .ledger th:nth-child(8), .ledger td:nth-child(8) { display: none; }
  .cell-name .site-link { max-width: 60vw; }
}

/* ── Filter rail ──────────────────────────── */

.rail {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: calc(var(--radius) + 4px);
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}
.rail form {
  display: flex;
  flex-direction: column;
  min-height: 0;
  height: 100%;
}
.rail-scroll {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain; /* no rubber-band bleeding to the page on iOS */
  -webkit-overflow-scrolling: touch;
  padding: 1.4rem 1.3rem 0.4rem;
}
.rail-foot {
  flex: none;
  padding: 0.4rem 1.3rem 1.4rem;
  border-top: 1px solid var(--line);
  background: var(--card);
}
.rail-foot .rail-actions { margin-top: 0.9rem; }

.field { margin-bottom: 0.95rem; flex: 1; min-width: 0; }
.field label {
  display: block;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 0.35rem;
}
.field label small {
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
  color: var(--text-muted);
  opacity: 0.75;
}
.field input,
.field select {
  width: 100%;
  min-width: 0;
  max-width: 100%;
  font-family: var(--sans);
  font-size: 0.92rem;
  padding: 0.5rem 0.65rem;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--charcoal);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.field input::placeholder { color: var(--text-muted); opacity: 0.6; }
.field input:focus,
.field select:focus {
  outline: none;
  border-color: var(--olive);
  box-shadow: 0 0 0 3px var(--olive-pale);
}
.field-search input {
  font-size: 1rem;
  padding: 0.65rem 0.75rem;
  background: var(--stone);
}
.field-row { display: flex; gap: 0.7rem; }
.field-narrow { flex: 0 0 84px; }

.rail-rule {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin: 1.2rem 0 1rem;
  color: var(--olive);
  font-size: 0.66rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.16em;
}
.rail-rule::before,
.rail-rule::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--line);
}

.rail-actions { display: flex; gap: 0.7rem; margin-top: 1.1rem; }

.btn {
  font-family: var(--sans);
  font-size: 0.88rem;
  font-weight: 600;
  padding: 0.55rem 1.1rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card);
  color: var(--charcoal);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, box-shadow 0.15s;
}
.btn:hover { background: var(--stone); border-color: var(--olive-mid); }
.btn:active { box-shadow: inset 0 1px 3px rgba(26, 27, 24, 0.12); }
.btn-primary {
  flex: 1;
  background: var(--olive);
  border-color: var(--olive);
  color: #fff;
  box-shadow: var(--shadow-sm);
}
.btn-primary:hover { background: var(--olive-light); border-color: var(--olive-light); }
.btn-ghost { color: var(--text-muted); }
.btn-export {
  width: 100%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  background: var(--charcoal);
  border-color: var(--charcoal);
  color: #fff;
}
.btn-export:hover { background: hsl(90 7% 18%); border-color: hsl(90 7% 18%); }
.btn-export:disabled { opacity: 0.55; cursor: wait; }

/* ── Results ──────────────────────────────── */

.results {
  min-width: 0;
  min-height: 0;
  height: 100%;
  display: flex;
  flex-direction: column;
}
.results-scroll {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto; /* the results list scrolls here, not the page */
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding-right: 0.3rem;
}

/* ── Scrollbars: hidden until you hover the scrollable area ── */
.results-scroll, .rail-scroll, .fin-table-scroll {
  scrollbar-width: thin;
  scrollbar-color: transparent transparent; /* Firefox: invisible until hover */
}
.results-scroll:hover, .rail-scroll:hover, .fin-table-scroll:hover {
  scrollbar-color: rgba(26, 27, 24, 0.28) transparent;
}
.results-scroll::-webkit-scrollbar,
.rail-scroll::-webkit-scrollbar,
.fin-table-scroll::-webkit-scrollbar { width: 10px; height: 10px; }
.results-scroll::-webkit-scrollbar-thumb,
.rail-scroll::-webkit-scrollbar-thumb,
.fin-table-scroll::-webkit-scrollbar-thumb {
  background-color: transparent; /* gutter stays, thumb invisible — no layout shift */
  border: 3px solid transparent;
  background-clip: content-box;
  border-radius: 8px;
  transition: background-color 0.2s;
}
.results-scroll:hover::-webkit-scrollbar-thumb,
.rail-scroll:hover::-webkit-scrollbar-thumb,
.fin-table-scroll:hover::-webkit-scrollbar-thumb {
  background-color: rgba(26, 27, 24, 0.28);
}
.results-scroll::-webkit-scrollbar-track,
.rail-scroll::-webkit-scrollbar-track,
.fin-table-scroll::-webkit-scrollbar-track { background: transparent; }

.results-meta {
  flex: none;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.8rem;
  flex-wrap: wrap;
}
.meta-count {
  font-family: var(--display);
  font-size: 1.3rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}
.meta-count strong { color: var(--olive); }
.meta-took {
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--text-muted);
}
.count-prog {
  font-family: var(--mono);
  font-weight: 400;
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-left: 0.4rem;
}

.table-wrap {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: calc(var(--radius) + 4px);
  box-shadow: var(--shadow-md);
  position: relative;
}

.ledger {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}
.ledger thead th {
  font-size: 0.66rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  text-align: left;
  color: var(--text-muted);
  background: var(--stone);
  border-bottom: 1px solid var(--line);
  padding: 0.65rem 0.8rem;
  white-space: nowrap;
  position: sticky;
  top: 0;
  z-index: 1;
}
.ledger tbody td {
  padding: 0.62rem 0.8rem;
  border-bottom: 1px solid var(--stone);
  vertical-align: top;
}
.ledger tbody tr {
  transition: background 0.1s;
  animation: row-in 0.25s ease both;
}
.ledger tbody tr.company-row:hover { background: var(--olive-pale); }

@keyframes row-in {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: none; }
}

.col-cvr, td.cell-cvr { white-space: nowrap; }
.cell-cvr a {
  font-family: var(--mono);
  font-size: 0.82rem;
  color: var(--olive);
  text-decoration: none;
  border-bottom: 1px dotted var(--olive-mid);
}
.cell-cvr a:hover { color: var(--olive-light); border-bottom-style: solid; }

.cell-name { font-weight: 600; }
.cell-name .addr {
  display: block;
  font-weight: 400;
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: 0.15rem;
}
.cell-name .site-link {
  display: inline-block;
  font-weight: 400;
  font-size: 0.76rem;
  color: var(--olive);
  text-decoration: none;
  border-bottom: 1px dotted var(--olive-mid);
  margin-top: 0.15rem;
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  vertical-align: bottom;
}
.cell-name .site-link:hover { color: var(--olive-light); border-bottom-style: solid; }
.cell-name .fin-inline {
  display: block;
  font-weight: 500;
  font-size: 0.76rem;
  font-family: var(--mono);
  color: var(--olive);
  margin-top: 0.2rem;
}

.fin-filter-hint {
  font-size: 0.72rem;
  line-height: 1.45;
  color: var(--text-muted);
  margin: -0.3rem 0 0.9rem;
}
.fin-range::-webkit-outer-spin-button,
.fin-range::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

.cell-industry .code {
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--text-muted);
  opacity: 0.8;
  display: block;
}
.col-num, td.cell-num {
  text-align: right;
  font-family: var(--mono);
  font-size: 0.8rem;
  white-space: nowrap;
}

.badge {
  display: inline-block;
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  padding: 0.18rem 0.55rem;
  border-radius: 999px;
  white-space: nowrap;
}
.badge-active { color: var(--olive); background: var(--olive-pale); }
.badge-dead { color: var(--text-muted); background: var(--stone); }
.badge-warn { color: var(--amber); background: var(--amber-pale); }

.state-panel {
  padding: 3.5rem 2rem;
  text-align: center;
  font-family: var(--display);
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--text-muted);
}
.state-panel.error { color: var(--destructive); }

/* ── Cookie consent ───────────────────────── */
.consent {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 80;
  background: var(--card);
  border-top: 1px solid var(--line);
  box-shadow: 0 -2px 14px rgba(26, 27, 24, 0.10);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  flex-wrap: wrap;
  padding: 0.8rem 1.1rem;
  font-size: 0.85rem;
  color: var(--charcoal);
}
.consent[hidden] { display: none; }
.consent-text { max-width: 64ch; }
.consent-actions { display: flex; gap: 0.5rem; flex-shrink: 0; }
.consent .btn { flex: none; padding: 0.45rem 1.1rem; }

/* ── Export loader ────────────────────────── */

.export-overlay {
  position: fixed;
  inset: 0;
  background: rgba(26, 27, 24, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  backdrop-filter: blur(2px);
}
.export-overlay[hidden] { display: none; }
.export-modal {
  background: var(--card);
  border-radius: calc(var(--radius) + 4px);
  box-shadow: var(--shadow-md);
  padding: 2rem 2.4rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.1rem;
  min-width: 280px;
  max-width: 90vw;
  text-align: center;
}
.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--olive-pale);
  border-top-color: var(--olive);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.export-msg {
  font-family: var(--display);
  font-weight: 600;
  font-size: 1rem;
  color: var(--charcoal);
}

/* ── Infinite scroll ──────────────────────── */

.scroll-status {
  min-height: 1.2rem;
  padding: 0.8rem 0.2rem 0;
  text-align: center;
  font-size: 0.78rem;
  color: var(--text-muted);
}
.scroll-sentinel { height: 1px; }

/* ── Footer ───────────────────────────────── */

.colophon {
  max-width: 1380px;
  width: 100%;
  margin: 0 auto;
  padding: 1.2rem 2rem 2rem;
  font-size: 0.74rem;
  line-height: 1.55;
  color: var(--text-muted);
  border-top: 1px solid var(--line);
}

.loading .ledger tbody { opacity: 0.4; }

/* ── SEO content (crawlable) ──────────────── */
.seo-content {
  max-width: 760px;
  margin: 1rem auto 2rem;
  padding: 1.4rem 1.6rem;
  color: var(--text-muted);
  font-size: 0.86rem;
  line-height: 1.6;
}
.seo-content h2 {
  font-family: var(--display);
  font-size: 1.1rem;
  color: var(--charcoal);
  margin-bottom: 0.6rem;
}
.seo-content h3 {
  font-family: var(--display);
  font-size: 0.92rem;
  color: var(--charcoal);
  margin: 1rem 0 0.4rem;
}
.seo-content p { margin-bottom: 0.7rem; }
.seo-content ul { margin: 0 0 0.7rem 1.1rem; }
.seo-content li { margin-bottom: 0.2rem; }
.seo-content a { color: var(--olive); }

/* ── Export options ───────────────────────── */

.check-field {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  margin: 0 0 0.9rem;
  font-size: 0.8rem;
  cursor: pointer;
  color: var(--text-muted);
}
.check-field input {
  accent-color: var(--olive);
  margin-top: 0.15rem;
  flex-shrink: 0;
}
.check-field small {
  display: block;
  opacity: 0.8;
}

/* ── Financial detail row ─────────────────── */

.company-row { cursor: pointer; }
.company-row.expanded { background: var(--olive-pale); }
.company-row.expanded td { border-bottom-color: transparent; }

.fin-row td {
  padding: 0;
  border-bottom: 1px solid var(--line);
  background: var(--stone);
}
.fin-panel {
  padding: 0.9rem 1rem 1rem;
  border-left: 3px solid var(--olive);
  animation: row-in 0.2s ease both;
}
.fin-table-scroll {
  overflow-x: auto; /* the 7-col figures table swipes horizontally on narrow screens */
  -webkit-overflow-scrolling: touch;
}
.fin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
}
.fin-table th {
  font-size: 0.64rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  text-align: right;
  color: var(--text-muted);
  border-bottom: 1px solid var(--line);
  padding: 0.3rem 0.6rem;
}
.fin-table th:first-child { text-align: left; }
.fin-table td {
  font-family: var(--mono);
  font-size: 0.76rem;
  text-align: right;
  padding: 0.35rem 0.6rem;
  border-bottom: 1px solid var(--line);
}
.fin-table td:first-child { text-align: left; }
.fin-na { color: var(--text-muted); opacity: 0.6; }
.fin-empty, .fin-error { font-size: 0.84rem; color: var(--text-muted); }
.fin-error { color: var(--destructive); }
.fin-note {
  margin-top: 0.5rem;
  font-size: 0.7rem;
  color: var(--text-muted);
  opacity: 0.85;
}
