:root {
  --bg-primary: #0f172a;
  --bg-secondary: #1e293b;
  --bg-tertiary: #334155;
  --bg-card: #1a2332;
  --text-primary: #e2e8f0;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --accent-light: rgba(59, 130, 246, 0.15);
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --border: #334155;
  --border-light: #475569;
  --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.3);
  --radius: 8px;
  --radius-sm: 4px;
  --transition: 0.2s ease;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  overflow: hidden;
  height: 100vh;
}

.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 24px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  height: 56px;
  flex-shrink: 0;
}

.header h1 {
  font-size: 1.25rem;
  font-weight: 600;
  background: linear-gradient(135deg, var(--accent), #8b5cf6);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.header-actions { display: flex; gap: 8px; }

.main-container {
  display: grid;
  grid-template-columns: 300px 1fr 340px;
  height: calc(100vh - 56px);
  overflow: hidden;
}

.sidebar {
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.sidebar-right {
  border-right: none;
  border-left: 1px solid var(--border);
}

.panel {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
}

.panel-title {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.form-group {
  margin-bottom: 12px;
}

.form-group label {
  display: block;
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

select, textarea, input[type="range"] {
  width: 100%;
  padding: 8px 10px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 0.85rem;
  outline: none;
  transition: border-color var(--transition);
}

select:focus, textarea:focus {
  border-color: var(--accent);
}

input[type="range"] {
  -webkit-appearance: none;
  height: 6px;
  padding: 0;
  background: var(--bg-tertiary);
  border-radius: 3px;
  cursor: pointer;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  background: var(--accent);
  border-radius: 50%;
  cursor: pointer;
}

textarea {
  resize: vertical;
  font-family: 'Courier New', monospace;
  font-size: 0.75rem;
  min-height: 80px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px 16px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
}

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

.btn-primary:hover { background: var(--accent-hover); }

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

.btn-secondary:hover { background: var(--border-light); }

.btn-sm { padding: 5px 12px; font-size: 0.75rem; }

.btn-icon {
  width: 32px;
  height: 32px;
  padding: 0;
  border-radius: var(--radius-sm);
  background: var(--bg-tertiary);
  color: var(--text-primary);
  border: 1px solid var(--border-light);
  font-size: 1rem;
  cursor: pointer;
}

.btn-icon:hover { background: var(--border-light); }

.main-content {
  position: relative;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.viz-toolbar {
  display: flex;
  gap: 6px;
  padding: 8px 16px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
}

.tree-container {
  flex: 1;
  position: relative;
  overflow: hidden;
  cursor: grab;
}

.tree-container:active { cursor: grabbing; }
.tree-container.panning { cursor: grabbing; }

#tree-svg {
  width: 100%;
  height: 100%;
}

.tree-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  pointer-events: none;
}

.placeholder-icon { font-size: 3rem; margin-bottom: 12px; }

.node-detail {
  position: absolute;
  bottom: 16px;
  right: 16px;
  width: 280px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow);
  z-index: 10;
}

.node-detail.hidden { display: none; }

.node-detail h3 {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.data-preview {
  max-height: 150px;
  overflow: auto;
  font-size: 0.7rem;
  margin-top: 8px;
  background: var(--bg-tertiary);
  border-radius: var(--radius-sm);
  padding: 8px;
}

.data-preview table { width: 100%; border-collapse: collapse; }
.data-preview th, .data-preview td {
  padding: 3px 6px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.data-preview th {
  color: var(--accent);
  position: sticky;
  top: 0;
  background: var(--bg-tertiary);
}

.metrics-content {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.metric-card {
  background: var(--bg-tertiary);
  border-radius: var(--radius-sm);
  padding: 10px;
  text-align: center;
}

.metric-label {
  display: block;
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.metric-value {
  display: block;
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--accent);
}

.confusion-matrix {
  overflow-x: auto;
  font-size: 0.75rem;
}

.confusion-matrix table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 8px;
}

.confusion-matrix th, .confusion-matrix td {
  padding: 6px 8px;
  text-align: center;
  border: 1px solid var(--border);
}

.confusion-matrix th { background: var(--bg-tertiary); color: var(--text-secondary); }
.confusion-matrix td.correct { background: rgba(16, 185, 129, 0.2); color: var(--success); }
.confusion-matrix td.incorrect { background: rgba(239, 68, 68, 0.1); color: var(--danger); }

.prediction-inputs {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 10px;
}

.prediction-inputs .form-group {
  margin-bottom: 0;
}

.prediction-inputs input {
  width: 100%;
  padding: 6px 8px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 0.8rem;
  outline: none;
}

.prediction-inputs input:focus { border-color: var(--accent); }

.prediction-result {
  margin-top: 10px;
  padding: 10px;
  background: var(--accent-light);
  border: 1px solid var(--accent);
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
}

.prediction-result.hidden { display: none; }

/* D3 Tree Styles */
.tree-node circle {
  stroke-width: 2px;
  transition: all 0.3s ease;
}

.tree-node text {
  font-size: 11px;
  fill: var(--text-primary);
  pointer-events: none;
  user-select: none;
}

.tree-link {
  fill: none;
  stroke: var(--border-light);
  stroke-width: 1.5px;
}

.tree-link.highlighted {
  stroke: var(--accent);
  stroke-width: 3px;
  filter: drop-shadow(0 0 4px rgba(59, 130, 246, 0.4));
}

.tree-node-path {
  fill: none;
  stroke: var(--accent);
  stroke-width: 3px;
  stroke-dasharray: 6 3;
  animation: dash-flow 1s linear infinite;
}

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

.node-box {
  cursor: pointer;
}

.node-box rect {
  transition: all 0.3s ease;
}

.node-box.highlighted rect {
  stroke: var(--accent);
  stroke-width: 3px;
  filter: drop-shadow(0 0 8px rgba(59, 130, 246, 0.5));
}

.node-box.leaf rect {
  rx: 20;
}

.node-box.split rect {
  rx: 6;
}

.node-leaf text { fill: var(--success); font-weight: 600; }

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

/* Mobile */
@media (max-width: 1024px) {
  .main-container {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr auto;
  }
  .sidebar-left {
    max-height: 300px;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  .sidebar-right {
    max-height: 350px;
    border-left: none;
    border-top: 1px solid var(--border);
  }
}

@media (max-width: 640px) {
  .header { padding: 8px 12px; }
  .header h1 { font-size: 1rem; }
  .sidebar, .sidebar-right { padding: 8px; }
}
