
:root {
  --bg: #0b1220;
  --bg-elevated: #121a2b;
  --panel: #162033;
  --panel-border: #2a3a55;
  --text: #e8eef8;
  --muted: #8fa3bf;
  --accent: #3d8bfd;
  --accent-hover: #2f78e6;
  --green: #34d399;
  --green-bg: #0f2f24;
  --red: #f87171;
  --red-bg: #3b1212;
  --amber: #fbbf24;
  --amber-bg: #3b2f0f;
  --input-bg: #0f1729;
  --nav-width: 220px;
  --radius: 10px;
  --font: "Source Sans 3", "Segoe UI", system-ui, sans-serif;
  --font-display: "DM Sans", "Source Sans 3", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; min-height: 100%; }
body {
  font-family: var(--font);
  background:
    radial-gradient(ellipse 80% 50% at 10% -10%, rgba(61,139,253,0.18), transparent 50%),
    radial-gradient(ellipse 60% 40% at 100% 0%, rgba(52,211,153,0.08), transparent 45%),
    var(--bg);
  color: var(--text);
  line-height: 1.45;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---- Login ---- */
.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 16px;
  padding: 36px 32px;
  box-shadow: 0 24px 60px rgba(0,0,0,0.35);
}
.login-brand {
  font-family: var(--font-display);
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.03em;
  margin: 0 0 6px;
}
.login-sub {
  color: var(--muted);
  font-size: 14px;
  margin: 0 0 28px;
}
.form-group { margin-bottom: 16px; }
.form-group label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin-bottom: 6px;
}
input[type="text"],
input[type="password"],
input[type="url"],
textarea,
select {
  width: 100%;
  background: var(--input-bg);
  border: 1px solid var(--panel-border);
  color: var(--text);
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
}
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(61,139,253,0.2);
}
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: var(--accent);
  color: white;
  border: none;
  padding: 10px 16px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}
.btn:hover { background: var(--accent-hover); }
.btn:disabled { background: #475569; cursor: not-allowed; }
.btn-block { width: 100%; }
.btn-secondary {
  background: transparent;
  border: 1px solid var(--panel-border);
  color: var(--text);
}
.btn-secondary:hover { background: var(--bg-elevated); }
.btn-danger { background: #7f1d1d; }
.btn-danger:hover { background: #991b1b; }
.btn-sm { padding: 6px 10px; font-size: 12px; }
.alert {
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 13px;
  margin-bottom: 16px;
}
.alert-error { background: var(--red-bg); color: var(--red); border: 1px solid #7f1d1d; }
.alert-warn { background: var(--amber-bg); color: var(--amber); border: 1px solid #854d0e; }
.alert-ok { background: var(--green-bg); color: var(--green); border: 1px solid #14532d; }

/* ---- Shell / nav ---- */
.app-shell { display: flex; min-height: 100vh; }
.sidebar {
  width: var(--nav-width);
  flex-shrink: 0;
  background: rgba(15, 23, 41, 0.92);
  border-right: 1px solid var(--panel-border);
  padding: 20px 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.sidebar-brand {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 18px;
  letter-spacing: -0.02em;
  padding: 4px 10px 18px;
}
.sidebar-brand span { color: var(--muted); font-weight: 500; font-size: 12px; display: block; margin-top: 2px; }
.nav-link {
  display: block;
  padding: 10px 12px;
  border-radius: 8px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 500;
  text-decoration: none;
}
.nav-link:hover { background: var(--panel); color: var(--text); text-decoration: none; }
.nav-link.active { background: rgba(61,139,253,0.15); color: var(--accent); }
.sidebar-footer {
  margin-top: auto;
  padding: 12px 10px 4px;
  border-top: 1px solid var(--panel-border);
  font-size: 12px;
  color: var(--muted);
}
.sidebar-footer form { margin-top: 8px; }
.main {
  flex: 1;
  padding: 28px 32px 48px;
  min-width: 0;
}
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 24px;
}
.page-header h1 {
  font-family: var(--font-display);
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin: 0 0 4px;
}
.page-header .subtitle { color: var(--muted); font-size: 14px; margin: 0; }
.controls { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

.panel {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  padding: 18px 20px;
  margin-bottom: 18px;
}
.panel h2 {
  font-size: 15px;
  font-weight: 650;
  margin: 0 0 14px;
  letter-spacing: -0.01em;
}
.panel-hint { color: var(--muted); font-size: 13px; margin: -8px 0 14px; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}
.card {
  background: var(--bg-elevated);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  padding: 14px;
}
.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}
.card-name { font-weight: 600; font-size: 14px; }
.card-id { color: var(--muted); font-size: 11px; margin-top: 2px; }
.badge {
  font-size: 11px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 999px;
  white-space: nowrap;
}
.badge.available { background: var(--green-bg); color: var(--green); }
.badge.unavailable { background: transparent; color: var(--muted); border: 1px solid var(--panel-border); }
.badge.error { background: var(--red-bg); color: var(--red); }
.agent-list { font-size: 12px; margin-top: 6px; line-height: 1.6; }
.error-text { font-size: 12px; color: var(--red); margin-top: 6px; }
.empty-state { color: var(--muted); font-size: 13px; padding: 16px 4px; }

#summary {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  padding: 14px 18px;
  margin-bottom: 18px;
  font-size: 14px;
  display: none;
}
#summary.show { display: block; }
#lastChecked { color: var(--muted); font-size: 12px; }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--panel-border); vertical-align: middle; }
th { color: var(--muted); font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; }
.row-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.add-row { display: flex; gap: 8px; margin-top: 14px; flex-wrap: wrap; }
.add-row input { flex: 1; min-width: 140px; }

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px 18px;
}
.form-grid .full { grid-column: 1 / -1; }
.field-hint { font-size: 12px; color: var(--muted); margin-top: 4px; }
.toggle-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid var(--panel-border);
}
.toggle-row:last-child { border-bottom: none; }
.toggle-row .label { font-weight: 560; font-size: 14px; }
.toggle-row .desc { font-size: 12px; color: var(--muted); margin-top: 2px; }
.switch {
  position: relative;
  width: 44px;
  height: 24px;
  flex-shrink: 0;
}
.switch input { opacity: 0; width: 0; height: 0; }
.switch .slider {
  position: absolute;
  inset: 0;
  background: #334155;
  border-radius: 999px;
  cursor: pointer;
  transition: 0.2s;
}
.switch .slider:before {
  content: "";
  position: absolute;
  width: 18px;
  height: 18px;
  left: 3px;
  top: 3px;
  background: white;
  border-radius: 50%;
  transition: 0.2s;
}
.switch input:checked + .slider { background: var(--accent); }
.switch input:checked + .slider:before { transform: translateX(20px); }

.master-toggle {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 18px;
  background: var(--bg-elevated);
  border-radius: var(--radius);
  border: 1px solid var(--panel-border);
  margin-bottom: 8px;
}
.master-toggle.on { border-color: rgba(52,211,153,0.4); }
.master-toggle.off { border-color: rgba(248,113,113,0.4); }
.master-status { font-size: 18px; font-weight: 700; }
.master-status.on { color: var(--green); }
.master-status.off { color: var(--red); }

.log-filters { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.log-table td { font-size: 12.5px; }
.log-table .ts { color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.level-info { color: var(--accent); }
.level-warning { color: var(--amber); }
.level-error { color: var(--red); }
.type-pill {
  display: inline-block;
  font-size: 11px;
  padding: 2px 7px;
  border-radius: 999px;
  background: var(--bg);
  border: 1px solid var(--panel-border);
  color: var(--muted);
}

.toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  padding: 10px 16px;
  border-radius: 8px;
  font-size: 13px;
  display: none;
  z-index: 50;
  max-width: 360px;
}
.toast.show { display: block; }
.toast.error { border-color: var(--red); color: var(--red); }

@media (max-width: 800px) {
  .app-shell { flex-direction: column; }
  .sidebar {
    width: 100%;
    height: auto;
    position: relative;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
  }
  .sidebar-brand { width: 100%; padding-bottom: 8px; }
  .sidebar-footer { width: 100%; margin-top: 8px; }
  .main { padding: 20px 16px 40px; }
  .form-grid { grid-template-columns: 1fr; }
}


/* ---- Instructions / docs ---- */
.docs-layout {
  display: grid;
  grid-template-columns: 200px 1fr;
  gap: 24px;
  align-items: start;
}
.docs-toc {
  position: sticky;
  top: 20px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  padding: 14px 12px;
}
.docs-toc h3 {
  margin: 0 0 10px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}
.docs-toc a {
  display: block;
  padding: 5px 8px;
  border-radius: 6px;
  color: var(--muted);
  font-size: 13px;
  text-decoration: none;
}
.docs-toc a:hover { background: var(--bg-elevated); color: var(--text); text-decoration: none; }
.docs-section {
  scroll-margin-top: 20px;
  margin-bottom: 8px;
}
.docs-section h2 {
  font-family: var(--font-display);
  font-size: 18px;
  margin: 0 0 10px;
  letter-spacing: -0.02em;
}
.docs-section h3 {
  font-size: 14px;
  margin: 18px 0 8px;
  color: var(--text);
}
.docs-section p, .docs-section li {
  font-size: 14px;
  color: var(--muted);
}
.docs-section p { margin: 0 0 10px; }
.docs-section ul, .docs-section ol { margin: 0 0 12px; padding-left: 1.2em; }
.docs-section code, .docs-inline code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 12.5px;
  background: var(--bg);
  border: 1px solid var(--panel-border);
  border-radius: 4px;
  padding: 1px 5px;
  color: var(--text);
}
.docs-section pre {
  background: var(--bg);
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  padding: 12px 14px;
  overflow-x: auto;
  margin: 0 0 14px;
}
.docs-section pre code {
  border: none;
  background: transparent;
  padding: 0;
  font-size: 12.5px;
  color: #c7d2fe;
}
.method {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 4px;
  background: rgba(61,139,253,0.2);
  color: var(--accent);
  margin-right: 6px;
  vertical-align: middle;
}
.endpoint-path {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 13.5px;
  color: var(--text);
  font-weight: 600;
}
@media (max-width: 900px) {
  .docs-layout { grid-template-columns: 1fr; }
  .docs-toc { position: relative; top: 0; }
}


.queue-toolbar {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 14px;
}
.queue-toolbar label {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}
.queue-toolbar select {
  min-width: 160px;
  background: var(--input-bg);
  border: 1px solid var(--panel-border);
  color: var(--text);
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 13px;
  font-family: inherit;
}
.bulk-add {
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid var(--panel-border);
}
.bulk-add textarea {
  width: 100%;
  min-height: 120px;
  background: var(--input-bg);
  border: 1px solid var(--panel-border);
  color: var(--text);
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 13px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  resize: vertical;
}
.bulk-add .bulk-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
  margin-top: 10px;
}
.bulk-add .bulk-actions input {
  max-width: 200px;
}
.filter-count {
  color: var(--muted);
  font-size: 12px;
  margin-left: auto;
}


/* ---- Light theme ---- */
html[data-theme="light"] {
  --bg: #eef2f7;
  --bg-elevated: #ffffff;
  --panel: #ffffff;
  --panel-border: #d0dae8;
  --text: #1a2433;
  --muted: #5c6b80;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --green: #159a5a;
  --green-bg: #e6f7ee;
  --red: #dc2626;
  --red-bg: #fee2e2;
  --amber: #b45309;
  --amber-bg: #fef3c7;
  --input-bg: #f7f9fc;
}
html[data-theme="light"] body {
  background:
    radial-gradient(ellipse 80% 50% at 10% -10%, rgba(37,99,235,0.10), transparent 50%),
    radial-gradient(ellipse 60% 40% at 100% 0%, rgba(21,154,90,0.06), transparent 45%),
    var(--bg);
}
html[data-theme="light"] .sidebar {
  background: rgba(255, 255, 255, 0.92);
}
html[data-theme="light"] .docs-section pre code {
  color: #1e3a5f;
}
html[data-theme="light"] .toast {
  box-shadow: 0 8px 24px rgba(26, 36, 51, 0.12);
}
html[data-theme="light"] dialog {
  box-shadow: 0 20px 50px rgba(26, 36, 51, 0.18);
}
html[data-theme="light"] .master-toggle.on {
  border-color: rgba(21, 154, 90, 0.45);
}
html[data-theme="light"] .master-toggle.off {
  border-color: rgba(220, 38, 38, 0.4);
}

.theme-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
  width: 100%;
}
.theme-toggle .btn {
  flex: 1;
}
