:root {
  --bg: #0f1117;
  --bg-card: #1a1d27;
  --bg-input: #252836;
  --border: #2d3040;
  --text: #e4e6ed;
  --text-muted: #8b8fa3;
  --text-dim: #5c6078;
  --accent: #6c8aff;
  --accent-dim: #4a5e99;
  --green: #4ade80;
  --green-dim: #166534;
  --yellow: #facc15;
  --yellow-dim: #713f12;
  --red: #f87171;
  --red-dim: #7f1d1d;
  --orange: #fb923c;
  --purple: #a78bfa;
  --radius: 8px;
  --shadow: 0 2px 8px rgba(0,0,0,0.3);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

/* Header */
header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 24px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 24px;
}

header h1 {
  font-size: 16px;
  font-weight: 600;
  color: var(--accent);
  letter-spacing: -0.3px;
}

nav {
  display: flex;
  gap: 4px;
}

.nav-link {
  color: var(--text-muted);
  text-decoration: none;
  padding: 6px 14px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 500;
  transition: all 0.15s;
}

.nav-link:hover { color: var(--text); background: var(--bg-input); }
.nav-link.active { color: var(--text); background: var(--accent-dim); }

/* Budget Indicator */
.budget-indicator {
  display: flex;
  align-items: center;
  gap: 10px;
}

.budget-bar {
  width: 120px;
  height: 6px;
  background: var(--bg-input);
  border-radius: 3px;
  overflow: hidden;
}

.budget-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.5s ease, background-color 0.3s;
  background: var(--green);
  width: 0%;
}

.budget-fill.warning { background: var(--yellow); }
.budget-fill.exceeded { background: var(--red); }

.budget-text {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

/* Main content */
main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px;
}

/* Cards */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.card-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* Budget Meter (large) */
.budget-meter {
  text-align: center;
  padding: 24px 0;
}

.budget-meter-bar {
  width: 100%;
  height: 16px;
  background: var(--bg-input);
  border-radius: 8px;
  overflow: hidden;
  margin-bottom: 12px;
}

.budget-meter-fill {
  height: 100%;
  border-radius: 8px;
  transition: width 0.5s ease, background-color 0.3s;
}

.budget-remaining {
  font-size: 28px;
  font-weight: 700;
  margin-bottom: 4px;
  font-variant-numeric: tabular-nums;
}

.budget-remaining.ok { color: var(--green); }
.budget-remaining.warning { color: var(--yellow); }
.budget-remaining.exceeded { color: var(--red); }

.budget-subtitle {
  font-size: 13px;
  color: var(--text-muted);
}

/* Stats grid */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.stat-card {
  background: var(--bg-input);
  border-radius: var(--radius);
  padding: 14px;
  text-align: center;
}

.stat-value {
  font-size: 22px;
  font-weight: 700;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.stat-label {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-top: 2px;
}

/* Tables */
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

th {
  text-align: left;
  padding: 8px 12px;
  font-weight: 600;
  color: var(--text-muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 1px solid var(--border);
}

td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  font-variant-numeric: tabular-nums;
}

tr:last-child td { border-bottom: none; }
tr:hover td { background: rgba(108, 138, 255, 0.04); }

/* Status badges */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.badge-ok, .badge-completed { background: var(--green-dim); color: var(--green); }
.badge-warning, .badge-paused { background: var(--yellow-dim); color: var(--yellow); }
.badge-exceeded, .badge-failed, .badge-stopped { background: var(--red-dim); color: var(--red); }
.badge-running { background: rgba(108, 138, 255, 0.15); color: var(--accent); }
.badge-pending { background: rgba(139, 143, 163, 0.15); color: var(--text-muted); }
.badge-skipped { background: rgba(92, 96, 120, 0.15); color: var(--text-dim); }

/* Progress bar (inline) */
.progress-bar {
  width: 100%;
  height: 8px;
  background: var(--bg-input);
  border-radius: 4px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  border-radius: 4px;
  background: var(--accent);
  transition: width 0.3s ease;
}

.progress-fill.complete { background: var(--green); }
.progress-fill.has-failures { background: var(--orange); }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-input);
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
}

.btn:hover { border-color: var(--accent-dim); background: rgba(108, 138, 255, 0.1); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }

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

.btn-primary:hover { background: #5a78ee; }

.btn-danger {
  border-color: var(--red-dim);
  color: var(--red);
}

.btn-danger:hover { background: rgba(248, 113, 113, 0.1); }

.btn-sm { padding: 4px 10px; font-size: 12px; }

.btn-group {
  display: flex;
  gap: 8px;
}

/* Forms */
.form-group {
  margin-bottom: 14px;
}

.form-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 6px;
}

textarea, input[type="text"], input[type="number"] {
  width: 100%;
  padding: 10px 12px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 13px;
  font-family: 'JetBrains Mono', 'Fira Code', monospace;
  resize: vertical;
}

textarea:focus, input:focus {
  outline: none;
  border-color: var(--accent-dim);
}

input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

.range-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.range-value {
  font-size: 14px;
  font-weight: 600;
  color: var(--accent);
  min-width: 24px;
  text-align: center;
}

/* Batch item list */
.item-list {
  max-height: 400px;
  overflow-y: auto;
}

.item-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}

.item-row:last-child { border-bottom: none; }

.item-status { min-width: 80px; }
.item-prompt {
  flex: 1;
  font-size: 12px;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: 'JetBrains Mono', 'Fira Code', monospace;
}

.item-meta {
  font-size: 11px;
  color: var(--text-dim);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.item-error {
  font-size: 11px;
  color: var(--red);
  margin-top: 2px;
}

/* Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-dim); }

/* Empty state */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-dim);
}

.empty-state-icon {
  font-size: 36px;
  margin-bottom: 12px;
}

.empty-state-text {
  font-size: 14px;
  margin-bottom: 16px;
}

/* Utility */
.text-green { color: var(--green); }
.text-yellow { color: var(--yellow); }
.text-red { color: var(--red); }
.text-muted { color: var(--text-muted); }
.text-mono { font-family: 'JetBrains Mono', 'Fira Code', monospace; }
.mt-12 { margin-top: 12px; }
.mb-16 { margin-bottom: 16px; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }

/* Back link */
.back-link {
  color: var(--text-muted);
  text-decoration: none;
  font-size: 13px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-bottom: 16px;
}

.back-link:hover { color: var(--text); }

/* Modal / form overlay */
.overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
}

.modal {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  width: 100%;
  max-width: 600px;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: var(--shadow);
}

.modal-title {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 20px;
}

/* --- Log Viewer --- */

.log-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 20px;
  background: var(--bg-card);
  border-top: 1px solid var(--border);
  flex-wrap: wrap;
}

.log-filter-input {
  width: 220px;
  padding: 5px 10px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 12px;
  font-family: 'JetBrains Mono', 'Fira Code', monospace;
}

.log-filter-input:focus {
  outline: none;
  border-color: var(--accent-dim);
}

.log-filter-input::placeholder { color: var(--text-dim); }

.log-level-toggles {
  display: flex;
  gap: 4px;
}

.log-level-btn {
  background: var(--bg-input);
  color: var(--text-dim);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 3px 10px;
  font-size: 11px;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.15s;
}

.log-level-btn.active[data-level="info"] { color: var(--accent); border-color: var(--accent-dim); background: rgba(108, 138, 255, 0.1); }
.log-level-btn.active[data-level="warn"] { color: var(--yellow); border-color: var(--yellow-dim); background: rgba(250, 204, 21, 0.08); }
.log-level-btn.active[data-level="error"] { color: var(--red); border-color: var(--red-dim); background: rgba(248, 113, 113, 0.08); }
.log-level-btn.active[data-level="debug"] { color: var(--text-muted); border-color: var(--text-dim); background: rgba(139, 143, 163, 0.08); }

.log-category-filter select {
  background: var(--bg-input);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 4px 8px;
  font-size: 12px;
  font-family: inherit;
  cursor: pointer;
}

.log-category-filter select:focus { outline: none; border-color: var(--accent-dim); }

.log-stream-container {
  background: var(--bg);
  border: 1px solid var(--border);
  border-top: none;
  border-radius: 0 0 var(--radius) var(--radius);
  height: calc(100vh - 250px);
  min-height: 300px;
  overflow-y: auto;
  overflow-x: hidden;
  font-family: 'JetBrains Mono', 'Fira Code', monospace;
  font-size: 12px;
}

.log-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 200px;
}

/* Log row */
.log-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 3px 12px;
  border-bottom: 1px solid rgba(45, 48, 64, 0.5);
  line-height: 1.5;
  transition: background 0.1s;
}

.log-row:hover { background: rgba(108, 138, 255, 0.04); }

.log-row.log-flash {
  animation: log-flash-in 0.4s ease-out;
}

@keyframes log-flash-in {
  0% { background: rgba(108, 138, 255, 0.12); }
  100% { background: transparent; }
}

.log-ts {
  color: var(--text-dim);
  white-space: nowrap;
  flex-shrink: 0;
  min-width: 90px;
}

.log-badge {
  font-size: 9px;
  font-weight: 700;
  text-transform: uppercase;
  padding: 1px 5px;
  border-radius: 3px;
  flex-shrink: 0;
  min-width: 38px;
  text-align: center;
  line-height: 1.6;
}

.log-badge-info { color: var(--accent); background: rgba(108, 138, 255, 0.15); }
.log-badge-warn { color: var(--yellow); background: rgba(250, 204, 21, 0.12); }
.log-badge-error { color: var(--red); background: rgba(248, 113, 113, 0.12); }
.log-badge-debug { color: var(--text-dim); background: rgba(92, 96, 120, 0.15); }

.log-cat {
  color: var(--green);
  flex-shrink: 0;
  min-width: 54px;
  max-width: 80px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.log-msg {
  color: var(--text);
  flex-shrink: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.log-meta {
  color: var(--text-dim);
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: pointer;
  min-width: 0;
}

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

.log-expanded .log-meta {
  white-space: pre-wrap;
  word-break: break-all;
  overflow: visible;
}

.log-expanded .log-msg {
  white-space: pre-wrap;
  word-break: break-all;
  overflow: visible;
}

.log-jump-btn {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 16px;
  padding: 8px 16px;
  font-size: 12px;
  font-family: inherit;
  cursor: pointer;
  box-shadow: var(--shadow);
  display: none;
  z-index: 10;
}

.log-jump-btn:hover { background: #5a78ee; }

#log-pause-btn.active {
  color: var(--yellow);
  border-color: var(--yellow-dim);
}

/* Tab group */
.tab-group {
  display: flex;
  gap: 4px;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 8px;
}

.tab-group .tab {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid transparent;
  border-radius: var(--radius);
  padding: 6px 14px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  font-family: inherit;
}

.tab-group .tab:hover {
  color: var(--text);
  background: var(--bg-input);
}

.tab-group .tab.active {
  color: var(--text);
  background: var(--accent-dim);
  border-color: var(--accent-dim);
}

/* Cost bar (horizontal) */
.cost-bar {
  height: 8px;
  background: var(--bg-input);
  border-radius: 4px;
  overflow: hidden;
}

.cost-bar-fill {
  height: 100%;
  border-radius: 4px;
  background: var(--green);
  opacity: 0.6;
  transition: width 0.3s ease;
}

/* Toggle switch */
.toggle-switch {
  position: relative;
  display: inline-block;
  width: 36px;
  height: 20px;
}

.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-slider {
  position: absolute;
  cursor: pointer;
  top: 0; left: 0; right: 0; bottom: 0;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 10px;
  transition: all 0.2s;
}

.toggle-slider:before {
  content: '';
  position: absolute;
  height: 14px;
  width: 14px;
  left: 2px;
  bottom: 2px;
  background: var(--text-dim);
  border-radius: 50%;
  transition: all 0.2s;
}

.toggle-switch input:checked + .toggle-slider {
  background: var(--accent-dim);
  border-color: var(--accent);
}

.toggle-switch input:checked + .toggle-slider:before {
  transform: translateX(16px);
  background: var(--accent);
}

@media (max-width: 768px) {
  main { padding: 16px; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .budget-bar { width: 80px; }
  .log-stream-container { height: calc(100vh - 300px); }
  .log-filter-input { width: 160px; }
  .log-cat { display: none; }
}
