/* ═══════════════════════════════════════════════════════════════
   TORMENT NEXUS — Operational Console Styles
   Aesthetic: Corporate clinical. Jira for civilisational collapse.
   ═══════════════════════════════════════════════════════════════ */

/* ── Reset & Base ── */

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

:root {
  --font-system: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
  --font-mono: 'SF Mono', 'Fira Code', 'Fira Mono', Menlo, Consolas, monospace;

  --color-bg: #ffffff;
  --color-bg-panel: #f8f9fa;
  --color-bg-hover: #f0f1f3;
  --color-border: #dee2e6;
  --color-border-light: #e9ecef;
  --color-text: #212529;
  --color-text-secondary: #6c757d;
  --color-text-muted: #adb5bd;

  --color-module-g: #4a90d9;
  --color-module-g-bg: #eef4fb;
  --color-module-a: #d9844a;
  --color-module-a-bg: #fdf4ee;

  --color-good: #2d8a56;
  --color-warning: #d9a441;
  --color-danger: #c94444;

  --color-accent: #5a6fd9;

  --header-height: 72px;
  --footer-height: 120px;
  --panel-side-width: 280px;

  --radius-sm: 3px;
  --radius-md: 5px;
}

html {
  font-size: 14px;
  line-height: 1.4;
}

body {
  font-family: var(--font-system);
  color: var(--color-text);
  background: var(--color-bg);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

a {
  color: var(--color-accent);
  text-decoration: none;
}
a:hover {
  text-decoration: underline;
}

/* ── Header ── */

.console-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--color-bg);
  border-bottom: 1px solid var(--color-border);
}

.classification {
  background: var(--color-text);
  color: #fff;
  text-align: center;
  font-size: 0.7rem;
  letter-spacing: 0.15em;
  padding: 3px 0;
  font-weight: 500;
}

.header-main {
  padding: 10px 20px;
  display: flex;
  align-items: baseline;
  gap: 20px;
  flex-wrap: wrap;
}

.header-main h1 {
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.header-meta {
  display: flex;
  align-items: center;
  gap: 16px;
  font-size: 0.78rem;
  color: var(--color-text-secondary);
  margin-left: auto;
}

.status-badge {
  background: var(--color-good);
  color: #fff;
  padding: 2px 8px;
  border-radius: var(--radius-sm);
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.05em;
}

.cycle-counter {
  font-family: var(--font-mono);
  font-size: 0.78rem;
}

.risk-display {
  font-size: 0.75rem;
}

/* ── Main Grid ── */

.console-grid {
  flex: 1;
  display: grid;
  grid-template-columns: var(--panel-side-width) 1fr var(--panel-side-width);
  min-height: 0;
  overflow: hidden;
}

.panel {
  overflow-y: auto;
  padding: 14px;
  border-right: 1px solid var(--color-border);
}
.panel:last-child {
  border-right: none;
  border-left: 1px solid var(--color-border);
}

.panel-left {
  background: var(--color-bg-panel);
}

.panel-center {
  background: var(--color-bg);
  padding: 20px;
  border-right: none;
}

.panel-right {
  background: var(--color-bg-panel);
}

.panel-title {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--color-text-secondary);
  margin-bottom: 12px;
}

.panel-subtitle {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--color-text-muted);
  margin: 14px 0 8px;
  padding-top: 10px;
  border-top: 1px solid var(--color-border-light);
}

/* ── Module Blocks ── */

.module-block {
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 10px 12px;
  margin-bottom: 8px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  background: var(--color-bg);
}

.module-block:hover {
  background: var(--color-bg-hover);
}

.module-block.selected {
  border-width: 2px;
}

.module-block.module-g {
  border-left: 3px solid var(--color-module-g);
}
.module-block.module-g.selected {
  border-color: var(--color-module-g);
  background: var(--color-module-g-bg);
}

.module-block.module-a {
  border-left: 3px solid var(--color-module-a);
}
.module-block.module-a.selected {
  border-color: var(--color-module-a);
  background: var(--color-module-a-bg);
}

.module-block-label {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.module-block-name {
  font-size: 0.8rem;
  color: var(--color-text-secondary);
  margin-top: 2px;
}

/* ── Cross-Module Connection Lines ── */

.cross-module-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  margin: 2px 0;
  font-size: 0.72rem;
  color: var(--color-text-secondary);
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: background 0.15s;
}
.cross-module-item:hover {
  background: var(--color-bg-hover);
}
.cross-module-item.active {
  color: var(--color-warning);
  font-weight: 500;
}

.cross-module-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--color-text-muted);
  flex-shrink: 0;
}
.cross-module-item.active .cross-module-dot {
  background: var(--color-warning);
  box-shadow: 0 0 4px var(--color-warning);
}

.cross-module-priority {
  font-size: 0.65rem;
  color: var(--color-text-muted);
  margin-left: auto;
}

/* ── State Variable Gauges ── */

.gauge {
  display: grid;
  grid-template-columns: 1fr 120px 36px;
  align-items: center;
  gap: 6px;
  margin-bottom: 6px;
}

.gauge-label {
  font-size: 0.72rem;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.gauge-bar {
  height: 8px;
  background: var(--color-border-light);
  border-radius: 4px;
  overflow: hidden;
}

.gauge-fill {
  height: 100%;
  border-radius: 4px;
  transition: width 0.3s ease, background-color 0.5s ease;
  min-width: 2px;
}

.gauge-value {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  text-align: right;
  color: var(--color-text-secondary);
}

/* ── Parameter Controls ── */

.sim-controls {
  display: flex;
  gap: 6px;
  margin-bottom: 10px;
}

.sim-btn {
  flex: 1;
  padding: 5px 8px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-bg);
  font-family: var(--font-system);
  font-size: 0.72rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.sim-btn:hover {
  background: var(--color-bg-hover);
  border-color: var(--color-text-muted);
}
.sim-btn.active {
  background: var(--color-good);
  color: #fff;
  border-color: var(--color-good);
}

.param-control {
  margin-bottom: 8px;
}

.param-control label {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 0.72rem;
  margin-bottom: 2px;
}

.param-name {
  font-family: var(--font-mono);
  font-weight: 500;
  font-size: 0.68rem;
}

.param-value {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  color: var(--color-text-secondary);
}

/* Range slider styling */
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 4px;
  background: var(--color-border-light);
  border-radius: 2px;
  outline: none;
  cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 12px;
  height: 12px;
  background: var(--color-text-secondary);
  border-radius: 50%;
  border: 2px solid var(--color-bg);
  box-shadow: 0 0 0 1px var(--color-border);
  cursor: pointer;
  transition: background 0.15s;
}
input[type="range"]::-webkit-slider-thumb:hover {
  background: var(--color-text);
}
input[type="range"]::-moz-range-thumb {
  width: 12px;
  height: 12px;
  background: var(--color-text-secondary);
  border-radius: 50%;
  border: 2px solid var(--color-bg);
  box-shadow: 0 0 0 1px var(--color-border);
  cursor: pointer;
}

/* ── Platform Toggles ── */

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 0;
}

.toggle-label {
  font-size: 0.72rem;
  font-weight: 500;
}

.toggle-switch {
  position: relative;
  width: 32px;
  height: 18px;
  flex-shrink: 0;
}

.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-slider {
  position: absolute;
  inset: 0;
  background: var(--color-border);
  border-radius: 9px;
  cursor: pointer;
  transition: background 0.2s;
}

.toggle-slider::before {
  content: '';
  position: absolute;
  width: 14px;
  height: 14px;
  left: 2px;
  top: 2px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.2s;
}

.toggle-switch input:checked + .toggle-slider {
  background: var(--color-module-g);
}

.toggle-switch input:checked + .toggle-slider::before {
  transform: translateX(14px);
}

.toggle-switch.module-a input:checked + .toggle-slider {
  background: var(--color-module-a);
}

/* ── Center Panel Detail View ── */

.detail-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--color-text-muted);
}

.detail-hint {
  font-size: 0.85rem;
}

.detail-header {
  margin-bottom: 16px;
}

.detail-header h2 {
  font-size: 1.1rem;
  font-weight: 600;
}

.detail-header .deployed-as {
  font-size: 0.8rem;
  color: var(--color-text-secondary);
  margin-top: 2px;
}

.platform-cards {
  display: grid;
  gap: 10px;
}

.platform-card {
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  background: var(--color-bg);
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.platform-card:hover {
  border-color: var(--color-text-muted);
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}
.platform-card.selected {
  border-color: var(--color-accent);
}

.platform-card-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 6px;
}

.platform-card-name {
  font-weight: 600;
  font-size: 0.85rem;
}

.platform-card-deployed {
  font-size: 0.72rem;
  color: var(--color-text-secondary);
}

.mechanic-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-bottom: 8px;
}

.mechanic-tag {
  font-size: 0.65rem;
  font-weight: 500;
  padding: 2px 6px;
  border-radius: 10px;
  background: var(--color-bg-panel);
  border: 1px solid var(--color-border-light);
  color: var(--color-text-secondary);
}

/* ── Effects Display ── */

.effects-list {
  margin: 8px 0;
}

.effect-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  padding: 3px 0;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  border-bottom: 1px solid var(--color-border-light);
}
.effect-row:last-child {
  border-bottom: none;
}

.effect-equation {
  color: var(--color-text);
}

.effect-current {
  color: var(--color-text-secondary);
  text-align: right;
}

.effect-positive {
  color: var(--color-good);
}

.effect-negative {
  color: var(--color-danger);
}

/* ── Platform Detail Properties ── */

.detail-section {
  margin: 12px 0;
}

.detail-section-title {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--color-text-muted);
  margin-bottom: 4px;
}

.detail-property {
  font-size: 0.8rem;
  color: var(--color-text-secondary);
  margin: 2px 0;
}

.detail-property strong {
  color: var(--color-text);
  font-weight: 500;
}

/* ── DSL Source View ── */

.dsl-toggle-btn {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  color: var(--color-accent);
  cursor: pointer;
  padding: 4px 0;
  border: none;
  background: none;
  font-family: var(--font-system);
  margin-top: 8px;
}
.dsl-toggle-btn:hover {
  text-decoration: underline;
}

.dsl-source {
  margin-top: 8px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  overflow: hidden;
  display: none;
}
.dsl-source.visible {
  display: block;
}

.dsl-source-header {
  background: var(--color-bg-panel);
  padding: 6px 10px;
  border-bottom: 1px solid var(--color-border-light);
  font-size: 0.68rem;
  color: var(--color-text-secondary);
  letter-spacing: 0.03em;
}

.dsl-source-code {
  padding: 10px 12px;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  line-height: 1.5;
  white-space: pre;
  overflow-x: auto;
  background: #fafbfc;
}

/* DSL syntax coloring */
.kw { color: #7c4dff; font-weight: 500; }
.str { color: #2d8a56; }
.num { color: #d9844a; }
.comment { color: #adb5bd; font-style: italic; }
.op { color: #c94444; }

/* ── Feedback Loop Detail ── */

.loop-chain {
  margin: 10px 0;
  padding-left: 4px;
}

.loop-chain-step {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 4px 0;
  font-size: 0.78rem;
}

.loop-chain-arrow {
  color: var(--color-text-muted);
  font-family: var(--font-mono);
  flex-shrink: 0;
  padding-top: 1px;
}

.loop-chain-text {
  color: var(--color-text-secondary);
}

.loop-chain-text.module-g-ref {
  color: var(--color-module-g);
  font-weight: 500;
}

.loop-chain-text.module-a-ref {
  color: var(--color-module-a);
  font-weight: 500;
}

.loop-chain-terminal {
  font-weight: 600;
  color: var(--color-warning);
}

.loop-chain-terminal.active {
  animation: pulse 1.5s ease-in-out infinite;
}

/* ── Outcome Cards ── */

.outcomes-strip {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  padding: 10px 20px;
  border-top: 1px solid var(--color-border);
}

.outcome-card {
  text-align: center;
  padding: 8px;
}

.outcome-label {
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-text-secondary);
  margin-bottom: 4px;
}

.outcome-value {
  font-family: var(--font-mono);
  font-size: 1.3rem;
  font-weight: 600;
  line-height: 1;
}

.outcome-metric {
  font-size: 0.65rem;
  color: var(--color-text-muted);
  margin-top: 2px;
}

.outcome-sparkline {
  margin: 4px auto 0;
  display: block;
}

.outcome-value.status-good { color: var(--color-good); }
.outcome-value.status-warning { color: var(--color-warning); }
.outcome-value.status-danger { color: var(--color-danger); }

/* ── Footer ── */

.console-footer {
  border-top: 1px solid var(--color-border);
  background: var(--color-bg);
}

.attribution {
  text-align: center;
  font-size: 0.7rem;
  color: var(--color-text-muted);
  padding: 8px 20px 10px;
  border-top: 1px solid var(--color-border-light);
}

.attribution em {
  font-style: italic;
}

/* ── Animations ── */

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

@keyframes flow {
  to { stroke-dashoffset: -12; }
}

.feedback-line {
  stroke-dasharray: 8 4;
  animation: flow 1s linear infinite;
}

.feedback-line.active {
  stroke: var(--color-warning);
  stroke-width: 2;
  filter: drop-shadow(0 0 3px var(--color-warning));
}

/* ── Responsive ── */

@media (max-width: 900px) {
  .console-grid {
    grid-template-columns: 1fr;
  }
  .panel-left, .panel-right {
    border-right: none;
    border-left: none;
    border-bottom: 1px solid var(--color-border);
  }
  .header-main {
    flex-direction: column;
    gap: 6px;
  }
  .header-meta {
    margin-left: 0;
    flex-wrap: wrap;
  }
  .outcomes-strip {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* ── Utility ── */

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}
