/* ===== CSS Custom Properties ===== */
:root {
  --bg-primary: #07090f;
  --bg-card: #0f1219;
  --bg-card-hover: #151a24;
  --bg-elevated: #1a1f2e;
  --accent-red: #ef4444;
  --accent-amber: #f59e0b;
  --accent-purple: #8b5cf6;
  --accent-green: #22c55e;
  --accent-pink: #ec4899;
  --accent-indigo: #6366f1;
  --accent-orange: #f97316;
  --accent-teal: #14b8a6;
  --accent-slate: #64748b;
  --text-primary: #e2e8f0;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --border-color: #1e293b;
  --border-subtle: #151b28;
  --font-display: 'Syne', sans-serif;
  --font-body: 'Outfit', sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  --shadow-glow-red: 0 0 20px rgba(239, 68, 68, 0.15);
  --shadow-glow-amber: 0 0 20px rgba(245, 158, 11, 0.15);
  --transition-fast: 150ms ease;
  --transition-base: 250ms ease;
  --transition-slow: 400ms ease;
}

/* ===== Reset & Base ===== */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

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

/* ===== Scrollbar ===== */
::-webkit-scrollbar {
  width: 6px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

/* ===== Input View ===== */
.input-view {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(ellipse at center, rgba(239, 68, 68, 0.04) 0%, transparent 60%),
              var(--bg-primary);
  z-index: 10;
  transition: opacity var(--transition-slow), visibility var(--transition-slow);
}

.input-view.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.input-card {
  width: 100%;
  max-width: 720px;
  padding: 48px;
  animation: fadeSlideUp 0.6s ease both;
}

@keyframes fadeSlideUp {
  from {
    opacity: 0;
    transform: translateY(24px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ===== Logo ===== */
.logo {
  display: flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
  cursor: pointer;
}

.logo-icon {
  width: 32px;
  height: 32px;
  flex-shrink: 0;
}

.logo-text {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 1.5rem;
  color: var(--text-primary);
  letter-spacing: -0.02em;
}

.logo-text .accent {
  color: var(--accent-red);
}

.input-logo {
  justify-content: center;
  margin-bottom: 8px;
}

.input-logo .logo-text {
  font-size: 2.25rem;
}

.tagline {
  text-align: center;
  color: var(--text-muted);
  font-size: 1rem;
  margin-bottom: 36px;
  font-family: var(--font-body);
}

/* ===== Textarea ===== */
.input-textarea {
  width: 100%;
  min-height: 300px;
  padding: 20px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 0.85rem;
  line-height: 1.7;
  resize: vertical;
  transition: border-color var(--transition-base), box-shadow var(--transition-base);
  outline: none;
}

.input-textarea::placeholder {
  color: var(--text-muted);
  font-family: var(--font-body);
  font-size: 0.95rem;
}

.input-textarea:focus {
  border-color: var(--accent-red);
  box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.1);
}

.input-textarea.scanning {
  border-color: var(--accent-red);
  animation: borderPulse 1.5s ease-in-out infinite;
}

@keyframes borderPulse {
  0%, 100% { box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.08); }
  50% { box-shadow: 0 0 0 6px rgba(239, 68, 68, 0.15); }
}

/* ===== Buttons ===== */
.btn-row {
  display: flex;
  gap: 12px;
  margin-top: 20px;
  align-items: center;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 12px 24px;
  border: none;
  border-radius: var(--radius-md);
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  transition: all var(--transition-fast);
  outline: none;
  white-space: nowrap;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--accent-red);
  color: white;
}

.btn-primary:hover:not(:disabled) {
  background: #dc2626;
  box-shadow: 0 0 24px rgba(239, 68, 68, 0.3);
}

.btn-secondary {
  background: var(--bg-elevated);
  color: var(--text-secondary);
  border: 1px solid var(--border-color);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--bg-card-hover);
  color: var(--text-primary);
  border-color: var(--text-muted);
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  padding: 8px 12px;
}

.btn-ghost:hover {
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.05);
}

.btn-sm {
  padding: 6px 14px;
  font-size: 0.8rem;
}

.scan-hint {
  color: var(--text-muted);
  font-size: 0.8rem;
  margin-left: auto;
}

.scan-hint kbd {
  background: var(--bg-elevated);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  border: 1px solid var(--border-color);
}

/* ===== Scanning spinner ===== */
.scan-spinner {
  display: inline-block;
  width: 18px;
  height: 18px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ===== Graph View ===== */
.graph-view {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  opacity: 0;
  visibility: hidden;
  transition: opacity var(--transition-slow), visibility var(--transition-slow);
}

.graph-view.active {
  opacity: 1;
  visibility: visible;
}

/* ===== Top Bar ===== */
.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  background: rgba(15, 18, 25, 0.9);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-subtle);
  z-index: 100;
  flex-shrink: 0;
}

.top-bar-left .logo-text {
  font-size: 1.15rem;
}

.top-bar-center {
  font-family: var(--font-body);
  font-weight: 500;
  color: var(--text-secondary);
  font-size: 0.9rem;
  text-align: center;
  flex: 1;
  padding: 0 16px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.top-bar-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.risk-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px;
  border-radius: 20px;
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.risk-badge.low { background: rgba(34, 197, 94, 0.12); color: var(--accent-green); }
.risk-badge.medium { background: rgba(245, 158, 11, 0.12); color: var(--accent-amber); }
.risk-badge.high { background: rgba(239, 68, 68, 0.12); color: var(--accent-red); }
.risk-badge.critical {
  background: rgba(239, 68, 68, 0.15);
  color: var(--accent-red);
  animation: criticalPulse 2s ease-in-out infinite;
}

@keyframes criticalPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.2); }
  50% { box-shadow: 0 0 12px 2px rgba(239, 68, 68, 0.3); }
}

.node-count {
  color: var(--text-muted);
  font-size: 0.82rem;
  font-family: var(--font-mono);
}

/* ===== Graph Main Area ===== */
.graph-main {
  display: flex;
  flex: 1;
  position: relative;
  overflow: hidden;
}

/* ===== Side Panel ===== */
.side-panel {
  width: 350px;
  min-width: 350px;
  background: rgba(15, 18, 25, 0.95);
  backdrop-filter: blur(12px);
  border-right: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  z-index: 50;
  overflow: hidden;
  transition: margin-left var(--transition-base), min-width var(--transition-base), width var(--transition-base);
}

.side-panel.collapsed {
  margin-left: -350px;
  min-width: 0;
  width: 0;
}

.side-panel-inner {
  overflow-y: auto;
  flex: 1;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.panel-toggle {
  position: absolute;
  left: 350px;
  top: 50%;
  transform: translateY(-50%);
  z-index: 51;
  width: 24px;
  height: 48px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-left: none;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: left var(--transition-base), color var(--transition-fast), background var(--transition-fast);
}

.panel-toggle:hover {
  color: var(--text-primary);
  background: var(--bg-elevated);
}

.side-panel.collapsed + .panel-toggle {
  left: 0;
}

.panel-toggle svg {
  width: 14px;
  height: 14px;
  transition: transform var(--transition-base);
}

.side-panel.collapsed + .panel-toggle svg {
  transform: rotate(180deg);
}

/* ===== Panel Cards ===== */
.panel-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 14px;
}

.panel-card-title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 10px;
}

.assessment-text {
  font-size: 0.88rem;
  line-height: 1.6;
  color: var(--text-secondary);
}

/* ===== Legend ===== */
.legend-section {
  margin-bottom: 8px;
}

.legend-label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.legend-items {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 0.75rem;
  color: var(--text-secondary);
}

.legend-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.legend-line {
  width: 16px;
  height: 2px;
  border-radius: 1px;
  flex-shrink: 0;
}

/* ===== Node List ===== */
.node-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

/* Grouped node list */
.node-list-group {
  margin-bottom: 2px;
}

.node-list-group-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: background var(--transition-fast);
}

.node-list-group-header:hover {
  background: rgba(255, 255, 255, 0.03);
}

.node-list-group-title {
  flex: 1;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.node-list-group-count {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--text-muted);
}

.node-list-chevron {
  width: 14px;
  height: 14px;
  color: var(--text-muted);
  transition: transform var(--transition-base);
  flex-shrink: 0;
}

.node-list-group.collapsed .node-list-chevron {
  transform: rotate(-90deg);
}

.node-list-group-items {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding-left: 18px;
  max-height: 2000px;
  overflow: hidden;
  transition: max-height 0.3s ease, padding 0.2s ease;
}

.node-list-group.collapsed .node-list-group-items {
  max-height: 0;
  padding: 0 0 0 18px;
}

.node-type-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.node-list-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.node-list-item:hover {
  background: var(--bg-card-hover);
  border-color: var(--text-muted);
}

.node-list-item.highlighted {
  border-color: var(--accent-red);
  box-shadow: 0 0 8px rgba(239, 68, 68, 0.15);
}

.node-list-title {
  flex: 1;
  font-size: 0.82rem;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.severity-badge {
  font-size: 0.68rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 10px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  flex-shrink: 0;
}

.severity-badge.critical { background: rgba(239, 68, 68, 0.15); color: var(--accent-red); }
.severity-badge.high { background: rgba(249, 115, 22, 0.15); color: var(--accent-orange); }
.severity-badge.medium { background: rgba(245, 158, 11, 0.15); color: var(--accent-amber); }
.severity-badge.low { background: rgba(100, 116, 139, 0.15); color: var(--accent-slate); }

/* ===== Stats ===== */
.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.stat-item {
  text-align: center;
  padding: 8px;
  background: var(--bg-primary);
  border-radius: var(--radius-sm);
}

.stat-value {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 1.3rem;
  color: var(--text-primary);
}

.stat-label {
  font-size: 0.7rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.mini-bar {
  display: flex;
  height: 6px;
  border-radius: 3px;
  overflow: hidden;
  margin-top: 10px;
  background: var(--bg-primary);
}

.mini-bar-segment {
  height: 100%;
  transition: width var(--transition-base);
}

/* ===== Graph Controls ===== */
.graph-controls {
  position: absolute;
  top: 16px;
  right: 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  z-index: 30;
}

.graph-controls .btn-ghost {
  background: rgba(15, 18, 25, 0.85);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  width: 38px;
  height: 38px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.graph-controls .btn-ghost svg {
  width: 16px;
  height: 16px;
}

/* ===== Graph Container ===== */
.graph-container {
  flex: 1;
  position: relative;
  overflow: hidden;
  background: var(--bg-primary);
}

.graph-container svg {
  width: 100%;
  height: 100%;
  display: block;
}

/* ===== Toast System ===== */
.toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 10000;
  display: flex;
  flex-direction: column-reverse;
  gap: 8px;
}

.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 18px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  font-size: 0.85rem;
  color: var(--text-primary);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
  animation: toastIn 0.3s ease both;
  max-width: 380px;
}

.toast.removing {
  animation: toastOut 0.3s ease both;
}

.toast-icon {
  flex-shrink: 0;
  width: 18px;
  height: 18px;
}

.toast.success { border-left: 3px solid var(--accent-green); }
.toast.success .toast-icon { color: var(--accent-green); }
.toast.error { border-left: 3px solid var(--accent-red); }
.toast.error .toast-icon { color: var(--accent-red); }
.toast.info { border-left: 3px solid var(--accent-indigo); }
.toast.info .toast-icon { color: var(--accent-indigo); }

@keyframes toastIn {
  from { opacity: 0; transform: translateX(40px); }
  to { opacity: 1; transform: translateX(0); }
}

@keyframes toastOut {
  from { opacity: 1; transform: translateX(0); }
  to { opacity: 0; transform: translateX(40px); }
}

/* ===== Tooltip ===== */
.graph-tooltip {
  position: fixed;
  padding: 8px 14px;
  background: rgba(15, 18, 25, 0.95);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  color: var(--text-primary);
  pointer-events: none;
  z-index: 200;
  max-width: 280px;
  opacity: 0;
  transition: opacity var(--transition-fast);
}

.graph-tooltip.visible {
  opacity: 1;
}

.graph-tooltip .tt-title {
  font-weight: 600;
  margin-bottom: 2px;
}

.graph-tooltip .tt-meta {
  font-size: 0.72rem;
  color: var(--text-muted);
}

/* ===== Responsive ===== */
@media (max-width: 1024px) {
  .side-panel {
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    z-index: 60;
    box-shadow: 8px 0 32px rgba(0, 0, 0, 0.5);
  }
  .side-panel.collapsed {
    margin-left: -350px;
  }
  .panel-toggle {
    left: 0;
  }
  .side-panel:not(.collapsed) + .panel-toggle {
    left: 350px;
  }
}

@media (max-width: 768px) {
  .input-card {
    padding: 24px 16px;
  }

  .input-logo .logo-text {
    font-size: 1.6rem;
  }

  .input-textarea {
    min-height: 220px;
  }

  .btn-row {
    flex-wrap: wrap;
  }

  .scan-hint {
    margin-left: 0;
    width: 100%;
    text-align: center;
    margin-top: 4px;
  }

  .top-bar {
    padding: 10px 12px;
  }

  .top-bar-center {
    font-size: 0.78rem;
  }

  /* Hide graph, show only sidebar list */
  .graph-container {
    display: none !important;
  }

  .graph-controls {
    display: none !important;
  }

  .side-panel {
    position: relative !important;
    width: 100% !important;
    min-width: 0 !important;
    flex: 1;
    border-right: none;
    margin-left: 0 !important;
    max-height: none;
    border-radius: 0;
    box-shadow: none;
  }

  .side-panel.collapsed {
    margin-left: 0 !important;
    transform: none;
  }

  .panel-toggle {
    display: none !important;
  }
}
