/* ============================================================================
 * base.css — resets, typography, the ONE shared app-shell layout + responsive.
 * Layout is identical across all four themes (themes only swap tokens).
 * ========================================================================== */

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: var(--font); font-size: 15px; line-height: 1.5;
  -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
  transition: background var(--t), color var(--t);
}
h1,h2,h3,h4 { font-family: var(--font-display); margin: 0; font-weight: var(--fw-bold); letter-spacing: -.01em; }
h1 { font-size: 1.9rem; } h2 { font-size: 1.3rem; } h3 { font-size: 1.05rem; }
a { color: var(--primary); text-decoration: none; }
button { font-family: inherit; -webkit-tap-highlight-color: transparent; }
img { max-width: 100%; display: block; }
::selection { background: var(--primary-weak); }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.dim { color: var(--text-2); }
.nowrap { white-space: nowrap; }
.spacer { flex: 1; }
.scroll-y { overflow-y: auto; }

/* scrollbars */
* { scrollbar-width: thin; scrollbar-color: var(--border-2) transparent; }
*::-webkit-scrollbar { width: 9px; height: 9px; }
*::-webkit-scrollbar-thumb { background: var(--border-2); border-radius: var(--pill); }
*::-webkit-scrollbar-track { background: transparent; }

/* ---- icons (Lucide sprite, stroke=currentColor) -------------------------- */
.ico { width: 20px; height: 20px; flex: none; stroke: currentColor; fill: none;
  stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.ico.sm { width: 16px; height: 16px; } .ico.lg { width: 24px; height: 24px; }

/* ============================================================================
 * APP SHELL — icon rail (left) + appbar (top) + content; bottom nav on mobile.
 * ========================================================================== */
#app { min-height: 100%; }
/* Bound the shell to the viewport so .content is the ONLY vertical scroller.
 * This keeps the appbar + the sticky section control band fixed at the very top
 * (no gap, no list bleed) and the persistent AI panel viewport-height. */
.appshell { display: grid; grid-template-columns: var(--sb) 1fr; height: 100vh; overflow: hidden; }

/* left icon rail */
.rail {
  position: sticky; top: 0; align-self: start; height: 100vh;
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 16px 0; background: var(--surface); border-right: 1px solid var(--border);
  z-index: 30;
}
/* logo tile uses ACCENT (never --primary) so it stays distinct from the active
 * nav item, which uses --primary — the two must never read as the same colour. */
.rail .brand { width: 40px; height: 40px; border-radius: var(--r-sm); display: grid; place-items: center;
  background: var(--accent); color: var(--on-accent); margin-bottom: 10px; font-weight: var(--fw-bold); }
.rail-item { width: 46px; height: 46px; border-radius: var(--r-sm); border: 0; background: transparent;
  color: var(--muted); display: grid; place-items: center; cursor: pointer; transition: var(--t-fast);
  position: relative; }
.rail-item:hover { background: var(--surface-2); color: var(--text); }
.rail-item.active { background: var(--primary); color: var(--on-primary); box-shadow: var(--glow); }
.rail-item .ico { width: 22px; height: 22px; }
.rail .spacer { flex: 1; }
.rail-tip { position: absolute; left: calc(100% + 10px); top: 50%; transform: translateY(-50%);
  background: var(--text); color: var(--bg); padding: 5px 10px; border-radius: var(--r-xs); font-size: 12.5px;
  white-space: nowrap; opacity: 0; pointer-events: none; transition: var(--t-fast); box-shadow: var(--sh); z-index: 50; }
.rail-item:hover .rail-tip { opacity: 1; }

/* main column — bounded to the viewport; its .content child scrolls internally */
.main { display: flex; flex-direction: column; min-width: 0; height: 100vh; min-height: 0; overflow: hidden; }

/* appbar — sticky; holds title + actions + search; controls never scroll away */
.appbar {
  position: sticky; top: 0; z-index: 20; flex: none;
  display: flex; align-items: center; gap: 14px;
  height: var(--appbar-h); padding: 0 24px;
  background: var(--bg); border-bottom: 1px solid var(--border);   /* opaque — no list bleed */
}
.appbar .menu-btn { display: none; }
/* sections own their title (section-head); the appbar title would duplicate it.
 * Keep it only on mobile, where the section-head can scroll away. */
.appbar h1 { font-size: 1.15rem; display: none; }
@media (max-width: 980px) { .appbar h1 { display: block; } .section-head .title { display: none; } }
.appbar .crumbs { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 13.5px; min-width: 0; }
.appbar .crumbs b { color: var(--text); font-weight: var(--fw-semibold); }

/* workarea = section content column (left) + the PERMANENT AI panel (right).
 * Two always-visible columns on desktop; drills push INSIDE the left column
 * (see .content-col / .drill-host) and never cover the chat. */
.workarea { flex: 1; display: flex; min-height: 0; }
/* persistent assistant — docked on the RIGHT (section content on the left).
 * order:2 puts it after the content even though it's first in the DOM. */
/* the chat is a rounded card that floats with margins, consistent with the
 * dashboard's widgets (not a flush full-bleed column). */
.ai-panel { width: 42%; max-width: 560px; min-width: 360px; order: 2; display: flex; flex-direction: column;
  margin: 14px 18px 18px 8px; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-lg); box-shadow: var(--sh-sm); overflow: hidden; min-height: 0; }
.ai-panel.hidden { display: none; }
/* left column — the positioning context for the in-pane drill stack. Holds the
 * section content (#content scroller) and, when a drill is open, the drill panel
 * absolutely filling this column (the chat to the right stays put). */
.content-col { order: 1; flex: 1; min-width: 0; position: relative; display: flex; flex-direction: column; min-height: 0; }
.workarea:has(.ai-panel:not(.hidden)) .content { max-width: none; margin: 0; }

/* content area — the only place vertical scroll is allowed (for collections).
 * NO top padding: the sticky control band must anchor flush under the appbar (any
 * top padding sits inside the sticky constraint and lets scrolled cards peek through).
 * The control band / section-head supply their own top spacing (padding 14px). */
.content { flex: 1; padding: 0 24px 24px; max-width: var(--maxw); width: 100%; margin: 0 auto; overflow-y: auto; min-width: 0; }
.section { display: flex; flex-direction: column; gap: var(--gap); }

/* sticky section header with its actions (controls stay accessible).
 * Opaque background is REQUIRED: scrolled list content must not bleed through
 * the sticky band (the old transparent gradient caused visible artifacts). */
.section-head { position: sticky; top: 0; z-index: 12;
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 14px 0 12px; background: var(--bg); box-shadow: 0 1px 0 var(--border); }
.section-head .title { font-size: 1.5rem; font-weight: var(--fw-bold); font-family: var(--font-display); }
.section-head .sub { color: var(--muted); font-size: 13.5px; }

/* ONE shared control band for list sections: title-row + search/filters stacked
 * in a SINGLE sticky opaque container, so the search never hides behind a sticky
 * header and nothing bleeds. The inner section-head is static (the band is sticky). */
.section-controls { position: sticky; top: 0; z-index: 12;
  background: var(--bg); box-shadow: 0 1px 0 var(--border);
  padding: 14px 0 12px; display: flex; flex-direction: column; gap: 12px; }
.section-controls .section-head { position: static; padding: 0; background: none; box-shadow: none; }

/* grids */
.grid { display: grid; gap: var(--gap); }
.grid.cards { grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); }
.grid.cards-lg { grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }

/* bottom nav (mobile only) */
.bottomnav { display: none; }

/* ---- responsive ---------------------------------------------------------- */
@media (max-width: 980px) {
  .appshell { grid-template-columns: 1fr; }
  .rail { position: fixed; left: 0; top: 0; transform: translateX(-100%); transition: transform var(--t);
    width: 240px; align-items: stretch; padding: 16px 12px; box-shadow: var(--sh-lg); }
  .rail.open { transform: translateX(0); }
  .rail-item { width: 100%; height: 48px; display: flex; align-items: center; justify-content: flex-start; gap: 12px; padding: 0 14px; }
  .rail-item .rail-tip { position: static; transform: none; opacity: 1; background: transparent; color: inherit;
    box-shadow: none; padding: 0; font-size: 14px; }
  .appbar { padding: 0 16px; }
  .appbar .menu-btn { display: grid; }
  .content { padding: 0 16px; padding-bottom: calc(var(--bottomnav-h) + 20px); }
  .ai-panel { display: none !important; }   /* mobile: AI opens full-screen via a button */
  .scrim { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 25; opacity: 0; pointer-events: none; transition: var(--t); }
  .scrim.show { opacity: 1; pointer-events: auto; }
  .bottomnav { display: flex; position: fixed; bottom: 0; left: 0; right: 0; height: var(--bottomnav-h);
    background: var(--surface); border-top: 1px solid var(--border); z-index: 24; padding: 6px 4px; }
  .bottomnav button { flex: 1; border: 0; background: transparent; color: var(--muted); display: flex;
    flex-direction: column; align-items: center; gap: 2px; font-size: 10.5px; cursor: pointer; border-radius: var(--r-sm); }
  .bottomnav button.active { color: var(--primary); }
  .section-head { top: 0; }
}
@media (max-width: 520px) {
  .grid.cards, .grid.cards-lg { grid-template-columns: 1fr; }
  h1 { font-size: 1.5rem; }
}
