/* ============================================================================
   CourseForge – application shell and the workspace panes.

   Breakpoints, and what changes at each:
     ≥ 1600px  full desktop: sidebar + outline + editor + inspector, all fixed
     ≥ 1280px  same, with narrower side panes
     ≥ 1024px  inspector collapses into a slide-over
     <  1024px sidebar and outline collapse into slide-overs, one column
   ========================================================================== */

/* -- shell ----------------------------------------------------------------- */
.shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  height: 100%;
  background: var(--bg);
}

.sidebar {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
}

.sidebar__brand {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  height: var(--header-h);
  padding: 0 var(--s-4);
  border-bottom: 1px solid var(--border-soft);
  flex: none;
}

.sidebar__mark {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  flex: none;
  border-radius: var(--r-md);
  background: linear-gradient(140deg, var(--accent), var(--accent-strong));
  color: var(--accent-ink);
}

.sidebar__name { font-weight: 650; letter-spacing: -0.015em; }

.sidebar__nav { display: flex; flex-direction: column; gap: 2px; padding: var(--s-3); }

.sidebar__foot {
  margin-top: auto;
  padding: var(--s-3);
  border-top: 1px solid var(--border-soft);
  display: flex;
  flex-direction: column;
  gap: var(--s-2);
}

.nav-item {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  padding: 8px 10px;
  border: 0;
  border-radius: var(--r-md);
  background: transparent;
  color: var(--text-muted);
  font-size: var(--t-sm);
  font-weight: 500;
  cursor: pointer;
  text-align: left;
  transition: background var(--speed) var(--ease), color var(--speed) var(--ease);
}
.nav-item:hover { background: var(--surface-hover); color: var(--text); }
.nav-item.is-active { background: var(--accent-soft); color: var(--accent); }
.nav-item__count {
  margin-left: auto;
  font-size: var(--t-2xs);
  font-variant-numeric: tabular-nums;
  color: var(--text-faint);
}

/* -- main column ----------------------------------------------------------- */
.main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}

.topbar {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  height: var(--header-h);
  flex: none;
  padding: 0 var(--s-5);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.topbar__title { font-size: var(--t-lg); font-weight: 620; letter-spacing: -0.015em; }

.crumbs { display: flex; align-items: center; gap: var(--s-2); min-width: 0; font-size: var(--t-sm); }
.crumbs__sep { color: var(--text-faint); }

.view { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; }
.view-scroll { flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain; }
.view-pad { padding: var(--s-6); }
.container { width: 100%; max-width: 1560px; margin-inline: auto; }
.container-narrow { width: 100%; max-width: 1080px; margin-inline: auto; }

/* -- tab bar --------------------------------------------------------------- */
.tabbar {
  display: flex;
  gap: 2px;
  flex: none;
  padding: 0 var(--s-5);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  scrollbar-width: none;
}
.tabbar::-webkit-scrollbar { display: none; }

.tab {
  position: relative;
  display: flex;
  align-items: center;
  gap: var(--s-2);
  padding: 10px 13px;
  border: 0;
  background: transparent;
  color: var(--text-muted);
  font-size: var(--t-sm);
  font-weight: 520;
  white-space: nowrap;
  cursor: pointer;
  transition: color var(--speed) var(--ease);
}
.tab::after {
  content: "";
  position: absolute;
  inset: auto 8px -1px 8px;
  height: 2px;
  border-radius: 2px;
  background: transparent;
  transition: background var(--speed) var(--ease);
}
.tab:hover { color: var(--text); }
.tab.is-active { color: var(--accent); }
.tab.is-active::after { background: var(--accent); }

/* -- workspace (structure / content) --------------------------------------- */
.workspace {
  display: grid;
  grid-template-columns: var(--outline-w) minmax(0, 1fr) var(--inspector-w);
  flex: 1 1 auto;
  min-height: 0;
}
.workspace--two { grid-template-columns: var(--outline-w) minmax(0, 1fr); }

.pane {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background: var(--bg);
}
.pane--left { background: var(--surface); border-right: 1px solid var(--border); }
.pane--right { background: var(--surface); border-left: 1px solid var(--border); }

.pane__head {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  flex: none;
  padding: var(--s-3) var(--s-4);
  border-bottom: 1px solid var(--border-soft);
  min-height: 46px;
}
.pane__body { flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain; }
.pane__foot { flex: none; padding: var(--s-3) var(--s-4); border-top: 1px solid var(--border-soft); }

/* -- editor split ---------------------------------------------------------- */
.split { display: grid; grid-template-columns: minmax(0, 1fr); flex: 1 1 auto; min-height: 0; }
.split--both { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
.split__half { min-width: 0; min-height: 0; display: flex; flex-direction: column; }
.split__half + .split__half { border-left: 1px solid var(--border); }

.code-area {
  flex: 1 1 auto;
  width: 100%;
  min-height: 0;
  padding: var(--s-5);
  border: 0;
  border-radius: 0;
  resize: none;
  background: var(--bg);
  font-family: var(--mono);
  font-size: var(--t-sm);
  line-height: 1.7;
  tab-size: 2;
}
.code-area:focus { box-shadow: none; background: var(--bg); }

/* -- drawers (small screens) ----------------------------------------------- */
.scrim {
  position: fixed;
  inset: 0;
  z-index: var(--z-drawer);
  background: var(--overlay);
  backdrop-filter: blur(2px);
  animation: cf-fade var(--speed) var(--ease);
}
@keyframes cf-fade { from { opacity: 0; } to { opacity: 1; } }

@media (max-width: 1599px) {
  :root { --outline-w: 292px; --inspector-w: 340px; }
}

@media (max-width: 1279px) {
  :root { --sidebar-w: 210px; --outline-w: 268px; }

  .workspace { grid-template-columns: var(--outline-w) minmax(0, 1fr); }

  /* The inspector becomes a slide-over that is only in the DOM flow when open. */
  .pane--right { display: none; }
  .pane--right.is-open {
    display: flex;
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    z-index: calc(var(--z-drawer) + 1);
    width: min(400px, 92vw);
    box-shadow: var(--shadow-lg);
    animation: cf-slide-right var(--speed) var(--ease);
  }
}

@keyframes cf-slide-right { from { transform: translateX(16px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes cf-slide-left  { from { transform: translateX(-16px); opacity: 0; } to { transform: none; opacity: 1; } }

@media (max-width: 1023px) {
  .shell { grid-template-columns: minmax(0, 1fr); }

  .sidebar { display: none; }
  .sidebar.is-open {
    display: flex;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: calc(var(--z-drawer) + 1);
    width: min(280px, 86vw);
    box-shadow: var(--shadow-lg);
    animation: cf-slide-left var(--speed) var(--ease);
  }

  .workspace { grid-template-columns: minmax(0, 1fr); }

  .pane--left { display: none; }
  .pane--left.is-open {
    display: flex;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: calc(var(--z-drawer) + 1);
    width: min(340px, 90vw);
    box-shadow: var(--shadow-lg);
    animation: cf-slide-left var(--speed) var(--ease);
  }

  .split--both { grid-template-columns: minmax(0, 1fr); }
  .split--both .split__half:last-child { display: none; }

  .topbar, .tabbar { padding-inline: var(--s-3); }
  .view-pad { padding: var(--s-4); }
  .grid-2, .grid-3 { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 640px) {
  :root { --header-h: 52px; }
  .view-pad { padding: var(--s-3); }
  .hide-sm { display: none !important; }
}

/* -- drawer triggers -------------------------------------------------------
   The .btn rule in components.css loads later, so these need the extra
   specificity of a compound selector to win rather than an !important. */
.btn.menu-toggle,
.btn.outline-toggle,
.btn.drawer-toggle { display: none; }

@media (max-width: 1279px) {
  .btn.drawer-toggle { display: inline-flex; }
}

@media (max-width: 1023px) {
  .btn.menu-toggle,
  .btn.outline-toggle { display: inline-flex; }
}

/* -- a side column that is a real grid column, never a drawer -------------- */
.pane--aside { background: var(--surface); border-left: 1px solid var(--border); }

/* Two panes that stack (and scroll) instead of squashing on small screens. */
@media (max-width: 1023px) {
  .workspace--stack {
    grid-template-columns: minmax(0, 1fr);
    grid-auto-rows: min-content;
    overflow-y: auto;
    overscroll-behavior: contain;
  }
  .workspace--stack .pane { min-height: 70vh; }
  .workspace--stack .pane--aside { border-left: 0; border-top: 1px solid var(--border); min-height: 0; }
  .workspace--stack .pane__body { overflow: visible; }
}

/* -- content-specific grids ------------------------------------------------ */
.grid-model   { grid-template-columns: 1.1fr 1.6fr 0.7fr 0.8fr; align-items: end; }
.grid-publish { grid-template-columns: minmax(0, 420px) minmax(0, 1fr); align-items: start; }

@media (max-width: 1279px) {
  .grid-model { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 1023px) {
  .grid-model, .grid-publish { grid-template-columns: minmax(0, 1fr); }
}
