/* Reset */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

/* Base */
body {
  font-family: system-ui, -apple-system, sans-serif;
  background: #0f1117;
  color: #e0e0e0;
  min-height: 100vh;
}

/* Header */
header {
  background: #1a1d27;
  padding: 16px 24px;
  border-bottom: 1px solid #2a2d37;
  display: flex;
  align-items: center;
  gap: 16px;
}

header h1 {
  font-size: 1.4rem;
  color: #fff;
  font-weight: 600;
}

header .subtitle {
  font-size: 0.85rem;
  color: #888;
}

/* Alert Banner */
.alert-banner {
  background: #dc2626;
  color: #fff;
  padding: 12px 24px;
  font-weight: 600;
  text-align: center;
  font-size: 0.95rem;
  animation: pulse 2s ease-in-out infinite;
}

.alert-banner.hidden {
  display: none;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.7; }
}

/* Status Bar */
.status-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0;
  background: #1a1d27;
  border-bottom: 1px solid #2a2d37;
  padding: 8px 24px;
}

.status-item {
  display: flex;
  flex-direction: column;
  padding: 8px 16px;
  min-width: 120px;
}

.status-item label {
  font-size: 0.7rem;
  text-transform: uppercase;
  color: #888;
  letter-spacing: 0.05em;
  margin-bottom: 4px;
}

.status-item span {
  font-size: 1rem;
  font-weight: 500;
  color: #e0e0e0;
}

/* Status bar actions (refresh button) */
.status-bar-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  padding: 0 8px;
}

.refresh-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  background: #23263a;
  border: 1px solid #2a2d37;
  color: #a0a0b0;
  font-size: 0.82rem;
  font-weight: 500;
  padding: 6px 14px;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  white-space: nowrap;
}

.refresh-btn:hover {
  background: #2a2d45;
  color: #e0e0e0;
  border-color: #3a3d57;
}

.refresh-btn:active {
  background: #1a1d27;
}

.refresh-icon {
  font-size: 1rem;
  line-height: 1;
  display: inline-block;
  transition: transform 0.4s ease;
}

.refresh-btn.spinning .refresh-icon {
  animation: spin 0.5s linear;
}

@keyframes spin {
  from { transform: rotate(0deg); }
  to   { transform: rotate(360deg); }
}

/* State color classes */
.state-sleeping { color: #facc15; }
.state-waking   { color: #38bdf8; }
.state-running  { color: #4ade80; }
.state-dead     { color: #ef4444; }
.state-unknown  { color: #888; }

/* Tier color classes */
.tier-normal       { color: #4ade80; }
.tier-low_compute  { color: #facc15; }
.tier-critical     { color: #ef4444; }
.tier-dead         { color: #ef4444; }

/* Process indicator */
.process-alive { color: #4ade80; }
.process-dead  { color: #ef4444; }

/* Tab navigation */
.tab-nav {
  display: flex;
  gap: 0;
  background: #13151f;
  border-bottom: 1px solid #2a2d37;
  padding: 0 24px;
  overflow-x: auto;
  scrollbar-width: none;
}

.tab-nav::-webkit-scrollbar {
  display: none;
}

.tab-btn {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: #888;
  font-size: 0.9rem;
  font-weight: 500;
  padding: 12px 18px;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
  white-space: nowrap;
  outline: none;
}

.tab-btn:hover {
  color: #c0c0d0;
  background: rgba(255,255,255,0.03);
}

.tab-btn.active {
  color: #fff;
  border-bottom-color: #6366f1;
}

/* Tab panels */
.tab-panel {
  display: block;
}

.tab-panel.hidden {
  display: none;
}

/* Main content */
main {
  padding: 24px;
}

/* Overview grid */
.overview-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 16px;
}

/* Panel card */
.panel {
  background: #1a1d27;
  border: 1px solid #2a2d37;
  border-radius: 8px;
  overflow: hidden;
}

.panel-header {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #888;
  font-weight: 600;
  padding: 10px 16px;
  border-bottom: 1px solid #2a2d37;
}

.panel-body {
  padding: 16px;
}

.muted {
  color: #666;
  font-size: 0.9rem;
  line-height: 1.5;
}

/* Stat rows */
.stat-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 0;
  border-bottom: 1px solid #1f2235;
  font-size: 0.9rem;
}

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

.stat-label {
  color: #888;
}

/* Coming soon placeholders */
.coming-soon {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 80px 24px;
  text-align: center;
  gap: 12px;
}

.coming-soon-icon {
  font-size: 3rem;
  opacity: 0.4;
}

.coming-soon-title {
  font-size: 1.3rem;
  font-weight: 600;
  color: #c0c0c0;
}

.coming-soon-desc {
  font-size: 0.9rem;
  color: #666;
  max-width: 420px;
  line-height: 1.5;
}

/* Control panel */
#control-panel {
  padding: 16px 24px;
  display: flex;
  gap: 12px;
  align-items: center;
  background: #1a1d27;
  border-bottom: 1px solid #2a2d37;
}

/* Control buttons */
.btn {
  padding: 10px 24px;
  border: none;
  border-radius: 6px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, opacity 0.2s;
}

.btn-start {
  background: #22c55e;
  color: #fff;
}

.btn-start:hover:not(:disabled) {
  background: #16a34a;
}

.btn-stop {
  background: #ef4444;
  color: #fff;
}

.btn-stop:hover:not(:disabled) {
  background: #dc2626;
}

.btn:disabled,
.btn-disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* --- Conversations --- */
.turn { border: 1px solid #333; border-radius: 6px; margin-bottom: 8px; overflow: hidden; }
.turn-header { display: flex; align-items: center; gap: 12px; padding: 10px 14px; cursor: pointer; background: #1a1a2e; transition: background 0.2s; }
.turn-header:hover { background: #222244; }
.turn-header.expanded { background: #222244; border-bottom: 1px solid #333; }
.expand-icon { font-size: 10px; color: #888; width: 14px; }
.turn-time { color: #4fc3f7; font-size: 13px; }
.turn-state { color: #888; font-size: 12px; }
.turn-tools { color: #aaa; font-size: 12px; }
.turn-cost { color: #888; font-size: 12px; margin-left: auto; }
.turn-detail { padding: 14px; background: #0d1117; }
.turn-section { margin-bottom: 12px; }
.turn-section > label { display: block; font-size: 11px; color: #888; text-transform: uppercase; margin-bottom: 4px; }
.thinking-block { white-space: pre-wrap; word-break: break-word; max-height: 400px; overflow-y: auto; font-size: 13px; color: #e0e0e0; background: #16213e; padding: 10px; border-radius: 4px; }
.tool-call { border: 1px solid #2a2a4a; border-radius: 4px; margin-bottom: 6px; }
.tool-call-header { display: flex; align-items: center; gap: 8px; padding: 8px 10px; cursor: pointer; background: #16213e; font-size: 13px; }
.tool-call-header:hover { background: #1a2540; }
.tool-call-header.expanded { border-bottom: 1px solid #2a2a4a; }
.tool-name { color: #4fc3f7; font-weight: 600; }
.tool-duration { color: #888; font-size: 11px; }
.tool-error { color: #ff5252; font-size: 11px; font-weight: 600; }
.tool-call-detail { padding: 10px; background: #0d1117; }
.tool-section { margin-bottom: 8px; }
.tool-section > label { display: block; font-size: 10px; color: #666; text-transform: uppercase; margin-bottom: 2px; }
.tool-section pre { white-space: pre-wrap; word-break: break-word; max-height: 300px; overflow-y: auto; font-size: 12px; color: #ccc; background: #111; padding: 8px; border-radius: 4px; }
.error-text { color: #ff5252; }
.pagination { display: flex; align-items: center; justify-content: center; gap: 16px; padding: 12px 0; }
.page-btn { background: #16213e; color: #4fc3f7; border: 1px solid #333; border-radius: 4px; padding: 6px 14px; cursor: pointer; font-size: 13px; }
.page-btn:hover:not(:disabled) { background: #222244; }
.page-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.page-info { color: #888; font-size: 13px; }
.empty-state { text-align: center; padding: 40px; color: #666; font-size: 14px; }

/* --- Config Tab --- */
.config-toolbar { display: flex; gap: 8px; margin-bottom: 12px; }
.btn-sm { padding: 6px 14px; font-size: 12px; border-radius: 4px; border: 1px solid #333; background: #16213e; color: #e0e0e0; cursor: pointer; }
.btn-sm:hover { background: #222244; }
.btn-primary { background: #1565c0; border-color: #1565c0; color: #fff; }
.btn-primary:hover { background: #1976d2; }
.btn-sm.active { background: #c62828; border-color: #c62828; color: #fff; }
.config-section { margin-bottom: 16px; border: 1px solid #333; border-radius: 6px; overflow: hidden; }
.config-section h3 { padding: 8px 14px; background: #1a1a2e; font-size: 13px; color: #4fc3f7; border-bottom: 1px solid #333; }
.config-fields { padding: 10px 14px; }
.config-field { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; }
.config-field label { width: 200px; font-size: 12px; color: #888; flex-shrink: 0; }
.config-field input { flex: 1; background: #0d1117; border: 1px solid #333; border-radius: 4px; padding: 6px 10px; color: #e0e0e0; font-size: 13px; font-family: monospace; }
.config-field input[readonly] { opacity: 0.5; }
.sensitive-section { border-color: #c62828; }
.sensitive-section h3 { background: #2a0a0a; color: #ff5252; }
.toast { padding: 8px 16px; border-radius: 4px; font-size: 13px; margin-bottom: 10px; }
.toast-success { background: #1b5e20; color: #a5d6a7; }
.toast-error { background: #b71c1c; color: #ef9a9a; }

/* --- Soul Tab --- */
.soul-toolbar { display: flex; gap: 8px; margin-bottom: 10px; }
.soul-editor { width: 100%; min-height: 400px; background: #0d1117; border: 1px solid #333; border-radius: 6px; padding: 14px; color: #e0e0e0; font-size: 14px; font-family: 'Courier New', monospace; line-height: 1.6; resize: vertical; }

/* --- Heartbeat Tab --- */
.heartbeat-table { width: 100%; border-collapse: collapse; }
.heartbeat-table th { text-align: left; padding: 8px 12px; background: #1a1a2e; color: #4fc3f7; font-size: 12px; text-transform: uppercase; border-bottom: 1px solid #333; }
.heartbeat-table td { padding: 8px 12px; border-bottom: 1px solid #222; font-size: 13px; color: #e0e0e0; }
.task-name { font-weight: 600; }
.task-cron code { color: #4fc3f7; font-size: 12px; }
.task-last-run { color: #888; font-size: 12px; }
.task-run-count { color: #888; text-align: center; }
.toggle { position: relative; display: inline-block; width: 36px; height: 20px; }
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle-slider { position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; background: #333; border-radius: 20px; transition: 0.3s; }
.toggle-slider::before { content: ""; position: absolute; height: 14px; width: 14px; left: 3px; bottom: 3px; background: #888; border-radius: 50%; transition: 0.3s; }
.toggle input:checked + .toggle-slider { background: #1565c0; }
.toggle input:checked + .toggle-slider::before { transform: translateX(16px); background: #fff; }
