/* ============================================================================
   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); overflow-y: auto; min-height: 0; }

/* The heading over a group of destinations: "Workspace", "Administration".
   A glyph beside the word, both a step quieter than the entries under it. */
.nav-section {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: var(--s-2) 10px var(--s-1);
  font-size: var(--t-2xs);
  font-weight: 650;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--text-faint);
}
.nav-section + .nav-item { margin-top: 1px; }
.nav-section--later { margin-top: var(--s-3); padding-top: var(--s-3); border-top: 1px solid var(--border-soft); }

.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 > .icon { color: var(--text-dim); transition: color var(--speed) var(--ease); }
.nav-item:hover > .icon, .nav-item.is-active > .icon { color: currentColor; }
.nav-item__count {
  margin-left: auto;
  padding: 1px 7px;
  border-radius: var(--r-pill);
  background: var(--neutral-soft);
  font-size: var(--t-2xs);
  font-variant-numeric: tabular-nums;
  color: var(--text-faint);
}
.nav-item.is-active .nav-item__count { background: var(--accent-soft); }

/* The account entry at the foot: an avatar, the name and the role. */
.sidebar__user { align-items: center; }
.sidebar__user-name { font-size: var(--t-sm); font-weight: 550; line-height: 1.2; }
.sidebar__user-role { font-size: var(--t-2xs); color: var(--text-faint); line-height: 1.2; }

/* Dark, light, or whatever the system says: three glyphs in a segmented
   control, the chosen one raised. */
.theme-switch {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 2px;
  padding: 3px;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--surface-2);
}
.theme-switch__opt {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 5px 0;
  border: 0;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--text-dim);
  font-size: var(--t-2xs);
  font-weight: 600;
  cursor: pointer;
  transition: background var(--speed) var(--ease), color var(--speed) var(--ease);
}
.theme-switch__opt:hover { color: var(--text); }
.theme-switch__opt.is-active { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }

/* Keyboard users land on the page, not on the navigation, by pressing Tab
   once: the link is invisible until it has the focus. */
.skip-link {
  position: absolute;
  top: -100px;
  left: var(--s-3);
  z-index: var(--z-toast);
  padding: 8px 12px;
  border-radius: var(--r-md);
  background: var(--accent);
  color: var(--accent-ink);
  font-size: var(--t-sm);
  font-weight: 600;
}
.skip-link:focus { top: var(--s-3); outline: 2px solid var(--accent-ink); }

/* -- 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; }

/* The title and, under it, one line on what the screen is for. The line goes
   on a narrow screen, where the header has room for the title alone. */
.topbar__titles { display: flex; flex-direction: column; min-width: 0; line-height: 1.2; }
.topbar__sub { font-size: var(--t-xs); color: var(--text-dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.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;
}

/*
 * A pane can be a narrow column - the outline is 320px - and its head still
 * carries a label, a badge and two buttons. The label is the item that gives
 * way, and with `min-width: 0` from `.grow` it gave way all the way to nothing:
 * it wrapped to three lines and painted itself underneath the badge. Keeping it
 * whole is what pushes the rest onto a second row instead, which is why these
 * heads wrap.
 *
 * Only the heads that are labelled this way, hence the `:has()`: a head built
 * around a text field wants that field as wide as the row can make it, and
 * wrapping it would cost a phone two rows of height for nothing. An eyebrow that
 * asked for `truncate` has said it would rather be cut short, so it is left out
 * of both rules.
 */
.pane__head:has(> .eyebrow:not(.truncate)) { flex-wrap: wrap; }
.pane__head:has(> .eyebrow:not(.truncate)) > .eyebrow { white-space: nowrap; min-width: max-content; }
.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; }
  .topbar__sub { display: none; }
}

/* -- 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; }
}

/* -- the Structure tab ------------------------------------------------------
   The outline takes the width and the AI panel is the inspector column on
   the right - and below 1280px it is the same drawer the Content tab's
   inspector becomes, which the .pane--right rules above already draw. */
.workspace--editor-aside { grid-template-columns: minmax(0, 1fr) var(--inspector-w); }

@media (max-width: 1279px) {
  .workspace--editor-aside { grid-template-columns: minmax(0, 1fr); }
}

/* -- 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); }
}
