/* design-system/css/app-shell.css
   Shared chrome for every Clevernest HUB page (library, learning goals,
   certifications, my progress). Provides: the app-shell layout (left vertical
   nav + main column), the top bar (star / XP chips + avatar-to-settings), the
   settings modal, and the shared page primitives (panels, stat tiles, progress
   bars, pills, buttons, fields, toggles) the section pages build on.
   The course PLAYER (course.html) is a focused mode and does NOT use this.
   Injected/wired by ui/app-shell.js. */

:root {
  --charcoal: #2D3640; --gold: #D2A56B; --offwhite: #F7F7F8; --white: #FFFFFF;
  --slate: #46515C; --coolgrey: #AEB6BF; --softblack: #1A1C20; --sand: #F3E8D0;
  --teal: #00C5CC; --teal-300: #66E5E8; --teal-700: #008A90; --teal-050: #E6FAFB;
  --gold-600: #B98A4E; --gold-100: #F1E2CB;
  --pink: #E91E63; --pink-050: #FDE9F0; --pink-700: #B4124B;
  --ink-100: #E4E7EA; --ink-050: #F0F1F3;
  --radius-md: 14px; --radius-lg: 20px; --radius-pill: 999px;
  --shadow-sm: 0 2px 8px rgba(45,54,64,0.06); --shadow-md: 0 8px 24px rgba(45,54,64,0.08);
  --shadow-lg: 0 24px 60px rgba(26,28,32,0.28);
  --ease-bounce: cubic-bezier(0.34, 1.56, 0.64, 1);
  --font-display: 'Bricolage Grotesque', 'Hanken Grotesk', 'Segoe UI', sans-serif;
  --font-ui: 'Hanken Grotesk', 'Segoe UI', sans-serif;
  --nav-collapsed: 84px;  /* icon + caption rail */
  --nav-expanded: 248px;  /* labelled drawer (hover-peek overlay, or pinned) */
  --content-max: 1520px; /* caps the main content so app components stay well-proportioned */
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { min-height: 100%; }
body.appshell {
  font-family: var(--font-ui); background: var(--offwhite); color: var(--charcoal);
  -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
}
.appshell .display { font-family: var(--font-display); }
button:focus-visible, input:focus-visible, a:focus-visible { outline: 2px solid var(--teal); outline-offset: 2px; }

/* ================= Vertical nav (collapsible charcoal rail) =================
   Collapsed by default: an 84px charcoal rail of icon + tiny caption. It widens
   to a labelled 248px drawer either transiently on hover-peek (overlaying the
   content) or permanently when the user pins it (pushing the content right).
   The `.expanded` visual selector below is shared by hover, pinned and mobile. */
.sidenav {
  width: var(--nav-collapsed); background: var(--charcoal); color: #fff;
  position: fixed; left: 0; top: 0; height: 100vh; height: 100dvh;
  display: flex; flex-direction: column; z-index: 60; overflow: hidden;
  transition: width 0.2s ease, box-shadow 0.2s ease;
}
/* Expansion is driven by an `.expanded` class (set in JS on hover-peek and pin),
   NOT the CSS :hover pseudo, so the pin can decisively collapse the rail even
   while the pointer is still over it. Pinned always carries `.expanded` too. */
.sidenav.expanded { width: var(--nav-expanded); }
.sidenav.expanded:not(.pinned) { box-shadow: 0 24px 60px rgba(26,28,32,0.45); }

.sidenav-logo { height: 64px; display: flex; align-items: center; padding: 0 22px; flex-shrink: 0; }
.sidenav-logo a { display: inline-flex; align-items: center; flex-shrink: 0; }
.sidenav-logo .logo-mark { height: 34px; width: 34px; display: block; }
.sidenav-logo .logo-full { height: 42px; width: auto; display: none; }
.sidenav.expanded .logo-mark { display: none; }
.sidenav.expanded .logo-full { display: block; }

/* Pin toggle: top-right of the rail, revealed only when the rail is expanded.
   Gold when active (pinned open), muted otherwise. */
.nav-pin { display: none; width: 30px; height: 30px; margin-left: auto; border: none; background: none; border-radius: 8px; cursor: pointer; align-items: center; justify-content: center; color: rgba(255,255,255,0.5); flex-shrink: 0; transition: background 0.15s, color 0.15s; }
.nav-pin svg { width: 16px; height: 16px; }
.nav-pin:hover { background: rgba(255,255,255,0.08); color: #fff; }
.nav-pin[aria-pressed="true"] { color: var(--gold); }
.sidenav.expanded .nav-pin { display: flex; }

.sidenav-nav { padding: 8px 14px; display: flex; flex-direction: column; gap: 6px; overflow-y: auto; overflow-x: hidden; flex: 1; }
.sidenav-sect { font-size: 10px; font-weight: 800; letter-spacing: 0.11em; text-transform: uppercase; color: rgba(255,255,255,0.4); padding: 12px 10px 4px; white-space: nowrap; opacity: 0; transition: opacity 0.15s; height: 0; overflow: hidden; }

.navitem {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  min-height: 56px; padding: 8px 6px; border-radius: 14px; text-decoration: none;
  color: rgba(255,255,255,0.62); font-size: 10px; font-weight: 700; letter-spacing: 0.2px;
  position: relative; transition: background 0.15s, color 0.15s; cursor: pointer;
  border: none; background: none; font-family: inherit; width: 100%;
}
.navitem svg { width: 22px; height: 22px; flex-shrink: 0; stroke: currentColor; }
.navitem .nl { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.navitem:hover { background: rgba(255,255,255,0.08); color: #fff; }
.navitem.active { background: rgba(210,165,107,0.16); color: var(--gold); }
.navitem .nav-badge {
  min-width: 18px; height: 18px; padding: 0 5px; border-radius: 999px;
  background: rgba(255,255,255,0.16); color: #fff; font-size: 10.5px; font-weight: 800;
  display: none; align-items: center; justify-content: center;
}
.navitem.active .nav-badge { background: var(--gold); color: var(--charcoal); }

.sidenav-foot { padding: 10px 14px 16px; display: flex; flex-direction: column; gap: 6px; flex-shrink: 0; border-top: 1px solid rgba(255,255,255,0.08); }

/* ---- Expanded visual state (hover-peek, pinned, or mobile drawer) ---- */
.sidenav.expanded .sidenav-sect { opacity: 1; height: auto; }
.sidenav.expanded .navitem {
  flex-direction: row; justify-content: flex-start; gap: 14px;
  padding: 0 14px; min-height: 46px; font-size: 14.5px; font-weight: 700;
}
.sidenav.expanded .navitem .nav-badge { display: flex; margin-left: auto; }

/* mobile off-canvas + backdrop */
.nav-scrim { display: none; position: fixed; inset: 0; background: rgba(26,28,32,0.42); z-index: 55; }
.nav-scrim.show { display: block; }

/* ================= Main column ================= */
.appmain { margin-left: var(--nav-collapsed); min-width: 0; display: flex; flex-direction: column; min-height: 100vh; transition: margin-left 0.2s ease; }
body.nav-pinned .appmain { margin-left: var(--nav-expanded); }

.topbar {
  position: sticky; top: 0; z-index: 40; display: flex; justify-content: center;
  background: var(--white); border-bottom: 1px solid var(--ink-100);
}
.topbar-inner {
  width: 100%; max-width: var(--content-max); height: 64px; padding: 0 108px;
  display: flex; align-items: center; gap: 12px;
}

/* breadcrumbs (left of the topbar) */
.crumbs { display: flex; align-items: center; gap: 9px; min-width: 0; font-size: 14px; font-weight: 700; overflow: hidden; }
.crumbs a { color: var(--slate); text-decoration: none; white-space: nowrap; }
.crumbs a:hover { color: var(--charcoal); }
.crumbs .sep { color: var(--coolgrey); flex-shrink: 0; }
.crumbs .here { color: var(--charcoal); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.navtoggle {
  display: none; width: 38px; height: 38px; margin-left: -6px; border: none; background: none;
  border-radius: 10px; cursor: pointer; align-items: center; justify-content: center; color: var(--charcoal);
}
.navtoggle:hover { background: var(--ink-050); }
.navtoggle svg { width: 20px; height: 20px; }
.topbar .spacer { flex: 1; }
.chip-stat {
  display: flex; align-items: center; gap: 6px; height: 34px; padding: 0 14px; flex-shrink: 0;
  border-radius: var(--radius-pill); font-size: 13px; font-weight: 800;
  background: linear-gradient(180deg, #F3E8D0, #D2A56B); color: #6B4E20;
  box-shadow: inset 0 1px 0 #F3E8D0, inset 0 -2px 0 #B98A4E, 0 2px 6px rgba(210,165,107,0.35);
  font-variant-numeric: tabular-nums;
}
.avatar-btn {
  width: 38px; height: 38px; border-radius: 50%; flex-shrink: 0; border: 2px solid var(--ink-100);
  background: var(--charcoal); color: #fff; cursor: pointer; padding: 0; overflow: hidden;
  display: flex; align-items: center; justify-content: center; font-size: 13.5px; font-weight: 800;
  transition: box-shadow 0.15s, border-color 0.15s;
}
.avatar-btn:hover { border-color: var(--gold); box-shadow: 0 0 0 3px rgba(210,165,107,0.22); }
.avatar-btn img { width: 100%; height: 100%; object-fit: cover; }

/* ================= Page frame + primitives ================= */
/* Fills the main column with balanced gutters, so content sits close to the nav
   on the left and the same distance from the right edge, at any width. */
.page { width: 100%; max-width: var(--content-max); margin: 0 auto; padding: 28px 108px 90px; }
.pagehead { margin: 6px 0 24px; display: flex; align-items: flex-end; justify-content: space-between; gap: 18px; flex-wrap: wrap; }
.pagehead h1 {
  font-family: var(--font-display); font-weight: 800; font-size: 34px; letter-spacing: 0.01em;
  text-transform: uppercase; color: var(--charcoal); line-height: 1.05;
}
.pagehead p { margin-top: 7px; font-size: 15px; color: var(--slate); max-width: 620px; line-height: 1.55; }
.pagehead .headline-actions { display: flex; gap: 10px; }

.sect-title { font-family: var(--font-display); font-weight: 800; font-size: 20px; color: var(--charcoal); letter-spacing: -0.01em; }
.sect-sub { font-size: 13.5px; color: var(--slate); margin-top: 3px; line-height: 1.5; }

.panel {
  background: var(--white); border: 1px solid var(--ink-100); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm); padding: 22px 24px;
}
.panel-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; margin-bottom: 16px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.grid4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }
.stack { display: flex; flex-direction: column; gap: 18px; }

/* stat tiles */
.stat-tile {
  background: var(--white); border: 1px solid var(--ink-100); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm); padding: 18px 18px 16px; display: flex; flex-direction: column; gap: 10px;
}
.stat-ico {
  width: 40px; height: 40px; border-radius: 12px; display: flex; align-items: center; justify-content: center;
  background: var(--teal-050); color: var(--teal-700);
}
.stat-ico svg { width: 21px; height: 21px; stroke: currentColor; }
.stat-ico.gold { background: var(--gold-100); color: var(--gold-600); }
.stat-ico.pink { background: var(--pink-050); color: var(--pink-700); }
.stat-num { font-family: var(--font-display); font-weight: 800; font-size: 30px; color: var(--charcoal); line-height: 1; font-variant-numeric: tabular-nums; }
.stat-lbl { font-size: 12.5px; font-weight: 700; color: var(--slate); }
.stat-delta { font-size: 11.5px; font-weight: 800; color: var(--teal-700); }

/* progress bar */
.pbar { height: 8px; border-radius: 999px; background: var(--ink-100); overflow: hidden; }
.pbar > i { display: block; height: 100%; border-radius: 999px; background: linear-gradient(90deg, var(--teal-300), var(--teal)); }
.pbar.gold > i { background: linear-gradient(90deg, var(--sand), var(--gold)); }
.pbar.pink > i { background: linear-gradient(90deg, #FF7CA6, var(--pink)); }

/* pills / tags */
.pill { display: inline-flex; align-items: center; gap: 6px; height: 24px; padding: 0 11px; border-radius: 999px; font-size: 11.5px; font-weight: 800; letter-spacing: 0.02em; white-space: nowrap; }
.pill svg { width: 12px; height: 12px; }
.pill-teal { background: var(--teal-050); color: var(--teal-700); }
.pill-gold { background: var(--gold-100); color: var(--gold-600); }
.pill-pink { background: var(--pink-050); color: var(--pink-700); }
.pill-grey { background: var(--ink-050); color: var(--slate); }
.pill-solid-teal { background: var(--teal); color: #fff; }

/* buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 42px; padding: 0 20px; border-radius: var(--radius-pill); border: none; cursor: pointer; font-family: inherit; font-size: 14px; font-weight: 800; text-decoration: none; transition: transform 0.12s, box-shadow 0.15s, background 0.15s, border-color 0.15s, filter 0.15s; white-space: nowrap; }
/* Hover lifts, press sinks. :active is declared after :hover so a held click
   wins while the pointer is still over the button. */
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(1px); transition-duration: 0.05s; }
.btn:focus-visible { outline: 2.5px solid var(--gold-600); outline-offset: 2px; }
.btn svg { width: 17px; height: 17px; }
.btn-teal { background: linear-gradient(180deg, #12D3DA, #00B3BA); color: #fff; box-shadow: inset 0 -2px 0 #008A90, 0 3px 10px rgba(0,197,204,0.32); }
.btn-teal:hover { box-shadow: inset 0 -2px 0 #008A90, 0 6px 18px rgba(0,197,204,0.42); }
.btn-teal:active { box-shadow: inset 0 -1px 0 #008A90, 0 1px 4px rgba(0,197,204,0.3); }
.btn-teal:focus-visible { outline-color: var(--teal-700); }
.btn-gold { background: linear-gradient(180deg, #E0BE86, #C99A56); color: #4A3413; box-shadow: inset 0 -2px 0 #B98A4E, 0 3px 10px rgba(210,165,107,0.34); }
.btn-gold:hover { background: linear-gradient(180deg, #E7C892, #D2A56B); box-shadow: inset 0 -2px 0 #B98A4E, 0 6px 18px rgba(210,165,107,0.46); }
.btn-gold:active { background: linear-gradient(180deg, #D9B276, #BE8F4C); box-shadow: inset 0 -1px 0 #B98A4E, 0 1px 4px rgba(210,165,107,0.3); }
.btn-ghost { background: var(--white); color: var(--slate); border: 1.5px solid var(--ink-100); }
.btn-ghost:hover { border-color: var(--coolgrey); color: var(--charcoal); box-shadow: var(--shadow-sm); }
.btn-ghost:active { background: var(--offwhite); box-shadow: none; }
.btn-danger { background: var(--white); color: var(--pink-700); border: 1.5px solid #F3C6D5; }
.btn-danger:hover { background: var(--pink-050); border-color: var(--pink); }
.btn-danger:focus-visible { outline-color: var(--pink-700); }
.btn-sm { height: 34px; padding: 0 14px; font-size: 13px; }
.btn-block { width: 100%; }

/* segmented control */
.seg { display: inline-flex; background: var(--ink-050); border-radius: var(--radius-pill); padding: 3px; gap: 2px; }
.seg button { border: none; background: none; cursor: pointer; font-family: inherit; font-size: 13px; font-weight: 800; color: var(--slate); height: 32px; padding: 0 16px; border-radius: var(--radius-pill); transition: background 0.15s, color 0.15s; }
.seg button.on { background: var(--white); color: var(--charcoal); box-shadow: var(--shadow-sm); }

/* fields + toggles (settings, reminders) */
.field { display: flex; flex-direction: column; gap: 7px; }
.field label { font-size: 12.5px; font-weight: 800; color: var(--slate); }
.field input, .field select {
  height: 44px; padding: 0 14px; border-radius: 12px; border: 1.5px solid var(--ink-100);
  background: var(--white); font-family: inherit; font-size: 14.5px; color: var(--charcoal); width: 100%;
}
.field input:focus, .field select:focus { outline: none; border-color: var(--teal); box-shadow: 0 0 0 3px rgba(0,197,204,0.16); }
.field input[readonly] { background: var(--offwhite); color: var(--slate); }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }

.switch { position: relative; width: 44px; height: 26px; flex-shrink: 0; }
.switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.switch .track { position: absolute; inset: 0; border-radius: 999px; background: var(--ink-100); transition: background 0.18s; }
.switch .track::after { content: ''; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(45,54,64,0.3); transition: transform 0.18s; }
.switch input:checked + .track { background: var(--teal); }
.switch input:checked + .track::after { transform: translateX(18px); }
.toggle-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 13px 0; border-bottom: 1px solid var(--ink-050); }
.toggle-row:last-child { border-bottom: none; }
.toggle-row .tr-label { font-size: 14px; font-weight: 700; color: var(--charcoal); }
.toggle-row .tr-sub { font-size: 12.5px; color: var(--slate); margin-top: 2px; }

/* ================= Settings modal ================= */
.modal-scrim {
  position: fixed; inset: 0; background: rgba(26,28,32,0.5); backdrop-filter: blur(3px);
  display: none; align-items: flex-start; justify-content: center; padding: 40px 20px; z-index: 100; overflow-y: auto;
}
.modal-scrim.show { display: flex; }
.modal {
  width: 100%; max-width: 540px; background: var(--white); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg); overflow: hidden; animation: modalpop 0.24s var(--ease-bounce);
}
@keyframes modalpop { from { opacity: 0; transform: translateY(14px) scale(0.98); } to { opacity: 1; transform: none; } }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 20px 22px; border-bottom: 1px solid var(--ink-100); }
.modal-head h2 { font-family: var(--font-display); font-weight: 800; font-size: 20px; color: var(--charcoal); }
.modal-close { width: 34px; height: 34px; border: none; background: none; border-radius: 9px; cursor: pointer; color: var(--slate); display: flex; align-items: center; justify-content: center; }
.modal-close:hover { background: var(--ink-050); color: var(--charcoal); }
.modal-body { padding: 22px; display: flex; flex-direction: column; gap: 20px; }
.modal-foot { padding: 16px 22px; border-top: 1px solid var(--ink-100); display: flex; align-items: center; justify-content: flex-end; gap: 10px; background: var(--offwhite); }

.avatar-edit { display: flex; align-items: center; gap: 18px; }
.avatar-big { position: relative; width: 88px; height: 88px; flex-shrink: 0; }
.avatar-big .ab-face { width: 88px; height: 88px; border-radius: 50%; background: var(--charcoal); color: #fff; display: flex; align-items: center; justify-content: center; font-family: var(--font-display); font-size: 30px; font-weight: 800; overflow: hidden; }
.avatar-big .ab-face img { width: 100%; height: 100%; object-fit: cover; }
.avatar-big .ab-cam { position: absolute; right: -2px; bottom: -2px; width: 30px; height: 30px; border-radius: 50%; background: var(--teal); color: #fff; border: 3px solid #fff; display: flex; align-items: center; justify-content: center; cursor: pointer; }
.avatar-big .ab-cam svg { width: 15px; height: 15px; }
.avatar-edit .ae-actions { display: flex; flex-direction: column; gap: 8px; }
.avatar-edit .ae-hint { font-size: 12px; color: var(--coolgrey); }

.danger-zone { border: 1.5px solid #F3C6D5; border-radius: var(--radius-md); padding: 15px 16px; background: var(--pink-050); }
.danger-zone h4 { font-size: 13.5px; font-weight: 800; color: var(--pink-700); }
.danger-zone p { font-size: 12.5px; color: var(--slate); margin: 4px 0 12px; line-height: 1.5; }

.divider { height: 1px; background: var(--ink-100); border: none; }

/* ================= Responsive ================= */
/* Ease the wide desktop gutters back on narrower viewports so content is not
   squeezed once the main column loses room. */
@media (max-width: 1360px) {
  .page { padding-left: 60px; padding-right: 60px; }
  .topbar-inner { padding: 0 60px; }
}
@media (max-width: 900px) {
  .appmain, body.nav-pinned .appmain { margin-left: 0; }
  .page { padding-left: 36px; padding-right: 36px; }
  .topbar-inner { padding: 0 36px; }
  /* Off-canvas drawer: always the full labelled width, slid off-screen until opened. */
  .sidenav, .sidenav.pinned { width: var(--nav-expanded); transform: translateX(-100%); transition: transform 0.24s ease; box-shadow: none; }
  .sidenav.open { transform: none; box-shadow: var(--shadow-lg); }
  .sidenav .sidenav-sect { opacity: 1; height: auto; }
  .sidenav .logo-mark { display: none; }
  .sidenav .logo-full { display: block; }
  .sidenav .nav-pin { display: none !important; }
  .sidenav .navitem { flex-direction: row; justify-content: flex-start; gap: 14px; padding: 0 14px; min-height: 46px; font-size: 14.5px; }
  .sidenav .navitem .nav-badge { display: flex; margin-left: auto; }
  .navtoggle { display: flex; }
  .grid4 { grid-template-columns: 1fr 1fr; }
  .grid3 { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  .page { padding: 22px 18px 80px; }
  .topbar-inner { padding: 0 18px; }
  .pagehead h1 { font-size: 27px; }
  .grid2 { grid-template-columns: 1fr; }
  .grid4 { grid-template-columns: 1fr 1fr; }
  .field-row { grid-template-columns: 1fr; }
  .chip-stat.xp { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  .modal, .sidenav { animation: none; transition: none; }
}
