/* Alone — responsive.css
 *
 * ALL media queries live here. Every page links this file AFTER its embedded
 * <style> block so these rules win the cascade (the embedded grids are
 * non-media; same specificity means later source order wins).
 *
 * Breakpoints:
 *   Desktop  >= 1024px  — unchanged (no rules here apply).
 *   Tablet   768-1023px — sidebar narrows, multi-col grids drop to 2 columns.
 *   Mobile   < 768px    — sidebar becomes off-canvas drawer, content single-col.
 *
 * Constraints honored: desktop look untouched, no color theme change, no emoji,
 * no markup restructure. Drawer toggle markup is injected by alone-bind.js; the
 * hamburger button (.nav-toggle) and backdrop (.nav-backdrop) are styled here
 * and hidden at >= 768px.
 */

/* =========================================================================
 * Shell elements injected by alone-bind.js — hidden on desktop/tablet.
 * Kept outside media queries with an explicit >=768 hide below.
 * ========================================================================= */
.nav-toggle {
  display: none;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  margin-left: -10px;          /* optical: pull toward the left edge of the bar */
  margin-right: 4px;
  border: 0;
  background: transparent;
  color: var(--text-2);
  cursor: pointer;
  border-radius: 10px;
  flex-shrink: 0;
}
.nav-toggle:hover { color: var(--accent); background: var(--panel); }
.nav-toggle .ico { width: 22px; height: 22px; }

.nav-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 40;
  background: oklch(from var(--text) l c h / 0.38);
  -webkit-backdrop-filter: blur(1px);
  backdrop-filter: blur(1px);
  opacity: 0;
  transition: opacity 0.2s ease;
}

/* =========================================================================
 * TABLET — 768px to 1023px
 *   Sidebar visible but narrower; multi-col content grids -> 2 columns.
 * ========================================================================= */
@media (min-width: 768px) and (max-width: 1023px) {
  .sidebar { width: 200px; padding: 24px 14px; }
  .brand { gap: 10px; padding-bottom: 18px; }
  .brand-name { font-size: 16px; }
  .nav { padding: 14px 0; }
  .nav-item, .nav-proj { padding: 9px 8px; }

  .thinbar { padding: 0 24px; }
  .thinbar .right { gap: 12px; }

  /* hero / heads — trim large horizontal padding */
  .hero { padding: 36px 32px 18px; }
  .hero h1 { font-size: 34px; }
  .chat-zone { padding: 0 32px 20px; }
  .composer { padding: 16px 32px 28px; }

  .tasks-head, .dash-head, .asset-head, .set-head { padding-left: 32px; padding-right: 32px; }
  .cal-head { padding-left: 32px; padding-right: 32px; }
  .proj-head { padding-left: 32px; padding-right: 32px; }
  .queue, .dash-body, .asset-body, .proj-body { padding-left: 32px; padding-right: 32px; }
  .cal-grid-wrap { padding-left: 32px; padding-right: 32px; }
  .ambient { margin-left: 32px; margin-right: 32px; }
  .demo-note { margin-left: 32px; margin-right: 32px; }
  .set-split { padding-left: 32px; padding-right: 32px; gap: 22px; }

  /* today: 3-card now-row -> 2 columns */
  .now-row { grid-template-columns: repeat(2, 1fr); }

  /* dashboard: 4 stat cards -> 2 columns */
  .stat-row { grid-template-columns: repeat(2, 1fr); }

  /* asset: 4 fin cards -> 2; holdings 5 -> 3 */
  .fin-strip { grid-template-columns: repeat(2, 1fr); }
  .hold-grid { grid-template-columns: repeat(3, 1fr); }

  /* project: 4 summary cards -> 2; domain 3 -> 2 */
  .sumstrip { grid-template-columns: repeat(2, 1fr); }
  .dom-grid { grid-template-columns: repeat(2, 1fr); }

  /* docs: narrow the tree pane a touch */
  .doc-tree { width: 240px; }
  .doc-content { padding: 28px 32px 40px; }

  /* settings: narrow side nav */
  .set-nav { width: 160px; }
}

/* =========================================================================
 * MOBILE — < 768px
 *   Sidebar becomes an off-canvas drawer; content single column.
 * ========================================================================= */
@media (max-width: 767px) {

  /* ---- safety net: never allow horizontal page scroll ---- */
  html, body { overflow-x: hidden; }

  /* ---- Off-canvas sidebar drawer ---- */
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 50;
    width: 84vw;
    max-width: 320px;
    padding: 24px 18px;
    border-right: 1px solid var(--border);
    box-shadow: 2px 0 24px oklch(from var(--text) l c h / 0.18);
    transform: translateX(-100%);
    transition: transform 0.24s ease;
    overflow-y: auto;
  }
  body.nav-open .sidebar { transform: translateX(0); }
  body.nav-open .nav-backdrop { display: block; opacity: 1; }

  /* main takes the full viewport width */
  .main { width: 100%; }

  /* show the hamburger only on mobile */
  .nav-toggle { display: inline-flex; }

  /* ---- top bar padding trim (thinbar + docs-bar) ---- */
  .thinbar {
    padding: 0 14px;
    height: 52px;
  }
  /* keep the bar usable: hide the verbose right-side status cluster */
  .thinbar .right { display: none; }
  .thinbar .left { gap: 10px; font-size: 11px; flex-wrap: wrap; }

  .docs-bar { padding: 0 12px; height: 56px; gap: 10px; flex-wrap: wrap; }
  .docs-bar .crumb, .docs-bar .bar-sep { display: none; }
  .docs-bar .bar-right { margin-left: auto; }
  .docs-search { min-width: 0; flex: 1; }

  /* =====================================================================
   * GLOBAL content padding: drop big 56px horizontal padding to 16px.
   * ===================================================================== */
  .hero { padding: 26px 16px 14px; }
  .hero h1 { font-size: 26px; line-height: 1.22; }
  .hero .sub { font-size: 13.5px; margin-top: 10px; }
  .chips { margin-top: 24px; }

  .chat-zone { padding: 0 16px 16px; margin-top: 30px; }
  .chat-zone .msg-row { max-width: 100%; }
  .composer { padding: 12px 16px 20px; }
  .composer-box { padding: 13px 14px; gap: 9px; border-radius: 14px; }
  .composer-box input { font-size: 14px; min-width: 0; }
  .composer-box .hint { display: none; }   /* "Enter" pill — noise on touch */

  .tasks-head, .dash-head, .asset-head, .set-head,
  .cal-head, .proj-head { padding-left: 16px; padding-right: 16px; }
  .tasks-head { padding-top: 28px; }
  .tasks-head h1, .dash-head h1, .asset-head h1,
  .set-head h1, .cal-head h1, .proj-id .pi-main h1 { font-size: 24px; }
  .tasks-head .sub, .dash-head .sub, .asset-head .sub,
  .set-head .sub, .proj-line { font-size: 13.5px; }

  .queue, .dash-body, .asset-body, .proj-body { padding-left: 16px; padding-right: 16px; }
  .cal-grid-wrap { padding-left: 16px; padding-right: 16px; }
  .ambient { margin-left: 16px; margin-right: 16px; flex-wrap: wrap; gap: 10px; }
  .ambient .am-link { margin-left: 0; }
  .demo-note { margin-left: 16px; margin-right: 16px; }

  /* =====================================================================
   * TODAY
   * ===================================================================== */
  .now-row { grid-template-columns: 1fr; gap: 12px; margin-top: 24px; }
  .chips { gap: 8px; }

  /* =====================================================================
   * TASKS — qcard stacks: content over actions; buttons wrap full width.
   * ===================================================================== */
  .qcard { flex-direction: column; gap: 14px; padding: 18px 16px; }
  .qside { flex-direction: row; align-items: center; min-width: 0; width: 100%; flex-wrap: wrap; }
  .qacts { flex-direction: row; flex-wrap: wrap; width: 100%; }
  .qacts .qbtn { flex: 1 1 auto; min-width: 130px; min-height: 44px; }
  .qbtn.split { width: 100%; }
  .qevidence .qe-body { max-width: 100%; }

  /* =====================================================================
   * DASHBOARD — stat cards single column; node board scrolls horizontally
   *             if a row is too wide rather than breaking layout.
   * ===================================================================== */
  .stat-row { grid-template-columns: 1fr; gap: 12px; }
  .stat-card { min-height: 0; }
  .board-strip { flex-wrap: wrap; }
  .status-group .sg-rows { overflow-x: auto; }
  .node-row { min-width: 0; }
  .node-row .ntitle {
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0;
  }

  /* =====================================================================
   * CALENDAR — the week grid is intrinsically wide. Allow horizontal scroll
   *            inside its wrapper (already overflow:auto) and give the grid a
   *            sensible min-width so columns stay legible instead of crushing.
   * ===================================================================== */
  .cal-head { padding-top: 24px; }
  .cal-topline { flex-wrap: wrap; gap: 12px; }
  .cal-nav { margin-left: 0; flex-wrap: wrap; }
  .cal-legend { flex-wrap: wrap; gap: 12px; }
  .cal-legend .hint { margin-left: 0; flex-basis: 100%; }
  .cal-grid-wrap { -webkit-overflow-scrolling: touch; }
  .cal-grid { min-width: 720px; }     /* time col + 7 days; scroll within wrap */
  .cal-month { min-width: 700px; min-height: 620px; }

  /* =====================================================================
   * ASSET — fin strip 1col; holdings 2col; budget/income rows stack.
   * ===================================================================== */
  .asset-topline { flex-wrap: wrap; }
  .asset-toggle { margin-left: 0; }
  .fin-strip { grid-template-columns: 1fr; gap: 12px; }
  .hold-grid { grid-template-columns: repeat(2, 1fr); gap: 12px; }
  .hold-card { min-height: 0; }

  .budget-total { flex-direction: column; align-items: flex-start; gap: 14px; }
  .budget-total .bt-pct { margin-left: 0; }
  .budget-total .bt-remain {
    padding-left: 0; border-left: 0; text-align: left;
    border-top: 1px solid var(--border); padding-top: 14px; width: 100%;
  }
  .budget-legend { flex-wrap: wrap; gap: 12px; }
  .budget-legend .hint { margin-left: 0; flex-basis: 100%; }

  .budget-row { flex-wrap: wrap; gap: 12px; }
  .br-id { width: 100%; }
  .br-mid { flex-basis: 100%; order: 3; }
  .br-nums { width: auto; margin-left: auto; text-align: right; }
  .br-act { width: auto; }

  .income-row { flex-wrap: wrap; gap: 10px; }
  .income-row .ir-amt { width: auto; margin-left: auto; }

  /* =====================================================================
   * PROJECT / PROJECT-PERSONAL
   * ===================================================================== */
  .proj-id { flex-wrap: wrap; }
  .proj-id .pi-scope { margin-left: 0; flex-basis: 100%; }
  .sumstrip { grid-template-columns: 1fr; gap: 12px; }
  .dom-grid { grid-template-columns: 1fr; gap: 12px; }
  .pitem { flex-wrap: wrap; gap: 8px 12px; }
  .pitem .pi-when { margin-left: auto; }

  /* =====================================================================
   * DOCS — tree + content side-by-side -> stack vertically (tree on top,
   *        collapsed-ish height with its own scroll; content below).
   * ===================================================================== */
  .docs-split { flex-direction: column; }
  .doc-tree {
    width: 100%;
    border-right: 0;
    border-bottom: 1px solid var(--border);
    max-height: 38vh;
    padding: 12px 10px;
  }
  .doc-content { padding: 22px 16px 36px; }
  .doc-content .dc-body { max-width: 100%; }
  .dc-titlerow { flex-wrap: wrap; gap: 10px; }
  .dc-ctxtag { margin-left: 0; }

  /* =====================================================================
   * SETTINGS — side nav + groups side-by-side -> stack; rows wrap.
   * ===================================================================== */
  .set-head { padding-top: 24px; }
  .set-split { flex-direction: column; padding: 18px 16px 32px; gap: 18px; }
  .set-nav {
    width: 100%;
    position: static;
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
  }
  .set-nav a { flex: 0 0 auto; }
  .set-nav a + a { margin-top: 0; }
  .set-main { max-width: 100%; }
  .set-row { flex-wrap: wrap; gap: 12px; }
  .sr-label { flex-basis: 100%; }
  .sr-control { margin-left: auto; }
  .fleet-tiers { width: 100%; }
}

/* =========================================================================
 * Touch comfort — apply to coarse pointers regardless of width.
 * ========================================================================= */
@media (max-width: 767px) {
  .nav-item, .nav-proj { min-height: 44px; }
  .chip { min-height: 38px; }
}
