/* ============================================================
   Infrastructure Explorer
   Pan/zoom canvas, hierarchy sidebar, detail panel
   Failure simulation, directional arrows
   ============================================================ */

/* ---- layout ------------------------------------------------ */
.explorer {
  display: flex;
  height: calc(100vh - 49px);
  overflow: hidden;
}

/* ---- sidebar (left hierarchy) ------------------------------ */
.exp-sidebar {
  width: 248px;
  min-width: 248px;
  border-right: 1px solid var(--border-color);
  background: var(--bg-secondary);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.exp-sidebar__header {
  padding: var(--space-3) var(--space-3);
  border-bottom: 1px solid var(--border-color);
}

.exp-sidebar__search {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: 6px var(--space-3);
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
}

.exp-sidebar__search svg { flex: none; color: var(--text-tertiary); }

.exp-sidebar__search input {
  flex: 1;
  border: none;
  background: none;
  font-family: var(--font-body);
  font-size: 0.8125rem;
  color: var(--text-primary);
  outline: none;
}

.exp-sidebar__search input::placeholder { color: var(--text-tertiary); }

.exp-sidebar__list {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-2) 0;
}

.exp-sidebar__system { margin-bottom: 2px; }

.exp-sidebar__system-label {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: 5px var(--space-3);
  font-family: var(--font-body);
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-tertiary);
  cursor: pointer;
  user-select: none;
  transition: color 0.15s;
}

.exp-sidebar__system-label:hover { color: var(--text-secondary); }

.exp-sidebar__system-label svg {
  flex: none;
  transition: transform 0.2s;
}

.exp-sidebar__system-label.collapsed svg {
  transform: rotate(-90deg);
}

.exp-sidebar__system-count {
  font-size: 0.5625rem;
  background: var(--bg-tertiary);
  padding: 1px 6px;
  border-radius: var(--radius-pill);
  color: var(--text-tertiary);
  margin-left: auto;
}

.exp-sidebar__items { overflow: hidden; }
.exp-sidebar__items.collapsed { display: none; }

.exp-sidebar__item {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: 3px var(--space-3) 3px 28px;
  cursor: pointer;
  transition: background 0.1s;
  font-family: var(--font-mono);
  font-size: 0.6875rem;
  color: var(--text-secondary);
}

.exp-sidebar__item:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.exp-sidebar__item.active {
  background: var(--accent-wash);
  color: var(--accent);
}

.exp-sidebar__dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  flex: none;
}

/* ---- main canvas area -------------------------------------- */
.exp-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  position: relative;
}

/* ---- toolbar ----------------------------------------------- */
.exp-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px var(--space-4);
  border-bottom: 1px solid var(--border-color);
  background: var(--bg-primary);
  z-index: 10;
  gap: var(--space-3);
}

.exp-toolbar__filters {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}

.exp-chip {
  padding: 4px 12px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border-color);
  background: var(--bg-primary);
  font-family: var(--font-body);
  font-size: 0.6875rem;
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}

.exp-chip:hover {
  border-color: var(--border-strong);
  color: var(--text-primary);
}

.exp-chip.active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}

.exp-toolbar__zoom {
  display: flex;
  align-items: center;
  gap: 4px;
  flex: none;
}

.exp-zoom-btn {
  width: 28px;
  height: 28px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  background: var(--bg-primary);
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.875rem;
  font-weight: 500;
  transition: all 0.12s;
}

.exp-zoom-btn:hover {
  border-color: var(--border-strong);
  color: var(--text-primary);
  background: var(--bg-hover);
}

.exp-zoom-level {
  font-family: var(--font-mono);
  font-size: 0.625rem;
  color: var(--text-tertiary);
  min-width: 34px;
  text-align: center;
}

/* ---- viewport (clip + event area) -------------------------- */
.exp-viewport {
  flex: 1;
  overflow: hidden;
  position: relative;
  cursor: grab;
  background:
    radial-gradient(circle, var(--grid-dot) 1px, transparent 1px);
  background-size: var(--grid-size) var(--grid-size);
}

.exp-viewport.grabbing { cursor: grabbing; }

/* ---- canvas (transformed container) ------------------------ */
.exp-canvas {
  position: absolute;
  top: 0;
  left: 0;
  transform-origin: 0 0;
  will-change: transform;
}

/* ---- SVG connections --------------------------------------- */
.exp-lines {
  position: absolute;
  top: 0;
  left: 0;
  pointer-events: none;
  overflow: visible;
}

.exp-line {
  fill: none;
  stroke: var(--line-stroke);
  stroke-width: 1.8;
  opacity: 1;
  transition: opacity 0.2s, stroke 0.2s;
}

.exp-line.highlighted {
  stroke: var(--accent);
  stroke-width: 2.2;
  opacity: 1;
}

.exp-line--cross {
  stroke: var(--line-stroke);
  opacity: 0.55;
  stroke-dasharray: 5 4;
}

.exp-line--fail {
  stroke: #DC2626;
  stroke-width: 2.5;
  opacity: 1;
}

/* ---- system labels on canvas ------------------------------- */
.exp-system-label {
  position: absolute;
  font-family: var(--font-body);
  font-size: 0.6875rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  pointer-events: none;
  white-space: nowrap;
  opacity: 0.6;
}

/* ---- nodes ------------------------------------------------- */
.exp-node {
  position: absolute;
  width: 168px;
  height: 72px;
  background: var(--bg-card);
  border: 1.5px solid var(--border-color);
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 2px;
  padding: 8px 12px;
  cursor: pointer;
  transition: box-shadow 0.15s, border-color 0.15s, opacity 0.25s;
  user-select: none;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06), 0 0 1px rgba(0,0,0,0.08);
  border-left: 4px solid #888;
}

.exp-node:hover {
  border-color: var(--border-strong);
  box-shadow: 0 4px 14px rgba(0,0,0,0.10), 0 1px 3px rgba(0,0,0,0.06);
  z-index: 5;
}

.exp-node.selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-wash), 0 4px 14px rgba(0,0,0,0.10);
  z-index: 6;
}

.exp-node.dimmed { opacity: 0.12; }
.exp-node.highlighted { opacity: 1; }

/* failure simulation states */
.exp-node.failed {
  border-color: #DC2626;
  box-shadow: 0 0 0 2px rgba(220,38,38,0.25), 0 0 12px rgba(220,38,38,0.2);
  z-index: 7;
  animation: expPulseRed 1.3s ease-in-out infinite;
}

@keyframes expPulseRed {
  0%, 100% { box-shadow: 0 0 0 2px rgba(220,38,38,0.25), 0 0 6px rgba(220,38,38,0.15); }
  50%      { box-shadow: 0 0 0 3px rgba(220,38,38,0.4), 0 0 16px rgba(220,38,38,0.3); }
}

.exp-node.downstream {
  border-color: #D97706;
  box-shadow: 0 0 0 2px rgba(217,119,6,0.2);
  z-index: 6;
}

.exp-node.upstream {
  border-color: #DC2626;
  box-shadow: 0 0 0 2px rgba(220,38,38,0.18);
  opacity: 0.75;
  z-index: 6;
}

/* node top row */
.exp-node__top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 4px;
}

.exp-node__status {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-family: var(--font-body);
  font-size: 0.5rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  white-space: nowrap;
}

.exp-node__status.status-ok { color: var(--status-ok); }
.exp-node__status.status-warn { color: var(--status-progress); }
.exp-node__status.status-crit { color: var(--status-blocked); }

.exp-node__dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex: none;
}

.exp-node__dot--low    { background: var(--status-ok); }
.exp-node__dot--medium { background: var(--status-progress); }
.exp-node__dot--high   { background: var(--status-blocked); }

.exp-node__type {
  font-family: var(--font-body);
  font-size: 0.5rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-tertiary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.exp-node__name {
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.exp-node__loc {
  font-family: var(--font-body);
  font-size: 0.5625rem;
  color: var(--text-tertiary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ---- incident banner --------------------------------------- */
.exp-incident {
  position: absolute;
  top: var(--space-3);
  left: 50%;
  transform: translateX(-50%);
  z-index: 30;
  display: none;
  align-items: center;
  gap: var(--space-3);
  padding: 10px 16px;
  background: var(--bg-card);
  border: 2px solid #DC2626;
  border-radius: 12px;
  box-shadow: 0 12px 36px rgba(0,0,0,0.12);
  min-width: 360px;
  max-width: 600px;
  animation: expFadeIn 0.3s ease;
}

.exp-incident.show { display: flex; }

@keyframes expFadeIn {
  from { opacity: 0; transform: translateX(-50%) translateY(-8px); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}

.exp-incident__body { flex: 1; }

.exp-incident__title {
  font-family: var(--font-body);
  font-weight: 700;
  font-size: 0.875rem;
  color: #DC2626;
}

.exp-incident__sub {
  font-family: var(--font-mono);
  font-size: 0.6875rem;
  color: var(--text-secondary);
  margin-top: 2px;
}

.exp-incident__close {
  width: 28px;
  height: 28px;
  border: none;
  background: none;
  cursor: pointer;
  color: var(--text-tertiary);
  font-size: 18px;
  flex: none;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.15s, background 0.15s;
}

.exp-incident__close:hover {
  color: #DC2626;
  background: rgba(220,38,38,0.08);
}

/* ---- hint overlay ------------------------------------------ */
.exp-hint {
  position: absolute;
  top: var(--space-3);
  left: 50%;
  transform: translateX(-50%);
  z-index: 10;
  padding: 6px 16px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-pill);
  font-family: var(--font-body);
  font-size: 0.75rem;
  color: var(--text-tertiary);
  pointer-events: none;
  box-shadow: var(--shadow-rest);
  white-space: nowrap;
  animation: expHintFade 4s ease forwards;
}

@keyframes expHintFade {
  0%, 65% { opacity: 1; }
  100%    { opacity: 0; }
}

/* ---- detail panel (right) ---------------------------------- */
.exp-detail {
  width: 0;
  min-width: 0;
  overflow: hidden;
  border-left: 1px solid var(--border-color);
  background: var(--bg-secondary);
  transition: width 0.25s ease, min-width 0.25s ease;
  display: flex;
  flex-direction: column;
}

.exp-detail.open {
  width: 320px;
  min-width: 320px;
}

.exp-detail__header {
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-3);
}

.exp-detail__title {
  font-family: var(--font-mono);
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--text-primary);
}

.exp-detail__subtitle {
  font-size: 0.6875rem;
  color: var(--text-tertiary);
  margin-top: 2px;
}

.exp-detail__close {
  background: none;
  border: none;
  color: var(--text-tertiary);
  cursor: pointer;
  padding: 4px;
  border-radius: var(--radius-sm);
  flex: none;
  display: flex;
}

.exp-detail__close:hover {
  color: var(--text-primary);
  background: var(--bg-hover);
}

/* detail tabs */
.exp-detail__tabs {
  display: flex;
  border-bottom: 1px solid var(--border-color);
}

.exp-detail__tab {
  flex: 1;
  padding: 8px var(--space-2);
  border: none;
  background: none;
  font-family: var(--font-body);
  font-size: 0.625rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-tertiary);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: color 0.15s, border-color 0.15s;
}

.exp-detail__tab:hover { color: var(--text-secondary); }

.exp-detail__tab.active {
  color: var(--text-primary);
  border-bottom-color: var(--accent);
}

.exp-detail__body {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-4);
}

/* detail content sections */
.exp-detail__section { margin-bottom: var(--space-5); }

.exp-detail__section-title {
  font-family: var(--font-body);
  font-size: 0.5625rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-tertiary);
  margin-bottom: var(--space-2);
}

.exp-detail__row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 3px 0;
  font-size: 0.8125rem;
}

.exp-detail__label { color: var(--text-tertiary); font-size: 0.75rem; }
.exp-detail__value { color: var(--text-primary); font-weight: 500; font-size: 0.75rem; }

.exp-detail__risk {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 10px;
  border-radius: var(--radius-pill);
  font-size: 0.6875rem;
  font-weight: 600;
  font-family: var(--font-mono);
}

.exp-detail__risk--low    { background: rgba(22,163,74,0.1); color: var(--status-ok); }
.exp-detail__risk--medium { background: rgba(232,163,61,0.1); color: var(--status-progress); }
.exp-detail__risk--high   { background: rgba(220,38,38,0.1); color: var(--status-blocked); }

/* gate list */
.exp-gate {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: 4px 0;
  font-size: 0.6875rem;
  border-bottom: 1px solid var(--border-color);
}

.exp-gate:last-child { border-bottom: none; }

.exp-gate__dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex: none;
}

.exp-gate__dot--signed           { background: var(--status-ok); }
.exp-gate__dot--in_progress      { background: var(--status-progress); }
.exp-gate__dot--blocked          { background: var(--status-blocked); }
.exp-gate__dot--waived_with_risk { background: #D97706; }
.exp-gate__dot--not_started      { background: var(--status-idle); }

.exp-gate__name {
  flex: 1;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.exp-gate__status {
  font-family: var(--font-mono);
  font-size: 0.625rem;
  color: var(--text-tertiary);
  white-space: nowrap;
  text-transform: capitalize;
}

/* ---- impact card ------------------------------------------- */
.exp-impact-card {
  padding: 14px;
  background: rgba(220,38,38,0.06);
  border: 1px solid rgba(220,38,38,0.2);
  border-radius: 8px;
  margin-bottom: 12px;
}

.exp-impact-card__label {
  font-size: 0.5625rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #DC2626;
}

.exp-impact-card__value {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.5rem;
  color: #DC2626;
  margin-top: 4px;
}

/* ---- simulate button --------------------------------------- */
.exp-sim-btn {
  display: block;
  width: 100%;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(220,38,38,0.3);
  background: rgba(220,38,38,0.06);
  color: #DC2626;
  font-family: var(--font-body);
  font-size: 0.8125rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
}

.exp-sim-btn:hover {
  background: #DC2626;
  color: #fff;
  border-color: #DC2626;
}

/* ---- responsive -------------------------------------------- */
@media (max-width: 1024px) {
  .exp-sidebar { display: none; }
  .exp-detail.open { width: 280px; min-width: 280px; }
}

@media (max-width: 640px) {
  .exp-toolbar { flex-wrap: wrap; }
  .exp-detail.open {
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    width: 100%;
    min-width: 100%;
    z-index: 20;
  }
}

/* ============================================================
   Collapsible filter panel
   ============================================================ */
.exp-sidebar {
  transition: width 0.26s cubic-bezier(0.4, 0, 0.2, 1),
              min-width 0.26s cubic-bezier(0.4, 0, 0.2, 1),
              opacity 0.2s ease,
              transform 0.26s cubic-bezier(0.4, 0, 0.2, 1);
}

.explorer.sidebar-collapsed .exp-sidebar {
  width: 0;
  min-width: 0;
  opacity: 0;
  transform: translateX(-12px);
  border-right-color: transparent;
  pointer-events: none;
}

.exp-sidebar__header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  margin-bottom: var(--space-2);
}

.exp-sidebar__heading {
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-tertiary);
  white-space: nowrap;
}

.exp-sidebar__collapse {
  flex: none;
  background: none;
  border: none;
  color: var(--text-tertiary);
  cursor: pointer;
  padding: 3px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.15s, background 0.15s;
}
.exp-sidebar__collapse:hover {
  color: var(--text-primary);
  background: var(--bg-hover);
}

/* reopen tab, hidden until collapsed */
.exp-sidebar__reopen {
  display: none;
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  z-index: 20;
  width: 22px;
  height: 52px;
  border: 1px solid var(--border-color);
  border-left: none;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  background: var(--bg-secondary);
  color: var(--text-tertiary);
  cursor: pointer;
  align-items: center;
  justify-content: center;
  transition: all 0.18s;
  box-shadow: var(--shadow-rest);
}
.exp-sidebar__reopen:hover {
  color: var(--accent);
  background: var(--bg-card);
  width: 26px;
}

.explorer { position: relative; }
.explorer.sidebar-collapsed .exp-sidebar__reopen { display: flex; }
