/*
 * Data Structures & Algorithms Visualizer v2.0.0
 * Modern Responsive Styling (Dark & Light Theme)
 */

:root {
  --bg-primary: #f8fafc;
  --bg-secondary: #ffffff;
  --bg-tertiary: #f1f5f9;
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #94a3b8;
  --accent-primary: #0284c7;
  --accent-hover: #0369a1;
  --accent-light: #e0f2fe;
  --border-color: #e2e8f0;
  --card-shadow: 0 4px 6px -1px rgb(0 0 0 / 0.05), 0 2px 4px -2px rgb(0 0 0 / 0.05);
  --header-height: 56px;
  --sidebar-width: 270px;
}

body.dark-theme {
  --bg-primary: #090d16;
  --bg-secondary: #111827;
  --bg-tertiary: #1f2937;
  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --accent-primary: #38bdf8;
  --accent-hover: #0284c7;
  --accent-light: #082f49;
  --border-color: #1e293b;
  --card-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}

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

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background-color: var(--bg-primary);
  color: var(--text-primary);
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  user-select: none;
}

/* Header */
.app-header {
  height: var(--header-height);
  background-color: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.25rem;
  z-index: 50;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.brand h1 {
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.badge-version {
  background: var(--accent-light);
  color: var(--accent-primary);
  font-size: 0.72rem;
  font-weight: 700;
  padding: 0.2rem 0.5rem;
  border-radius: 9999px;
  border: 1px solid var(--accent-primary);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.8rem;
}

.select-custom, .btn-action {
  background: var(--bg-tertiary);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  padding: 0.45rem 0.8rem;
  border-radius: 6px;
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.15s ease;
}

.select-custom:hover, .btn-action:hover {
  border-color: var(--accent-primary);
}

/* Layout */
.app-layout {
  flex: 1;
  display: flex;
  overflow: hidden;
  position: relative;
}

/* Sidebar */
.app-sidebar {
  width: var(--sidebar-width);
  background: var(--bg-secondary);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  flex-shrink: 0;
}

.app-sidebar.collapsed {
  display: none !important;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.8rem 1rem 0.2rem;
}

.sidebar-header .sidebar-section-title {
  padding: 0;
}

.btn-icon-sidebar {
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  color: var(--text-muted);
  cursor: pointer;
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
  font-size: 0.75rem;
  transition: all 0.15s ease;
}

.btn-icon-sidebar:hover {
  color: var(--accent-primary);
  border-color: var(--accent-primary);
}

.sidebar-section-title {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  padding: 1rem 1rem 0.4rem;
  font-weight: 700;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.65rem 1rem;
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 0.88rem;
  font-weight: 500;
  cursor: pointer;
  border-left: 3px solid transparent;
  transition: all 0.15s ease;
}

.nav-item:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

.nav-item.active {
  background: var(--accent-light);
  color: var(--accent-primary);
  border-left-color: var(--accent-primary);
  font-weight: 600;
}

/* Main Area */
.main-view {
  flex: 1;
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
}

/* Operational Top Toolbar */
.algo-toolbar {
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  padding: 0.6rem 1.25rem;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.7rem;
  min-height: 52px;
}

.input-group {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.input-custom {
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  padding: 0.45rem 0.65rem;
  border-radius: 6px;
  font-size: 0.85rem;
  width: 90px;
}

.input-custom:focus {
  outline: 2px solid var(--accent-primary);
}

.btn-primary {
  background: var(--accent-primary);
  color: #ffffff;
  border: none;
  padding: 0.45rem 0.9rem;
  border-radius: 6px;
  font-weight: 600;
  font-size: 0.85rem;
  cursor: pointer;
  transition: background 0.15s;
}

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

.btn-secondary {
  background: var(--bg-tertiary);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  padding: 0.45rem 0.8rem;
  border-radius: 6px;
  font-size: 0.85rem;
  cursor: pointer;
}

.btn-secondary:hover {
  border-color: var(--accent-primary);
}

/* Canvas Viewport */
.canvas-wrapper {
  flex: 1;
  position: relative;
  background-color: var(--bg-primary);
  overflow: hidden;
  cursor: grab;
}

.canvas-wrapper canvas {
  display: block;
}

/* Floating Zoom Controls */
.zoom-controls {
  position: absolute;
  top: 1rem;
  right: 1.25rem;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  box-shadow: var(--card-shadow);
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 20;
}

.zoom-btn {
  background: none;
  border: none;
  border-bottom: 1px solid var(--border-color);
  color: var(--text-primary);
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  cursor: pointer;
  transition: background 0.15s;
}

.zoom-btn:last-child {
  border-bottom: none;
  font-size: 0.8rem;
  font-weight: 600;
}

.zoom-btn:hover {
  background: var(--bg-tertiary);
  color: var(--accent-primary);
}

/* Bottom Playback & Timeline Bar */
.playback-bar {
  background: var(--bg-secondary);
  border-top: 1px solid var(--border-color);
  padding: 0.6rem 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  min-height: 56px;
}

.playback-controls {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.playback-btn {
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  width: 36px;
  height: 36px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.15s;
}

.playback-btn:hover {
  border-color: var(--accent-primary);
  color: var(--accent-primary);
}

.playback-btn.btn-play-pause {
  width: 42px;
  background: var(--accent-primary);
  color: #ffffff;
  border: none;
}

.playback-btn.btn-play-pause:hover {
  background: var(--accent-hover);
}

.status-pill {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-size: 0.86rem;
  font-weight: 500;
  flex: 1;
  min-width: 250px;
  overflow: hidden;
}

#statusMessage {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.badge-tag-rotation {
  background: #fef3c7;
  color: #b45309;
  border: 1px solid #fde68a;
  padding: 0.15rem 0.5rem;
  border-radius: 4px;
  font-weight: 700;
  font-size: 0.78rem;
  letter-spacing: 0.3px;
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  white-space: nowrap;
}

.badge-tag-recolor {
  background: #fee2e2;
  color: #b91c1c;
  border: 1px solid #fecaca;
  padding: 0.15rem 0.5rem;
  border-radius: 4px;
  font-weight: 700;
  font-size: 0.78rem;
  letter-spacing: 0.3px;
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  white-space: nowrap;
}

.badge-tag-balance {
  background: #dcfce7;
  color: #15803d;
  border: 1px solid #bbf7d0;
  padding: 0.15rem 0.5rem;
  border-radius: 4px;
  font-weight: 700;
  font-size: 0.78rem;
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  white-space: nowrap;
}

.status-indicator {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #10b981;
  flex-shrink: 0;
}

.speed-control {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.speed-control input[type="range"] {
  width: 100px;
  accent-color: var(--accent-primary);
}

/* Right Explanations Drawer */
.explanation-drawer {
  width: 380px;
  background: var(--bg-secondary);
  border-left: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  transition: transform 0.25s ease;
  z-index: 30;
}

.explanation-drawer.collapsed {
  display: none;
}

.drawer-header {
  padding: 0.9rem 1rem;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.drawer-header h3 {
  font-size: 0.95rem;
  font-weight: 700;
}

.drawer-tabs {
  display: flex;
  border-bottom: 1px solid var(--border-color);
}

.drawer-tab {
  flex: 1;
  background: none;
  border: none;
  padding: 0.6rem 0.4rem;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
}

.drawer-tab.active {
  color: var(--accent-primary);
  border-bottom-color: var(--accent-primary);
}

.drawer-content {
  flex: 1;
  padding: 1rem;
  overflow-y: auto;
  font-size: 0.86rem;
  line-height: 1.5;
  color: var(--text-secondary);
}

.drawer-content h4 {
  color: var(--text-primary);
  margin-bottom: 0.5rem;
  font-size: 0.92rem;
}

.complexity-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 0.8rem;
  font-size: 0.82rem;
}

.complexity-table th, .complexity-table td {
  padding: 0.5rem 0.6rem;
  border: 1px solid var(--border-color);
  text-align: left;
}

.complexity-table th {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

.code-block {
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  padding: 0.75rem;
  font-family: 'JetBrains Mono', 'Fira Code', monospace;
  font-size: 0.78rem;
  overflow-x: auto;
  white-space: pre;
  color: var(--text-primary);
  line-height: 1.45;
}

/* -------------------------------------------------------------
 * Tree Auditor & Student Exercises Styles
 * ------------------------------------------------------------- */
.audit-status-banner {
  padding: 0.85rem 1rem;
  border-radius: 8px;
  font-weight: 600;
  margin-bottom: 1rem;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-size: 0.88rem;
}

.audit-status-banner.error {
  background: rgba(239, 68, 68, 0.12);
  color: #dc2626;
  border: 1px solid rgba(239, 68, 68, 0.3);
}

.audit-status-banner.valid {
  background: rgba(16, 185, 129, 0.12);
  color: #059669;
  border: 1px solid rgba(16, 185, 129, 0.3);
}

.audit-status-banner.hidden {
  background: rgba(245, 158, 11, 0.12);
  color: #d97706;
  border: 1px solid rgba(245, 158, 11, 0.3);
}

.audit-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-left: 4px solid #ef4444;
  border-radius: 8px;
  padding: 0.9rem 1rem;
  margin-bottom: 0.9rem;
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
  transition: all 0.2s ease;
}

.audit-card:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 6px -1px rgba(0,0,0,0.1);
}

.audit-card.success {
  border-left-color: #10b981;
}

.audit-card.warning {
  border-left-color: #f59e0b;
}

.audit-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.5rem;
}

.audit-rule-tag {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 0.15rem 0.5rem;
  border-radius: 4px;
  background: rgba(239, 68, 68, 0.15);
  color: #dc2626;
}

.audit-rule-tag.tag-success {
  background: rgba(16, 185, 129, 0.15);
  color: #059669;
}

.audit-card-title {
  font-size: 0.92rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 0.35rem;
}

.audit-card-msg {
  font-size: 0.84rem;
  color: var(--text-primary);
  margin-bottom: 0.5rem;
  line-height: 1.45;
}

.audit-card-explanation {
  font-size: 0.8rem;
  color: var(--text-secondary);
  background: var(--bg-tertiary);
  padding: 0.6rem 0.75rem;
  border-radius: 6px;
  margin-bottom: 0.5rem;
  line-height: 1.45;
}

.audit-fix-box {
  font-size: 0.8rem;
  color: #0369a1;
  background: var(--accent-light);
  padding: 0.55rem 0.75rem;
  border-radius: 6px;
  border-left: 3px solid var(--accent-primary);
  line-height: 1.4;
}

body.dark-theme .audit-fix-box {
  color: #38bdf8;
  background: rgba(56, 189, 248, 0.1);
}

.audit-classroom-box {
  text-align: center;
  padding: 2rem 1rem;
  background: var(--bg-tertiary);
  border: 1px dashed var(--border-color);
  border-radius: 8px;
}

.badge-tag-violation {
  display: inline-block;
  background: rgba(239, 68, 68, 0.2);
  color: #dc2626;
  font-weight: 700;
  font-size: 0.74rem;
  padding: 0.12rem 0.45rem;
  border-radius: 4px;
  border: 1px solid #ef4444;
  margin-right: 0.3rem;
}

