/* ============================================================
   App Shell — three-pane Command Center
   ============================================================ */

body {
  overflow: hidden;
  height: 100vh;
}

.app {
  display: grid;
  grid-template-columns: 280px 1fr 340px;
  grid-template-rows: 52px 1fr;
  grid-template-areas:
    "topbar topbar topbar"
    "left   main   right";
  height: 100vh;
}

/* ==================== TOPBAR ==================== */
.topbar {
  grid-area: topbar;
  display: flex;
  align-items: center;
  gap: var(--s-5);
  padding: 0 var(--s-6);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  z-index: var(--z-sticky);
}

.brand {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  color: var(--text);
  padding-right: var(--s-4);
  border-right: 1px solid var(--divider);
  text-decoration: none;
}

.brand-mark {
  width: 30px;
  height: 30px;
  border-radius: var(--r-sm);
  background: var(--primary-soft);
  border: 1px solid var(--primary-soft-hover);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--primary);
  flex-shrink: 0;
}

.brand-bracket {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-family: var(--font-mono);
  font-size: 0.88rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  line-height: 1;
  color: var(--text);
}

.brand-bracket .bk {
  color: var(--primary);
  font-weight: 600;
  font-size: 1rem;
}

.brand-bracket .vs {
  color: var(--text);
  font-weight: 600;
}

.brand-bracket .tag {
  color: var(--muted);
  font-weight: 500;
}

.brand em { font-style: italic; color: var(--primary); }

/* ---------- Theme toggle ---------- */
.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: var(--r-sm);
  background: var(--surface-2);
  border: 1px solid var(--divider);
  color: var(--muted);
  transition: all 150ms ease;
  padding: 0;
}

.theme-toggle:hover {
  color: var(--primary);
  border-color: var(--primary-soft-hover);
  background: var(--primary-soft);
}

.theme-toggle .theme-icon { display: none; }
.theme-toggle[data-theme-state='dark'] .theme-icon--sun { display: block; }
.theme-toggle[data-theme-state='light'] .theme-icon--moon { display: block; }

.search {
  flex: 1;
  max-width: 620px;
  position: relative;
}

.search input {
  width: 100%;
  padding: 8px 12px 8px 36px;
  background: var(--surface-2);
  border: 1px solid var(--divider);
  border-radius: var(--r-md);
  color: var(--text);
  font-size: var(--text-sm);
  transition: all 150ms ease;
}

.search input:focus {
  outline: none;
  border-color: var(--primary);
  background: var(--offset);
}

.search input::placeholder { color: var(--faint); }

.search svg {
  position: absolute;
  top: 50%;
  left: 12px;
  transform: translateY(-50%);
  color: var(--muted);
  pointer-events: none;
}

.search .kbd-hint {
  position: absolute;
  top: 50%;
  right: 10px;
  transform: translateY(-50%);
  display: flex;
  gap: 3px;
  pointer-events: none;
}

.topbar-meta {
  display: flex;
  align-items: center;
  gap: var(--s-4);
  margin-left: auto;
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--muted);
}

.topbar-meta strong { color: var(--text); font-weight: 500; }

.topbar-actions {
  display: flex;
  gap: var(--s-2);
}

/* ==================== LEFT RAIL ==================== */
.left-rail {
  grid-area: left;
  background: var(--surface);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: var(--s-5) var(--s-3) var(--s-8);
}

.rail-section {
  margin-bottom: var(--s-6);
}

.rail-label {
  padding: 0 var(--s-3) var(--s-3);
  font-family: var(--font-mono);
  font-size: 0.65rem;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--faint);
}

.stage-item {
  display: grid;
  grid-template-columns: 22px 1fr;
  gap: var(--s-2);
  padding: 7px var(--s-3);
  border-radius: var(--r-sm);
  color: var(--text);
  font-size: var(--text-sm);
  cursor: pointer;
  transition: background 120ms ease;
  align-items: baseline;
}

.stage-item:hover { background: var(--surface-2); }

.stage-item.active {
  background: var(--primary-soft);
  color: var(--primary-hover);
}

.stage-item .num {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--faint);
}

.stage-item.active .num { color: var(--primary); }

.stage-children {
  margin: 4px 0 var(--s-3) 30px;
  border-left: 1px solid var(--divider);
  padding-left: 10px;
  display: none;
}

.stage-item.expanded + .stage-children { display: block; }

.stage-children a {
  display: block;
  padding: 5px var(--s-3);
  border-radius: var(--r-sm);
  font-size: 0.82rem;
  color: var(--muted);
  transition: all 120ms ease;
}

.stage-children a:hover {
  background: var(--surface-2);
  color: var(--text);
}

.stage-children a.active {
  background: var(--offset);
  color: var(--primary-hover);
  font-weight: 500;
}

.quick-view {
  display: block;
  padding: 7px var(--s-3);
  border-radius: var(--r-sm);
  color: var(--muted);
  font-size: var(--text-sm);
  transition: all 120ms ease;
}

.quick-view:hover {
  background: var(--surface-2);
  color: var(--text);
}

.quick-view.active {
  background: var(--primary-soft);
  color: var(--primary-hover);
}

/* ==================== MAIN ==================== */
.main {
  grid-area: main;
  overflow-y: auto;
  padding: var(--s-8) var(--s-10) var(--s-16);
}

.main-inner {
  max-width: 880px;
  margin: 0 auto;
}

.crumbs {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--muted);
  margin-bottom: var(--s-5);
}

.crumbs a { color: var(--muted); transition: color 120ms ease; }
.crumbs a:hover { color: var(--primary); }
.crumbs .sep { color: var(--faint); }
.crumbs .current { color: var(--text); }

/* ==================== RIGHT RAIL ==================== */
.right-rail {
  grid-area: right;
  background: var(--surface);
  border-left: 1px solid var(--border);
  overflow-y: auto;
  padding: var(--s-5) var(--s-5) var(--s-8);
}

.right-section {
  margin-bottom: var(--s-6);
}

.right-section h4 {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--faint);
  font-weight: 500;
  margin-bottom: var(--s-3);
}

.when-list {
  background: var(--surface-2);
  border: 1px solid var(--divider);
  border-radius: var(--r-md);
  padding: var(--s-4);
}

.when-list li {
  position: relative;
  padding-left: var(--s-4);
  font-size: var(--text-sm);
  line-height: 1.5;
  color: var(--text);
  margin-bottom: var(--s-3);
}

.when-list li:last-child { margin-bottom: 0; }

.when-list li::before {
  content: '—';
  position: absolute;
  left: 0;
  top: 0;
  color: var(--primary);
}

.stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--s-2);
}

.stat-card {
  padding: var(--s-3) var(--s-4);
  background: var(--surface-2);
  border: 1px solid var(--divider);
  border-radius: var(--r-md);
}

.stat-card .stat-num {
  font-family: var(--font-serif);
  font-size: 2rem;
  line-height: 1;
  color: var(--primary);
  margin-bottom: 4px;
}

.stat-card .stat-label {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--faint);
}

.recent-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.recent-item {
  display: grid;
  grid-template-columns: 26px 1fr;
  gap: var(--s-2);
  align-items: baseline;
  padding: 6px var(--s-3);
  border-radius: var(--r-sm);
  font-size: 0.82rem;
  color: var(--muted);
  transition: all 120ms ease;
}

.recent-item:hover {
  background: var(--surface-2);
  color: var(--text);
}

.recent-item .num {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  color: var(--faint);
}

.recent-item .empty {
  grid-column: 1 / -1;
  font-style: italic;
  font-family: var(--font-serif);
  color: var(--faint);
  font-size: 0.9rem;
  padding: var(--s-2) 0;
}

/* ==================== MAIN: LANDING ==================== */
.landing-hero {
  padding: var(--s-6) 0 var(--s-10);
  border-bottom: 1px solid var(--divider);
  margin-bottom: var(--s-10);
}

.landing-hero .eyebrow { margin-bottom: var(--s-3); }

.landing-hero h1 {
  font-size: clamp(2.5rem, 5vw, 3.6rem);
  line-height: 1;
  margin-bottom: var(--s-4);
}

.landing-hero h1 em {
  font-style: italic;
  color: var(--primary);
}

.landing-hero p {
  font-family: var(--font-serif);
  font-style: italic;
  font-size: 1.25rem;
  color: var(--muted);
  max-width: 620px;
  line-height: 1.4;
}

.stage-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--s-5);
  margin-bottom: var(--s-10);
}

.stage-card {
  padding: var(--s-6);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  transition: all 180ms ease;
  display: flex;
  flex-direction: column;
  cursor: pointer;
}

.stage-card:hover {
  transform: translateY(-2px);
  border-color: var(--primary);
  box-shadow: var(--shadow-md);
}

.stage-card .num {
  font-family: var(--font-serif);
  font-style: italic;
  font-size: 2.4rem;
  line-height: 1;
  color: var(--primary);
  margin-bottom: var(--s-3);
  opacity: 0.8;
}

.stage-card h3 {
  font-size: 1.6rem;
  margin-bottom: var(--s-2);
}

.stage-card .tagline {
  font-family: var(--font-serif);
  font-style: italic;
  color: var(--muted);
  margin-bottom: var(--s-4);
  font-size: 0.95rem;
}

.stage-card .meta {
  margin-top: auto;
  padding-top: var(--s-3);
  border-top: 1px solid var(--divider);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--faint);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.stage-card .meta .arrow {
  color: var(--primary);
  transition: transform 180ms ease;
}

.stage-card:hover .meta .arrow {
  transform: translateX(4px);
}

/* ==================== MAIN: CATEGORY / STAGE ==================== */
.stage-header {
  padding-bottom: var(--s-8);
  border-bottom: 1px solid var(--divider);
  margin-bottom: var(--s-8);
}

.stage-header .num {
  font-family: var(--font-serif);
  font-style: italic;
  font-size: 3rem;
  line-height: 1;
  color: var(--primary);
  opacity: 0.7;
  margin-bottom: var(--s-4);
}

.stage-header h1 {
  font-size: 2.8rem;
  margin-bottom: var(--s-4);
}

.stage-header .tagline {
  font-family: var(--font-serif);
  font-style: italic;
  font-size: 1.3rem;
  color: var(--muted);
  margin-bottom: var(--s-5);
  max-width: 680px;
  line-height: 1.35;
}

.stage-header .description {
  max-width: 720px;
  font-size: var(--text-md);
  line-height: 1.7;
  color: var(--text);
}

.fw-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  overflow: hidden;
}

.fw-table thead th {
  text-align: left;
  padding: var(--s-3) var(--s-4);
  background: var(--surface-2);
  font-family: var(--font-mono);
  font-size: 0.65rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--faint);
  font-weight: 500;
  border-bottom: 1px solid var(--border);
}

.fw-table tbody tr {
  cursor: pointer;
  transition: background 120ms ease;
}

.fw-table tbody tr:hover { background: var(--surface-2); }
.fw-table tbody tr + tr td { border-top: 1px solid var(--divider); }

.fw-table td {
  padding: var(--s-4);
  font-size: var(--text-sm);
  vertical-align: top;
}

.fw-table td.num {
  width: 44px;
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--faint);
  padding-top: calc(var(--s-4) + 3px);
}

.fw-table td.name {
  width: 220px;
}

.fw-table td.name .name-label {
  font-family: var(--font-serif);
  font-size: 1.2rem;
  color: var(--text);
  line-height: 1.15;
  margin-bottom: 2px;
}

.fw-table td.name .subtitle {
  font-size: 0.78rem;
  color: var(--muted);
  line-height: 1.3;
}

.fw-table td.one-liner {
  color: var(--text);
  line-height: 1.5;
}

.fw-table td.badges {
  width: 120px;
  text-align: right;
}

.fw-table tbody tr:hover td.name .name-label { color: var(--primary-hover); }

/* ==================== MAIN: FRAMEWORK DETAIL ==================== */
.fw-head {
  padding-bottom: var(--s-8);
  border-bottom: 1px solid var(--divider);
  margin-bottom: var(--s-8);
}

.fw-head .cat-tag {
  margin-bottom: var(--s-4);
}

.fw-head h1 {
  font-size: 3rem;
  margin-bottom: var(--s-2);
  letter-spacing: -0.02em;
}

.fw-head .subtitle {
  font-family: var(--font-serif);
  font-style: italic;
  font-size: 1.35rem;
  color: var(--muted);
  margin-bottom: var(--s-6);
}

.fw-head .one-liner {
  font-size: 1.1rem;
  line-height: 1.6;
  color: var(--text);
  padding: var(--s-5) var(--s-6);
  background: var(--surface-2);
  border-left: 3px solid var(--primary);
  border-radius: 0 var(--r-md) var(--r-md) 0;
}

.section {
  margin-bottom: var(--s-10);
}

.section h2 {
  font-size: 1.5rem;
  margin-bottom: var(--s-5);
  display: flex;
  align-items: baseline;
  gap: var(--s-3);
}

.section h2::before {
  content: attr(data-num);
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--primary);
  letter-spacing: 0.15em;
  flex: none;
  padding-top: 4px;
}

.section ul.bulleted {
  padding-left: 0;
}

.section ul.bulleted li {
  position: relative;
  padding: var(--s-3) 0 var(--s-3) var(--s-6);
  border-bottom: 1px dotted var(--divider);
  line-height: 1.6;
  color: var(--text);
}

.section ul.bulleted li::before {
  content: '';
  position: absolute;
  left: 0;
  top: calc(var(--s-3) + 10px);
  width: 10px;
  height: 1px;
  background: var(--primary);
}

.section ul.bulleted li:last-child { border-bottom: none; }

.section ol.numbered {
  counter-reset: step;
}

.section ol.numbered li {
  counter-increment: step;
  position: relative;
  padding: var(--s-3) 0 var(--s-3) var(--s-10);
  border-bottom: 1px dotted var(--divider);
  line-height: 1.6;
  color: var(--text);
}

.section ol.numbered li::before {
  content: counter(step, decimal-leading-zero);
  position: absolute;
  left: 0;
  top: var(--s-3);
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--primary);
  font-weight: 500;
}

.section ol.numbered li:last-child { border-bottom: none; }

.callout {
  padding: var(--s-5) var(--s-6);
  background: var(--primary-soft);
  border: 1px solid var(--primary-soft-hover);
  border-radius: var(--r-md);
  font-family: var(--font-serif);
  font-style: italic;
  font-size: 1.05rem;
  line-height: 1.6;
  color: var(--text);
}

.callout::before {
  content: 'Vignette';
  display: block;
  font-family: var(--font-mono);
  font-style: normal;
  font-size: 0.65rem;
  letter-spacing: 0.25em;
  text-transform: uppercase;
  color: var(--primary);
  margin-bottom: var(--s-2);
}

.pitfall-list li {
  background: var(--surface-2);
  border: 1px solid var(--divider);
  border-left: 3px solid var(--danger);
  border-radius: var(--r-sm);
  padding: var(--s-3) var(--s-4);
  margin-bottom: var(--s-2);
  font-size: var(--text-sm);
  line-height: 1.5;
}

.pitfall-list li:last-child { margin-bottom: 0; }

.q-list li {
  padding: var(--s-3) var(--s-4);
  background: var(--surface-2);
  border: 1px solid var(--divider);
  border-radius: var(--r-sm);
  margin-bottom: var(--s-2);
  font-family: var(--font-serif);
  font-style: italic;
  font-size: 1.05rem;
  line-height: 1.5;
  color: var(--text);
}

.q-list li::before {
  content: '" ';
  color: var(--primary);
  font-family: var(--font-serif);
  font-size: 1.3rem;
}

.q-list li::after {
  content: ' "';
  color: var(--primary);
  font-family: var(--font-serif);
  font-size: 1.3rem;
}

.smb-note {
  padding: var(--s-5) var(--s-6);
  background: var(--surface-2);
  border: 1px solid var(--divider);
  border-radius: var(--r-md);
  font-size: var(--text-md);
  line-height: 1.65;
  color: var(--text);
  position: relative;
}

.smb-note::before {
  content: 'SMB Practice Note';
  display: block;
  font-family: var(--font-mono);
  font-size: 0.65rem;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: var(--s-3);
}

.fw-footer-nav {
  display: flex;
  justify-content: space-between;
  gap: var(--s-4);
  padding-top: var(--s-6);
  border-top: 1px solid var(--divider);
  margin-top: var(--s-10);
}

.fw-nav-link {
  flex: 1;
  padding: var(--s-4);
  border: 1px solid var(--divider);
  border-radius: var(--r-md);
  background: var(--surface);
  transition: all 150ms ease;
  max-width: 320px;
}

.fw-nav-link:hover {
  border-color: var(--primary);
  background: var(--surface-2);
}

.fw-nav-link.next { margin-left: auto; text-align: right; }

.fw-nav-link .dir {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 4px;
}

.fw-nav-link .label {
  font-family: var(--font-serif);
  font-size: 1.15rem;
  color: var(--text);
}

/* ==================== RESPONSIVE (graceful collapse) ==================== */
@media (max-width: 1200px) {
  .app {
    grid-template-columns: 240px 1fr 300px;
  }
  .main { padding: var(--s-6) var(--s-6) var(--s-16); }
}

@media (max-width: 960px) {
  .app {
    grid-template-columns: 1fr;
    grid-template-rows: 52px auto 1fr auto;
    grid-template-areas:
      "topbar"
      "left"
      "main"
      "right";
    height: auto;
    min-height: 100vh;
  }
  body { overflow: auto; height: auto; }
  .left-rail, .right-rail { max-height: none; border: none; border-bottom: 1px solid var(--border); }
  .main { padding: var(--s-5); }
  .stage-grid { grid-template-columns: 1fr; }
  .fw-table td.one-liner { display: none; }
  .topbar-meta { display: none; }
}
