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

:root {
  --bg: #f5f6f8;
  --card: #ffffff;
  --border: #e2e5ea;
  --text: #1a1a2e;
  --muted: #5a6070;
  --accent: #632CA6;
  --accent-light: #f0e8f8;
  --green: #2e7d32;
  --green-light: #e8f5e9;
  --red: #c62828;
  --orange: #ef6c00;
  --shadow: 0 1px 3px rgba(0,0,0,0.08);
  --radius: 8px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

/* Header */
header {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 10px 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow);
}

h1 { font-size: 16px; font-weight: 700; color: var(--accent); white-space: nowrap; }

.tabs { display: flex; gap: 2px; background: var(--bg); border-radius: 6px; padding: 2px; border: 1px solid var(--border); }
.tab {
  padding: 5px 14px; border: none; background: transparent; cursor: pointer;
  font-size: 13px; font-weight: 500; color: var(--muted); border-radius: 4px; transition: all 0.15s;
}
.tab.active { background: var(--accent); color: white; }

.header-controls { margin-left: auto; display: flex; gap: 8px; }
.preset-buttons { display: flex; gap: 4px; }
.preset-buttons button {
  padding: 5px 10px; border: 1px solid var(--border); border-radius: 5px;
  background: var(--card); cursor: pointer; font-size: 12px; color: var(--muted); transition: all 0.15s;
}
.preset-buttons button:hover { border-color: var(--accent); color: var(--accent); }

/* App Layout */
.app-layout {
  display: grid;
  grid-template-columns: 1fr 320px;
  height: calc(100vh - 52px);
  overflow: hidden;
}

.content-area { overflow-y: auto; padding: 12px; }

.panel { display: none; height: 100%; }
.panel.active { display: flex; flex-direction: column; }

/* Sidebar */
.sidebar {
  border-left: 1px solid var(--border);
  background: var(--card);
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  font-size: 13px;
}

.sb-section { }
.sb-label { font-size: 12px; font-weight: 500; color: var(--muted); display: block; margin-bottom: 4px; }
.sidebar input[type="range"] { width: 100%; accent-color: var(--accent); }

.billing-toggle { display: flex; background: var(--bg); border-radius: 5px; border: 1px solid var(--border); overflow: hidden; }
.billing-toggle button {
  flex: 1; padding: 4px 10px; border: none; background: transparent; cursor: pointer;
  font-size: 12px; font-weight: 500; color: var(--muted); transition: all 0.15s;
}
.billing-toggle button.active { background: var(--accent); color: white; }

.sb-total-card {
  background: var(--accent); color: white; border-radius: var(--radius);
  padding: 14px; text-align: center;
}
.sb-total-label { font-size: 11px; opacity: 0.8; text-transform: uppercase; letter-spacing: 0.5px; }
.sb-total-amount { font-size: 28px; font-weight: 800; font-variant-numeric: tabular-nums; }
.sb-total-annual { font-size: 12px; opacity: 0.8; }

.sb-savings {
  background: var(--green-light); border: 1px solid var(--green); border-radius: var(--radius);
  padding: 8px 12px; font-size: 12px; color: var(--green); text-align: center;
}
.sb-savings span { font-weight: 700; }

.sb-products h5 { font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px; color: var(--muted); margin-bottom: 6px; }

.sb-product {
  display: flex; align-items: center; gap: 6px; padding: 4px 0;
  border-bottom: 1px solid #f0f1f3;
}
.sb-product input[type="checkbox"] { accent-color: var(--accent); flex-shrink: 0; }
.sb-pname { flex: 1; font-size: 12px; }
.sb-sel { font-size: 11px; padding: 1px 2px; border: 1px solid var(--border); border-radius: 3px; background: var(--bg); }
.sb-cost { font-size: 12px; font-weight: 600; color: var(--accent); font-variant-numeric: tabular-nums; white-space: nowrap; min-width: 55px; text-align: right; }

.sb-detail {
  padding: 4px 0 4px 22px; display: flex; gap: 6px; flex-wrap: wrap;
}
.sb-detail label { font-size: 11px; color: var(--muted); display: flex; align-items: center; gap: 3px; }
.sb-detail input { width: 55px; font-size: 11px; padding: 2px 4px; border: 1px solid var(--border); border-radius: 3px; }

.sb-infra h5, .sb-teams h5 { font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px; color: var(--muted); margin-bottom: 4px; }
.sb-row { display: flex; justify-content: space-between; padding: 2px 0; font-size: 12px; }
.sb-row span:last-child { font-weight: 600; font-variant-numeric: tabular-nums; }

.sb-teams .sb-team-row { display: flex; justify-content: space-between; padding: 3px 0; font-size: 12px; border-bottom: 1px solid #f0f1f3; }
.sb-teams .sb-team-row span:first-child { display: flex; align-items: center; gap: 6px; }
.sb-teams .sb-team-row .team-dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.sb-teams .sb-team-row span:last-child { font-weight: 600; }

/* Topology */
#topology-panel .topo-controls {
  display: flex; align-items: center; gap: 10px; padding: 8px 12px;
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 8px;
}
#topology-panel .topo-controls label { font-size: 12px; color: var(--muted); white-space: nowrap; }
#topology-panel .topo-controls input[type="range"] { width: 200px; accent-color: var(--accent); }

#topology {
  flex: 1; width: 100%; min-height: 400px;
  background: #f8f9fb;
  background-image: radial-gradient(circle, #dde 1px, transparent 1px);
  background-size: 20px 20px;
  border: 1px solid var(--border); border-radius: var(--radius);
}

/* D3 topology styles */
.team-bg { fill: rgba(99, 44, 166, 0.04); stroke: var(--border); stroke-width: 1; rx: 8; }
.team-label { font-size: 11px; font-weight: 600; fill: var(--muted); }
.team-info { font-size: 10px; fill: var(--muted); opacity: 0.7; }

.node { cursor: pointer; }
.node-bg { fill: white; stroke: var(--border); stroke-width: 1; rx: 6; filter: drop-shadow(0 1px 2px rgba(0,0,0,0.06)); }
.node:hover .node-bg { stroke: var(--accent); stroke-width: 1.5; }
.node.selected .node-bg { stroke: var(--accent); stroke-width: 2; }
.node-accent { rx: 3; }
.node-name { font-size: 11px; font-weight: 600; fill: var(--text); }
.node-info { font-size: 9px; fill: var(--muted); }
.node-traffic { font-size: 9px; fill: var(--accent); font-weight: 600; }
.node-type-badge { font-size: 8px; fill: white; font-weight: 600; }
.node-type-bg { rx: 3; }

.link { fill: none; stroke: #aab; stroke-width: 1.2; stroke-opacity: 0.5; }
.link.cross-team { stroke-dasharray: 4 3; stroke: var(--accent); stroke-opacity: 0.4; }
.link.highlighted { stroke-opacity: 0.9; stroke-width: 2; stroke: var(--accent); }
.link.dimmed { stroke-opacity: 0.1; }
.link-arrow { fill: #aab; }

.service-detail {
  margin-top: 8px; padding: 12px; background: var(--card);
  border: 1px solid var(--border); border-radius: var(--radius);
  font-size: 12px; display: none;
}
.service-detail.visible { display: block; }
.service-detail h4 { font-size: 14px; margin-bottom: 8px; }
.sd-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; }
.sd-item { background: var(--bg); padding: 6px 8px; border-radius: 4px; }
.sd-item .sd-label { font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.3px; }
.sd-item .sd-value { font-size: 14px; font-weight: 600; }

/* Config / YAML */
#config-panel { padding: 0; }
#yamlEditor {
  flex: 1; width: 100%; border: 1px solid var(--border); border-radius: var(--radius);
  font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace; font-size: 13px;
  padding: 12px; line-height: 1.6; resize: none; background: #1e1e2e; color: #cdd6f4;
  tab-size: 2;
}
#yamlEditor:focus { outline: none; border-color: var(--accent); }
.yaml-error {
  display: none; padding: 8px 12px; background: #ffebee; color: var(--red);
  border-radius: 0 0 var(--radius) var(--radius); font-size: 12px; font-family: monospace;
}
.yaml-error.visible { display: block; }

/* Calculator / Dimensions */
.dim-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 10px; margin-bottom: 16px;
}
.dim-card {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 12px;
}
.dim-card h4 { font-size: 13px; font-weight: 600; color: var(--accent); margin: 0; }
.dim-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.dim-cost { font-size: 15px; font-weight: 700; color: var(--accent); white-space: nowrap; }
.dim-breakdown { font-size: 11px; color: var(--muted); line-height: 1.6; }

/* Price-sheet tables inside dim cards */
.ps { width: 100%; border-collapse: collapse; font-size: 11px; margin-bottom: 6px; background: var(--bg); border-radius: 4px; }
.ps thead th { text-align: left; font-size: 10px; text-transform: uppercase; letter-spacing: 0.3px; color: var(--muted); padding: 4px 8px; border-bottom: 1px solid var(--border); }
.ps thead th:last-child { text-align: right; }
.ps td { padding: 2px 8px; border-bottom: 1px solid #eee; }
.ps td:last-child { text-align: right; font-variant-numeric: tabular-nums; }
.ps tr.ps-calc { background: var(--accent-light); }
.ps tr.ps-calc td { font-weight: 600; padding: 4px 8px; border-bottom: 1px solid var(--accent); border-top: 1px solid var(--accent); }
.ps tr.ps-total td { font-weight: 700; padding: 5px 8px; border-top: 2px solid var(--border); font-size: 12px; }

.ps-note { font-size: 10px; color: var(--muted); margin-top: 6px; padding: 5px 8px; background: #f0f1f3; border-radius: 3px; line-height: 1.5; border-left: 3px solid var(--accent); }
.ps-contrib { font-size: 10px; color: var(--muted); margin: 4px 0; }

/* Analysis */
.analysis-section { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 4px; }
.analysis-card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; }
.analysis-card h4 { font-size: 13px; font-weight: 600; margin-bottom: 8px; }
.input-row { display: flex; gap: 10px; margin-top: 6px; }
.input-group { flex: 1; }
.input-group label { display: block; font-size: 11px; font-weight: 500; color: var(--muted); margin-bottom: 3px; }
.input-group input, .input-group select {
  width: 100%; padding: 5px 8px; border: 1px solid var(--border); border-radius: 5px;
  font-size: 13px; font-family: inherit; background: var(--bg);
}
.input-group input:focus, .input-group select:focus { outline: none; border-color: var(--accent); }
.hint { font-size: 11px; color: var(--muted); margin-bottom: 8px; }
.growth-summary { margin-top: 8px; font-size: 12px; color: var(--muted); padding: 8px; background: var(--bg); border-radius: 5px; }

#hwmResults { margin-top: 10px; padding: 10px; background: var(--bg); border-radius: 5px; }
.hwm-explain { font-size: 12px; color: var(--muted); margin-bottom: 8px; padding-bottom: 8px; border-bottom: 1px solid var(--border); line-height: 1.5; }
.hwm-row { display: flex; justify-content: space-between; padding: 3px 0; font-size: 12px; }
.hwm-row.highlight { font-weight: 700; color: var(--red); border-top: 1px solid var(--border); padding-top: 6px; margin-top: 3px; }
.hwm-row.good { color: var(--green); font-weight: 600; }

/* Shared table */
.sb-section table { width: 100%; border-collapse: collapse; font-size: 12px; }
.sb-section th { text-align: left; font-size: 10px; text-transform: uppercase; letter-spacing: 0.3px; color: var(--muted); padding: 3px 0; border-bottom: 1px solid var(--border); }
.sb-section th:last-child, .sb-section td:last-child { text-align: right; }
.sb-section td { padding: 3px 0; border-bottom: 1px solid #f0f1f3; font-variant-numeric: tabular-nums; }
.sb-section tr:last-child td { font-weight: 700; border-top: 2px solid var(--border); border-bottom: none; }

footer { padding: 12px 20px; text-align: center; font-size: 11px; color: var(--muted); }

@media (max-width: 1024px) {
  .app-layout { grid-template-columns: 1fr; height: auto; }
  .sidebar { border-left: none; border-top: 1px solid var(--border); }
  .analysis-section { grid-template-columns: 1fr; }
}
