/* ═══════════════════════════════════════════════════════════════
   Learning Platform - W3Schools Inspired Theme
   ═══════════════════════════════════════════════════════════════ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap');

:root {
  --primary: #04AA6D;
  --primary-dark: #059862;
  --primary-light: #e8f5e9;
  --accent: #282A35;
  --bg: #f8f9fa;
  --white: #ffffff;
  --text: #2c3e50;
  --text-muted: #636e72;
  --border: #dfe6e9;
  --code-bg: #2d3436;
  --code-text: #dfe6e9;
  --sidebar-w: 280px;
  --navbar-h: 64px;
  --radius: 12px;
  --shadow: 0 4px 20px rgba(0,0,0,0.05);
  --shadow-lg: 0 10px 40px rgba(0,0,0,0.1);
}

* { margin: 0; padding: 0; box-sizing: border-box; }
body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  overflow-x: hidden;
}

/* ─── Top Navbar ────────────────────────────────────────── */
.top-navbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 1000;
  height: var(--navbar-h);
  background: var(--accent);
  display: flex; align-items: center;
  padding: 0 20px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}
.top-navbar .brand {
  color: var(--primary);
  font-size: 1.3rem;
  font-weight: 700;
  text-decoration: none;
  margin-right: 30px;
  white-space: nowrap;
  display: flex; align-items: center; gap: 8px;
}
.top-navbar .brand span { color: var(--white); }
.unit-tabs {
  display: flex; gap: 2px;
  overflow-x: auto;
  scrollbar-width: none;
  flex: 1;
}
.unit-tabs::-webkit-scrollbar { display: none; }
.unit-tab {
  padding: 8px 18px;
  color: #ccc;
  text-decoration: none;
  font-size: 0.85rem;
  font-weight: 500;
  white-space: nowrap;
  border-radius: var(--radius) var(--radius) 0 0;
  transition: all 0.2s;
  cursor: pointer;
  border: none; background: none;
}
.unit-tab:hover { color: #fff; background: rgba(255,255,255,0.05); }
.unit-tab.active {
  color: #fff;
  background: var(--primary);
}
.menu-toggle {
  display: none;
  background: none; border: none;
  color: white; font-size: 1.5rem;
  cursor: pointer; padding: 4px 8px;
}

/* ─── Sidebar ───────────────────────────────────────────── */
.sidebar {
  position: fixed;
  top: var(--navbar-h); left: 0; bottom: 0;
  width: var(--sidebar-w);
  background: var(--white);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  z-index: 900;
  padding: 12px 0;
  transition: transform 0.3s ease;
}
.sidebar-header {
  padding: 12px 20px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-muted);
}
.topic-item {
  display: block;
  padding: 10px 20px;
  color: var(--text);
  text-decoration: none;
  font-size: 0.9rem;
  cursor: pointer;
  transition: all 0.15s;
  border-left: 3px solid transparent;
}
.topic-item:hover {
  background: var(--primary-light);
  color: var(--primary-dark);
}
.topic-item.active {
  background: var(--primary-light);
  color: var(--primary-dark);
  border-left-color: var(--primary);
  font-weight: 600;
}
.topic-count {
  float: right;
  background: var(--bg);
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* ─── Main Content ──────────────────────────────────────── */
.main-content {
  margin-left: var(--sidebar-w);
  margin-top: var(--navbar-h);
  padding: 24px 32px;
  min-height: calc(100vh - var(--navbar-h));
}
.welcome-banner {
  background: linear-gradient(135deg, var(--primary), #2ecc71);
  color: white;
  padding: 40px;
  border-radius: var(--radius);
  margin-bottom: 24px;
  box-shadow: var(--shadow);
}
.welcome-banner h1 { font-size: 1.8rem; margin-bottom: 8px; }
.welcome-banner p { opacity: 0.9; font-size: 1rem; }

/* ─── Question Card ─────────────────────────────────────── */
.question-card {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 24px;
  overflow: hidden;
  border: 1px solid var(--border);
  transition: box-shadow 0.2s;
}
.question-card:hover { box-shadow: var(--shadow-lg); }
.question-header {
  padding: 16px 24px;
  background: var(--accent);
  color: white;
  display: flex; align-items: center; gap: 12px;
  cursor: pointer;
}
.question-header .q-number {
  background: var(--primary);
  color: white;
  width: 32px; height: 32px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 0.85rem;
  flex-shrink: 0;
}
.question-header h3 {
  font-size: 0.95rem;
  font-weight: 500;
  flex: 1;
}
.question-header .toggle-icon {
  font-size: 1.2rem;
  transition: transform 0.3s;
}
.question-header.collapsed .toggle-icon { transform: rotate(-90deg); }

.question-body {
  padding: 24px;
}
.question-body h3 {
  color: var(--primary);
  font-size: 1rem;
  margin: 16px 0 8px 0;
  padding-bottom: 4px;
  border-bottom: 2px solid var(--primary-light);
}
.question-body h3:first-child { margin-top: 0; }
.question-body p { margin-bottom: 10px; font-size: 0.92rem; }
.question-body ul {
  margin: 8px 0 16px 24px;
  list-style: none;
}
.question-body ul li {
  padding: 4px 0;
  font-size: 0.9rem;
  position: relative;
  padding-left: 16px;
}
.question-body ul li::before {
  content: '✦';
  position: absolute; left: 0;
  color: var(--primary);
  font-size: 0.7rem;
}
.question-body code {
  background: #fff0f5;
  padding: 3px 8px;
  border-radius: 4px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.88rem;
  color: #d63384;
  border: 1px solid rgba(214, 51, 132, 0.1);
}

/* ─── Table Styling ─────────────────────────────────────── */
.table-responsive {
  margin: 20px 0;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}
table {
  width: 100%;
  border-collapse: collapse;
  background: white;
}
th, td {
  padding: 12px 16px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}
th {
  background: var(--accent);
  color: white;
  font-weight: 600;
  text-transform: uppercase;
  font-size: 0.8rem;
  letter-spacing: 0.5px;
}
tr:last-child td { border-bottom: none; }
tr:hover td { background-color: #f8f9fa; }

/* ─── Answer Sections ───────────────────────────────────── */
.answer-section {
  margin-bottom: 24px;
}
.text-primary { color: var(--primary) !important; }
.border-bottom { border-bottom: 2px solid var(--primary-light) !important; }
.pb-2 { padding-bottom: 0.5rem !important; }
.mt-3 { margin-top: 1rem !important; }
.mb-3 { margin-bottom: 1rem !important; }

/* ─── Code Playground ───────────────────────────────────── */
.playground {
  margin-top: 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.playground-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 16px;
  background: var(--accent);
  color: #ccc;
  font-size: 0.8rem;
  font-weight: 600;
}
.playground-header .lang-badge {
  background: var(--primary);
  color: white;
  padding: 2px 10px;
  border-radius: 4px;
  font-size: 0.75rem;
  text-transform: uppercase;
}
.playground-actions {
  display: flex; gap: 6px;
}
.btn-run, .btn-reset {
  padding: 6px 16px;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.8rem;
  font-weight: 600;
  transition: all 0.2s;
}
.btn-run {
  background: var(--primary);
  color: white;
}
.btn-run:hover { background: var(--primary-dark); transform: translateY(-1px); }
.btn-reset {
  background: rgba(255,255,255,0.1);
  color: #ccc;
  border: 1px solid rgba(255,255,255,0.2);
}
.btn-reset:hover { background: rgba(255,255,255,0.2); }

.code-editor {
  width: 100%;
  min-height: 180px;
  padding: 16px;
  background: var(--code-bg);
  color: var(--code-text);
  border: none;
  resize: vertical;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.85rem;
  line-height: 1.6;
  tab-size: 2;
  outline: none;
}
.code-editor:focus {
  box-shadow: inset 0 0 0 2px var(--primary);
}

.output-panel {
  border-top: 2px solid var(--primary);
  background: #1e1e1e;
  min-height: 80px;
  max-height: 300px;
  overflow: auto;
}
.output-label {
  padding: 6px 16px;
  font-size: 0.75rem;
  color: var(--primary);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  background: #252525;
}
.output-content {
  padding: 12px 16px;
  color: #d4d4d4;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.85rem;
  white-space: pre-wrap;
  line-height: 1.5;
}
.output-content.error { color: #ff6b6b; }
.output-iframe {
  width: 100%;
  min-height: 150px;
  border: none;
  background: white;
}

/* ─── Loading & Empty States ────────────────────────────── */
.loading {
  display: flex; align-items: center; justify-content: center;
  padding: 60px;
  color: var(--text-muted);
  gap: 12px;
}
.spinner {
  width: 24px; height: 24px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}
.empty-state .icon { font-size: 3rem; margin-bottom: 12px; }

/* ─── Responsive ────────────────────────────────────────── */
@media (max-width: 768px) {
  .menu-toggle { display: block; }
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); box-shadow: var(--shadow-lg); }
  .main-content { margin-left: 0; padding: 16px; }
  #siteFooter { margin-left: 0; }
  .unit-tabs { display: none; }
  .unit-tabs.show { display: flex; flex-direction: column; position: absolute; top: var(--navbar-h); left: 0; right: 0; background: var(--accent); padding: 8px; z-index: 999; }
  .question-body { padding: 16px; }
  .welcome-banner { padding: 24px; }
  .welcome-banner h1 { font-size: 1.3rem; }
}

/* ─── Scrollbar ─────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #ccc; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #aaa; }

/* ─── Animations ────────────────────────────────────────── */
.fade-in {
  animation: fadeIn 0.3s ease-out;
}
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
