/* RELAY / MONITOR — dark technical dashboard */

:root {
  --bg: #0B0F16;
  --bg-alt: #111827;
  --surface: #151D2B;
  --surface-2: #1A2333;
  --border: #232E42;
  --border-strong: #2C3A52;
  --text: #E5EAF2;
  --text-2: #8995A8;
  --accent: #4F8CFF;
  --accent-hover: #6BA1FF;
  --success: #34C98B;
  --warning: #E9B44C;
  --error: #F16D78;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Consolas, "JetBrains Mono", monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --radius: 10px;
  --radius-sm: 7px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 var(--sans);
  -webkit-text-size-adjust: 100%;
}

body { min-height: 100vh; overflow-x: hidden; }

h1 { font-size: 22px; font-weight: 650; margin: 0; letter-spacing: -0.01em; }
h2 { font-size: 15px; font-weight: 600; margin: 0 0 12px; }
h3 { font-size: 13px; font-weight: 600; margin: 0 0 8px; color: var(--text-2); }

.muted { color: var(--text-2); }
.small { font-size: 12px; font-weight: 400; }
.ok { color: var(--success); }
.bad { color: var(--error); }
.warn { color: var(--warning); }
.wrap-text { overflow-wrap: anywhere; }

/* ------------------------------------------------------------ brand */

.brand {
  font: 600 14px/1 var(--mono);
  letter-spacing: 0.08em;
  color: var(--text);
  white-space: nowrap;
}
.brand .sep { color: var(--accent); margin: 0 4px; }
.brand-lg { font-size: 18px; letter-spacing: 0.12em; }

/* ------------------------------------------------------------ login */

.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 20px;
  background: var(--bg);
}
.login-card {
  width: min(380px, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
}
.login-sub { color: var(--text-2); font-size: 13px; margin: 8px 0 22px; }
.login-foot { color: var(--text-2); font-size: 12px; margin: 18px 0 0; text-align: center; }

/* ------------------------------------------------------------ fields / buttons */

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field > span { font-size: 12px; color: var(--text-2); }
.field.inline { flex-direction: row; align-items: center; gap: 8px; margin-bottom: 0; }
.field.inline > span { white-space: nowrap; }

input, select, textarea {
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 8px 10px;
  font: 14px/1.4 var(--sans);
  outline: none;
  transition: border-color 0.12s ease;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
input::placeholder { color: #5D6A7E; }
input[type="number"] { width: 90px; font-family: var(--mono); }
textarea { resize: vertical; width: 100%; font-family: var(--mono); font-size: 13px; }
select { cursor: pointer; }
input[type="date"] { font-family: var(--mono); font-size: 13px; }
input[type="checkbox"] { accent-color: var(--accent); width: 15px; height: 15px; padding: 0; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 8px 16px;
  font: 500 13px/1.2 var(--sans);
  cursor: pointer;
  transition: background 0.12s ease, border-color 0.12s ease;
}
.btn:hover { background: #212C40; border-color: #38486A; }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #08101F; font-weight: 600; }
.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.ghost { background: transparent; border-color: var(--border); color: var(--text-2); }
.btn.ghost:hover { color: var(--text); border-color: var(--border-strong); }
.btn.danger { background: transparent; border-color: #5A2E35; color: var(--error); }
.btn.danger:hover { background: #2A1A20; border-color: var(--error); }
.btn.block { width: 100%; padding: 10px; }

.ghost-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-2);
  border-radius: var(--radius-sm);
  padding: 6px 12px;
  font-size: 13px;
  cursor: pointer;
}
.ghost-btn:hover { color: var(--text); border-color: var(--border-strong); }

.icon-btn {
  background: transparent;
  border: none;
  color: var(--text-2);
  font-size: 15px;
  cursor: pointer;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
}
.icon-btn:hover { color: var(--text); background: var(--surface-2); }

.form-error { color: var(--error); font-size: 13px; margin: 8px 0 0; }
.ok-msg { color: var(--success); font-size: 13px; margin-left: 10px; }

/* ------------------------------------------------------------ topbar */

.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 20px;
  height: 52px;
  background: var(--bg-alt);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 40;
}
.topbar-status { display: flex; gap: 8px; flex: 1; min-width: 0; overflow: hidden; }
.topbar-actions { display: flex; gap: 8px; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 4px 10px;
  font-size: 12px;
  color: var(--text-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chip-label { color: #5D6A7E; }

.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--text-2); flex: none; }
.dot-ok { background: var(--success); }
.dot-warn { background: var(--warning); }
.dot-bad { background: var(--error); }
.dot-muted { background: var(--text-2); }

/* ------------------------------------------------------------ tabs */

.tabs {
  display: flex;
  gap: 4px;
  padding: 0 20px;
  background: var(--bg-alt);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-2);
  padding: 11px 14px;
  font: 500 13px/1 var(--sans);
  cursor: pointer;
  white-space: nowrap;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--text); border-bottom-color: var(--accent); }
.tab:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }

/* ------------------------------------------------------------ layout */

.container { max-width: 1280px; margin: 0 auto; padding: 22px 20px 60px; }
.view { display: block; }
.view[hidden] { display: none; }

.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
  margin-bottom: 18px;
}
.page-actions { display: flex; gap: 10px; }

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  margin-bottom: 16px;
}
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}
.panel-head h2 { margin: 0; }

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 16px;
}
.grid-2 .panel { margin-bottom: 0; }

/* ------------------------------------------------------------ cards */

.cards {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 16px;
}
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
}
.card b {
  display: block;
  font: 600 26px/1.1 var(--mono);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}
.card span { display: block; color: var(--text-2); font-size: 12px; margin-top: 5px; }

/* ------------------------------------------------------------ run params */

.params-grid {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 14px;
}
.params-meta { display: flex; flex-direction: column; gap: 2px; min-width: 180px; }
.params-mode { font: 600 14px/1.3 var(--mono); color: var(--accent); }
.params-buttons { display: flex; gap: 8px; margin-left: auto; }

/* ------------------------------------------------------------ run panel */

.run-panel { border-color: #2A3B5C; }
.run-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}
.run-title { display: flex; align-items: center; gap: 12px; }
.run-mode { font: 600 13px/1.3 var(--mono); letter-spacing: 0.1em; color: var(--accent); }
.run-sub { color: var(--text-2); font-size: 13px; }
.run-percent { font: 600 24px/1 var(--mono); font-variant-numeric: tabular-nums; }

.pulse {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--accent);
  animation: pulse 1.4s ease-in-out infinite;
  flex: none;
}
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.25; } }
@media (prefers-reduced-motion: reduce) { .pulse { animation: none; } }

.progress {
  height: 6px;
  background: var(--bg-alt);
  border-radius: 4px;
  overflow: hidden;
  margin-bottom: 14px;
}
.progress-bar {
  height: 100%;
  width: 0%;
  background: var(--accent);
  border-radius: 4px;
  transition: width 0.3s ease;
}
@media (prefers-reduced-motion: reduce) { .progress-bar { transition: none; } }

.run-counts {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-bottom: 14px;
}
.rc {
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.rc span:last-child { font-size: 11px; color: var(--text-2); }
.rc-n { font: 600 18px/1.2 var(--mono); font-variant-numeric: tabular-nums; }

.run-recent h3 { margin-bottom: 6px; }
.run-recent ul { list-style: none; margin: 0; padding: 0; }
.run-recent li {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 5px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.run-recent li:last-child { border-bottom: none; }
.run-recent .rr-model { font-family: var(--mono); font-size: 12.5px; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap; }
.run-recent .rr-meta { color: var(--text-2); font-family: var(--mono); font-size: 12px;
  white-space: nowrap; }

/* ------------------------------------------------------------ fast list / kv */

.fast-list { list-style: none; margin: 0; padding: 0; counter-reset: fast; }
.fast-list li {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 7px 0;
  border-bottom: 1px solid var(--border);
  counter-increment: fast;
}
.fast-list li:last-child { border-bottom: none; }
.fast-list li::before {
  content: counter(fast);
  font: 500 11px/1 var(--mono);
  color: var(--text-2);
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 3px 6px;
  min-width: 22px;
  text-align: center;
}
.fast-list .fl-model { font-family: var(--mono); font-size: 12.5px; flex: 1;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fast-list .fl-metrics { font-family: var(--mono); font-size: 12px; color: var(--text-2);
  font-variant-numeric: tabular-nums; white-space: nowrap; }
.fast-list .fl-ttft { color: var(--success); }

.kv { display: grid; grid-template-columns: auto 1fr; gap: 7px 16px; margin: 0; font-size: 13px; }
.kv dt { color: var(--text-2); }
.kv dd { margin: 0; font-family: var(--mono); font-size: 12.5px; overflow-wrap: anywhere; }

.model-list { list-style: none; margin: 0; padding: 0; }
.model-list li {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.model-list li:last-child { border-bottom: none; }
.model-list .ml-name { font-family: var(--mono); font-size: 12.5px; overflow-wrap: anywhere; }
.model-list .ml-delta { font-family: var(--mono); font-size: 12px; white-space: nowrap;
  font-variant-numeric: tabular-nums; }

/* ------------------------------------------------------------ tables */

.table-tools {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}
.table-tools .search { min-width: 220px; flex: 1; max-width: 340px; }
.table-tools .check {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  color: var(--text-2);
  cursor: pointer;
  user-select: none;
}
.table-tools .check:hover { color: var(--text); }

.table-scroll { overflow: auto; max-height: 62vh; border: 1px solid var(--border);
  border-radius: var(--radius-sm); }
.table-scroll.tall { max-height: 70vh; }
.table-foot { margin-top: 10px; text-align: center; }

.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table th {
  position: sticky;
  top: 0;
  background: var(--surface-2);
  color: var(--text-2);
  font-weight: 500;
  font-size: 12px;
  text-align: left;
  padding: 9px 12px;
  border-bottom: 1px solid var(--border-strong);
  white-space: nowrap;
  z-index: 2;
}
.data-table td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover { background: #1B2536; }
.data-table tbody tr.clickable { cursor: pointer; }
.data-table .num { text-align: right; font-family: var(--mono); font-size: 12.5px;
  font-variant-numeric: tabular-nums; white-space: nowrap; }
.data-table th.num { text-align: right; }
.data-table th.sortable { cursor: pointer; user-select: none; }
.data-table th.sortable:hover { color: var(--text); }
.data-table th.sortable::after {
  content: "↕";
  margin-left: 5px;
  font-size: 10px;
  opacity: 0.35;
}
.data-table th.sortable.active::after { content: "↑"; opacity: 1; }
.data-table th.sortable.active.desc::after { content: "↓"; }
.data-table .col-model { max-width: 340px; }
.data-table td.col-model {
  font-family: var(--mono);
  font-size: 12.5px;
  overflow-wrap: anywhere;
  max-width: 340px;
}
.data-table td.err { color: var(--text-2); font-size: 12px; max-width: 300px;
  overflow-wrap: anywhere; }
.data-table .empty-row td { color: var(--text-2); text-align: center; padding: 24px; }

.empty { color: var(--text-2); text-align: center; padding: 28px 12px; font-size: 13px; }

/* ------------------------------------------------------------ badges */

.badge {
  display: inline-block;
  font: 500 11.5px/1 var(--mono);
  padding: 4px 8px;
  border-radius: 20px;
  white-space: nowrap;
  border: 1px solid transparent;
}
.st-WORKING { color: var(--success); background: #123528; border-color: #1D4A38; }
.st-TIMEOUT { color: var(--warning); background: #362A12; border-color: #4A3A1A; }
.st-UNAVAILABLE { color: var(--warning); background: #362A12; border-color: #4A3A1A; }
.st-RATE_LIMIT { color: var(--warning); background: #362A12; border-color: #4A3A1A; }
.st-NO_TEXT { color: var(--warning); background: #362A12; border-color: #4A3A1A; }
.st-ERROR { color: var(--error); background: #3A1B21; border-color: #55282F; }
.st-INVALID_MODEL_ID { color: var(--error); background: #3A1B21; border-color: #55282F; }

.run-badge.COMPLETED { color: var(--success); background: #123528; border-color: #1D4A38; }
.run-badge.RUNNING { color: var(--accent); background: #14273F; border-color: #1F3A5F; }
.run-badge.INTERRUPTED, .run-badge.FAILED { color: var(--error); background: #3A1B21;
  border-color: #55282F; }

/* ------------------------------------------------------------ history detail */

.detail-head { display: flex; align-items: flex-start; justify-content: space-between;
  gap: 12px; }
.detail-head h2 { font-family: var(--mono); font-size: 16px; margin-bottom: 4px; }
.detail-head p { margin: 0; font-size: 13px; }

/* ------------------------------------------------------------ compare */

.compare-pickers {
  display: flex;
  align-items: flex-end;
  gap: 14px;
  flex-wrap: wrap;
}
.compare-pickers .field { flex: 1; min-width: 220px; margin-bottom: 0; }
.compare-pickers select { width: 100%; }

/* ------------------------------------------------------------ settings */

.settings-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 14px 18px;
  align-items: end;
}
.settings-grid .field { margin-bottom: 0; }
.settings-grid .span-all { grid-column: 1 / -1; }
.settings-grid input, .settings-grid select { width: 100%; }

.apikey-row { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; }
.apikey-row .grow { flex: 1; min-width: 240px; margin-bottom: 0; }
.apikey-row input { width: 100%; font-family: var(--mono); }

/* ------------------------------------------------------------ drawer */

.drawer {
  position: fixed;
  top: 0;
  right: 0;
  width: min(420px, 100%);
  height: 100vh;
  background: var(--bg-alt);
  border-left: 1px solid var(--border-strong);
  z-index: 60;
  display: flex;
  flex-direction: column;
  transform: translateX(0);
}
.drawer[hidden] { display: none; }
.drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}
.drawer-head h3 {
  margin: 0;
  font-family: var(--mono);
  font-size: 14px;
  color: var(--text);
  overflow-wrap: anywhere;
}
.drawer-body { padding: 16px 18px; overflow-y: auto; }
.drawer-body .kv { grid-template-columns: 110px 1fr; }
.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(4, 7, 12, 0.55);
  z-index: 55;
}
.drawer-backdrop[hidden] { display: none; }

/* ------------------------------------------------------------ toasts */

.toasts {
  position: fixed;
  bottom: 18px;
  right: 18px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 80;
  max-width: min(360px, calc(100vw - 36px));
}
.toast {
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  border-left-width: 3px;
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 13px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.35);
  animation: toast-in 0.18s ease;
}
.toast.ok { border-left-color: var(--success); }
.toast.error { border-left-color: var(--error); }
.toast.info { border-left-color: var(--accent); }
@keyframes toast-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .toast { animation: none; } }

/* ------------------------------------------------------------ responsive */

@media (max-width: 960px) {
  .grid-2 { grid-template-columns: 1fr; }
  .cards { grid-template-columns: repeat(2, 1fr); }
  .run-counts { grid-template-columns: repeat(2, 1fr); }
  .chip-wide { display: none; }
}

@media (max-width: 640px) {
  .topbar { height: auto; min-height: 52px; flex-wrap: wrap; padding: 8px 14px; gap: 8px; }
  .topbar-status { order: 3; width: 100%; overflow-x: auto; scrollbar-width: none; }
  .topbar-status::-webkit-scrollbar { display: none; }
  .topbar-actions { margin-left: auto; }
  .tabs { padding: 0 10px; }
  .container { padding: 16px 12px 48px; }
  h1 { font-size: 19px; }
  .panel { padding: 14px; }
  .cards { gap: 8px; }
  .card b { font-size: 22px; }
  .table-tools .search { min-width: 100%; max-width: none; }
  .params-buttons { margin-left: 0; width: 100%; }
  .params-buttons .btn { flex: 1; }
  .compare-pickers .field { min-width: 100%; }
  .compare-pickers .btn { width: 100%; }
  .apikey-row .btn { flex: 1; }
  .data-table .col-model, .data-table td.col-model { max-width: 190px; }
  .drawer { width: 100%; }
}
