/* SDOS v2 shell: rail + topbar + content + drawer */
@layer shell {
  .shell { display: flex; min-height: 100vh; }

  /* ---- navigation rail (2026-08 redesign: labelled + grouped, collapsible) ----
     232px with labels by default. The 62px icon-only rail is the SAME markup
     under three triggers (identical rule blocks below — keep them in sync):
       1. html.sdos-railcollapsed — the person's choice (cookie `rail`, rendered
          server-side like the theme, so it never flashes);
       2. any viewport ≤1180px;
       3. the fixed-width workspaces (/orders has a 960px floor, /locations two
          fixed panes) ≤1359px = 960 + 44 content padding + 232 rail + slack.
     Every entry is an <a class="rail-item">; titles keep the names when
     labels are hidden. */
  .rail {
    width: 232px; flex: 0 0 232px;
    background: var(--rail);
    display: flex; flex-direction: column; align-items: stretch;
    padding: 14px 12px; gap: 2px;
    position: sticky; top: 0; height: 100vh; overflow-y: auto; overflow-x: hidden;
    scrollbar-width: thin; scrollbar-color: rgba(255, 255, 255, 0.25) transparent;
  }
  .rail::-webkit-scrollbar { width: 4px; }
  .rail::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.25); border-radius: 4px; }
  .rail-label { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
  .rail-logo {
    display: flex; align-items: center; gap: 12px;
    height: 44px; padding: 0 4px; margin-bottom: 10px;
    text-decoration: none; color: #fff;
  }
  .rail-logo-tile {
    width: 34px; height: 34px; border-radius: 9px; flex-shrink: 0;
    background: #ffffff; color: var(--rail);
    display: grid; place-items: center;
    font-weight: 700; font-size: 13px; letter-spacing: 0.02em;
  }
  .rail-logo-text { display: flex; flex-direction: column; font-weight: 700; font-size: 15px; line-height: 1.15; }
  .rail-logo-text small { font-weight: 500; font-size: 11px; color: #9db8cd; }
  .rail-group { display: flex; flex-direction: column; gap: 2px; }
  .rail-group-label {
    display: block; height: 30px; padding: 12px 12px 0; box-sizing: border-box;
    font-size: 11px; font-weight: 700; letter-spacing: 0.08em; line-height: 1.4;
    color: #7f9db3; text-transform: uppercase;
  }
  .rail-spacer { flex: 1; min-height: 6px; }
  .rail a.rail-item {
    display: flex; align-items: center; gap: 12px;
    height: 44px; padding: 0 12px; border-radius: 10px;
    color: #9db8cd; text-decoration: none;
    font-size: 14px; font-weight: 500; line-height: 1.2;
  }
  .rail a.rail-item svg { flex-shrink: 0; }
  .rail a.rail-item:hover { background: rgba(255, 255, 255, 0.08); color: #cfe0ee; }
  .rail a.rail-item[aria-current="page"] { background: rgba(255, 255, 255, 0.16); color: #fff; }
  .rail-avatar {
    display: flex; align-items: center; gap: 12px;
    height: 48px; padding: 0 8px; margin-top: 6px; border-radius: 10px;
    text-decoration: none; color: #fff;
  }
  .rail-avatar:hover { background: rgba(255, 255, 255, 0.08); }
  .rail-avatar[aria-current="page"] { background: rgba(255, 255, 255, 0.16); }
  .avatar-tile {
    width: 28px; height: 28px; border-radius: 50%; background: var(--avatar-bg); flex-shrink: 0;
    display: grid; place-items: center;
    color: #fff; font-size: 11px; font-weight: 700;
    border: 2px solid rgba(255, 255, 255, 0.35);
  }
  .rail-user { display: flex; flex-direction: column; font-size: 13px; font-weight: 600; line-height: 1.25; }
  .rail-user small { font-size: 11px; font-weight: 500; color: #9db8cd; }
  .rail-collapse {
    display: flex; align-items: center; gap: 12px;
    height: 40px; padding: 0 12px; margin-top: 4px; border-radius: 10px;
    border: none; background: transparent; color: #7f9db3;
    font: inherit; font-size: 13px; cursor: pointer; text-align: left;
  }
  .rail-collapse:hover { background: rgba(255, 255, 255, 0.08); color: #cfe0ee; }
  .rail-collapse svg { flex-shrink: 0; }
  .rail-collapse-out { display: none; }

  /* trigger 1: the person collapsed it */
  html.sdos-railcollapsed .rail { width: 62px; flex-basis: 62px; padding: 14px 11px; align-items: center; }
  html.sdos-railcollapsed .rail .rail-label { display: none; }
  html.sdos-railcollapsed .rail-logo { width: 40px; padding: 0; justify-content: center; }
  html.sdos-railcollapsed .rail-group { align-items: center; }
  html.sdos-railcollapsed .rail-group-label { width: 28px; height: 1px; padding: 0; margin: 8px 0 6px; background: rgba(255, 255, 255, 0.14); }
  html.sdos-railcollapsed .rail a.rail-item, html.sdos-railcollapsed .rail-avatar, html.sdos-railcollapsed .rail-collapse { width: 40px; height: 40px; padding: 0; justify-content: center; }
  html.sdos-railcollapsed .rail-collapse-in { display: none; }
  html.sdos-railcollapsed .rail-collapse-out { display: block; }

  /* ---- main column ---- */
  .maincol { flex: 1; min-width: 0; display: flex; flex-direction: column; }

  .topbar {
    display: flex; align-items: center; gap: 12px;
    padding: 18px 24px 12px;
    background: var(--bg);
    position: sticky; top: 0; z-index: 30;
  }
  .topbar-titles { min-width: 0; }
  .topbar-title { font-size: 20px; font-weight: 700; line-height: 1.25; }
  .topbar-sub { font-size: 13px; color: var(--muted); margin-top: 1px; }
  .topbar-spacer { flex: 1; }
  .topbar-tools { display: contents; } /* wide: search + action sit in the bar's own flow */
  .topbar-search { position: relative; flex-shrink: 0; }
  .topbar-search svg { position: absolute; left: 13px; top: 12px; color: var(--muted); pointer-events: none; }
  .topbar-search input {
    width: 320px; max-width: 30vw; height: 44px; box-sizing: border-box;
    border-radius: 10px; padding: 0 13px 0 40px;
    font-size: 14px; background: var(--surface); border: 1px solid var(--line-strong);
  }
  .topbar-search input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
  .topbar-cta {
    height: 44px; display: inline-flex; align-items: center; gap: 8px;
    padding: 0 16px; border-radius: 10px; flex-shrink: 0; white-space: nowrap;
    font-size: 14px; font-weight: 600;
  }
  .topbar-actions { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
  .theme-toggle {
    flex-shrink: 0; border: 1px solid var(--line-strong); cursor: pointer;
    background: var(--surface); color: var(--text-2); border-radius: 10px;
    width: 40px; height: 40px; font-size: 15px; line-height: 1;
    display: grid; place-items: center;
  }
  .theme-toggle:hover { background: var(--surface-2); }
  .seg { display: flex; background: var(--surface-3); border-radius: 10px; padding: 3px; flex-shrink: 0; }
  .seg-form { display: contents; }
  .seg-btn {
    border: none; cursor: pointer; border-radius: 7px; padding: 7px 12px;
    font-size: 12.5px; font-weight: 600; background: transparent; color: var(--muted);
    text-decoration: none; display: inline-flex; align-items: center; line-height: 1.4;
  }
  .seg-btn:hover { text-decoration: none; }
  .seg-btn.on { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(20, 35, 60, 0.15); }

  .content { padding: 18px 22px 40px; flex: 1; min-width: 0; }

  /* ---- detail drawer ---- */
  .drawer {
    position: fixed; top: 0; right: 0; bottom: 0;
    width: min(430px, 100vw);
    background: var(--surface);
    border-left: 1px solid var(--line);
    box-shadow: var(--shadow-pop);
    transform: translateX(102%);
    transition: transform 0.18s ease;
    z-index: 60; overflow-y: auto;
  }
  .drawer.open { transform: none; }
  .drawer-overlay {
    position: fixed; inset: 0; background: rgba(10, 18, 28, 0.35);
    opacity: 0; pointer-events: none; transition: opacity 0.18s ease; z-index: 55;
  }
  .drawer.open + .drawer-overlay, .drawer-overlay.open { opacity: 1; pointer-events: auto; }
  .drawer-inner { padding: 18px; }
  .drawer-close {
    position: sticky; top: 8px; float: right;
    background: var(--surface-2); border: 1px solid var(--line);
    border-radius: 50%; width: 30px; height: 30px; font-size: 14px;
  }

  /* trigger 3: fixed-width workspaces need the room (no toggle — it cannot win) */
  @media (max-width: 1359px) {
    :is(.shell:has(.orders-workspace), .shell:has(.loc-screen)) .rail { width: 62px; flex-basis: 62px; padding: 14px 11px; align-items: center; }
    :is(.shell:has(.orders-workspace), .shell:has(.loc-screen)) .rail .rail-label { display: none; }
    :is(.shell:has(.orders-workspace), .shell:has(.loc-screen)) .rail-logo { width: 40px; padding: 0; justify-content: center; }
    :is(.shell:has(.orders-workspace), .shell:has(.loc-screen)) .rail-group { align-items: center; }
    :is(.shell:has(.orders-workspace), .shell:has(.loc-screen)) .rail-group-label { width: 28px; height: 1px; padding: 0; margin: 8px 0 6px; background: rgba(255, 255, 255, 0.14); }
    :is(.shell:has(.orders-workspace), .shell:has(.loc-screen)) .rail a.rail-item, :is(.shell:has(.orders-workspace), .shell:has(.loc-screen)) .rail-avatar, :is(.shell:has(.orders-workspace), .shell:has(.loc-screen)) .rail-collapse { width: 40px; height: 40px; padding: 0; justify-content: center; }
    :is(.shell:has(.orders-workspace), .shell:has(.loc-screen)) .rail-collapse-in { display: none; }
    :is(.shell:has(.orders-workspace), .shell:has(.loc-screen)) .rail-collapse-out { display: block; }
    :is(.shell:has(.orders-workspace), .shell:has(.loc-screen)) .rail-collapse { display: none; }
  }

  /* trigger 2: narrow laptops / tablets */
  @media (max-width: 1180px) {
    .rail { width: 62px; flex-basis: 62px; padding: 14px 11px; align-items: center; }
    .rail .rail-label { display: none; }
    .rail-logo { width: 40px; padding: 0; justify-content: center; }
    .rail-group { align-items: center; }
    .rail-group-label { width: 28px; height: 1px; padding: 0; margin: 8px 0 6px; background: rgba(255, 255, 255, 0.14); }
    .rail a.rail-item, .rail-avatar, .rail-collapse { width: 40px; height: 40px; padding: 0; justify-content: center; }
    .rail-collapse-in { display: none; }
    .rail-collapse-out { display: block; }
    .rail-collapse { display: none; }
    .topbar-search input { width: 220px; }
  }

  /* narrow windows: search + primary action take their own full-width row
     (the search grows) under the title and the controls */
  @media (max-width: 1000px) {
    .topbar { flex-wrap: wrap; row-gap: 10px; }
    .topbar-titles { flex: 1 1 auto; }
    .topbar-tools { display: flex; align-items: center; gap: 10px; flex: 1 1 100%; order: 9; }
    .topbar-search { flex: 1 1 auto; }
    .topbar-search input { width: 100%; max-width: none; }
  }

  @media (max-width: 700px) {
    .rail { display: none; }
    .content { padding: 14px 14px 40px; }
  }
}
