/* ═══════════════════════════════════════════════════════════════
   Layout — App Shell, Sidebar, Topbar, Content Grid
   ═══════════════════════════════════════════════════════════════ */

/* ── Reset & Base ──────────────────────────────────────────── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  scroll-behavior: smooth;
  font-size: 14px;
  -webkit-text-size-adjust: 100%;
  tab-size: 4;
}

body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--fg);
  line-height: var(--leading-normal);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  min-height: 100vh;
  overflow-x: hidden;
}

a { color: inherit; text-decoration: none; }
img, svg, video { display: block; max-width: 100%; height: auto; }
button { font: inherit; color: inherit; background: none; border: none; cursor: pointer; }
ul, ol { list-style: none; }

/* Scrollbar */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: var(--r-full); }
::-webkit-scrollbar-thumb:hover { background: var(--fg-faint); }

/* ── App Shell ─────────────────────────────────────────────── */
.app {
  display: flex;
  min-height: 100vh;
}

/* ── Top Bar ───────────────────────────────────────────────── */
.topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--topbar-h);
  background: var(--topbar-glass);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 var(--space-4);
  z-index: var(--z-topbar);
  gap: var(--space-3);
}

.topbar__hamburger {
  display: none;
  width: 32px;
  height: 32px;
  border-radius: var(--r-md);
  color: var(--fg-muted);
  transition: all var(--dur-fast) var(--ease-out);
}

.topbar__hamburger:hover {
  background: var(--hover-bg);
  color: var(--fg);
}

@media (max-width: 900px) {
  .topbar__hamburger {
    display: grid;
    place-items: center;
  }
}

.topbar__brand {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-weight: var(--weight-bold);
  font-size: var(--text-base);
  letter-spacing: var(--tracking-tight);
  color: var(--fg);
  flex-shrink: 0;
  min-width: calc(var(--sidebar-w) - var(--space-8));
  user-select: none;
}

.topbar__brand-icon {
  width: 24px;
  height: 24px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-md);
  display: grid;
  place-items: center;
  color: var(--fg);
  font-size: 11px;
  font-family: var(--font-mono);
  font-weight: var(--weight-bold);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

.topbar__brand-text {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--fg);
}

.topbar__track-badge {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: var(--weight-semibold);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--fg-faint);
  background: var(--chip-bg);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 1px 6px;
  margin-left: 2px;
}

.topbar__search {
  flex: 1;
  max-width: 440px;
}

.topbar__search-trigger {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 5px var(--space-3);
  color: var(--fg-muted);
  font-size: var(--text-sm);
  width: 100%;
  cursor: pointer;
  transition: all var(--dur-fast) var(--ease-out);
}

.topbar__search-trigger:hover {
  background: var(--surface);
  border-color: var(--border-strong);
  color: var(--fg);
}

.topbar__search-kbd {
  margin-left: auto;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--fg-faint);
  background: var(--chip-bg);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 1px 5px;
  line-height: 1.4;
}

.topbar__actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin-left: auto;
}

.topbar__btn {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: var(--r-md);
  color: var(--fg-muted);
  border: 1px solid transparent;
  transition: all var(--dur-fast) var(--ease-out);
}

.topbar__btn:hover {
  background: var(--hover-bg);
  border-color: var(--border);
  color: var(--fg);
}

.topbar__progress-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--chip-bg);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 3px 10px;
  font-size: var(--text-xs);
  font-family: var(--font-mono);
  color: var(--fg-muted);
  font-weight: var(--weight-medium);
}

.topbar__progress-ring {
  width: 16px;
  height: 16px;
}

.topbar__progress-ring circle {
  fill: none;
  stroke-width: 2.5;
}

.topbar__progress-ring .track { stroke: var(--progress-track); }
.topbar__progress-ring .fill {
  stroke: var(--success);
  stroke-linecap: round;
  transition: stroke-dashoffset var(--dur-slow) var(--ease-out);
  transform: rotate(-90deg);
  transform-origin: center;
}

/* ── Sidebar ───────────────────────────────────────────────── */
.sidebar {
  position: fixed;
  top: var(--topbar-h);
  left: 0;
  bottom: 0;
  width: var(--sidebar-w);
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: var(--z-sidebar);
  overflow: hidden;
  transition: transform var(--dur-normal) var(--ease-out);
}

.sidebar__tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  padding: 0 var(--space-3);
  flex-shrink: 0;
}

.sidebar__tab {
  padding: var(--space-3) var(--space-3);
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  color: var(--fg-muted);
  border-bottom: 2px solid transparent;
  transition: all var(--dur-fast) var(--ease-out);
  white-space: nowrap;
}

.sidebar__tab:hover { color: var(--fg); }

.sidebar__tab.active {
  color: var(--fg);
  border-bottom-color: var(--accent);
}

.sidebar__content {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-2) 0;
}

/* Module Groups */
.module-group {
  padding: var(--space-1) 0;
}

.module-group__header {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-4);
  cursor: pointer;
  user-select: none;
  transition: background var(--dur-fast) var(--ease-out);
}

.module-group__header:hover {
  background: var(--hover-bg);
}

.module-group__chevron {
  width: 16px;
  height: 16px;
  color: var(--fg-faint);
  transition: transform var(--dur-fast) var(--ease-out);
  flex-shrink: 0;
}

.module-group.collapsed .module-group__chevron {
  transform: rotate(-90deg);
}

.module-group__number {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: var(--weight-semibold);
  color: var(--fg-faint);
  min-width: 22px;
}

.module-group__title {
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: var(--fg);
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.module-group__count {
  font-size: 11px;
  color: var(--fg-faint);
  font-family: var(--font-mono);
}

.module-group__progress {
  width: 32px;
  height: 3px;
  background: var(--progress-track);
  border-radius: var(--r-full);
  overflow: hidden;
  flex-shrink: 0;
}

.module-group__progress-fill {
  height: 100%;
  background: var(--success);
  border-radius: var(--r-full);
  transition: width var(--dur-normal) var(--ease-out);
}

/* Unit Items */
.module-group__units {
  overflow: hidden;
  transition: max-height var(--dur-normal) var(--ease-out);
}

.module-group.collapsed .module-group__units {
  max-height: 0 !important;
}

.unit-item {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: 6px var(--space-4) 6px calc(var(--space-4) + 38px);
  font-size: var(--text-sm);
  color: var(--fg-muted);
  cursor: pointer;
  transition: all var(--dur-fast) var(--ease-out);
  position: relative;
  min-height: 32px;
}

.unit-item:hover {
  background: var(--hover-bg);
  color: var(--fg);
}

.unit-item.active {
  background: var(--surface-hover);
  color: var(--fg);
  font-weight: var(--weight-medium);
}

.unit-item.active::before {
  content: '';
  position: absolute;
  left: 0;
  top: 6px;
  bottom: 6px;
  width: 2px;
  background: var(--accent);
  border-radius: 0 var(--r-sm) var(--r-sm) 0;
}

.unit-item__status {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  display: grid;
  place-items: center;
}

.unit-item__status--completed { color: var(--success); }
.unit-item__status--active { color: var(--accent); }
.unit-item__status--pending { color: var(--fg-faint); }

.unit-item__title {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  line-height: var(--leading-snug);
}

.unit-item__kind {
  font-size: 10px;
  font-family: var(--font-mono);
  color: var(--fg-faint);
  text-transform: uppercase;
  letter-spacing: var(--tracking-wider);
  flex-shrink: 0;
}

/* ── Main Content ──────────────────────────────────────────── */
.main {
  flex: 1;
  margin-left: var(--sidebar-w);
  margin-top: var(--topbar-h);
  min-height: calc(100vh - var(--topbar-h));
  display: flex;
  flex-direction: column;
}

.main__content {
  max-width: var(--content-max);
  width: 100%;
  margin: 0 auto;
  padding: var(--space-8) var(--space-6);
  flex: 1;
}

/* ── Breadcrumbs ───────────────────────────────────────────── */
.breadcrumbs {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  font-size: var(--text-xs);
  color: var(--fg-faint);
  margin-bottom: var(--space-6);
  flex-wrap: wrap;
}

.breadcrumbs a {
  color: var(--fg-muted);
  transition: color var(--dur-fast);
}

.breadcrumbs a:hover { color: var(--accent); }

.breadcrumbs__sep {
  color: var(--fg-faint);
  margin: 0 2px;
}

.breadcrumbs__current {
  color: var(--fg);
  font-weight: var(--weight-medium);
}

/* ── Lesson Navigation (Prev/Next) ─────────────────────────── */
.lesson-nav {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-4);
  margin-top: var(--space-12);
  padding-top: var(--space-8);
  border-top: 1px solid var(--divider);
}

.lesson-nav__link {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  padding: var(--space-4);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  transition: all var(--dur-fast) var(--ease-out);
}

.lesson-nav__link:hover {
  border-color: var(--accent);
  background: var(--surface-hover);
}

.lesson-nav__link--next {
  text-align: right;
}

.lesson-nav__label {
  font-size: var(--text-xs);
  color: var(--fg-faint);
  text-transform: uppercase;
  letter-spacing: var(--tracking-wide);
}

.lesson-nav__title {
  font-size: var(--text-base);
  font-weight: var(--weight-medium);
  color: var(--fg);
}

/* ── Mobile Overlay ────────────────────────────────────────── */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: calc(var(--z-sidebar) - 1);
  backdrop-filter: blur(2px);
}

/* ── Hamburger ─────────────────────────────────────────────── */
.topbar__hamburger {
  display: none;
  width: 34px;
  height: 34px;
  border-radius: var(--r-md);
  place-items: center;
  color: var(--fg-muted);
}

.topbar__hamburger:hover {
  background: var(--hover-bg);
  color: var(--fg);
}

/* ── Responsive ────────────────────────────────────────────── */
@media (max-width: 1024px) {
  .sidebar {
    transform: translateX(-100%);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .sidebar.open ~ .sidebar-overlay {
    display: block;
  }

  .main {
    margin-left: 0;
  }

  .topbar__hamburger {
    display: grid;
  }

  .topbar__brand {
    min-width: auto;
  }
}

@media (max-width: 640px) {
  .main__content {
    padding: var(--space-4) var(--space-4);
  }

  .topbar {
    padding: 0 var(--space-3);
  }

  .topbar__search {
    display: none;
  }

  .topbar__progress-pill span {
    display: none;
  }

  .lesson-nav {
    grid-template-columns: 1fr;
  }

  .breadcrumbs {
    font-size: 11px;
  }
}

/* ── Utility: Skip Link ────────────────────────────────────── */
.skip-link {
  position: absolute;
  top: -100px;
  left: var(--space-4);
  background: var(--accent);
  color: white;
  padding: var(--space-2) var(--space-4);
  border-radius: var(--r-md);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  z-index: 100;
  transition: top var(--dur-fast);
}

.skip-link:focus {
  top: var(--space-2);
}
