/* ══════════════════════════════════════════════════════════════════════
   Scenario Playground — Styles
   Dark theme, CSS custom properties, no external dependencies
   ══════════════════════════════════════════════════════════════════════ */

/* ── Variables ───────────────────────────────────────────────────────── */
:root {
  --bg:          #0f1117;
  --surface:     #1a1d27;
  --surface-2:   #242736;
  --surface-3:   #2e3348;
  --border:      #2e3348;
  --primary:     #6366f1;
  --primary-dim: #4f52c8;
  --success:     #22c55e;
  --warning:     #f59e0b;
  --danger:      #ef4444;
  --info:        #38bdf8;
  --text:        #e2e8f0;
  --text-muted:  #64748b;
  --text-dim:    #94a3b8;
  --radius:      8px;
  --radius-sm:   4px;
  --font:        'Segoe UI', system-ui, -apple-system, sans-serif;
  --font-mono:   'Cascadia Code', 'Fira Code', 'Consolas', monospace;

  /* Stage colours */
  --idle:    #334155;
  --running: #6366f1;
  --success-stage: #22c55e;
  --retry:   #f59e0b;
  --failed:  #ef4444;

  --navbar-h: 52px;
  --sidebar-w: 250px;
  --queue-h: 220px;
}

/* ── Reset ───────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
  display: flex;
  flex-direction: column;
}

/* ── Navbar ──────────────────────────────────────────────────────────── */
.navbar {
  height: var(--navbar-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 1rem;
  gap: 1rem;
  flex-shrink: 0;
  z-index: 100;
}
.navbar__brand { display: flex; align-items: center; gap: .5rem; flex: 1; }
.navbar__icon  { font-size: 1.2rem; }
.navbar__title { font-size: 15px; font-weight: 700; color: var(--text); }
.navbar__subtitle {
  font-size: 11px; color: var(--text-muted);
  border-left: 1px solid var(--border); padding-left: .5rem; margin-left: .25rem;
}
.navbar__controls { display: flex; align-items: center; gap: .75rem; }

/* Mode toggle */
.mode-toggle {
  display: flex; align-items: center; gap: .4rem;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 20px; padding: .25rem .75rem; cursor: pointer;
  user-select: none; transition: background .2s;
}
.mode-toggle:hover { background: var(--surface-3); }
.mode-toggle__dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--text-muted); transition: background .3s;
}
.mode-toggle.live .mode-toggle__dot { background: var(--success); }
.mode-toggle__label { font-size: 11px; font-weight: 700; letter-spacing: .05em; color: var(--text-dim); }
.mode-toggle.live .mode-toggle__label { color: var(--success); }

/* API URL input */
.api-url-wrap {
  display: flex; align-items: center; gap: .4rem;
}
.api-url-input {
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text);
  padding: .3rem .6rem; font-size: 12px; font-family: var(--font-mono);
  width: 220px; outline: none;
}
.api-url-input:focus { border-color: var(--primary); }
.api-status { font-size: 16px; color: var(--text-muted); cursor: default; }
.api-status.connected { color: var(--success); }
.api-status.error { color: var(--danger); }

/* ── Buttons ─────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: .4rem;
  border: none; border-radius: var(--radius-sm);
  padding: .35rem .8rem; font-size: 12px; font-weight: 600;
  cursor: pointer; transition: background .15s, opacity .15s; white-space: nowrap;
}
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn--primary  { background: var(--primary); color: #fff; }
.btn--primary:hover:not(:disabled) { background: var(--primary-dim); }
.btn--ghost    { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); }
.btn--ghost:hover:not(:disabled) { background: var(--surface-3); }
.btn--danger   { background: var(--danger); color: #fff; }
.btn--danger:hover:not(:disabled) { background: #c53030; }
.btn--sm  { padding: .25rem .6rem; font-size: 11px; }
.btn--icon { min-width: 34px; justify-content: center; }

/* ── Layout ──────────────────────────────────────────────────────────── */
.layout {
  display: flex;
  flex: 1;
  height: calc(100vh - var(--navbar-h) - var(--queue-h));
  overflow: hidden;
}

/* ── Sidebar ─────────────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: .75rem;
  gap: .5rem;
  overflow-y: auto;
  flex-shrink: 0;
}
.sidebar__controls {
  display: flex; flex-wrap: wrap; gap: .4rem;
  padding-bottom: .75rem; border-bottom: 1px solid var(--border);
}
.sidebar__section-title {
  font-size: 10px; font-weight: 700; letter-spacing: .08em;
  color: var(--text-muted); padding: .25rem 0;
}
.speed-wrap { display: flex; align-items: center; gap: .4rem; margin-left: auto; }
.speed-label { font-size: 11px; color: var(--text-muted); }
.speed-select {
  background: var(--surface-2); border: 1px solid var(--border);
  color: var(--text); border-radius: var(--radius-sm); padding: .25rem .4rem;
  font-size: 11px; cursor: pointer;
}

/* Scenario list */
.scenario-list { list-style: none; display: flex; flex-direction: column; gap: .25rem; }
.scenario-item {
  display: flex; align-items: center; gap: .5rem;
  padding: .5rem .6rem; border-radius: var(--radius-sm);
  cursor: pointer; transition: background .15s;
  border: 1px solid transparent;
}
.scenario-item:hover { background: var(--surface-2); }
.scenario-item.active { background: rgba(99,102,241,.15); border-color: var(--primary); }
.scenario-item__icon { font-size: 14px; flex-shrink: 0; }
.scenario-item__name { flex: 1; font-weight: 500; font-size: 12px; }
.scenario-item__tag {
  font-size: 10px; padding: .1rem .35rem; border-radius: 3px;
  background: var(--surface-3); color: var(--text-muted);
}

/* Filter chips */
.filter-chips { display: flex; flex-wrap: wrap; gap: .3rem; }
.chip {
  font-size: 10px; padding: .2rem .5rem; border-radius: 10px;
  background: var(--surface-2); color: var(--text-muted);
  border: 1px solid var(--border); cursor: pointer; transition: all .15s;
}
.chip:hover { border-color: var(--primary); color: var(--text); }
.chip--active { background: rgba(99,102,241,.2); border-color: var(--primary); color: var(--primary); }

/* ── Main content ────────────────────────────────────────────────────── */
.main {
  flex: 1; overflow-y: auto;
  display: flex; flex-direction: column; gap: .5px;
}

/* Panels */
.panel {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: .75rem 1rem;
}
.panel__header {
  display: flex; align-items: center; gap: .75rem;
  margin-bottom: .75rem;
}
.panel__title { font-size: 12px; font-weight: 700; letter-spacing: .05em; color: var(--text-dim); }
.config-actions { display: flex; gap: .4rem; margin-left: auto; }

/* Run badge */
.run-badge {
  font-size: 10px; font-family: var(--font-mono);
  background: var(--surface-3); color: var(--text-muted);
  padding: .15rem .5rem; border-radius: 3px;
}

/* ── Pipeline Visualization ──────────────────────────────────────────── */
.pipeline-panel { flex-shrink: 0; }
.pipeline-container { display: flex; flex-direction: column; gap: .75rem; }
.pipeline-row {
  display: flex; align-items: center; gap: 0; flex-wrap: nowrap; overflow-x: auto;
  padding-bottom: .25rem;
}

/* Stage card */
.stage-card {
  position: relative;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  width: 96px; min-height: 80px;
  background: var(--surface-2); border: 2px solid var(--idle);
  border-radius: var(--radius); padding: .5rem .4rem;
  transition: border-color .3s, box-shadow .3s;
  flex-shrink: 0;
}
.stage-card__icon { font-size: 20px; line-height: 1; }
.stage-card__name { font-size: 10px; font-weight: 600; text-align: center; margin-top: .25rem; color: var(--text-dim); }
.stage-card__count {
  font-size: 11px; font-weight: 700; margin-top: .2rem;
  color: var(--text-muted); font-family: var(--font-mono);
}
.stage-card__status-dot {
  position: absolute; top: 5px; right: 5px;
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--idle);
}

/* Stage states */
.stage-card--idle    { border-color: var(--idle); }
.stage-card--running { border-color: var(--running); animation: pulse-ring 1.2s infinite; }
.stage-card--success { border-color: var(--success-stage); }
.stage-card--retry   { border-color: var(--retry); }
.stage-card--failed  { border-color: var(--failed); }

.stage-card--running .stage-card__status-dot  { background: var(--running); }
.stage-card--success .stage-card__status-dot  { background: var(--success-stage); }
.stage-card--retry   .stage-card__status-dot  { background: var(--retry); }
.stage-card--failed  .stage-card__status-dot  { background: var(--failed); }

/* Connectors between stages */
.stage-connector {
  position: relative; width: 32px; height: 2px;
  background: var(--border); flex-shrink: 0; align-self: center;
}
.stage-connector::after {
  content: '';
  position: absolute; right: -4px; top: -3px;
  border: 4px solid transparent; border-left-color: var(--border);
}
.stage-connector.active { background: var(--primary); }
.stage-connector.active::after { border-left-color: var(--primary); }

/* Flow particles */
.flow-particle {
  position: absolute; top: -4px; left: 0;
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--primary); opacity: 0;
  animation: flow-anim .7s ease-in forwards;
}
@keyframes flow-anim {
  0%   { left: 0;    opacity: 1; }
  80%  { left: 22px; opacity: 1; }
  100% { left: 32px; opacity: 0; }
}

/* Fan-out row */
.fanout-row {
  display: flex; align-items: flex-start; gap: 1rem;
  padding: .5rem 0 0 48px;
}
.fanout-label {
  font-size: 10px; color: var(--text-muted); margin-bottom: .3rem; text-align: center;
}
.fanout-channel {
  display: flex; flex-direction: column; align-items: center; gap: .25rem;
}
.fanout-channel .stage-card { width: 72px; min-height: 60px; }
.fanout-channel .stage-card__icon { font-size: 16px; }
.fanout-line {
  width: 2px; height: 20px;
  background: var(--border); margin: 0 auto;
}
.fanout-line.active { background: var(--primary); }

/* Pipeline log */
.pipeline-log {
  height: 52px; overflow-y: auto;
  background: var(--bg); border-radius: var(--radius-sm);
  border: 1px solid var(--border); padding: .4rem .6rem;
  margin-top: .5rem; font-family: var(--font-mono); font-size: 11px;
}
.log-line { padding: .1rem 0; }
.log-line--info    { color: var(--text-dim); }
.log-line--success { color: var(--success); }
.log-line--warn    { color: var(--warning); }
.log-line--error   { color: var(--danger); }

/* Animations */
@keyframes pulse-ring {
  0%   { box-shadow: 0 0 0 0   rgba(99,102,241,.6); }
  70%  { box-shadow: 0 0 0 6px rgba(99,102,241,0);  }
  100% { box-shadow: 0 0 0 0   rgba(99,102,241,0);  }
}
@keyframes fade-in-up {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── Config Panel ────────────────────────────────────────────────────── */
.config-panel { flex: 1; }
.config-empty { color: var(--text-muted); font-style: italic; padding: .5rem 0; }
.config-body  { display: flex; flex-direction: column; gap: .75rem; }

.config-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: .75rem;
}
.config-card {
  background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--radius); padding: .6rem .75rem;
}
.config-card__label {
  font-size: 10px; font-weight: 700; letter-spacing: .06em;
  color: var(--text-muted); margin-bottom: .4rem;
}
.config-card__value { color: var(--text-dim); font-size: 12px; line-height: 1.5; }
.config-card__value code {
  font-family: var(--font-mono); font-size: 11px;
  background: var(--surface-3); padding: .1rem .3rem; border-radius: 3px;
}
.rule-tag {
  display: inline-block; font-size: 10px;
  background: rgba(99,102,241,.15); color: var(--primary);
  border: 1px solid rgba(99,102,241,.3);
  padding: .1rem .4rem; border-radius: 3px; margin: .15rem;
}
.action-tag {
  display: inline-flex; align-items: center; gap: .3rem;
  font-size: 11px; padding: .2rem .5rem; border-radius: 3px;
  font-weight: 600; margin: .15rem;
}
.action-tag--email   { background: rgba(56,189,248,.15); color: var(--info); }
.action-tag--sms     { background: rgba(34,197,94,.15);  color: var(--success); }
.action-tag--webhook { background: rgba(245,158,11,.15); color: var(--warning); }
.action-tag--push    { background: rgba(99,102,241,.15); color: var(--primary); }

/* Live config fields */
.live-field {
  display: flex; align-items: center; gap: .5rem; flex-wrap: wrap;
}
.live-field label { font-size: 11px; color: var(--text-muted); min-width: 110px; }
.live-field input {
  background: var(--surface-2); border: 1px solid var(--border);
  color: var(--text); border-radius: var(--radius-sm); padding: .25rem .5rem;
  font-size: 12px; width: 120px;
}
.live-field input:focus { outline: none; border-color: var(--primary); }

/* ── Queue Monitor ───────────────────────────────────────────────────── */
.queue-panel {
  height: var(--queue-h);
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex; flex-direction: column;
  flex-shrink: 0;
}
.queue-panel__header {
  display: flex; align-items: center; gap: .75rem;
  padding: .5rem .75rem; border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.queue-tabs { display: flex; gap: .25rem; }
.queue-tab {
  background: none; border: none; color: var(--text-muted);
  padding: .3rem .6rem; border-radius: var(--radius-sm);
  cursor: pointer; font-size: 12px; font-weight: 600;
  border-bottom: 2px solid transparent; transition: color .15s;
}
.queue-tab:hover { color: var(--text); }
.queue-tab--active { color: var(--primary); border-bottom-color: var(--primary); }
.queue-controls { display: flex; align-items: center; gap: .5rem; margin-left: auto; }
.filter-select {
  background: var(--surface-2); border: 1px solid var(--border);
  color: var(--text); border-radius: var(--radius-sm); padding: .25rem .5rem;
  font-size: 11px; cursor: pointer;
}
.queue-content { flex: 1; overflow: hidden; }
.queue-table-wrap { height: 100%; overflow-y: auto; }

/* Queue table */
.queue-table {
  width: 100%; border-collapse: collapse; font-size: 11px;
}
.queue-table thead th {
  background: var(--surface-2); color: var(--text-muted);
  padding: .35rem .6rem; text-align: left; font-weight: 600;
  font-size: 10px; letter-spacing: .04em;
  position: sticky; top: 0; z-index: 1;
  border-bottom: 1px solid var(--border);
}
.queue-table tbody tr {
  border-bottom: 1px solid rgba(46,51,72,.5);
  transition: background .1s;
}
.queue-table tbody tr:hover { background: var(--surface-2); }
.queue-table td { padding: .3rem .6rem; color: var(--text-dim); font-family: var(--font-mono); }

/* Status badges */
.status-badge {
  display: inline-block; font-size: 10px; font-weight: 600;
  padding: .15rem .45rem; border-radius: 3px;
}
.status-badge--pending    { background: rgba(100,116,139,.2); color: var(--text-muted); }
.status-badge--inprogress { background: rgba(99,102,241,.2);  color: var(--primary); }
.status-badge--completed  { background: rgba(34,197,94,.2);   color: var(--success); }
.status-badge--failed     { background: rgba(239,68,68,.2);   color: var(--danger); }
.status-badge--sent       { background: rgba(34,197,94,.2);   color: var(--success); }

/* Queue empty */
.queue-empty {
  display: flex; align-items: center; justify-content: center;
  height: 100%; color: var(--text-muted); font-style: italic;
}

/* Badge counter */
.badge {
  font-size: 10px; background: var(--surface-3); color: var(--text-muted);
  padding: .1rem .35rem; border-radius: 8px;
}
.badge--active { background: var(--primary); color: #fff; }

/* ── Tutorial overlay ────────────────────────────────────────────────── */
.tutorial-overlay {
  position: fixed; inset: 0; z-index: 1000;
  display: flex; align-items: flex-start; justify-content: flex-end;
  padding: 1rem;
}
.tutorial-backdrop {
  position: absolute; inset: 0;
  background: rgba(0,0,0,.7); backdrop-filter: blur(2px);
}
.tutorial-card {
  position: relative; z-index: 1001;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1.25rem;
  width: 340px; max-height: 280px;
  display: flex; flex-direction: column; gap: .75rem;
  box-shadow: 0 20px 60px rgba(0,0,0,.5);
  animation: fade-in-up .3s ease;
}
.tutorial-progress {
  font-size: 11px; color: var(--text-muted); font-weight: 600;
}
.tutorial-title { font-size: 16px; font-weight: 700; color: var(--text); }
.tutorial-body  { font-size: 13px; color: var(--text-dim); line-height: 1.6; flex: 1; overflow-y: auto; }
.tutorial-footer { display: flex; gap: .5rem; justify-content: flex-end; }

/* Spotlight highlight on tutorial step */
.tutorial-highlight {
  position: relative; z-index: 1002;
  box-shadow: 0 0 0 4px var(--primary), 0 0 30px rgba(99,102,241,.5) !important;
  border-radius: var(--radius);
}

/* ── Modal ───────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0; z-index: 900;
  background: rgba(0,0,0,.7); backdrop-filter: blur(2px);
  display: flex; align-items: center; justify-content: center;
}
.modal {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); width: 600px; max-height: 80vh;
  display: flex; flex-direction: column;
  box-shadow: 0 20px 60px rgba(0,0,0,.5);
  animation: fade-in-up .2s ease;
}
.modal__header {
  display: flex; align-items: center; gap: .75rem;
  padding: .75rem 1rem; border-bottom: 1px solid var(--border);
}
.modal__title  { font-size: 14px; font-weight: 700; flex: 1; }
.modal__close  { background: none; border: none; color: var(--text-muted); font-size: 16px; cursor: pointer; }
.modal__close:hover { color: var(--text); }
.modal__body   { flex: 1; overflow-y: auto; padding: 1rem; }
.modal__footer {
  display: flex; gap: .5rem; justify-content: flex-end;
  padding: .75rem 1rem; border-top: 1px solid var(--border);
}

/* Editor fields */
.editor-section { margin-bottom: 1rem; }
.editor-section__title {
  font-size: 11px; font-weight: 700; color: var(--text-muted);
  letter-spacing: .05em; margin-bottom: .5rem;
}
.editor-field { margin-bottom: .6rem; }
.editor-field label { display: block; font-size: 11px; color: var(--text-muted); margin-bottom: .25rem; }
.editor-field input,
.editor-field textarea {
  width: 100%; background: var(--surface-2); border: 1px solid var(--border);
  color: var(--text); border-radius: var(--radius-sm); padding: .35rem .5rem;
  font-size: 12px; font-family: var(--font-mono);
}
.editor-field input:focus,
.editor-field textarea:focus { outline: none; border-color: var(--primary); }
.editor-field textarea { min-height: 80px; resize: vertical; }

/* Scrollbar */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--surface-3); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--border); }

/* Misc */
.text-success { color: var(--success); }
.text-danger  { color: var(--danger); }
.text-warn    { color: var(--warning); }
.text-muted   { color: var(--text-muted); }
.mono         { font-family: var(--font-mono); }
