:root {
  --sidebar: #1b2633;
  --ground: #f3f5f8;
  --card: #ffffff;
  --border: #cbd2dc;
  --accent: #1d5fd1;
  --ok: #1e7b4f;
  --bad: #b23a2e;
  --warn: #b7791f;
  --text: #1b2633;
  --muted: #5b6774;
  --radius: 10px;
  --btn-gap: 8px;   /* 0.7.9: gap between adjacent buttons (CTpos UiMetrics.ButtonSpacing) */
  --font: 'IBM Plex Sans', system-ui, sans-serif;
  --mono: 'IBM Plex Mono', ui-monospace, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font-family: var(--font); font-size: 14px; color: var(--text); background: var(--ground); }
h1 { font-size: 22px; font-weight: 600; margin: 0 0 16px; }
h2 { font-size: 16px; font-weight: 600; margin: 0 0 12px; }
h3 { font-size: 14px; font-weight: 600; margin: 0 0 8px; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
p { margin: 0 0 8px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-family: var(--mono); }
.num { text-align: right; font-family: var(--mono); font-variant-numeric: tabular-nums; }
td.num { white-space: nowrap; }
.ok { color: var(--ok); }
.bad { color: var(--bad); }
.warn { color: var(--warn); }
.big { font-size: 28px; font-weight: 600; }
.nowrap { white-space: nowrap; }

/* Shell */
.shell { display: grid; grid-template-columns: 240px minmax(0, 1fr); min-height: 100vh; }
.sidebar { background: var(--sidebar); color: #fff; display: flex; flex-direction: column; padding: 20px 12px; position: sticky; top: 0; height: 100vh;; overflow-y: auto; overscroll-behavior: contain; scrollbar-width: thin; scrollbar-color: rgba(255,255,255,.28) transparent; }
/* The menu never overflows its dark background: with every group open the sidebar scrolls on its own (sticky, full height). */
.sidebar > * { flex-shrink: 0; }
.brand { padding: 4px 12px 20px; }
.brand-name { font-weight: 600; font-size: 16px; }
.brand-user { color: #a9b4c2; font-size: 12px; margin-top: 2px; }
.sidebar nav { display: flex; flex-direction: column; gap: 2px; flex: 1 0 auto; }
.nav-item { color: #d8dee8; padding: 8px 12px; border-radius: 6px; display: block; }
.nav-item:hover { background: rgba(255,255,255,.08); text-decoration: none; color: #fff; }
.nav-item.active { background: var(--accent); color: #fff; }
.nav-section { color: #8a97a8; font-size: 11px; letter-spacing: .08em; text-transform: uppercase; padding: 16px 12px 4px; }
.logout { padding: 8px 4px 0; }
.lang-switch { padding: 8px 8px 0; font-size: 13px; }
.lang-switch a { color: #d8dee8; opacity: .85; }
.logout .btn { color: #d8dee8; width: 100%; }
.content { padding: 28px 32px; max-width: 1400px; width: 100%; min-width: 0; }

/* Cards */
.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; margin-bottom: 16px; min-width: 0; overflow-wrap: break-word; }
.card.tight { padding: 12px 14px; }
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.cols-3 { display: grid; grid-template-columns: 260px 1fr 360px; gap: 16px; align-items: start; }
.cols-2 { display: grid; grid-template-columns: 1fr 420px; gap: 16px; align-items: start; }
.kpi .label { color: var(--muted); font-size: 12px; margin-bottom: 6px; }
.kpi .value { font-size: 26px; font-weight: 600; font-family: var(--mono); }
.kpi .sub { color: var(--muted); font-size: 12px; margin-top: 4px; }
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.toolbar .spacer { flex: 1; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.stack { display: flex; flex-direction: column; gap: 10px; }

/* Tables */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 8px 8px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { color: var(--muted); font-weight: 500; font-size: 12px; }
tr.clickable { cursor: pointer; }
tr.clickable:hover { background: #f7f9fc; }
tr.selected { background: #e9f0fc; }
td.actions { white-space: nowrap; text-align: right; }
/* 0.7.9: visible spacing between adjacent buttons where no flex gap applies; button rows wrap on narrow screens */
td.actions .btn + .btn { margin-left: var(--btn-gap); }
.btn-row { display: flex; flex-wrap: wrap; gap: var(--btn-gap); align-items: center; }

/* Forms */
label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 10px; }
label > input, label > select, label > textarea { margin-top: 4px; }
/* Text-like fields share one look with the dropdowns (select, below): same height, border, radius and focus ring.
   input[type=search] and the time/month types were missing here and rendered as native fields. */
input[type=text], input[type=number], input[type=email], input[type=password], input[type=date], input[type=tel], input[type=search],
input[type=time], input[type=month], input[type=datetime-local], input[type=url], input:not([type]), select, textarea {
  width: 100%; font: inherit; line-height: 1.3; color: var(--field-text, var(--text)); padding: 7px 12px; min-height: 36px;
  border: 1px solid var(--field-border, var(--border)); border-radius: 8px; background-color: var(--field-bg, #fff);
  transition: border-color .12s, box-shadow .12s;
}
input[type=search] { -webkit-appearance: none; appearance: none; }
/* Search fields say so: a magnifier in front of the text. */
input[type=search] {
  padding-left: 34px; background-repeat: no-repeat; background-position: 11px 50%; background-size: 15px 15px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%235b6774' stroke-width='2.2' stroke-linecap='round'%3E%3Ccircle cx='10.5' cy='10.5' r='6.5'/%3E%3Cpath d='M15.5 15.5 21 21'/%3E%3C/svg%3E");
}
input:hover:not(:disabled):not([type=checkbox]):not([type=radio]), textarea:hover:not(:disabled) { border-color: var(--field-border-hover, var(--accent)); }
input:not([type=checkbox]):not([type=radio]):focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--focus-ring, #c9d8f5); }
input[type=checkbox] { width: 16px; height: 16px; vertical-align: -3px; margin-right: 6px; }
input:disabled { background: #eef1f5; color: var(--muted); }
.check { display: flex; align-items: center; gap: 6px; font-size: 14px; color: var(--text); }
.inline-form { display: flex; gap: 8px; align-items: end; flex-wrap: wrap; }
.inline-form label { margin-bottom: 0; min-width: 120px; }
.validation-message { color: var(--bad); font-size: 12px; }

/* Buttons */
.btn { font: inherit; font-weight: 500; padding: 8px 14px; border-radius: 6px; border: 1px solid var(--border); background: #fff; color: var(--text); cursor: pointer; }
.btn:hover { background: #f3f5f8; }
.btn:disabled { opacity: .55; cursor: default; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: #174db0; }
.btn-danger { color: var(--bad); border-color: #e3c2be; }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-block { width: 100%; }
.stepper { display: inline-flex; align-items: center; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.stepper button { border: 0; background: #f3f5f8; width: 32px; height: 32px; font-size: 16px; cursor: pointer; }
.stepper span { width: 40px; text-align: center; font-family: var(--mono); }

/* Badges / alerts */
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 500; background: #e7ebf1; color: var(--text); }
.badge-ok { background: #e3f3ea; color: var(--ok); }
.badge-bad { background: #f8e4e1; color: var(--bad); }
.badge-warn { background: #f9efdc; color: var(--warn); }
.badge-accent { background: #e2ebfb; color: var(--accent); }
.chip { display: inline-block; padding: 4px 10px; border-radius: 999px; border: 1px solid var(--border); background: #fff; cursor: pointer; font-size: 12px; margin: 0 6px 6px 0; }
.chip.on { background: var(--accent); color: #fff; border-color: var(--accent); }
.alert { padding: 10px 12px; border-radius: 6px; margin-bottom: 12px; font-size: 13px; }
.alert-ok { background: #e3f3ea; color: var(--ok); }
.alert-bad { background: #f8e4e1; color: var(--bad); }
.alert-warn { background: #f9efdc; color: var(--warn); }
.alert-info { background: #e2ebfb; color: var(--accent); }
.code-big { font-family: var(--mono); font-size: 40px; font-weight: 600; letter-spacing: .08em; text-align: center; padding: 16px; background: #f3f5f8; border-radius: var(--radius); }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; }
.dot-ok { background: var(--ok); }
.dot-bad { background: var(--bad); }
.list { list-style: none; margin: 0; padding: 0; }
.list li { padding: 8px 0; border-bottom: 1px solid var(--border); }
.list li:last-child { border-bottom: 0; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; }
.tab { padding: 8px 14px; border: 0; background: transparent; font: inherit; cursor: pointer; color: var(--muted); border-bottom: 2px solid transparent; }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 500; }
.tree { list-style: none; margin: 0; padding: 0; }
.tree li { padding: 4px 0; }
.tree .mg { font-weight: 600; cursor: pointer; display: flex; justify-content: space-between; }
.tree .g { padding: 5px 8px 5px 16px; border-radius: 6px; cursor: pointer; display: flex; justify-content: space-between; }
.tree .g:hover { background: #f3f5f8; }
.tree .g.selected { background: #e2ebfb; color: var(--accent); }
.count { color: var(--muted); font-size: 12px; }
.sig { font-family: var(--mono); font-size: 11px; word-break: break-all; color: var(--muted); }

/* Operator impersonation bar */
.impersonation-bar { background: #fff3c4; border: 1px solid #e3c86b; color: #5a4300; border-radius: var(--radius); padding: 10px 14px; margin-bottom: 16px; display: flex; justify-content: space-between; align-items: center; }
.impersonation-bar a { font-weight: 600; }
.login-box { font-family: var(--mono); font-size: 13px; background: #f3f5f8; border: 1px solid var(--border); border-radius: 6px; padding: 10px 12px; white-space: pre-wrap; }

/* Login */
.login-shell { min-height: 100vh; display: grid; place-items: center; }
.login-card { width: 360px; }
.login-card h1 { margin-bottom: 4px; }
.login-card .btn { margin-top: 6px; }

#blazor-error-ui { background: #fff3cd; bottom: 0; box-shadow: 0 -1px 2px rgba(0,0,0,.2); display: none; left: 0; padding: .6rem 1.25rem .7rem 1.25rem; position: fixed; width: 100%; z-index: 1000; }
#blazor-error-ui .dismiss { cursor: pointer; position: absolute; right: .75rem; top: .5rem; }
.blazor-error-boundary { background: #b23a2e; padding: 1rem; color: white; }

/* Admin site additions */
.sidebar-admin { background: #10263d; }
.sql-editor { width: 100%; min-height: 160px; font-family: var(--mono); font-size: 13px; padding: 10px; border: 1px solid var(--border); border-radius: 6px; resize: vertical; }
.grid-scroll { overflow: auto; max-height: 60vh; border: 1px solid var(--border); border-radius: 6px; }
.grid-scroll table { font-size: 13px; }
.grid-scroll th { position: sticky; top: 0; background: #fff; }
.grid-scroll td { font-family: var(--mono); white-space: nowrap; max-width: 420px; overflow: hidden; text-overflow: ellipsis; }
.null { color: var(--muted); font-style: italic; }
.history li { cursor: pointer; font-family: var(--mono); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.history li:hover { color: var(--accent); }
th.sortable { cursor: pointer; }
th.sortable:hover { color: var(--accent); }
.modal-backdrop { position: fixed; inset: 0; background: rgba(27,38,51,.45); display: grid; place-items: center; z-index: 50; }
.modal { background: #fff; border-radius: var(--radius); padding: 20px 22px; width: 460px; border: 1px solid var(--border); }
/* Invoice header preview (Mine oplysninger) */
.inv-preview { background: #fff; color: #111; border: 1px solid var(--border); border-radius: 6px; padding: 16px; font-size: 12px; }
.inv-preview .inv-head { display: flex; justify-content: space-between; gap: 16px; margin-bottom: 16px; }
.inv-preview .inv-logo { display: block; max-width: 180px; max-height: 80px; margin-bottom: 8px; }
.inv-preview .inv-seller { text-align: right; line-height: 1.5; }
.inv-preview .pay { padding: 10px 12px; border: 1px solid #cbd2dc; border-radius: 6px; line-height: 1.5; }

/* Compact tables (Priser, company prices) */
table.compact th, table.compact td { padding: 6px 6px; }
table.compact td.actions { white-space: nowrap; }

/* Long names: one line with ellipsis; the full text is in the title tooltip. */
.truncate { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }
.toolbar .search { width: 240px; max-width: 100%; }

/* Virksomheder list: fixed columns that fit 1280 and up without cut text. */
table.company-list { table-layout: fixed; width: 100%; }
table.company-list col.c-name { width: auto; }
table.company-list col.c-cvr { width: 96px; }
table.company-list col.c-status { width: 150px; }
table.company-list col.c-plan { width: 110px; }
table.company-list col.c-count { width: 130px; }
table.company-list col.c-activity { width: 170px; }
table.company-list td, table.company-list th { overflow: hidden; }
.create-company { max-width: 920px; }

/* Company page header: name truncates instead of pushing the buttons off screen. */
.page-title { display: flex; align-items: center; gap: 8px; min-width: 0; flex: 1 1 320px; }
.page-title .truncate { display: inline-block; max-width: 60vw; }

@media (max-width: 1100px) {
  .cols-2 { grid-template-columns: 1fr; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 760px) {
  table.company-list, table.company-list tbody, table.company-list tr, table.company-list td { display: block; width: 100%; }
  table.company-list colgroup, table.company-list thead { display: none; }
  table.company-list tr { border-bottom: 1px solid var(--border); padding: 8px 0; }
  table.company-list td { border: 0; padding: 2px 4px; text-align: left; }
  table.company-list td[data-label]:not(:first-child)::before { content: attr(data-label) ": "; color: var(--muted, #6b7685); font-size: 12px; }
  .kpis { grid-template-columns: 1fr; }
  .toolbar .search { width: 100%; }
}

/* Grid columns may shrink below their content (default min-width:auto lets wide tables push the page sideways). */
.cols-2 > *, .cols-3 > *, .grid > * { min-width: 0; }
.table-wrap { overflow-x: auto; }
.table-wrap > table { min-width: 420px; }

/* Narrow screens: the menu moves to the top and scrolls sideways, so the page itself never does. */
@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; padding: 10px 12px; }
  /* The menu stays a column of collapsible groups (closed except the current page's, so it is short). */
  .sidebar nav { flex-direction: column; gap: 2px; }
  .sidebar .nav-section { padding-top: 8px; }
  .nav-group > summary.nav-section { padding: 10px 12px; min-height: 40px; }
  .sidebar .nav-item { white-space: nowrap; }
  .content { min-width: 0; }
}
@media (max-width: 900px) {
  .shell > * { min-width: 0; }
  .sidebar { overflow: hidden; }
  .sidebar nav { flex: none; max-width: 100%; }
  .sidebar .nav-item { flex: none; }
  .sidebar .logout { margin-top: 6px; }
  table.company-list { table-layout: auto; }
}

/* ---- Dropdowns (select): rounded, consistent padding, custom chevron, focus ring; colours from tokens ----
   Light values below; dark values apply under data-theme="dark" (the backoffice itself has no dark mode yet).
   Contrast (checked): text on field >= 4.5:1, border on surface >= 3:1, in both. */
:root {
  --field-bg: #ffffff;
  --field-text: #1b2633;
  --field-border: #76818f;
  --field-border-hover: #4f5b69;
  --field-chevron: #3d4957;
  --field-disabled-bg: #eef1f5;
  --field-disabled-text: #5b6774;
  --focus-ring: rgba(29, 95, 209, .35);
}
:root[data-theme="dark"] {
  --ground: #121a23;
  --card: #1b2530;
  --border: #3a4756;
  --text: #e6ebf1;
  --muted: #a3afbd;
  --accent: #6d9cf0;
  --field-bg: #222e3b;
  --field-text: #e6ebf1;
  --field-border: #7d8a99;
  --field-border-hover: #a3afbd;
  --field-chevron: #c4cdd8;
  --field-disabled-bg: #1b2530;
  --field-disabled-text: #a3afbd;
  --focus-ring: rgba(109, 156, 240, .45);
}
select {
  appearance: none; -webkit-appearance: none;
  min-height: 36px; padding: 7px 34px 7px 12px; border: 1px solid var(--field-border); border-radius: 8px;
  background-color: var(--field-bg); color: var(--field-text); font: inherit; line-height: 1.3; cursor: pointer;
  background-image: linear-gradient(45deg, transparent 50%, var(--field-chevron) 50%), linear-gradient(135deg, var(--field-chevron) 50%, transparent 50%);
  background-position: calc(100% - 17px) 52%, calc(100% - 12px) 52%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  transition: border-color .12s, box-shadow .12s;
}
select:hover:not(:disabled) { border-color: var(--field-border-hover); }
select:focus, select:focus-visible { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--focus-ring); }
select:disabled { background-color: var(--field-disabled-bg); color: var(--field-disabled-text); cursor: not-allowed; opacity: 1; }
select[multiple], select[size]:not([size="1"]) { padding-right: 12px; background-image: none; }
select option { background: var(--field-bg); color: var(--field-text); }
.line-row select, .btn-sm + select, select.sm { min-height: 30px; padding: 4px 28px 4px 8px; border-radius: 6px; background-position: calc(100% - 14px) 52%, calc(100% - 9px) 52%; }

/* ---- Key/value lists (.detail dl, dl.kv) ----
   Label column sized to the longest label (110-170px), value column may shrink (min-width:0) and long values wrap
   inside the card: X.500 DNs, e-mails, paths, fingerprints. In a narrow card (< 380px) the label goes above the value. */
.detail, .kv-host { container-type: inline-size; }
.detail dl, dl.kv { display: grid; grid-template-columns: minmax(110px, max-content) minmax(0, 1fr); gap: 6px 16px; margin: 0; align-items: baseline; }
.detail dl > dt, dl.kv > dt { color: var(--muted); font-size: 12px; max-width: 170px; }
.detail dl > dd, dl.kv > dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
@container (max-width: 380px) {
  .detail dl, dl.kv { grid-template-columns: minmax(0, 1fr); gap: 0; }
  .detail dl > dt, dl.kv > dt { margin-top: 8px; max-width: none; }
}
/* A distinguished name: one RDN per line (C=DK / O=… / SERIALNUMBER=… / CN=…). */
.dn { display: flex; flex-direction: column; gap: 1px; font-size: 12px; line-height: 1.45; }
.dn > span { overflow-wrap: anywhere; }
.dn .dn-key { color: var(--muted); }
/* Hashes, fingerprints, tokens, ids: monospace and allowed to break anywhere. */
.hash { font-family: var(--mono); font-size: 12px; overflow-wrap: anywhere; word-break: break-all; }
/* Table cells with long free text (DNs, audit details, file paths): wrap anywhere, but keep a readable width. */
td.long, th.long { overflow-wrap: anywhere; min-width: 14em; }
.table-wrap > table.company-list { min-width: 0; }
.modal { max-width: calc(100vw - 32px); overflow-wrap: break-word; }
.chain-item + .chain-item { margin-top: 6px; padding-top: 6px; border-top: 1px dashed var(--border); }

/* Database › Størrelse og diskplads: one block per disk with a usage meter (green, yellow over 80 %, red over 90 %). */
.disk { border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; margin-bottom: 10px; display: flex; flex-direction: column; gap: 4px; }
.disk strong { overflow-wrap: anywhere; }
.meter { height: 10px; border-radius: 999px; background: #e7ebf1; overflow: hidden; }
.meter > span { display: block; height: 100%; background: var(--ok); border-radius: 999px; }
.disk-warn { border-color: #e7c98f; background: #fdf8ee; }
.disk-warn .meter > span { background: var(--warn); }
.disk-critical { border-color: #e3b0a9; background: #fcf1ef; }
.disk-critical .meter > span { background: var(--bad); }
:root[data-theme="dark"] .meter { background: #2a3644; }
:root[data-theme="dark"] .disk-warn { background: #2b2516; }
:root[data-theme="dark"] .disk-critical { background: #2e1c1a; }
/* S5: one write-only token per environment. */
.token-field { border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; margin-bottom: 10px; display: flex; flex-direction: column; gap: 8px; }
.token-field label { margin-bottom: 0; }
/* Preformatted text (stack traces, logs, login boxes, SMS previews) never widens its card: long tokens wrap. */
pre { max-width: 100%; overflow-wrap: anywhere; }
.login-box, .receipt-paper { overflow-wrap: anywhere; max-width: 100%; }
.receipt-paper { white-space: pre-wrap; }
code { overflow-wrap: anywhere; }
.storage-grid { grid-template-columns: repeat(auto-fit, minmax(min(100%, 420px), 1fr)); }

/* Collapsible menu groups (accordion, nav.js) – same look as the backoffice. */
.nav-group > summary.nav-section { list-style: none; cursor: pointer; display: flex; justify-content: space-between; align-items: center; user-select: none; }
.nav-group > summary.nav-section::-webkit-details-marker { display: none; }
.nav-group > summary.nav-section::after { content: "▸"; font-size: 10px; opacity: .7; transition: transform .15s; }
.nav-group[open] > summary.nav-section::after { transform: rotate(90deg); }
.nav-group > summary.nav-section:hover { color: #fff; }
