/* Inter or Outfit Google Font */
@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@300;400;500;600;700&family=Fira+Code:wght@400;500&display=swap');

:root {
  /* Color system */
  --bg-dark: #0b0f19;
  --bg-card: rgba(17, 24, 39, 0.7);
  --bg-card-hover: rgba(31, 41, 55, 0.85);
  --border-color: rgba(255, 255, 255, 0.08);
  --border-active: rgba(255, 255, 255, 0.2);
  --text-primary: #f3f4f6;
  --text-secondary: #9ca3af;
  --text-muted: #6b7280;

  /* Actor Colors */
  --color-customer: #3b82f6;      /* Blue */
  --color-backend: #10b981;       /* Green */
  --color-blockchain: #8b5cf6;    /* Purple */
  --color-admin: #f59e0b;         /* Orange */
  --color-external: #6b7280;      /* Grey */

  /* Actor Transparent Colors for shadows and bg */
  --color-customer-trans: rgba(59, 130, 246, 0.15);
  --color-backend-trans: rgba(16, 185, 129, 0.15);
  --color-blockchain-trans: rgba(139, 92, 246, 0.15);
  --color-admin-trans: rgba(245, 158, 11, 0.15);
  --color-external-trans: rgba(107, 114, 128, 0.15);

  /* Status Colors */
  --status-pending: #fbbf24;
  --status-pending-admin: #f59e0b;
  --status-success: #10b981;
  --status-failed: #ef4444;
  --status-rejected: #9ca3af;

  /* Font properties */
  --font-sans: 'Outfit', sans-serif;
  --font-mono: 'Fira Code', monospace;
  --transition-speed: 0.3s;
}

/* Light Theme overrides */
body.light-theme {
  --bg-dark: #f8fafc;
  --bg-card: rgba(255, 255, 255, 0.85);
  --bg-card-hover: rgba(255, 255, 255, 0.95);
  --border-color: rgba(0, 0, 0, 0.08);
  --border-active: rgba(0, 0, 0, 0.18);
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #94a3b8;

  --color-customer: #2563eb;
  --color-backend: #059669;
  --color-blockchain: #7c3aed;
  --color-admin: #d97706;
  --color-external: #4b5563;

  --color-customer-trans: rgba(37, 99, 235, 0.08);
  --color-backend-trans: rgba(5, 150, 105, 0.08);
  --color-blockchain-trans: rgba(124, 58, 237, 0.08);
  --color-admin-trans: rgba(217, 119, 6, 0.08);
  --color-external-trans: rgba(75, 85, 99, 0.08);
}

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

body {
  font-family: var(--font-sans);
  background-color: var(--bg-dark);
  color: var(--text-primary);
  overflow: hidden;
  height: 100vh;
  width: 100vw;
  transition: background-color var(--transition-speed), color var(--transition-speed);
}

/* Grid & Layout Structure */
.app-container {
  display: flex;
  height: 100vh;
  width: 100vw;
}

/* Flowchart Area */
.flowchart-area {
  flex: 1;
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* Header bar */
.top-header {
  padding: 15px 25px;
  background: rgba(15, 23, 42, 0.3);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border-color);
  z-index: 10;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.top-header h1 {
  font-size: 1.15rem;
  font-weight: 600;
  letter-spacing: 0.5px;
  color: var(--text-primary);
}

.top-header .subtitle {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 2px;
}

/* Viewport and Canvas */
.canvas-viewport {
  flex: 1;
  overflow: auto;
  position: relative;
  cursor: grab;
  outline: none;
}

.canvas-viewport:active {
  cursor: grabbing;
}

.canvas-zoomable {
  position: relative;
  transform-origin: 0 0;
  width: 3800px;
  height: 2350px;
  padding: 40px;
  background-size: 40px 40px;
  background-image: 
    linear-gradient(to right, rgba(255, 255, 255, 0.01) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(255, 255, 255, 0.01) 1px, transparent 1px);
  transition: transform 0.1s ease-out;
}

body.light-theme .canvas-zoomable {
  background-image: 
    linear-gradient(to right, rgba(0, 0, 0, 0.015) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(0, 0, 0, 0.015) 1px, transparent 1px);
}

/* SVG Connection Overlay */
.svg-connections {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 1;
}

.flow-path {
  fill: none;
  stroke: var(--text-muted);
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-linejoin: round;
  opacity: 0.75;
  transition: stroke var(--transition-speed), stroke-width var(--transition-speed), opacity var(--transition-speed);
}

/* Connection Path Types */
.flow-path.user-action-flow {
  stroke: var(--color-customer);
}
.flow-path.system-process-flow {
  stroke: var(--text-secondary);
}
.flow-path.data-info-flow {
  stroke: var(--text-muted);
  stroke-dasharray: 6 4;
}
.flow-path.blockchain-event-flow {
  stroke: var(--color-blockchain);
  stroke-dasharray: 6 4;
}
.flow-path.admin-action-flow {
  stroke: var(--color-admin);
}

/* Dynamic highlighting of connections */
.flow-path.active {
  stroke-width: 4;
  opacity: 1.0 !important;
  filter: drop-shadow(0 0 5px var(--active-color, #fff));
}

/* Dimming all paths when highlighting is active */
.svg-connections.has-highlight .flow-path:not(.active) {
  opacity: 0.12 !important;
}

/* Pulse animation on active lines */
.flow-path.pulse {
  animation: dash 35s linear infinite;
}

@keyframes dash {
  to {
    stroke-dashoffset: -1000;
  }
}

/* Grid Layout (7 Actor columns: Col 4 & 5 widened to 840px for parallel lanes) */
.flowchart-grid {
  display: grid;
  grid-template-columns: 120px 360px 360px 360px 840px 840px 360px 360px;
  grid-auto-rows: minmax(260px, auto);
  gap: 30px;
  position: relative;
  z-index: 2;
  transition: opacity var(--transition-speed);
}

/* Dimming all cards in grid when highlight active */
.flowchart-grid.has-highlight .node-card {
  opacity: 0.22;
}

/* Keep highlighted cards at full opacity */
.flowchart-grid.has-highlight .node-card.highlighted-node {
  opacity: 1.0;
  transform: translateY(-4px);
  border-color: var(--border-active);
  box-shadow: 0 8px 20px -3px rgba(0, 0, 0, 0.4);
}

/* Actor Header Columns */
.actor-headers {
  display: grid;
  grid-template-columns: 120px 360px 360px 360px 840px 840px 360px 360px;
  gap: 30px;
  margin-bottom: 25px;
  position: sticky;
  top: 0;
  z-index: 5;
  background: var(--bg-dark);
  padding: 10px 0;
}

.actor-header {
  padding: 15px;
  border-radius: 8px;
  text-align: center;
  font-weight: 600;
  font-size: 0.88rem;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: #fff;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.actor-header.customer { background: linear-gradient(135deg, #1d4ed8, #3b82f6); border-color: rgba(59, 130, 246, 0.3); }
.actor-header.backend { background: linear-gradient(135deg, #065f46, #10b981); border-color: rgba(16, 185, 129, 0.3); }
.actor-header.blockchain { background: linear-gradient(135deg, #5b21b6, #8b5cf6); border-color: rgba(139, 92, 246, 0.3); }
.actor-header.admin { background: linear-gradient(135deg, #b45309, #f59e0b); border-color: rgba(245, 158, 11, 0.3); }
.actor-header.external { background: linear-gradient(135deg, #374151, #6b7280); border-color: rgba(107, 114, 128, 0.3); }

/* Stage Sidebar (Row Labels) */
.stage-label-container {
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(15, 23, 42, 0.4);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 10px;
  text-align: center;
  position: relative;
}

.stage-label {
  font-weight: 700;
  font-size: 0.75rem;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  color: var(--text-secondary);
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  white-space: nowrap;
}

/* Card Cell Flex Column */
.grid-cell {
  display: flex;
  flex-direction: column;
  gap: 20px;
  align-items: center;
  justify-content: center;
  min-height: 200px;
  position: relative;
}

/* Card Styling */
.node-card {
  width: 100%;
  max-width: 330px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 16px;
  position: relative;
  transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1), 
              border-color var(--transition-speed), 
              box-shadow var(--transition-speed),
              opacity var(--transition-speed);
  cursor: pointer;
  box-shadow: 0 4px 15px -3px rgba(0, 0, 0, 0.2);
  backdrop-filter: blur(12px);
}

.node-card:hover {
  transform: translateY(-4px);
  background: var(--bg-card-hover);
  border-color: var(--border-active);
  box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.3);
}

/* Highlight themes for specific actors on select */
.node-card.highlighted-node.actor-customer { border-color: var(--color-customer); box-shadow: 0 0 20px 2px rgba(59, 130, 246, 0.3); }
.node-card.highlighted-node.actor-backend { border-color: var(--color-backend); box-shadow: 0 0 20px 2px rgba(16, 185, 129, 0.3); }
.node-card.highlighted-node.actor-blockchain { border-color: var(--color-blockchain); box-shadow: 0 0 20px 2px rgba(139, 92, 246, 0.3); }
.node-card.highlighted-node.actor-admin { border-color: var(--color-admin); box-shadow: 0 0 20px 2px rgba(245, 158, 11, 0.3); }
.node-card.highlighted-node.actor-external { border-color: var(--color-external); box-shadow: 0 0 20px 2px rgba(107, 114, 128, 0.3); }

/* Node Internal Details */
.card-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 10px;
}

.card-icon {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.05rem;
  color: #fff;
  flex-shrink: 0;
}

.actor-customer .card-icon { background: var(--color-customer-trans); color: var(--color-customer); }
.actor-backend .card-icon { background: var(--color-backend-trans); color: var(--color-backend); }
.actor-blockchain .card-icon { background: var(--color-blockchain-trans); color: var(--color-blockchain); }
.actor-admin .card-icon { background: var(--color-admin-trans); color: var(--color-admin); }
.actor-external .card-icon { background: var(--color-external-trans); color: var(--color-external); }

.card-title {
  font-weight: 600;
  font-size: 0.88rem;
  color: var(--text-primary);
  line-height: 1.2;
}

.card-body {
  font-size: 0.78rem;
  color: var(--text-secondary);
  line-height: 1.45;
}

.card-body ul {
  list-style: none;
  padding-left: 0;
}

.card-body li {
  position: relative;
  padding-left: 12px;
  margin-bottom: 4px;
}

.card-body li::before {
  content: "•";
  color: var(--text-muted);
  position: absolute;
  left: 0;
  font-weight: bold;
}

/* Status Indicator Tag */
.status-badge {
  position: absolute;
  top: 12px;
  right: 12px;
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.5px;
  padding: 2px 6px;
  border-radius: 10px;
  text-transform: uppercase;
}

.status-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  display: inline-block;
}

.badge-pending { background: rgba(251, 191, 36, 0.1); color: var(--status-pending); border: 1px solid rgba(251, 191, 36, 0.2); }
.badge-pending .status-dot { background: var(--status-pending); }

.badge-pending-admin { background: rgba(245, 158, 11, 0.1); color: var(--status-pending-admin); border: 1px solid rgba(245, 158, 11, 0.2); }
.badge-pending-admin .status-dot { background: var(--status-pending-admin); }

.badge-success { background: rgba(16, 185, 129, 0.1); color: var(--status-success); border: 1px solid rgba(16, 185, 129, 0.2); }
.badge-success .status-dot { background: var(--status-success); }

.badge-failed { background: rgba(239, 68, 68, 0.1); color: var(--status-failed); border: 1px solid rgba(239, 68, 68, 0.2); }
.badge-failed .status-dot { background: var(--status-failed); }

.badge-rejected { background: rgba(156, 163, 175, 0.1); color: var(--status-rejected); border: 1px solid rgba(156, 163, 175, 0.2); }
.badge-rejected .status-dot { background: var(--status-rejected); }

/* Stage 4 Sub-lane Styles */
.admin-execution-cell {
  display: flex;
  flex-direction: column;
  gap: 20px;
  align-items: stretch !important;
  justify-content: flex-start !important;
  padding: 0 10px;
  width: 100%;
  height: 100%;
}

.sub-lane-container {
  border: 1px dashed rgba(255, 255, 255, 0.08);
  background: rgba(255, 255, 255, 0.01);
  border-radius: 10px;
  padding: 15px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
}

body.light-theme .sub-lane-container {
  border-color: rgba(0, 0, 0, 0.08);
  background: rgba(0, 0, 0, 0.015);
}

.sub-lane-title {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  margin-bottom: 2px;
}

.sub-lane-title.text-customer { color: var(--color-customer); }
.sub-lane-title.text-blockchain { color: var(--color-blockchain); }
.sub-lane-title.text-admin { color: var(--color-admin); }

.sub-card {
  max-width: 250px !important;
  font-size: 0.76rem;
  padding: 12px;
  flex: 1;
}

.sub-card .card-header { margin-bottom: 6px; }
.sub-card .card-icon { width: 26px; height: 26px; font-size: 0.9rem; }
.sub-card .card-title { font-size: 0.8rem; }
.sub-card .card-body { font-size: 0.72rem; }

.bypass-box {
  border: 1px dashed var(--color-backend);
  background: rgba(16, 185, 129, 0.06);
  border-radius: 8px;
  padding: 15px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 70px;
  width: 100%;
}

body.light-theme .bypass-box {
  background: rgba(5, 150, 105, 0.04);
}

.bypass-badge {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--color-backend);
}

/* Floating Controls */
.canvas-controls {
  position: absolute;
  bottom: 25px;
  left: 25px;
  z-index: 10;
  display: flex;
  gap: 10px;
  background: rgba(15, 23, 42, 0.6);
  backdrop-filter: blur(10px);
  padding: 8px 12px;
  border-radius: 30px;
  border: 1px solid var(--border-color);
}

.canvas-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-primary);
  font-size: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
}

.canvas-btn:hover {
  background: rgba(255, 255, 255, 0.18);
  transform: scale(1.05);
}

.canvas-btn:active {
  transform: scale(0.95);
}

/* Control Side Panel */
.control-panel {
  width: 440px;
  border-left: 1px solid var(--border-color);
  background: rgba(15, 23, 42, 0.5);
  backdrop-filter: blur(20px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 10;
  flex-shrink: 0;
  transition: background-color var(--transition-speed);
}

body.light-theme .control-panel {
  background: rgba(255, 255, 255, 0.75);
}

.panel-header {
  padding: 20px 25px;
  border-bottom: 1px solid var(--border-color);
}

.panel-header h2 {
  font-size: 1.1rem;
  font-weight: 600;
  letter-spacing: 0.5px;
}

.panel-section {
  padding: 20px 25px;
  border-bottom: 1px solid var(--border-color);
}

.panel-section-title {
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 15px;
}

/* Scenario Buttons */
.scenario-grid {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.scenario-btn {
  padding: 12px 16px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  font-family: var(--font-sans);
  text-align: left;
  cursor: pointer;
  transition: all 0.2s ease;
  font-size: 0.88rem;
  font-weight: 500;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.scenario-btn:hover {
  background: rgba(255, 255, 255, 0.08);
  border-color: var(--border-active);
}

.scenario-btn.selected {
  background: var(--color-customer-trans);
  border-color: var(--color-customer);
  color: #fff;
  box-shadow: 0 0 12px rgba(59, 130, 246, 0.2);
}

body.light-theme .scenario-btn.selected {
  background: rgba(37, 99, 235, 0.15);
  color: var(--color-customer);
}

.scenario-tag {
  font-size: 0.65rem;
  padding: 2px 6px;
  border-radius: 4px;
  text-transform: uppercase;
  font-weight: bold;
}

.scenario-tag.tag-success { background: rgba(16, 185, 129, 0.2); color: var(--status-success); }
.scenario-tag.tag-error { background: rgba(239, 68, 68, 0.2); color: var(--status-failed); }
.scenario-tag.tag-admin { background: rgba(245, 158, 11, 0.2); color: var(--status-pending-admin); }

/* Step Navigation buttons */
.simulation-triggers {
  display: flex;
  gap: 12px;
}

.sim-btn {
  flex: 1;
  padding: 12px;
  border-radius: 8px;
  border: none;
  font-family: var(--font-sans);
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: all 0.2s ease;
}

.sim-btn-play {
  background: var(--color-backend);
  color: #fff;
}

.sim-btn-play:hover {
  background: #059669;
  box-shadow: 0 0 15px rgba(16, 185, 129, 0.3);
}

.sim-btn-reset {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
}

.sim-btn-reset:hover {
  background: rgba(255, 255, 255, 0.15);
}

/* Speed Slider styling */
.speed-control {
  font-size: 0.8rem;
  color: var(--text-secondary);
}

/* Console logs */
.console-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 180px;
}

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

.terminal-dots {
  display: flex;
  gap: 6px;
}

.terminal-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}
.terminal-dot:nth-child(1) { background: #ef4444; }
.terminal-dot:nth-child(2) { background: #fbbf24; }
.terminal-dot:nth-child(3) { background: #10b981; }

.terminal-body {
  flex: 1;
  background: #030712;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 15px;
  font-family: var(--font-mono);
  font-size: 0.78rem;
  line-height: 1.5;
  color: #10b981;
  overflow-y: auto;
  box-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.8);
}

.terminal-line {
  margin-bottom: 6px;
  white-space: pre-wrap;
  word-break: break-all;
}

.terminal-line.info { color: #3b82f6; }
.terminal-line.warn { color: #fbbf24; }
.terminal-line.error { color: #ef4444; }
.terminal-line.success { color: #10b981; }
.terminal-line.timestamp { color: var(--text-muted); }

/* Detail panel */
.details-container {
  padding: 20px 25px;
  flex: 1;
  overflow-y: auto;
  border-top: 1px solid var(--border-color);
}

.details-placeholder {
  color: var(--text-muted);
  font-style: italic;
  font-size: 0.85rem;
  text-align: center;
  padding: 20px 0;
}

.details-content h3 {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 12px;
}

.details-tag-row {
  display: flex;
  gap: 8px;
  margin-bottom: 15px;
}

.meta-payload {
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  padding: 12px;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: #e5e7eb;
  overflow-x: auto;
  margin-top: 10px;
}

/* Custom Scrollbar */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}
::-webkit-scrollbar-track {
  background: var(--bg-dark);
}
::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.2);
}

/* Legend Styling - Floating Canvas Legend */
.canvas-legend {
  position: absolute;
  bottom: 25px;
  right: 25px;
  z-index: 10;
  background: rgba(15, 23, 42, 0.6);
  backdrop-filter: blur(10px);
  padding: 12px 18px;
  border-radius: 12px;
  border: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 0.75rem;
  width: 210px;
}

body.light-theme .canvas-legend,
body.light-theme .canvas-controls {
  background: rgba(255, 255, 255, 0.85);
}

.legend-title {
  font-weight: 700;
  text-transform: uppercase;
  color: var(--text-muted);
  letter-spacing: 0.5px;
  margin-bottom: 4px;
}

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

.legend-color {
  width: 12px;
  height: 12px;
  border-radius: 3px;
}

.legend-color.customer { background: var(--color-customer); }
.legend-color.backend { background: var(--color-backend); }
.legend-color.blockchain { background: var(--color-blockchain); }
.legend-color.admin { background: var(--color-admin); }
.legend-color.external { background: var(--color-external); }

.legend-line {
  width: 24px;
  height: 3px;
  border-radius: 2px;
}
.legend-line.user-action { background: var(--color-customer); }
.legend-line.system-process { background: var(--text-secondary); }
.legend-line.data-info { border-bottom: 2.5px dashed var(--text-muted); height: 0; }
.legend-line.blockchain-event { border-bottom: 2.5px dashed var(--color-blockchain); height: 0; }
.legend-line.admin-action { background: var(--color-admin); }

/* Toggle Theme Button */
.theme-toggle-btn {
  margin-left: auto;
  margin-right: 15px;
}
