/* ConveySure application shell — the persistent sidebar layout.

   One shell, two tenants of it: the client portal (simple, six destinations)
   and the fee-earner workspace (dense, grouped, role-aware, collapsible). They
   share this file so the two halves of the product read as one application,
   and diverge only in what they put *inside* the sidebar.

   Two rules the layout enforces rather than asks for:

     * the sidebar occupies the same place on every page. Navigation that moves
       has to be re-learned on each screen; navigation that never moves is
       learned once. Nothing in a page template can reposition it.
     * status lives next to the destination. A count or a state mark beside
       "Findings" is visible while the user works, which is the point — an
       unresolved control that stays on screen is harder to walk past than one
       filed behind a tab.

   Mobile is the same sidebar, off-canvas. Not a second navigation with its own
   ideas: one structure, two presentations, so what a client learns on a laptop
   still holds on a phone.

   Progressive enhancement: the drawer behaviour is applied only under
   `html.js`. With JavaScript unavailable the sidebar renders as an ordinary
   block at the top of the document and every destination is still reachable. */

*, *::before, *::after { box-sizing: border-box; }

/* ── The grid ─────────────────────────────────────────────────────────────── */

.shell {
  --shell-sidebar-w: 17rem;
  --shell-sidebar-collapsed-w: 4.25rem;
  --shell-topbar-h: 3.5rem;
  min-height: 100vh;
}

.shell-main { min-width: 0; }

/* Wide content (a table of transactions, a long filename) scrolls inside its
   own box. The shell itself never scrolls sideways. */
.shell, .shell-main { overflow-x: clip; }

/* ── Sidebar ──────────────────────────────────────────────────────────────── */

.shell-sidebar {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  background: var(--shell-sidebar-bg, var(--surface-card));
  border-right: 1px solid var(--border-default);
  padding: var(--space-4) var(--space-3) var(--space-5);
}

.shell-brand {
  display: flex; align-items: center; gap: 8px;
  text-decoration: none; padding: 0 var(--space-2);
  min-height: 2.5rem;
}
.shell-brand-mark {
  font-family: var(--font-display); font-size: 1.0625rem; font-weight: 700;
  color: var(--shell-brand-color, var(--brand-700)); letter-spacing: -.01em;
}
.shell-brand-badge {
  font-family: var(--font-interface); background: var(--gold); color: var(--brand-900);
  font-size: .5rem; font-weight: 700; letter-spacing: .12em; text-transform: uppercase;
  padding: 3px 7px; border-radius: 3px;
}
.shell-brand-sub {
  font-size: .6875rem; color: var(--text-muted); padding: 0 var(--space-2);
  margin: -10px 0 0;
}

/* The context block: which matter am I looking at? Small, quiet, always there. */
.shell-context {
  padding: var(--space-3);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  background: var(--surface-subtle);
  font-size: .8125rem;
}
.shell-context-ref {
  font-weight: 700; font-size: .875rem; letter-spacing: .01em;
  color: var(--text-primary); display: block;
}
.shell-context-line { color: var(--text-secondary); display: block; margin-top: 4px; line-height: 1.4; }

.shell-nav { display: grid; gap: var(--space-1); }
.shell-nav-group + .shell-nav-group { margin-top: var(--space-4); }
.shell-nav-label {
  font-size: .625rem; font-weight: 700; letter-spacing: .11em; text-transform: uppercase;
  color: var(--text-muted); padding: 0 var(--space-2); margin: 0 0 var(--space-2);
}

.shell-nav-item {
  display: flex; align-items: center; gap: 10px;
  min-height: 44px; padding: 8px 10px;
  border-radius: var(--radius-sm);
  text-decoration: none; color: var(--text-secondary);
  font-size: .875rem; font-weight: 600;
  border: 1px solid transparent;
}
.shell-nav-item:hover { background: var(--brand-050); color: var(--text-primary); }
.shell-nav-item[aria-current] {
  background: var(--brand-100); color: var(--brand-800); border-color: var(--border-default);
}
.shell-nav-text { flex: 1 1 auto; min-width: 0; }

/* The four states, shared by both applications:
     ✓ complete   ● in progress   ! action needed   ○ not started
   The mark is decorative — every row also carries its state in words, either
   in the visible label or in screen-reader text. */
.shell-mark {
  flex: 0 0 auto; width: 1.375rem; height: 1.375rem; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: .75rem; font-weight: 700; line-height: 1;
  border: 1px solid var(--border-default); background: var(--surface-card);
  color: var(--text-muted);
}
.shell-mark[data-state="complete"]        { background: var(--success-bg); color: var(--success-text); border-color: var(--success-border); }
.shell-mark[data-state="in_progress"]     { background: var(--brand-100); color: var(--brand-700); border-color: var(--border-default); }
.shell-mark[data-state="needs_attention"] { background: var(--warning-bg); color: var(--warning-text); border-color: var(--warning-border); }
.shell-mark[data-state="withdrawn"]       { background: var(--neutral-bg); color: var(--neutral-text); border-color: var(--neutral-border); }
/* Neutral: the application has no authoritative state for this section. It
   deliberately looks like neither a tick nor an empty circle. */
.shell-mark[data-state="unknown"],
.shell-mark[data-state="not_applicable"] { background: transparent; color: var(--text-muted); border-style: dashed; }

/* A count is work outstanding, so it reads as work: never a neutral pill. */
.shell-count {
  flex: 0 0 auto;
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 1.375rem; height: 1.375rem; padding: 0 7px; border-radius: 999px;
  font-size: .6875rem; font-weight: 700;
  background: var(--warning-bg); color: var(--warning-text);
  border: 1px solid var(--warning-border);
}
.shell-count[data-tone="urgent"] { background: var(--danger-bg); color: var(--danger-text); border-color: var(--danger-border); }
.shell-count[data-tone="quiet"]  { background: var(--neutral-bg); color: var(--neutral-text); border-color: var(--neutral-border); }
/* Unknown: the count could not be read — dashed, never a zero. */
.shell-count[data-tone="unknown"] { background: transparent; color: var(--warning-text); border: 1px dashed var(--warning-border); }
.shell-done { flex: 0 0 auto; color: var(--success-text); font-weight: 700; }

/* Second-level navigation: the sections inside the destination you are in. */
.shell-subnav { display: grid; gap: 1px; margin: var(--space-1) 0 var(--space-2) var(--space-3); }
.shell-subnav .shell-nav-item {
  min-height: 40px; font-size: .8125rem; font-weight: 500;
  padding-left: 8px;
}
.shell-subnav .shell-nav-item[aria-current] { font-weight: 700; }
.shell-subnav-status { display: block; font-size: .625rem; font-weight: 600; color: var(--text-muted); }

.shell-footer {
  padding: var(--space-5) var(--page-inline-mobile) var(--space-8);
  font-size: .75rem; color: var(--text-muted);
  display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap;
}
.shell-footer a { color: var(--text-muted); }

.shell-search { padding: 0 var(--space-2); }
.shell-search input {
  width: 100%; min-height: 40px; padding: 8px 12px;
  border: 1px solid var(--border-default); border-radius: var(--radius-sm);
  background: var(--surface-subtle); font: inherit; font-size: .8125rem;
  color: var(--text-primary);
}
.shell-search input:focus { background: var(--surface-card); }

.shell-nav-back { color: var(--text-muted); font-size: .8125rem; }
.shell-nav-note {
  margin: 0 0 var(--space-2); padding: 8px 10px;
  font-size: .6875rem; line-height: 1.4; color: var(--warning-text);
  background: var(--warning-bg); border: 1px solid var(--warning-border);
  border-radius: var(--radius-sm);
}

.shell-sidebar-footer {
  margin-top: auto; padding-top: var(--space-3);
  border-top: 1px solid var(--border-default);
  display: grid; gap: var(--space-1);
}

.shell-user {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px;
  font-size: .8125rem; width: 100%; text-align: left;
  background: transparent; border: 1px solid transparent;
  border-radius: var(--radius-sm); font-family: inherit; cursor: pointer;
}
.shell-user:hover { background: var(--brand-050); }
.shell-user-menu-wrap { position: relative; }
/* The menu opens upwards: it sits at the foot of the sidebar. */
.shell-user-menu-wrap .nav-user-menu { bottom: 100%; top: auto; left: 0; right: auto; }
.shell-user-avatar {
  flex: 0 0 auto; width: 2rem; height: 2rem; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--brand-100); color: var(--brand-800); font-weight: 700;
}
.shell-user-name { font-weight: 700; color: var(--text-primary); display: block; }
.shell-user-role { color: var(--text-muted); display: block; font-size: .75rem; }

/* ── Top bar ──────────────────────────────────────────────────────────────
   Deliberately thin. Once the sidebar carries movement, the top bar carries
   only where-you-are and the few things that are global. */
.shell-topbar {
  display: flex; align-items: center; gap: var(--space-3);
  min-height: var(--shell-topbar-h);
  padding: var(--space-2) var(--page-inline-mobile);
  border-bottom: 1px solid var(--border-default);
  background: var(--surface-card);
  position: sticky; top: 0; z-index: 30;
}
.shell-topbar-title { flex: 1 1 auto; min-width: 0; }
.shell-topbar-title h1,
.shell-topbar-context {
  display: block;
  margin: 0; font-size: 1rem; font-weight: 700; line-height: 1.3;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.shell-topbar-sub { font-size: .75rem; color: var(--text-secondary); }
.shell-topbar-meta { flex: 0 0 auto; font-size: .75rem; color: var(--text-secondary); }

.shell-menu-btn {
  flex: 0 0 auto;
  display: inline-flex; align-items: center; justify-content: center;
  width: 44px; height: 44px; padding: 0;
  border: 1px solid var(--border-default); border-radius: var(--radius-sm);
  background: var(--surface-card); color: var(--text-primary);
  font-size: 1.125rem; cursor: pointer;
}
.shell-menu-btn:hover { border-color: var(--brand-600); }

.shell-collapse-btn {
  display: none;
  align-items: center; justify-content: center; gap: 8px;
  min-height: 40px; padding: 8px 10px; width: 100%;
  border: 1px solid transparent; border-radius: var(--radius-sm);
  background: transparent; color: var(--text-muted);
  font: inherit; font-size: .75rem; font-weight: 600; cursor: pointer;
}
.shell-collapse-btn:hover { background: var(--brand-050); color: var(--text-primary); }

.shell-backdrop { display: none; }

/* ── Focus ────────────────────────────────────────────────────────────────── */
:where(.shell a, .shell button, .shell input, .shell select, .shell textarea,
       .shell summary, .shell [tabindex]):focus-visible {
  outline: 3px solid var(--brand-600); outline-offset: 2px; border-radius: 4px;
}

.shell-skip {
  position: absolute; left: -9999px; top: 0; z-index: 100;
  background: var(--brand-900); color: #fff; padding: 12px 18px;
  border-radius: 0 0 var(--radius-sm) 0; font-weight: 600;
}
.shell-skip:focus { left: 0; }

.shell-visually-hidden {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ── Mobile: the same sidebar, off-canvas ─────────────────────────────────
   Only applied once JavaScript has run. Without it the sidebar is an ordinary
   block at the top of the page and every destination is still reachable — a
   client on a locked-down browser is never stranded. */
@media (max-width: 63.99rem) {
  .js .shell-sidebar {
    position: fixed; inset: 0 auto 0 0; z-index: 60;
    width: min(19rem, 86vw);
    transform: translateX(-100%);
    transition: transform .22s ease;
    overflow-y: auto;
    box-shadow: var(--shadow-md);
  }
  .js .shell[data-nav-open="true"] .shell-sidebar { transform: translateX(0); }
  .js .shell[data-nav-open="true"] .shell-backdrop {
    display: block; position: fixed; inset: 0; z-index: 50;
    background: rgba(28, 15, 8, .45);
  }
  .shell-menu-btn { display: inline-flex; }
}

@media (prefers-reduced-motion: reduce) {
  .js .shell-sidebar { transition: none; }
}

/* ── Desktop: the sidebar is simply there ─────────────────────────────────── */
@media (min-width: 64rem) {
  .shell {
    display: grid;
    grid-template-columns: var(--shell-sidebar-w) minmax(0, 1fr);
  }
  .shell[data-collapsed="true"] { grid-template-columns: var(--shell-sidebar-collapsed-w) minmax(0, 1fr); }
  .shell-sidebar { position: sticky; top: 0; height: 100vh; overflow-y: auto; }
  .shell-menu-btn { display: none; }
  .shell-collapse-btn { display: flex; }
  .shell-topbar { padding-inline: var(--page-inline-desktop); }

  /* Collapsed: icons and counts only, labels withdrawn. The destination order
     never changes, so muscle memory survives the collapse. */
  .shell[data-collapsed="true"] .shell-nav-text,
  .shell[data-collapsed="true"] .shell-nav-label,
  .shell[data-collapsed="true"] .shell-context,
  .shell[data-collapsed="true"] .shell-brand-sub,
  .shell[data-collapsed="true"] .shell-brand-mark,
  .shell[data-collapsed="true"] .shell-subnav,
  .shell[data-collapsed="true"] .shell-user-text,
  .shell[data-collapsed="true"] .shell-collapse-label { display: none; }
  .shell[data-collapsed="true"] .shell-nav-item { justify-content: center; padding-inline: 4px; }
  .shell[data-collapsed="true"] .shell-search,
  .shell[data-collapsed="true"] .shell-nav-note,
  .shell[data-collapsed="true"] .shell-nav-back { display: none; }
  /* A count still has to be visible collapsed — that is the point of the
     rail — so it rides on the destination mark rather than beside it. */
  .shell[data-collapsed="true"] .shell-nav-item { position: relative; }
  .shell[data-collapsed="true"] .shell-count {
    position: absolute; top: 2px; right: 2px;
    min-width: 1rem; height: 1rem; padding: 0 4px; font-size: .5625rem;
  }
  .shell[data-collapsed="true"] .shell-sidebar { padding-inline: var(--space-2); }
}

@media (min-width: 48rem) and (max-width: 63.99rem) {
  .shell-topbar { padding-inline: var(--page-inline-tablet); }
}
