:root {
  --bg: #0b0f17;
  --bg-elevated: #111827;
  --bg-card: #151c2c;
  --bg-hover: #1a2336;
  --border: #243044;
  --border-subtle: #1c2538;
  --text: #e8edf5;
  --text-muted: #8b9ab8;
  --text-dim: #5c6b88;
  --accent: #0ea5e9;
  --accent-hover: #38bdf8;
  --accent-glow: rgba(14, 165, 233, 0.15);
  --success: #22c55e;
  --success-bg: rgba(34, 197, 94, 0.12);
  --warning: #f59e0b;
  --warning-bg: rgba(245, 158, 11, 0.12);
  --danger: #ef4444;
  --danger-bg: rgba(239, 68, 68, 0.12);
  --info: #6366f1;
  --sidebar-w: 240px;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.35);
  --font: 'Inter', system-ui, -apple-system, sans-serif;
  --mono: 'JetBrains Mono', 'SF Mono', ui-monospace, monospace;
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }
.text-muted { color: var(--text-muted); }
.card-header { display: flex; align-items: center; justify-content: space-between; padding: 1rem 1.125rem; border-bottom: 1px solid var(--border-subtle); }
.card-header h3 { margin: 0; font-size: 0.875rem; font-weight: 600; }
.data-table { width: 100%; border-collapse: collapse; font-size: 0.8125rem; }
.data-table th, .data-table td { padding: 0.625rem 0.75rem; text-align: left; border-bottom: 1px solid var(--border-subtle); }
.data-table th { color: var(--text-muted); font-weight: 500; font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.03em; }
.data-table tr.clickable { cursor: pointer; }
.data-table tr.clickable:hover { background: var(--bg-hover); }
.service-row { display: flex; justify-content: space-between; align-items: center; padding: 0.5rem 0; border-bottom: 1px solid var(--border-subtle); }
.field { margin-bottom: 1rem; }
.field label { display: block; font-size: 0.8125rem; font-weight: 500; color: var(--text-muted); margin-bottom: 0.375rem; }
.field input,
.field select,
.field textarea { width: 100%; padding: 0.625rem 0.75rem; background: var(--bg-elevated); border: 1px solid var(--border); border-radius: var(--radius-sm); color: var(--text); font-family: inherit; font-size: 0.875rem; }
.field textarea { min-height: 80px; resize: vertical; }
.field input:focus,
.field select:focus,
.field textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-glow); }
.stat-grid .stat-card { background: var(--bg-card); border: 1px solid var(--border-subtle); border-radius: var(--radius); }
.page { animation: fadeIn 0.15s ease; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* ── Login ── */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 1.5rem;
}

.login-bg {
  position: fixed;
  inset: 0;
  background:
    radial-gradient(ellipse 80% 60% at 50% -10%, rgba(14, 165, 233, 0.18), transparent),
    radial-gradient(ellipse 50% 40% at 100% 100%, rgba(99, 102, 241, 0.1), transparent),
    var(--bg);
  z-index: 0;
}

.login-card {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 400px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 2rem;
  box-shadow: var(--shadow);
}

.login-brand { text-align: center; margin-bottom: 1.75rem; }
.login-brand h1 { margin: 0.75rem 0 0.25rem; font-size: 1.35rem; font-weight: 600; letter-spacing: -0.02em; }
.login-brand p { margin: 0; color: var(--text-muted); font-size: 0.875rem; }

.brand-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  border-radius: 12px;
  background: var(--accent-glow);
  color: var(--accent);
}
.brand-icon svg { width: 26px; height: 26px; }

.login-form .field { margin-bottom: 1rem; }
.login-form label { display: block; font-size: 0.8125rem; font-weight: 500; color: var(--text-muted); margin-bottom: 0.375rem; }
.login-form input {
  width: 100%;
  padding: 0.625rem 0.875rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 0.9375rem;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.login-form input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.form-error {
  color: var(--danger);
  font-size: 0.8125rem;
  margin: 0 0 0.75rem;
  padding: 0.5rem 0.75rem;
  background: var(--danger-bg);
  border-radius: var(--radius-sm);
}

.login-foot {
  margin: 1.5rem 0 0;
  text-align: center;
  font-size: 0.75rem;
  color: var(--text-dim);
}

/* ── Layout ── */
.app-shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--bg-elevated);
  border-right: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 100;
}

.sidebar-brand {
  padding: 1.25rem 1rem;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  gap: 0.625rem;
}
.sidebar-brand .brand-icon { width: 36px; height: 36px; border-radius: 8px; }
.sidebar-brand .brand-icon svg { width: 20px; height: 20px; }
.sidebar-brand span { font-weight: 600; font-size: 0.9375rem; letter-spacing: -0.01em; }

.sidebar-nav {
  flex: 1;
  padding: 0.75rem 0.625rem;
  overflow-y: auto;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  width: 100%;
  padding: 0.5625rem 0.75rem;
  margin-bottom: 2px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-muted);
  font-size: 0.875rem;
  font-family: inherit;
  cursor: pointer;
  text-align: left;
  transition: background 0.12s, color 0.12s;
}
.nav-item:hover { background: var(--bg-hover); color: var(--text); }
.nav-item.active { background: var(--accent-glow); color: var(--accent); font-weight: 500; }
.nav-item svg { width: 18px; height: 18px; flex-shrink: 0; opacity: 0.85; }

.sidebar-foot {
  padding: 0.75rem 0.625rem 1rem;
  border-top: 1px solid var(--border-subtle);
}
.sidebar-foot .user-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 0.75rem;
  font-size: 0.8125rem;
  color: var(--text-muted);
}

.main {
  flex: 1;
  margin-left: var(--sidebar-w);
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.75rem;
  border-bottom: 1px solid var(--border-subtle);
  background: rgba(11, 15, 23, 0.8);
  backdrop-filter: blur(8px);
  position: sticky;
  top: 0;
  z-index: 50;
}
.topbar h2 { margin: 0; font-size: 1.125rem; font-weight: 600; letter-spacing: -0.02em; }
.topbar-actions { display: flex; gap: 0.5rem; align-items: center; }

.content {
  padding: 1.5rem 1.75rem 2rem;
  flex: 1;
}

/* ── Components ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.375rem;
  padding: 0.4375rem 0.875rem;
  border: none;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 0.8125rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.12s, opacity 0.12s, transform 0.08s;
  white-space: nowrap;
}
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn:active:not(:disabled) { transform: scale(0.98); }

.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
}
.btn-ghost:hover:not(:disabled) { background: var(--bg-hover); color: var(--text); }

.btn-danger { background: var(--danger-bg); color: var(--danger); border: 1px solid transparent; }
.btn-danger:hover:not(:disabled) { background: rgba(239, 68, 68, 0.2); }

.btn-sm { padding: 0.3125rem 0.625rem; font-size: 0.75rem; }
.btn-block { width: 100%; padding: 0.6875rem; font-size: 0.9375rem; }

.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.grid { display: grid; gap: 1rem; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }

@media (max-width: 1100px) {
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
  .grid-3 { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); }
  .main { margin-left: 0; }
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
}

.card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius);
  overflow: hidden;
}
.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.875rem 1.125rem;
  border-bottom: 1px solid var(--border-subtle);
}
.card-head h3 { margin: 0; font-size: 0.875rem; font-weight: 600; }
.card-body { padding: 1.125rem; }

.stat-card {
  padding: 1.125rem;
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
}
.stat-card .label { font-size: 0.75rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; font-weight: 500; }
.stat-card .value { font-size: 1.75rem; font-weight: 700; letter-spacing: -0.03em; line-height: 1.1; }
.stat-card .sub { font-size: 0.75rem; color: var(--text-dim); }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.1875rem 0.5rem;
  border-radius: 999px;
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.badge::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}
.badge-success { background: var(--success-bg); color: var(--success); }
.badge-warning { background: var(--warning-bg); color: var(--warning); }
.badge-danger { background: var(--danger-bg); color: var(--danger); }
.badge-info { background: rgba(99, 102, 241, 0.12); color: var(--info); }
.badge-muted { background: rgba(139, 154, 184, 0.12); color: var(--text-muted); }

.table-wrap { overflow-x: auto; }
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8125rem;
}
th {
  text-align: left;
  padding: 0.625rem 1rem;
  font-weight: 500;
  color: var(--text-muted);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 1px solid var(--border-subtle);
  background: rgba(0,0,0,0.15);
}
td {
  padding: 0.6875rem 1rem;
  border-bottom: 1px solid var(--border-subtle);
  vertical-align: middle;
}
tr:last-child td { border-bottom: none; }
tr:hover td { background: rgba(255,255,255,0.02); }

.mono { font-family: var(--mono); font-size: 0.75rem; }

.log-view {
  background: #060a10;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 1rem;
  font-family: var(--mono);
  font-size: 0.75rem;
  line-height: 1.6;
  color: #a8b8d0;
  overflow: auto;
  max-height: 480px;
  white-space: pre-wrap;
  word-break: break-all;
  margin: 0;
}

.empty-state {
  text-align: center;
  padding: 2.5rem 1rem;
  color: var(--text-muted);
}
.empty-state svg { width: 40px; height: 40px; opacity: 0.35; margin-bottom: 0.75rem; }
.empty-state p { margin: 0; font-size: 0.875rem; }

.loading-state {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.625rem;
  padding: 2rem;
  color: var(--text-muted);
  font-size: 0.875rem;
}
.loading-state .spinner { border-color: rgba(139,154,184,0.3); border-top-color: var(--accent); }

.error-banner {
  padding: 0.75rem 1rem;
  background: var(--danger-bg);
  border: 1px solid rgba(239,68,68,0.25);
  border-radius: var(--radius-sm);
  color: #fca5a5;
  font-size: 0.8125rem;
  margin-bottom: 1rem;
}

.quick-links {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}
.quick-link {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.4375rem 0.75rem;
  background: var(--bg-hover);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: 0.8125rem;
  text-decoration: none;
  transition: color 0.12s, border-color 0.12s;
}
.quick-link:hover { color: var(--accent); border-color: var(--accent); }

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  margin-bottom: 1rem;
}
.toolbar input, .toolbar select {
  padding: 0.4375rem 0.75rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: inherit;
  font-size: 0.8125rem;
}
.toolbar input:focus, .toolbar select:focus {
  outline: none;
  border-color: var(--accent);
}

.job-section { margin-bottom: 1.25rem; }
.job-section h4 {
  margin: 0 0 0.5rem;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
}

.session-detail pre {
  background: #060a10;
  padding: 0.75rem;
  border-radius: var(--radius-sm);
  overflow: auto;
  max-height: 300px;
  font-size: 0.75rem;
}

.page { display: none; }
.page.active { display: block; }

.toast {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  padding: 0.75rem 1.125rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  font-size: 0.8125rem;
  z-index: 1000;
  animation: slideUp 0.25s ease;
}
@keyframes slideUp {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.text-muted { color: var(--text-muted); }

.chat-panel {
  display: flex;
  flex-direction: column;
  gap: 0.625rem;
  max-height: 380px;
  overflow-y: auto;
  padding: 0.75rem;
  background: #060a10;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  margin: 0.75rem 0;
}

.chat-msg {
  max-width: 88%;
  padding: 0.625rem 0.875rem;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  white-space: pre-wrap;
  line-height: 1.45;
}

.chat-msg.user { align-self: flex-end; background: rgba(14, 165, 233, 0.2); border: 1px solid rgba(14, 165, 233, 0.35); }
.chat-msg.assistant { align-self: flex-start; background: var(--bg-hover); border: 1px solid var(--border-subtle); }
.chat-msg.system { align-self: center; background: var(--warning-bg); color: var(--warning); font-size: 0.8125rem; max-width: 100%; }

.chat-compose {
  display: flex;
  gap: 0.625rem;
  align-items: flex-end;
}

.chat-compose textarea {
  flex: 1;
  padding: 0.625rem 0.75rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 0.875rem;
  resize: vertical;
}

.tool-log {
  list-style: none;
  margin: 0;
  padding: 0.625rem;
  background: #060a10;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  font-family: var(--mono);
  font-size: 0.75rem;
  max-height: 200px;
  overflow-y: auto;
}

.tool-log li { padding: 0.35rem 0; border-bottom: 1px solid var(--border-subtle); }
.tool-log li:last-child { border-bottom: 0; }

.confirm-banner {
  margin: 0.75rem 0;
  padding: 0.75rem 1rem;
  background: var(--warning-bg);
  border: 1px solid rgba(245, 158, 11, 0.35);
  border-radius: var(--radius-sm);
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
}

.step-timeline { list-style: none; margin: 0; padding: 0; }
.step-timeline li {
  display: flex;
  gap: 0.75rem;
  padding: 0.625rem 0;
  border-bottom: 1px solid var(--border-subtle);
  font-size: 0.8125rem;
}
.step-timeline li:last-child { border-bottom: 0; }
.step-dot {
  width: 10px; height: 10px; border-radius: 50%; margin-top: 0.35rem; flex-shrink: 0;
}
.step-dot.ok { background: var(--success); }
.step-dot.fail { background: var(--danger); }

.screenshot-gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 0.75rem;
  margin: 0.75rem 0;
}
.screenshot-gallery a {
  display: block;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--bg);
}
.screenshot-gallery img {
  width: 100%;
  height: 120px;
  object-fit: cover;
  display: block;
}
.screenshot-gallery span {
  display: block;
  padding: 0.35rem 0.5rem;
  font-size: 0.6875rem;
  color: var(--text-muted);
  font-family: var(--mono);
}

.video-player {
  width: 100%;
  max-width: 720px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: #000;
}

.settings-form label {
  display: block;
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: 0.25rem;
}
.settings-form input[type="text"],
.settings-form input[type="password"],
.settings-form textarea {
  width: 100%;
  max-width: 480px;
  padding: 0.5rem 0.75rem;
  margin-bottom: 0.75rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: inherit;
  font-size: 0.8125rem;
}
.settings-form .row { display: flex; gap: 0.75rem; align-items: center; margin-bottom: 0.75rem; }
.cron-row {
  display: grid;
  grid-template-columns: 1fr 1.5fr auto auto;
  gap: 0.5rem;
  align-items: center;
  margin-bottom: 0.5rem;
  font-size: 0.8125rem;
}
.observer-card {
  padding: 0.75rem;
  background: var(--bg-hover);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  margin-top: 0.75rem;
  font-size: 0.8125rem;
}

.allowed-models-block {
  margin-bottom: 1.5rem;
  padding-bottom: 1.25rem;
  border-bottom: 1px solid var(--border-subtle);
}
.allowed-models-block:last-child { border-bottom: none; margin-bottom: 0; padding-bottom: 0; }
.allowed-models-links { font-size: 0.8125rem; margin: 0.35rem 0 0.75rem; }
.allowed-models-links a { color: var(--accent); margin-right: 1rem; }
.allowed-models-list {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  max-height: 220px;
  overflow-y: auto;
  margin: 0.5rem 0;
  padding: 0.5rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.allowed-model-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.8125rem;
  font-family: var(--mono);
}
.allowed-model-row .price-hint {
  margin-left: auto;
  font-family: var(--font);
  font-size: 0.7rem;
  color: var(--text-dim);
}
.allowed-models-custom {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.5rem;
  flex-wrap: wrap;
}
.allowed-models-custom input {
  flex: 1;
  min-width: 160px;
  padding: 0.4rem 0.6rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: var(--mono);
  font-size: 0.75rem;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(0, 0, 0, 0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.modal-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
  max-width: 480px;
  width: 100%;
  box-shadow: var(--shadow);
}
.modal-card h3 { margin: 0 0 0.75rem; }

.meter { margin-top: 0.75rem; height: 6px; background: var(--border-subtle); border-radius: 999px; overflow: hidden; }
.meter-fill { height: 100%; border-radius: 999px; transition: width 0.3s ease; }
.meter-fill.meter-ok { background: var(--accent, #3b82f6); }
.meter-fill.meter-warning { background: #f59e0b; }
.meter-fill.meter-danger { background: #ef4444; }
