/* Tunnelwright's shared look, for the panel and the users' portal (plan
   0.4 P21): colours and fonts as variables, light and dark (the panel's
   data-theme on <html>: light, dark, or system, which follows
   prefers-color-scheme; the portal always follows the system), text
   contrast at least WCAG AA (4.5:1, large and UI parts 3:1; checked by
   TestContrast), focus visible for the keyboard, logical properties only
   (dir="rtl" mirrors it), a status never only its colour. The panel's
   own layout is app.css, the portal's portal.css. An organization's
   branding, when it comes, replaces --accent and --focus (in both
   themes) and the logo, nothing else. */

:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #eef0f4;
  --text: #1b1f24;          /* 15.9:1 on --bg */
  --muted: #555e6b;         /* 6.3:1 on --surface */
  --border: #d4d8df;
  --accent: #1f5fbf;        /* 5.6:1 on --surface */
  --accent-text: #ffffff;
  --ok: #1d7a3a;            /* 5.2:1 */
  --warn: #8a5a00;          /* 5.5:1 */
  --error: #b42318;         /* 6.0:1 */
  --error-text: #ffffff;    /* on --error: 6.6:1 */
  --ok-bg: #e6f4ea;
  --warn-bg: #fdf3dc;
  --error-bg: #fde8e6;
  --focus: #1f5fbf;
  --radius: 6px;
  --gap: 16px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
  --mono: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111418;
  --surface: #1a1e24;
  --surface-2: #232830;
  --text: #e8ebef;        /* 14.8:1 on --bg */
  --muted: #a3acb8;       /* 7.4:1 on --surface */
  --border: #343b45;
  --accent: #7aa7ff;      /* 7.0:1 on --surface */
  --accent-text: #0d1117;
  --ok: #6fd28d;
  --warn: #e7b84c;
  --error: #ff8a80;
  --error-text: #0d1117;  /* on --error: 8.3:1 */
  --ok-bg: #16301f;
  --warn-bg: #33290f;
  --error-bg: #3a1a18;
  --focus: #7aa7ff;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]):not([data-theme="dark"]) {
    color-scheme: dark;
    --bg: #111418;
    --surface: #1a1e24;
    --surface-2: #232830;
    --text: #e8ebef;        /* 14.8:1 on --bg */
    --muted: #a3acb8;       /* 7.4:1 on --surface */
    --border: #343b45;
    --accent: #7aa7ff;      /* 7.0:1 on --surface */
    --accent-text: #0d1117;
    --ok: #6fd28d;
    --warn: #e7b84c;
    --error: #ff8a80;
    --error-text: #0d1117;  /* on --error: 8.3:1 */
    --ok-bg: #16301f;
    --warn-bg: #33290f;
    --error-bg: #3a1a18;
    --focus: #7aa7ff;
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { font-size: 15px; }
body {
  margin: 0;
  font-family: var(--font);
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
}

a { color: var(--accent); }
a:hover { text-decoration-thickness: 2px; }

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.skip {
  position: absolute;
  inset-inline-start: -9999px;
}
.skip:focus { inset-inline-start: var(--gap); top: var(--gap); background: var(--surface); padding: 8px 12px; z-index: 10; }


/* the menu is a <details> drawer (plan 0.4 P14): on a narrow screen its
   ☰ opens it, and a link's new page starts with it closed; on a wide
   screen it is always open, without its toggle, where the browser can
   style the details' content (::details-content); elsewhere the toggle
   stays and the menu opens with it */
.drawer { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; gap: 4px; }
.drawer[open] { overflow-y: auto; }
.drawer-toggle { cursor: pointer; padding: 8px 10px; border-radius: var(--radius); font-weight: 600; list-style: none; }
.drawer-toggle::-webkit-details-marker { display: none; }
.drawer-toggle:hover { background: var(--surface-2); }
@supports selector(::details-content) {
  @media (min-width: 761px) {
    .drawer > .drawer-toggle { display: none; }
    .drawer::details-content { content-visibility: visible; display: contents; }
  }
}

.center .logo { display: flex; justify-content: center; margin-bottom: var(--gap); }
.center .logo img { height: 48px; width: auto; max-width: 100%; }
/* the product's logo and mark in the chosen theme's version */
img.on-light { display: block; }
img.on-dark { display: none; }
:root[data-theme="dark"] img.on-light { display: none; }
:root[data-theme="dark"] img.on-dark { display: block; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]):not([data-theme="dark"]) img.on-light { display: none; }
  :root:not([data-theme="light"]):not([data-theme="dark"]) img.on-dark { display: block; }
}

h1 { font-size: 1.5rem; margin: 0 0 var(--gap); }
h2 { font-size: 1.15rem; margin: calc(var(--gap) * 1.5) 0 var(--gap); }

/* cards and grids */
/* margin-bottom: a chart or table right below keeps off the cards */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: var(--gap); margin-bottom: var(--gap); }
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--gap);
}
.card .label { color: var(--muted); font-size: 0.85rem; }
.card .value { font-size: 1.6rem; font-weight: 650; }

/* tables */
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: start; padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-weight: 600; color: var(--muted); font-size: 0.85rem; background: var(--surface-2); }
/* a row's name (th scope=row) is a cell like the others: the table's ground, the
   text's size and colour (a link stays a link); only a grid's (.scroll) is a
   header. A row is one height, its cells in the middle (plan 0.4, the
   owner's finding of 2026-11-25) */
.table-wrap:not(.scroll) tbody th[scope="row"] { font-weight: 400; color: var(--text); font-size: inherit; background: none; }
.table-wrap:not(.scroll) tbody :is(td, th) { vertical-align: middle; }
/* a state's badge keeps its line; the detail under it may wrap */
.status { white-space: nowrap; }
td.state { white-space: normal; }
/* the buttons of a row: a table cell (so the row's lines meet), the
   buttons in the line with a gap; groups (.btn-row: a device's download,
   then Block and Remove) one under another, apart */
td.actions { display: table-cell; }
td.actions > :is(a, button, form) { display: inline-block; margin-block: 2px; margin-inline: 0 6px; }
td.actions .btn-row { display: flex; flex-wrap: wrap; gap: 8px; }
td.actions .btn-row + .btn-row { margin-block-start: 8px; padding-block-start: 8px; border-block-start: 1px dashed var(--border); }
td.actions .btn-row form { display: inline; }
tbody tr:last-child :is(td, th) { border-bottom: 0; }
td.num, th.num { text-align: end; font-variant-numeric: tabular-nums; }
th, td { white-space: nowrap; }
/* a narrow screen shows each row as a card, every value under its column's
   name (data-label, a line of its own: a long name in any language never
   covers the next one), so actions are never off the screen; only a grid
   (.scroll: the access matrix) scrolls sideways */
@media (max-width: 760px) {
  .table-wrap:not(.scroll) { background: none; border: 0; border-radius: 0; overflow: visible; }
  .table-wrap:not(.scroll) thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
  .table-wrap:not(.scroll) :is(table, tbody, td, th[scope="row"]) { display: block; }
  /* two values a line; the first (the row's name), actions and forms a line each */
  .table-wrap:not(.scroll) tr {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    column-gap: 12px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 6px 12px;
    margin-bottom: 10px;
  }
  .table-wrap:not(.scroll) :is(td, th[scope="row"]) { border: 0; padding: 6px 0; white-space: normal; overflow-wrap: break-word; text-align: start; max-width: none; min-width: 0; font-size: 0.95rem; }
  .table-wrap:not(.scroll) tbody th[scope="row"] { color: var(--text); background: none; font-size: 1rem; font-weight: 600; }
  .table-wrap:not(.scroll) td[data-label]::before {
    content: attr(data-label);
    display: block;
    color: var(--muted); font-size: 0.8rem; font-weight: 600;
  }
  .table-wrap:not(.scroll) :is(td:first-child, th[scope="row"], td.actions, td.state, td:has(form, select, code)) { grid-column: 1 / -1; }
  .table-wrap:not(.scroll) td.actions { display: flex; flex-wrap: wrap; gap: 8px; padding-top: 10px; }
  .table-wrap:not(.scroll) td.actions > :is(a, button, form) { margin: 0; }
  .table-wrap:not(.scroll) td.actions:has(> .btn-row) { flex-direction: column; align-items: stretch; gap: 0; }
  /* a long badge ("Required, not set up yet") may wrap on a phone */
  .status { white-space: normal; }
}

/* a status: the word carries it, the mark only repeats it */
.status { display: inline-flex; align-items: center; gap: 6px; font-weight: 600; }
.status::before { content: ""; width: 0.6em; height: 0.6em; border-radius: 50%; background: currentColor; flex: none; }
.status.ok { color: var(--ok); }
.status.warn { color: var(--warn); }
.status.warn::before { border-radius: 0; transform: rotate(45deg); }
.status.error { color: var(--error); }
.status.error::before { border-radius: 0; }
.status.off { color: var(--muted); }
.status.off::before { background: transparent; border: 2px solid currentColor; }
/* invited: the account exists, its password is not set yet (accent, a ring with a dot) */
.status.invited { color: var(--accent); }
.status.invited::before { background: radial-gradient(currentColor 30%, transparent 32%); border: 2px solid currentColor; box-sizing: border-box; width: 0.75em; height: 0.75em; }

/* notices */
.notice { border-radius: var(--radius); padding: 12px 14px; margin: 0 0 var(--gap); border: 1px solid; }
.notice.error { background: var(--error-bg); border-color: var(--error); }
.notice.warn { background: var(--warn-bg); border-color: var(--warn); }
.notice.ok { background: var(--ok-bg); border-color: var(--ok); }
.notice strong { display: block; }

/* forms: every control has its label */
form.stack { display: grid; gap: var(--gap); max-width: 520px; }
/* align-content: in a row of fields the tallest (a longer hint) sets the
   height; the others keep their label and input at the top */
.field { display: grid; gap: 6px; align-content: start; }
.field label { font-weight: 600; }
.field .hint { color: var(--muted); font-size: 0.9rem; }
.field .error { color: var(--error); font-weight: 600; }
input[type="text"], input[type="search"], input[type="email"], input[type="password"], input[type="number"], input[type="date"], select, textarea {
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 10px;
  width: 100%;
}
/* one height for every one-line field: on its own a select is lower and a
   date field (its picker) higher than a text field */
input:is([type="text"], [type="search"], [type="password"], [type="number"], [type="date"]), select:not([multiple]) { height: calc(1.5em + 18px); }
input[aria-invalid="true"] { border-color: var(--error); border-width: 2px; }
fieldset { border: 1px solid var(--border); border-radius: var(--radius); padding: var(--gap); }
legend { font-weight: 600; padding: 0 6px; }
details > summary { cursor: pointer; font-weight: 600; }

button, .button {
  font: inherit;
  font-weight: 600;
  border-radius: var(--radius);
  padding: 8px 14px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: var(--accent-text);
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
}
button.secondary, .button.secondary { background: transparent; color: var(--accent); }
button.danger, .button.danger { background: var(--error); border-color: var(--error); color: var(--error-text); }
/* red: a step that takes access away for good; outlined (Block: the device stays listed) or filled (Remove, Delete) */
button.danger.secondary, .button.danger.secondary { background: transparent; border-color: var(--error); color: var(--error); }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.actions form { display: inline; }
button.link { background: none; border: 0; padding: 0; color: var(--accent); text-decoration: underline; font-weight: 400; }

/* sign-in and the first run: one centred card */
.center { min-height: 100vh; display: grid; place-items: center; align-content: center; padding: var(--gap); }
.center .card { width: 100%; max-width: 420px; padding: calc(var(--gap) * 1.5); }

/* code, secrets and diffs */
pre, code { font-family: var(--mono); font-size: 0.9rem; }
pre { background: var(--surface-2); padding: 12px; border-radius: var(--radius); overflow-x: auto; }
.secret { font-family: var(--mono); letter-spacing: 0.05em; word-break: break-all; }
.codes { columns: 2; font-family: var(--mono); }
ins { background: var(--ok-bg); text-decoration: none; }
del { background: var(--error-bg); }
.muted { color: var(--muted); }
.source { color: var(--muted); font-size: 0.85rem; font-style: italic; }
.source::before { content: "· "; }
.qr { width: 220px; height: 220px; background: #fff; padding: 8px; border-radius: var(--radius); }

.card .value .of { color: var(--muted); font-size: 1rem; font-weight: 400; }
.empty { color: var(--muted); }
.small { font-size: 0.85rem; }
button.small { padding: 4px 10px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.tag { display: inline-block; font-size: 0.8rem; padding: 1px 8px; border-radius: 999px; border: 1px solid var(--border); color: var(--muted); }
/* settings rows (panel and portal, plan 0.4): a label of fixed width, the
   value, an action at the row's end (.row-action), a line between rows;
   on a narrow screen the label above the value and the action below it.
   Words break only when one alone is wider than the row; a long single
   value (an e-mail) is .one-line: cut with "…", the whole in its title */
dl.facts { display: grid; grid-template-columns: minmax(9rem, 14rem) minmax(0, 1fr); margin: 0; }
dl.facts > dt, dl.facts > dd { padding-block: 10px; border-block-start: 1px solid var(--border); }
dl.facts > dt:first-of-type, dl.facts > dt:first-of-type + dd { border-block-start: 0; padding-block-start: 0; }
dl.facts > dt { color: var(--muted); padding-inline-end: 16px; }
dl.facts > dd { margin: 0; min-width: 0; overflow-wrap: break-word; }
dl.facts > dd > .row-action { float: inline-end; margin-inline-start: 12px; }
/* a state's detail under its badge: when it began or ends ("since today, 19:31 CET") */
.state-detail { color: var(--muted); font-size: 0.9rem; font-weight: 400; margin-block-start: 2px; }
.one-line { display: inline-block; max-width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; vertical-align: bottom; }
@media (max-width: 600px) {
  dl.facts { grid-template-columns: minmax(0, 1fr); }
  dl.facts > dt { padding-block-end: 2px; font-size: 0.85rem; }
  dl.facts > dd { border-block-start: 0; padding-block-start: 0; }
  dl.facts > dt:first-of-type + dd { padding-block-start: 0; }
  dl.facts > dd:has(> .row-action) { display: flex; flex-direction: column; align-items: flex-start; }
  dl.facts > dd > .row-action { float: none; order: 1; margin-inline-start: 0; margin-block-start: 8px; }
}
/* a button under a list of facts (the portal's profile) keeps the cards' gap */
dl.facts + .actions { margin-block-start: var(--gap); }
/* the way back above a page's title (panel and portal) */
.crumbs { margin: 0 0 4px; color: var(--muted); font-size: 0.9rem; }
.crumbs a::before { content: "←\00a0"; }
.crumbs a:dir(rtl)::before { content: "→\00a0"; }
/* cards of sections one under another keep the gap; a card's title starts at its top (panel and portal) */
section.card + section.card { margin-block-start: var(--gap); }
section.card > h2:first-child { margin-block-start: 0; }
td.actions { white-space: normal; }
/* a long value (a fingerprint, a link) breaks anywhere rather than leave the screen */
code.wrap { overflow-wrap: anywhere; }
pre.wrap { white-space: pre-wrap; overflow-wrap: anywhere; }
.center .foot { display: flex; flex-direction: column; align-items: center; gap: 8px; margin-top: var(--gap); }
/* the maker's mark: quiet */
a.vendor { display: block; color: var(--muted); font-size: 0.8rem; text-decoration: none; }
a.vendor:hover, a.vendor:focus-visible { text-decoration: underline; }

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