/* AMTI Causal Grid Visualization */

/* ── Cube diagram ────────────────────────────────────────────── */
.cube-container {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 32px;
  margin: 32px 0;
  display: flex;
  justify-content: center;
}

.cube-diagram {
  width: 100%;
  max-width: 720px;
  height: auto;
}

.layer {
  /* Group for 3×3 grid per Z-layer */
}

.layer-label {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text-mute);
  letter-spacing: 1px;
  text-transform: uppercase;
}

.cell {
  stroke: var(--line);
  stroke-width: 1.5;
  transition: opacity 0.2s ease, filter 0.2s ease;
  rx: 2;
}

.cell:hover {
  opacity: 1 !important;
  filter: brightness(1.2);
}

.cell.amti {
  stroke: var(--gold);
  stroke-width: 2.5;
  filter: drop-shadow(0 0 12px rgba(201, 162, 39, 0.6));
}

.cell.service {
  cursor: pointer;
}

.cell-label {
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 600;
  text-anchor: middle;
  fill: var(--text);
  pointer-events: none;
}

.cell-label.amti-label {
  fill: var(--bg);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 1px;
}

/* Causal edges (flow lines) */
.causal-edge {
  stroke-width: 2;
  stroke-linecap: round;
  animation: flow-dash 1.5s linear infinite;
}

@keyframes flow-dash {
  0% {
    stroke-dashoffset: 0;
  }
  100% {
    stroke-dashoffset: -10;
  }
}

.edges {
  pointer-events: none;
}

/* ── Service cards grid ────────────────────────────────────────────── */
.services-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 18px;
  margin: 32px 0;
}

.service-card {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-left: 4px solid var(--gold);
  border-radius: 8px;
  padding: 20px;
  transition: all 0.2s ease;
}

.service-card:hover {
  border-color: var(--gold);
  box-shadow: 0 0 16px rgba(201, 162, 39, 0.15);
  transform: translateY(-2px);
}

.svc-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  border-bottom: 1px dashed var(--line);
  padding-bottom: 12px;
}

.svc-head h3 {
  margin: 0;
  font-size: 16px;
  color: var(--text);
  font-weight: 600;
}

.svc-color-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  flex-shrink: 0;
}

.svc-body {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.metric-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  font-size: 13px;
}

.metric-lbl {
  color: var(--text-dim);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.metric-val {
  font-family: var(--mono);
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
  text-align: right;
}

.causedby {
  background: rgba(201, 162, 39, 0.06);
  border-left: 3px solid var(--gold);
  padding: 10px 12px;
  border-radius: 4px;
  font-size: 12px;
  color: var(--text-dim);
  display: flex;
  align-items: center;
  gap: 6px;
}

.causedby .arrow {
  color: var(--gold);
  font-weight: 700;
}

.source-val {
  font-family: var(--mono);
  color: var(--text-mute);
  font-size: 11px;
}

.rule {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-mute);
  background: rgba(230, 234, 241, 0.04);
  padding: 8px 10px;
  border-radius: 4px;
  line-height: 1.4;
}

/* ── Trace panel (역추적 패널) ────────────────────────────────────────────── */
.trace-panel {
  background: var(--bg-elev);
  border: 2px solid var(--gold);
  border-radius: 8px;
  padding: 24px;
  margin: 32px 0;
  box-shadow: 0 0 20px rgba(201, 162, 39, 0.2);
}

.trace-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 12px;
}

.trace-header h3 {
  margin: 0;
  font-size: 16px;
  color: var(--gold);
  font-weight: 600;
}

.close-trace {
  background: transparent;
  border: none;
  color: var(--text-mute);
  font-size: 24px;
  cursor: pointer;
  padding: 0;
  transition: color 0.15s ease;
}

.close-trace:hover {
  color: var(--text);
}

.trace-content {
  font-size: 13px;
}

.trace-chain {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.trace-step {
  display: grid;
  grid-template-columns: 40px 1fr;
  gap: 12px;
  align-items: flex-start;
}

.step-idx {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--gold);
  color: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--mono);
  font-weight: 700;
  font-size: 12px;
  flex-shrink: 0;
}

.step-content {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.step-path {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text-dim);
  font-weight: 600;
}

.step-value {
  font-family: var(--mono);
  font-size: 14px;
  color: var(--text);
  font-weight: 500;
}

.step-rule {
  font-size: 11px;
  color: var(--text-mute);
  background: rgba(230, 234, 241, 0.04);
  padding: 6px 8px;
  border-radius: 3px;
  line-height: 1.3;
}

.trace-arrow {
  text-align: center;
  color: var(--gold);
  font-size: 18px;
  margin: 0 0 -8px 20px;
}

/* ── Crisis alerts ────────────────────────────────────────────── */
.crisis-alert {
  background: rgba(228, 88, 88, 0.08);
  border: 1px solid var(--risk);
  border-radius: 8px;
  padding: 24px;
  margin: 32px 0;
}

.crisis-alert h3 {
  color: var(--risk);
  margin: 0 0 16px;
  font-size: 16px;
}

.crisis-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.crisis-item {
  background: var(--bg-card);
  border: 1px solid var(--risk);
  border-radius: 6px;
  padding: 12px 14px;
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 16px;
  align-items: center;
  font-size: 13px;
}

.crisis-metric {
  font-family: var(--mono);
  color: var(--text);
  font-weight: 600;
}

.crisis-value {
  font-family: var(--mono);
  font-weight: 600;
  font-size: 14px;
}

.crisis-threshold {
  color: var(--text-mute);
  font-size: 11px;
}

/* ── Header / Meta ────────────────────────────────────────────── */
.viz-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 32px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--line);
}

.refer-badge {
  display: inline-block;
  font-family: var(--mono);
  font-size: 12px;
  padding: 6px 12px;
  background: rgba(201, 162, 39, 0.12);
  border: 1px solid var(--gold-dim);
  border-radius: 4px;
  color: var(--gold);
  font-weight: 600;
  letter-spacing: 1px;
}

.viz-meta {
  font-size: 12px;
  color: var(--text-mute);
  margin: 8px 0 0;
}

/* ── Bidirectional causal section ────────────────────────────────────────────── */
.bidir-section {
  margin: 40px 0 0;
}

.bidir-legend {
  display: flex;
  gap: 24px;
  align-items: center;
  margin-bottom: 20px;
  padding: 12px 16px;
  background: rgba(201, 162, 39, 0.04);
  border: 1px solid var(--line);
  border-radius: 6px;
  flex-wrap: wrap;
}

.bidir-legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-dim);
}

.legend-arrow {
  font-size: 16px;
  font-weight: 700;
}

.gold-arrow {
  color: var(--gold);
}

.red-arrow {
  color: #E45858;
}

/* Reverse edge animation */
.causal-edge-rev {
  animation: flow-dash-rev 1.8s linear infinite;
}

@keyframes flow-dash-rev {
  0% {
    stroke-dashoffset: 0;
  }
  100% {
    stroke-dashoffset: 10;
  }
}

.causal-edge-fwd {
  animation: flow-dash 1.5s linear infinite;
}

.bidir-panel {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 24px;
  margin-bottom: 24px;
}

.bidir-panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
  gap: 12px;
}

.bidir-panel-title {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-dim);
  letter-spacing: 0.5px;
}

.reverse-causal-panel {
  border-left: 3px solid #E45858;
}

/* ── Reverse timeline ────────────────────────────────────────────── */
.reverse-timeline-wrap {
  margin-top: 24px;
  padding-top: 20px;
  border-top: 1px dashed var(--line);
}

.timeline-title {
  font-size: 12px;
  color: var(--text-mute);
  letter-spacing: 1px;
  text-transform: uppercase;
  margin: 0 0 14px;
}

.reverse-timeline {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.rt-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: rgba(228, 88, 88, 0.04);
  border: 1px solid rgba(228, 88, 88, 0.18);
  border-radius: 5px;
  font-size: 12px;
  flex-wrap: wrap;
}

.rt-phase-badge {
  display: inline-block;
  padding: 2px 6px;
  border-radius: 3px;
  background: rgba(228, 88, 88, 0.14);
  color: #E45858;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.5px;
  flex-shrink: 0;
}

.rt-event {
  font-family: var(--mono);
  color: var(--text);
  font-weight: 500;
}

.rt-arrow {
  color: #E45858;
  font-weight: 700;
}

.rt-metric {
  font-family: var(--mono);
  color: var(--text-dim);
  font-size: 12px;
}

.rt-delta-neg {
  color: #E45858;
  font-weight: 700;
}

.rt-delta-pos {
  color: #4DA86E;
  font-weight: 700;
}

.rt-delta-zero {
  color: var(--text-mute);
}

.rt-date {
  color: var(--text-mute);
  font-size: 11px;
  margin-left: auto;
}

/* ── Anchor chain panel ────────────────────────────────────────────── */
.anchor-panel {
  border-left: 3px solid var(--gold);
}

.anchor-panel-header {
  gap: 12px;
}

.anchor-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.anchor-verify-badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 600;
}

.anchor-verify-badge.badge-ok {
  background: rgba(77, 168, 110, 0.12);
  color: #4DA86E;
  border: 1px solid rgba(77, 168, 110, 0.3);
}

.anchor-verify-badge.badge-err {
  background: rgba(228, 88, 88, 0.1);
  color: #E45858;
  border: 1px solid rgba(228, 88, 88, 0.3);
}

.anchor-chain-container {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.anchor-empty {
  color: var(--text-mute);
  font-size: 13px;
  display: block;
  padding: 8px 0;
}

.anchor-err {
  color: #E45858;
}

.anchor-block {
  display: flex;
  flex-direction: column;
  align-items: stretch;
}

.anchor-block-inner {
  background: var(--bg-card, #13161F);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 12px 16px;
  transition: border-color 0.2s ease;
}

.anchor-block-latest .anchor-block-inner {
  border-color: var(--gold-dim, rgba(201, 162, 39, 0.4));
  box-shadow: 0 0 12px rgba(201, 162, 39, 0.1);
}

.anchor-block-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.anchor-block-meta {
  margin-top: 6px;
}

.anchor-kind {
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 600;
  color: var(--gold);
  text-transform: uppercase;
  letter-spacing: 1px;
}

.anchor-hash {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text-dim);
  background: rgba(230, 234, 241, 0.04);
  padding: 2px 8px;
  border-radius: 3px;
}

.anchor-ts {
  font-size: 11px;
  color: var(--text-mute);
}

.anchor-prev {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-mute);
}

.anchor-chain-link {
  text-align: center;
  color: var(--gold);
  font-size: 14px;
  line-height: 1;
  margin: 2px 0;
  opacity: 0.5;
}

/* ── Responsive ────────────────────────────────────────────── */
@media (max-width: 768px) {
  .services-grid {
    grid-template-columns: 1fr;
  }

  .cube-container {
    padding: 16px;
  }

  .cube-diagram {
    max-width: 100%;
  }

  .trace-step {
    grid-template-columns: 36px 1fr;
  }

  .step-idx {
    width: 28px;
    height: 28px;
    font-size: 11px;
  }

  .bidir-legend {
    gap: 14px;
  }

  .anchor-block-row {
    flex-wrap: wrap;
  }

  .rt-item {
    flex-wrap: wrap;
  }

  .rt-date {
    margin-left: 0;
  }
}
