/* UI kit 1.0.1 supplies shared readable text, states, controls and fonts.
   The portal keeps its accepted surfaces, amber brand and proportional card profile. */
/* ---------- Design tokens ----------
   Dark is the default palette. The light one applies when the system prefers light and the person has not chosen
   dark, and whenever they chose light (theme.js sets data-theme before the first paint). Server-rendered pages run
   no script and follow the system setting. Components use only these names, so the two palettes stay in step. */
:root {
  color-scheme: dark;
  /* Surfaces, from the page upward. */
  --bg: #0a0c10;
  --bg-glow: #161b25;
  --bg-elev: #111419;
  --bg-input: #0d0f13;
  --card: #121519;
  --card-hover: #15191f;
  --surface-1: #14171d;
  --surface-2: #1a1e25;
  --surface-3: #232831;
  --control-active: #262b35;
  --border: #1f242c;
  --border-strong: var(--ui-color-control-border);
  --border-hover: var(--ui-color-control-border);
  /* Text, strongest first. */
  --text-strong: #f5f6f8;
  --text: var(--ui-color-text);
  --muted: var(--ui-color-text-muted);
  --faint: #6b7382;
  --secondary: var(--ui-color-text-muted);
  --danger-fill: var(--ui-color-danger);
  --on-danger: var(--ui-color-on-danger);
  --footer: var(--ui-color-text-muted);
  /* Brand: amber for actions and emphasis; --accent-ink is the same hue made readable as text. */
  --accent: #f5a623;
  --accent-hover: #ffb743;
  --accent-contrast: #1c1100;
  --accent-ink: #fbbd52;
  --accent-soft: rgba(245, 166, 35, 0.13);
  --accent-2: #38bdf8;
  --ring: rgba(245, 166, 35, 0.38);
  /* States. */
  --danger: var(--ui-color-error-text);
  --danger-border: rgba(248, 113, 113, 0.42);
  --danger-bg: var(--ui-color-error-surface);
  --ok: var(--ui-color-success-text);
  --ok-bg: var(--ui-color-success-surface);
  --warn: var(--ui-color-warning-text);
  --warn-bg: var(--ui-color-warning-surface);
  --info: var(--ui-color-info-text);
  --info-bg: var(--ui-color-info-surface);
  --chip-bg: rgba(255, 255, 255, 0.03);
  --icon-edge: rgba(255, 255, 255, 0.07);
  --tabbar-bg: rgba(10, 12, 16, 0.76);
  --backdrop: rgba(2, 4, 8, 0.62);
  --toast-bg: #1d2129;
  --toast-text: #f3f4f7;
  /* Login entrance. */
  --login-story: #0e131a;
  --login-pane: #0a0c10;
  --login-line: #2a3642;
  --login-route: #4b5c6c;
  --login-node: #141c25;
  /* Depth: dark surfaces get a hairline top highlight, light ones soft layered shadows. */
  --highlight: inset 0 1px 0 rgba(255, 255, 255, 0.04);
  --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.32);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.36), 0 4px 14px rgba(0, 0, 0, 0.22);
  --shadow: 0 18px 44px rgba(0, 0, 0, 0.46), 0 3px 10px rgba(0, 0, 0, 0.28);
  --shadow-lg: 0 32px 80px rgba(0, 0, 0, 0.62), 0 4px 14px rgba(0, 0, 0, 0.3);
  --radius: var(--ui-panel-radius);
  --radius-sm: var(--ui-control-radius);
  --radius-lg: 16px;
  /* Expand the main content on wide screens while keeping it within the viewport. */
  --content-max: min(1680px, 94vw);
  /* app.js sets this browser-local card scale; level 8 uses the original 1x dimensions. */
  --card-scale: 1;
  --font: var(--ui-font-family);
  --mono: var(--ui-font-mono);
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    color-scheme: light;
    --bg: #f4f5f7;
    --bg-glow: #ffffff;
    --bg-elev: #ffffff;
    --bg-input: #ffffff;
    --card: #ffffff;
    --card-hover: #ffffff;
    --surface-1: #f8f9fb;
    --surface-2: #f1f3f6;
    --surface-3: #e7eaef;
    --control-active: #ffffff;
    --border: #e3e6eb;
    --border-strong: var(--ui-color-control-border);
    --border-hover: var(--ui-color-control-border);
    --text-strong: #0c111b;
    --text: var(--ui-color-text);
    --muted: var(--ui-color-text-muted);
    --faint: #788192;
    --footer: var(--ui-color-text-muted);
    --accent: #f59e0b;
    --accent-hover: #e89206;
    --accent-contrast: #211300;
    --accent-ink: #b25200;
    --accent-soft: rgba(245, 158, 11, 0.12);
    --accent-2: #0284c7;
    --ring: rgba(245, 158, 11, 0.3);
    --danger: var(--ui-color-error-text);
    --danger-border: rgba(217, 45, 32, 0.32);
    --danger-bg: var(--ui-color-error-surface);
    --ok: var(--ui-color-success-text);
    --ok-bg: var(--ui-color-success-surface);
    --warn: var(--ui-color-warning-text);
    --warn-bg: var(--ui-color-warning-surface);
    --info: var(--ui-color-info-text);
    --info-bg: var(--ui-color-info-surface);
    --chip-bg: #f6f7f9;
    --icon-edge: rgba(16, 24, 40, 0.07);
    --tabbar-bg: rgba(255, 255, 255, 0.84);
    --backdrop: rgba(16, 24, 40, 0.36);
    --toast-bg: #151a23;
    --toast-text: #f5f6f8;
    --login-story: #eef2f6;
    --login-pane: #ffffff;
    --login-line: #cfd9e2;
    --login-route: #a1b3c2;
    --login-node: #ffffff;
    --highlight: 0 0 #0000;
    --shadow-xs: 0 1px 2px rgba(16, 24, 40, 0.05);
    --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.08);
    --shadow: 0 14px 28px -6px rgba(16, 24, 40, 0.12), 0 4px 10px -3px rgba(16, 24, 40, 0.06);
    --shadow-lg: 0 28px 56px -14px rgba(16, 24, 40, 0.26), 0 6px 14px -4px rgba(16, 24, 40, 0.08);
  }
}
/* An explicit light choice applies the same palette even when the system prefers dark. */
:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f4f5f7;
  --bg-glow: #ffffff;
  --bg-elev: #ffffff;
  --bg-input: #ffffff;
  --card: #ffffff;
  --card-hover: #ffffff;
  --surface-1: #f8f9fb;
  --surface-2: #f1f3f6;
  --surface-3: #e7eaef;
  --control-active: #ffffff;
  --border: #e3e6eb;
  --border-strong: var(--ui-color-control-border);
  --border-hover: var(--ui-color-control-border);
  --text-strong: #0c111b;
  --text: var(--ui-color-text);
  --muted: var(--ui-color-text-muted);
  --faint: #788192;
  --footer: var(--ui-color-text-muted);
  --accent: #f59e0b;
  --accent-hover: #e89206;
  --accent-contrast: #211300;
  --accent-ink: #b25200;
  --accent-soft: rgba(245, 158, 11, 0.12);
  --accent-2: #0284c7;
  --ring: rgba(245, 158, 11, 0.3);
  --danger: var(--ui-color-error-text);
  --danger-border: rgba(217, 45, 32, 0.32);
  --danger-bg: var(--ui-color-error-surface);
  --ok: var(--ui-color-success-text);
  --ok-bg: var(--ui-color-success-surface);
  --warn: var(--ui-color-warning-text);
  --warn-bg: var(--ui-color-warning-surface);
  --info: var(--ui-color-info-text);
  --info-bg: var(--ui-color-info-surface);
  --chip-bg: #f6f7f9;
  --icon-edge: rgba(16, 24, 40, 0.07);
  --tabbar-bg: rgba(255, 255, 255, 0.84);
  --backdrop: rgba(16, 24, 40, 0.36);
  --toast-bg: #151a23;
  --toast-text: #f5f6f8;
  --login-story: #eef2f6;
  --login-pane: #ffffff;
  --login-line: #cfd9e2;
  --login-route: #a1b3c2;
  --login-node: #ffffff;
  --highlight: 0 0 #0000;
  --shadow-xs: 0 1px 2px rgba(16, 24, 40, 0.05);
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.08);
  --shadow: 0 14px 28px -6px rgba(16, 24, 40, 0.12), 0 4px 10px -3px rgba(16, 24, 40, 0.06);
  --shadow-lg: 0 28px 56px -14px rgba(16, 24, 40, 0.26), 0 6px 14px -4px rgba(16, 24, 40, 0.08);
}

/* ---------- Base ---------- */
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font); font-size: var(--ui-body-size); line-height: var(--ui-body-line); color: var(--text);
  background: radial-gradient(1200px 480px at 50% -160px, var(--bg-glow), transparent 72%) no-repeat, var(--bg);
  min-height: 100vh; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale;
  transition: background-color 0.2s, color 0.2s;
}
h1, h2, h3 { color: var(--text-strong); }
::selection { background: var(--accent-soft); }
a { color: inherit; text-decoration: none; }
button { font: inherit; }
code { font-family: var(--mono); font-size: 0.88em; background: var(--surface-2); border: 1px solid var(--border); padding: 1px 6px; border-radius: 6px; }
.hidden { display: none !important; }

/* ---------- Brand ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 28px; gap: 16px;
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--text-strong); }
.brand-mark {
  width: 26px; height: 26px; border-radius: 8px; flex: none;
  background: conic-gradient(from 210deg, var(--accent), var(--accent-2), var(--accent));
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.2), 0 2px 8px rgba(245, 158, 11, 0.28);
}
.brand-text { font-size: 17px; font-weight: 600; letter-spacing: -0.02em; }
.brand-text b { color: var(--accent-ink); font-weight: 750; }
.topbar-actions { display: flex; gap: 8px; align-items: center; }
.who { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 320px; }
.who a { color: inherit; }
.who a:hover, .who a:focus-visible { color: var(--text); }

/* ---------- Buttons: neutral by default, amber primary, outlined danger ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px; white-space: nowrap;
  min-height: var(--ui-control-height); padding: 0 14px; border-radius: var(--radius-sm); cursor: pointer;
  border: 1px solid var(--border-strong); background: var(--bg-elev); color: var(--text);
  font-size: 13.5px; font-weight: 600; line-height: 1.2; letter-spacing: -0.005em;
  box-shadow: var(--shadow-xs), var(--highlight);
  transition: background 0.15s, border-color 0.15s, box-shadow 0.15s, color 0.15s, transform 0.05s;
}
.btn:hover { background: var(--surface-2); border-color: var(--border-hover); }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--ring); border-color: var(--accent); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: 0.5; cursor: not-allowed; transform: none; }
.btn.sm { min-height: 30px; padding: 0 11px; font-size: 12.5px; border-radius: 8px; }
.btn.lg { min-height: 42px; padding: 0 20px; font-size: 14.5px; border-radius: 10px; }
.btn.primary {
  background: var(--accent); border-color: color-mix(in srgb, var(--accent) 82%, #000); color: var(--accent-contrast);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.14), inset 0 1px 0 rgba(255, 255, 255, 0.28);
}
.btn.primary:hover { background: var(--accent-hover); border-color: color-mix(in srgb, var(--accent-hover) 82%, #000); }
.btn.ghost { background: transparent; box-shadow: none; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.danger { background: transparent; border-color: var(--danger-border); color: var(--danger); box-shadow: none; }
.btn.danger:hover { background: var(--danger-bg); border-color: var(--danger); }
.btn.danger-solid { background: var(--danger-fill); border-color: var(--danger-fill); color: var(--on-danger); box-shadow: 0 1px 2px rgba(0, 0, 0, 0.16); }
.btn.danger-solid:hover { filter: brightness(1.06); }

/* ---------- Grouped controls: theme choice and the browser-local card size ---------- */
.theme-switch {
  display: inline-flex; align-items: center; padding: 3px; gap: 2px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface-1);
}
.theme-switch button {
  width: 30px; height: 28px; border-radius: 7px; border: 0; background: transparent; color: var(--secondary);
  cursor: pointer; display: grid; place-items: center; transition: color 0.15s, background 0.15s;
}
.theme-switch button:hover { color: var(--text); }
.theme-switch button[aria-pressed="true"] { background: var(--control-active); color: var(--text-strong); box-shadow: var(--shadow-xs), 0 0 0 1px var(--border-strong); }
.theme-switch svg { width: 15px; height: 15px; }
.card-size {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 0 6px 0 10px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface-1);
  color: var(--secondary);
}
.card-size:hover { color: var(--text); }
.card-size > svg { width: 15px; height: 15px; flex: none; }
.card-size input[type="range"] {
  width: 84px; height: 28px; margin: 0; padding: 0;
  background: transparent; accent-color: var(--accent); cursor: pointer;
}
.card-size-val {
  min-width: 24px; min-height: 24px; height: 24px; padding: 0 4px; border: 0; border-radius: 6px;
  background: transparent; color: var(--muted); cursor: pointer;
  font: inherit; font-size: 12px; font-weight: 600; font-variant-numeric: tabular-nums;
}
.card-size-val:hover { background: var(--surface-3); color: var(--text); }

/* ---------- Dashboard top bar: brand, search, primary action, who is signed in ---------- */
.app-top {
  position: sticky; top: 0; z-index: 30; display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 20px;
  height: 60px; padding: 0 28px; border-bottom: 1px solid var(--border); background: var(--tabbar-bg); backdrop-filter: saturate(160%) blur(14px);
}
.app-top .brand-text { white-space: nowrap; }
.app-search {
  justify-self: center; width: 100%; max-width: 600px; height: 38px; display: flex; align-items: center; gap: 9px; padding: 0 9px 0 12px;
  border: 1px solid var(--border); border-radius: 10px; background: var(--surface-1); color: var(--secondary);
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
}
.app-search:hover { border-color: var(--border-strong); }
.app-search:focus-within { background: var(--bg-input); border-color: var(--accent); box-shadow: 0 0 0 3px var(--ring); color: var(--muted); }
.app-search svg { flex: none; width: 16px; height: 16px; }
.app-search input { flex: 1; min-width: 0; height: 100%; border: 0; outline: 0; background: transparent; color: var(--text); font: inherit; font-size: 14px; }
.app-search input::placeholder { color: var(--secondary); }
.app-search input::-webkit-search-cancel-button { cursor: pointer; }
.search-key {
  flex: none; min-width: 20px; height: 20px; display: grid; place-items: center; padding: 0 5px;
  border: 1px solid var(--border-strong); border-radius: 5px; background: var(--bg-elev); box-shadow: 0 1px 0 var(--border-strong);
  color: var(--secondary); font: 600 11px var(--mono);
}
.app-search:focus-within .search-key { display: none; }
.app-top-actions { display: flex; align-items: center; gap: 10px; }
.app-top-actions .btn { min-height: var(--ui-control-height); }
.who-chip {
  display: inline-flex; align-items: center; gap: 8px; height: 36px; padding: 0 3px 0 4px; max-width: 300px;
  border: 1px solid var(--border); border-radius: 999px; background: var(--bg-elev); box-shadow: var(--shadow-xs), var(--highlight);
  color: var(--text); font-size: 13px; font-weight: 500;
}
.avatar {
  flex: none; width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; font-size: 12px; font-weight: 700;
  color: var(--accent-contrast); background: linear-gradient(135deg, var(--accent), var(--accent-2));
}
.who-email { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.who-logout { flex: none; width: 28px; height: 28px; display: grid; place-items: center; border-radius: 50%; color: var(--secondary); }
.who-logout:hover, .who-logout:focus-visible { background: var(--surface-2); color: var(--text); outline: none; }

/* ---------- Section tabs on the left, view controls and tools on the right ---------- */
.app-toolbar {
  width: var(--content-max); max-width: 100%; margin: 22px auto 0; padding: 0 28px;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
}
.tabs {
  display: flex; gap: 2px; min-width: 0; overflow-x: auto; scrollbar-width: none;
  padding: 3px; border: 1px solid var(--border); border-radius: 11px; background: var(--surface-1);
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  white-space: nowrap; min-height: 30px; padding: 0 14px; border-radius: 8px; font-size: 13.5px; font-weight: 500; color: var(--muted);
  border: 0; background: transparent; cursor: pointer; transition: color 0.15s, background 0.15s;
}
.tab:hover { color: var(--text-strong); }
.tab:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.tab.active { background: var(--control-active); color: var(--text-strong); font-weight: 600; box-shadow: var(--shadow-xs), 0 0 0 1px var(--border-strong); }
.toolbar-tools { display: flex; align-items: center; gap: 8px; flex: none; }
.tool-sep { width: 1px; height: 22px; background: var(--border-strong); margin: 0 2px; }
.icon-btn {
  width: 36px; height: 36px; display: inline-grid; place-items: center; border-radius: 9px; cursor: pointer;
  border: 1px solid var(--border-strong); background: var(--bg-elev); color: var(--muted); box-shadow: var(--shadow-xs), var(--highlight);
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.icon-btn:hover { color: var(--text-strong); background: var(--surface-2); border-color: var(--border-hover); }
.icon-btn:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--ring); border-color: var(--accent); }
.icon-btn svg { width: 17px; height: 17px; }
.toolbar-tools .card-size, .toolbar-tools .theme-switch { height: 36px; }

/* ---------- Link sections and cards ---------- */
.sections { width: var(--content-max); max-width: 100%; margin: 0 auto; padding: 6px 28px 72px; }
.section { margin-top: 30px; scroll-margin-top: 84px; }
.section-head { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.section-head h2 { font-size: 15px; font-weight: 700; margin: 0; letter-spacing: -0.01em; }
.section-head .count {
  display: inline-flex; align-items: center; height: 20px; padding: 0 7px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--muted); font-size: 11.5px; font-weight: 600; font-variant-numeric: tabular-nums;
}
.section-head::after { content: ''; flex: 1; height: 1px; background: var(--border); }
/* Scale grid columns, card spacing, typography, icons, and controls together.
   Changing --card-scale affects layout, so smaller cards also fit in more columns.
   The original size is 1; app.js supplies the current browser's preference. */
.grid {
  display: grid; gap: calc(16px * var(--card-scale));
  grid-template-columns: repeat(auto-fill, minmax(min(100%, calc(280px * var(--card-scale))), 1fr));
}
.card {
  position: relative; display: flex; flex-direction: column; min-width: 0;
  min-height: calc(150px * var(--card-scale)); padding: 0;
  background: var(--card); border: 1px solid var(--border); border-radius: calc(var(--radius) * var(--card-scale));
  box-shadow: var(--shadow-xs), var(--highlight); cursor: pointer;
  transition: transform 0.15s, border-color 0.15s, background 0.15s, box-shadow 0.15s;
}
.card:hover { transform: translateY(-2px); border-color: var(--border-hover); background: var(--card-hover); box-shadow: var(--shadow), var(--highlight); }
.card-open { display: flex; flex-direction: column; flex: 1; min-width: 0; padding: calc(18px * var(--card-scale)); color: inherit; border-radius: inherit; }
.card-open:focus-visible { outline: none; }
.card:focus-within { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--ring); }
/* Drag handlers in app.js toggle these classes on the source and current drop target. */
.card.dragging { opacity: 0.4; }
.card.drop-target { outline: 2px dashed var(--accent); outline-offset: -2px; }
.card-head { display: flex; align-items: center; gap: calc(12px * var(--card-scale)); min-width: 0; margin-bottom: calc(12px * var(--card-scale)); }
.card-icon {
  position: relative; flex: none; width: calc(42px * var(--card-scale)); height: calc(42px * var(--card-scale));
  border-radius: calc(11px * var(--card-scale)); display: grid; place-items: center;
  font-size: calc(22px * var(--card-scale)); overflow: hidden;
}
.card-icon::after { content: ''; position: absolute; inset: 0; border-radius: inherit; box-shadow: inset 0 0 0 1px var(--icon-edge); pointer-events: none; }
.card-icon svg { width: 100%; height: 100%; display: block; }
.card-heading { flex: 1; min-width: 0; }
.card-title {
  margin: 0; padding-right: max(24px, calc(24px * var(--card-scale))); font-size: calc(15px * var(--card-scale)); font-weight: 650; line-height: 1.35; letter-spacing: -0.015em;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.card-link {
  display: flex; align-items: center; gap: calc(4px * var(--card-scale)); min-width: 0; margin-top: calc(3px * var(--card-scale));
  font-family: var(--mono); font-size: calc(12px * var(--card-scale)); color: var(--secondary); white-space: nowrap;
}
.card-link span { overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.card-link.keyword { color: var(--accent-ink); }
.card-link svg { flex: none; width: calc(12px * var(--card-scale)); height: calc(12px * var(--card-scale)); }
.card-desc {
  margin: 0 0 calc(14px * var(--card-scale)); color: var(--muted); font-size: calc(13px * var(--card-scale)); line-height: 1.55;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.card-foot {
  display: flex; align-items: center; flex-wrap: wrap; gap: calc(6px * var(--card-scale)); margin-top: auto;
  padding-top: calc(12px * var(--card-scale)); border-top: 1px solid var(--border);
}
.card-foot .chip, .card-audience, .card-access {
  display: inline-flex; align-items: center; gap: calc(5px * var(--card-scale)); max-width: 100%;
  height: calc(22px * var(--card-scale)); padding: 0 calc(8px * var(--card-scale)); border-radius: calc(6px * var(--card-scale));
  font-size: calc(11.5px * var(--card-scale)); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.card-foot .chip { color: var(--muted); }
.card-audience { color: var(--info); background: var(--info-bg); border: 1px solid color-mix(in srgb, var(--info) 22%, transparent); font-weight: 600; }
.card-audience svg { width: calc(11px * var(--card-scale)); height: calc(11px * var(--card-scale)); flex: none; }
.card-target {
  margin-left: auto; min-width: 0; max-width: 55%; font-family: var(--mono); font-size: calc(11.5px * var(--card-scale)); color: var(--secondary);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.card-edit {
  position: absolute; top: calc(12px * var(--card-scale)); right: calc(12px * var(--card-scale));
  width: max(24px, calc(28px * var(--card-scale))); height: max(24px, calc(28px * var(--card-scale)));
  border-radius: calc(7px * var(--card-scale));
  border: 1px solid transparent; background: transparent; color: var(--secondary); cursor: pointer;
  display: grid; place-items: center; opacity: 0; transition: opacity 0.15s, background 0.15s, color 0.15s;
}
.card-edit svg { width: calc(15px * var(--card-scale)); height: calc(15px * var(--card-scale)); }
/* Reveal editing on mouse hover or keyboard focus; mobile rules keep it visible. */
.card:hover .card-edit, .card:focus-within .card-edit { opacity: 1; }
.card-edit:hover { background: var(--surface-2); color: var(--text); border-color: var(--border-strong); }

/* ---------- Empty collection and search-result messages ---------- */
.empty { text-align: center; padding: 88px 20px; color: var(--muted); }
.empty-icon {
  width: 64px; height: 64px; margin: 0 auto 20px; border-radius: 18px; border: 1px solid var(--border-strong);
  background: linear-gradient(135deg, var(--accent-soft), var(--info-bg)), var(--bg-elev); box-shadow: var(--shadow-sm);
}
.empty h2 { font-size: 18px; margin: 0 0 8px; letter-spacing: -0.02em; }
.empty p { margin: 0; font-size: 14px; }
.empty b { color: var(--text); }

.footer { text-align: center; color: var(--footer); font-size: 12px; padding: 20px 0 40px; }

.load-status { max-width: var(--content-max); margin: 28px auto; padding: 20px 28px; }
.load-status p { color: var(--muted); margin: 0 0 12px; }
.field [aria-invalid="true"] { border-color: var(--danger); }
.picker[aria-invalid="true"] { outline: 1px solid var(--danger); outline-offset: 4px; border-radius: var(--radius-sm); }

/* ---------- Dialogs and form fields ---------- */
.modal {
  border: 1px solid var(--border-strong); border-radius: var(--radius-lg); background: var(--bg-elev); color: var(--text);
  padding: 0; width: min(540px, calc(100vw - 32px)); box-shadow: var(--shadow-lg), var(--highlight);
}
.modal[open] { animation: modal-in 0.16s ease-out; }
@keyframes modal-in { from { opacity: 0; transform: translateY(6px) scale(0.985); } }
.modal::backdrop { background: var(--backdrop); backdrop-filter: blur(4px); }
.modal form, .modal-body { padding: 24px 24px 20px; display: flex; flex-direction: column; gap: 16px; }
.modal h2 { margin: 0; font-size: 18px; font-weight: 700; letter-spacing: -0.02em; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; }
.field > span { color: var(--text); font-weight: 600; }
.field em { color: var(--accent-ink); font-style: normal; }
.field input, .field textarea {
  min-height: 38px; padding: 8px 12px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  background: var(--bg-input); color: var(--text); font: inherit; font-size: 14px; outline: none;
  box-shadow: var(--shadow-xs); transition: border-color 0.15s, box-shadow 0.15s;
}
.field textarea { resize: vertical; font-family: var(--mono); font-size: 13px; line-height: 1.5; }
.field input::placeholder, .field textarea::placeholder { color: var(--secondary); }
.field input:hover, .field textarea:hover { border-color: var(--border-hover); }
.field input:focus, .field textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--ring); }
.field input:disabled, .field textarea:disabled { background: var(--surface-1); color: var(--muted); cursor: not-allowed; }
.field small { color: var(--secondary); font-size: 12px; line-height: 1.5; font-weight: 400; }
.keyword-row { display: flex; align-items: stretch; }
.keyword-suffix {
  display: flex; align-items: center; padding: 0 11px; font-size: 12.5px; color: var(--muted);
  background: var(--surface-1); border: 1px solid var(--border-strong); border-left: 0; border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  font-family: var(--mono); white-space: nowrap; max-width: 55%; overflow: hidden; text-overflow: ellipsis;
}
.keyword-suffix:empty { display: none; }
.keyword-row input { flex: 1; min-width: 0; }
.keyword-row input:has(+ .keyword-suffix:not(:empty)) { border-radius: var(--radius-sm) 0 0 var(--radius-sm) !important; }
.field.check { flex-direction: row; align-items: flex-start; gap: 10px; }
.field.check input { width: 16px; height: 16px; min-height: 0; margin-top: 1px; accent-color: var(--accent); box-shadow: none; }
.field.check span { color: var(--text); }
.field.check small { color: var(--secondary); display: block; margin-top: 2px; }
/* Preview of another person's view: a banner, notes on keywords they could not open, editing locked. */
.preview-bar {
  width: var(--content-max); max-width: calc(100% - 56px); margin: 16px auto 0; padding: 10px 12px 10px 14px;
  display: flex; align-items: center; gap: 12px; border: 1px solid color-mix(in srgb, var(--info) 35%, transparent);
  border-radius: var(--radius); background: var(--info-bg); color: var(--text); font-size: 13.5px; box-shadow: var(--shadow-xs);
}
.preview-bar > svg { width: 20px; height: 20px; flex: none; color: var(--info); }
.preview-text { flex: 1; min-width: 0; line-height: 1.5; }
.preview-text b { color: var(--text-strong); }
.preview-text span { color: var(--muted); }
body.is-preview #btn-add, body.is-preview #btn-import { opacity: 0.45; pointer-events: none; }
.card-access { font-weight: 600; }
.card-access.login { color: var(--warn); background: var(--warn-bg); border: 1px solid color-mix(in srgb, var(--warn) 24%, transparent); }
.card-access.group { color: var(--danger); background: var(--danger-bg); border: 1px solid var(--danger-border); }
@media (max-width: 640px) { .preview-bar { max-width: calc(100% - 32px); flex-wrap: wrap; } }
/* Two-choice switch (radio group) in dialogs. */
.segmented { display: inline-flex; padding: 3px; gap: 2px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface-1); align-self: flex-start; }
.segmented label { position: relative; }
.segmented input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.segmented span { display: inline-flex; align-items: center; min-height: 30px; padding: 0 14px; border-radius: 7px; font-size: 13px; font-weight: 500; color: var(--muted); }
.segmented label:hover span { color: var(--text); }
.segmented input:checked + span { background: var(--control-active); color: var(--text-strong); font-weight: 600; box-shadow: var(--shadow-xs), 0 0 0 1px var(--border-strong); }
.segmented input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 1px; }
.segmented input:disabled + span { opacity: 0.55; }
#audience .picker { margin-top: 4px; }
.icon-row { display: grid; grid-template-columns: 110px 44px 1fr; gap: 10px; align-items: center; }
.icon-row small { line-height: 1.4; }
.icon-preview { width: 44px; height: 44px; border-radius: 11px; display: grid; place-items: center; font-size: 24px; overflow: hidden; box-shadow: inset 0 0 0 1px var(--icon-edge); }
.icon-preview svg { width: 100%; height: 100%; display: block; }
.form-error { color: var(--danger); font-size: 13px; margin: 0; min-height: 1em; }
.form-error:empty { display: none; }
/* The dialog's own footer: a quiet band under the content. */
.modal-actions {
  display: flex; align-items: center; gap: 8px; margin: 4px -24px -20px; padding: 14px 24px;
  border-top: 1px solid var(--border); background: var(--surface-1); border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}
.modal-actions .spacer { flex: 1; }

/* ---------- Scrollable CA installation dialog and fingerprint display ---------- */
.modal.modal-wide { width: min(640px, calc(100vw - 32px)); }
.ca-actions { display: flex; flex-direction: column; gap: 8px; padding: 12px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface-1); }
.ca-fp { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.ca-fp-label { font-size: 12px; color: var(--muted); white-space: nowrap; }
.ca-fp code { font-size: 11.5px; word-break: break-all; line-height: 1.5; flex: 1; min-width: 200px; }
.btn.small { min-height: 30px; padding: 0 10px; font-size: 12.5px; }
.ca-steps h3 { font-size: 14.5px; margin: 10px 0 4px; }
.ca-check { margin: 4px 0 0; padding-left: 20px; line-height: 1.6; }
.ca-check li { margin: 4px 0; }
.modal-body ul li b, .modal-body ol li b { color: var(--text-strong); }
.modal-body { font-size: 14px; max-height: 85vh; overflow: auto; }
.modal-body .lead { margin: 0; color: var(--muted); line-height: 1.6; }
.modal-body .btn.primary { align-self: flex-start; }
.modal-actions .btn.primary { align-self: auto; }
.modal-body details { border: 1px solid var(--border); border-radius: 10px; padding: 8px 12px; background: var(--surface-1); }
.modal-body summary { cursor: pointer; font-weight: 600; padding: 4px 0; }
.modal-body ol { margin: 8px 0 4px; padding-left: 20px; line-height: 1.6; color: var(--text); }
.modal-body li { margin: 2px 0; }
.modal-body .note { margin: 6px 0 2px; color: var(--secondary); font-size: 12.5px; line-height: 1.5; }
.modal-body pre { margin: 8px 0; padding: 10px 12px; border-radius: 8px; background: var(--surface-2); font-size: 12.5px; overflow: auto; }

/* ---------- Transient status toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%) translateY(16px);
  background: var(--toast-bg); color: var(--toast-text); border: 1px solid rgba(255, 255, 255, 0.08);
  padding: 10px 16px; border-radius: 10px; font-size: 13.5px; font-weight: 500; opacity: 0; pointer-events: none;
  transition: opacity 0.2s, transform 0.2s; box-shadow: var(--shadow-lg); z-index: 50;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* Show keyboard focus without adding the same outline to ordinary pointer clicks. */
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.app-search input:focus-visible { outline: none; }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; }
}

/* The login entrance has its own layout while sharing the dashboard's palette and mark. */
body.login-page { background: var(--login-pane); }
.login-shell {
  display: grid; grid-template-columns: minmax(0, 1.08fr) minmax(430px, 0.92fr);
  max-width: 1600px; min-height: 100vh; min-height: 100svh; margin: 0 auto;
  border-inline: 1px solid var(--border);
}
.login-story {
  position: relative; isolation: isolate; overflow: hidden;
  min-height: 760px; padding: clamp(32px, 4.2vw, 68px);
  display: flex; flex-direction: column; justify-content: space-between;
  background:
    radial-gradient(550px 420px at 16% 103%, rgba(56, 189, 248, 0.08), transparent 72%),
    radial-gradient(520px 420px at 90% 0%, var(--accent-soft), transparent 70%),
    var(--login-story);
  border-right: 1px solid var(--border-strong);
}
.login-story::before {
  content: ''; position: absolute; z-index: -1;
  width: 850px; aspect-ratio: 1; right: -530px; top: -300px;
  border: 1px solid var(--login-line); border-radius: 50%;
  box-shadow: 0 0 0 110px var(--login-story), 0 0 0 111px var(--login-line),
    0 0 0 225px var(--login-story), 0 0 0 226px var(--login-line);
  opacity: 0.5;
}
.login-brand {
  display: inline-flex; align-items: center; align-self: flex-start; gap: 11px;
  color: var(--text); font-size: 21px; font-weight: 700; letter-spacing: -0.55px;
}
.login-brand .brand-mark { width: 28px; height: 28px; }
.login-brand b { color: var(--accent-ink); }
.login-story-copy { position: relative; max-width: 660px; margin: auto 0 26px; padding-top: 70px; }
.login-kicker, .login-story-foot, .login-panel-top {
  font-family: var(--mono);
  font-size: 11px; font-weight: 600; letter-spacing: 0.14em;
}
.login-kicker { margin: 0 0 24px; color: var(--accent-ink); }
.login-story h1 {
  margin: 0; font-size: clamp(40px, 4.2vw, 66px); font-weight: 700;
  line-height: 1.18; letter-spacing: -0.065em; text-wrap: balance;
}
.login-story h1 span { color: var(--accent-ink); }
.login-intro { margin: 24px 0 0; color: var(--muted); font-size: 16px; line-height: 1.65; }
.login-map { width: min(620px, 100%); margin: 0 auto 28px; }
.login-map svg { display: block; width: 100%; height: auto; overflow: visible; }
.login-map-route, .login-map-route-accent { fill: none; stroke: var(--login-route); stroke-width: 1.5; }
.login-map-route-accent { stroke: var(--accent); stroke-width: 2; }
.login-map-node rect { fill: var(--login-node); stroke: var(--login-line); filter: drop-shadow(0 2px 4px rgba(16, 24, 40, 0.06)); }
.login-map-node circle { fill: var(--accent-2); opacity: 0.75; }
.login-map-node path { fill: none; stroke: var(--login-route); stroke-width: 2; stroke-linecap: round; }
.login-map-core { fill: var(--card); stroke: var(--border-strong); filter: drop-shadow(0 8px 18px rgba(16, 24, 40, 0.12)); }
.login-map-core-mark { fill: var(--accent); }
.login-map-core-link { fill: none; stroke: var(--accent-contrast); stroke-width: 2.5; stroke-linecap: round; }
.login-map text { fill: var(--text-strong); font-family: var(--font); font-size: 20px; font-weight: 700; letter-spacing: -0.5px; }
.login-story-foot { position: relative; margin: 0; color: var(--secondary); letter-spacing: 0.08em; }
.login-story-foot span { color: var(--accent-ink); padding: 0 7px; }
.login-access {
  display: flex; flex-direction: column; justify-content: center; align-items: center;
  padding: 48px clamp(28px, 5vw, 80px); background: var(--login-pane);
}
.login-panel { width: min(440px, 100%); }
.login-panel-top { display: flex; align-items: center; gap: 12px; color: var(--secondary); }
.login-panel-symbol {
  display: grid; place-items: center; width: 32px; height: 32px;
  border: 1px solid var(--border-strong); border-radius: 9px;
  color: var(--accent-ink); font-family: var(--font); font-size: 19px; letter-spacing: 0; background: var(--bg-elev); box-shadow: var(--shadow-xs);
}
.login-step { margin: 76px 0 12px; color: var(--accent-ink); font-size: 13px; font-weight: 700; }
.login-panel h2 { margin: 0; font-size: clamp(34px, 3.2vw, 47px); line-height: 1.2; letter-spacing: -0.055em; }
.login-description { max-width: 360px; margin: 20px 0 0; color: var(--muted); font-size: 15px; line-height: 1.7; }
.login-google {
  display: grid; grid-template-columns: 22px 1fr 22px; align-items: center; gap: 12px;
  width: 100%; min-height: 56px; margin-top: 42px; padding: 12px 18px;
  border: 1px solid #e2e5e9; border-radius: 10px;
  background: #f8fafc; color: #171b23; font-size: 14px; font-weight: 700; text-align: center;
  transition: background 0.15s, box-shadow 0.15s, transform 0.05s;
}
.login-google:hover { background: #ffffff; box-shadow: 0 8px 28px rgba(0, 0, 0, 0.14); }
.login-google:active { transform: translateY(1px); }
.login-google svg { display: block; }
.login-google-arrow { color: #606a78; font-size: 21px; font-weight: 400; line-height: 1; }
.login-footer { width: min(440px, 100%); margin: 64px 0 0; color: var(--footer); font-size: 11px; }

/* Gateway-owned status page: the target service may be offline, so only the apex serves its assets. */
.service-error-page .topbar { width: min(1200px, 100%); margin: 0 auto; padding-block: 28px; }
.service-error-shell {
  width: min(1144px, calc(100% - 56px)); min-height: min(640px, calc(100svh - 120px));
  margin: 12px auto 48px; border: 1px solid var(--border-strong); border-radius: 20px;
  background: var(--bg-elev); box-shadow: var(--shadow), var(--highlight);
  display: flex; flex-direction: column; overflow: hidden;
}
.service-error-rail, .service-error-foot {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 22px 32px; color: var(--secondary); font-size: 11px; font-weight: 650;
  letter-spacing: 0.12em; font-family: var(--mono);
}
.service-error-rail { border-bottom: 1px solid var(--border); background: var(--surface-1); }
.service-error-rail span:last-child { color: var(--accent-ink); }
.service-error-content {
  flex: 1; display: grid; grid-template-columns: minmax(250px, 0.8fr) minmax(0, 1.2fr);
  align-items: center; gap: clamp(24px, 5vw, 88px); padding: clamp(38px, 6vw, 84px);
}
.service-error-code {
  color: var(--text); font-size: clamp(112px, 16vw, 220px); font-weight: 750;
  line-height: 0.95; letter-spacing: -0.105em; font-variant-numeric: tabular-nums;
}
.service-error-code span { color: var(--accent-ink); }
.service-error-kicker { margin: 0 0 18px; color: var(--accent-ink); font-size: 12px; font-weight: 700; letter-spacing: 0.08em; }
.service-error-copy h1 { margin: 0; font-size: clamp(28px, 3.5vw, 44px); line-height: 1.2; letter-spacing: -0.055em; text-wrap: balance; }
.service-error-copy > p:not(.service-error-kicker) { max-width: 460px; margin: 20px 0 0; color: var(--muted); font-size: 15px; line-height: 1.75; }
.service-error-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 36px; }
.service-error-actions .btn { min-height: 44px; justify-content: center; }
.service-error-foot { border-top: 1px solid var(--border); background: var(--surface-1); letter-spacing: 0.04em; }
.service-error-foot span:first-child { color: var(--muted); font-family: var(--font); font-size: 12px; letter-spacing: 0; overflow-wrap: anywhere; }

@media (max-width: 700px) {
  .service-error-shell { width: calc(100% - 32px); min-height: calc(100svh - 112px); margin-top: 0; border-radius: 16px; }
  .service-error-content { grid-template-columns: 1fr; align-content: center; gap: 22px; padding: 32px 28px 48px; }
  .service-error-code { font-size: clamp(104px, 26vw, 164px); }
  .service-error-rail, .service-error-foot { padding-inline: 24px; }
  .service-error-foot span:last-child { display: none; }
}

@media (max-width: 900px) {
  .login-shell { display: block; border: 0; }
  .login-story { min-height: 0; padding: 32px clamp(24px, 6vw, 52px) 42px; border-right: 0; border-bottom: 1px solid var(--border-strong); }
  .login-story-copy { margin: 68px 0 0; padding: 0; }
  .login-story h1 { font-size: clamp(38px, 6.2vw, 58px); }
  .login-map, .login-story-foot { display: none; }
  .login-access { padding: 56px 24px 44px; }
  .login-step { margin-top: 52px; }
  .login-footer { margin-top: 52px; }
}
@media (max-width: 480px) {
  .login-story { padding: 26px 24px 36px; }
  .login-story-copy { margin-top: 52px; }
  .login-story h1 { font-size: clamp(34px, 9vw, 42px); }
  .login-kicker { margin-bottom: 18px; font-size: 10px; }
  .login-intro { margin-top: 18px; font-size: 13px; }
  .login-access { padding: 42px 24px 30px; }
  .login-step { margin-top: 42px; }
  .login-panel h2 { font-size: 34px; }
  .login-google { margin-top: 32px; }
  .login-footer { margin-top: 42px; }
}

/* Medium screens: search takes its own row; small screens: tools wrap and the add button keeps its icon. */
@media (max-width: 900px) {
  .app-top { grid-template-columns: auto 1fr; grid-template-areas: "brand actions" "search search"; height: auto; row-gap: 10px; padding: 10px 16px 12px; }
  .app-toolbar { margin-top: 16px; }
  .app-top .brand { grid-area: brand; }
  .app-top-actions { grid-area: actions; justify-self: end; }
  .app-search { grid-area: search; max-width: none; }
  .app-toolbar { padding: 0 16px; flex-wrap: wrap; }
  .sections { padding: 10px 16px 40px; }
}
@media (max-width: 640px) {
  .btn-label, .who-email { display: none; }
  .who-chip { padding: 0 4px; }
  .toolbar-tools { width: 100%; justify-content: flex-end; flex-wrap: wrap; }
  /* Cards are one column on a phone: the size slider has nothing to change there. */
  .toolbar-tools .card-size { display: none; }
  .card-edit { opacity: 1; }
}

/* Short mobile viewports prioritize the login action while retaining the brand and account instructions. */
@media (max-width: 900px) and (max-height: 700px) {
  .login-story { padding: 20px 24px; }
  .login-story-copy { margin-top: 24px; }
  .login-kicker { margin-bottom: 12px; }
  .login-intro { margin-top: 12px; }
  .login-access { padding: 24px; }
  .login-panel-top { display: none; }
  .login-step { margin: 0 0 8px; }
  .login-description { margin-top: 14px; }
  .login-google { margin-top: 20px; }
  .login-footer { margin-top: 24px; }
}

/* ---------- Administrator console (/admin) ---------- */
body.console { background: var(--bg); }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.console-top {
  position: sticky; top: 0; z-index: 30; height: 56px; padding: 0 20px;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  border-bottom: 1px solid var(--border); background: var(--tabbar-bg); backdrop-filter: saturate(160%) blur(14px);
}
.console-brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.console-crumb {
  display: inline-flex; align-items: center; height: 22px; padding: 0 9px; border-radius: 6px;
  border: 1px solid var(--border); background: var(--surface-1); color: var(--muted); font-size: 12.5px; font-weight: 600; white-space: nowrap;
}
.console-top-actions { display: flex; align-items: center; gap: 8px; }
.console-top .who { margin-right: 4px; }
.console-shell { display: grid; grid-template-columns: 232px minmax(0, 1fr); min-height: calc(100vh - 56px); }
.console-nav {
  position: sticky; top: 56px; align-self: start; height: calc(100vh - 56px);
  display: flex; flex-direction: column; gap: 2px; padding: 18px 12px; border-right: 1px solid var(--border);
}
.console-nav button {
  display: flex; align-items: center; gap: 10px; width: 100%; min-height: 38px; padding: 0 12px;
  border: 0; border-radius: 8px; background: transparent; color: var(--muted); font-size: 14px; font-weight: 500; text-align: left; cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.console-nav button:hover { background: var(--surface-2); color: var(--text-strong); }
.console-nav button:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.console-nav button[aria-current="page"] {
  background: var(--bg-elev); color: var(--text-strong); font-weight: 600; box-shadow: var(--shadow-xs), 0 0 0 1px var(--border), var(--highlight);
}
.console-nav button[aria-current="page"] svg { color: var(--accent-ink); }
.console-nav svg { width: 17px; height: 17px; flex: none; }
.nav-count {
  margin-left: auto; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px;
  display: inline-grid; place-items: center; background: var(--accent); color: var(--accent-contrast); font-size: 11.5px; font-weight: 700;
}
.console-main { width: 100%; max-width: 1320px; padding: 32px 40px 80px; }
/* No menu (a notice instead of the views): the card uses the whole row. */
.console-nav.hidden + .console-main { grid-column: 1 / -1; margin: 0 auto; }
.console-status { margin: 0 0 14px; min-height: 1.4em; color: var(--muted); font-size: 13px; }
.console-status[role="alert"], .view-status[role="alert"] { color: var(--danger); }
.view-status { margin: 0 0 12px; min-height: 0; font-size: 13.5px; }
.view-status:empty { display: none; }
.head-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.records-count { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.view-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px 24px; flex-wrap: wrap; margin-bottom: 20px; }
.view-head h1 { margin: 0; font-size: 22px; font-weight: 700; letter-spacing: -0.025em; }
.view-head p { margin: 6px 0 0; max-width: 760px; color: var(--muted); font-size: 13.5px; line-height: 1.65; }
.panel { border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg-elev); box-shadow: var(--shadow-xs), var(--highlight); }
.panel + .panel, .panel + section.panel { margin-top: 16px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 20px; border-bottom: 1px solid var(--border); }
.panel-head h2 { margin: 0; font-size: 14.5px; font-weight: 650; letter-spacing: -0.01em; }
.panel-body { padding: 20px; }
.stack { display: flex; flex-direction: column; gap: 14px; }
/* Tables: a tinted header, roomy rows, numbers aligned, horizontal scroll on narrow screens. */
.console .table-scroll { position: relative; overflow-x: auto; border: 0; border-radius: var(--radius); background: transparent; }
.data-table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 13.5px; }
.data-table th {
  padding: 10px 16px; text-align: left; font-size: 12px; font-weight: 600; color: var(--muted); white-space: nowrap;
  border-bottom: 1px solid var(--border); background: var(--surface-1);
}
.data-table th:first-child { border-top-left-radius: calc(var(--radius) - 1px); }
.data-table th:last-child { border-top-right-radius: calc(var(--radius) - 1px); }
.data-table td { padding: 12px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; transition: background 0.12s; }
.data-table tbody tr:last-child td { border-bottom: 0; }
.data-table tbody tr:hover td { background: var(--surface-1); }
.data-table tr.is-pending td { background: color-mix(in srgb, var(--warn) 6%, transparent); }
.data-table tr.is-pending td:first-child { box-shadow: inset 3px 0 0 var(--warn); }
.data-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.records-table td { white-space: pre-wrap; overflow-wrap: anywhere; vertical-align: top; min-width: 140px; font-size: 13px; }
.cell-main { display: block; font-weight: 600; color: var(--text-strong); word-break: keep-all; overflow-wrap: anywhere; }
.data-table td:first-child { min-width: 230px; }
.cell-sub { display: block; margin-top: 3px; color: var(--secondary); font-size: 12px; background: none; border: 0; padding: 0; }
code.cell-sub { font-size: 11.5px; }
.empty-cell { padding: 40px 16px !important; text-align: center; color: var(--muted); }
.actions-cell { width: 1%; white-space: nowrap; }
.row-actions { display: flex; justify-content: flex-end; gap: 6px; flex-wrap: nowrap; }
.groups-cell { min-width: 190px; }
.time-cell { white-space: nowrap; color: var(--muted); font-variant-numeric: tabular-nums; }
.groups-cell .chips { display: inline-flex; margin-right: 8px; vertical-align: middle; }
.groups-cell .btn { vertical-align: middle; }
.pagination { display: flex; align-items: center; justify-content: flex-end; gap: 10px; padding: 12px 16px; border-top: 1px solid var(--border); background: var(--surface-1); border-radius: 0 0 var(--radius) var(--radius); }
.pagination span { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
/* ---------- Status badges, chips, switches and pickers (shared) ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 6px; height: 22px; padding: 0 9px; border-radius: 999px;
  border: 1px solid transparent; font-size: 12px; font-weight: 600; white-space: nowrap;
}
.badge::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.ok { color: var(--ok); background: var(--ok-bg); border-color: color-mix(in srgb, var(--ok) 24%, transparent); }
.badge.warn { color: var(--warn); background: var(--warn-bg); border-color: color-mix(in srgb, var(--warn) 26%, transparent); }
.badge.off { color: var(--muted); background: var(--surface-2); border-color: var(--border); }
.badge.admin { color: var(--accent-ink); background: var(--accent-soft); border-color: color-mix(in srgb, var(--accent) 30%, transparent); }
.chips { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.chip {
  display: inline-flex; align-items: center; height: 24px; padding: 0 9px; border-radius: 7px;
  border: 1px solid var(--border); background: var(--chip-bg); color: var(--text); font-size: 12px; font-weight: 500;
}
.chip.muted { color: var(--secondary); border-style: dashed; background: transparent; }
/* On/off switch on a checkbox (role="switch"). */
.switch { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; font-size: 14px; }
.switch input {
  appearance: none; -webkit-appearance: none; flex: none; position: relative; width: 36px; height: 20px; margin: 0; border-radius: 10px;
  border: 1px solid var(--border-strong); background: var(--surface-3); cursor: pointer; transition: background 0.15s, border-color 0.15s;
}
.switch input::after {
  content: ''; position: absolute; top: 2px; left: 2px; width: 14px; height: 14px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 0 0 0.5px rgba(0, 0, 0, 0.06); transition: transform 0.15s;
}
.switch input:checked { background: var(--accent); border-color: color-mix(in srgb, var(--accent) 82%, #000); }
.switch input:checked::after { transform: translateX(16px); }
.switch input:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--ring); }
.switch input:disabled { opacity: 0.5; cursor: not-allowed; }
.switch small { display: block; margin-top: 2px; color: var(--secondary); font-size: 12.5px; font-weight: 400; }
/* Pickers: one toggle chip per choice. */
.picker { display: flex; flex-wrap: wrap; gap: 8px; }
.pick {
  position: relative; display: inline-flex; align-items: center; gap: 6px; min-height: 32px; padding: 0 12px; border-radius: 8px;
  border: 1px solid var(--border-strong); background: var(--bg-input); color: var(--text); font-size: 13px; font-weight: 500;
  cursor: pointer; user-select: none; box-shadow: var(--shadow-xs); transition: border-color 0.15s, background 0.15s;
}
.pick input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.pick small { color: var(--secondary); font-size: 11.5px; font-family: var(--mono); font-weight: 400; }
.pick:hover { border-color: var(--border-hover); }
.pick:has(input:checked) { border-color: color-mix(in srgb, var(--accent) 60%, transparent); background: var(--accent-soft); color: var(--text-strong); font-weight: 600; }
.pick:has(input:checked)::before { content: '✓'; color: var(--accent-ink); font-weight: 700; }
.pick:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }
.pick:has(input:disabled) { opacity: 0.55; cursor: not-allowed; }
.pick.missing span { text-decoration: line-through; color: var(--secondary); }
.picker-list { max-height: 50vh; overflow: auto; padding: 2px; }
/* Forms in the console. */
.console .field { font-size: 13px; }
.console .field input { min-height: 38px; }
.field input[aria-invalid="true"], .picker[aria-invalid="true"] { border-color: var(--danger); }
.notice-card { max-width: 440px; margin: 10vh auto 0; box-shadow: var(--shadow), var(--highlight); }
.notice-card .panel-body { padding: 28px; }
.notice-card h1 { margin: 0 0 6px; font-size: 20px; letter-spacing: -0.02em; }
.notice-card p { margin: 0 0 10px; line-height: 1.6; font-size: 13.5px; }
.notice-card p:empty { display: none; }
.notice-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 20px; }
.add-panel { margin-bottom: 16px; }
.add-grid { display: grid; grid-template-columns: minmax(220px, 1fr) minmax(220px, 1.4fr) auto auto; align-items: end; gap: 16px; }
.add-actions { display: flex; gap: 8px; }
.filter-bar { display: flex; align-items: flex-end; gap: 12px; flex-wrap: wrap; padding: 16px 20px; margin-bottom: 16px; }
.filter-bar .field { flex: 1 1 170px; }
.filter-bar .btn { min-height: 38px; }
.settings-form { display: flex; flex-direction: column; gap: 16px; }
.settings-form fieldset { margin: 0; padding: 0; min-width: 0; }
.settings-form legend { width: 100%; padding: 14px 20px; float: left; }
.settings-form legend + .panel-body { clear: both; }
.settings-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 280px), 1fr)); gap: 18px 20px; align-items: start; }
.settings-grid .field { min-width: 0; }
.settings-grid .field input, .settings-grid .field textarea { min-width: 0; max-width: 100%; }
.settings-grid .wide { grid-column: 1 / -1; }
.settings-grid .switch { min-height: 38px; }
.settings-bar {
  position: sticky; bottom: 16px; z-index: 5; display: flex; align-items: center; justify-content: flex-end; gap: 16px;
  padding: 12px 14px 12px 20px; border: 1px solid var(--border-strong); border-radius: var(--radius); background: var(--tabbar-bg);
  backdrop-filter: saturate(160%) blur(14px); box-shadow: var(--shadow);
}
.settings-bar p { margin: 0 auto 0 0; color: var(--muted); font-size: 13px; white-space: pre-line; }
#settings-status[role="alert"] { color: var(--danger); }
.modal.modal-sm { width: min(460px, calc(100vw - 32px)); }
/* Developer documents: the list beside the open document, drawn from Markdown by docs.js. */
.docs-shell { display: grid; grid-template-columns: 250px minmax(0, 1fr); gap: 16px; align-items: start; }
.docs-list { position: sticky; top: 72px; display: flex; flex-direction: column; gap: 2px; padding: 8px; }
.docs-list button {
  display: flex; flex-direction: column; align-items: flex-start; gap: 2px; width: 100%; padding: 10px 12px;
  border: 0; border-radius: 8px; background: transparent; color: var(--muted); font: inherit; text-align: left; cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.docs-list button:hover { background: var(--surface-2); }
.docs-list button:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.docs-list button[aria-current="page"] { background: var(--accent-soft); }
.docs-list button .cell-main { font-size: 13.5px; }
.docs-list button .cell-sub { margin-top: 0; }
.docs-list .empty-cell { padding: 24px 12px !important; }
.docs-body { padding: 28px 32px 36px; font-size: 14px; line-height: 1.7; color: var(--text); overflow-wrap: anywhere; }
.docs-body:empty { display: none; }
.docs-body > :first-child { margin-top: 0; }
.docs-body h2 { margin: 0 0 16px; font-size: 22px; font-weight: 700; letter-spacing: -0.025em; }
.docs-body h3 { margin: 30px 0 10px; padding-top: 22px; border-top: 1px solid var(--border); font-size: 17px; font-weight: 650; letter-spacing: -0.015em; }
.docs-body h4 { margin: 22px 0 8px; font-size: 14.5px; font-weight: 650; }
.docs-body h5, .docs-body h6 { margin: 18px 0 6px; font-size: 13.5px; font-weight: 650; color: var(--muted); }
.docs-body p, .docs-body ul, .docs-body ol { margin: 0 0 12px; }
.docs-body ul, .docs-body ol { padding-left: 22px; }
.docs-body li { margin: 3px 0; }
.docs-body li > p { margin: 0 0 6px; }
.docs-body li > ul, .docs-body li > ol { margin: 4px 0 6px; }
.docs-body pre { margin: 0 0 14px; padding: 12px 14px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface-1); font-size: 12.5px; line-height: 1.55; overflow: auto; }
.docs-body pre code { padding: 0; border: 0; background: none; font-size: inherit; }
.docs-body blockquote { margin: 0 0 12px; padding: 2px 0 2px 14px; border-left: 3px solid var(--accent); color: var(--muted); }
.docs-body blockquote > :last-child { margin-bottom: 0; }
.docs-body hr { margin: 24px 0; border: 0; border-top: 1px solid var(--border); }
/* A wide table scrolls inside its frame rather than squeezing its cells: words and code stay whole. */
.console .docs-body .table-scroll { margin: 0 0 14px; border: 1px solid var(--border); }
.docs-body .data-table { font-size: 13px; }
.docs-body .data-table th, .docs-body .data-table td { overflow-wrap: normal; word-break: keep-all; }
.docs-body .data-table th { white-space: normal; }
.docs-body .data-table td { vertical-align: top; line-height: 1.6; }
.docs-body .data-table td:first-child { min-width: 120px; }
.docs-body .data-table code { white-space: nowrap; }
.docs-body a { color: var(--accent-ink); text-decoration: underline; text-underline-offset: 2px; }
.docs-body a:hover { color: var(--accent-hover); }
.docs-body [id^="doc-"] { scroll-margin-top: 72px; }

@media (max-width: 960px) {
  .console-shell { grid-template-columns: minmax(0, 1fr); }
  .docs-shell { grid-template-columns: minmax(0, 1fr); }
  .docs-list { position: static; }
  .docs-body { padding: 20px 18px 28px; }
  .console-nav { position: sticky; top: 56px; z-index: 20; height: auto; flex-direction: row; overflow-x: auto; padding: 8px 12px;
    border-right: 0; border-bottom: 1px solid var(--border); background: var(--tabbar-bg); backdrop-filter: blur(14px); }
  .console-nav button { width: auto; flex: none; min-height: var(--ui-control-height); }
  .console-main { padding: 22px 16px 64px; }
  .add-grid { grid-template-columns: 1fr; }
  .console-crumb { display: none; }
}
@media (max-width: 640px) {
  .console-top { padding: 0 12px; }
  .console-top .who { display: none; }
  .console-top .brand-text { white-space: nowrap; }
}

/* ---------- Server-rendered message pages (login outcomes, logout confirmation) ---------- */
.message-page { background: radial-gradient(900px 420px at 50% 0%, var(--bg-glow), transparent 70%) no-repeat, var(--bg); }
.message-shell { min-height: calc(100vh - 56px); display: grid; place-items: center; padding: 32px 16px 64px; }
.message-card {
  position: relative; width: min(500px, 100%); padding: 32px 32px 0; overflow: hidden;
  border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--bg-elev); box-shadow: var(--shadow), var(--highlight);
}
.message-card::before { content: ''; position: absolute; inset: 0 0 auto; height: 3px; background: linear-gradient(90deg, var(--accent), var(--accent-2)); }
.message-card h1 { margin: 0 0 10px; font-size: 20px; letter-spacing: -0.025em; }
.message-card p { margin: 0 0 10px; color: var(--muted); font-size: 14px; line-height: 1.7; }
.message-card .message-detail { color: var(--secondary); font-size: 12.5px; }
.message-actions {
  display: flex; flex-wrap: wrap; gap: 8px; margin: 22px -32px 0; padding: 16px 32px;
  border-top: 1px solid var(--border); background: var(--surface-1);
}
.message-card > p:last-child { margin-bottom: 28px; }
.message-actions form { margin: 0; }
.message-actions .btn { min-height: 38px; }
