/* The portal's stylesheet, in the product's design language: the colour and type tokens of the Workbench's theme
   (AddCAT engineering/addcat/theme.py, palettes _LIGHT and _DARK; engineering/addcat_fluent/styles.py and geometry.py
   for the type, the radii and the spacing), copied as they are; the light palette by default, the dark one when the
   browser prefers it. No framework. Every page fits a phone: a 16 px gutter, nothing wider than the screen, long words
   (an address, a label, an id) broken rather than scrolled; inputs at 16 px below 640 px wide, so a phone does not zoom
   into them. */

:root {
  /* surfaces (theme.py _LIGHT) */
  --bg: #f3f5f8;
  --surface: #fcfdff;
  --surface-container: #f6f8fb;
  --elevated: #ffffff;
  --elevated-hi: #edf1f6;
  --outline: #d7dee8;
  --outline-dim: #e7ebf1;
  --selection: #cfe5ff;
  /* content */
  --text: #102a43;
  --muted: #4b5d70;
  --disabled: #7f8b99;
  /* the brand blue */
  --accent: #0f65cd;
  --accent-hover: #0056bd;
  --accent-press: #004aa0;
  --on-accent: #ffffff;
  --accent-container: #e5f0ff;
  --accent-text: #0b57bd;
  /* status */
  --success: #1f9d63;
  --warning: #b3641a;
  --error: #c0392f;
  --on-error: #ffffff;
  --error-container: #f7d9d6;
  --info: #2b86c5;
  /* type (styles.py) */
  --font-ui: 'Segoe UI Variable Text', 'Segoe UI', 'Inter', sans-serif;
  --font-mono: 'Cascadia Mono', 'JetBrains Mono', 'Consolas', 'Courier New', monospace;
  --size-caption: 12px;
  --size-body: 13px;
  --size-heading: 14px;
  --size-title: 16px;
  --size-display: 24px;
  --size-mono: 12px;
  --weight-regular: 400;
  --weight-medium: 500;
  --weight-semibold: 600;
  --weight-bold: 700;
  /* geometry (geometry.py) */
  --space-xs: 4px;
  --space-sm: 8px;
  --space-md: 12px;
  --space-lg: 16px;
  --space-xl: 24px;
  --space-xxl: 32px;
  --radius-control: 6px;
  --radius-surface: 8px;
  --control-height: 32px;
  --gutter: 16px;
  --page-width: 960px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    /* theme.py _DARK */
    --bg: #15171c;
    --surface: #1b1e24;
    --surface-container: #21252d;
    --elevated: #272c35;
    --elevated-hi: #313742;
    --outline: #30353e;
    --outline-dim: #23272f;
    --selection: #2d4f7d;
    --text: #e4e7ec;
    --muted: #aeb6c2;
    --disabled: #737d8b;
    --accent: #2f7ae0;
    --accent-hover: #4b91ee;
    --accent-press: #1f63c8;
    --on-accent: #ffffff;
    --accent-container: #1a3a5e;
    --accent-text: #7cb6ff;
    --success: #4ec98a;
    --warning: #e0a23a;
    --error: #e3676f;
    --on-error: #3a0e12;
    --error-container: #3a2126;
    --info: #62b5e6;
  }
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: var(--size-body);
  font-weight: var(--weight-regular);
  line-height: 1.5;
  overflow-wrap: anywhere;
}

::selection { background: var(--selection); }

a { color: var(--accent-text); }
a:hover { color: var(--accent-hover); }

h1 { font-size: var(--size-display); font-weight: var(--weight-semibold); line-height: 1.25; margin: 0 0 var(--space-lg); }
h2 { font-size: var(--size-title); font-weight: var(--weight-semibold); margin: var(--space-xl) 0 var(--space-sm); }
h3 { font-size: var(--size-heading); font-weight: var(--weight-semibold); margin: var(--space-lg) 0 var(--space-xs); }
p { margin: 0 0 var(--space-md); }

code, kbd, pre {
  font-family: var(--font-mono);
  font-size: var(--size-mono);
  background: var(--surface-container);
  border: 1px solid var(--outline-dim);
  border-radius: var(--space-xs);
  padding: 1px var(--space-xs);
}

/* --- the frame ------------------------------------------------------------------------------------------------- */

header.site, footer.site {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-sm) var(--space-lg);
  padding: var(--space-md) var(--gutter);
  background: var(--surface-container);
  border-bottom: 1px solid var(--outline-dim);
}
footer.site {
  border-bottom: 0;
  border-top: 1px solid var(--outline-dim);
  color: var(--muted);
  font-size: var(--size-caption);
  margin-top: var(--space-xxl);
}
.brand {
  color: var(--text);
  font-weight: var(--weight-bold);
  font-size: var(--size-title);
  text-decoration: none;
  letter-spacing: 0.02em;
}
.brand::before {
  content: "";
  display: inline-block;
  width: 10px;
  height: 10px;
  margin-right: var(--space-sm);
  border-radius: 2px;
  background: var(--accent);
  vertical-align: 1px;
}
.site-nav { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-xs) var(--space-lg); margin-left: auto; }
.site-nav form { margin: 0; }

main {
  max-width: var(--page-width);
  margin: 0 auto;
  padding: var(--space-xl) var(--gutter);
}

section.entrance { max-width: 480px; }

.account-nav {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-xs) var(--space-lg);
  padding-bottom: var(--space-sm);
  margin-bottom: var(--space-lg);
  border-bottom: 1px solid var(--outline);
}
.account-nav a { font-weight: var(--weight-medium); text-decoration: none; }

/* --- what the pages say ---------------------------------------------------------------------------------------- */

.muted { color: var(--muted); }

.notice, .message, ul.messages li {
  padding: var(--space-sm) var(--space-md);
  border-radius: var(--radius-control);
  border: 1px solid var(--outline);
  background: var(--accent-container);
}
.message { background: var(--error-container); border-color: var(--error); }
ul.messages { list-style: none; margin: 0 0 var(--space-lg); padding: 0; display: grid; gap: var(--space-xs); }
ul.messages li.error { background: var(--error-container); border-color: var(--error); }

dl.facts { display: grid; grid-template-columns: max-content 1fr; gap: var(--space-xs) var(--space-lg); margin: 0; }
dl.facts dt { color: var(--muted); }
dl.facts dd { margin: 0; }
@media (max-width: 640px) {
  dl.facts { grid-template-columns: 1fr; }
  dl.facts dd { margin-bottom: var(--space-sm); }
}

ul.rows, ul.choices { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--space-sm); }
ul.rows > li, ul.choices > li {
  background: var(--surface);
  border: 1px solid var(--outline-dim);
  border-radius: var(--radius-surface);
  padding: var(--space-md);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-sm) var(--space-md);
}
ul.rows > li > div { flex: 1 1 240px; min-width: 0; }
ul.rows > li.muted { background: transparent; border-style: dashed; }
ul.rows.people > li { align-items: flex-start; }
ul.rows.people form.tags { flex: 1 1 100%; }

.recovery-codes { font-family: var(--font-mono); font-size: var(--size-mono); }

/* the fleet (machines/fleet.html) */
ul.rows.fleet > li { align-items: flex-start; }
ul.rows.fleet form.tags { flex: 1 1 100%; }
.web-name { display: inline-flex; flex-wrap: wrap; align-items: center; gap: var(--space-xs); margin-left: var(--space-sm); }
.state { margin-top: var(--space-xs); }
.online { color: var(--success); font-weight: var(--weight-medium); }
.unit-id { font-family: var(--font-mono); font-size: var(--size-mono); }
.verbs { display: inline-flex; flex-wrap: wrap; gap: var(--space-sm); }

/* the Activity page's tabs and the usage summary (accounts/audit.html, accounts/usage.html) */
nav.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-xs) var(--space-lg);
  margin: 0 0 var(--space-lg);
  border-bottom: 1px solid var(--outline-dim);
}
nav.tabs a { padding: var(--space-xs) 0; font-weight: var(--weight-medium); text-decoration: none; }
nav.tabs a[aria-current="page"] { color: var(--text); border-bottom: 2px solid var(--accent); }
form.filters input[name="month"] { width: 8em; }
section.summary table { width: 100%; max-width: 560px; border-collapse: collapse; margin: 0 0 var(--space-md); }
section.summary th, section.summary td {
  text-align: left;
  padding: var(--space-xs) var(--space-sm);
  border-bottom: 1px solid var(--outline-dim);
}
section.summary th { color: var(--muted); font-weight: var(--weight-medium); }

/* --- forms ----------------------------------------------------------------------------------------------------- */

form { margin: 0 0 var(--space-md); }
form > div { margin-bottom: var(--space-md); }
form.inline { display: inline-flex; flex-wrap: wrap; align-items: center; gap: var(--space-sm); margin: 0; }
label { display: block; font-weight: var(--weight-medium); margin-bottom: var(--space-xs); }
form.inline label, fieldset label { display: inline-flex; align-items: center; gap: var(--space-xs); margin: 0 var(--space-md) 0 0; }
fieldset { border: 1px solid var(--outline-dim); border-radius: var(--radius-control); margin: 0 0 var(--space-sm); padding: var(--space-sm) var(--space-md); }
legend { padding: 0 var(--space-xs); color: var(--muted); }

input, select, textarea {
  font: inherit;
  color: var(--text);
  background: var(--elevated);
  border: 1px solid var(--outline);
  border-radius: var(--radius-control);
  min-height: var(--control-height);
  padding: var(--space-xs) var(--space-sm);
  max-width: 100%;
}
input:not([type="checkbox"]):not([type="radio"]) { width: 100%; max-width: 420px; }
form.inline input:not([type="checkbox"]) { width: auto; }
input:focus, select:focus, textarea:focus, button:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
.helptext, form span.helptext { display: block; color: var(--muted); font-size: var(--size-caption); margin-top: var(--space-xs); }

ul.errorlist {
  list-style: none;
  margin: 0 0 var(--space-xs);
  padding: 0;
  color: var(--error);
  font-weight: var(--weight-medium);
}

button, .button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--control-height);
  padding: var(--space-xs) var(--space-md);
  font: inherit;
  font-weight: var(--weight-medium);
  color: var(--text);
  background: var(--elevated);
  border: 1px solid var(--outline);
  border-radius: var(--radius-control);
  text-decoration: none;
  cursor: pointer;
}
button:hover, .button:hover { background: var(--elevated-hi); color: var(--text); }
button.primary, .button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
  font-weight: var(--weight-semibold);
}
button.primary:hover, .button.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); color: var(--on-accent); }
button.primary:active, .button.primary:active { background: var(--accent-press); }
button.destructive { color: var(--error); border-color: var(--error); background: transparent; }
button.destructive:hover { background: var(--error-container); }
button.link {
  background: none;
  border: 0;
  min-height: 0;
  padding: 0;
  color: var(--accent-text);
  text-decoration: underline;
  font-weight: var(--weight-regular);
}

.visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* htmx: a row being changed */
.htmx-request { opacity: 0.6; }

@media (max-width: 640px) {
  input, select, textarea, button, .button { font-size: 16px; }
  h1 { font-size: 20px; }
  main { padding-top: var(--space-lg); }
  .site-nav { margin-left: 0; }
}
