:root {
  --bg: #f5f7fa;
  --panel-bg: #ffffff;
  --border: #d1d5db;
  --text: #1f2937;
  --text-muted: #6b7280;
  --accent: #2563eb;

  /* Node type colors */
  --vpc-header: #1e40af;
  --vpc-bg: #eff6ff;
  --vpc-border: #93c5fd;

  --tgw-header: #b45309;
  --tgw-bg: #fffbeb;
  --tgw-border: #fcd34d;

  --ext-tgw-header: #0e7490;
  --ext-tgw-bg: #ecfeff;
  --ext-tgw-border: #67e8f9;

  --ext-vpc-header: #9333ea;
  --ext-vpc-bg: #faf5ff;
  --ext-vpc-border: #c4b5fd;

  /* Subnet category colors */
  --cat-public-edge: #059669;
  --cat-security: #dc2626;
  --cat-cloud-native: #2563eb;
  --cat-platform: #7c3aed;
  --cat-dmz: #d97706;
  --cat-private-app: #0891b2;
  --cat-application: #4f46e5;
  --cat-default: #6b7280;

  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

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

body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.app-header {
  background: var(--panel-bg);
  border-bottom: 1px solid var(--border);
  padding: 10px 20px;
  flex-shrink: 0;
}
.header-content { display: flex; justify-content: space-between; align-items: center; }
h1 { font-size: 1.1rem; font-weight: 700; color: var(--text); }
.metadata { font-family: var(--font-mono); font-size: 0.7rem; color: var(--text-muted); }

.toolbar {
  display: flex; justify-content: space-between; align-items: center;
  padding: 6px 20px;
  background: var(--panel-bg);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.toolbar-left { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.toolbar-right { display: flex; gap: 4px; }

.summary-badges { display: flex; gap: 6px; flex-wrap: wrap; }
.summary-badge {
  font-size: 0.7rem; font-weight: 600;
  padding: 2px 8px; border-radius: 10px;
  background: #e0e7ff; color: #3730a3;
}

.tool-btn {
  width: 28px; height: 28px;
  background: var(--panel-bg); border: 1px solid var(--border);
  border-radius: 4px; cursor: pointer;
  font-size: 1rem; display: flex; align-items: center; justify-content: center;
  color: var(--text);
}
.tool-btn:hover { background: #e5e7eb; border-color: var(--accent); }

.vpc-filter-btn {
  width: auto;
  padding: 0 10px;
  font-size: 0.72rem;
  font-weight: 600;
  gap: 4px;
  white-space: nowrap;
}

.canvas-wrap {
  flex: 1; overflow: hidden; position: relative;
  cursor: grab;
}
.canvas-wrap:active { cursor: grabbing; }

.canvas {
  width: 100%; height: 100%;
  position: relative;
}

#diagram-svg {
  width: 100%; height: 100%;
  position: absolute; top: 0; left: 0;
}

/* Detail Panel */
.detail-panel {
  position: fixed; right: 0; top: 0; bottom: 0;
  width: 380px; background: var(--panel-bg);
  border-left: 1px solid var(--border);
  box-shadow: -4px 0 12px rgba(0,0,0,0.08);
  z-index: 100; display: flex; flex-direction: column;
  transition: transform 0.2s ease;
}
.detail-panel.hidden { transform: translateX(100%); }
.panel-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 16px; border-bottom: 1px solid var(--border);
  font-weight: 700; font-size: 0.9rem;
}
.panel-close-btn {
  background: none; border: none; cursor: pointer;
  font-size: 1.1rem; color: var(--text-muted);
}
.panel-close-btn:hover { color: var(--text); }
.panel-body { flex: 1; overflow-y: auto; padding: 12px 16px; font-size: 0.82rem; }

.panel-section { margin-bottom: 16px; }
.panel-section-title {
  font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--text-muted); margin-bottom: 6px; font-weight: 600;
  border-bottom: 1px solid #e5e7eb; padding-bottom: 3px;
}
.panel-row { display: flex; justify-content: space-between; margin-bottom: 3px; gap: 8px; }
.panel-label { color: var(--text-muted); white-space: nowrap; }
.panel-value { font-family: var(--font-mono); text-align: right; word-break: break-all; font-size: 0.78rem; }

.panel-badge-list { display: flex; flex-wrap: wrap; gap: 4px; }
.panel-badge {
  font-size: 0.65rem; font-family: var(--font-mono);
  padding: 1px 6px; border-radius: 3px;
  background: #f3f4f6; border: 1px solid #e5e7eb;
}

.subnet-mini {
  background: #f9fafb; border: 1px solid #e5e7eb;
  border-radius: 4px; padding: 6px 8px; margin-bottom: 6px;
}
.subnet-mini-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 2px; }
.subnet-mini-name { font-weight: 600; font-size: 0.78rem; }
.subnet-mini-badge {
  font-size: 0.6rem; padding: 1px 5px; border-radius: 3px;
  font-weight: 600;
}
.subnet-mini-badge.public { background: #d1fae5; color: #065f46; }
.subnet-mini-badge.private { background: #fee2e2; color: #991b1b; }

/* Legend */
.legend {
  position: fixed; bottom: 16px; left: 16px;
  background: var(--panel-bg); border: 1px solid var(--border);
  border-radius: 6px; padding: 10px 14px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
  z-index: 50; font-size: 0.72rem;
}
.legend-title { font-weight: 700; margin-bottom: 6px; font-size: 0.75rem; }
.legend-items { display: flex; flex-direction: column; gap: 3px; }
.legend-row { display: flex; align-items: center; gap: 6px; }
.legend-swatch {
  width: 14px; height: 14px; border-radius: 3px; border: 1px solid rgba(0,0,0,0.1);
  flex-shrink: 0;
}
.legend-divider { height: 1px; background: #e5e7eb; margin: 4px 0; }
.legend-subtitle { font-weight: 600; font-size: 0.68rem; color: #6b7280; margin-top: 2px; }

/* Tooltip */
.tooltip {
  position: fixed; z-index: 200;
  background: white; border: 1px solid #d1d5db;
  border-radius: 6px; padding: 0;
  box-shadow: 0 4px 16px rgba(0,0,0,0.12);
  font-size: 0.78rem; max-width: 320px;
  pointer-events: none;
  animation: tipIn 0.12s ease;
}
@keyframes tipIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }
.tip-header { padding: 8px 10px; border-bottom: 1px solid #f3f4f6; }
.tip-name { font-weight: 700; font-size: 0.82rem; }
.tip-meta { font-size: 0.7rem; color: #6b7280; font-family: var(--font-mono); margin-top: 2px; }
.tip-section { padding: 6px 10px; }
.tip-label { font-size: 0.65rem; text-transform: uppercase; color: #9ca3af; font-weight: 600; margin-bottom: 3px; }
.tip-route { font-family: var(--font-mono); font-size: 0.7rem; color: #374151; padding: 1px 0; }
.tip-muted { font-size: 0.7rem; color: #9ca3af; }

/* SVG styles */
.node-group { cursor: pointer; }
.node-group:hover .node-box { filter: brightness(0.97); }
.subnet-group { cursor: pointer; }
.subnet-group:hover .subnet-rect { filter: brightness(0.94); stroke-width: 1.5; }
.node-box { transition: filter 0.15s; }
.node-header-text { font-family: var(--font-sans); font-weight: 700; fill: white; }
.node-body-text { font-family: var(--font-mono); fill: var(--text); }
.node-subtitle-text { font-family: var(--font-mono); fill: var(--text-muted); }

.subnet-rect { rx: 3; ry: 3; }
.subnet-label { font-family: var(--font-sans); font-size: 9px; }
.subnet-cidr { font-family: var(--font-mono); font-size: 8px; fill: var(--text-muted); }

.az-label { font-family: var(--font-sans); font-weight: 600; font-size: 10px; fill: var(--text-muted); }

.edge-line {
  fill: none; stroke: #9ca3af; stroke-width: 1.5;
}
.edge-line.attachment { stroke: #6366f1; stroke-width: 2; }
.edge-line.peering { stroke: #0891b2; stroke-width: 1.5; stroke-dasharray: 6 3; }
.edge-line.vpc-peering { stroke: #a855f7; stroke-width: 1.5; stroke-dasharray: 4 4; }

.edge-label-bg { fill: white; }
.edge-label-text { font-family: var(--font-mono); font-size: 8px; fill: var(--text-muted); }

.edge-arrow { fill: #9ca3af; }
.edge-arrow.attachment { fill: #6366f1; }
.edge-arrow.peering { fill: #0891b2; }
.edge-arrow.vpc-peering { fill: #a855f7; }

.selected .node-box { stroke-width: 3; stroke: var(--accent); }

/* TGW Route Table expand/collapse */
.rt-expand-btn {
  background: none; border: 1px solid #fcd34d; border-radius: 4px;
  padding: 3px 8px; cursor: pointer; font-size: 0.72rem; font-weight: 600;
  color: #92400e; background: #fffbeb;
  transition: background 0.15s;
}
.rt-expand-btn:hover { background: #fef3c7; }

.rt-table {
  width: 100%; border-collapse: collapse; margin-top: 6px; font-size: 0.7rem;
}
.rt-table th {
  text-align: left; font-size: 0.62rem; text-transform: uppercase;
  letter-spacing: 0.04em; color: #9ca3af; padding: 3px 4px;
  border-bottom: 1px solid #e5e7eb; font-weight: 600;
}
.rt-table td {
  padding: 4px; border-bottom: 1px solid #f3f4f6; vertical-align: top;
}
.rt-dest { font-family: var(--font-mono); font-weight: 600; font-size: 0.72rem; color: #1f2937; }
.rt-target { font-family: var(--font-mono); font-size: 0.65rem; color: #6b7280; word-break: break-all; }
.rt-type-badge { font-size: 0.65rem; font-weight: 600; }

/* Route target link */
.rt-target-link {
  color: #2563eb; text-decoration: none; cursor: pointer;
  font-family: var(--font-mono); font-size: 0.65rem;
  border-bottom: 1px dashed #93c5fd;
  transition: color 0.15s;
}
.rt-target-link:hover { color: #1d4ed8; border-bottom-color: #2563eb; }

/* Highlight pulse on SVG node */
@keyframes nodePulse {
  0%   { stroke-opacity: 1; stroke-width: 4; }
  50%  { stroke-opacity: 0.4; stroke-width: 6; }
  100% { stroke-opacity: 1; stroke-width: 4; }
}
.node-group.highlight-pulse .node-box {
  stroke: #ef4444;
  stroke-width: 4;
  animation: nodePulse 0.5s ease-in-out 3;
}

/* Route Trace UI */
.trace-input-row {
  display: flex; gap: 6px; margin-bottom: 10px;
}
.trace-input {
  flex: 1; padding: 6px 10px; border: 1px solid #d1d5db; border-radius: 4px;
  font-family: var(--font-mono); font-size: 0.8rem; background: #f9fafb;
  color: var(--text);
}
.trace-input:focus { outline: none; border-color: #2563eb; background: white; }
.trace-btn {
  padding: 6px 14px; background: #2563eb; color: white; border: none;
  border-radius: 4px; font-size: 0.78rem; font-weight: 600; cursor: pointer;
  white-space: nowrap;
}
.trace-btn:hover { background: #1d4ed8; }

.trace-path { display: flex; flex-direction: column; gap: 0; }
.trace-step {
  display: flex; align-items: flex-start; gap: 8px;
  padding: 8px 10px; background: #f9fafb; border: 1px solid #e5e7eb;
  border-radius: 6px; transition: background 0.15s;
}
.trace-step:hover { background: #eff6ff; }
.trace-icon { font-size: 1rem; flex-shrink: 0; margin-top: 1px; }
.trace-step-body { flex: 1; min-width: 0; }
.trace-step-label { font-weight: 700; font-size: 0.78rem; color: #1f2937; }
.trace-step-detail {
  font-family: var(--font-mono); font-size: 0.7rem; color: #6b7280;
  word-break: break-all; margin-top: 1px;
}
.trace-arrow {
  text-align: center; color: #9ca3af; font-size: 0.85rem;
  padding: 2px 0; line-height: 1;
}
.trace-error {
  padding: 8px; background: #fef2f2; border: 1px solid #fecaca;
  border-radius: 4px; color: #991b1b; font-size: 0.78rem;
}

/* Upload Overlay */
.upload-overlay {
  position: fixed; inset: 0; z-index: 500;
  background: rgba(249,250,251,0.95);
  display: flex; align-items: center; justify-content: center;
}
.upload-box {
  background: white; border: 2px dashed #d1d5db; border-radius: 12px;
  padding: 48px 64px; text-align: center;
  transition: border-color 0.2s, background 0.2s;
}
.upload-box.drag-over { border-color: #2563eb; background: #eff6ff; }
.upload-icon { font-size: 3rem; margin-bottom: 12px; }
.upload-title { font-size: 1.2rem; font-weight: 700; color: #1f2937; margin-bottom: 6px; }
.upload-hint { font-size: 0.85rem; color: #6b7280; }
.upload-hint code { background: #f3f4f6; padding: 2px 6px; border-radius: 3px; font-size: 0.8rem; }
.upload-or { color: #9ca3af; font-size: 0.8rem; margin: 12px 0; }
.upload-btn {
  display: inline-block; padding: 8px 20px;
  background: #2563eb; color: white; border-radius: 6px;
  font-size: 0.85rem; font-weight: 600; cursor: pointer;
  transition: background 0.15s;
}
.upload-btn:hover { background: #1d4ed8; }

/* Upload help section */
.upload-help {
  margin-top: 20px; text-align: left; max-width: 600px;
}
.upload-help summary {
  cursor: pointer; font-size: 0.82rem; color: #2563eb; font-weight: 600;
  text-align: center;
}
.upload-help summary:hover { text-decoration: underline; }
.upload-help-body {
  margin-top: 12px; font-size: 0.78rem; color: #374151; line-height: 1.6;
}
.upload-help-body p { margin: 10px 0 4px; font-weight: 600; }
.upload-help-body pre {
  background: #1f2937; color: #e5e7eb; padding: 10px 14px;
  border-radius: 6px; font-size: 0.72rem; overflow-x: auto;
  line-height: 1.5; font-family: var(--font-mono);
  white-space: pre-wrap; word-break: break-all;
}
.upload-help-body code {
  background: #f3f4f6; padding: 1px 5px; border-radius: 3px;
  font-size: 0.75rem;
}

/* Route 53 */
.r53-group-label {
  font-size: 0.72rem;
  font-weight: 700;
  color: #374151;
  margin: 8px 0 4px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.r53-shared-to {
  margin-top: 4px;
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  align-items: center;
}
.r53-shared-label {
  font-size: 0.68rem;
  font-weight: 600;
  color: #7c3aed;
}

/* VPC Panel Summary */
.vpc-summary {
  padding: 4px 0 8px;
  border-bottom: 1px solid #e5e7eb;
  margin-bottom: 6px;
}
.vpc-summary-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 2px 0;
  font-size: 0.78rem;
}
.vpc-summary-label {
  color: #6b7280;
  font-weight: 500;
  min-width: 60px;
}
.vpc-summary-val {
  color: #111827;
  text-align: right;
  flex: 1;
  margin-left: 8px;
}
.vpc-summary-val.mono {
  font-family: var(--font-mono);
  font-size: 0.72rem;
}
.vpc-stat-sub {
  color: #9ca3af;
  font-size: 0.7rem;
}

/* Accordion */
.acc-header {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 4px;
  margin: 0;
  font-size: 0.8rem;
  font-weight: 600;
  color: #1f2937;
  cursor: pointer;
  border-bottom: 1px solid #f3f4f6;
  user-select: none;
  transition: background 0.15s;
}
.acc-header:hover {
  background: #f9fafb;
  border-radius: 4px;
}
.acc-header.nested {
  font-size: 0.74rem;
  font-weight: 500;
  color: #374151;
  padding: 6px 4px 6px 8px;
  border-bottom: 1px solid #f9fafb;
}
.acc-arrow {
  font-size: 0.65rem;
  color: #9ca3af;
  width: 12px;
  text-align: center;
  flex-shrink: 0;
}
.acc-body {
  padding: 2px 0 4px 4px;
}

/* Accordion items */
.acc-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 6px;
  border-radius: 4px;
  transition: background 0.12s;
}
.acc-item:hover {
  background: #f9fafb;
}
.acc-item-icon {
  font-size: 0.85rem;
  flex-shrink: 0;
}
.acc-item-name {
  font-size: 0.76rem;
  font-weight: 600;
  color: #1f2937;
  line-height: 1.3;
}
.acc-item-meta {
  font-size: 0.68rem;
  color: #6b7280;
  line-height: 1.3;
}
.acc-item-meta.mono {
  font-family: var(--font-mono);
}
.acc-item-count {
  font-size: 0.65rem;
  font-weight: 400;
  color: #9ca3af;
  margin-left: 4px;
}

/* Subnet items in accordion */
.acc-subnet {
  padding: 4px 8px;
  margin: 2px 0;
  border-radius: 4px;
  transition: background 0.12s;
}
.acc-subnet:hover {
  background: #f9fafb;
}
.acc-subnet-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

/* LB stats bar */
.acc-lb-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 4px 6px 8px;
}
.acc-lb-tag {
  font-size: 0.65rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 10px;
}
.acc-lb-tag.alb { background: #dbeafe; color: #1e40af; }
.acc-lb-tag.nlb { background: #d1fae5; color: #065f46; }
.acc-lb-tag.pub { background: #fef3c7; color: #92400e; }
.acc-lb-tag.prv { background: #f3f4f6; color: #374151; }
