/* ── OctoDecks app shell ─────────────────────────────────────────────────────
   One page frame for the teacher's "home" pages (Deck library, Interactive
   Sessions): header with the search box in the middle, a left side menu with a
   "New" button on top, and a page head over the content. Load after ui.css.
   js/app-shell.js adds search behaviour and the keyboard shortcuts box.

     Body ........ body.as-page  (maps each page's own colour names to --as-*)
     Header ...... .as-header > .as-brand  .as-search  .as-actions(.hdr-actions)
     Layout ...... .as-layout > .as-sidebar + .as-main
     Side menu ... .as-new  .sb-section  .sb-heading  .sb-item  .sb-item-name  .sb-count
     Page head ... .as-page-head > .as-page-titles (h1 + p + .as-page-count)  .as-page-actions
     Shortcuts ... .as-kbd-*  (built by app-shell.js)

   Each page names its colours differently (the library: --bg/--card/--text,
   Interactive Sessions: --bg-light/--bg-white/--text-primary), so the shell
   reads either. */

body.as-page {
  --as-bg: var(--bg, var(--bg-light, #f4f5f7));
  --as-surface: var(--card, var(--bg-white, #fff));
  --as-surface2: var(--card2, var(--grey-100, #eef0f3));
  --as-text: var(--text, var(--text-primary, #1d1f23));
  --as-muted: var(--muted, var(--text-secondary, #5f6670));
  --as-border: var(--border, var(--border-color, #d3d7dd));
  --as-accent: var(--accent, var(--oct-accent));
  --as-header-h: 64px;
  --as-font: 'Atkinson Hyperlegible Next', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--as-bg); color: var(--as-text);
}

/* ── Header ─────────────────────────────────────────────────────────────── */
.as-header {
  position: sticky; top: 0; z-index: 100;
  display: grid; grid-template-columns: 240px minmax(0, 1fr) auto; align-items: center; gap: var(--oct-sp-4);
  min-height: var(--as-header-h); padding: var(--oct-sp-2) var(--oct-sp-4) var(--oct-sp-2) var(--oct-sp-3); box-sizing: border-box;
  background: var(--as-bg);   /* page colour, no dividing line: the header is part of the page */
}
.as-brand {
  display: inline-flex; align-items: center; gap: var(--oct-sp-3); min-width: 0; padding: var(--oct-sp-1) var(--oct-sp-2) var(--oct-sp-1) var(--oct-sp-1);
  border-radius: var(--oct-r-pill); color: inherit; text-decoration: none; transition: var(--oct-trans);
}
.as-brand:hover { background: var(--oct-state-hover); }
.as-brand:active { background: var(--oct-state-press); }
.as-brand-logo { width: 38px; height: 38px; border-radius: 10px; display: block; flex-shrink: 0; }
.as-brand-stack { display: flex; flex-direction: column; line-height: 1.12; min-width: 0; }
.as-brand-name { font-size: var(--oct-fs-4); font-weight: 600; letter-spacing: -.01em; color: var(--as-text); white-space: nowrap; }
.as-brand-sub { font-size: var(--oct-fs-1); font-weight: 600; color: var(--as-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Search: a wide pill in the middle, like the search in an office suite */
.as-search {
  position: relative; display: flex; align-items: center; gap: 10px;
  width: 100%; max-width: 720px; height: 48px; padding: 0 var(--oct-sp-2) 0 var(--oct-sp-4); box-sizing: border-box;
  border-radius: var(--oct-r-pill); background: var(--as-surface2); border: 1px solid transparent;
  color: var(--as-muted); transition: var(--oct-trans);
}
.as-search:focus-within { background: var(--as-surface); border-color: var(--as-border); box-shadow: var(--oct-elev-2); }
.as-search > svg, .as-search > .oi { width: 20px; height: 20px; flex-shrink: 0; }
.as-search input {
  flex: 1; min-width: 0; height: 100%; border: none !important; outline: none; background: none;
  box-shadow: none !important; padding: 0; color: var(--as-text); font: inherit; font-size: var(--oct-fs-3);
}
.as-search input::placeholder { color: var(--as-muted); opacity: 1; }
.as-search input::-webkit-search-cancel-button { display: none; }
.as-search-key {
  flex-shrink: 0; min-width: 22px; height: 22px; padding: 0 6px; box-sizing: border-box;
  display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid var(--as-border); border-radius: var(--oct-r-sm); background: var(--as-surface);
  font: 600 var(--oct-fs-1)/1 var(--as-font); color: var(--as-muted);
}
.as-search:focus-within .as-search-key, .as-search.has-text .as-search-key { display: none; }
.as-search-clear {
  display: none; width: 32px; height: 32px; flex-shrink: 0; border: none; border-radius: 50%;
  background: none; color: var(--as-muted); cursor: pointer; align-items: center; justify-content: center;
}
.as-search.has-text .as-search-clear { display: inline-flex; }
.as-search-clear:hover { background: var(--oct-state-hover); color: var(--as-text); }
.as-search-clear:active { background: var(--oct-state-press); }
.as-search-clear::before {
  content: ''; width: 12px; height: 12px; background: currentColor;
  -webkit-mask: var(--oct-mask-x) center / contain no-repeat; mask: var(--oct-mask-x) center / contain no-repeat;
}

.as-actions { display: flex; align-items: center; justify-content: flex-end; gap: 8px; flex-shrink: 0; }
.as-icon-btn {
  width: var(--oct-h-md); height: var(--oct-h-md); flex-shrink: 0; border: none; border-radius: 50%; background: none;
  display: inline-flex; align-items: center; justify-content: center; color: var(--as-muted); cursor: pointer;
  transition: var(--oct-trans);
}
.as-icon-btn:hover { background: var(--oct-state-hover); color: var(--as-text); }
.as-icon-btn:active { background: var(--oct-state-press); }
.as-icon-btn svg, .as-icon-btn .oi { width: 18px; height: 18px; }

/* ── Layout ─────────────────────────────────────────────────────────────────
   The frame (header, side menu) sits on the page colour; the content gets its
   own rounded box that scrolls on its own, while header and menu stay put. */
body.as-page { height: 100vh; height: 100dvh; overflow: hidden; }
.as-layout { display: flex; align-items: stretch; height: calc(100vh - var(--as-header-h)); height: calc(100dvh - var(--as-header-h)); }
.as-sidebar {
  width: 240px; flex-shrink: 0; box-sizing: border-box; padding: var(--oct-sp-2) var(--oct-sp-3) var(--oct-sp-10);
  overflow-y: auto;
}
.as-main {
  flex: 1; min-width: 0; box-sizing: border-box; padding: var(--oct-sp-8) var(--oct-sp-8) var(--oct-sp-12);
  margin: 0 16px 16px 0; border-radius: var(--oct-r-panel);
  background: var(--as-surface); overflow-y: auto; overscroll-behavior: contain;
}

/* "New" button at the top of the side menu: the page's main action, a blue pill.
   Dark octopus blue in both themes so the white label always reads (5.6:1). */
.as-new {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: var(--oct-h-lg); padding: 0 var(--oct-sp-5) 0 var(--oct-sp-4); margin: 0 0 var(--oct-sp-5) 0; box-sizing: border-box;
  border: none; border-radius: var(--oct-r-pill); background: var(--oct-brand); color: #fff;
  box-shadow: var(--oct-elev-1);
  font: 700 var(--oct-fs-2)/1 var(--as-font); text-decoration: none; white-space: nowrap; cursor: pointer;
  transition: var(--oct-trans);
}
.as-new:hover { background: #06599a; box-shadow: var(--oct-elev-2); }
.as-new:active { background: #054c84; box-shadow: var(--oct-elev-1); }
.as-new::before {
  content: ''; width: 14px; height: 14px; flex-shrink: 0;
  background: var(--oct-img-plus) center / 14px no-repeat;
}

/* Small controls in a page head (sort, rebuild covers…): one height, outline pill */
.as-tool {
  display: inline-flex; align-items: center; gap: var(--oct-sp-2); height: 36px; padding: 0 var(--oct-sp-4); box-sizing: border-box;
  border: 1px solid var(--as-border); border-radius: var(--oct-r-pill); background: transparent; color: var(--as-text);
  font: 600 var(--oct-fs-2)/1 var(--as-font); white-space: nowrap; cursor: pointer; transition: var(--oct-trans);
}
.as-tool:hover { background: var(--oct-state-hover); }
.as-tool:active { background: var(--oct-state-press); }
.as-tool svg, .as-tool .oi { width: 16px; height: 16px; flex-shrink: 0; color: var(--as-muted); }
select.as-tool {
  appearance: none; -webkit-appearance: none; padding-right: 34px;
  background: transparent url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpath d='M3 4.5l3 3 3-3' fill='none' stroke='%237a7f88' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") right 12px center / 12px no-repeat;
}
select.as-tool:hover { background-color: var(--oct-state-hover); }
select.as-tool option { background: var(--as-surface); color: var(--as-text); }

/* Side menu */
.sb-section { margin-bottom: 20px; }
.sb-heading { font-size: var(--oct-fs-1); font-weight: 700; color: var(--as-muted); padding: 0 var(--oct-sp-3); margin-bottom: var(--oct-sp-1); }
.sb-item {
  display: flex; align-items: center; gap: var(--oct-sp-3); width: 100%; min-height: 36px; padding: var(--oct-sp-2) var(--oct-sp-3); box-sizing: border-box;
  border: none; border-radius: var(--oct-r-pill); background: none; color: var(--as-text);
  font: 500 var(--oct-fs-2) var(--as-font); text-align: left; cursor: pointer; user-select: none; position: relative;
  transition: var(--oct-trans);
}
.sb-item:hover { background: var(--oct-state-hover); }
.sb-item:active { background: var(--oct-state-press); }
.sb-item.active { background: var(--oct-accent-a15); color: var(--as-accent); font-weight: 700; }
.sb-item-icon { width: 16px; height: 16px; flex-shrink: 0; opacity: .75; }
.sb-item-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sb-count { font-size: var(--oct-fs-1); font-weight: 600; color: var(--as-muted); flex-shrink: 0; }
.sb-item.active .sb-count { color: var(--as-accent); }

/* ── Page head ──────────────────────────────────────────────────────────── */
.as-page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 10px 16px; margin-bottom: 20px; }
.as-page-titles { flex: 1 1 260px; min-width: 0; }
.as-page-titles h1, .as-page-titles h2 { font-size: var(--oct-fs-6); font-weight: 700; letter-spacing: -.02em; color: var(--as-text); margin: 0 0 4px; overflow-wrap: anywhere; }
.as-page-titles p { font-size: var(--oct-fs-2); color: var(--as-muted); line-height: 1.5; margin: 0; max-width: 60ch; }
.as-page-count { font-size: var(--oct-fs-1); font-weight: 600; color: var(--as-muted); margin-top: 6px; }
.as-page-count:empty { display: none; }
.as-page-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; flex: 0 0 auto; }

/* Nothing matched a search */
.as-no-results { display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 64px 24px; text-align: center; color: var(--as-muted); }
.as-no-results[hidden] { display: none; }
.as-no-results img { width: 80px; height: 80px; }
.as-no-results strong { font-size: var(--oct-fs-3); color: var(--as-text); }

/* ── Keyboard shortcuts box ─────────────────────────────────────────────── */
.as-kbd-backdrop { position: fixed; inset: 0; z-index: 9500; display: flex; align-items: center; justify-content: center; padding: 16px; }
.as-kbd-backdrop[hidden] { display: none; }
.as-kbd-panel { width: 100%; max-width: 560px; max-height: 86vh; display: flex; flex-direction: column; overflow: hidden; }
.as-kbd-body { padding: 4px 20px 20px; overflow-y: auto; }
.as-kbd-group + .as-kbd-group { margin-top: 18px; }
.as-kbd-group h3 { font-size: var(--oct-fs-2); font-weight: 700; color: var(--as-text); margin: 0 0 6px; }
.as-kbd-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 7px 0; border-bottom: 1px solid var(--as-border); font-size: var(--oct-fs-2); color: var(--as-text); }
.as-kbd-row:last-child { border-bottom: none; }
.as-kbd-keys { display: inline-flex; gap: 4px; flex-shrink: 0; }
.as-kbd-keys kbd {
  min-width: 26px; height: 26px; padding: 0 7px; box-sizing: border-box; display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid var(--as-border); border-bottom-width: 2px; border-radius: var(--oct-r-sm);
  background: var(--as-surface2); font: 700 var(--oct-fs-1)/1 var(--as-font); color: var(--as-text);
}

/* ── Smaller screens ────────────────────────────────────────────────────── */
@media (max-width: 1000px) {
  .as-header { grid-template-columns: auto minmax(0, 1fr) auto; }
  .as-brand-sub { display: none; }
}
@media (max-width: 720px) {
  body.as-page { --as-header-h: 112px; height: auto; overflow: visible; }
  .as-header { grid-template-columns: minmax(0, 1fr) auto; gap: 8px 10px; padding: 8px 12px; }
  .as-search { grid-column: 1 / -1; grid-row: 2; max-width: none; height: 42px; }
  .as-search-key { display: none; }
  .as-brand-logo { width: 32px; height: 32px; }
  .as-layout { flex-direction: column; align-items: stretch; height: auto; }
  .as-sidebar {
    width: 100%; height: auto; position: static; overflow: visible;
    padding: 12px 12px 10px; border-bottom: 1px solid var(--as-border);
    display: flex; flex-wrap: wrap; gap: 6px; align-items: center;
  }
  .as-sidebar > nav { display: contents; }
  .as-new { height: var(--oct-h-lg); margin: 0; padding: 0 16px 0 13px; font-size: var(--oct-fs-2); }
  .sb-section { display: contents; }
  .sb-heading { display: none; }
  .sb-item { display: inline-flex; align-items: center; width: auto; min-height: 0; height: var(--oct-h-md); box-sizing: border-box; border: 1px solid var(--as-border); padding: 0 12px; font-size: var(--oct-fs-2); }
  .sb-item.active { border-color: var(--as-accent); }
  /* Phones: no box, the content runs full width and the whole page scrolls */
  .as-main { padding: 20px 16px 40px; margin: 0; border-radius: 0; overflow: visible; background: var(--as-bg); }
  .as-page-titles h1, .as-page-titles h2 { font-size: var(--oct-fs-5); }
}
