/* ==========================================================================
   SIGNALFORGE — design tokens
   ========================================================================== */
:root {
  --bg: #0A0E17;
  --bg-panel: #10151F;
  --bg-panel-raised: #141B29;
  --grid-line: rgba(76, 243, 214, 0.07);
  --border: rgba(124, 135, 152, 0.16);
  --border-bright: rgba(76, 243, 214, 0.35);

  --text: #E7ECF3;
  --text-dim: #8791A3;
  --text-faint: #566175;

  --cyan: #4CF3D6;
  --violet: #8B5CF6;
  --magenta: #FF3D81;
  --amber: #FFB347;

  --grad-signal: linear-gradient(90deg, var(--cyan), var(--violet));

  --font-display: "Chakra Petch", "Inter", sans-serif;
  --font-body: "Inter", sans-serif;
  --font-mono: "JetBrains Mono", monospace;

  --radius-s: 6px;
  --radius-m: 12px;
  --radius-l: 18px;

  --ease: cubic-bezier(.16,.84,.44,1);
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; transition-duration: 0.001ms !important; }
}

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

body {
  background:
    radial-gradient(ellipse 1200px 600px at 15% -10%, rgba(139,92,246,0.10), transparent 60%),
    radial-gradient(ellipse 900px 500px at 100% 0%, rgba(76,243,214,0.08), transparent 55%),
    var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  background-attachment: fixed;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(var(--grid-line) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-line) 1px, transparent 1px);
  background-size: 42px 42px;
  mask-image: radial-gradient(ellipse 80% 60% at 50% 0%, black, transparent 75%);
  z-index: 0;
}

.scanlines {
  position: fixed; inset: 0; pointer-events: none; z-index: 60;
  background: repeating-linear-gradient(180deg, rgba(255,255,255,0.012) 0px, rgba(255,255,255,0.012) 1px, transparent 1px, transparent 3px);
  opacity: 0.5;
}

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

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

/* ==========================================================================
   Topbar
   ========================================================================== */
.topbar {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 20px;
  background: rgba(10,14,23,0.82);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; font-family: var(--font-display); font-weight: 600; letter-spacing: 0.04em; font-size: 17px; }
.brand-mark {
  width: 20px; height: 20px; border-radius: 50%;
  background: conic-gradient(var(--cyan), var(--violet), var(--magenta), var(--cyan));
  box-shadow: 0 0 14px rgba(76,243,214,0.5);
  position: relative;
}
.brand-mark::after { content:""; position:absolute; inset:5px; background: var(--bg); border-radius:50%; }
.brand-text em { font-style: normal; color: var(--cyan); }

.topbar-right { display: flex; align-items: center; gap: 8px; }

.mode-pill {
  display: flex; align-items: center; gap: 8px;
  background: var(--bg-panel-raised); border: 1px solid var(--border);
  border-radius: 999px; padding: 6px 14px; font-size: 12.5px; color: var(--text-dim);
  cursor: pointer; transition: border-color .2s var(--ease);
}
.mode-pill:hover { border-color: var(--border-bright); }
.mode-pill .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--amber); box-shadow: 0 0 8px var(--amber); }
.mode-pill .dot.live { background: var(--cyan); box-shadow: 0 0 8px var(--cyan); }

.icon-btn {
  width: 36px; height: 36px; display: grid; place-items: center;
  background: var(--bg-panel-raised); border: 1px solid var(--border); border-radius: var(--radius-s);
  color: var(--text-dim); cursor: pointer; transition: all .2s var(--ease);
}
.icon-btn:hover { color: var(--cyan); border-color: var(--border-bright); }

/* ==========================================================================
   Stage rail — signature "signal chain" element
   ========================================================================== */
.stage-rail {
  position: relative; z-index: 5;
  padding: 18px 14px;
  overflow-x: auto;
}
.chain {
  list-style: none; margin: 0; padding: 0;
  display: flex; gap: 6px; align-items: center;
}
.chain-node {
  flex: 1 0 auto;
  display: flex; align-items: center; gap: 8px;
  font-family: var(--font-mono); font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--text-faint);
  padding: 8px 10px;
  white-space: nowrap;
  position: relative;
}
.chain-node:not(:last-child)::after {
  content: ""; position: absolute; right: -3px; top: 50%; width: 14px; height: 1px;
  background: var(--border);
}
.node-dot {
  width: 9px; height: 9px; border-radius: 50%; background: var(--bg-panel-raised);
  border: 1.5px solid var(--border); flex-shrink: 0; transition: all .3s var(--ease);
}
.chain-node.done .node-dot { background: var(--cyan); border-color: var(--cyan); box-shadow: 0 0 8px rgba(76,243,214,0.7); }
.chain-node.active .node-dot { background: var(--violet); border-color: var(--violet); box-shadow: 0 0 10px rgba(139,92,246,0.8); animation: pulse-dot 1.4s ease-in-out infinite; }
.chain-node.error .node-dot { background: var(--magenta); border-color: var(--magenta); box-shadow: 0 0 8px rgba(255,61,129,0.7); }
.chain-node.done, .chain-node.active { color: var(--text); }
.chain-node.error { color: var(--magenta); }

@keyframes pulse-dot { 0%,100% { transform: scale(1); } 50% { transform: scale(1.35); } }

/* ==========================================================================
   Layout
   ========================================================================== */
.app-main {
  position: relative; z-index: 1;
  max-width: 900px; margin: 0 auto;
  padding: 6px 16px 80px;
  display: flex; flex-direction: column; gap: 18px;
}

.panel {
  background: linear-gradient(180deg, var(--bg-panel-raised), var(--bg-panel));
  border: 1px solid var(--border);
  border-radius: var(--radius-l);
  padding: 22px;
  animation: rise .5s var(--ease) both;
}
@keyframes rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

.panel-title {
  font-family: var(--font-display); font-weight: 600; font-size: 20px; margin: 0 0 4px;
  letter-spacing: 0.01em;
}
.panel-sub { color: var(--text-dim); font-size: 13.5px; margin: 0 0 18px; line-height: 1.5; }
.panel-hint { color: var(--text-faint); font-size: 12.5px; margin-top: 8px; }

/* ==========================================================================
   Form
   ========================================================================== */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.field label { font-size: 12.5px; color: var(--text-dim); font-weight: 500; display: flex; justify-content: space-between; }
.field .unit { color: var(--cyan); font-family: var(--font-mono); }

input[type="text"], input[type="url"], textarea, select {
  background: rgba(6,9,15,0.6);
  border: 1px solid var(--border);
  border-radius: var(--radius-s);
  padding: 11px 13px;
  font-size: 14.5px;
  color: var(--text);
  outline: none;
  transition: border-color .2s var(--ease), box-shadow .2s var(--ease);
  width: 100%;
}
input[type="text"]:focus, input[type="url"]:focus, textarea:focus, select:focus {
  border-color: var(--cyan);
  box-shadow: 0 0 0 3px rgba(76,243,214,0.12);
}
textarea { resize: vertical; min-height: 70px; font-family: var(--font-body); }

select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%238791A3' stroke-width='1.6' fill='none'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 13px center; padding-right: 34px; }

input[type="range"] {
  width: 100%; height: 4px; -webkit-appearance: none; appearance: none;
  background: linear-gradient(90deg, var(--cyan), var(--violet));
  border-radius: 999px; outline: none; margin-top: 6px;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 18px; height: 18px; border-radius: 50%;
  background: var(--text); border: 3px solid var(--violet); cursor: pointer;
  box-shadow: 0 0 10px rgba(139,92,246,0.6);
}
input[type="range"]::-moz-range-thumb {
  width: 18px; height: 18px; border-radius: 50%; background: var(--text); border: 3px solid var(--violet); cursor: pointer;
}

.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.field-error { color: var(--magenta); font-size: 12px; min-height: 14px; }

.generate-btn {
  position: relative; overflow: hidden;
  width: 100%; padding: 15px; margin-top: 4px;
  border: none; border-radius: var(--radius-m);
  background: var(--grad-signal);
  color: #061019; font-family: var(--font-display); font-weight: 700; font-size: 15px; letter-spacing: 0.03em;
  cursor: pointer;
  transition: transform .15s var(--ease), box-shadow .2s var(--ease);
  box-shadow: 0 4px 24px rgba(76,243,214,0.18);
}
.generate-btn:hover { transform: translateY(-1px); box-shadow: 0 6px 30px rgba(76,243,214,0.3); }
.generate-btn:active { transform: translateY(0); }
.generate-btn:disabled { opacity: 0.55; cursor: not-allowed; transform: none; }
.btn-pulse {
  position: absolute; inset: 0; background: rgba(255,255,255,0.25);
  transform: translateX(-100%); animation: sweep 2.6s ease-in-out infinite;
}
@keyframes sweep { 0% { transform: translateX(-100%); } 60%,100% { transform: translateX(100%); } }

/* ==========================================================================
   Dashboard
   ========================================================================== */
.dash-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.dash-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.ghost-btn, .primary-btn {
  border-radius: var(--radius-s); padding: 9px 16px; font-size: 13px; font-weight: 600;
  cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; gap: 6px;
  transition: all .2s var(--ease);
}
.ghost-btn { background: transparent; border: 1px solid var(--border); color: var(--text-dim); }
.ghost-btn:hover { border-color: var(--border-bright); color: var(--cyan); }
.primary-btn { background: var(--grad-signal); border: none; color: #061019; }
.primary-btn:hover { filter: brightness(1.08); }

.progress-track { height: 8px; background: rgba(255,255,255,0.05); border-radius: 999px; overflow: hidden; border: 1px solid var(--border); }
.progress-fill { height: 100%; width: 0%; background: var(--grad-signal); border-radius: 999px; transition: width .5s var(--ease); box-shadow: 0 0 12px rgba(76,243,214,0.5); }
.progress-meta { display: flex; justify-content: space-between; font-family: var(--font-mono); font-size: 12px; color: var(--text-dim); margin: 8px 0 18px; }

.router-card { background: rgba(6,9,15,0.5); border: 1px solid var(--border); border-radius: var(--radius-m); padding: 14px 16px; margin-bottom: 18px; }
.router-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.router-title { font-family: var(--font-display); font-size: 13px; letter-spacing: 0.05em; color: var(--text-dim); text-transform: uppercase; }
.router-active { font-family: var(--font-mono); font-size: 12px; color: var(--cyan); }

.router-chain { list-style: none; display: flex; gap: 8px; margin: 0; padding: 0; flex-wrap: wrap; }
.router-chain li {
  font-family: var(--font-mono); font-size: 11px; padding: 6px 10px; border-radius: 999px;
  border: 1px solid var(--border); color: var(--text-faint); transition: all .3s var(--ease);
}
.router-chain li.trying { border-color: var(--amber); color: var(--amber); box-shadow: 0 0 10px rgba(255,179,71,0.35); animation: pulse-dot 1s ease-in-out infinite; }
.router-chain li.success { border-color: var(--cyan); color: var(--cyan); background: rgba(76,243,214,0.08); }
.router-chain li.failed { border-color: var(--magenta); color: var(--magenta); opacity: 0.6; text-decoration: line-through; }

/* Tabs */
.tab-bar { display: flex; gap: 4px; overflow-x: auto; border-bottom: 1px solid var(--border); margin-bottom: 14px; }
.tab-btn {
  background: none; border: none; color: var(--text-faint); padding: 9px 12px; font-size: 12.5px;
  cursor: pointer; white-space: nowrap; border-bottom: 2px solid transparent; transition: all .2s var(--ease);
}
.tab-btn:hover { color: var(--text-dim); }
.tab-btn.active { color: var(--cyan); border-bottom-color: var(--cyan); }
.tab-panel { display: none; }
.tab-panel.active { display: block; animation: rise .3s var(--ease) both; }

.output-box {
  background: rgba(6,9,15,0.6); border: 1px solid var(--border); border-radius: var(--radius-s);
  padding: 14px; font-family: var(--font-mono); font-size: 12.5px; line-height: 1.65; color: var(--text);
  white-space: pre-wrap; word-break: break-word; max-height: 360px; overflow-y: auto; margin: 0;
}

.thumb-preview { display: flex; justify-content: center; }
.thumb-placeholder {
  width: 100%; max-width: 480px; aspect-ratio: 16/9; border-radius: var(--radius-m);
  border: 1px dashed var(--border); display: grid; place-items: center; color: var(--text-faint);
  font-size: 13px; background: rgba(6,9,15,0.4); overflow: hidden;
}
.thumb-placeholder img { width: 100%; height: 100%; object-fit: cover; }

.video-preview { width: 100%; border-radius: var(--radius-m); background: #000; }

/* Error log */
.error-log { border-top: 1px solid var(--border); margin-top: 18px; padding-top: 14px; }
.error-log summary { cursor: pointer; font-size: 13px; color: var(--text-dim); display: flex; align-items: center; gap: 8px; }
.error-log summary::marker { color: var(--cyan); }
.log-count { background: var(--bg-panel-raised); border: 1px solid var(--border); border-radius: 999px; padding: 1px 8px; font-family: var(--font-mono); font-size: 11px; }
.log-list { list-style: none; padding: 0; margin: 12px 0 0; display: flex; flex-direction: column; gap: 8px; }
.log-list li { font-family: var(--font-mono); font-size: 11.5px; color: var(--text-dim); border-left: 2px solid var(--magenta); padding: 6px 10px; background: rgba(255,61,129,0.05); border-radius: 0 6px 6px 0; }
.log-list .log-time { color: var(--text-faint); margin-right: 8px; }

/* History */
.history-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 10px; }
.history-empty { color: var(--text-faint); font-size: 13px; }
.history-item {
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  background: rgba(6,9,15,0.4); border: 1px solid var(--border); border-radius: var(--radius-m);
  padding: 12px 14px; cursor: pointer; transition: border-color .2s var(--ease);
}
.history-item:hover { border-color: var(--border-bright); }
.history-item .h-title { font-weight: 600; font-size: 13.5px; }
.history-item .h-meta { color: var(--text-faint); font-size: 11.5px; font-family: var(--font-mono); margin-top: 2px; }
.history-item .h-status { font-size: 11px; font-family: var(--font-mono); padding: 3px 9px; border-radius: 999px; border: 1px solid var(--border); }
.history-item .h-status.done { color: var(--cyan); border-color: var(--cyan); }
.history-item .h-status.error { color: var(--magenta); border-color: var(--magenta); }
.history-item .h-status.progress { color: var(--amber); border-color: var(--amber); }

/* ==========================================================================
   Modal
   ========================================================================== */
.modal { border: 1px solid var(--border); border-radius: var(--radius-l); background: var(--bg-panel); color: var(--text); padding: 0; max-width: 420px; width: 92%; }
.modal::backdrop { background: rgba(6,9,15,0.75); backdrop-filter: blur(4px); }
.modal-form { padding: 22px; display: flex; flex-direction: column; gap: 14px; }
.modal-form h3 { margin: 0; font-family: var(--font-display); }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 6px; }

/* Toasts */
.toast-stack { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 80; width: min(92%, 420px); }
.toast {
  background: var(--bg-panel-raised); border: 1px solid var(--border-bright); border-radius: var(--radius-s);
  padding: 12px 16px; font-size: 13px; box-shadow: 0 8px 30px rgba(0,0,0,0.4); animation: rise .3s var(--ease) both;
}
.toast.error { border-color: var(--magenta); }

/* ==========================================================================
   Loading skeleton pulse (used by JS-injected states)
   ========================================================================== */
.skeleton { background: linear-gradient(90deg, rgba(255,255,255,0.03), rgba(255,255,255,0.08), rgba(255,255,255,0.03)); background-size: 200% 100%; animation: shimmer 1.4s ease-in-out infinite; border-radius: 4px; }
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

/* ==========================================================================
   Responsive: desktop layout with side rail
   ========================================================================== */
@media (min-width: 860px) {
  .app-main { max-width: 1180px; display: grid; grid-template-columns: 220px 1fr; align-items: start; gap: 24px; padding-top: 18px; }
  .stage-rail { position: sticky; top: 74px; padding: 10px; grid-row: 1 / span 2; }
  .chain { flex-direction: column; align-items: stretch; }
  .chain-node:not(:last-child)::after { right: auto; left: 13px; top: 100%; width: 1px; height: 14px; }
  .form-panel, .dashboard-panel, .history-panel { grid-column: 2; }
}

@media (max-width: 859px) {
  .field-row { grid-template-columns: 1fr; }
}
