/* ==========================================================================
   1. DESIGN TOKENS & BASE STYLES (Google Font: Prompt + Offline Fallback)
   ========================================================================== */
:root {
  --bg-app: #090e1a;
  --bg-panel: #111827;
  --bg-card: #1e293b;
  --bg-card-hover: #273549;
  --border-subtle: #334155;
  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;

  /* Link & Status Colors */
  --c-fiber: #ef4444;
  --c-lan: #38bdf8;
  --c-vpn: #22c55e;
  --c-5g: #eab308;
  --c-dr: #a855f7;
  --c-cloud: #f97316;
  --c-warn: #f59e0b;
  --c-danger: #f43f5e;
  --c-ok: #10b981;

  --radius-lg: 14px;
  --radius-md: 10px;
  --radius-sm: 6px;
  --shadow-card: 0 10px 25px -5px rgba(0, 0, 0, 0.5);
  --font-main: 'Prompt', system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans Thai", "Tahoma", sans-serif;
}

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

body {
  font-family: var(--font-main);
  background-color: var(--bg-app);
  color: var(--text-primary);
  line-height: 1.5;
  min-height: 100vh;
  overflow-x: hidden;
}

svg text {
  font-family: var(--font-main);
}

/* ==========================================================================
   2. LAYOUT & TOP HEADER
   ========================================================================== */
.app-container {
  max-width: 1580px;
  margin: 0 auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.topbar {
  background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 14px 20px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  box-shadow: var(--shadow-card);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-icon {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  background: rgba(56, 189, 248, 0.14);
  border: 1px solid rgba(56, 189, 248, 0.45);
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.brand h1 {
  font-size: 1.08rem;
  font-weight: 700;
  color: var(--text-primary);
}

.brand p {
  font-size: 0.78rem;
  color: var(--text-secondary);
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.badge-offline {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.74rem;
  font-weight: 600;
  padding: 6px 11px;
  border-radius: 999px;
  background: rgba(16, 185, 129, 0.14);
  color: #34d399;
  border: 1px solid rgba(16, 185, 129, 0.35);
}

.dot-pulse {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #10b981;
  animation: pulse-dot 1.8s infinite;
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.4; transform: scale(1.35); }
}

/* ==========================================================================
   3. TOP KPI STATUS BAR (5 CARDS)
   ========================================================================== */
.metrics-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
}

.metric-card {
  background: var(--bg-panel);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 11px 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  transition: border-color 0.25s ease;
}

.metric-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-secondary);
}

.metric-value {
  font-size: 0.96rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 6px;
}

.metric-sub {
  font-size: 0.72rem;
  color: var(--text-muted);
}

.status-ok { color: #34d399; }
.status-warn { color: #fbbf24; }
.status-danger { color: #fb7185; }

.ups-bar-track {
  width: 100%;
  height: 6px;
  background: #1e293b;
  border-radius: 999px;
  overflow: hidden;
  margin-top: 2px;
}

.ups-bar-fill {
  height: 100%;
  width: 100%;
  background: #10b981;
  border-radius: 999px;
  transition: width 0.35s linear, background-color 0.35s ease;
}

/* ==========================================================================
   4. CATEGORIZED SCENARIO CONTROL PANEL (TABS + CHAOS TOGGLES)
   ========================================================================== */
.control-wrapper {
  background: var(--bg-panel);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  box-shadow: var(--shadow-card);
}

.tabs-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  border-bottom: 1px solid #1e293b;
  padding-bottom: 10px;
}

.tab-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.tab-btn {
  appearance: none;
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  padding: 7px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.2s ease;
}

.tab-btn:hover {
  color: var(--text-primary);
  background: rgba(30, 41, 59, 0.7);
}

.tab-btn.active {
  background: rgba(56, 189, 248, 0.16);
  border-color: rgba(56, 189, 248, 0.45);
  color: #7dd3fc;
}

.tab-pane {
  display: none;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.tab-pane.active {
  display: flex;
}

.btn-sim {
  appearance: none;
  border: 1px solid var(--border-subtle);
  background: var(--bg-card);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 500;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: all 0.2s ease;
}

.btn-sim:hover {
  background: var(--bg-card-hover);
  border-color: #64748b;
  transform: translateY(-1px);
}

.btn-sim.active-fault {
  background: rgba(244, 63, 94, 0.2);
  border-color: #f43f5e;
  color: #fda4af;
  box-shadow: 0 0 12px rgba(244, 63, 94, 0.25);
}

.btn-sim.btn-attack {
  border-color: rgba(245, 158, 11, 0.5);
  background: rgba(245, 158, 11, 0.12);
  color: #fcd34d;
}

.btn-sim.btn-attack:hover {
  background: rgba(245, 158, 11, 0.24);
  border-color: #f59e0b;
}

.btn-sim.btn-reset {
  background: rgba(16, 185, 129, 0.15);
  border-color: rgba(16, 185, 129, 0.5);
  color: #6ee7b7;
}

.btn-sim.btn-reset:hover {
  background: rgba(16, 185, 129, 0.28);
}

/* Chaos Mode Toggle Switches */
.chaos-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  width: 100%;
  padding-top: 4px;
}

.chaos-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: rgba(30, 41, 59, 0.75);
  border: 1px solid var(--border-subtle);
  padding: 6px 11px;
  border-radius: var(--radius-sm);
  font-size: 0.78rem;
  font-weight: 500;
  cursor: pointer;
  user-select: none;
  transition: border-color 0.2s ease, background 0.2s ease;
}

.chaos-toggle input {
  accent-color: #f43f5e;
  width: 15px;
  height: 15px;
  cursor: pointer;
}

.chaos-toggle.is-tripped {
  border-color: #f43f5e;
  background: rgba(244, 63, 94, 0.16);
  color: #fda4af;
}

/* ==========================================================================
   5. WORKSPACE: SVG DIAGRAM + CALLOUT BALLOONS + INSPECTOR
   ========================================================================== */
.workspace {
  display: grid;
  grid-template-columns: 1fr 330px;
  gap: 12px;
  align-items: start;
}

.diagram-card {
  background: var(--bg-panel);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 12px;
  box-shadow: var(--shadow-card);
  overflow: hidden;
}

.diagram-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
  padding: 0 4px;
}

.diagram-hint {
  font-size: 0.76rem;
  color: var(--text-secondary);
}

.legend-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  font-size: 0.72rem;
  color: var(--text-secondary);
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.legend-line {
  width: 18px;
  height: 3px;
  border-radius: 2px;
  display: inline-block;
}

.event-alert-strip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 12px;
  margin-bottom: 8px;
  border-radius: var(--radius-sm);
  background: rgba(244, 63, 94, 0.14);
  border: 1px solid rgba(244, 63, 94, 0.5);
  color: #fecaca;
  font-size: 0.8rem;
  font-weight: 500;
}

.event-alert-strip.mode-info {
  background: rgba(56, 189, 248, 0.14);
  border-color: rgba(56, 189, 248, 0.5);
  color: #bae6fd;
}

.event-alert-strip.mode-warn {
  background: rgba(245, 158, 11, 0.16);
  border-color: rgba(245, 158, 11, 0.55);
  color: #fde68a;
}

.event-alert-strip.hidden {
  display: none;
}

.btn-dismiss-mini {
  background: rgba(15, 23, 42, 0.7);
  border: 1px solid rgba(148, 163, 184, 0.4);
  color: #f8fafc;
  font-family: inherit;
  font-size: 0.72rem;
  padding: 3px 9px;
  border-radius: 5px;
  cursor: pointer;
  white-space: nowrap;
}

.btn-dismiss-mini:hover {
  background: rgba(30, 41, 59, 0.95);
}

.svg-wrapper {
  width: 100%;
  overflow-x: auto;
  background: #070b14;
  border-radius: var(--radius-md);
  border: 1px solid #1e293b;
}

.svg-stage {
  position: relative;
  min-width: 960px;
  width: 100%;
}

svg#networkSvg {
  width: 100%;
  height: auto;
  display: block;
  user-select: none;
}

/* ==========================================================================
   DYNAMIC CALLOUT BALLOON OVERLAY
   ========================================================================== */
.balloon-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 20;
}

.callout-balloon {
  position: absolute;
  max-width: 270px;
  min-width: 200px;
  background: rgba(15, 23, 42, 0.96);
  border: 1.5px solid #38bdf8;
  border-radius: 10px;
  padding: 9px 11px;
  color: #f8fafc;
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.65);
  pointer-events: auto;
  transform: translate(-50%, -100%);
  margin-top: -14px;
  animation: balloon-pop 0.28s cubic-bezier(0.22, 1, 0.36, 1) forwards;
}

.callout-balloon.below {
  transform: translate(-50%, 0);
  margin-top: 14px;
}

.callout-balloon.tone-danger {
  border-color: #f43f5e;
  box-shadow: 0 0 18px rgba(244, 63, 94, 0.35), 0 12px 24px rgba(0, 0, 0, 0.65);
}

.callout-balloon.tone-warn {
  border-color: #f59e0b;
  box-shadow: 0 0 18px rgba(245, 158, 11, 0.3), 0 12px 24px rgba(0, 0, 0, 0.65);
}

.callout-balloon.tone-ok {
  border-color: #10b981;
  box-shadow: 0 0 18px rgba(16, 185, 129, 0.3), 0 12px 24px rgba(0, 0, 0, 0.65);
}

.callout-balloon.tone-purple {
  border-color: #a855f7;
  box-shadow: 0 0 18px rgba(168, 85, 247, 0.35), 0 12px 24px rgba(0, 0, 0, 0.65);
}

/* Pointer triangle */
.callout-balloon::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -8px;
  transform: translateX(-50%) rotate(45deg);
  width: 14px;
  height: 14px;
  background: rgba(15, 23, 42, 0.96);
  border-right: 1.5px solid inherit;
  border-bottom: 1.5px solid inherit;
  border-color: inherit;
  border-top: none;
  border-left: none;
}

.callout-balloon.below::after {
  bottom: auto;
  top: -8px;
  border-right: none;
  border-bottom: none;
  border-top: 1.5px solid inherit;
  border-left: 1.5px solid inherit;
}

.balloon-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 4px;
}

.balloon-title {
  font-size: 0.78rem;
  font-weight: 700;
  line-height: 1.3;
}

.tone-danger .balloon-title { color: #fda4af; }
.tone-warn .balloon-title { color: #fde047; }
.tone-ok .balloon-title { color: #6ee7b7; }
.tone-purple .balloon-title { color: #e9d5ff; }

.balloon-close {
  background: transparent;
  border: none;
  color: #94a3b8;
  font-size: 0.95rem;
  line-height: 1;
  cursor: pointer;
  padding: 0 2px;
}

.balloon-close:hover {
  color: #ffffff;
}

.balloon-body {
  font-size: 0.72rem;
  color: #e2e8f0;
  line-height: 1.45;
}

@keyframes balloon-pop {
  0% { opacity: 0; scale: 0.88; }
  100% { opacity: 1; scale: 1; }
}

/* ==========================================================================
   6. PURE CSS SVG PACKET FLOW & CYBER ALERT ANIMATIONS
   ========================================================================== */
.flow-anim {
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-dasharray: 8 10;
  animation: flow-dash 1.2s linear infinite;
  transition: opacity 0.3s ease, stroke 0.3s ease;
}

.flow-anim-slow {
  stroke-dasharray: 6 12;
  animation: flow-dash 2.2s linear infinite;
}

.flow-anim-fast {
  stroke-dasharray: 10 8;
  animation: flow-dash 0.7s linear infinite;
}

.flow-standby {
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-dasharray: 4 6;
  opacity: 0.32;
  animation: none;
  transition: opacity 0.3s ease;
}

.flow-down {
  fill: none;
  stroke: #475569 !important;
  stroke-dasharray: 3 6 !important;
  opacity: 0.22 !important;
  animation: none !important;
}

@keyframes flow-dash {
  to { stroke-dashoffset: -36; }
}

/* Attack & Threat Paths */
.attack-path {
  fill: none;
  stroke: #f43f5e;
  stroke-width: 4;
  stroke-dasharray: 10 10;
  opacity: 0;
  pointer-events: none;
}

.attack-path.active {
  opacity: 1;
  animation: attack-flow 0.45s linear infinite;
  filter: drop-shadow(0 0 8px #f43f5e);
}

.attack-path.ddos-heavy {
  stroke-width: 7;
  stroke-dasharray: 14 8;
  animation: attack-flow 0.28s linear infinite;
}

@keyframes attack-flow {
  to { stroke-dashoffset: -40; }
}

/* Pulsing Cyber Impact Rings */
.impact-ring {
  fill: rgba(244, 63, 94, 0.14);
  stroke: #f43f5e;
  stroke-width: 2.5;
  opacity: 0;
  pointer-events: none;
  transform-box: fill-box;
  transform-origin: center;
}

.impact-ring.active {
  opacity: 1;
  animation: ring-radar 1.1s ease-out infinite;
}

@keyframes ring-radar {
  0% { transform: scale(0.85); opacity: 0.95; }
  100% { transform: scale(1.38); opacity: 0; }
}

/* Shield & Alert Pulses */
.shield-pulse {
  transform-box: fill-box;
  transform-origin: center;
}

.shield-pulse.alerting {
  animation: shield-hit 0.45s ease-in-out infinite;
}

@keyframes shield-hit {
  0%, 100% { transform: scale(1); filter: drop-shadow(0 0 5px #f43f5e); }
  50% { transform: scale(1.3); filter: drop-shadow(0 0 16px #f43f5e); }
}

/* Interactive SVG Nodes */
.node-group {
  cursor: pointer;
  transition: opacity 0.25s ease;
}

.node-group:hover .node-box {
  stroke: #38bdf8;
  stroke-width: 2.2;
  filter: drop-shadow(0 0 8px rgba(56, 189, 248, 0.38));
}

.node-group.selected .node-box {
  stroke: #fbbf24;
  stroke-width: 2.5;
  filter: drop-shadow(0 0 10px rgba(251, 191, 36, 0.45));
}

.node-group.is-down .node-box {
  fill: #2a1215 !important;
  stroke: #f43f5e !important;
  stroke-dasharray: 4 3;
}

.node-group.is-down {
  opacity: 0.72;
}

.node-group.is-dr-active .node-box {
  stroke: #a855f7 !important;
  stroke-width: 3 !important;
  filter: drop-shadow(0 0 14px rgba(168, 85, 247, 0.65));
}

.fault-x, .badge-overlay {
  opacity: 0;
  transition: opacity 0.25s ease;
  pointer-events: none;
}

.fault-x.visible, .badge-overlay.visible {
  opacity: 1;
}

/* ==========================================================================
   7. INSPECTOR SIDEBAR & SIEM LOG CONSOLE
   ========================================================================== */
.inspector-card {
  background: var(--bg-panel);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 15px;
  box-shadow: var(--shadow-card);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.inspector-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border-subtle);
  padding-bottom: 9px;
  gap: 8px;
}

.inspector-header h2 { font-size: 0.92rem; font-weight: 700; }

.tag-pill {
  font-size: 0.68rem;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 999px;
  background: rgba(56, 189, 248, 0.15);
  color: #7dd3fc;
  border: 1px solid rgba(56, 189, 248, 0.35);
  white-space: nowrap;
}

.inspector-row {
  display: flex;
  flex-direction: column;
  gap: 2px;
  background: rgba(30, 41, 59, 0.55);
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(51, 65, 85, 0.7);
}

.inspector-row span.lbl {
  font-size: 0.68rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

.inspector-row span.val {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-primary);
}

.inspector-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 0.78rem;
  color: #cbd5e1;
}

.inspector-list li::before {
  content: "•";
  color: #38bdf8;
  font-weight: bold;
  margin-right: 6px;
}

/* SIEM Console */
.siem-card {
  background: var(--bg-panel);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 13px 16px;
  box-shadow: var(--shadow-card);
}

.siem-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.siem-header h3 {
  font-size: 0.88rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
}

.siem-clear {
  background: transparent;
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 0.72rem;
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
}

.siem-clear:hover { color: var(--text-primary); border-color: #64748b; }

.siem-log-box {
  background: #060911;
  border: 1px solid #1e293b;
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  height: 170px;
  overflow-y: auto;
  font-family: 'Prompt', ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.log-entry {
  display: flex;
  gap: 8px;
  align-items: baseline;
  line-height: 1.45;
  border-bottom: 1px dashed rgba(51, 65, 85, 0.35);
  padding-bottom: 4px;
}

.log-time { color: #64748b; white-space: nowrap; }
.log-lvl {
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 0.66rem;
  white-space: nowrap;
}
.lvl-INFO { background: rgba(56, 189, 248, 0.16); color: #38bdf8; }
.lvl-WARN { background: rgba(245, 158, 11, 0.18); color: #fbbf24; }
.lvl-CRIT { background: rgba(244, 63, 94, 0.22); color: #fda4af; }
.lvl-BLOCKED { background: rgba(168, 85, 247, 0.24); color: #e9d5ff; }
.log-msg { color: #e2e8f0; }

/* ==========================================================================
   8. RESPONSIVE BREAKPOINTS
   ========================================================================== */
@media (max-width: 1200px) {
  .workspace { grid-template-columns: 1fr; }
  .metrics-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 720px) {
  .metrics-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 480px) {
  .metrics-grid { grid-template-columns: 1fr; }
}
