/*
  This file is part of SISO-UI.
  Copyright (C) 2026 Jonathan Bailey

  This program is free software: you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation, either version 3 of the License, or
  (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program. If not, see <http://www.gnu.org/licenses/>.

*/

/* ── SISO Demo Styles ────────────────────────── */

:root {
  --bg: #0c141f;
  --bg-panel: #0f1922;
  --bg-card: #162029;
  --border: #1e3a4a;
  --text: #b8c5d6;
  --text-dim: #4a5d73;
  --cyan: #18d6e0;
  --magenta: #c4b5fd;
  --orange: #df740c;
  --green: #34d399;
  --gold: #fde68a;
}

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

body {
  font-family: 'JetBrains Mono', monospace;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

header {
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: baseline;
  gap: 1rem;
}

header h1 {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 1.25rem;
  background: linear-gradient(90deg, var(--cyan), var(--magenta));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

header p { color: var(--text-dim); font-size: 0.75rem; }

main {
  flex: 1;
  display: grid;
  grid-template-columns: 220px 1fr 280px;
  min-height: 0;
  margin-top:4rem;
}

.panel {
  padding: 1rem;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}

.panel:last-child { border-right: none; }

.panel h2 {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 2px;
  color: var(--cyan);
  margin-bottom: 0.5rem;
}

.hint {
  font-size: 0.6rem;
  color: var(--text-dim);
  margin-bottom: 0.75rem;
}

/* ── Gates ────────────────────────────────────── */

.gate-list {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.gate {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.6rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 4px;
  cursor: grab;
  transition: all 0.2s;
  position: relative;
}

.gate.dragging {
  opacity: 0.5;
  cursor: grabbing;
}

.gate.drag-over {
  border-color: var(--cyan);
  transform: translateY(2px);
}

.gate-icon { font-size: 1rem; }
.gate-info { flex: 1; }
.gate-name { font-size: 0.7rem; font-weight: 700; color: var(--text); }
.gate-desc { font-size: 0.55rem; color: var(--text-dim); }

.gate-order {
  width: 18px;
  height: 18px;
  background: var(--bg);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.6rem;
  color: var(--cyan);
  font-weight: 700;
}

.gate[data-color="cyan"] { border-left: 3px solid var(--cyan); }
.gate[data-color="magenta"] { border-left: 3px solid var(--magenta); }
.gate[data-color="orange"] { border-left: 3px solid var(--orange); }

/* ── Sandbox ──────────────────────────────────── */

.sandbox-section {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

.sandbox-toggle {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.sandbox-toggle label {
  font-size: 0.7rem;
  flex: 1;
}

.toggle {
  width: 36px;
  height: 20px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
  position: relative;
  transition: all 0.2s;
}

.toggle::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 12px;
  height: 12px;
  background: var(--text-dim);
  border-radius: 50%;
  transition: all 0.2s;
}

.toggle[data-active="true"] {
  background: var(--green);
  border-color: var(--green);
}

.toggle[data-active="true"]::after {
  left: 19px;
  background: var(--bg);
}

.sandbox-editor {
  width: 100%;
  height: 120px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.5rem;
  color: var(--text);
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.65rem;
  resize: none;
}

.sandbox-editor:focus {
  outline: none;
  border-color: var(--green);
}

.sandbox-editor:disabled {
  opacity: 0.4;
}

/* ── Stream Panel ─────────────────────────────── */

[data-panel="stream"] {
  background: var(--bg-panel);
}

.stream-view {
  flex: 1;
  min-height: 100px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  position: relative;
  overflow: hidden;
  margin-bottom: 1rem;
}

.stream-track {
  position: absolute;
  top: 50%; left: 0; right: 0;
  transform: translateY(-50%);
  height: 50px;
}

.stream-line {
  position: absolute;
  top: 50%; left: 0; right: 0;
  height: 2px;
  background: var(--border);
}

.stream-line::after {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 100%;
  background: linear-gradient(90deg, transparent, var(--cyan), transparent);
  animation: flow 2s linear infinite;
}

@keyframes flow {
  from { transform: translateX(-100%); }
  to { transform: translateX(100%); }
}

.gate-stations {
  display: flex;
  justify-content: space-around;
  align-items: center;
  height: 100%;
  padding: 0 2rem;
}

.station {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
}

.station-box {
  width: 36px; height: 36px;
  background: var(--bg-card);
  border: 2px solid var(--border);
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
  transition: all 0.2s;
}

.station-label { font-size: 0.5rem; color: var(--text-dim); }

[data-processing="true"] .station-box {
  border-color: var(--cyan);
  box-shadow: 0 0 15px var(--cyan);
  transform: scale(1.15);
}

.event-packet {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 24px; height: 24px;
  background: var(--cyan);
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  box-shadow: 0 0 15px var(--cyan);
  z-index: 10;
}

/* ── Input / Output ───────────────────────────── */

.io-section {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.input-area { display: flex; gap: 0.4rem; }

.input-area input {
  flex: 1;
  padding: 0.6rem 0.75rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  font-family: inherit;
  font-size: 0.8rem;
}

.input-area input:focus { outline: none; border-color: var(--cyan); }

.input-area button {
  padding: 0.6rem 1.25rem;
  background: var(--cyan);
  border: none;
  border-radius: 4px;
  color: var(--bg);
  font-family: inherit;
  font-weight: 700;
  font-size: 0.75rem;
  cursor: pointer;
  transition: all 0.2s;
}

.input-area button:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 15px rgba(0, 240, 255, 0.4);
}

.output-box {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.75rem;
}

.output-box label {
  display: block;
  font-size: 0.6rem;
  color: var(--text-dim);
  margin-bottom: 0.4rem;
}

.output-box .output {
  font-size: 0.9rem;
  min-height: 1.4em;
  color: var(--text);
}

.output-box .output[data-changed="true"] {
  color: var(--magenta);
}

.output-box .trace {
  margin-top: 0.5rem;
  padding-top: 0.5rem;
  border-top: 1px solid var(--border);
  font-size: 0.6rem;
  color: var(--text-dim);
}

.trace-step {
  margin: 0.25rem 0;
}

.trace-step .arrow { color: var(--cyan); }
.trace-step .gate-label { color: var(--orange); }

/* ── Log Panel ────────────────────────────────── */

.log-list {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  overflow-y: auto;
  min-height: 0;
}

.log-entry {
  padding: 0.5rem;
  background: var(--bg);
  border-radius: 4px;
  font-size: 0.65rem;
  border-left: 3px solid var(--cyan);
  animation: slideIn 0.2s ease-out;
}

@keyframes slideIn {
  from { opacity: 0; transform: translateX(10px); }
}

.log-time { color: var(--text-dim); }
.log-input { color: var(--text); }
.log-output { color: var(--magenta); font-weight: 700; }
.log-arrow { color: var(--cyan); margin: 0 0.25rem; }

/* ── Footer ───────────────────────────────────── */

footer {
  padding: 0.75rem 1.5rem;
  border-top: 1px solid var(--border);
  background: var(--bg-panel);
}

.time-travel { display: flex; align-items: center; gap: 0.75rem; }
.time-travel label { font-size: 0.65rem; color: var(--text-dim); }

.time-travel input[type="range"] {
  flex: 1;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  -webkit-appearance: none;
}

.time-travel input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px; height: 14px;
  background: var(--cyan);
  border-radius: 50%;
  cursor: pointer;
}

#time-display { font-size: 0.65rem; color: var(--text-dim); min-width: 50px; }

.time-travel button {
  padding: 0.4rem 0.75rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  font-family: inherit;
  font-size: 0.65rem;
  cursor: pointer;
}

.time-travel button:hover { border-color: var(--cyan); }

/* ── Toast ────────────────────────────────────── */

#toast {
  position: fixed;
  bottom: 4rem;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--bg-card);
  border: 1px solid var(--cyan);
  padding: 0.6rem 1.25rem;
  border-radius: 4px;
  font-size: 0.75rem;
  opacity: 0;
  transition: all 0.3s;
  pointer-events: none;
  z-index: 100;
}

[data-toast="visible"] {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ── Test Indicator ───────────────────────────── */

#test-results {
  position: fixed;
  top: 4rem;
  right: 1rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.4rem 0.75rem;
  font-size: 0.65rem;
  z-index: 100;
}

[data-status="pass"] { border-color: var(--green); color: var(--green); }
[data-status="fail"] { border-color: var(--magenta); color: var(--magenta); }

/* ── Intro Modal ──────────────────────────────── */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.9);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  opacity: 1;
  transition: opacity 0.4s;
}

.modal-overlay[data-state="hidden"] {
  opacity: 0;
  pointer-events: none;
}

.modal {
  background: var(--bg-panel);
  border: 1px solid var(--cyan);
  border-radius: 8px;
  padding: 2rem;
  max-width: 520px;
  width: 90%;
  box-shadow: 0 0 60px rgba(0, 240, 255, 0.2);
}

.modal-title {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 1.5rem;
  margin-bottom: 1.5rem;
  background: linear-gradient(90deg, var(--cyan), var(--magenta));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  opacity: 0;
  transform: translateY(10px);
  animation: fadeUp 0.5s ease forwards;
}

.modal-section {
  margin-bottom: 1.25rem;
  opacity: 0;
  transform: translateY(10px);
}

.modal-section[data-visible="true"] {
  animation: fadeUp 0.5s ease forwards;
}

@keyframes fadeUp {
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.modal-section h3 {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--cyan);
  margin-bottom: 0.4rem;
}

.modal-section p {
  font-size: 0.85rem;
  line-height: 1.5;
  color: var(--text);
}

.modal-pitch {
  background: var(--bg);
  border-left: 3px solid var(--magenta);
  padding: 1rem;
  margin: 1.5rem 0;
  font-size: 0.95rem;
  line-height: 1.6;
  opacity: 0;
  transform: translateY(10px);
}

.modal-pitch[data-visible="true"] {
  animation: fadeUp 0.6s ease forwards;
}

.modal-pitch strong {
  color: var(--magenta);
}

.modal-pitch em {
  color: var(--cyan);
  font-style: normal;
}

.modal-steps {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-top: 1rem;
}

.modal-step {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.8rem;
  opacity: 0;
  transform: translateX(-10px);
}

.modal-step[data-visible="true"] {
  animation: fadeRight 0.4s ease forwards;
}

@keyframes fadeRight {
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

.modal-step .step-num {
  width: 24px;
  height: 24px;
  background: var(--bg);
  border: 1px solid var(--cyan);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  color: var(--cyan);
  font-weight: 700;
  flex-shrink: 0;
}

.modal-btn {
  width: 100%;
  padding: 0.9rem;
  background: var(--cyan);
  border: none;
  border-radius: 4px;
  color: var(--bg);
  font-family: inherit;
  font-weight: 700;
  font-size: 0.9rem;
  cursor: pointer;
  margin-top: 1rem;
  opacity: 0;
  transform: scale(0.95);
  transition: all 0.2s;
}

.modal-btn[data-visible="true"] {
  animation: popIn 0.4s ease forwards;
}

@keyframes popIn {
  to {
    opacity: 1;
    transform: scale(1);
  }
}

.modal-btn:hover {
  box-shadow: 0 0 20px rgba(0, 240, 255, 0.5);
  transform: scale(1.02);
}

.modal-skip {
  text-align: center;
  margin-top: 0.75rem;
  font-size: 0.65rem;
  color: var(--text-dim);
  opacity: 0;
}

.modal-skip[data-visible="true"] {
  animation: fadeUp 0.3s ease forwards;
}

.modal-skip a {
  color: var(--text-dim);
  cursor: pointer;
  text-decoration: underline;
}

.modal-skip a:hover {
  color: var(--text);
}

/* ── Empty State ──────────────────────────────── */

.empty-state {
  color: var(--text-dim);
  font-size: 0.8rem;
  line-height: 1.5;
}

.empty-state .prompt {
  color: var(--cyan);
  font-weight: 700;
}

.empty-state .hint {
  font-size: 0.7rem;
  margin-top: 0.25rem;
}

/* ── Mode Indicator ───────────────────────────── */

.mode-indicator {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.5rem;
  margin-bottom: 1rem;
  font-size: 0.65rem;
  text-align: center;
}

.mode-indicator[data-mode="pipeline"] {
  border-color: var(--cyan);
  color: var(--cyan);
}

.mode-indicator[data-mode="sandbox"] {
  border-color: var(--green);
  color: var(--green);
}
