/* ============================================================================
   gobro — "Instrument Console" design system
   ----------------------------------------------------------------------------
   A precision control panel for covert browser sessions. Near-black canvas,
   hairline blueprint grid, IBM Plex superfamily, a single cyan "signal" accent
   used as punctuation (links, focus, live state) — never as wallpaper.

   Full rules and rationale: docs/ai/domains/design-system.md
   Edit tokens here; do not hardcode colors/fonts in views.
   ========================================================================== */

/* ----- Fonts (self-hosted, no external CDN — this is a stealth tool) ------- */

@font-face {
  font-family: "IBM Plex Mono";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("/public/fonts/ibm-plex-mono-latin-400-normal.woff2") format("woff2");
}
@font-face {
  font-family: "IBM Plex Mono";
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url("/public/fonts/ibm-plex-mono-latin-500-normal.woff2") format("woff2");
}
@font-face {
  font-family: "IBM Plex Mono";
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url("/public/fonts/ibm-plex-mono-latin-600-normal.woff2") format("woff2");
}
@font-face {
  font-family: "IBM Plex Mono";
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url("/public/fonts/ibm-plex-mono-latin-700-normal.woff2") format("woff2");
}
@font-face {
  font-family: "IBM Plex Sans";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("/public/fonts/ibm-plex-sans-latin-400-normal.woff2") format("woff2");
}
@font-face {
  font-family: "IBM Plex Sans";
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url("/public/fonts/ibm-plex-sans-latin-500-normal.woff2") format("woff2");
}
@font-face {
  font-family: "IBM Plex Sans";
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url("/public/fonts/ibm-plex-sans-latin-600-normal.woff2") format("woff2");
}

/* ----- Design tokens ------------------------------------------------------- */

:root {
  /* Surfaces — near-black with a faint cool tint, layered for depth */
  --bg:           #06080b;
  --bg-2:         #080b0f;
  --surface:      #0b1016;
  --surface-2:    #0f151c;
  --surface-3:    #141c25;

  /* Hairlines */
  --line:         #1a222c;
  --line-2:       #28323e;

  /* Text */
  --text:         #d6e1ea;
  --text-dim:     #8794a1;
  --text-mute:    #586471;

  /* Signal — the one accent. Cyan oscilloscope trace. Used sparingly. */
  --signal:       #2bd9ef;
  --signal-rgb:   43, 217, 239;
  --signal-bright:#6fe9f8;
  --signal-deep:  #15a3b8;

  /* Semantic states */
  --success:      #3ad07d;  --success-rgb: 58, 208, 125;
  --warning:      #f6a93b;  --warning-rgb: 246, 169, 59;
  --danger:       #ff5d5d;  --danger-rgb:  255, 93, 93;

  /* Geometry — sharp, instrument-grade */
  --radius:       4px;
  --radius-sm:    2px;
  --radius-lg:    6px;
  --sidebar-w:    248px;
  --header-h:     56px;
  --control-h:    40px;  /* shared height for every form control (input/select/button) */

  /* Depth */
  --shadow:       0 2px 8px rgba(0, 0, 0, .4), 0 12px 40px rgba(0, 0, 0, .35);
  --glow:         0 0 0 1px rgba(var(--signal-rgb), .35), 0 0 16px rgba(var(--signal-rgb), .22);

  /* Type */
  --mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --sans: "IBM Plex Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

/* ----- Reset / base -------------------------------------------------------- */

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

::selection { background: rgba(var(--signal-rgb), .28); color: #fff; }

/* Themed scrollbars */
* { scrollbar-color: var(--line-2) transparent; scrollbar-width: thin; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-thumb { background: var(--line-2); border: 3px solid var(--bg); border-radius: 8px; }
*::-webkit-scrollbar-thumb:hover { background: #36424f; }

/* ----- Page shell (grid: header / sidebar / main) -------------------------- */

body {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  grid-template-rows: var(--header-h) 1fr;
  grid-template-areas:
    "header header"
    "sidebar main";
  min-height: 100vh;
}

/* Background layers: blueprint grid + faint grain, faded toward edges */
body::before,
body::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
}
body::before {
  background-image:
    linear-gradient(to right, rgba(255, 255, 255, .022) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(255, 255, 255, .022) 1px, transparent 1px);
  background-size: 34px 34px;
  -webkit-mask-image: radial-gradient(ellipse 120% 90% at 30% 0%, #000 0%, transparent 78%);
          mask-image: radial-gradient(ellipse 120% 90% at 30% 0%, #000 0%, transparent 78%);
}
body::after {
  opacity: .035;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

header, aside.sidebar, main { position: relative; z-index: 1; }

/* ----- Header -------------------------------------------------------------- */

header {
  grid-area: header;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  background: linear-gradient(180deg, var(--surface-2), var(--surface));
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-family: var(--mono);
  font-weight: 700;
  font-size: 16px;
  letter-spacing: .04em;
  color: var(--text);
  text-decoration: none;
}
.brand__dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--signal);
  box-shadow: 0 0 10px rgba(var(--signal-rgb), .9);
  animation: pulse 2.4s ease-in-out infinite;
}
.brand:hover { color: #fff; }
.brand__tag {
  font-weight: 400;
  font-size: 12px;
  color: var(--text-mute);
  letter-spacing: .02em;
}

.sys {
  display: flex;
  align-items: center;
  gap: 14px;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--text-dim);
}
.sys__item { display: inline-flex; align-items: center; gap: 7px; }
.sys__sep { width: 1px; height: 14px; background: var(--line-2); }

/* ----- Sidebar ------------------------------------------------------------- */

aside.sidebar {
  grid-area: sidebar;
  display: flex;
  flex-direction: column;
  background: linear-gradient(180deg, var(--surface), var(--bg-2));
  border-right: 1px solid var(--line);
  padding: 18px 0 0;
  overflow-y: auto;
  position: sticky;
  top: var(--header-h);
  height: calc(100vh - var(--header-h));
}

aside.sidebar nav { flex: 1; }

aside.sidebar nav h4 {
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .18em;
  color: var(--text-mute);
  padding: 14px 22px 8px;
  margin: 0;
  display: flex;
  align-items: center;
  gap: 8px;
}
aside.sidebar nav h4::before {
  content: "";
  width: 5px; height: 5px;
  background: var(--line-2);
  transform: rotate(45deg);
}

aside.sidebar nav ul { list-style: none; padding: 0; margin: 0 0 10px; }

aside.sidebar nav li a {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 22px;
  color: var(--text-dim);
  text-decoration: none;
  font-family: var(--mono);
  font-size: 13px;
  letter-spacing: .01em;
  border-left: 2px solid transparent;
  transition: background .12s, color .12s, border-color .12s;
}
aside.sidebar nav li a::before {
  content: "›";
  color: var(--text-mute);
  opacity: 0;
  transform: translateX(-4px);
  transition: opacity .12s, transform .12s, color .12s;
}
aside.sidebar nav li a:hover {
  background: var(--surface-2);
  color: var(--text);
}
aside.sidebar nav li a:hover::before { opacity: 1; transform: none; }
aside.sidebar nav li a.active {
  background: linear-gradient(90deg, rgba(var(--signal-rgb), .10), transparent 80%);
  border-left-color: var(--signal);
  color: var(--signal-bright);
}
aside.sidebar nav li a.active::before { opacity: 1; transform: none; color: var(--signal); }

.sidebar__foot {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--text-mute);
  padding: 14px 22px;
  border-top: 1px solid var(--line);
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ----- Main content -------------------------------------------------------- */

main {
  grid-area: main;
  padding: 30px 38px 60px;
  max-width: 1320px;
  width: 100%;
}

/* ----- Typography ---------------------------------------------------------- */

main h1 {
  display: flex;
  align-items: center;
  gap: 12px;
  font-family: var(--mono);
  font-size: 23px;
  font-weight: 600;
  letter-spacing: -.01em;
  margin: 0 0 22px;
  color: #fff;
}
main h1::before {
  content: "";
  width: 4px;
  align-self: stretch;
  min-height: 22px;
  background: var(--signal);
  box-shadow: 0 0 12px rgba(var(--signal-rgb), .6);
  border-radius: 1px;
}

main h2 {
  display: flex;
  align-items: center;
  gap: 14px;
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .16em;
  color: var(--text-dim);
  margin: 30px 0 14px;
}
main h2::after {
  content: "";
  flex: 1;
  height: 1px;
  background: linear-gradient(90deg, var(--line-2), transparent);
}

main h3 {
  font-family: var(--mono);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: .02em;
  color: var(--text);
  margin: 22px 0 10px;
}

main p { margin: 0 0 12px; color: var(--text-dim); }

main a { color: var(--signal); text-decoration: none; transition: color .1s; }
main a:hover { color: var(--signal-bright); text-decoration: underline; text-underline-offset: 3px; }

main strong { color: var(--text); font-weight: 600; }

/* ----- Panels (sections, tiles, modal) with corner-bracket framing --------- */

main section {
  position: relative;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, .015), transparent 120px),
    var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 20px 24px;
  margin-bottom: 18px;
}
main section h2 { margin-top: 0; }
main section h3:first-child { margin-top: 0; }

/* Corner brackets: thin L marks at top-left + bottom-right */
main section::before,
main section::after,
.tile::before,
.tile::after,
.modal::before,
.modal::after {
  content: "";
  position: absolute;
  width: 11px;
  height: 11px;
  pointer-events: none;
}
main section::before,
.tile::before,
.modal::before {
  top: -1px; left: -1px;
  border-top: 1px solid var(--line-2);
  border-left: 1px solid var(--line-2);
  border-top-left-radius: var(--radius-lg);
}
main section::after,
.tile::after,
.modal::after {
  bottom: -1px; right: -1px;
  border-bottom: 1px solid var(--line-2);
  border-right: 1px solid var(--line-2);
  border-bottom-right-radius: var(--radius-lg);
}

/* ----- Metric tiles (dashboard) -------------------------------------------- */

.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 14px;
  margin: 0 0 6px;
}
.tile {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  transition: border-color .15s, transform .15s;
}
.tile:hover { border-color: var(--line-2); transform: translateY(-2px); }
.tile__label {
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .14em;
  color: var(--text-mute);
}
.tile__value {
  font-family: var(--mono);
  font-size: 32px;
  font-weight: 600;
  line-height: 1;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}
.tile--signal .tile__value { color: var(--signal); text-shadow: 0 0 18px rgba(var(--signal-rgb), .4); }
.tile--danger .tile__value { color: var(--danger); }
.tile--success .tile__value { color: var(--success); }
.tile__label .dot { margin-left: 0; }

/* ----- Tables -------------------------------------------------------------- */

table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  overflow: hidden;
  margin: 14px 0;
  font-variant-numeric: tabular-nums;
}

th, td {
  text-align: left;
  padding: 11px 16px;
  border-bottom: 1px solid var(--line);
  font-size: 12.5px;
}

th {
  background: var(--surface-2);
  color: var(--text-mute);
  font-family: var(--mono);
  font-weight: 600;
  text-transform: uppercase;
  font-size: 10px;
  letter-spacing: .12em;
}

td { font-family: var(--mono); color: var(--text-dim); }
td a { color: var(--signal); }

tbody tr:last-child td { border-bottom: 0; }
tbody tr { transition: background .1s; }
tbody tr:hover td { background: rgba(var(--signal-rgb), .045); color: var(--text); }
tbody tr:hover td:first-child { box-shadow: inset 2px 0 0 var(--signal); }

/* ----- Compact proxy pool table ------------------------------------------- */
/* Used for the /proxies page. Tightens padding, keeps everything single-line
   where possible, and lays the action buttons out on one row regardless of
   how many child <form> wrappers there are. */

.proxy-pool-table th,
.proxy-pool-table td {
  padding: 8px 10px;
  vertical-align: middle;
}
.proxy-pool-table td.nowrap { white-space: nowrap; }
.proxy-pool-table .multi-cell { text-align: center; }

/* Click-to-edit name cell: looks like plain text until hovered/focused. */
.proxy-name-input {
  width: 130px;
  padding: 4px 6px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 4px;
  color: inherit;
  font: inherit;
}
.proxy-name-input:hover { border-color: var(--line-2); }
.proxy-name-input:focus {
  border-color: var(--signal);
  background: rgba(0, 0, 0, .25);
  outline: none;
}
.proxy-name-input::placeholder { color: var(--text-mute); opacity: .6; }

.proxy-source {
  display: flex;
  flex-direction: column;
  gap: 2px;
  white-space: nowrap;
}
.proxy-source__expiry {
  font-size: 10.5px;
  color: var(--text-mute);
}
.proxy-source__badge {
  display: inline-block;
  margin-top: 2px;
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 999px;
  border: 1px solid rgba(var(--warning-rgb), .45);
  color: var(--warning);
  background: rgba(var(--warning-rgb), .08);
  text-transform: uppercase;
  letter-spacing: .06em;
}

.profile-tags {
  display: flex;
  flex-direction: column;
  gap: 3px;
  max-width: 220px;
}
.profile-tag {
  display: inline-flex;
  align-items: baseline;
  gap: 5px;
  overflow: hidden;
  white-space: nowrap;
}
.profile-tag__label {
  overflow: hidden;
  text-overflow: ellipsis;
}
.profile-tag__module {
  font-size: 10.5px;
  color: var(--text-mute);
}

input[type='checkbox'].multi-toggle {
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  display: inline-block;
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  width: 34px;
  height: 18px;
  border-radius: 999px;
  background: #1a222c;
  border: 1px solid #36424f;
  position: relative;
  cursor: pointer;
  transition: background .12s ease, border-color .12s ease;
  vertical-align: middle;
  flex-shrink: 0;
}
input[type='checkbox'].multi-toggle::after {
  content: '';
  position: absolute;
  top: 1px;
  left: 1px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #8794a1;
  transition: transform .12s ease, background .12s ease;
}
input[type='checkbox'].multi-toggle:checked {
  background: rgba(var(--signal-rgb), .25);
  border-color: var(--signal);
}
input[type='checkbox'].multi-toggle:checked::after {
  transform: translateX(15px);
  background: var(--signal);
}

.row-actions {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  justify-content: flex-start; /* Test always at left edge — same x across rows */
  gap: 2px;
}
.row-actions form {
  /* Make the form participate in the flex layout so its single button stays
     inline with the others — otherwise each form claims its own line in a
     narrow cell. */
  display: contents;
}
/* Compact action buttons override the base .btn — flat, tight, single-row toolbar feel. */
.row-actions .btn {
  padding: 4px 9px;
  min-height: 26px;
  min-width: 26px;
  font-size: 11.5px;
  letter-spacing: .02em;
  border-radius: 5px;
}
.row-actions .btn-icon {
  padding: 4px 6px;
  font-size: 13px;
  line-height: 1;
}

/* ----- Forms --------------------------------------------------------------- */

form { margin: 14px 0; }

/* Horizontal filter/action bar */
.filters {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 12px;
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
}
.filters label { margin-bottom: 0; }
.filters :where(input, select) { width: auto; min-width: 170px; }
.filters button, .filters .btn { margin: 0; }

/* Stacked field */
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 16px;
  max-width: 520px;
}
.field > label { margin-bottom: 0; }

label {
  display: block;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text-dim);
  margin-bottom: 6px;
  letter-spacing: .01em;
}

/* Caption labels that wrap their own control become stacked fields */
label:has(> input),
label:has(> select),
label:has(> textarea) {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 14px;
}

/* Choice labels (radio/checkbox) override the above: inline row, sentence case.
   Higher specificity than the caption rule, so it wins without :not() chains. */
label:has(> input[type="radio"]),
label:has(> input[type="checkbox"]) {
  display: inline-flex;
  flex-direction: row;
  align-items: center;
  gap: 8px;
  margin: 0 16px 6px 0;
  color: var(--text);
  cursor: pointer;
}
:where(label:has(> input), label:has(> select), label:has(> textarea)) > :where(input, select, textarea) {
  width: 100%;
}

/* Compact horizontal field row (caption-labels side by side, no card chrome) —
   e.g. the Custom host/port/scheme group in the personal create-profile form. */
.np-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  max-width: 520px;
  margin-bottom: 16px;
}
.np-row > label { margin-bottom: 0; }
.np-row > label:first-child { flex: 2 1 160px; }
.np-row > label:nth-child(2),
.np-row > label:nth-child(3) { flex: 1 1 90px; }
/* `hidden` must win over the flex display above (a flex/grid rule otherwise
   overrides the UA `[hidden] { display: none }`). */
.field[hidden], .np-row[hidden] { display: none; }

/* Every text-like input (incl. type-less ones), select and textarea share one look.
   The :not() chain excludes toggles/buttons/hidden so they keep their own styling. */
input:not([type="checkbox"]):not([type="radio"]):not([type="submit"]):not([type="button"]):not([type="reset"]):not([type="file"]):not([type="range"]):not([type="color"]):not([type="hidden"]),
select,
textarea {
  background: var(--bg-2);
  border: 1px solid var(--line-2);
  color: var(--text);
  padding: 9px 12px;
  border-radius: var(--radius);
  font-size: 13px;
  font-family: var(--mono);
  line-height: 1.4;
  min-width: 200px;
  min-height: var(--control-h);
  transition: border-color .12s, box-shadow .12s, background .12s;
}
input::placeholder, textarea::placeholder { color: var(--text-mute); }

input:not([type="checkbox"]):not([type="radio"]):not([type="submit"]):not([type="button"]):not([type="reset"]):not([type="file"]):not([type="range"]):not([type="color"]):not([type="hidden"]):focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--signal);
  background: var(--bg);
  box-shadow: 0 0 0 3px rgba(var(--signal-rgb), .16), 0 0 14px rgba(var(--signal-rgb), .12);
}

select {
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--text-dim) 50%),
                    linear-gradient(135deg, var(--text-dim) 50%, transparent 50%);
  background-position: calc(100% - 17px) 50%, calc(100% - 12px) 50%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: 32px;
}

textarea {
  resize: vertical;
  min-height: 130px;
  width: 100%;
  line-height: 1.6;
}

input[type="checkbox"], input[type="radio"] {
  accent-color: var(--signal);
  width: 15px;
  height: 15px;
  min-width: 0;
}

/* ----- Buttons ------------------------------------------------------------- */
/* Default <button> and .btn-primary = signal action; .btn = ghost; danger = red */

button,
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .04em;
  padding: 9px 16px;
  min-height: var(--control-h);
  border-radius: var(--radius);
  cursor: pointer;
  text-decoration: none;
  transition: background .12s, border-color .12s, box-shadow .12s, color .12s, transform .04s;
  /* primary (signal) */
  background: rgba(var(--signal-rgb), .12);
  color: var(--signal-bright);
  border: 1px solid rgba(var(--signal-rgb), .45);
}
button:hover,
.btn-primary:hover {
  background: rgba(var(--signal-rgb), .2);
  border-color: var(--signal);
  box-shadow: 0 0 16px rgba(var(--signal-rgb), .25);
  color: #eafdff;
}
button:active, .btn:active { transform: translateY(1px); }

/* Ghost / secondary */
button[type="button"]:not(.btn-danger):not(.btn-primary),
.btn:not(.btn-primary):not(.btn-danger) {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--line-2);
}
button[type="button"]:not(.btn-danger):not(.btn-primary):hover,
.btn:not(.btn-primary):not(.btn-danger):hover {
  background: var(--surface-3);
  border-color: var(--signal-deep);
  color: var(--signal-bright);
  box-shadow: none;
}

/* Primary explicit */
.btn-primary {
  background: rgba(var(--signal-rgb), .12);
  color: var(--signal-bright);
  border: 1px solid rgba(var(--signal-rgb), .45);
}

/* Danger */
.btn-danger,
button.btn-danger {
  background: rgba(var(--danger-rgb), .12);
  color: var(--danger);
  border: 1px solid rgba(var(--danger-rgb), .4);
}
.btn-danger:hover,
button.btn-danger:hover {
  background: rgba(var(--danger-rgb), .2);
  border-color: var(--danger);
  box-shadow: 0 0 16px rgba(var(--danger-rgb), .22);
  color: #fff;
}

button:focus-visible,
.btn:focus-visible,
a:focus-visible {
  outline: 2px solid var(--signal);
  outline-offset: 2px;
}

/* ----- Status chips + telemetry dots --------------------------------------- */

.dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-mute);
  position: relative;
  flex: none;
}
.dot--live   { background: var(--signal);  box-shadow: 0 0 8px rgba(var(--signal-rgb), .9);  animation: pulse 2.4s ease-in-out infinite; }
.dot--ok     { background: var(--success); box-shadow: 0 0 8px rgba(var(--success-rgb), .8); }
.dot--warn   { background: var(--warning); box-shadow: 0 0 8px rgba(var(--warning-rgb), .8); }
.dot--danger { background: var(--danger);  box-shadow: 0 0 8px rgba(var(--danger-rgb), .8); }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 3px 11px 3px 9px;
  border-radius: 100px;
  font-family: var(--mono);
  font-size: 10.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .08em;
  border: 1px solid transparent;
}
.chip::before {
  content: "";
  width: 7px; height: 7px;
  border-radius: 50%;
  background: currentColor;
}
.chip-pending { background: rgba(110, 118, 129, .12); color: var(--text-dim); border-color: rgba(110, 118, 129, .3); }
.chip-running { background: rgba(var(--signal-rgb), .12);  color: var(--signal);  border-color: rgba(var(--signal-rgb), .35); }
.chip-running::before { box-shadow: 0 0 8px currentColor; animation: pulse 2.4s ease-in-out infinite; }
.chip-done    { background: rgba(var(--success-rgb), .12); color: var(--success); border-color: rgba(var(--success-rgb), .32); }
.chip-failed  { background: rgba(var(--danger-rgb), .12);  color: var(--danger);  border-color: rgba(var(--danger-rgb), .35); }

/* ----- Native <dialog> overlay --------------------------------------------- */
/* Used by the per-row ProxyRouter location / renew modals. Each fragment opens
   the dialog with `.showModal()` from an inline <script> after the HTMX swap. */
dialog {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--line-2);
  border-radius: var(--radius);
  padding: 22px 22px 18px;
  max-width: 520px;
  width: 90vw;
  box-shadow: 0 24px 48px rgba(0, 0, 0, .55);
}
dialog::backdrop {
  background: rgba(0, 0, 0, .65);
  backdrop-filter: blur(2px);
}
dialog menu {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin: 14px 0 0;
  padding: 0;
}

/* ----- Tabs (segmented section switcher) ----------------------------------- */
/* Used when a page has 2-4 mutually exclusive sub-views that would otherwise
   stack as long parallel <section>s. The visible panel is sticky in
   localStorage so a redirect-after-submit doesn't snap back to default. */

.tabs {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--line-2);
  margin: 18px 0 18px;
}
.tabs__btn {
  background: transparent;
  border: 0;
  border-radius: 0;
  border-bottom: 2px solid transparent;
  color: var(--text-dim);
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  padding: 11px 18px;
  margin-bottom: -1px; /* overlap .tabs's bottom border so the active underline sits flush */
  cursor: pointer;
  transition: color .12s ease, border-color .12s ease;
}
.tabs__btn:hover { color: var(--text); }
.tabs__btn[aria-selected="true"] {
  color: var(--signal);
  border-bottom-color: var(--signal);
}
.tab-panel[hidden] { display: none; }

/* ----- Alerts (also rendered by the HTMX error handler) -------------------- */

.alert {
  font-family: var(--mono);
  font-size: 12.5px;
  padding: 11px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--line-2);
  border-left-width: 3px;
  background: var(--surface-2);
  color: var(--text);
  margin: 12px 0;
}
.alert-error,
.alert-danger  { border-left-color: var(--danger);  color: #ffd9d9; background: rgba(var(--danger-rgb), .08); }
.alert-success { border-left-color: var(--success); color: #c7f5db; background: rgba(var(--success-rgb), .08); }
.alert-warning { border-left-color: var(--warning); color: #ffe6bf; background: rgba(var(--warning-rgb), .08); }
.alert-info    { border-left-color: var(--signal);  color: #cdf6fd; background: rgba(var(--signal-rgb), .08); }

/* ----- Definition list (readout) ------------------------------------------- */

dl {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 9px 24px;
  margin: 14px 0 22px;
  align-items: baseline;
}
dt {
  font-family: var(--mono);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .1em;
  color: var(--text-mute);
  font-weight: 600;
}
dd { margin: 0; font-family: var(--mono); font-size: 13px; color: var(--text); }

/* ----- Code / pre ---------------------------------------------------------- */

code {
  font-family: var(--mono);
  background: var(--surface-2);
  padding: 2px 7px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  color: var(--signal-bright);
  border: 1px solid var(--line);
}

pre {
  position: relative;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-left: 3px solid var(--line-2);
  border-radius: var(--radius);
  padding: 14px 18px;
  overflow: auto;
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.6;
  color: var(--text-dim);
}
pre code { border: 0; padding: 0; background: transparent; color: var(--text-dim); }

/* ----- Disclosure (collapsible "advanced" block) --------------------------- */

main details {
  margin: 6px 0 18px;
  border-top: 1px solid var(--line);
  padding-top: 12px;
}
main details > summary {
  cursor: pointer;
  list-style: none;
  user-select: none;
  font-family: var(--mono);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .1em;
  color: var(--text-dim);
  transition: color .15s ease;
}
main details > summary::-webkit-details-marker { display: none; }
main details > summary::before {
  content: '▸';
  display: inline-block;
  margin-right: 8px;
  color: var(--signal);
  transition: transform .15s ease;
}
main details[open] > summary::before { transform: rotate(90deg); }
main details > summary:hover { color: var(--text); }

/* Card-level disclosure — collapses a whole readout; summary reads as a section
   header (h2-style: wider tracking + trailing hairline). Used by the fingerprint
   and proxy cards on the account/profile pages. */
main details.card-toggle { margin: 0; border: 0; padding: 0; }
main details.card-toggle > summary {
  display: flex;
  align-items: center;
  gap: 12px;
  letter-spacing: .16em;
}
main details.card-toggle > summary::before { margin-right: 0; }
main details.card-toggle > summary::after {
  content: "";
  flex: 1;
  height: 1px;
  background: linear-gradient(90deg, var(--line-2), transparent);
}
main details.card-toggle[open] > summary { margin-bottom: 6px; }

/* Proxy summary pill in a collapsed card header: a status dot + the current
   proxy address, opting out of the summary's uppercase/tracking. */
.proxy-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  text-transform: none;
  letter-spacing: normal;
  font-weight: 400;
  color: var(--text);
}

/* ----- Lists (generic, e.g. dashboard feed fallback) ----------------------- */

main section ul { list-style: none; padding: 0; margin: 0; }

.feed { display: flex; flex-direction: column; }
.feed__row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 11px 2px;
  border-bottom: 1px solid var(--line);
}
.feed__row:last-child { border-bottom: 0; }
.feed__row code { background: transparent; border: 0; padding: 0; color: var(--text); }

/* ----- Module card (sidebar fallback shape) -------------------------------- */

.module-card {
  display: block;
  padding: 9px 14px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  margin: 4px 14px;
  color: var(--text);
  text-decoration: none;
  transition: border-color .12s;
}
.module-card:hover { border-color: var(--signal-deep); }
.module-card strong { display: block; font-size: 13px; font-family: var(--mono); }
.module-card small { color: var(--text-mute); font-size: 11px; }

/* ----- Modal --------------------------------------------------------------- */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(2, 4, 6, .66);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  backdrop-filter: blur(3px);
  animation: fade-in .14s ease-out;
}
.modal {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--line-2);
  border-radius: var(--radius-lg);
  padding: 26px 30px;
  min-width: 440px;
  max-width: 560px;
  box-shadow: var(--shadow);
  animation: rise .18s cubic-bezier(.2, .7, .3, 1);
}
.modal h3 { margin: 0 0 10px; font-size: 16px; }
.modal .close {
  position: absolute;
  top: 10px;
  right: 12px;
  background: transparent;
  border: 0;
  color: var(--text-mute);
  font-size: 22px;
  cursor: pointer;
  padding: 4px 10px;
  line-height: 1;
  box-shadow: none;
}
.modal .close:hover { color: var(--danger); background: transparent; box-shadow: none; }
.modal form { margin: 0; }
.modal .field { max-width: 100%; }
.modal button[type="submit"] { width: 100%; margin-top: 6px; }

/* ----- Embedded browser ---------------------------------------------------- */

/* Tab strip (interactive multi-tab browser) */
.browser-tabs { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; padding: 8px 10px; margin-bottom: 8px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); }
.browser-tab { display: inline-flex; align-items: center; gap: 6px; max-width: 200px; padding: 5px 8px; background: var(--surface-2); border: 1px solid var(--line-2); border-bottom: 2px solid transparent; border-radius: var(--radius); color: var(--text-dim); font: 11.5px var(--mono); cursor: pointer; }
.browser-tab.is-active { color: var(--signal); border-bottom-color: var(--signal); }
.browser-tab__label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.browser-tab__close { background: none; border: 0; color: inherit; cursor: pointer; padding: 0 2px; min-height: 0; }
.browser-tab__add { background: var(--surface-2); border: 1px solid var(--line-2); border-radius: var(--radius); color: var(--text-dim); cursor: pointer; padding: 4px 9px; min-height: 26px; }

/* ★ bookmarks dropdown */
.bm-wrap { position: relative; display: inline-flex; }
.bm-menu { position: absolute; top: calc(100% + 4px); right: 0; z-index: 20; min-width: 200px; display: flex; flex-direction: column; background: rgba(20, 24, 33, .96); border: 1px solid var(--line-2); border-radius: var(--radius); box-shadow: var(--shadow); }
.bm-menu[hidden] { display: none; }
.bm-item { text-align: left; background: none; border: 0; color: var(--text); font: 12px var(--mono); padding: 8px 12px; cursor: pointer; }
.bm-item:hover { background: var(--surface-2); color: var(--signal); }

.browser-toolbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  padding: 12px 14px;
  margin-bottom: 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
}
.browser-toolbar .btn { padding: 7px 12px; }
.browser-toolbar select { min-width: 0; padding: 8px 30px 8px 12px; }
.browser-toolbar .url {
  flex: 1;
  min-width: 200px;
  background: var(--bg-2);
  border: 1px solid var(--line-2);
  color: var(--text);
  padding: 8px 12px;
  border-radius: var(--radius);
  font-size: 13px;
  font-family: var(--mono);
}
.browser-toolbar .url:focus {
  outline: none;
  border-color: var(--signal);
  box-shadow: 0 0 0 3px rgba(var(--signal-rgb), .16);
}
.browser-canvas-wrap {
  display: inline-block;
  position: relative;
  background: #000;
  border: 1px solid var(--line-2);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow);
}
.browser-canvas-wrap canvas { display: block; cursor: default; outline: none; }

/* Labeled control groups in the toolbar (Resolution / Screen). */
.browser-toolbar .tb-group {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}
.browser-toolbar .tb-label {
  font-size: 10px;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--text-mute);
}
/* Fullscreen: wrap covers the screen and centers the scaled canvas (black bars
   where aspect ratios differ). browser.js sets transform-origin to center. */
.browser-canvas-wrap:fullscreen {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100vw;
  height: 100vh;
  max-width: none;
  border: 0;
  border-radius: 0;
}

/* Transient feedback shown on top of the canvas for clipboard / input actions.
   The footer status line is easy to miss (and is overwritten by the per-frame
   FPS counter), so user-triggered results surface here instead. */
.browser-toast {
  position: absolute;
  top: 14px;
  left: 50%;
  transform: translateX(-50%) translateY(-8px);
  max-width: 80%;
  padding: 9px 16px;
  font-family: var(--mono);
  font-size: 13px;
  font-weight: 600;
  color: #fff;
  background: rgba(20, 24, 33, .94);
  border: 1px solid var(--line-2);
  border-left: 3px solid var(--signal);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  pointer-events: none;
  opacity: 0;
  transition: opacity .18s ease, transform .18s ease;
  z-index: 5;
}
.browser-toast.is-visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
.browser-toast.is-ok { border-left-color: var(--success, #3fb950); }
.browser-toast.is-err { border-left-color: var(--danger, #f85149); }
.browser-status {
  margin-top: 12px;
  padding: 8px 13px;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text-dim);
  background: var(--surface);
  border: 1px solid var(--line);
  border-left: 3px solid var(--signal-deep);
  border-radius: var(--radius);
  display: inline-block;
}

/* Footer: status bar + proxy/geo card side by side, fingerprint card below. */
.browser-footer {
  display: flex;
  flex-wrap: wrap;
  align-items: stretch;
  gap: 10px;
  margin-top: 12px;
}
.browser-footer .browser-status {
  margin-top: 0;
  display: flex;
  align-items: center;
}
.browser-proxy {
  padding: 8px 13px;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text-dim);
  background: var(--surface);
  border: 1px solid var(--line);
  border-left: 3px solid var(--signal);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
  min-width: 0;
}
.browser-proxy .bp-row { display: flex; flex-wrap: wrap; align-items: center; gap: 7px; }
.browser-proxy .bp-k { color: var(--text-mute); font-size: 10px; letter-spacing: .08em; }
.browser-proxy .bp-v { color: var(--text); }
.browser-proxy .bp-isp { color: var(--text-dim); }
.browser-proxy .bp-sep { color: var(--line-2); }
#fingerprint-slot { margin-top: 12px; }

/* ----- Action button spacing ----------------------------------------------- */

main button[hx-get],
main button[hx-post] { margin: 0 6px 8px 0; }

/* ----- Utilities ----------------------------------------------------------- */

.text-dim { color: var(--text-dim); }
.text-mute, .muted { color: var(--text-mute); }
.text-ok { color: var(--success); }
.text-warn { color: var(--warning); }
.text-danger { color: var(--danger); }
.mono { font-family: var(--mono); }
.note { font-size: 12.5px; color: var(--text-mute); margin-top: 24px; }

hr { border: 0; border-top: 1px solid var(--line); margin: 18px 0; }

/* ----- Motion -------------------------------------------------------------- */

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%      { opacity: .35; }
}
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes enter {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: none; }
}

/* Staggered page-load reveal of top-level blocks in main */
main > * { animation: enter .42s cubic-bezier(.2, .7, .3, 1) both; }
main > *:nth-child(1) { animation-delay: .02s; }
main > *:nth-child(2) { animation-delay: .07s; }
main > *:nth-child(3) { animation-delay: .12s; }
main > *:nth-child(4) { animation-delay: .17s; }
main > *:nth-child(5) { animation-delay: .22s; }
main > *:nth-child(n+6) { animation-delay: .26s; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
  }
}

/* ---------- Login page (standalone, no sidebar shell) ---------- */
.login-wrap {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1;
}
.login-card { width: min(380px, 92vw); }
.login-card .brand { margin-bottom: 18px; display: inline-flex; }
.login-card h1 { margin-top: 0; }
.login-card form { display: flex; flex-direction: column; gap: 14px; }
.login-card .btn-primary { margin-top: 4px; }
.inline-form { display: inline; }

/* Sidebar footer with the logout control */
.sidebar__foot { display: flex; align-items: center; gap: 8px; }
.logout-form { display: inline; margin-left: auto; }
