/* 
  Cognispace Framework Explorer | Canon-Aligned Design System
  Governed by STD-002 CSIM v1.0
*/

:root {
  /* Canon Color Identity - Impulse */
  --color-impulse: #FF6A3D;
  --color-impulse-alt: #F4B400;
  --color-impulse-glow: rgba(255, 106, 61, 0.2);

  /* Canon Color Identity - Evaluator */
  --color-evaluator: #4B5BD5;
  --color-evaluator-alt: #2F3A56;
  --color-evaluator-glow: rgba(75, 91, 213, 0.15);

  /* Canon Color Identity - Persona */
  --color-persona: #2FB8A6;
  --color-persona-alt: #C9CCD6;
  --color-persona-glow: rgba(47, 184, 166, 0.15);

  /* Canon Color Identity - Deliberation Flow */
  --color-flow-gradient: linear-gradient(135deg, #8B5CF6, #2FB8A6);

  /* UI Tokens */
  --explorer-bg: #FAFAF8;
  --explorer-surface: #FFFFFF;
  --explorer-border: #E9E7E2;
  --explorer-text: #171717;
  --explorer-muted: #6B6B6B;
  --radius-xl: 24px;
  --radius-lg: 16px;
  --radius-pill: 999px;
  --shadow-soft: 0 8px 30px rgba(0,0,0,0.04);
  --shadow-glow: 0 0 40px rgba(0,0,0,0.08);
}

.explorer-section {
  padding: var(--sp-20) 0;
  background-color: var(--explorer-bg);
}

.explorer-header {
  margin-bottom: var(--sp-12);
}

/* Mode Toggles */
.explorer-controls {
  display: flex;
  flex-direction: column;
  gap: var(--sp-6);
  align-items: center;
  margin-bottom: var(--sp-10);
}

.mode-toggle {
  display: inline-flex;
  background: var(--explorer-surface);
  border: 1px solid var(--explorer-border);
  border-radius: var(--radius-pill);
  padding: 4px;
  box-shadow: var(--shadow-soft);
}

.mode-btn {
  padding: 8px 18px;
  border-radius: var(--radius-pill);
  border: none;
  background: transparent;
  color: var(--explorer-muted);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
}

.mode-btn:hover {
  color: var(--explorer-text);
}

.mode-btn.active {
  background: var(--explorer-text);
  color: white;
}

/* Scenario Chips */
.scenario-chips {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: var(--sp-3);
}

.scenario-chip {
  padding: 6px 14px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--explorer-border);
  background: var(--explorer-surface);
  color: var(--explorer-muted);
  font-size: 0.8125rem;
  cursor: pointer;
  transition: all 0.2s ease;
}

.scenario-chip:hover {
  border-color: var(--explorer-text);
  color: var(--explorer-text);
}

.scenario-chip.active {
  background: var(--explorer-text);
  color: white;
  border-color: var(--explorer-text);
}

/* 3-Column Layout */
.explorer-grid {
  display: grid;
  grid-template-columns: 1.2fr 1fr 1.2fr;
  gap: var(--sp-8);
  align-items: start;
}

/* Left: Triangle Visualizer */
.explorer-visual {
  position: relative;
  background: var(--explorer-surface);
  border-radius: var(--radius-xl);
  padding: var(--sp-8);
  border: 1px solid var(--explorer-border);
  box-shadow: var(--shadow-soft);
  min-height: 440px;
  display: flex;
  align-items: center;
  justify-content: center;
}

#triadic-svg {
  width: 100%;
  height: auto;
  max-width: 400px;
}

.node-group {
  cursor: pointer;
}

.node-bg {
  fill: var(--explorer-surface);
  stroke: var(--explorer-border);
  stroke-width: 1px;
}

.node-ring {
  fill: none;
  stroke-width: 2.5px;
}

.node-glow {
  filter: blur(8px);
  opacity: 0;
  transition: opacity 0.4s ease;
}

.node-group.active .node-glow {
  opacity: 0.6;
}

.node-group.active .node-ring {
  stroke-width: 3.5px;
}

.node-label {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  fill: var(--explorer-text);
}

.rel-line {
  stroke-linecap: round;
  /* stroke and stroke-width are set via SVG attributes and JS — do not override here */
}

/* Center: Timeline */
.explorer-timeline {
  display: flex;
  flex-direction: column;
  gap: var(--sp-4);
  padding: var(--sp-4) 0;
}

.timeline-step {
  position: relative;
  padding-left: 1.75rem;
  border-left: 1px solid var(--explorer-border);
  padding-bottom: var(--sp-8);
}

.timeline-step:last-child {
  padding-bottom: 0;
  border-left-color: transparent;
}

.step-marker {
  position: absolute;
  left: -8px;
  top: 3px;
  width: 14px;
  height: 14px;
  background: var(--explorer-surface);
  border: 2px solid var(--explorer-border);
  border-radius: 50%;
  z-index: 2;
}

.step-content {
  opacity: 0.5;
  transition: all 0.4s ease;
  padding-left: 0.25rem;
}

.timeline-step.active .step-marker {
  border-color: currentColor;
  box-shadow: 0 0 10px currentColor;
}

.timeline-step.active .step-content {
  opacity: 1;
}

.step-title {
  font-size: 0.8125rem;
  font-weight: 600;
  margin-bottom: 2px;
  display: block;
}

.step-description {
  font-size: 0.8125rem;
  color: var(--explorer-muted);
  line-height: 1.4;
}

/* Right: Card */
.explorer-card {
  background: var(--explorer-surface);
  border-radius: var(--radius-xl);
  border: 1px solid var(--explorer-border);
  box-shadow: var(--shadow-soft);
  overflow: hidden;
  height: 100%;
  display: flex;
  flex-direction: column;
}

.card-header {
  padding: var(--sp-8) var(--sp-8) var(--sp-4);
  border-bottom: 1px solid var(--explorer-border);
}

.card-title {
  font-size: 1.25rem;
  font-weight: 500;
  color: var(--explorer-text);
  margin-bottom: var(--sp-2);
}

.card-body {
  padding: var(--sp-8);
  flex-grow: 1;
}

.card-description {
  font-size: 0.9375rem;
  line-height: 1.6;
  color: var(--explorer-muted);
  margin-bottom: var(--sp-8);
}

.tag-cloud {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-2);
}

.tag {
  font-size: 0.6875rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 4px 8px;
  background: var(--explorer-bg);
  border-radius: 4px;
  color: var(--explorer-muted);
}

.card-footer {
  padding: var(--sp-6) var(--sp-8);
  background: var(--explorer-bg);
  border-top: 1px solid var(--explorer-border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

/* Mode Specific States */
.mode-mpa .articulation-origin {
  stroke-dasharray: 0;
  animation: pulse-ring 2s infinite;
}

.mode-dominance .dominant-node {
  transform: scale(1.15);
  filter: drop-shadow(0 0 15px currentColor);
}

@keyframes pulse-ring {
  0% { r: 14; opacity: 1; }
  100% { r: 24; opacity: 0; }
}

/* Mobile Responsive */
@media (max-width: 1024px) {
  .explorer-grid {
    grid-template-columns: 1fr;
  }
  .explorer-timeline {
    order: 3;
    padding: var(--sp-8);
    background: var(--explorer-surface);
    border-radius: var(--radius-xl);
    border: 1px solid var(--explorer-border);
  }
  .explorer-card {
    order: 4;
  }
}

/* ── Step tags in timeline ─────────────────────────────────── */
.step-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem;
    margin-top: 0.375rem;
}

.step-tag {
    font-size: 0.55rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    background: rgba(255,255,255,0.06);
    border: 1px solid var(--explorer-border);
    border-radius: 3px;
    padding: 0.1em 0.4em;
    color: var(--text-tertiary, #A3A3A3);
}

/* ── Overlay/State node highlights ─────────────────────────── */
.affected-node .node-ring,
.state-node    .node-ring {
    stroke-width: 3px;
    opacity: 1;
}

.affected-node .node-glow,
.state-node    .node-glow {
    opacity: 0.25;
}

/* ── Deep Dive Button ─────────────────────────────────────── */
.btn-detail {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: 0.75rem;
    font-weight: 700;
    color: #fff;
    background: var(--color-evaluator, #4B5BD5);
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-family: inherit;
    padding: 6px 12px;
    transition: all 0.15s;
    letter-spacing: 0.01em;
    box-shadow: 0 1px 4px rgba(75,91,213,0.25);
}

.btn-detail:hover {
    background: #3a4ac4;
    box-shadow: 0 2px 8px rgba(75,91,213,0.35);
    transform: translateY(-1px);
}

.btn-canon {
    font-size: 0.75rem;
    font-weight: 600;
    text-decoration: none;
    color: var(--explorer-text, #171717);
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 5px 10px;
    border-radius: 6px;
    border: 1.5px solid rgba(0,0,0,0.15);
    background: var(--explorer-surface, #fff);
    transition: all 0.15s;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}

.btn-canon:hover {
    border-color: var(--explorer-text, #171717);
    background: var(--explorer-bg, #FAFAF8);
    box-shadow: 0 2px 6px rgba(0,0,0,0.1);
    text-decoration: none;
}

/* ── Deep Dive Modal (centered overlay) ──────────────────────── */
.explorer-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
}

.explorer-modal-overlay.open {
    opacity: 1;
    pointer-events: all;
}

.explorer-modal-dialog {
    background: var(--explorer-surface, #FFFFFF);
    border-radius: 16px;
    box-shadow: 0 24px 64px rgba(0,0,0,0.18), 0 4px 16px rgba(0,0,0,0.08);
    width: 100%;
    max-width: 560px;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transform: translateY(12px) scale(0.98);
    transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

.explorer-modal-overlay.open .explorer-modal-dialog {
    transform: translateY(0) scale(1);
}

/* Reuse existing panel-header / panel-body / panel-section styles */
.explorer-modal-dialog .panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--explorer-border);
    flex-shrink: 0;
    background: var(--bg-alt, #F7F7F8);
}

.explorer-modal-dialog .panel-title {
    font-size: 1rem;
    font-weight: 700;
    color: var(--text-primary, #171717);
    line-height: 1.3;
}

.explorer-modal-dialog .panel-close {
    background: rgba(0,0,0,0.07);
    border: 1px solid rgba(0,0,0,0.12);
    border-radius: 50%;
    width: 28px;
    height: 28px;
    font-size: 1rem;
    color: var(--text-primary, #171717);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    transition: background 0.15s, color 0.15s;
    flex-shrink: 0;
}

.explorer-modal-dialog .panel-close:hover {
    background: rgba(0,0,0,0.13);
}

.explorer-modal-dialog .panel-body {
    flex: 1;
    overflow-y: auto;
    padding: 1.25rem 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.625rem;
    scrollbar-width: thin;
    scrollbar-color: rgba(0,0,0,0.1) transparent;
}

.explorer-modal-dialog .panel-body::-webkit-scrollbar { width: 4px; }
.explorer-modal-dialog .panel-body::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.1); border-radius: 2px; }

.explorer-modal-dialog .panel-sections {
    display: flex;
    flex-direction: column;
    gap: 0.625rem;
    flex: 1;
}

.explorer-modal-dialog .panel-footer {
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid rgba(0,0,0,0.06);
    text-align: center;
}

body.modal-open {
    overflow: hidden;
}

@media (max-width: 600px) {
    .explorer-modal-overlay {
        align-items: flex-end;
        padding: 0;
    }
    .explorer-modal-dialog {
        max-width: 100%;
        border-radius: 16px 16px 0 0;
        max-height: 85vh;
        transform: translateY(100%);
    }
    .explorer-modal-overlay.open .explorer-modal-dialog {
        transform: translateY(0);
    }
}

/* ── Shared panel section styles (used in modal) ────────────── */
.panel-section {
    padding: 0.75rem 0.875rem;
    border-radius: 8px;
    border: 1px solid rgba(0,0,0,0.06);
    background: var(--bg-soft-gray, #FBFBFB);
}

.panel-section--healthy {
    background: rgba(13,148,136,0.04);
    border-color: rgba(13,148,136,0.15);
}

.panel-section--warn {
    background: rgba(255,106,61,0.04);
    border-color: rgba(255,106,61,0.15);
}

.panel-section--neutral {
    background: rgba(37,99,235,0.04);
    border-color: rgba(37,99,235,0.12);
}

.panel-section-label {
    font-size: 0.6rem;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--text-tertiary, #A3A3A3);
    margin-bottom: 0.375rem;
}

.panel-section--healthy .panel-section-label { color: #0D9488; }
.panel-section--warn    .panel-section-label { color: #C2410C; }
.panel-section--neutral .panel-section-label { color: #2563EB; }

.panel-section-body {
    font-size: 0.825rem;
    color: var(--text-secondary, #525252);
    line-height: 1.65;
    margin: 0;
}

/* ── Card body no longer needs scroll ───────────────────────── */
.explorer-card .card-body {
    overflow-y: visible;
    max-height: none;
}
