/* Kjerne Utils dashboard - dark-first theme. */
:root {
  --bg: #0f1115;
  --bg-elev: #171a21;
  --bg-elev-2: #1f232c;
  --border: #2a2f3a;
  --text: #e6e8ec;
  --text-dim: #9aa3b2;
  --accent: #5865f2;       /* Discord blurple */
  --accent-hover: #4752c4;
  --danger: #ed4245;
  --ok: #3ba55d;
  --warn: #faa61a;
  --radius: 10px;
  --shadow: 0 2px 10px rgba(0,0,0,.35);
}
[data-theme="light"] {
  --bg: #f5f6f8; --bg-elev: #fff; --bg-elev-2: #eef0f3;
  --border: #d8dbe0; --text: #1d2026; --text-dim: #5b6370;
  --shadow: 0 2px 10px rgba(0,0,0,.12);
}
[data-theme="black"] {
  --bg: #000; --bg-elev: #0a0a0c; --bg-elev-2: #141418;
  --border: #24242e; --text: #ececf1; --text-dim: #8b8b96;
}
[data-theme="midnight"] {
  --bg: #12101f; --bg-elev: #1a1730; --bg-elev-2: #241f42;
  --border: #352c56; --text: #ece9f7; --text-dim: #a99fc7;
  --accent: #a855f7; --accent-hover: #9333ea;
}
[data-theme="ocean"] {
  --bg: #0b1620; --bg-elev: #0f2030; --bg-elev-2: #152b3f;
  --border: #20415c; --text: #e2edf3; --text-dim: #8fb0c4;
  --accent: #14b8a6; --accent-hover: #0d9488;
}
[data-theme="forest"] {
  --bg: #0c140f; --bg-elev: #111e17; --bg-elev-2: #182a20;
  --border: #22402f; --text: #e3efe8; --text-dim: #8fb3a1;
  --accent: #22c55e; --accent-hover: #16a34a;
}
[data-theme="crimson"] {
  --bg: #160b0d; --bg-elev: #1f1113; --bg-elev-2: #2c181b;
  --border: #4a2328; --text: #f3e6e8; --text-dim: #c39aa0;
  --accent: #ef4444; --accent-hover: #dc2626;
}
[data-theme="sunset"] {
  --bg: #17110a; --bg-elev: #211810; --bg-elev-2: #2f2214;
  --border: #4a3620; --text: #f4ebdf; --text-dim: #c8ac8d;
  --accent: #f97316; --accent-hover: #ea580c;
}
[data-theme="rose"] {
  --bg: #160f13; --bg-elev: #20161c; --bg-elev-2: #2c1f28;
  --border: #472f40; --text: #f3e8ef; --text-dim: #c49bb4;
  --accent: #ec4899; --accent-hover: #db2777;
}
[data-theme="nord"] {
  --bg: #20242c; --bg-elev: #2a2f3a; --bg-elev-2: #333a47;
  --border: #3f4757; --text: #e5e9f0; --text-dim: #a3adc0;
  --accent: #5e81ac; --accent-hover: #4c6f96;
}
[data-theme="github"] {
  --bg: #0d1117; --bg-elev: #161b22; --bg-elev-2: #21262d;
  --border: #30363d; --text: #c9d1d9; --text-dim: #8b949e;
  --accent: #58a6ff; --accent-hover: #388bfd; --ok: #3fb950; --danger: #f85149;
}
[data-theme="vscode"] {
  --bg: #1e1e1e; --bg-elev: #252526; --bg-elev-2: #2d2d30;
  --border: #3c3c3c; --text: #d4d4d4; --text-dim: #969696;
  --accent: #007acc; --accent-hover: #0e639c;
}
[data-theme="dracula"] {
  --bg: #282a36; --bg-elev: #21222c; --bg-elev-2: #343746;
  --border: #44475a; --text: #f8f8f2; --text-dim: #8b90b8;
  --accent: #bd93f9; --accent-hover: #a679f0; --ok: #50fa7b; --danger: #ff5555; --warn: #f1fa8c;
}
[data-theme="tokyo"] {
  --bg: #1a1b26; --bg-elev: #1f2335; --bg-elev-2: #24283b;
  --border: #2f334d; --text: #c0caf5; --text-dim: #7a82ab;
  --accent: #7aa2f7; --accent-hover: #6a92e7; --ok: #9ece6a; --danger: #f7768e;
}
[data-theme="gruvbox"] {
  --bg: #282828; --bg-elev: #32302f; --bg-elev-2: #3c3836;
  --border: #504945; --text: #ebdbb2; --text-dim: #a89984;
  --accent: #fabd2f; --accent-hover: #d79921; --ok: #b8bb26; --danger: #fb4934;
}
[data-theme="catppuccin"] {
  --bg: #1e1e2e; --bg-elev: #181825; --bg-elev-2: #313244;
  --border: #45475a; --text: #cdd6f4; --text-dim: #a6adc8;
  --accent: #cba6f7; --accent-hover: #b794f6; --ok: #a6e3a1; --danger: #f38ba8; --warn: #f9e2af;
}
[data-theme="onedark"] {
  --bg: #282c34; --bg-elev: #21252b; --bg-elev-2: #2c313a;
  --border: #3e4451; --text: #abb2bf; --text-dim: #7f848e;
  --accent: #61afef; --accent-hover: #4d9fe0; --ok: #98c379; --danger: #e06c75; --warn: #e5c07b;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }

/* Scrollbars follow the active theme (the vars are re-declared per theme above);
   without this, scroll containers render the browser default light chrome. */
* { scrollbar-width: thin; scrollbar-color: var(--border) transparent; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--border); border-radius: 6px;
  border: 2px solid transparent; background-clip: content-box;
}
::-webkit-scrollbar-thumb:hover { background: var(--text-dim); background-clip: content-box; }
::-webkit-scrollbar-corner { background: transparent; }
body {
  background: var(--bg); color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  display: flex; flex-direction: column; min-height: 100vh;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.topbar {
  display: flex; align-items: center; gap: 18px;
  padding: 12px 20px; background: var(--bg-elev);
  border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 10;
}
.brand { font-weight: 700; font-size: 18px; color: var(--text); }
/* Topbar chrome links are buttons/nav, not prose: kill the global hover underline
   (brand "Kjerne", the Servers/Backups/Admin topnav, and their icons). */
.brand:hover, .topnav a:hover { text-decoration: none; }
.topnav { display: flex; gap: 16px; }
.topnav a { color: var(--text-dim); }
.topnav a:hover { color: var(--text); }
.user { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.user-menu { margin-left: auto; }
/* User dropdown opens flush to the right edge and is sized for its short menu. */
.user-menu .server-switch-menu { left: auto; right: 0; min-width: 180px; }
.username { color: var(--text-dim); }

.container { width: 100%; max-width: 1680px; margin: 0 auto; padding: 26px 34px; flex: 1; }
.footer { padding: 16px 34px; color: var(--text-dim); border-top: 1px solid var(--border); font-size: 13px; }

[x-cloak] { display: none !important; }

/* Server switcher (top bar) */
.server-switch { position: relative; }
.server-switch-btn {
  display: flex; align-items: center; gap: 8px; cursor: pointer;
  background: var(--bg-elev-2); border: 1px solid var(--border); color: var(--text);
  padding: 7px 12px; border-radius: 8px; font: inherit; font-size: 14px;
}
.server-switch-btn:hover { border-color: var(--accent); }
.server-switch-menu {
  position: absolute; top: 110%; left: 0; z-index: 30; min-width: 260px; max-height: 380px;
  overflow-y: auto; background: var(--bg-elev); border: 1px solid var(--border);
  border-radius: 10px; box-shadow: var(--shadow); padding: 8px;
}
.server-switch-menu a, .server-switch-menu button {
  display: block; width: 100%; text-align: left; padding: 8px 10px; border-radius: 6px;
  color: var(--text); background: none; border: 0; font: inherit; cursor: pointer; }
.server-switch-menu a:hover, .server-switch-menu button:hover { background: var(--bg-elev-2); text-decoration: none; }
.server-switch-menu a.active, .server-switch-menu button.active { background: var(--accent); color: #fff; }
.server-switch-search { width: 100%; margin-bottom: 6px; }
/* Logout is a POST form (CSRF) styled to sit among the menu anchors. */
.server-switch-menu .logout-form { margin: 0; }
/* Theme switcher lives in the top-right corner; open its menu right-aligned so
   it doesn't overflow off-screen. */
.theme-switch { margin-left: 8px; }
.tsw-menu { left: auto; right: 0; min-width: 180px; }

/* Token select (searchable multi/single with removable chips) */
.ts { position: relative; }
.ts-box {
  display: flex; flex-wrap: wrap; gap: 6px; align-items: center; min-height: 40px;
  padding: 6px 8px; background: var(--bg-elev-2); border: 1px solid var(--border); border-radius: 8px;
}
.ts-box:focus-within { border-color: var(--accent); }
.chip {
  display: inline-flex; align-items: center; gap: 6px; background: var(--accent);
  color: #fff; border-radius: 6px; padding: 3px 4px 3px 9px; font-size: 13px;
}
.chip button {
  background: transparent; border: none; color: #fff; cursor: pointer; font-size: 14px;
  line-height: 1; padding: 0 4px; border-radius: 4px;
}
.chip button:hover { background: rgba(255,255,255,.25); }
.ts-input { flex: 1; min-width: 120px; border: none; background: transparent; color: var(--text); font: inherit; outline: none; padding: 4px; }
.ts-caret { color: var(--text-dim); cursor: pointer; padding: 0 4px; align-self: center; }
.ts-box:hover .ts-caret { color: var(--accent); }

/* Multi-select checkbox list (JS-free) */
.ms { border: 1px solid var(--border); border-radius: 8px; background: var(--bg-elev-2); overflow: hidden; }
.ms-filter { width: 100%; border: none; border-bottom: 1px solid var(--border); border-radius: 0;
  background: var(--bg-elev); padding: 8px 11px; }
.ms-filter:focus { outline: none; border-bottom-color: var(--accent); }
.ms-list { max-height: 220px; overflow-y: auto; padding: 4px; }
.ms-list label {
  display: flex; align-items: center; gap: 9px; padding: 6px 9px; border-radius: 6px;
  cursor: pointer; margin: 0; color: var(--text); font-size: 14px;
}
.ms-list label:hover { background: var(--bg-elev); }
.ms-list input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--accent); margin: 0; }
.ts-native { width: 100%; }
.ts-drop {
  position: absolute; top: 100%; left: 0; right: 0; z-index: 20; margin-top: 4px; max-height: 240px;
  overflow-y: auto; background: var(--bg-elev); border: 1px solid var(--border); border-radius: 8px; box-shadow: var(--shadow);
}
.ts-opt { padding: 8px 11px; cursor: pointer; font-size: 14px; display: flex; align-items: center; gap: 8px; }
.ts-opt:hover, .ts-opt.hi { background: var(--accent); color: #fff; }
/* Coloured role dot in chips + dropdown options. */
.ts-dot { width: 10px; height: 10px; border-radius: 50%; flex: none; display: inline-block; }

/* Feature-page on/off pill (consistent enable toggle across every page). */
.toggle-pill {
  display: inline-flex; align-items: center; gap: 8px; padding: 7px 14px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--bg-elev-2); color: var(--text);
  cursor: pointer; font-weight: 600; font-size: 13px; white-space: nowrap;
}
.toggle-pill .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--text-dim); }
.toggle-pill:hover { border-color: var(--accent); }
.toggle-pill.on { border-color: #3ba55d; color: #3ba55d; }
.toggle-pill.on .dot { background: #3ba55d; box-shadow: 0 0 6px #3ba55d; }
.toggle-pill.off { color: var(--text-dim); }
.toggle-pill.off .dot { background: #9aa3b2; }

/* --- Embed builder layout --- */
.eb-toolbar {
  display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 8px;
  margin-bottom: 14px; padding: 10px 12px; background: var(--bg-elev);
  border: 1px solid var(--border); border-radius: 12px;
}
.eb-grid { display: grid; grid-template-columns: minmax(0, 1fr) 420px; gap: 20px; align-items: start; }
@media (max-width: 1000px) { .eb-grid { grid-template-columns: 1fr; } .eb-side { position: static !important; } }
.eb-editor { display: flex; flex-direction: column; gap: 10px; }
.eb-side { position: sticky; top: calc(var(--topbar-h) + var(--context-h) + 8px); align-self: start; display: flex; flex-direction: column; gap: 12px; }
.eb-section { background: var(--bg-elev); border: 1px solid var(--border); border-radius: 12px; overflow: hidden; }
.eb-section-head {
  width: 100%; display: flex; align-items: center; gap: 8px; padding: 12px 14px;
  background: transparent; border: none; color: var(--text); font-weight: 600; font-size: 15px;
  cursor: pointer; text-align: left; font-family: inherit;
}
.eb-section-head:hover { background: var(--bg-elev-2); }
.eb-section-hint { font-weight: 400; font-size: 12px; margin-left: auto; }
.eb-caret { display: inline-block; transition: transform .15s; color: var(--text-dim); font-size: 12px; }
.eb-caret.open { transform: rotate(90deg); }
.eb-section-body { padding: 0 14px 14px; display: flex; flex-direction: column; gap: 10px; }
.eb-item { background: var(--bg-elev-2); border: 1px solid var(--border); border-radius: 8px; padding: 10px; }
.eb-item + .eb-item { margin-top: 8px; }
.eb-item.eb-dragging { opacity: .45; }
.eb-drag-handle { cursor: grab; color: var(--text-dim); padding: 0 6px; user-select: none; font-size: 16px; line-height: 1; align-self: center; }
.eb-drag-handle:active { cursor: grabbing; }
.eb-count { font-size: 11px; font-weight: 400; }

/* Markdown / emoji toolbar above description + field-value textareas. */
.eb-mdbar { display: flex; flex-wrap: wrap; gap: 4px; margin: 6px 0; align-items: center; }
.eb-mdbar button {
  background: var(--bg-elev); border: 1px solid var(--border); color: var(--text);
  border-radius: 6px; padding: 2px 7px; font-size: 13px; line-height: 1.5; cursor: pointer;
}
.eb-mdbar button:hover { border-color: var(--accent); }
.eb-mdbar-sep { width: 1px; align-self: stretch; background: var(--border); margin: 2px 4px; }
.eb-emoji-wrap { position: relative; }
.eb-emoji-pop {
  position: absolute; top: 110%; left: 0; z-index: 40; width: 250px;
  background: var(--bg-elev); border: 1px solid var(--border); border-radius: 10px;
  box-shadow: var(--shadow); padding: 8px;
}
.eb-emoji-head { font-size: 11px; color: var(--text-dim); margin: 2px 2px 4px; text-transform: uppercase; letter-spacing: .04em; }
.eb-emoji-grid { display: grid; grid-template-columns: repeat(10, 1fr); gap: 2px; margin-bottom: 6px; }
.eb-emoji-grid button {
  background: transparent; border: none; cursor: pointer; font-size: 16px;
  padding: 3px 0; border-radius: 5px; line-height: 1;
}
.eb-emoji-grid button:hover { background: var(--bg-elev-2); }

/* A <label> styled as a button (e.g. Import file) must match real buttons. */
label.btn { display: inline-flex; align-items: center; justify-content: center; line-height: 1.2; }

/* Floating Save/Reset bar (sticky on scroll). Centered + prominent. */
#save-fab {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%);
  display: none; gap: 10px; z-index: 60; align-items: center;
  background: var(--bg-elev); border: 2px solid var(--accent); border-radius: 14px;
  padding: 10px 14px; box-shadow: 0 8px 30px rgba(0,0,0,.45), 0 0 0 4px rgba(88,101,242,.12);
}
#save-fab .btn { padding: 9px 20px; font-weight: 600; }
#save-fab::before {
  content: "Unsaved changes"; color: var(--text-dim); font-size: 13px; margin-right: 4px;
}

/* Date/time inputs: match the dark theme + a cleaner picker icon. */
input[type="date"], input[type="datetime-local"], input[type="time"], input[type="month"] {
  color-scheme: dark;
}
input[type="date"]::-webkit-calendar-picker-indicator,
input[type="datetime-local"]::-webkit-calendar-picker-indicator,
input[type="time"]::-webkit-calendar-picker-indicator {
  filter: invert(0.65); cursor: pointer; opacity: 0.8;
}
input[type="date"]::-webkit-calendar-picker-indicator:hover { opacity: 1; }

/* Custom date + time picker (calendar popover). Replaces native date fields. */
.dtp { position: relative; }
.dtp-trigger {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  width: 100%; text-align: left; font-family: inherit;
  padding: 9px 11px; background: var(--bg-elev-2); border: 1px solid var(--border);
  border-radius: 8px; cursor: pointer; color: var(--text); font-size: 14px;
}
.dtp-trigger:hover { border-color: var(--accent); }
.dtp-trigger .dtp-placeholder { color: var(--text-dim); }
.dtp-trigger i { color: var(--text-dim); }
.dtp-pop {
  position: absolute; z-index: 50; top: calc(100% + 4px); left: 0; width: 262px;
  background: var(--bg-elev); border: 1px solid var(--border); border-radius: 10px;
  box-shadow: var(--shadow); padding: 10px;
}
.dtp-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; font-weight: 600; }
.dtp-head button {
  background: var(--bg-elev-2); border: 1px solid var(--border); color: var(--text);
  width: 28px; height: 28px; border-radius: 6px; cursor: pointer; font-size: 16px; line-height: 1;
}
.dtp-head button:hover { border-color: var(--accent); }
.dtp-dow, .dtp-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; }
.dtp-dow span { text-align: center; font-size: 11px; color: var(--text-dim); padding: 2px 0; }
.dtp-day {
  aspect-ratio: 1; background: transparent; border: none; border-radius: 6px;
  color: var(--text); cursor: pointer; font-size: 13px;
}
.dtp-day:hover:not(.empty) { background: var(--bg-elev-2); }
.dtp-day.sel { background: var(--accent); color: #fff; }
.dtp-day.empty { visibility: hidden; cursor: default; }
.dtp-time { display: flex; align-items: center; gap: 6px; margin-top: 10px; padding-top: 8px; border-top: 1px solid var(--border); }
.dtp-time input { width: 56px; text-align: center; }
.dtp-time .btn-sm { margin-left: auto; }

/* Staff permission editor */
.perm-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.perm-allctl { display: inline-flex; gap: 6px; font-weight: 400; }
.perm-groups { display: flex; flex-direction: column; gap: 8px; }
.perm-group { border: 1px solid var(--border); border-radius: 8px; background: var(--bg-elev-2); overflow: hidden; }
.perm-group-head {
  width: 100%; display: flex; align-items: center; gap: 8px; padding: 10px 12px;
  background: none; border: 0; color: var(--text); font: inherit; font-weight: 600; cursor: pointer; text-align: left;
}
.perm-group-head::before {
  content: "▶"; font-size: 10px; color: var(--text-dim); transition: transform .15s ease; flex: none;
}
.perm-group.open .perm-group-head::before { transform: rotate(90deg); }
.perm-group-name { flex: 1; }
.perm-group-count { font-weight: 400; font-size: 12px; }
.perm-group-body { display: none; flex-direction: column; gap: 4px; padding: 4px 10px 10px; }
.perm-group.open .perm-group-body { display: flex; }

.perm-item { border: 1px solid var(--border); border-radius: 8px; background: var(--bg-elev); }
.perm-row { display: flex; align-items: center; gap: 14px; padding: 8px 12px; }
.perm-name { font-weight: 500; }
.perm-tog { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-size: 14px; color: var(--text); }
.perm-actions { display: none; flex-direction: column; gap: 8px; padding: 4px 12px 12px 34px; border-top: 1px solid var(--border); }
.perm-item.viewon .perm-actions { display: flex; }
.perm-action-item { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-size: 13px; color: var(--text-dim); }
.perm-reserved { opacity: .7; }
.perm-soon {
  font-size: 10px; text-transform: uppercase; letter-spacing: .04em; padding: 1px 6px; border-radius: 10px;
  border: 1px solid var(--border); color: var(--text-dim); background: var(--bg-elev-2);
}
.perm-groups input[type="checkbox"] {
  -webkit-appearance: none; appearance: none; width: 19px; height: 19px; margin: 0; flex: none;
  border: 1px solid var(--border); border-radius: 5px; background: var(--bg-elev);
  cursor: pointer; position: relative; vertical-align: middle;
}
.perm-groups input[type="checkbox"]:hover { border-color: var(--accent); }
.perm-groups input[type="checkbox"]:checked { background: var(--accent); border-color: var(--accent); }
.perm-groups input[type="checkbox"]:checked::after {
  content: "✓"; color: #fff; font-size: 13px; font-weight: 700;
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
}

/* Dashboard confirm dialog */
.confirm-modal { display: none; position: fixed; inset: 0; z-index: 1100; padding: 24px;
  background: rgba(0,0,0,.6); align-items: center; justify-content: center; }
.confirm-modal.open { display: flex; }
.confirm-box { width: 100%; max-width: 420px; background: var(--bg-elev); border: 1px solid var(--border);
  border-radius: 12px; padding: 20px; box-shadow: 0 12px 40px rgba(0,0,0,.4); }

/* User-history quick-view modal */
.uh-modal { display: none; position: fixed; inset: 0; z-index: 1000; padding: 24px;
  background: rgba(0,0,0,.6); align-items: flex-start; justify-content: center; overflow-y: auto; }
.uh-modal.open { display: flex; }
.uh-modal-box { position: relative; width: 100%; max-width: 920px; margin-top: 40px;
  background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: 0 12px 40px rgba(0,0,0,.5); padding: 20px; }
.uh-del { display: inline; margin: 0; }

/* Consistent filter/search bar: label-above-control, all controls same height,
   bottom-aligned so mixed control types (selects, text, custom date pickers,
   buttons) line up. Used by user history, audit log, records, etc. */
.filterbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: flex-end; }
.filterbar > label { display: flex; flex-direction: column; gap: 3px; margin: 0;
  font-size: 12px; color: var(--text-dim); }
.filterbar > label > br { display: none; }
.filterbar .field, .filterbar .dtp { margin: 0; }
.filterbar .field > label, .filterbar .dtp > label { font-size: 12px; color: var(--text-dim);
  margin: 0 0 3px; }
.filterbar select, .filterbar input[type="text"], .filterbar input[type="number"],
.filterbar .dtp-trigger, .filterbar .btn {
  height: 34px; box-sizing: border-box; }
/* Fixed 34px height + the base 9px vertical padding left too little room for the
   line box, clipping text at the bottom. Trim vertical padding on the fixed-height
   controls (horizontal padding kept) and pin the line-height so text centres. */
.filterbar select, .filterbar input[type="text"], .filterbar input[type="number"] {
  padding-top: 0; padding-bottom: 0; line-height: 32px; }
.filterbar .btn { display: inline-flex; align-items: center; }

/* Shared layout metrics for the sticky top chrome. Not theme-dependent, so set
   once: topbar height (matches the top:64px other sticky bars already use) and
   the context/breadcrumb bar height. Sticky offsets below compose from these. */
:root { --topbar-h: 62px; --context-h: 48px; }

/* Sticky context bar under the topbar: a breadcrumb trail so the viewer always
   knows where they are, plus the Ctrl-K search trigger on the right. */
.context-bar {
  position: sticky; top: var(--topbar-h); z-index: 8;
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  min-height: var(--context-h); margin: 0 0 18px; padding: 8px 0;
  background: var(--bg); border-bottom: 1px solid var(--border);
}
.crumbs { display: flex; align-items: center; gap: 6px; flex-wrap: wrap;
  min-width: 0; font-size: 14px; }
.crumb { display: inline-flex; align-items: center; gap: 6px; color: var(--text-dim);
  white-space: nowrap; }
.crumb i { font-size: 15px; opacity: .85; }
.crumb-home { color: var(--text); font-weight: 600; }
.crumb-home:hover { color: var(--accent); text-decoration: none; }
.crumb-home img { border-radius: 50%; flex: none; }
.crumb-tab { color: var(--text); font-weight: 600; }
.crumb-sep { font-size: 13px; color: var(--text-dim); opacity: .6; }
.context-bar .ksearch-trigger { margin-left: auto; }

/* Tab strip on a section page (ui.tab_strip). A segmented control: each tab is a
   plain link to the same page with a different ?tab=, so the active one is styled
   by the server, not JS. Named .page-* to sit with .page-toc as page chrome, and
   to stay clear of the user-history modal's own .uh-tab-btn tabs. The wrapper is
   the sticky/scroll surface so the inner nav keeps its rounded segmented look. */
.page-tabs-wrap { position: sticky; z-index: 7;
  top: calc(var(--topbar-h) + var(--context-h));
  margin: 0 0 16px; padding: 6px 0; background: var(--bg); }
.page-tabs { display: inline-flex; flex-wrap: wrap; gap: 4px; max-width: 100%;
  margin: 0; padding: 4px;
  background: var(--bg-elev-2); border: 1px solid var(--border); border-radius: 12px; }
.page-tab { padding: 7px 14px; font-size: 13px; font-weight: 500; line-height: 1;
  display: inline-flex; align-items: center; color: var(--text-dim);
  text-decoration: none; border-radius: 8px;
  transition: background .12s ease, color .12s ease; }
.page-tab:hover { color: var(--text); background: var(--bg-elev); text-decoration: none; }
.page-tab.is-active { color: #fff; background: var(--accent); box-shadow: var(--shadow); }
.page-tab.is-active:hover { color: #fff; background: var(--accent-hover); }

/* In-page section nav ("On this page"): a sticky right rail injected on long
   feature pages. The wrap grows to a third column only when a nav is present. */
.guild-wrap.has-toc { grid-template-columns: 220px minmax(0, 1fr) 210px; }
.page-toc { position: sticky; top: calc(var(--topbar-h) + var(--context-h) + 12px);
  align-self: start;
  max-height: calc(100vh - 92px); overflow: auto;
  background: var(--bg-elev); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 12px 12px 14px; display: flex; flex-direction: column; gap: 10px; }
.page-toc-label { font-weight: 600; font-size: 11px; color: var(--text-dim);
  text-transform: uppercase; letter-spacing: .6px;
  display: inline-flex; align-items: center; gap: 7px;
  padding: 0 4px 10px; border-bottom: 1px solid var(--border); }
.page-toc-label i { font-size: 14px; }
/* faint static track; accent marker slides over it */
.page-toc-links { position: relative; display: flex; flex-direction: column;
  gap: 2px; padding-left: 12px; border-left: 2px solid var(--border); }
.page-toc-marker { position: absolute; left: -2px; width: 2px; top: 0; height: 0;
  background: var(--accent); border-radius: 2px; opacity: 0;
  transition: transform .22s cubic-bezier(.4,0,.2,1),
              height .22s cubic-bezier(.4,0,.2,1), opacity .15s; }
.page-toc-marker.on { opacity: 1; }
.page-toc-links a { font-size: 13px; padding: 6px 10px; color: var(--text-dim);
  text-decoration: none; line-height: 1.35; border-radius: 7px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  transition: color .12s, background .12s; }
.page-toc-links a:hover { color: var(--text); background: var(--bg-elev-2); }
.page-toc-links a.active { color: var(--text); font-weight: 600; }
/* Leave a gap above a card when jumped to from the section nav (clears the whole
   sticky top stack: topbar + context bar + a little breathing room). */
.toc-target { scroll-margin-top: calc(var(--topbar-h) + var(--context-h) + 20px); }
/* Below this width the right rail would crowd the content - drop back to 2 cols
   and hide the nav. */
@media (max-width: 1180px) {
  .guild-wrap.has-toc { grid-template-columns: 220px minmax(0, 1fr); }
  .page-toc { display: none; }
}

/* Owner-blocked feature banner shown at the top of a locked category page. */
.owner-block-bar { display: flex; align-items: center; gap: 10px;
  margin: 0 0 16px; padding: 10px 14px; border-radius: var(--radius);
  background: rgba(229,72,77,.12); border: 1px solid var(--danger, #e5484d);
  color: var(--danger, #e5484d); font-size: 14px;
  position: sticky; top: calc(var(--topbar-h) + var(--context-h)); z-index: 6; }
.owner-block-bar strong { color: var(--danger, #e5484d); }
.owner-block-bar i { font-size: 18px; flex: none; }

/* Custom checkbox matching the theme (generalised from .perm-groups). */
.chk { -webkit-appearance: none; appearance: none; width: 19px; height: 19px; margin: 0; flex: none;
  border: 1px solid var(--border); border-radius: 5px; background: var(--bg-elev);
  cursor: pointer; position: relative; vertical-align: middle; }
.chk:hover { border-color: var(--accent); }
.chk:checked { background: var(--accent); border-color: var(--accent); }
.chk:checked::after { content: "✓"; color: #fff; font-size: 13px; font-weight: 700;
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; }
/* Sits inside the dialog box (the box has 20px padding + position:relative);
   it used to float 30px above it, detached from the dialog on the backdrop. */
.uh-modal-close { position: absolute; top: 10px; right: 10px; background: none; border: 0;
  color: var(--text-dim); font-size: 20px; cursor: pointer; line-height: 1; }
.uh-modal-close:hover, .uh-modal-close:focus-visible { color: var(--text); }
.uh-modal-close:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px;
  border-radius: 6px; }

/* Ticket conversation (dashboard web-support view) */
.ticket-convo { display: flex; flex-direction: column; gap: 10px; max-height: 480px; overflow-y: auto; padding: 4px 2px; }
.tk-msg { max-width: 80%; padding: 8px 12px; border-radius: 10px; border: 1px solid var(--border); background: var(--bg-elev-2); }
.tk-user { align-self: flex-start; }
.tk-staff { align-self: flex-end; border-color: var(--accent); }
.tk-meta { display: flex; align-items: center; gap: 8px; font-size: 12px; margin-bottom: 3px; }
.tk-tag { background: var(--accent); color: #fff; border-radius: 4px; padding: 0 6px; font-size: 11px; }
.tk-body { white-space: pre-wrap; font-size: 14px; word-break: break-word; }
.tk-media { max-width: 260px; max-height: 220px; border-radius: 8px; margin-top: 4px; display: block; }

/* Ticket detail: conversation + right-side open-ticket queue */
.tk-layout { display: grid; grid-template-columns: minmax(0, 1fr) 290px; gap: 16px; align-items: start; }
@media (max-width: 1000px) { .tk-layout { grid-template-columns: 1fr; } .tk-queue { position: static !important; } }
.tk-queue { position: sticky; top: calc(var(--topbar-h) + var(--context-h) + 8px); }
.tk-qgroup { margin-top: 10px; }
.tk-qhead { font-size: 12px; color: var(--text-dim); text-transform: uppercase; letter-spacing: .04em; margin-bottom: 4px; }
.tk-qitem { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; padding: 6px 8px; border-radius: 8px; border: 1px solid var(--border); margin-bottom: 5px; color: var(--text); font-size: 13px; }
.tk-qitem:hover { border-color: var(--accent); text-decoration: none; }
.tk-qitem.active { border-color: var(--accent); background: var(--bg-elev-2); }
.tk-prio, .tk-wait { font-size: 11px; border-radius: 4px; padding: 1px 6px; }
.tk-prio { background: var(--bg-elev-2); color: var(--text-dim); }
.tk-prio-high { background: var(--warn); color: #1a1a1a; }
.tk-prio-urgent { background: var(--danger); color: #fff; }
.tk-wait { margin-left: auto; }
.tk-wait-staff { background: var(--warn); color: #1a1a1a; }
.tk-wait-user { background: var(--bg-elev-2); color: var(--text-dim); }
/* Compact select that matches a .btn-sm height (used next to buttons). */
.select-sm { padding: 5px 10px; font-size: 13px; width: auto; }

/* Modern color swatch (native picker, restyled). */
input[type="color"] {
  -webkit-appearance: none; -moz-appearance: none; appearance: none;
  width: 48px; height: 34px; padding: 3px; cursor: pointer;
  background: var(--bg-elev-2); border: 1px solid var(--border); border-radius: 8px;
}
input[type="color"]:hover { border-color: var(--accent); }
input[type="color"]::-webkit-color-swatch-wrapper { padding: 0; }
input[type="color"]::-webkit-color-swatch { border: none; border-radius: 5px; }
input[type="color"]::-moz-color-swatch { border: none; border-radius: 5px; }

/* Overview enabled/disabled indicator dot. */
.ov-dot { width: 11px; height: 11px; border-radius: 50%; display: inline-block; flex: none; margin-top: 4px; }
.ov-dot.on { background: #3ba55d; box-shadow: 0 0 6px #3ba55d; }
.ov-dot.off { background: #ed4245; }
.ts-empty { padding: 8px 11px; color: var(--text-dim); font-size: 13px; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; cursor: pointer;
  padding: 8px 14px; border-radius: var(--radius); border: 1px solid var(--border);
  background: var(--bg-elev-2); color: var(--text); font-size: 14px; line-height: 1.2;
  vertical-align: middle; box-sizing: border-box; transition: .15s;
}
.btn:hover { text-decoration: none; border-color: var(--accent); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-ghost { background: transparent; }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-sm { padding: 5px 10px; font-size: 13px; }

/* Cards / layout */
.grid { display: grid; gap: 16px; }
.grid-cards { grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
.card {
  background: var(--bg-elev); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow);
}
.card h3 { margin: 0 0 6px; }
.muted { color: var(--text-dim); }
.row { display: flex; gap: 12px; align-items: center; }
.spread { justify-content: space-between; }
.stack { display: flex; flex-direction: column; gap: 14px; }

/* Guild layout with sidebar */
.guild-wrap { display: grid; grid-template-columns: 220px 1fr; gap: 24px; }
/* A grid item defaults to min-width:auto, so wide content (a table) would stretch
   the whole column past the viewport instead of scrolling inside its own box.
   min-width:0 lets the column shrink so .table-scroll can do its job. */
.guild-wrap > section { min-width: 0; }
.sidebar { display: flex; flex-direction: column; gap: 4px; }
.sidebar a {
  padding: 9px 12px; border-radius: 8px; color: var(--text-dim);
}
.sidebar a:hover { background: var(--bg-elev-2); text-decoration: none; }
.sidebar a.active { background: var(--accent); color: #fff; }
.sidebar a i { width: 18px; margin-right: 8px; text-align: center; opacity: .85; }
/* Collapsible sidebar parent group */
.nav-group { border-radius: 8px; }
.nav-group > summary {
  list-style: none; cursor: pointer; padding: 9px 12px; border-radius: 8px;
  color: var(--text-dim); display: flex; align-items: center; user-select: none;
}
.nav-group > summary::-webkit-details-marker { display: none; }
.nav-group > summary::after {
  content: "▸"; margin-left: auto; font-size: 11px; opacity: .7; transition: transform .15s;
}
.nav-group[open] > summary::after { transform: rotate(90deg); }
.nav-group > summary:hover { background: var(--bg-elev-2); }
.nav-group > summary i { width: 18px; margin-right: 8px; text-align: center; opacity: .85; }
.nav-group-body { display: flex; flex-direction: column; gap: 4px; margin: 4px 0 4px 14px;
  padding-left: 8px; border-left: 1px solid var(--border); }
.topnav a i, .brand i { margin-right: 6px; }
.brand i { color: var(--accent); }
.nav-label { min-width: 0; overflow: hidden; text-overflow: ellipsis; }

/* Desktop sidebar collapse toggle (top of the sidebar). Slim icon rail state is
   applied via html.sidebar-collapsed (set pre-paint), scoped to desktop below. */
.sidebar-collapse {
  display: flex; align-items: center; justify-content: center; align-self: flex-end;
  width: 28px; height: 28px; margin-bottom: 4px; padding: 0; border-radius: 7px;
  background: var(--bg-elev-2); border: 1px solid var(--border);
  color: var(--text-dim); cursor: pointer;
}
.sidebar-collapse:hover { border-color: var(--accent); color: var(--text); }
.sidebar-collapse i { transition: transform .15s; }

@media (min-width: 821px) {
  html.sidebar-collapsed .guild-wrap { grid-template-columns: 58px 1fr; }
  html.sidebar-collapsed .guild-wrap.has-toc {
    grid-template-columns: 58px minmax(0, 1fr) 210px; }
  html.sidebar-collapsed .sidebar-collapse { align-self: center; }
  html.sidebar-collapsed .sidebar-collapse i { transform: rotate(180deg); }
  html.sidebar-collapsed .nav-label { display: none; }
  html.sidebar-collapsed .sidebar a,
  html.sidebar-collapsed .nav-group > summary {
    display: flex; justify-content: center; padding-left: 0; padding-right: 0; }
  html.sidebar-collapsed .sidebar a i,
  html.sidebar-collapsed .nav-group > summary i { margin-right: 0; }
  html.sidebar-collapsed .nav-group > summary::after { display: none; }
  /* The icon rail never shows group children inline - they rendered as a jumble
     of indistinguishable centered icons. Clicking a group icon expands the
     sidebar and opens that group instead (guild_base.html). */
  html.sidebar-collapsed .nav-group-body { display: none; }
}

/* Mobile bottom nav bar + in-page jump sheet: hidden on desktop, revealed in the
   820px block. The bar is the primary phone navigation; the sheet mirrors the
   desktop "On this page" rail. */
.bottom-nav { display: none; }
.toc-sheet { display: none; }

/* --- Mobile nav: hamburger, off-canvas sidebar drawer, topbar overflow menu ---
   On desktop `.topbar-tools` is `display:contents`, so its children participate
   directly in the topbar flex row and the layout is byte-identical to before the
   wrapper existed. Below 820px they collapse into a dropdown, and the per-guild
   sidebar becomes a slide-in drawer behind a backdrop. */
.nav-toggle, .topbar-more {
  display: none; align-items: center; justify-content: center; flex: none;
  width: 38px; height: 38px; padding: 0; border-radius: 8px; cursor: pointer;
  background: var(--bg-elev-2); border: 1px solid var(--border);
  color: var(--text); font: inherit; font-size: 18px;
}
.nav-toggle:hover, .topbar-more:hover { border-color: var(--accent); }
.topbar-tools { display: contents; }
.sidebar-backdrop { display: none; }

@media (max-width: 820px) {
  .guild-wrap, .guild-wrap.has-toc { grid-template-columns: 1fr; }
  /* Sidebar becomes an off-canvas drawer, opened from the bottom nav's Menu button
     (the topbar hamburger is retired on mobile - Menu is always reachable). */
  .sidebar {
    position: fixed; top: 0; left: 0; bottom: 0; width: 264px; z-index: 120;
    flex-direction: column; flex-wrap: nowrap; gap: 4px;
    /* Bottom padding clears the fixed bottom nav (z-index 130, ~60px + safe
       area) so the drawer's last items can scroll into view above it. */
    padding: 16px 16px calc(76px + env(safe-area-inset-bottom)); overflow-y: auto;
    background: var(--bg-elev); border-right: 1px solid var(--border);
    box-shadow: var(--shadow);
    transform: translateX(-100%); transition: transform .2s ease, visibility .2s;
    /* Keep the off-canvas drawer out of the tab order while closed: a bare
       translateX leaves its links focusable for keyboard/screen-reader users. */
    visibility: hidden;
  }
  body.nav-open .sidebar { transform: none; visibility: visible; }
  .sidebar-backdrop { position: fixed; inset: 0; z-index: 110; background: rgba(0, 0, 0, .5); }
  body.nav-open .sidebar-backdrop { display: block; }

  /* Topbar tools fold into a dropdown under a "more" button. */
  .topbar-more { display: inline-flex; margin-left: auto; }
  .topbar-tools {
    display: none; position: absolute; top: 100%; right: 8px; z-index: 100;
    flex-direction: column; align-items: stretch; gap: 10px; min-width: 220px;
    padding: 12px; background: var(--bg-elev);
    border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow);
  }
  .topbar.tools-open .topbar-tools { display: flex; }
  .topbar-tools .topnav { flex-direction: column; gap: 12px; }
  .topbar-tools .user-menu, .topbar-tools .theme-switch { margin-left: 0; }

  /* Collapse toggle is desktop-only; the drawer always shows full labels. */
  .sidebar-collapse { display: none; }

  /* Context bar: let a long trail scroll sideways instead of growing tall (which
     would throw off the sticky offsets below it). */
  .crumbs { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
  .crumbs::-webkit-scrollbar { display: none; }
  .context-bar .ksearch-trigger { flex: none; }

  /* Tab strip becomes a horizontal scroller rather than wrapping into rows. It
     still sticks BELOW the context bar (which stays sticky at --topbar-h with a
     higher z-index), so it must clear both or it slides behind the crumbs. */
  .page-tabs-wrap { top: calc(var(--topbar-h) + var(--context-h)); }
  .page-tabs { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
  .page-tabs::-webkit-scrollbar { display: none; }
  .page-tab { white-space: nowrap; }

  /* Bottom nav bar: fixed primary navigation. Content clears it via body padding,
     including the safe-area inset the nav itself adds on notched phones. */
  body { padding-bottom: calc(60px + env(safe-area-inset-bottom)); }
  .bottom-nav {
    display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 130;
    background: var(--bg-elev); border-top: 1px solid var(--border);
    padding: 4px 4px calc(4px + env(safe-area-inset-bottom));
  }
  .bottom-nav [hidden] { display: none; }
  .bn-item {
    flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px;
    padding: 6px 0; background: none; border: 0; cursor: pointer;
    color: var(--text-dim); font: inherit; font-size: 10px; text-decoration: none;
  }
  .bn-item i { font-size: 21px; }
  .bn-item:hover, .bn-item.active { color: var(--accent); }

  /* In-page jump sheet (mobile TOC), opened from the bottom nav. */
  .toc-sheet { display: block; position: fixed; inset: 0; z-index: 140;
    background: rgba(0, 0, 0, .5); }
  .toc-sheet[hidden] { display: none; }
  .toc-sheet-box {
    position: absolute; left: 0; right: 0; bottom: 0; max-height: 70vh; overflow-y: auto;
    background: var(--bg-elev); border-top: 1px solid var(--border);
    border-radius: 16px 16px 0 0;
    padding: 16px 16px calc(76px + env(safe-area-inset-bottom));
  }
  .toc-sheet-head {
    font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .5px;
    color: var(--text-dim); display: flex; align-items: center; gap: 8px;
    padding-bottom: 10px; margin-bottom: 8px; border-bottom: 1px solid var(--border);
  }
  .toc-sheet-links { display: flex; flex-direction: column; gap: 2px; }
  .toc-sheet-links a { padding: 12px 10px; border-radius: 8px; color: var(--text); font-size: 15px; }
  .toc-sheet-links a:hover { background: var(--bg-elev-2); text-decoration: none; }
}

/* Forms */
label { display: block; font-size: 13px; color: var(--text-dim); margin-bottom: 4px; }
input[type=text], input[type=number], input[type=url], textarea, select {
  width: 100%; padding: 9px 11px; background: var(--bg-elev-2);
  border: 1px solid var(--border); border-radius: 8px; color: var(--text); font: inherit;
}
/* --- field help tooltip (ui.tip) ----------------------------------------
   A real <button> so it is keyboard-reachable; the bubble is CSS-only, shown on
   hover and on :focus-visible so keyboard users get the same information. The
   text lives in data-tip and is duplicated into aria-label for screen readers. */
.tip {
  display: inline-flex; align-items: center; justify-content: center;
  margin-left: 6px; padding: 0; border: 0; background: none; cursor: help;
  color: var(--muted); font-size: 13px; line-height: 1; vertical-align: middle;
  position: relative;
}
.tip:hover, .tip:focus-visible { color: var(--text); }
.tip:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 50%; }
.tip::after {
  content: attr(data-tip);
  position: absolute; bottom: calc(100% + 8px); left: 50%; transform: translateX(-50%);
  min-width: 180px; max-width: 320px; width: max-content;
  padding: 8px 10px; border-radius: 8px;
  background: var(--bg-elev-2); color: var(--text);
  border: 1px solid var(--border); box-shadow: 0 6px 20px rgba(0,0,0,.35);
  font-size: 12px; font-weight: 400; line-height: 1.45; text-align: left;
  white-space: normal; opacity: 0; visibility: hidden; transition: opacity .12s ease;
  z-index: 60; pointer-events: none;
}
.tip:hover::after, .tip:focus-visible::after { opacity: 1; visibility: visible; }
/* Near the top of a card the bubble would clip; flip it below. */
.tip.tip-below::after { bottom: auto; top: calc(100% + 8px); }
@media (max-width: 640px) {
  .tip::after { left: auto; right: 0; transform: none; max-width: 240px; }
  /* Two-up form fields stack on phones. */
  .field-row { grid-template-columns: 1fr; }
  /* Any multi-column .grid (many use an inline "1fr 1fr") collapses to one
     column; !important is needed to beat those inline styles. */
  .grid { grid-template-columns: 1fr !important; }
  /* Data-table cells stay on one line and the table scrolls sideways inside its
     .table-scroll box, instead of the global break rule shredding dates,
     usernames and dotted action names ("21-\n07-\n2026", "sett\nings") into
     cramped stacks. Long free-text (reasons) still wraps via .note-cell / .wrap. */
  .table-scroll th, .table-scroll td { white-space: nowrap; word-break: normal; overflow-wrap: normal; }
  .table-scroll .note-cell, .table-scroll .wrap { white-space: normal; overflow-wrap: anywhere; }
  /* Reclaim horizontal space eaten by the desktop gutters. */
  .container { padding: 18px 14px; }
  .footer { padding: 14px; }
  /* Card padding tightened so content isn't squeezed into a sliver. */
  .card { padding: 14px; }
}

textarea { min-height: 90px; resize: vertical; }
/* Grow with the content instead of hiding a long value behind a scrollbar. The
   `rows` attribute set by the textarea macro is the floor; max-height keeps a
   very long template from pushing the Save button off-screen. Ignored by
   browsers without field-sizing, which fall back to `rows`. */
@supports (field-sizing: content) {
  textarea { field-sizing: content; max-height: 60vh; }
}
.field { margin-bottom: 14px; }
/* align-items:start keeps a short control (a switch) top-aligned with the taller
   inputs beside it instead of stretching to their height. */
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; align-items: start; }

/* Wide tables scroll inside their own box (wrapped by csp.js) so they never push
   the page sideways on narrow screens. */
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; max-width: 100%; }
/* Chart.js canvases and any stray media never exceed their column. */
canvas, img { max-width: 100%; }

/* Themed file picker (see the `filefield` macro). The real input stays in the
   layout but invisible so it remains focusable for :required validation - a
   display:none required input makes the browser refuse to submit with an error
   it cannot show. */
.filepick { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.filepick input[type="file"] {
  position: absolute; width: 1px; height: 1px; padding: 0;
  margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.filepick .btn { cursor: pointer; }
.filepick-name { font-size: 13px; word-break: break-all; }

/* Toggle switch */
.switch { position: relative; display: inline-block; width: 44px; height: 24px; }
.switch input { display: none; }
.slider {
  position: absolute; inset: 0; background: var(--bg-elev-2);
  border: 1px solid var(--border); border-radius: 24px; transition: .2s; cursor: pointer;
}
.slider::before {
  content: ""; position: absolute; height: 18px; width: 18px; left: 2px; top: 2px;
  background: var(--text-dim); border-radius: 50%; transition: .2s;
}
.switch input:checked + .slider { background: var(--accent); border-color: var(--accent); }
.switch input:checked + .slider::before { transform: translateX(20px); background: #fff; }

/* Status pills */
.pill { padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.pill-on { background: rgba(59,165,93,.18); color: var(--ok); }
.pill-off { background: rgba(154,163,178,.18); color: var(--text-dim); }

.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 16px; }
.flash-ok { background: rgba(59,165,93,.15); color: var(--ok); }
.flash-err { background: rgba(237,66,69,.15); color: var(--danger); }

/* Live message preview (welcome/goodbye) */
.preview { background: #313338; border-radius: 8px; padding: 12px 14px; margin: 6px 0 4px; min-height: 24px; }
.preview .pv-text { white-space: pre-wrap; color: #dbdee1; font-size: 14px; }
.preview img { max-width: 100%; border-radius: 6px; margin-top: 8px; }
.preview .pv-empty { color: #80848e; font-style: italic; }

/* Logging sample embeds */
.log-sample { background: #313338; border-radius: 4px; padding: 8px 12px; margin: 6px 0; border-left: 4px solid var(--accent); }
.log-sample .ls-title { font-weight: 600; font-size: 13px; }
.log-sample .ls-body { color: #dbdee1; font-size: 13px; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--border);
  overflow-wrap: anywhere; word-break: break-word; }
th { color: var(--text-dim); font-weight: 600; font-size: 13px; }
/* Long unbreakable tokens (ids, action strings, urls) shouldn't overflow their box. */
code { overflow-wrap: anywhere; }

/* --- Global search palette (Ctrl/Cmd-K) --------------------------------- */
.ksearch-trigger {
  display: inline-flex; align-items: center; gap: 8px; cursor: pointer;
  background: var(--bg-elev); color: var(--text-dim);
  border: 1px solid var(--border); border-radius: 8px; padding: 7px 12px;
  font-size: 13px; font-family: inherit;
}
.ksearch-trigger:hover { color: var(--text); border-color: var(--text-dim); }
.ksearch-trigger kbd, .ksearch-input kbd {
  font-family: inherit; font-size: 11px; color: var(--text-dim);
  border: 1px solid var(--border); border-radius: 4px; padding: 1px 5px;
  background: var(--bg-elev-2);
}
.ksearch-backdrop {
  position: fixed; inset: 0; z-index: 200; background: rgba(0, 0, 0, .55);
  display: flex; justify-content: center; align-items: flex-start; padding: 12vh 16px 16px;
}
.ksearch-backdrop[hidden] { display: none; }
.ksearch-box {
  width: 100%; max-width: 620px; background: var(--bg-elev);
  border: 1px solid var(--border); border-radius: 12px; overflow: hidden;
  box-shadow: 0 18px 50px rgba(0, 0, 0, .45);
}
.ksearch-input { display: flex; align-items: center; gap: 10px; padding: 12px 14px;
  border-bottom: 1px solid var(--border); }
.ksearch-input i { color: var(--text-dim); }
.ksearch-input input {
  flex: 1; background: none; border: 0; outline: none; color: var(--text);
  font-size: 15px; font-family: inherit; padding: 0;
}
.ksearch-results { max-height: 52vh; overflow-y: auto; }
.ksearch-empty { padding: 18px 16px; color: var(--text-dim); font-size: 13px; }
.ksearch-hit {
  display: grid; grid-template-columns: 18px 1fr auto auto; gap: 10px;
  align-items: center; padding: 9px 14px; color: var(--text);
  text-decoration: none; border-bottom: 1px solid var(--border);
}
.ksearch-hit:last-child { border-bottom: 0; }
.ksearch-hit.on, .ksearch-hit:hover { background: var(--bg-elev-2); }
.ksearch-hit i { color: var(--text-dim); font-size: 16px; }
.ksearch-label { font-size: 14px; overflow-wrap: anywhere; }
.ksearch-ctx { color: var(--text-dim); font-size: 12px; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis; max-width: 200px; }
.ksearch-kind {
  font-size: 11px; color: var(--text-dim); border: 1px solid var(--border);
  border-radius: 4px; padding: 1px 6px; white-space: nowrap;
}
@media (max-width: 640px) {
  .ksearch-trigger span { display: none; }
  .ksearch-trigger kbd { display: none; }
  .ksearch-ctx { display: none; }
}

/* "Getting started" checklist (guild overview). */
.setup-item { display: flex; align-items: center; gap: 10px; padding: 8px 10px;
  border: 1px solid var(--border); border-radius: 8px; color: var(--text); }
.setup-item:hover { background: var(--bg-elev-2); text-decoration: none; }
.setup-item-ic { color: var(--text-dim); width: 18px; text-align: center; }
.setup-item.is-done { color: var(--text-dim); }
.setup-item.is-done .setup-item-ic { color: var(--ok); }
.setup-item-go { margin-left: auto; opacity: .5; }

/* User-ID field live preview (ui.userfield macro). The preview floats just below
   the input (absolute) instead of adding height, so in an inline `.row` form with
   align-items:flex-end the ID input lines up with the plain fields beside it
   rather than sitting a line higher. */
.userfield { margin-bottom: 0; position: relative; }
.userfield-preview { position: absolute; top: 100%; left: 0; right: 0;
  min-height: 1em; margin-top: 4px; font-size: 12px; pointer-events: none; }
.userfield-preview.ok { color: var(--ok); }
.userfield-preview.bad { color: var(--danger); }

/* Standard empty-state block (ui.empty_state macro). */
.empty-state { text-align: center; padding: 28px 18px; }
.empty-state-ic { display: block; margin: 0 auto 10px; font-size: 32px; opacity: .5; color: var(--text-dim); }
.empty-state-title { font-size: 14px; font-weight: 600; color: var(--text); margin-bottom: 4px; }
.empty-state-hint { max-width: 380px; margin: 0 auto; font-size: 13px; color: var(--text-dim); }
.empty-state-action { margin-top: 14px; }

/* Prominent "finish setting this up" callout (Protection page and friends). */
.setup-callout {
  border: 1px solid var(--danger);
  box-shadow: 0 0 0 1px var(--danger) inset;
  margin-bottom: 16px;
}
.setup-callout h3 { color: var(--danger); display: flex; align-items: center; gap: 8px; }

/* Click-to-copy id chip (kjerne copy_id macro). Looks like inline monospace
   text until hovered, when the copy glyph and a subtle bg appear. */
.copy-id {
  font: inherit;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.9em;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 1px 5px;
  margin: 0;
  border: 1px solid transparent;
  border-radius: 5px;
  background: none;
  color: inherit;
  cursor: pointer;
  vertical-align: baseline;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
}
.copy-id:hover { background: var(--bg-elev-2); border-color: var(--border); }
.copy-id .copy-id-ic { font-size: 0.9em; opacity: 0; transition: opacity 0.12s; }
.copy-id:hover .copy-id-ic { opacity: 0.7; }
.copy-id.copied { color: var(--ok); border-color: var(--ok); background: none; }
.copy-id.copied .copy-id-ic { opacity: 1; }

/* Records/notes reason cell: long text used to hog the column and squash the
   others. Cap the width, wrap even unbroken tokens, and clamp to a few lines
   with click-to-expand (toggled by widgets.js). */
.note-cell {
  max-width: 460px;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
  display: -webkit-box;
  -webkit-line-clamp: 6;
  -webkit-box-orient: vertical;
  overflow: hidden;
  cursor: pointer;
}
.note-cell.expanded {
  display: block;
  -webkit-line-clamp: unset;
}
/* The cells are keyboard-toggleable (tabindex=0 + role=button in the templates);
   show the same focus ring the other interactive bits use. */
.note-cell:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px;
  border-radius: 4px; }

/* Clickable username -> user-history popup (ui.user_link macro). Looks like a
   link, not a button. */
.user-link {
  font: inherit;
  display: inline;
  padding: 0;
  margin: 0;
  border: none;
  background: none;
  color: var(--accent);
  cursor: pointer;
  text-align: left;
}
.user-link:hover { text-decoration: underline; }
