/* ==========================================================================
   Iron Mind AI — Orchestrator Dashboard
   See docs/brandbook.md for the design system this file implements.
   ========================================================================== */

:root {
  /* Color system */
  --bg: #0b0d10;
  --bg-elevated: #12151a;
  --bg-elevated-2: #181c22;
  --border: #262b33;
  --border-strong: #333a45;
  --text: #e6e9ee;
  --text-muted: #9aa3af;
  --text-faint: #616a76;
  --accent: #4f8cff;
  --accent-hover: #6b9fff;
  --accent-dim: #1c2b4d;

  --status-running: #4f8cff;
  --status-completed: #3ecf8e;
  --status-failed: #f0555a;
  --status-stopped: #f0a35a;
  --status-orphaned: #8a919c;

  --font-ui: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, "SF Mono", "Cascadia Code", "Fira Code", Consolas, monospace;

  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-pill: 999px;
}

* { box-sizing: border-box; }

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

.hidden { display: none !important; }

button, input, textarea, select {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
}

a { color: var(--accent); }

/* ---------- Buttons ---------- */
.btn {
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-elevated-2);
  color: var(--text);
  padding: 8px 14px;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, opacity 0.15s ease;
}
.btn:hover { border-color: var(--border-strong); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #06090f;
  font-weight: 600;
}
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); border-color: var(--accent-hover); }

.btn-ghost { background: transparent; }

.btn-danger {
  background: transparent;
  border-color: var(--status-failed);
  color: var(--status-failed);
}
.btn-danger:hover { background: rgba(240, 85, 90, 0.1); }

.btn-sm { padding: 5px 10px; font-size: 12.5px; }
.btn-block { width: 100%; }

/* ---------- Auth screen ---------- */
.auth-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.auth-card {
  width: 100%;
  max-width: 360px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 32px 28px;
}
.auth-title { font-size: 18px; font-weight: 600; margin: 0 0 6px; }
.auth-sub { color: var(--text-muted); font-size: 13px; margin: 0 0 20px; }
#auth-form { display: flex; flex-direction: column; gap: 12px; }
#auth-password-input {
  background: var(--bg-elevated-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  color: var(--text);
}
#auth-password-input:focus-visible { outline: 2px solid var(--accent); border-color: var(--accent); }
.auth-error {
  margin-top: 14px;
  color: var(--status-failed);
  font-size: 12.5px;
  background: rgba(240, 85, 90, 0.08);
  border: 1px solid rgba(240, 85, 90, 0.3);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
}

/* ---------- Top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-elevated);
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar-left { display: flex; align-items: center; gap: 10px; }
.brand-dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 8px var(--accent);
}
.brand-title { font-size: 16px; font-weight: 600; margin: 0; }
.brand-sub { color: var(--text-faint); font-size: 12px; }
.topbar-right { display: flex; align-items: center; gap: 12px; }
.health-indicator { color: var(--status-orphaned); font-size: 12px; transition: color 0.2s ease; }
.health-indicator.ok { color: var(--status-completed); }
.health-indicator.down { color: var(--status-failed); }

/* ---------- Layout ---------- */
.layout {
  display: grid;
  grid-template-columns: 360px 1fr;
  gap: 16px;
  padding: 16px;
  align-items: start;
}
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
}

.panel {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px;
}
.panel-title { font-size: 14px; font-weight: 600; margin: 0 0 12px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-muted); }

/* ---------- Launch panel ---------- */
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 12px; color: var(--text-muted); margin-bottom: 6px; font-weight: 600; }

.field input[type="text"],
.field input[type="password"],
.field textarea {
  width: 100%;
  background: var(--bg-elevated-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  color: var(--text);
}
.field input:focus-visible, .field textarea:focus-visible {
  outline: 2px solid var(--accent);
  border-color: var(--accent);
}
.field textarea { resize: vertical; font-family: var(--font-mono); font-size: 12.5px; }

.option-list {
  margin-top: 6px;
  max-height: 160px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-elevated-2);
}
.option-list:empty { display: none; }
.option-item {
  padding: 7px 10px;
  cursor: pointer;
  font-size: 13px;
  border-bottom: 1px solid var(--border);
}
.option-item:last-child { border-bottom: none; }
.option-item:hover, .option-item.active { background: var(--accent-dim); color: var(--accent-hover); }
.option-empty { padding: 8px 10px; color: var(--text-faint); font-size: 12.5px; }

.selected-chip {
  margin-top: 8px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--accent-dim);
  color: var(--accent-hover);
  border: 1px solid var(--accent);
  border-radius: var(--radius-pill);
  padding: 4px 10px;
  font-size: 12.5px;
}

.mode-toggle {
  display: flex;
  gap: 4px;
  background: var(--bg-elevated-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 3px;
  margin-bottom: 14px;
}
.mode-btn {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text-muted);
  padding: 7px 10px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 12.5px;
  font-weight: 600;
}
.mode-btn.active { background: var(--accent); color: #06090f; }

.preset-description {
  font-size: 12.5px;
  color: var(--text-muted);
  background: var(--bg-elevated-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  margin: 0 0 12px;
}

.preset-vars { display: flex; flex-direction: column; gap: 10px; margin-bottom: 4px; }
.preset-var-field label { display: block; font-size: 12px; color: var(--text-muted); margin-bottom: 4px; }
.preset-var-field input {
  width: 100%;
  background: var(--bg-elevated-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 7px 9px;
}

.prompt-preview {
  white-space: pre-wrap;
  word-break: break-word;
  background: var(--bg-elevated-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-muted);
  max-height: 220px;
  overflow-y: auto;
  margin: 0;
}

/* ---------- Runs table ---------- */
.runs-panel-header { display: flex; align-items: center; justify-content: space-between; }
.runs-count { color: var(--text-faint); font-size: 12px; }

.table-wrap { overflow-x: auto; }
.runs-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.runs-table th {
  text-align: left;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  font-size: 11px;
  color: var(--text-faint);
  font-weight: 600;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.runs-table td {
  padding: 9px 10px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
  white-space: nowrap;
}
.runs-table td.prompt-cell {
  white-space: normal;
  max-width: 320px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.runs-table tbody tr { cursor: pointer; transition: background 0.1s ease; }
.runs-table tbody tr:hover { background: var(--bg-elevated-2); }
.runs-table tbody tr.selected { background: var(--accent-dim); }
.empty-row { color: var(--text-faint); text-align: center; padding: 24px !important; white-space: normal !important; }

/* ---------- Status badges ---------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  border-radius: var(--radius-pill);
  padding: 3px 9px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  border: 1px solid transparent;
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-running { color: var(--status-running); background: rgba(79, 140, 255, 0.12); border-color: rgba(79, 140, 255, 0.35); }
.badge-running::before { animation: pulse 1.2s ease-in-out infinite; }
.badge-completed { color: var(--status-completed); background: rgba(62, 207, 142, 0.12); border-color: rgba(62, 207, 142, 0.35); }
.badge-failed { color: var(--status-failed); background: rgba(240, 85, 90, 0.12); border-color: rgba(240, 85, 90, 0.35); }
.badge-stopped { color: var(--status-stopped); background: rgba(240, 163, 90, 0.12); border-color: rgba(240, 163, 90, 0.35); }
.badge-orphaned { color: var(--status-orphaned); background: rgba(138, 145, 156, 0.12); border-color: rgba(138, 145, 156, 0.35); }

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

/* ---------- Detail drawer ---------- */
.detail-drawer {
  position: fixed;
  top: 0; right: 0;
  height: 100vh;
  width: 560px;
  max-width: 92vw;
  background: var(--bg-elevated);
  border-left: 1px solid var(--border);
  box-shadow: -12px 0 32px rgba(0,0,0,0.4);
  z-index: 20;
  display: flex;
  flex-direction: column;
}
.detail-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}
.detail-header-actions { display: flex; gap: 8px; }
.detail-body { padding: 16px; overflow-y: auto; flex: 1; }

.detail-meta {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 16px;
  background: var(--bg-elevated-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  margin-bottom: 16px;
  font-size: 12.5px;
}
.meta-label { display: block; color: var(--text-faint); font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.03em; }
.meta-value { display: block; margin-top: 1px; }

.log-status { font-weight: 400; text-transform: none; letter-spacing: 0; color: var(--text-faint); margin-left: 6px; }

.log-viewer {
  background: var(--bg-elevated-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px;
  max-height: 420px;
  overflow-y: auto;
  font-family: var(--font-mono);
  font-size: 11.5px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.log-line { padding: 4px 6px; border-radius: 4px; border-bottom: 1px solid rgba(255,255,255,0.03); }
.log-line:hover { background: rgba(255,255,255,0.02); }
.log-tag {
  display: inline-block;
  font-weight: 700;
  font-size: 9.5px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 1px 6px;
  border-radius: 3px;
  margin-right: 6px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text-muted);
}
.log-tag-assistant { color: var(--accent-hover); border-color: rgba(79,140,255,0.35); }
.log-tag-user { color: var(--status-completed); border-color: rgba(62,207,142,0.35); }
.log-tag-system { color: var(--status-orphaned); }
.log-tag-result { color: var(--status-stopped); border-color: rgba(240,163,90,0.35); }
.log-tag-error { color: var(--status-failed); border-color: rgba(240,85,90,0.35); }
.log-text { white-space: pre-wrap; word-break: break-word; color: var(--text); }
.log-sub { color: var(--text-faint); }
.log-tool { color: var(--accent-hover); }
.log-raw { color: var(--text-faint); white-space: pre-wrap; word-break: break-word; }

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: var(--bg-elevated-2);
  border: 1px solid var(--status-failed);
  color: var(--text);
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 12.5px;
  max-width: 360px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  z-index: 100;
}
.toast.info { border-color: var(--accent); }
.toast.success { border-color: var(--status-completed); }
