/* ==========================================================================
   Ledger — Layout
   Shell grid, sidebar, and main content area structure.
   ========================================================================== */

  /* ---------- Shell ---------- */
  .shell{
    display: grid;
    grid-template-columns: 248px 1fr;
    min-height: 100vh;
    transition: grid-template-columns 0.18s ease;
  }
  .shell.sidebar-collapsed{
    grid-template-columns: 78px 1fr;
  }

  /* ---------- Sidebar ---------- */
  .sidebar{
    background: var(--sidebar-bg);
    color: var(--sidebar-fg);
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
    /* Explicit, not left to default: overflow-y:auto above otherwise
       silently promotes this axis from its default 'visible' to 'auto'
       too (the same CSS overflow computed-value quirk documented
       elsewhere in this file for .shell), meaning ANY child even
       fractionally wider than the sidebar's own content box would show
       a horizontal scrollbar at the bottom of this 100vh-tall column.
       Declaring it outright removes that risk permanently rather than
       relying on every current and future child staying narrow enough. */
    overflow-x: hidden;
    padding: 28px 0 28px 28px;
    display: flex;
    flex-direction: column;
    transition: padding 0.18s ease;
    border-right: 1px solid color-mix(in srgb, var(--sidebar-fg) 12%, transparent);
  }
  .brand{
    font-family: var(--font-heading);
    font-size: 22px;
    font-weight: 700;
    color: var(--sidebar-strong);
    margin-bottom: 2px;
    padding-right: 28px;
  }
  .sidebar-top{
    display:flex;
    align-items:flex-start;
    justify-content:space-between;
    gap:12px;
    padding-right:18px;
    /* Phase 1 §1: a fixed floor so the block's own height stays roughly
       consistent whether its children lay out as a row (expanded) or a
       stack (collapsed, see the collapsed override below) — flex-direction
       itself can't be transitioned, but keeping the container's height
       from jumping keeps where .nav (and "Home") starts feeling stable
       rather than lurching between the two states. */
    min-height:30px;
  }
  .sidebar-toggle{
    width:30px;
    height:30px;
    border-radius:7px;
    border:1px solid color-mix(in srgb, var(--sidebar-fg) 20%, transparent);
    background:color-mix(in srgb, var(--sidebar-fg) 8%, transparent);
    color:var(--sidebar-strong);
    font-family:var(--font-mono);
    line-height:1;
  }
  .sidebar-toggle:hover{ background:var(--sidebar-active); }
  .brand-sub{
    font-family: var(--font-mono);
    font-size: 11px;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--sidebar-muted);
    margin-bottom: 34px;
  }
  .nav{
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding-right: 28px;
  }
  .nav-item{
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 12px;
    border-radius: 7px;
    color: color-mix(in srgb, var(--sidebar-fg) 78%, transparent);
    font-size: 14.5px;
    font-family: var(--font-heading);
    font-weight: 500;
    background: none;
    border: none;
    text-align: left;
    width: 100%;
    white-space: nowrap;
    overflow: hidden;
  }
  .nav-item:hover{ background: var(--sidebar-hover); color: var(--sidebar-strong); }
  .nav-item.active{ background: var(--sidebar-active); color: var(--sidebar-strong); }
  .nav-icon{
    width: 17px;
    height: 17px;
    flex: none;
    display: flex;
    align-items: center;
    justify-content: center;
  }
  .nav-icon svg{ width: 100%; height: 100%; display: block; }

  .sidebar-foot{
    margin-top: auto;
    padding-right: 28px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
  }
  .sidebar-foot-text{
    font-family: var(--font-heading);
    font-style: italic;
    font-size: 12.5px;
    color: color-mix(in srgb, var(--sidebar-fg) 62%, transparent);
    line-height: 1.35;
  }
  .sidebar-foot-art{
    flex: none;
    width: 30px;
    height: 30px;
    color: var(--warn);
    opacity: 0.85;
    display: flex;
    align-items: center;
    justify-content: center;
  }
  .sidebar-foot-art svg{ width: 100%; height: 100%; display: block; }

  /* ---------- Main ---------- */
  .main{
    padding: 36px 44px 60px;
    max-width: none;
    width: 100%;
  }
  .topbar{
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    margin-bottom: 28px;
    flex-wrap: wrap;
    gap: 12px;
  }
  .page-title{
    font-size: 26px;
    font-weight: 700;
  }
  .page-date{
    font-family: 'JetBrains Mono', monospace;
    font-size: 12px;
    color: var(--ink-soft);
    letter-spacing: 0.03em;
  }

  .grid{
    display: grid;
    gap: 20px;
  }
  .grid-2{ grid-template-columns: 1.3fr 1fr; }
  .grid-3{ grid-template-columns: repeat(3, 1fr); }
  .grid-4{ grid-template-columns: repeat(4, 1fr); }

  @media (max-width: 980px){
    .shell{ grid-template-columns: 1fr; }
    .shell.sidebar-collapsed{ grid-template-columns: 1fr; }
    .sidebar{ flex-direction: row; align-items: center; overflow-x: auto; overflow-y: visible; height: auto; position: relative; top: auto; padding: 16px; border-right: none; border-bottom: 1px solid rgba(237,234,226,0.1); }
    .sidebar.has-overflow{
      -webkit-mask-image: linear-gradient(to right, black 0, black calc(100% - 36px), transparent 100%);
      mask-image: linear-gradient(to right, black 0, black calc(100% - 36px), transparent 100%);
    }
    .brand-sub{ display:none; }
    .sidebar-top{ padding-right:0; }
    .sidebar-toggle{ display:none; }
    .nav{ flex-direction: row; padding-right: 0; }
    .sidebar-foot{ display:none; }
    .main{ padding: 24px 18px 50px; }
    .grid-2, .grid-3, .grid-4{ grid-template-columns: 1fr; }
  }

  .shell.sidebar-collapsed .sidebar{
    padding-left:14px;
    padding-right:14px;
    align-items:center;
  }
  .shell.sidebar-collapsed .brand-sub,
  .shell.sidebar-collapsed .nav-label,
  .shell.sidebar-collapsed .sidebar-foot{
    display:none;
  }
  /* Collapsed rail is only 78px wide (50px of content once the 14px
     side padding is subtracted). .sidebar-top's default row layout
     (brand + search trigger + collapse toggle side by side) is what
     was causing the unintended desktop horizontal scrollbar (§3) — three
     ~28-30px-wide items in a row don't fit a 50px column. Stacking them
     vertically instead keeps every child within the rail's actual width,
     with the search trigger dropping to icon-only via the kbd-hint rule
     below (its own hint text is what would otherwise force extra width). */
  .shell.sidebar-collapsed .sidebar-top{
    padding-right:0;
    flex-direction:column;
    align-items:center;
    gap:10px;
    /* Phase 1 §1: expanded mode gets its breathing room before "Home"
       from .brand-sub's own 34px margin-bottom (below) — but brand-sub is
       display:none while collapsed, so without this the collapse/expand
       toggle (last item in this now-stacked column) would sit right on
       top of the first nav item with no separation at all. This restores
       comparable breathing room in the collapsed rail specifically. */
    margin-bottom:16px;
  }
  .shell.sidebar-collapsed .brand{ font-size:18px; padding-right:0; writing-mode:vertical-rl; transform:rotate(180deg); margin-bottom:4px; }
  .shell.sidebar-collapsed .nav{ padding-right:0; width:100%; }
  .shell.sidebar-collapsed .nav-item{ justify-content:center; padding:10px 0; }

  .card{
    background: var(--paper-raised);
    border: 1px solid var(--rule);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 20px;
  }
  .card-head{
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    margin-bottom: 14px;
  }
  .card-title{
    font-size: 15px;
    font-weight: 600;
    font-family: 'Space Grotesk', sans-serif;
  }
  .card-eyebrow{
    font-family: 'JetBrains Mono', monospace;
    font-size: 10.5px;
    text-transform: uppercase;
    letter-spacing: 0.09em;
    color: var(--ink-soft);
    opacity: 0.65;
  }


