:root {
  --bg: #0f1115;
  --panel: #181b22;
  --panel-2: #1f232c;
  --border: #2a2f3a;
  --text: #e6e8ee;
  --muted: #8b93a7;
  --accent: #4f8dff;
  --ok: #4ade80;
  --warn: #facc15;
  --err: #f87171;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html, body { margin:0; padding:0; background: var(--bg); color: var(--text);
  font: 13px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; }

header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 16px; background: var(--panel); border-bottom: 1px solid var(--border);
}
.title { display: flex; align-items: center; gap: 8px; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--muted); }
.dot.ok { background: var(--ok); }
.dot.err { background: var(--err); }

.auth { display: flex; gap: 6px; }
.auth input { background: var(--panel-2); color: var(--text); border: 1px solid var(--border);
  padding: 6px 8px; border-radius: 4px; width: 280px; font-family: var(--mono); }

button {
  background: var(--accent); color: white; border: 0; padding: 6px 12px; border-radius: 4px;
  cursor: pointer; font-size: 12px;
}
button.ghost { background: transparent; color: var(--muted); border: 1px solid var(--border); }
button.danger { background: var(--err); }
button:disabled { opacity: 0.5; cursor: not-allowed; }

.tabs { display: flex; background: var(--panel); border-bottom: 1px solid var(--border); padding: 0 16px; }
.tab-btn { background: transparent; color: var(--muted); border: 0; border-bottom: 2px solid transparent;
  padding: 10px 14px; border-radius: 0; }
.tab-btn.active { color: var(--text); border-bottom-color: var(--accent); }

main { padding: 16px; }
.tab { display: none; }
.tab.active { display: block; }

.toolbar { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.toolbar label { display: flex; gap: 6px; align-items: center; color: var(--muted); font-size: 12px; }
.toolbar select, .toolbar input {
  background: var(--panel-2); color: var(--text); border: 1px solid var(--border);
  padding: 4px 8px; border-radius: 3px; font-size: 12px; font-family: inherit;
}

table.grid { width: 100%; border-collapse: collapse; background: var(--panel); border-radius: 6px;
  overflow: hidden; }
table.grid th, table.grid td { padding: 6px 10px; text-align: left; font-size: 12px; }
table.grid thead { background: var(--panel-2); }
table.grid thead th { color: var(--muted); font-weight: 500; border-bottom: 1px solid var(--border); }
table.grid tbody tr { border-bottom: 1px solid var(--border); }
table.grid tbody tr:hover { background: var(--panel-2); cursor: pointer; }
table.grid code { font-family: var(--mono); font-size: 11px; color: #cbd5e1; }

.muted { color: var(--muted); }
.small { font-size: 11px; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 11px;
  background: var(--panel-2); border: 1px solid var(--border); color: var(--muted); }
.badge.queued         { color: #93c5fd; border-color: #3b82f6; }
.badge.running        { color: var(--accent); border-color: var(--accent); }
.badge.waiting_session{ color: #fcd34d; border-color: #eab308; }
.badge.success        { color: var(--ok); border-color: #22c55e; }
.badge.failed         { color: var(--err); border-color: #ef4444; }
.badge.canceled       { color: var(--muted); }
.badge.locked         { color: var(--warn); border-color: var(--warn); }

.bar { height: 6px; background: var(--panel-2); border-radius: 3px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--accent); transition: width 0.3s; }
.live-progress { margin: 12px 0; }

.live-header { display: flex; justify-content: space-between; align-items: center; gap: 8px;
  background: var(--panel); padding: 10px 14px; border-radius: 6px; }
.live-header code { font-family: var(--mono); font-size: 12px; }

.live-split { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); gap: 12px; margin-top: 12px; }
.live-screen, .live-logs { background: var(--panel); border-radius: 6px; display: flex; flex-direction: column; }
.screen-head { display: flex; justify-content: space-between; padding: 8px 12px;
  border-bottom: 1px solid var(--border); color: var(--muted); font-size: 12px; }
.screen-frame { padding: 8px; }
.screen-frame img { width: 100%; border: 1px solid var(--border); border-radius: 4px;
  background: #000; display: block; }
.live-logs pre { margin: 0; padding: 8px 12px; font-family: var(--mono); font-size: 11px;
  white-space: pre-wrap; word-break: break-word; overflow: auto; min-height: 300px; max-height: 60vh; }
.live-logs .log-info { color: #cbd5e1; }
.live-logs .log-warn { color: var(--warn); }
.live-logs .log-error { color: var(--err); }

.snapshot { margin-top: 12px; background: var(--panel); border-radius: 6px; padding: 8px 12px; }
.snapshot summary { cursor: pointer; color: var(--muted); }
.snapshot pre { font-family: var(--mono); font-size: 11px; white-space: pre-wrap;
  background: var(--bg); padding: 8px; border-radius: 4px; max-height: 320px; overflow: auto; }

.toast { position: fixed; bottom: 20px; right: 20px; background: var(--panel); color: var(--text);
  padding: 10px 16px; border-radius: 6px; border: 1px solid var(--border);
  box-shadow: 0 10px 30px rgba(0,0,0,0.5); }
.toast.hidden { display: none; }

code { font-family: var(--mono); font-size: 11px; }

/* --- Monitor wall (home tab) --- */
.section-title {
  font-size: 13px; font-weight: 500; color: var(--text);
  margin: 8px 0 12px; padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 8px;
}
.monitor-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 14px;
  margin-bottom: 28px;
}
.monitor-tile {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  cursor: pointer;
  transition: border-color 0.15s, transform 0.15s, box-shadow 0.15s;
  display: flex; flex-direction: column;
}
.monitor-tile:hover {
  border-color: var(--accent);
  transform: translateY(-1px);
  box-shadow: 0 4px 20px rgba(79, 141, 255, 0.15);
}
.monitor-tile-head {
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  padding: 8px 12px;
  background: var(--panel-2);
  border-bottom: 1px solid var(--border);
}
.monitor-tile-head .key {
  font-family: var(--mono); font-size: 11px; color: var(--accent);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1;
}
.monitor-tile-screen {
  aspect-ratio: 1366 / 900;
  background: #000;
  position: relative;
  overflow: hidden;
}
.monitor-tile-screen img {
  width: 100%; height: 100%;
  object-fit: cover; object-position: top;
  display: block;
}
.monitor-tile-screen .no-shot {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  color: var(--muted); font-size: 11px;
  background: repeating-linear-gradient(45deg, #0f1115, #0f1115 10px, #14171e 10px, #14171e 20px);
}
.monitor-tile-screen .pulse {
  position: absolute; top: 8px; right: 8px;
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--err); box-shadow: 0 0 8px var(--err);
  animation: pulse 1.5s ease-in-out infinite;
}
@keyframes pulse { 0%,100% {opacity:1} 50% {opacity:0.3} }

/* Recently-finished tiles get a muted look so live ones stand out */
.monitor-tile.terminal {
  opacity: 0.65;
  filter: saturate(0.6);
}
.monitor-tile.terminal .monitor-tile-screen img {
  filter: grayscale(0.25);
}
.monitor-tile-meta {
  padding: 6px 12px;
  font-size: 11px;
  display: flex; justify-content: space-between; align-items: center;
  gap: 8px;
  color: var(--muted);
}
.monitor-tile-meta .ma { font-family: var(--mono); color: #cbd5e1; }
.monitor-tile-meta .progress-line { flex: 1; height: 3px; background: var(--panel-2); border-radius: 2px; overflow: hidden; }
.monitor-tile-meta .progress-line > span { display: block; height: 100%; background: var(--accent); transition: width 0.3s; }

.empty-state {
  padding: 40px 20px; text-align: center;
  background: var(--panel); border-radius: 8px;
  border: 1px dashed var(--border);
  margin-bottom: 28px;
}
.empty-state .big { color: var(--muted); font-size: 14px; margin-bottom: 4px; }
.empty-state a { color: var(--accent); text-decoration: none; }
.empty-state a:hover { text-decoration: underline; }

/* --- Inline live panel (Jobs tab) --- */
.inline-live { background: var(--panel); border: 1px solid var(--border); border-radius: 8px;
  margin-bottom: 14px; overflow: hidden; display: flex; flex-direction: column; }
.inline-live.hidden { display: none; }
.inline-live-head { display: flex; justify-content: space-between; align-items: center;
  gap: 8px; padding: 8px 14px; background: var(--panel-2); border-bottom: 1px solid var(--border); }
.inline-live-meta { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; font-size: 12px; }
.inline-live-meta code { font-family: var(--mono); color: #cbd5e1; font-size: 11px; }
.inline-live-meta .sep { color: var(--border); }
.inline-live-actions { display: flex; gap: 6px; align-items: center; }
.inline-live-progress { padding: 8px 14px; border-bottom: 1px solid var(--border); }
.inline-live-split { display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr); gap: 1px;
  background: var(--border); }
.inline-screen { background: #000; position: relative; aspect-ratio: 1366 / 900; }
.inline-screen img { width: 100%; height: 100%; object-fit: cover; object-position: top; display: block; }
.inline-screen .no-shot { position: absolute; inset: 0; display: flex; align-items: center;
  justify-content: center; color: var(--muted); font-size: 11px;
  background: repeating-linear-gradient(45deg, #0f1115, #0f1115 10px, #14171e 10px, #14171e 20px); }
.inline-logs { background: var(--panel); display: flex; flex-direction: column; }
.inline-logs pre { margin: 0; padding: 10px 14px; font-family: var(--mono); font-size: 11px;
  white-space: pre-wrap; word-break: break-word; overflow-y: auto; flex: 1; min-height: 0;
  max-height: 480px; }
.inline-logs pre .log-info  { color: #cbd5e1; }
.inline-logs pre .log-warn  { color: var(--warn); }
.inline-logs pre .log-error { color: var(--err); }

button.small { padding: 3px 8px; font-size: 11px; }

/* --- Scrollable table body with sticky header --- */
.scroll-body { max-height: calc(100vh - 320px); overflow-y: auto;
  background: var(--panel); border-radius: 6px; }
table.grid.sticky thead th { position: sticky; top: 0; z-index: 2; background: var(--panel-2); }
/* highlight the currently-opened row so the user keeps track when scrolling */
table.grid tbody tr.active { background: rgba(79, 141, 255, 0.12); }
table.grid tbody tr.active td { border-left: 2px solid var(--accent); }
table.grid tbody tr.active td:first-child { border-left: 2px solid var(--accent); }

.test-help { margin-bottom: 12px; padding: 10px 14px; background: var(--panel);
  border-left: 3px solid var(--accent); border-radius: 4px; }
.test-form { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 20px;
  background: var(--panel); padding: 16px; border-radius: 6px; }
.test-form label { display: flex; flex-direction: column; gap: 4px; color: var(--muted); font-size: 12px; }
.test-form input[type=text], .test-form input:not([type]), .test-form input[type=number], .test-form select {
  background: var(--panel-2); color: var(--text); border: 1px solid var(--border);
  padding: 6px 8px; border-radius: 3px; font-size: 12px; font-family: inherit;
}
.test-form label:has(input[type=checkbox]) { flex-direction: row; align-items: center; }
.test-actions { grid-column: 1/-1; display: flex; gap: 10px; align-items: center; }
.test-preset { margin-top: 16px; display: flex; flex-wrap: wrap; gap: 8px; align-items: center;
  padding: 10px 14px; background: var(--panel); border-radius: 6px; }

/* --- Callback URLs tab --- */
.cb-config { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); gap: 16px;
  background: var(--panel); padding: 14px; border-radius: 6px; }
.cb-config-col { display: flex; flex-direction: column; gap: 8px; }
.cb-config .block-label { display: flex; flex-direction: column; gap: 4px; color: var(--muted); font-size: 12px; }
.cb-config textarea {
  background: var(--panel-2); color: var(--text); border: 1px solid var(--border);
  padding: 8px; border-radius: 4px; font-family: var(--mono); font-size: 12px;
  min-height: 140px; resize: vertical;
}
.cb-config input[type=number], .cb-config input[type=text] {
  background: var(--panel-2); color: var(--text); border: 1px solid var(--border);
  padding: 6px 8px; border-radius: 3px; font-size: 12px; font-family: inherit;
}
.cb-actions { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.cb-actions button.primary { background: var(--ok); color: #0b1d10; }
.cb-actions button.primary:hover { filter: brightness(1.1); }
#cb-liffs-body td { vertical-align: top; }
#cb-liffs-body tr.shared-channel td { background: rgba(79, 141, 255, 0.04); }
#cb-liffs-body tr.no-password td { color: var(--warn); }
#cb-liffs-body tr.no-password td:hover { background: rgba(250, 204, 21, 0.05); }
.cb-liffs-table th.sortable { cursor: pointer; user-select: none; }
.cb-liffs-table th.sortable:hover { color: var(--text); }
.cb-liffs-table th.sortable::after { content: ' ·'; color: var(--border); font-size: 10px; margin-left: 2px; }
.cb-liffs-table th.sortable.sort-asc::after  { content: ' ▲'; color: var(--accent); }
.cb-liffs-table th.sortable.sort-desc::after { content: ' ▼'; color: var(--accent); }
#cb-filter.invalid { border-color: var(--err); }
#cb-filter-hint { display: block; margin-top: 2px; font-size: 10px; }
#cb-filter-hint.regex { color: var(--accent); }
#cb-filter-hint.invalid { color: var(--err); }
.cb-batch { background: var(--panel); border: 1px solid var(--border); border-radius: 8px;
  padding: 10px 14px; margin-bottom: 12px; }
.cb-batch-head { display: flex; justify-content: space-between; align-items: center; gap: 8px;
  padding-bottom: 8px; border-bottom: 1px solid var(--border); margin-bottom: 10px; }
.cb-batch-head .sep { color: var(--border); margin: 0 6px; }
#cb-batch-items td { font-size: 12px; }
#cb-batch-items .status-queued { color: #93c5fd; }
#cb-batch-items .status-running { color: var(--accent); }
#cb-batch-items .status-success { color: var(--ok); }
#cb-batch-items .status-failed { color: var(--err); }
#cb-batch-logs { max-height: 260px; overflow: auto; margin: 0; padding: 8px;
  font-family: var(--mono); font-size: 11px; white-space: pre-wrap; word-break: break-word;
  background: var(--bg); border-radius: 4px; }
#cb-batch-logs .log-info  { color: #cbd5e1; }
#cb-batch-logs .log-warn  { color: var(--warn); }
#cb-batch-logs .log-error { color: var(--err); }
