/* Concessionaire — admin UI styles. Document-quality, not flashy. */

:root {
  --fg: #1a1a1a;
  --muted: #6b6b6b;
  --line: #d8d8d8;
  --bg: #ffffff;
  --soft: #fafafa;
  --accent: #2c5f8e;
  --accent-bg: #eaf2f9;
  --danger: #b03a3a;
  --danger-bg: #fbe9e9;
  --success: #2d6b34;
  --success-bg: #e6f1e7;
}

* { box-sizing: border-box; }
html { font-size: 15px; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--fg);
  background: var(--bg);
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Sidebar layout */
.layout { display: flex; min-height: 100vh; }
.sidebar {
  width: 210px;
  flex-shrink: 0;
  background: var(--soft);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  padding: 18px 0;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}
.sidebar .brand {
  font-weight: 700;
  font-size: 1.1rem;
  letter-spacing: -0.01em;
  color: var(--fg);
  text-decoration: none;
  padding: 0 20px 14px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 8px;
}
.sidebar .nav { display: flex; flex-direction: column; gap: 1px; flex: 1; }
.sidebar .nav a {
  color: var(--fg);
  text-decoration: none;
  font-size: 0.92rem;
  padding: 7px 20px;
  border-left: 3px solid transparent;
}
.sidebar .nav a:hover { background: #eef2f6; color: var(--accent); }
.sidebar .nav a.active { background: var(--accent-bg); border-left-color: var(--accent); color: var(--accent); font-weight: 600; }
.nav-group {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  padding: 12px 20px 4px;
  font-weight: 600;
}
.sidebar-foot {
  padding: 14px 20px 0;
  border-top: 1px solid var(--line);
  margin-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.sidebar-foot .version { font-size: 0.78rem; color: var(--muted); }
.linklike {
  background: none; border: none; cursor: pointer; color: var(--fg);
  font: inherit; font-size: 0.9rem; padding: 0; text-align: left;
}
.linklike:hover { color: var(--accent); }
.inline { display: inline; }

.content {
  flex: 1;
  min-width: 0;
  padding: 24px 32px;
  /* full viewport width (minus the sidebar) — screen real estate is precious */
}

/* Login page (no sidebar) */
.container.login-only {
  max-width: 420px;
  margin: 0 auto;
  padding: 60px 24px;
}

@media (max-width: 720px) {
  .layout { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; flex-direction: row; flex-wrap: wrap; align-items: center; }
  .sidebar .nav { flex-direction: row; flex-wrap: wrap; }
  .nav-group { display: none; }
  .content { padding: 20px; }
}

h1 {
  margin: 0 0 16px;
  font-size: 1.5rem;
  letter-spacing: -0.01em;
}
h2 { font-size: 1.2rem; }
.muted { color: var(--muted); }

.flash {
  padding: 10px 14px;
  border-radius: 4px;
  margin-bottom: 18px;
  border: 1px solid transparent;
  font-size: 0.95rem;
}
.flash.error { background: var(--danger-bg); border-color: var(--danger); color: var(--danger); }
.flash.success { background: var(--success-bg); border-color: var(--success); color: var(--success); }
.flash.info { background: var(--accent-bg); border-color: var(--accent); color: var(--accent); }

.login-card {
  max-width: 360px;
  margin: 40px auto;
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--soft);
}
.login-card h1 {
  text-align: center;
  margin-bottom: 22px;
}

.form { display: flex; flex-direction: column; gap: 14px; }
.form label { display: flex; flex-direction: column; gap: 4px; font-size: 0.9rem; color: var(--muted); }
.form input {
  font: inherit;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: #fff;
}
.form input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

button.primary {
  background: var(--accent);
  color: white;
  border: none;
  padding: 9px 16px;
  font: inherit;
  font-weight: 600;
  border-radius: 4px;
  cursor: pointer;
}
button.primary:hover { background: #244e75; }

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-top: 24px;
}
.card {
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--soft);
}
.card h2 {
  font-size: 2rem;
  margin: 0 0 4px;
  color: var(--accent);
  letter-spacing: -0.01em;
}
.card p { margin: 0; color: var(--muted); font-size: 0.9rem; }
a.card { text-decoration: none; color: inherit; display: block; transition: background-color 120ms ease; }
a.card:hover { background: #f0f4f8; }

/* Listing tables */
.count {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--muted);
  margin-left: 8px;
}

.table-wrap {
  border: 1px solid var(--line);
  border-radius: 5px;
  overflow-x: auto;
  background: #fff;
}

table.list {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}
table.list thead th {
  text-align: left;
  font-weight: 600;
  background: var(--soft);
  padding: 8px 12px;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  position: relative;
}
table.list thead th.sortable { cursor: pointer; user-select: none; }
table.list thead th.sortable:hover { background: #eef2f6; }
table.list thead th[data-sort="asc"]::after { content: " ▲"; font-size: 0.7em; color: var(--accent); }
table.list thead th[data-sort="desc"]::after { content: " ▼"; font-size: 0.7em; color: var(--accent); }
table.resizable { table-layout: fixed; }
table.resizable td { overflow: hidden; text-overflow: ellipsis; }
.col-grip {
  position: absolute;
  top: 0;
  right: 0;
  width: 6px;
  height: 100%;
  cursor: col-resize;
  user-select: none;
}
.col-grip:hover { background: var(--accent); opacity: 0.4; }
body.col-resizing { cursor: col-resize; user-select: none; }

.table-filter { margin: 6px 0 8px; }
.table-filter-box {
  width: 280px;
  max-width: 100%;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 4px;
  font: inherit;
  font-size: 0.9rem;
}

/* Proxy reachability probe cells */
.probe-cell { font-variant-numeric: tabular-nums; font-size: 0.85rem; }
.probe-cell.probe-ok { color: var(--success); font-weight: 600; }
.probe-cell.probe-bad { color: var(--danger); }
.probe-cell.probe-pending { color: var(--muted); }
.btn.probe-one { padding: 3px 9px; font-size: 0.82rem; }
table.list tbody td {
  padding: 7px 12px;
  border-bottom: 1px solid #eee;
  vertical-align: top;
}
table.list tbody tr:hover { background: #fafafa; }
table.list td.num { font-variant-numeric: tabular-nums; color: var(--muted); width: 50px; }
table.list td.name { font-weight: 500; }
table.list td.patt { font-family: "SF Mono", Menlo, Consolas, monospace; font-size: 0.85em; max-width: 480px; }
table.list code {
  font-family: "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.85em;
  background: var(--soft);
  padding: 1px 5px;
  border-radius: 3px;
}
code.truncate {
  display: inline-block;
  max-width: 360px;
  overflow: hidden;
  text-overflow: ellipsis;
  vertical-align: bottom;
  white-space: nowrap;
}

.tag, .flag, .member, .kv {
  display: inline-block;
  font-size: 0.78em;
  background: var(--accent-bg);
  color: var(--accent);
  padding: 1px 6px;
  border-radius: 3px;
  margin-right: 3px;
  margin-bottom: 2px;
}
.flag { background: #fef4e6; color: #885c1a; }
.member { background: #efe7d6; color: #5a4a1a; }
.kv { background: #eee; color: #444; font-family: "SF Mono", Menlo, Consolas, monospace; }
.kv b { font-weight: 600; }
.yes { color: var(--success); font-weight: 600; }
.badge-xui { display: inline-block; font-size: 0.7em; font-weight: 600; letter-spacing: 0.02em;
  background: #e6f0ff; color: #1a4d99; padding: 1px 5px; border-radius: 3px; margin-left: 6px;
  vertical-align: middle; text-transform: uppercase; }
/* Proxy-chain row controls in the device Proxies panel */
.dyn-chain { background: none; border: none; cursor: pointer; font-size: 0.95em; color: var(--muted); padding: 0 4px; line-height: 1; }
.dyn-chain:hover { color: #1a4d99; }
/* A chain row is a normal .proxy-row, marked with a subtle left accent + a tiny promote button. */
.proxy-row.chain-row { box-shadow: inset 3px 0 0 #1a4d99; }
.proxy-row.chain-row .proxy-row-name { font-style: italic; }
.chain-promote { padding: 1px 7px; }
.chain-promote:disabled { opacity: 0.5; cursor: default; }
/* Lightweight modal (proxy-chain dialer picker) */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.35); display: flex; align-items: center; justify-content: center; z-index: 1000; }
.modal-box { background: #fff; border-radius: 8px; padding: 1.2rem 1.4rem; max-width: 460px; width: 90%; box-shadow: 0 8px 30px rgba(0,0,0,0.2); }
.modal-box h4 { margin: 0 0 .4rem; }
.modal-label { display: block; margin: .6rem 0; }
.modal-label select { width: 100%; margin-top: .3rem; }
.modal-actions { display: flex; gap: .5rem; justify-content: flex-end; margin-top: 1rem; }
/* Wider modal for the per-device group-customization form + its inputs. */
.modal-box.modal-wide { max-width: 620px; max-height: 88vh; overflow: auto; }
.modal-wide .modal-label input[type="text"], .modal-wide .modal-label textarea, .modal-wide .modal-label .ts-control { width: 100%; margin-top: .3rem; box-sizing: border-box; }
.modal-wide .modal-label input.ro { background: #f3f4f6; color: var(--muted); }
.modal-check { display: flex; align-items: center; gap: 6px; margin: .6rem 0; font-size: .9rem; }
/* Per-row "customize" (✎) button in the device Proxy Groups panel. */
.proxy-row .row-customize { flex: 0 0 auto; border: none; background: none; color: var(--muted); font-size: .95rem; line-height: 1; cursor: pointer; padding: 0 4px; margin-left: auto; }
.proxy-row .row-customize + .row-remove { margin-left: 0; }
.proxy-row .row-customize:hover { color: var(--accent); }
.quota-foot-actions { margin: .5rem 0 .2rem; }
.badge-basis { display: inline-block; font-size: 0.72em; font-weight: 600; background: #eef2f6; color: #475569;
  padding: 0 5px; border-radius: 3px; vertical-align: middle; text-transform: uppercase; cursor: help; }
span.src { color: var(--muted); font-family: "SF Mono", Menlo, Consolas, monospace; font-size: 0.82em; }

.small { font-size: 0.85em; }

article.template {
  margin: 16px 0;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: #fff;
}
article.template header {
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--soft);
}
article.template h2 { margin: 0; font-size: 1rem; }
article.template pre.config {
  padding: 14px 16px;
  margin: 0;
  font-family: "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.82rem;
  background: #fafafa;
  overflow-x: auto;
  white-space: pre-wrap;
  line-height: 1.45;
}

/* Pages */
.page-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 16px;
}

.btn, .btn-link {
  display: inline-block;
  padding: 6px 12px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: #fff;
  font: inherit;
  font-size: 0.9rem;
  color: var(--fg);
  text-decoration: none;
  cursor: pointer;
}
.btn:hover { background: var(--soft); }
.btn-link { border: none; background: none; padding: 6px 0; color: var(--accent); }
.btn-link:hover { text-decoration: underline; }
.btn.primary { background: var(--accent); color: white; border-color: var(--accent); }
.btn.primary:hover { background: #244e75; }
.btn.danger { color: var(--danger); border-color: var(--danger); }
.btn.danger:hover { background: var(--danger-bg); }

a.btn.primary { color: white; }

.status {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 3px;
  font-size: 0.78em;
  font-weight: 600;
}
.status.active { background: var(--success-bg); color: var(--success); }
.status.revoked { background: var(--danger-bg); color: var(--danger); }

.form-wide { max-width: 640px; margin: 16px 0; }
/* Editors that should use the full content width, not the 640px form cap. */
.rules-edit-form, .ruleset-edit-form { max-width: none; width: 100%; }
.ruleset-edit-form label.full { width: 100%; }
.ruleset-edit-form select { padding: 7px 9px; border: 1px solid var(--line); border-radius: 4px; font: inherit; max-width: 480px; }

/* Relationship explainer (guardrail context on rule/rule-set pages) */
.relationship-note { background: #f0f5ff; border: 1px solid #adc6ff; border-radius: 6px; padding: 10px 14px; margin: 12px 0; font-size: 0.88rem; line-height: 1.5; color: #1d3a8a; }
.relationship-note em { font-style: normal; font-weight: 600; }
.form-wide select, .form-wide textarea {
  font: inherit;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: #fff;
}
.form-wide textarea { resize: vertical; }
/* Checkbox labels inside a form are inline (row), not stacked full-width field labels. */
.form label.check { flex-direction: row; align-items: center; gap: 6px; width: fit-content; color: var(--fg); cursor: pointer; }
.form label.check input { width: auto; flex: none; margin: 0; }
fieldset.assign {
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 10px 14px 14px;
}
fieldset.assign legend {
  font-weight: 600;
  font-size: 0.9rem;
  padding: 0 6px;
}
fieldset.assign label.check {
  display: block;
  margin: 4px 0;
  font-weight: normal;
  flex-direction: row;
}
fieldset.assign label.check input { margin-right: 6px; }
.form-actions { display: flex; gap: 10px; align-items: center; margin-top: 8px; }

dl.device-meta {
  display: grid;
  grid-template-columns: 180px 1fr;
  gap: 6px 18px;
  margin: 16px 0 24px;
  padding: 14px 18px;
  background: var(--soft);
  border: 1px solid var(--line);
  border-radius: 5px;
}
dl.device-meta dt { font-weight: 600; color: var(--muted); }
dl.device-meta dd { margin: 0; }
dl.device-meta code.copy {
  font-family: "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.85em;
  background: #fff;
  padding: 3px 8px;
  border-radius: 3px;
  border: 1px solid var(--line);
  user-select: all;
  word-break: break-all;
}

.device-actions {
  display: flex;
  gap: 8px;
  margin: 16px 0 28px;
  flex-wrap: wrap;
}

ul.assignments {
  list-style: none;
  padding: 0;
  margin: 8px 0 28px;
}
ul.assignments li { margin: 6px 0; }
ul.assignments strong { display: inline-block; min-width: 140px; color: var(--muted); font-weight: 600; }

pre.config {
  font-family: "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.78rem;
  background: #fafafa;
  border: 1px solid var(--line);
  padding: 14px 16px;
  border-radius: 4px;
  overflow-x: auto;
  white-space: pre;
  line-height: 1.5;
  max-height: 500px;
  overflow-y: auto;
}

details summary { cursor: pointer; margin: 6px 0; color: var(--accent); }
details[open] summary { margin-bottom: 12px; }

/* ---- Device control center (P4) ---- */
.card-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 720px) { .card-grid { grid-template-columns: 1fr; } }

.sel-card {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 14px 16px;
  margin: 14px 0;
  background: #fff;
}
.sel-card h3 { margin: 0 0 10px; font-size: 0.98rem; color: var(--fg); }
.sel-card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.sel-card-head h3 { margin: 0; }
/* Compact the device assignment form so it isn't so tall to scroll/configure. */
.assign-form .sel-card { padding: 10px 14px; margin: 10px 0; }
.assign-form .sel-card h3 { margin-bottom: 4px; }
.assign-form .sel-card-head { margin-bottom: 5px; }
.assign-form .sel-card > p.muted { margin: 2px 0 7px; }
.assign-form .proxy-row { padding: 3px 10px; }
.assign-form .subset-add, .assign-form .oc-add { margin: 4px 0; }
.plain-select { width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 4px; font: inherit; background: #fff; }

/* include-all switch */
.switch { display: inline-flex; align-items: center; gap: 6px; font-size: 0.88rem; color: var(--muted); cursor: pointer; }
.switch input { margin: 0; }

.subset { margin-top: 8px; }

/* Vendor fragment previews */
.frag-list { display: flex; flex-direction: column; gap: 8px; }
.frag-item { border: 1px solid var(--line); border-radius: 4px; padding: 8px 10px; background: var(--soft); }
.frag-item label.check { display: block; font-weight: normal; }
.frag-preview summary { font-size: 0.82rem; }
.frag-preview pre.config { max-height: 240px; margin-top: 8px; }

/* Merge / diff editor */
.merge-toolbar { display: flex; gap: 12px; align-items: center; margin: 10px 0; }
#mergeview { margin: 8px 0 4px; }
.CodeMirror-merge { border: 1px solid var(--line); border-radius: 5px; height: 480px; }
.CodeMirror-merge .CodeMirror { height: 480px; }
.CodeMirror-merge-pane { font-size: 0.8rem; }

/* Tom Select theming to match the app */
.ts-control { border-color: var(--line); border-radius: 4px; min-height: 38px; }
.ts-control.focus { border-color: var(--accent); box-shadow: none; }
.ts-dropdown { border-color: var(--line); }
.ts-control .item {
  background: var(--accent-bg) !important;
  color: var(--accent) !important;
  border-radius: 3px;
  font-size: 0.85rem;
}

/* ---- Proxy collections (P5) ---- */
.coll-mgr { padding: 12px 4px 4px; display: flex; flex-direction: column; gap: 8px; }
.coll-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.coll-rename input[type=text] { padding: 5px 8px; border: 1px solid var(--line); border-radius: 4px; font: inherit; min-width: 200px; }
.coll-new { margin-top: 6px; display: flex; gap: 8px; }
.coll-new input[type=text] { padding: 6px 10px; border: 1px solid var(--line); border-radius: 4px; font: inherit; min-width: 240px; }

.move-bar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 10px;
  background: var(--accent-bg);
  border: 1px solid var(--line); border-radius: 5px;
  padding: 8px 12px; margin: 12px 0;
}

.coll-section { margin: 10px 0; border: 1px solid var(--line); border-radius: 6px; background: #fff; }
.coll-section > summary {
  cursor: pointer; padding: 10px 14px; font-size: 0.98rem;
  display: flex; align-items: center; gap: 10px; background: var(--soft);
  border-radius: 6px 6px 0 0; list-style: none;
}
.coll-section[open] > summary { border-bottom: 1px solid var(--line); border-radius: 6px 6px 0 0; }
.coll-section > summary::-webkit-details-marker { display: none; }
.coll-section .coll-name { font-weight: 600; }
.drag-grip { cursor: grab; color: var(--muted); font-size: 1.1rem; line-height: 1; user-select: none; padding: 0 2px; }
.drag-grip:active { cursor: grabbing; }
.sortable-ghost { opacity: 0.4; }
.sortable-chosen > summary { background: var(--accent-bg); }
.coll-section .sel-all { margin-left: auto; font-size: 0.82rem; }
.coll-section .table-wrap { border: none; border-radius: 0 0 6px 6px; }
table.list td.cb, table.list th.cb { width: 28px; text-align: center; }

.coll-quickpick { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-bottom: 8px; }
.chip-btn { padding: 3px 10px; font-size: 0.82rem; border-radius: 12px; display: inline-flex; align-items: center; }
.chip-btn.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.chip-btn .chip-badge { margin-left: 5px; }
.chip-btn.active .chip-badge { background: #fff; color: var(--accent); }
/* Missing-node warning list (names the offending proxies). */
.flash.info .warn-list { margin: 5px 0 0; padding-left: 20px; }
.flash.info .warn-list li { margin: 1px 0; }

/* Rule-set page: upload + grouping */
.upload-box { border: 1px solid var(--line); border-radius: 6px; padding: 10px 14px; margin: 12px 0; background: #fafbfc; }
.upload-box > summary { cursor: pointer; }
.upload-form { margin-top: 10px; }
.upload-row { display: flex; flex-wrap: wrap; gap: 14px; align-items: flex-end; margin-bottom: 10px; }
.upload-row label { display: flex; flex-direction: column; gap: 4px; font-size: 0.85rem; color: var(--muted); }
.upload-row input[type=text], .upload-row select { padding: 7px 9px; border: 1px solid var(--line); border-radius: 4px; font: inherit; min-width: 220px; }
.inline-create { display: flex; gap: 8px; align-items: center; margin: 12px 0; }
.inline-create input { padding: 6px 9px; border: 1px solid var(--line); border-radius: 4px; font: inherit; }
.coll-tools { margin-left: 10px; display: inline-flex; gap: 6px; align-items: center; }
.btn.tiny { padding: 2px 8px; font-size: 0.78rem; }
.bulk-toolbar { position: sticky; bottom: 0; display: flex; gap: 10px; align-items: center; padding: 10px 14px; background: #fff; border: 1px solid var(--line); border-radius: 6px; box-shadow: 0 -2px 8px rgba(0,0,0,0.06); margin-top: 12px; }
.bulk-toolbar select { padding: 5px 8px; border: 1px solid var(--line); border-radius: 4px; }
.coll-section .coll-tools .inline { display: inline; }

/* Rule lint panel */
.rule-lint { margin: 12px 0 18px; }
.flash.warn { background: #fff7e6; border: 1px solid #ffd591; color: #874d00; }
.lint-list { list-style: none; margin: 8px 0; padding: 0; }
.lint-list li { padding: 3px 0; font-size: 0.88rem; }
.flag.error, .flag.bad { background: #fff1f0; color: #cf1322; border: 1px solid #ffa39e; }
.flag.warn { background: #fff7e6; color: #d46b08; border: 1px solid #ffd591; }
.flag.info { background: #f0f5ff; color: #1d39c4; border: 1px solid #adc6ff; }
.flag.ok { background: #f6ffed; color: #389e0d; border: 1px solid #b7eb8f; }
.url-check { margin: 10px 0; }
.url-check-list { list-style: none; margin: 8px 0; padding: 0; }
.url-check-list li { padding: 2px 0; font-size: 0.84rem; }
.lint-info { margin-top: 8px; }
.lint-info summary { cursor: pointer; color: var(--muted); font-size: 0.85rem; }
.htmx-indicator { display: none; }
.htmx-request .htmx-indicator, .htmx-request.htmx-indicator { display: inline; }

/* Per-device collection priority list (drag to order, toggle to include) */
.coll-priority { margin-bottom: 10px; }
.coll-order-list { list-style: none; margin: 8px 0 0; padding: 0; border: 1px solid var(--line); border-radius: 6px; background: #fff; max-height: 320px; overflow-y: auto; }
.coll-row { display: flex; align-items: center; gap: 8px; padding: 5px 10px; border-bottom: 1px solid var(--line); }
.coll-row:last-child { border-bottom: none; }
.coll-row .coll-row-name { font-weight: 600; }
.coll-row .coll-row-count { margin-left: auto; }
.coll-toggle { min-width: 26px; padding: 2px 0; text-align: center; }
.coll-toggle:disabled { opacity: 0.4; cursor: default; }
.coll-row.sortable-ghost { opacity: 0.4; background: var(--accent-weak, #eef3ff); }

/* Per-device asset lists (proxies / groups / rules / rule sets): draggable + selectable */
.subset-add { margin: 8px 0; }
.clone-form { display: inline-flex; gap: 4px; align-items: center; }
.clone-name { padding: 5px 8px; border: 1px solid var(--line); border-radius: 4px; font: inherit; width: 180px; }
.oc-actions { display: inline-flex; gap: 6px; }
.oc-actions .btn { padding: 3px 10px; font-size: 0.82rem; }

/* Rules per-line editor */
.rules-mode { display: flex; gap: 16px; margin: 8px 0 12px; }
.rule-rows { list-style: none; margin: 0 0 10px; padding: 0; }
.rule-row { display: flex; align-items: center; gap: 8px; padding: 4px 0; }
.rule-row .rule-kind { flex: 0 0 168px; }
.rule-row .rule-pattern { flex: 1 1 auto; min-width: 120px; }
.rule-row .rule-target { flex: 0 0 200px; }
.rule-row .rule-flags { flex: 0 0 110px; }
.rule-row select, .rule-row input { padding: 5px 7px; border: 1px solid var(--line); border-radius: 4px; font: inherit; background: #fff; }
.rule-row .row-remove { flex: 0 0 auto; border: none; background: none; color: var(--muted); font-size: 1.1rem; line-height: 1; cursor: pointer; padding: 0 4px; }
.rule-row .row-remove:hover { color: var(--danger, #b3261e); }
.rule-row.sortable-ghost { opacity: 0.4; background: var(--accent-weak, #eef3ff); }
.oc-list { list-style: none; margin: 8px 0 0; padding: 0; border: 1px solid var(--line); border-radius: 6px; background: #fff; max-height: 360px; overflow-y: auto; }
.proxy-row { display: flex; align-items: center; gap: 8px; padding: 5px 10px; border-bottom: 1px solid var(--line); cursor: pointer; }
.proxy-row.no-drag { cursor: default; }
.proxy-row:last-child { border-bottom: none; }
.proxy-row .proxy-row-name { font-weight: 600; }
.proxy-row .proxy-row-proto { margin-left: 6px; }
/* Duplicate proxy-group name in the derived set: can't ship — flag the row, block the save. */
.proxy-row.dup-invalid { background: var(--danger-bg); box-shadow: inset 3px 0 0 var(--danger); }
.proxy-row.dup-invalid .proxy-row-name { color: var(--danger); }
.proxy-row .dup-tag { margin-left: auto; font-size: 0.78rem; font-weight: 600; color: var(--danger); white-space: nowrap; }
.flash.error .warn-list { margin: 5px 0 0; padding-left: 20px; }
.flash.error .warn-list li { margin: 1px 0; }
/* 3x-ui (dynamic) proxy row: editable per-device name on top, original name in small print below. */
.proxy-row .proxy-row-namewrap { display: flex; flex-direction: column; gap: 1px; min-width: 0; flex: 1 1 auto; }
.proxy-row .dyn-name-input {
  font: inherit; font-weight: 600; color: var(--fg);
  border: 1px solid transparent; border-radius: 4px;
  background: transparent; padding: 1px 5px; margin: -1px -2px; width: 100%; max-width: 32ch;
}
.proxy-row .dyn-name-input:hover { border-color: var(--line); }
.proxy-row .dyn-name-input:focus { border-color: var(--accent); background: #fff; outline: none; }
.proxy-row .dyn-orig { padding-left: 5px; opacity: 0.8; }
.proxy-row .dyn-reset {
  border: none; background: none; color: var(--muted); cursor: pointer;
  font-size: 0.95rem; line-height: 1; padding: 2px 4px; border-radius: 4px; flex: 0 0 auto;
}
.proxy-row .dyn-reset:hover { color: var(--accent); background: var(--accent-weak, #eef3ff); }
.proxy-row .dyn-reset.at-default { opacity: 0.25; }
.proxy-row .dyn-reset.at-default:hover { opacity: 0.6; }
.proxy-row .row-remove { margin-left: auto; border: none; background: none; color: var(--muted); font-size: 1.1rem; line-height: 1; cursor: pointer; padding: 0 4px; }
.proxy-row .row-remove:hover { color: var(--danger, #b3261e); }
.proxy-row.selected { background: var(--accent-weak, #eef3ff); }
.proxy-row.sortable-ghost { opacity: 0.4; background: var(--accent-weak, #eef3ff); }
/* While dragging a multi-selection, dim the rows left behind; the flying clone shows a stack + count. */
.oc-list.group-dragging .proxy-row.selected { opacity: 0.4; }
.row-drag-ghost { background: #fff; border: 1px solid var(--accent); border-radius: 4px; }
.row-drag-ghost.is-stack { box-shadow: 3px 3px 0 -1px #fff, 4px 4px 0 0 var(--line), 7px 7px 0 -1px #fff, 8px 8px 0 0 var(--line); }
.row-drag-ghost .drag-count { display: inline-block; margin-left: 8px; min-width: 18px; padding: 0 6px; border-radius: 9px; background: var(--accent); color: #fff; font-size: 0.78rem; text-align: center; }

/* Inline action results (htmx-swapped) */
.action-result-wrap { margin: 8px 0; min-height: 0; }
.action-result {
  padding: 9px 14px;
  border-radius: 4px;
  border: 1px solid transparent;
  font-size: 0.92rem;
  margin: 8px 0;
}
.action-result.success { background: var(--success-bg); border-color: var(--success); color: var(--success); }
.action-result.error   { background: var(--danger-bg);  border-color: var(--danger);  color: var(--danger); }
.action-result.info    { background: var(--accent-bg);  border-color: var(--accent);  color: var(--accent); }

/* htmx loading indicator */
.htmx-indicator { display: none; }
.htmx-request .htmx-indicator,
.htmx-request.htmx-indicator { display: inline; }

/* CodeMirror sizing */
.CodeMirror {
  border: 1px solid var(--line);
  border-radius: 4px;
  height: auto;
  min-height: 320px;
  font-size: 0.82rem;
}
.editor-actions { display: flex; gap: 10px; align-items: center; margin-top: 10px; }
.head-actions { display: flex; gap: 10px; align-items: center; }
.template-head { display: flex; justify-content: space-between; align-items: center; }
.template-actions { display: flex; gap: 8px; align-items: center; }
.template-actions .btn { padding: 3px 10px; font-size: 0.82rem; }

.row3 { display: grid; grid-template-columns: 1fr 2fr 1fr; gap: 12px; }
textarea.mono, .form-wide textarea {
  font-family: "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.85rem;
}
table.list td .btn { padding: 3px 9px; font-size: 0.82rem; }
table.list td form.inline { display: inline; }

.status.override { background: #efe7d6; color: #886633; }

/* Device control-center assignment blocks */
.assign-block {
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 12px 14px;
  margin: 12px 0;
  background: #fff;
}
.assign-head { font-size: 0.95rem; margin-bottom: 6px; }
.assign-block select { font: inherit; padding: 7px 10px; border: 1px solid var(--line); border-radius: 4px; }
.filter-box {
  width: 100%;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 4px;
  font: inherit;
  margin-bottom: 8px;
}
.checklist {
  max-height: 280px;
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 8px 12px;
  background: var(--soft);
}
.checklist.short { max-height: 160px; }
.checklist label.check { display: block; margin: 3px 0; font-weight: normal; font-size: 0.9rem; }
.checklist label.check input { margin-right: 7px; }
.subset { margin-top: 8px; }

/* Usage page */
.resetday-input { width: 3.2em; padding: 2px 4px; }
.btn.small { padding: 2px 7px; font-size: 0.8rem; }
.range-form { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin: 8px 0 12px; }
.range-form label.inline { display: inline-flex; align-items: center; gap: 5px; }

/* Usage — provider quota cards */
.quota-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(310px, 1fr)); gap: 14px; margin: 10px 0 24px; }
.quota-card { border: 1px solid var(--line); border-radius: 7px; padding: 14px 16px; background: #fff; }
.quota-card.q-critical { border-color: var(--danger); background: #fdf5f5; }
.quota-card.q-warn { border-color: var(--partial, #b8860b); background: #fffaf0; }
.quota-card-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.quota-card-head strong { font-size: 1.02rem; }
.quota-badge { font-size: 0.68rem; font-weight: 700; padding: 1px 6px; border-radius: 3px; letter-spacing: 0.03em; }
.quota-badge.q-ok { background: var(--success-bg); color: var(--success); }
.quota-badge.q-warn { background: #fff0d0; color: #9a6a00; }
.quota-badge.q-critical { background: var(--danger-bg); color: var(--danger); }
.online-pill { margin-left: auto; }
.quota-remaining { font-size: 1.7rem; font-weight: 700; letter-spacing: -0.01em; margin: 2px 0; }
.quota-bar { height: 9px; background: #eee; border-radius: 5px; overflow: hidden; margin: 6px 0 4px; }
.quota-bar-fill { height: 100%; background: var(--success); border-radius: 5px; }
.quota-bar-fill.q-warn { background: #d9a300; }
.quota-bar-fill.q-critical { background: var(--danger); }

/* Quota "HP bar" — width = REMAINING quota (depletes as you use it), colour by how much is LEFT, like a
   fighting-game health bar: long & green = plenty, short & red = nearly out. */
.quota-bar.hp-bar {
  height: 13px; padding: 1px; margin: 6px 0 4px; overflow: hidden;
  background: #2c2f34; border: 1px solid rgba(0,0,0,.3); border-radius: 3px;
  box-shadow: inset 0 1px 2px rgba(0,0,0,.45);
}
.hp-bar .quota-bar-fill {
  height: 100%; min-width: 3px; border-radius: 2px; transition: width .35s ease;
  /* top gloss + faint segment ticks for the retro look */
  background-image:
    linear-gradient(to bottom, rgba(255,255,255,.5), rgba(255,255,255,.08) 45%, rgba(0,0,0,.18)),
    repeating-linear-gradient(90deg, rgba(0,0,0,.18) 0 1px, transparent 1px 15px);
}
.hp-bar .quota-bar-fill.hp-high { background-color: #2fb24f; }
.hp-bar .quota-bar-fill.hp-mid  { background-color: #e6a700; }
.hp-bar .quota-bar-fill.hp-low  { background-color: #e23b2e; animation: hp-pulse 1.1s ease-in-out infinite; }
@keyframes hp-pulse { 0%,100% { filter: none; } 50% { filter: brightness(1.4); } }
@media (prefers-reduced-motion: reduce) { .hp-bar .quota-bar-fill.hp-low { animation: none; } }
.quota-line { margin: 6px 0; font-size: 0.9rem; }
.quota-note { margin: 6px 0; font-weight: 600; }
.quota-note.q-critical { color: var(--danger); }
.quota-note.q-warn { color: #9a6a00; }
.quota-foot { margin-top: 8px; padding-top: 7px; border-top: 1px solid #eee; }
.device-breakdown { margin-top: 12px; }
.device-breakdown:empty { display: none; }
.breakdown-head { margin: 6px 0 8px; }
table.list.compact td, table.list.compact th { padding: 4px 10px; }

/* HTMX request indicators (hidden until the request is in flight). */
.htmx-indicator { opacity: 0; transition: opacity 120ms ease-in; }
.htmx-request .htmx-indicator,
.htmx-request.htmx-indicator { opacity: 1; }
.spinner {
  width: 14px; height: 14px; display: inline-block; vertical-align: middle;
  border: 2px solid rgba(0,0,0,.15); border-top-color: var(--accent); border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.sync-controls { display: inline-flex; align-items: center; gap: 8px; }
.sync-stamp { white-space: nowrap; }

/* Leak audit (provider counter advance vs our meter). */
.leak-line { margin-top: 4px; font-size: .85rem; }
.leak-ok { color: #16a34a; }
.leak-gap { color: #d97706; }
.leak-leak { color: #dc2626; font-weight: 600; }

/* Site reconciliation (3x-ui vs on-box site meter). */
.recon-line { font-size: .9rem; padding: 4px 0; }
.recon-ok { color: #16a34a; }
.recon-warn { color: #dc2626; font-weight: 600; }

/* Usage instance tiles as draggable, renamable widgets. */
.tile-grip { cursor: grab; color: #9aa5b1; margin-right: 2px; user-select: none; }
.tile-grip:active { cursor: grabbing; }
.tile-rename { background: none; border: none; cursor: pointer; opacity: .45; font-size: .85em; padding: 0 2px; }
.tile-rename:hover { opacity: 1; }
.quota-card.sortable-ghost { opacity: .35; }
.quota-card.sortable-chosen { box-shadow: 0 2px 10px rgba(0,0,0,.12); }
.manual-quota-form { display: flex; flex-wrap: wrap; gap: 6px; align-items: flex-end; margin-top: 6px; }
.manual-quota-form label { display: flex; flex-direction: column; font-size: .75rem; color: #667; gap: 2px; }
.manual-quota-form input { width: 96px; }

/* "Apply to devices" picker on asset edit pages. */
.apply-devices { margin-top: 14px; border-top: 1px solid #e5e9ee; padding-top: 12px; }
.apply-devices .field-label { font-weight: 600; display: block; margin-bottom: 4px; }
.apply-toolbar { margin-bottom: 6px; }
.apply-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 4px 14px; max-height: 240px; overflow-y: auto; padding: 4px 2px; }
.apply-chk { display: flex; align-items: center; gap: 6px; font-weight: normal; cursor: pointer; }
.apply-chk input { width: auto; margin: 0; }
.apply-chk.revoked { opacity: .55; }

/* Login: passkey divider. */
.login-or { display:flex; align-items:center; text-align:center; color:#9aa5b1; margin:14px 0 10px; }
.login-or::before, .login-or::after { content:""; flex:1; border-top:1px solid #e5e9ee; }
.login-or span { padding:0 10px; font-size:.85rem; }
#passkey-btn { width:100%; }

/* Device detail: inline owner edit. */
.meta-edit { display: inline-flex; gap: 6px; align-items: center; }
.meta-edit .owner-input { width: 240px; }

/* Security: new-token reveal + token login. */
.new-token { background:#fff8e1; border:1px solid #ffe082; border-radius:6px; padding:10px 12px; margin:8px 0; }
.new-token code { word-break:break-all; font-size:.95em; }
.token-login { margin-top:16px; }
.token-login summary { cursor:pointer; }
.token-login .form { max-width:360px; }

/* Proxy group label distinguisher. */
.grp-label { color: var(--accent); font-weight: 600; font-size: .9em; }
/* Same-named variant rows on the proxy-groups page (device customizations + label clones). */
.variant-row > td { background: #fbfbfd; border-top: 1px dashed var(--line); }
.variant-row .name { padding-left: 1.4rem; }
.variant-arrow { color: var(--muted); margin-right: 2px; }
.variant-tag { display: inline-block; margin-left: 6px; padding: 0 7px; border-radius: 10px; font-size: .76rem; background: var(--accent-bg); color: var(--accent); white-space: nowrap; }
.variant-count { display: inline-block; margin-left: 5px; padding: 0 6px; border-radius: 9px; font-size: .74rem; background: var(--accent-bg); color: var(--accent); vertical-align: middle; }

/* ============ OpenAI gateway UI ============ */
.kv-line { margin-top: 4px; }
.new-secret .secret-once { display: inline-block; margin-top: 4px; padding: 4px 8px; background: #fff; border: 1px dashed var(--accent); border-radius: 5px; font-family: var(--mono, monospace); user-select: all; word-break: break-all; }

/* trace list — chevron is a CSS-drawn triangle (no glyph, so no stray font artifacts) */
.exp-col { width: 28px; text-align: center; }
.exp-toggle { display: inline-block; width: 0; height: 0; padding: 0; background: none; border-style: solid;
  border-width: 4.5px 0 4.5px 6px; border-color: transparent transparent transparent var(--muted);
  cursor: pointer; vertical-align: middle; transition: transform .12s ease; }
.trace-row.expanded .exp-toggle { transform: rotate(90deg); border-left-color: var(--accent); }
.trace-row { cursor: pointer; }
.trace-row:hover > td { background: #fafbfc; }
.trace-expand > td { background: #f7f9fc; border-top: none; padding: 8px 14px 12px; }

/* readable conversation */
.oai-convo { display: flex; flex-direction: column; gap: 8px; }
.oai-turn { border-left: 3px solid var(--line); padding: 4px 0 4px 10px; }
.oai-turn .oai-role { display: inline-block; font-size: .7rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 700; margin-bottom: 2px; }
.oai-turn .msg-text { margin: 0; word-break: break-word; overflow-wrap: anywhere; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; font-size: .9rem; line-height: 1.5; color: var(--fg); }
/* rendered-markdown elements inside a message */
.msg-text strong { font-weight: 700; }
.msg-text em { font-style: italic; }
.msg-text h3, .msg-text h4, .msg-text h5, .msg-text h6 { margin: .5em 0 .25em; font-size: 1em; font-weight: 700; }
.msg-text ul { margin: .2em 0 .4em; padding-left: 1.3em; }
.msg-text li { margin: 1px 0; }
.msg-text code { font-family: "SF Mono", Menlo, Consolas, monospace; font-size: .85em; background: var(--soft); padding: 1px 4px; border-radius: 3px; }
.msg-text pre.md-code { background: #f6f8fa; border: 1px solid var(--line); border-radius: 5px; padding: 8px 10px; margin: .4em 0; overflow-x: auto; white-space: pre; font-family: "SF Mono", Menlo, Consolas, monospace; font-size: .82rem; line-height: 1.45; }
.msg-text a { color: var(--accent); }
.turn-user { border-left-color: #1a4d99; }
.turn-assistant { border-left-color: #2fb24f; }
.turn-system, .turn-instructions, .turn-developer { border-left-color: #999; }
.turn-assistant .oai-role { color: #2fb24f; }
.turn-user .oai-role { color: #1a4d99; }

/* detail */
.trace-detail { border: 1px solid var(--line); border-radius: 8px; padding: 12px 16px; margin: 10px 0 18px; background: #fff; }
.trace-detail h4 { margin: 14px 0 6px; }
.trace-meta { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding-bottom: 8px; border-bottom: 1px solid var(--line); }
.trace-raw { margin-top: 12px; }
.trace-raw > summary { cursor: pointer; color: var(--muted); font-size: .85rem; }
.trace-raw .CodeMirror { border: 1px solid var(--line); border-radius: 6px; height: auto; margin-bottom: 8px; font-size: .82rem; }
.trace-raw .CodeMirror-scroll { max-height: 420px; }

/* gateway trace: meta side-calls */
.meta-badge { display: inline-block; padding: 0 6px; border-radius: 9px; font-size: .72rem; background: #f0ecff; color: #5b3fb0; vertical-align: middle; }
.oai-meta { display: flex; gap: 8px; align-items: baseline; padding: 4px 0 4px 10px; border-left: 3px solid #b39ddb; margin-top: 2px; }
.oai-meta-lbl { font-size: .7rem; text-transform: uppercase; letter-spacing: .03em; color: #5b3fb0; font-weight: 700; white-space: nowrap; }
.oai-meta-txt { font-size: .88rem; color: var(--fg); }
.trace-details { vertical-align: middle; }
