/* ============================================================================
 * Milestone Corporation — Brand & component system
 *
 * The palette IS the wordmark: the navy of the M and "MILESTONE" (#1F375C) and
 * the grey of the swoosh and "CORPORATION" (#6D7278). --shell is that navy and
 * carries the chrome (topbar, rail, drawer); --brand is a lighter tint of it and
 * is the single accent that marks the live/selected thing. Large fills never use
 * --brand. Milestone is a HOLDING COMPANY, so the chrome stays restrained enough
 * that a subsidiary's own accent can sit on top without fighting it.
 *
 * RE-THEMING happens ONLY in the :root block below. Every rule in this file
 * references a token, so a logo drop or a subsidiary palette is a token edit,
 * never a find-and-replace through the components.
 *
 * PER-COMPANY ACCENT: ms-api.js sets data-company="<id>" on <html> and the
 * [data-company] blocks at the end of this file override --brand/--brand-t
 * for that subsidiary. Corporate (Milestone) uses the default.
 *
 * Loaded on every page. Tap targets >=44px, touch inputs >=16px (no iOS zoom).
 * ========================================================================== */

:root {
  /* Core ink & steel — taken straight from the Milestone wordmark: the navy of
     the M and "MILESTONE", and the grey of the swoosh and "CORPORATION".
     Component rules across this file reference --ink for "the dark surface" and
     --shell for the chrome, so restyling starts and ends here. */
  --ink:        #1b2430;
  --ink-2:      #1f375c;   /* logo navy */
  --ink-3:      #33507a;
  --shell:      #1f375c;   /* logo navy — topbar, rail, drawer */
  --shell-2:    #162945;   /* one step down, for depth inside the chrome */
  --steel:      #6d7278;   /* logo grey — "CORPORATION" / the swoosh */
  --steel-2:    #949aa1;
  --steel-3:    #c6cbd1;

  /* Surfaces */
  --bg:         #f3f5f8;
  --surface:    #ffffff;
  --surface-2:  #f7f9fb;
  --border:     #e3e7ed;
  --border-2:   #cfd6df;

  /* Text */
  --text:       #1b2430;
  --muted:      #5b6068;
  --faint:      #949aa1;

  /* Brand accent. Marks what is LIVE or SELECTED — the active rail item, a
     focus ring, a chosen tab. The identity is navy + grey only, so the accent
     is a lighter tint of the same navy: it stays on-brand, it is legible on
     both the white page and the navy rail, and — unlike a red/green accent — it
     never collides with the variance colours a financial statement depends on.
     Never used for large fills. */
  --brand:      #4c8fd1;
  --brand-t:    #eaf2fa;
  --accent:     #1f375c;      /* links + focus sit in the logo navy itself */

  /* Financial variance palette. THIS IS SEMANTIC, NOT DECORATIVE:
     --fav = better than plan/prior, --unfav = worse. Every KPI, variance column
     and trend arrow in the app reads these two and nothing else, so the whole
     suite flips together if the convention ever changes. */
  --fav:        #11794a;
  --unfav:      #c0392f;
  --fav-t:      #eaf6f0;
  --unfav-t:    #fdf0ef;
  --neutral:    #6d7278;
  --neutral-t:  #f1f3f6;

  /* Status palette — doubles as the meeting / calendar colour code */
  --st-red:     #c0392f;   /* Blocked / off track / overdue */
  --st-yellow:  #d99b0b;   /* At risk / needs review */
  --st-green:   #11794a;   /* On track / approved */
  --st-blue:    #1f375c;   /* Scheduled / informational */
  --st-gray:    #949aa1;   /* Draft / not started */

  --st-red-t:    #fdf0ef;
  --st-yellow-t: #fefaeb;
  --st-green-t:  #eaf6f0;
  --st-blue-t:   #eef2f7;
  --st-gray-t:   #f2f4f7;

  /* Chart series. Ordered for categorical use and safe to read in sequence —
     a consolidated statement charts one series PER SUBSIDIARY, so this list
     must hold at least as many entries as Milestone has companies. Anchored on
     the logo navy and grey, then widened enough to stay distinguishable. */
  --series-1: #1f375c;
  --series-2: #4c8fd1;
  --series-3: #6d7278;
  --series-4: #2f8f7d;
  --series-5: #a8623f;
  --series-6: #6b5aa8;
  --series-7: #8d8f3b;

  /* Feedback */
  --ok:    #11794a;
  --warn:  #d99b0b;
  --danger:#c0392f;

  --radius:    10px;
  --radius-lg: 14px;
  --radius-sm: 7px;

  --shadow:    0 1px 2px rgba(0,0,0,.05), 0 6px 20px rgba(0,0,0,.06);
  --shadow-sm: 0 1px 2px rgba(0,0,0,.06);

  --font-sans: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, Arial, sans-serif;
  --font-cond: 'Montserrat', 'Inter', system-ui, sans-serif;
  /* Financial figures ALWAYS set in a tabular-figure face so columns of money
     line up digit-for-digit. Used by .num / .money in the table kit. */
  --font-num:  'IBM Plex Mono', ui-monospace, 'SF Mono', Menlo, Consolas, monospace;

  --topbar-h: 54px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.45;
  -webkit-text-size-adjust: 100%;
  overflow-x: hidden; /* clip the off-screen slide-out nav drawer so no page scrolls sideways */
}

h1, h2, h3, .cond {
  font-family: var(--font-cond);
  letter-spacing: .01em;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------------------------- Topbar / chrome ---------------------------- */
header.topbar {
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center; gap: 12px;
  height: var(--topbar-h);
  padding: 0 14px;
  background: linear-gradient(180deg, var(--shell), var(--shell-2));
  color: #fff;
  box-shadow: 0 1px 0 rgba(0,0,0,.35), 0 2px 12px rgba(0,0,0,.18);
}
header.topbar a.home {
  display: flex; align-items: center; gap: 10px;
  color: #fff; text-decoration: none;
}
header.topbar a.home img { height: 26px; width: auto; display: block; }
header.topbar a.home img.ms-logo-img { height: 30px; width: auto; border-radius: 0; background: none; }
@media (max-width: 600px) { header.topbar a.home img.ms-logo-img { height: 24px; } }
header.topbar .wordmark {
  font-family: var(--font-cond);
  font-weight: 800; font-size: 18px; letter-spacing: .02em;
  text-transform: uppercase; color: #fff;
}
header.topbar .wordmark .light { color: var(--steel-2); }
header.topbar .module {
  font-family: var(--font-cond);
  font-weight: 600; text-transform: uppercase; letter-spacing: .04em;
  font-size: 13px; color: var(--steel-2);
  padding-left: 12px; margin-left: 4px;
  border-left: 1px solid rgba(255,255,255,.15);
}
header.topbar .spacer { flex: 1; }
.ms-offline { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 700; color: #fbbf24; background: rgba(251,191,36,.14); border: 1px solid rgba(251,191,36,.4); border-radius: 999px; padding: 3px 10px; margin-left: 10px; white-space: nowrap; }
.ms-offline[hidden] { display: none; }
/* Neutral loading placeholder — pages show this (not their empty state) until msHydrated(). */
.ms-loading { display: flex; align-items: center; justify-content: center; gap: 10px; padding: 30px 16px; color: var(--muted); font-weight: 600; }
.ms-loading::before { content: ''; width: 16px; height: 16px; border: 2px solid var(--border-2); border-top-color: var(--steel); border-radius: 50%; animation: ms-spin .7s linear infinite; }
@keyframes ms-spin { to { transform: rotate(360deg); } }

.ms-userchip {
  display: inline-flex; align-items: center; gap: 8px;
  font-size: 13px; color: #e5e5e5;
}
.ms-userchip .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--st-green); box-shadow: 0 0 0 3px rgba(22,163,74,.2); }
.ms-userchip .dot.off { background: var(--steel); box-shadow: none; }
.ms-userchip a { color: var(--steel-2); font-size: 12px; }

/* Hamburger + slide nav */
.ms-navbtn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 44px; height: 44px; min-width: 44px;
  border: none; background: transparent; color: #fff; cursor: pointer;
  border-radius: 8px; font-size: 20px;
}
.ms-navbtn:hover { background: rgba(255,255,255,.1); }
.ms-navbtn.ms-bell { position: relative; text-decoration: none; }
.ms-badge { position: absolute; top: 3px; right: 3px; min-width: 16px; height: 16px; padding: 0 4px; border-radius: 999px; background: var(--st-red); color: #fff; font-size: 10px; font-weight: 700; line-height: 16px; text-align: center; box-shadow: 0 0 0 2px var(--ink); }
.ms-nav-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.45);
  opacity: 0; pointer-events: none; transition: opacity .16s ease; z-index: 98;
}
.ms-nav-overlay.open { opacity: 1; pointer-events: auto; }
.ms-nav-drawer {
  position: fixed; top: 0; right: 0; height: 100%; max-height: 100dvh; width: 280px; max-width: 84vw;
  background: var(--ink); color: #fff; z-index: 99;
  transform: translateX(100%); transition: transform .18s ease;
  display: flex; flex-direction: column; padding: 14px 0;
  box-shadow: -8px 0 30px rgba(0,0,0,.4);
  overflow-y: auto; -webkit-overflow-scrolling: touch; /* long menus stay reachable on short screens */
}
.ms-nav-drawer.open { transform: translateX(0); }
.ms-nav-drawer .head {
  display: block; padding: 6px 18px 14px; border-bottom: 1px solid rgba(255,255,255,.12);
  font-family: var(--font-cond); font-weight: 800; text-transform: uppercase; letter-spacing: .03em;
  color: #fff; text-decoration: none;
}
.ms-nav-drawer a.head:hover { color: #fff; text-decoration: none; opacity: .85; }
.ms-nav-drawer a.link {
  display: flex; align-items: center; gap: 12px;
  padding: 13px 18px; color: #e5e5e5; text-decoration: none;
  font-size: 15px; min-height: 44px;
}
.ms-nav-drawer a.link:hover { background: rgba(255,255,255,.07); text-decoration: none; }
.ms-nav-drawer a.link.active { background: rgba(255,255,255,.12); color: #fff; box-shadow: inset 3px 0 0 rgba(255,255,255,.9); }
/* Drawer footer: who's signed in + Sign out. On phones this is the ONLY home for sign-out —
 * the topbar identity chip is hidden ≤600px (see the media rule below) so the four action
 * buttons always fit the viewport. */
.ms-nav-drawer .ms-nav-foot { border-top: 1px solid rgba(255,255,255,.12); margin-top: auto; padding: 12px 18px 4px; font-size: 13px; color: var(--steel-2); display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.ms-nav-drawer .ms-nav-foot a { color: #fff; min-height: 44px; display: inline-flex; align-items: center; }
.ms-nav-drawer .ms-nav-foot .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--st-green); flex: none; }
.ms-nav-drawer .ms-nav-foot .dot.off { background: var(--steel); }

/* -------------------------------- Layout -------------------------------- */
.page { max-width: 1200px; margin: 0 auto; padding: 18px 16px 60px; }
.page-head { display: flex; align-items: center; gap: 12px; margin: 6px 0 18px; flex-wrap: wrap; }
.page-head h1 { margin: 0; font-size: 26px; font-weight: 800; text-transform: uppercase; }
.page-head .sub { color: var(--muted); font-size: 14px; }

/* -------------------------------- Buttons ------------------------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 8px 16px;
  border: 1px solid var(--border-2); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text);
  font: inherit; font-weight: 600; cursor: pointer;
  transition: background .12s ease, border-color .12s ease, transform .05s ease;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--ink); border-color: var(--ink); color: #fff; }
.btn-primary:hover { background: var(--ink-3); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-sm { min-height: 32px; padding: 5px 11px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
/* Touch devices: small buttons stay compact on desktop (fine pointer) but meet the 44px
   tap-target rule on phones/tablets. Applies app-wide so every .btn-sm is field-friendly. */
@media (pointer: coarse) {
  .btn-sm { min-height: 44px; padding-top: 8px; padding-bottom: 8px; }
  /* But a <select> wearing .btn-sm is a FORM CONTROL, and iOS Safari zooms the
     whole page when one is focused below 16px. The height rule above made these
     look right while leaving the zoom trap in place. 13px is fine on a button,
     never on a select. Period pickers, the activity limit, the feedback status
     and the QuickBooks realm mapping are all this shape. */
  select.btn, select.btn-sm { font-size: 16px; }
}

/* --------------------------------- Cards -------------------------------- */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow-sm);
  padding: 16px;
}
.card + .card { margin-top: 14px; }

/* --------------------------------- Tags --------------------------------- */
.tag {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600;
  background: var(--st-gray-t); color: var(--ink-3);
}
.badge {
  display: inline-flex; align-items: center; padding: 2px 8px;
  border-radius: 6px; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .03em;
}
.badge.admin { background: #111; color: #fff; }
.badge.member { background: var(--st-gray-t); color: var(--ink-3); }

/* Status chips (schedule color code) */
.st-chip { display:inline-flex; align-items:center; gap:6px; font-size:12px; font-weight:600; }
.st-chip .sw { width:11px; height:11px; border-radius:3px; }
.sw-red{background:var(--st-red)} .sw-yellow{background:var(--st-yellow)}
.sw-green{background:var(--st-green)} .sw-blue{background:var(--st-blue)} .sw-gray{background:var(--st-gray)}

/* -------------------------------- Inputs -------------------------------- */
input, select, textarea {
  font: inherit; font-size: 16px; /* >=16px: no iOS zoom */
  padding: 9px 11px; border: 1px solid var(--border-2); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text); width: 100%;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(37,99,235,.15);
}
/* Keyboard focus ring for every interactive control (nav tiles, buttons, links, custom
   role=button rows) — not just form fields. Mouse/touch clicks don't trigger :focus-visible. */
.btn:focus-visible, a:focus-visible, button:focus-visible, .tile:focus-visible,
[role="button"]:focus-visible, [tabindex]:focus-visible, summary:focus-visible {
  outline: none; box-shadow: 0 0 0 3px rgba(37,99,235,.40); border-radius: 8px;
}
/* Respect reduced-motion for vestibular comfort — kill transitions/animations/hover lifts. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; scroll-behavior: auto !important; }
  .tile:hover, .card:hover { transform: none !important; }
}
label.fld { display: block; margin: 10px 0; }
label.fld > span { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 4px; }

/* -------------------------------- Modals -------------------------------- */
.modal-bg {
  position: fixed; inset: 0; background: rgba(20,20,20,.5);
  display: none; align-items: center; justify-content: center; z-index: 80; padding: 16px;
}
.modal-bg.open { display: flex; }
.modal {
  position: relative; /* anchor the top-right × */
  background: var(--surface); border-radius: var(--radius-lg);
  box-shadow: 0 20px 60px rgba(0,0,0,.3); width: 100%; max-width: 520px;
  max-height: 90vh; overflow: auto; padding: 20px;
}
.modal h2 { margin: 0 0 12px; font-size: 20px; }
/* Standard top-right close affordance for any card/detail modal (injected by msAddModalClose as the
   panel's FIRST child). STICKY + float so it stays pinned to the top-right and visible while the
   modal body scrolls; the negative bottom margin keeps it from consuming a line (the title flows up
   beside it). 44×44 on every device (incl. desktop mouse) so it always meets the tap-target rule. */
.modal-x {
  position: sticky; top: 4px; float: right;
  margin: -4px -4px -44px 8px;
  width: 44px; height: 44px; min-height: 44px;
  display: flex; align-items: center; justify-content: center;
  border: none; background: var(--surface); color: var(--muted);
  font-size: 24px; line-height: 1; border-radius: 10px; cursor: pointer; z-index: 3;
}
.modal-x:hover { background: var(--surface-2); color: var(--text); }
.modal-x:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* -------------------------------- Toasts -------------------------------- */
/* z-index 320: toasts must be visible above EVERY surface — the doc viewer (200), the daily-report
 * lightbox (300), and the shared image lightbox (310) were swallowing upload/save confirmations. */
.ms-toasts { position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%); z-index: 320; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }

/* Shared image lightbox (window.msImageLightbox) — replaces open-in-new-tab for attachment photos
 * so there is always a way back (✕ / backdrop / Esc). z 310: above the doc viewer + dr-lightbox,
 * below toasts. */
#ms-lb { position: fixed; inset: 0; z-index: 310; background: rgba(10,10,10,.94); display: flex; align-items: center; justify-content: center; }
#ms-lb .ms-lb-img { max-width: 94vw; max-height: 88vh; object-fit: contain; border-radius: 6px; }
#ms-lb .ms-lb-x { position: absolute; top: 10px; right: 12px; width: 48px; height: 48px; border: none; background: rgba(255,255,255,.16); color: #fff; font-size: 20px; border-radius: 999px; cursor: pointer; }
#ms-lb .ms-lb-nav { position: absolute; top: 50%; transform: translateY(-50%); width: 52px; height: 64px; border: none; background: rgba(255,255,255,.12); color: #fff; font-size: 34px; line-height: 1; cursor: pointer; border-radius: 10px; }
#ms-lb .ms-lb-prev { left: 8px; } #ms-lb .ms-lb-next { right: 8px; }
#ms-lb .ms-lb-count { position: absolute; bottom: 14px; left: 50%; transform: translateX(-50%); color: #fff; font-size: 13px; font-weight: 600; background: rgba(0,0,0,.4); padding: 4px 12px; border-radius: 999px; }
@media (pointer: coarse) { #ms-lb .ms-lb-x { width: 52px; height: 52px; } }

/* ---- shared card kit (labels + checklists) — ms-cardkit.js K.mount ---- */
.ck-members { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin: 4px 0 8px; }
.ck-mem { display: inline-flex; align-items: center; gap: 3px; width: 30px; height: 30px; justify-content: center; border-radius: 999px; background: var(--ink); color: #fff; font-size: 11px; font-weight: 800; text-transform: uppercase; position: relative; }
.ck-mem .ck-rm-mem { position: absolute; top: -5px; right: -5px; border: 0; background: #dc2626; color: #fff; border-radius: 999px; width: 15px; height: 15px; line-height: 13px; font-size: 11px; cursor: pointer; padding: 0; }
.ck-add-mem { border: 1px dashed var(--border-2, #d4d4d4); background: transparent; color: var(--muted); font-size: 12px; font-weight: 700; border-radius: 999px; padding: 4px 10px; min-height: 30px; cursor: pointer; }
.ck-add-mem:hover { color: var(--ink); border-color: var(--muted); }
.ck-mem-list { display: flex; flex-direction: column; gap: 2px; max-height: 240px; overflow: auto; }
.ck-mem-opt { display: flex; align-items: center; gap: 7px; font-size: 14px; padding: 5px 2px; cursor: pointer; }
.ck-face .ck-mem-dot { width: 18px; height: 18px; border-radius: 999px; background: var(--ink); color: #fff; font-size: 9px; font-weight: 800; display: inline-flex; align-items: center; justify-content: center; text-transform: uppercase; }
@media (pointer: coarse) { .ck-mem, .ck-add-mem { min-height: 40px; } .ck-mem { width: 40px; height: 40px; } .ck-mem-opt { padding: 8px 2px; } }
.ck-labels { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin: 4px 0 8px; }
.ck-chip { display: inline-flex; align-items: center; gap: 4px; color: #fff; font-size: 12px; font-weight: 700; padding: 3px 9px; border-radius: 999px; line-height: 1.4; min-height: 22px; }
.ck-chip .ck-rm-lbl { border: 0; background: rgba(255,255,255,.35); color: #fff; border-radius: 999px; width: 16px; height: 16px; line-height: 14px; font-size: 12px; cursor: pointer; padding: 0; }
.ck-add-lbl { border: 1px dashed var(--border-2, #d4d4d4); background: transparent; color: var(--muted); font-size: 12px; font-weight: 700; border-radius: 999px; padding: 3px 10px; min-height: 26px; cursor: pointer; }
.ck-add-lbl:hover { color: var(--ink); border-color: var(--muted); }
.ck-prog { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); font-weight: 700; margin-bottom: 4px; }
.ck-bar { flex: 1; height: 6px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.ck-bar i { display: block; height: 100%; background: var(--st-green, #16a34a); transition: width .15s; }
.ck-item { display: flex; align-items: center; gap: 8px; padding: 6px 0; font-size: 14px; cursor: pointer; }
.ck-item input { width: 20px; height: 20px; flex: none; }
.ck-item span { flex: 1; overflow-wrap: anywhere; }
.ck-item.done span { text-decoration: line-through; color: var(--muted); }
.ck-item .ck-rm { border: 0; background: transparent; color: var(--faint); font-size: 16px; cursor: pointer; padding: 0 4px; }
.ck-item .ck-rm:hover { color: #b91c1c; }
.ck-add { display: flex; gap: 6px; margin-top: 6px; }
.ck-add input { flex: 1; min-width: 0; font-size: 16px; padding: 7px 10px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); color: var(--ink); }
.ck-add button { flex: none; min-height: 40px; padding: 0 12px; border: 1px solid var(--border); background: var(--surface); border-radius: var(--radius-sm); font-weight: 700; cursor: pointer; color: var(--ink); }
@media (pointer: coarse) { .ck-item input { width: 24px; height: 24px; } .ck-add button, .ck-add-lbl { min-height: 44px; } .ck-item .ck-rm { padding: 0 10px; } }
.ck-pal { position: absolute; z-index: 340; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); box-shadow: var(--shadow); padding: 10px; width: 210px; }
.ck-pal .ck-pal-text { width: 100%; font-size: 16px; padding: 7px 9px; border: 1px solid var(--border); border-radius: var(--radius-sm); margin-bottom: 8px; background: var(--surface); color: var(--ink); }
.ck-pal-colors { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.ck-pal-c { height: 30px; border: 0; border-radius: 6px; cursor: pointer; }
/* card-face chip strip (compact, no remove button) reuses .ck-chip via a .ck-face wrapper */
.ck-face { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.ck-face .ck-dot { width: 30px; height: 8px; border-radius: 999px; }
.ms-toast {
  background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 999px;
  font-size: 14px; box-shadow: var(--shadow); max-width: 90vw;
  animation: msToastIn .18s ease; pointer-events: auto;
}
.ms-toast.ok    { background: #14532d; }
.ms-toast.error { background: #7f1d1d; }
.ms-toast.warn  { background: #78350f; }
@keyframes msToastIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ----------------------------- Sync progress ---------------------------- */
#ms-progress {
  position: fixed; top: 0; left: 0; height: 3px; width: 0;
  background: var(--st-red); z-index: 200; transition: width .2s ease, opacity .3s ease;
}

/* --------------------------------- Utils -------------------------------- */
.row { display: flex; gap: 12px; align-items: center; }
.wrap { flex-wrap: wrap; }
.grow { flex: 1; }
.muted { color: var(--muted); }
.hidden { display: none !important; }
.center { text-align: center; }

/* ----------------------------- attachments ----------------------------- */
.ms-atts { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.ms-atts .att { position: relative; width: 64px; height: 64px; border-radius: 8px; overflow: hidden; border: 1px solid var(--border); background: var(--surface-2); display: flex; align-items: center; justify-content: center; cursor: pointer; }
.ms-atts .att img { width: 100%; height: 100%; object-fit: cover; }
.ms-atts .att .doc { font-size: 10px; padding: 4px; text-align: center; word-break: break-all; color: var(--muted); }
.ms-atts .att .up { position: absolute; inset: 0; background: rgba(0,0,0,.45); color: #fff; display: flex; align-items: center; justify-content: center; font-size: 16px; }
.ms-atts .att .rm { position: absolute; top: 2px; right: 2px; width: 20px; height: 20px; border-radius: 50%; border: none; background: rgba(0,0,0,.6); color: #fff; font-size: 14px; line-height: 1; cursor: pointer; padding: 0; }
.ms-atts .addbtn { width: 64px; height: 64px; min-height: 44px; border-radius: 8px; border: 1px dashed var(--border-2); background: var(--surface); display: flex; align-items: center; justify-content: center; font-size: 22px; cursor: pointer; }
.ms-atts .addbtn:hover { background: var(--surface-2); }

/* ------------------------------ doc viewer ------------------------------ */
.ms-viewer { position: fixed; inset: 0; z-index: 200; background: #1a1a1a; display: flex; flex-direction: column; }
.bv-bar { display: flex; align-items: center; gap: 4px; padding: 6px 8px; background: #111; color: #fff; overflow-x: auto; flex: none; }
.bv-bar .bv-name { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 30vw; }
.bv-sp { flex: 1; }
.bv-btn { min-width: 44px; height: 44px; border: none; background: #262626; color: #fff; border-radius: 7px; font-size: 16px; cursor: pointer; flex: none; }
.bv-textinput { font-size: 16px; padding: 7px 9px; border-radius: 6px; border: 2px solid var(--accent); background: #fff; color: #111; width: 210px; max-width: 60vw; box-shadow: 0 4px 16px rgba(0,0,0,.4); }
.bv-btn.on { background: var(--accent); }
.bv-btn.bv-save { background: var(--st-green); font-size: 14px; padding: 0 12px; font-weight: 700; }
.bv-colors { display: inline-flex; gap: 3px; }
.bv-color { width: 26px; height: 26px; border-radius: 50%; border: 2px solid #444; cursor: pointer; padding: 0; }
.bv-color.on { border-color: #fff; }
.bv-pages { flex: 1; overflow: auto; padding: 12px; text-align: center; -webkit-overflow-scrolling: touch; touch-action: pan-x pan-y; }
.bv-page { position: relative; display: inline-block; margin: 0 auto 12px; box-shadow: 0 4px 20px rgba(0,0,0,.5); background: #fff; } /* no max-width: allow zoom past fit-width, .bv-pages scrolls */
.bv-page canvas.bv-overlay ~ canvas, .bv-page > canvas:first-child { display: block; width: 100%; height: auto; }
.bv-overlay { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: pan-x pan-y; }
.bv-pages.drawing .bv-overlay { touch-action: none; cursor: crosshair; }
.bv-loading { color: #ccc; padding: 40px; }

/* ---------------------------- job documents ---------------------------- */
.doc-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.doc-card { position: relative; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; cursor: pointer; box-shadow: var(--shadow-sm); }
.doc-card .doc-del { position: absolute; top: 4px; right: 4px; width: 28px; height: 28px; border-radius: 50%; border: none; background: rgba(0,0,0,.55); color: #fff; font-size: 16px; line-height: 1; cursor: pointer; padding: 0; }
.doc-card .thumb { height: 96px; background: var(--surface-2); display: flex; align-items: center; justify-content: center; font-size: 34px; color: var(--steel); }
.doc-card .thumb img { width: 100%; height: 100%; object-fit: cover; }
.doc-card .meta { padding: 8px 10px; }
.doc-card .meta .nm { font-weight: 600; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.doc-card .meta .sub { font-size: 11px; color: var(--muted); }
.doc-card .badge2 { display: inline-block; font-size: 10px; padding: 1px 6px; border-radius: 999px; background: var(--st-blue-t); color: #1e40af; margin-top: 3px; }
.doc-card .cached { color: var(--st-green); }

/* Access-denied overlay for permission gating */
.ms-denied {
  position: fixed; inset: var(--topbar-h) 0 0 0; background: var(--bg);
  display: flex; align-items: center; justify-content: center; z-index: 70; padding: 24px;
  overflow: auto;
}
.ms-denied .box { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 28px; max-width: 420px; text-align: center; box-shadow: var(--shadow); }

@media (max-width: 600px) {
  .page { padding: 14px 12px 60px; }
  .page-head h1 { font-size: 22px; }
  header.topbar .wordmark { font-size: 16px; }
  header.topbar .module { display: none; }
  /* Phones: the fixed-width topbar pieces (wordmark + name chip + FOUR 44px buttons) exceeded
   * narrow viewports — flexbox can't shrink them, so the FEEDBACK and MENU buttons were pushed
   * clean off-screen (427px layout on a 375px phone; "Sam has no feedback button"). Hide the
   * identity chip here (it moves to the nav-drawer footer — sign-out stays reachable) and
   * tighten gaps: 20 + 80 logo + 5×6 gaps + 4×44 buttons = 306px, safe down to 320px. */
  header.topbar { gap: 6px; padding: 0 10px; }
  header.topbar .ms-userchip { display: none; }
  /* The Offline pill must not re-blow the width budget (offline is exactly when crews are on
   * phones): float it just below the bar instead of occupying flex space in it. */
  .ms-offline { position: absolute; top: calc(var(--topbar-h) + 4px); right: 8px; margin-left: 0; z-index: 49; }
}

/* ============================================================================
 * Shared line-icon system (Phase 8 UI refresh)
 * SVG mask-image icons, colored by currentColor so they inherit each context and
 * stay NEUTRAL by default (color is reserved for KPIs). Defined in the render-
 * blocking stylesheet so they are always available (no JS timing, offline-safe).
 * ========================================================================== */
.ms-ico { display:inline-block; width:22px; height:22px; flex:none; background-color:currentColor;
  -webkit-mask:no-repeat center / contain; mask:no-repeat center / contain; }
.ms-navbtn .ms-ico { width:22px; height:22px; }
.ms-nav-drawer a.link .ms-ico { opacity:.78; }
.ms-nav-drawer a.link:hover .ms-ico, .ms-nav-drawer a.link.active .ms-ico { opacity:1; }
.ms-ico-home{-webkit-mask-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M3 11.5 12 4l9 7.5'/%3E%3Cpath d='M5.5 10v9.5h13V10'/%3E%3Cpath d='M9.5 19.5V14h5v5.5'/%3E%3C/svg%3E");mask-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M3 11.5 12 4l9 7.5'/%3E%3Cpath d='M5.5 10v9.5h13V10'/%3E%3Cpath d='M9.5 19.5V14h5v5.5'/%3E%3C/svg%3E")}
.ms-ico-myday{-webkit-mask-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='8.5'/%3E%3Cpath d='M12 7.5V12l3 2'/%3E%3C/svg%3E");mask-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='8.5'/%3E%3Cpath d='M12 7.5V12l3 2'/%3E%3C/svg%3E")}
.ms-ico-spark{-webkit-mask-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M12 3.5c0 4 1.6 5.6 5.6 5.6-4 0-5.6 1.6-5.6 5.6 0-4-1.6-5.6-5.6-5.6 4 0 5.6-1.6 5.6-5.6Z'/%3E%3Cpath d='M17.5 15.5c0 2.2.9 3.1 3.1 3.1-2.2 0-3.1.9-3.1 3.1 0-2.2-.9-3.1-3.1-3.1 2.2 0 3.1-.9 3.1-3.1Z'/%3E%3C/svg%3E");mask-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M12 3.5c0 4 1.6 5.6 5.6 5.6-4 0-5.6 1.6-5.6 5.6 0-4-1.6-5.6-5.6-5.6 4 0 5.6-1.6 5.6-5.6Z'/%3E%3Cpath d='M17.5 15.5c0 2.2.9 3.1 3.1 3.1-2.2 0-3.1.9-3.1 3.1 0-2.2-.9-3.1-3.1-3.1 2.2 0 3.1-.9 3.1-3.1Z'/%3E%3C/svg%3E")}
.ms-ico-scheduler{-webkit-mask-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M4 4.5v15'/%3E%3Crect x='7' y='6' width='9' height='3' rx='1.2'/%3E%3Crect x='10' y='10.5' width='8' height='3' rx='1.2'/%3E%3Crect x='7' y='15' width='6' height='3' rx='1.2'/%3E%3C/svg%3E");mask-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M4 4.5v15'/%3E%3Crect x='7' y='6' width='9' height='3' rx='1.2'/%3E%3Crect x='10' y='10.5' width='8' height='3' rx='1.2'/%3E%3Crect x='7' y='15' width='6' height='3' rx='1.2'/%3E%3C/svg%3E")}
.ms-ico-board{-webkit-mask-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='3.5' y='4.5' width='4.5' height='15' rx='1.2'/%3E%3Crect x='9.75' y='4.5' width='4.5' height='9' rx='1.2'/%3E%3Crect x='16' y='4.5' width='4.5' height='12' rx='1.2'/%3E%3C/svg%3E");mask-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='3.5' y='4.5' width='4.5' height='15' rx='1.2'/%3E%3Crect x='9.75' y='4.5' width='4.5' height='9' rx='1.2'/%3E%3Crect x='16' y='4.5' width='4.5' height='12' rx='1.2'/%3E%3C/svg%3E")}
.ms-ico-documents{-webkit-mask-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M13.5 3.5H7A1.5 1.5 0 0 0 5.5 5v14A1.5 1.5 0 0 0 7 20.5h10A1.5 1.5 0 0 0 18.5 19V8.5z'/%3E%3Cpath d='M13.5 3.5V8.5h5'/%3E%3Cpath d='M8.5 13h7'/%3E%3Cpath d='M8.5 16.5h7'/%3E%3C/svg%3E");mask-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M13.5 3.5H7A1.5 1.5 0 0 0 5.5 5v14A1.5 1.5 0 0 0 7 20.5h10A1.5 1.5 0 0 0 18.5 19V8.5z'/%3E%3Cpath d='M13.5 3.5V8.5h5'/%3E%3Cpath d='M8.5 13h7'/%3E%3Cpath d='M8.5 16.5h7'/%3E%3C/svg%3E")}
.ms-ico-chat{-webkit-mask-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M20 11.6a7.6 7.6 0 0 1-10.9 6.9L4 20l1.5-4.9A7.6 7.6 0 1 1 20 11.6z'/%3E%3C/svg%3E");mask-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M20 11.6a7.6 7.6 0 0 1-10.9 6.9L4 20l1.5-4.9A7.6 7.6 0 1 1 20 11.6z'/%3E%3C/svg%3E")}
.ms-ico-po{-webkit-mask-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='5.5' y='4.5' width='13' height='15.5' rx='2'/%3E%3Cpath d='M9 4.5V3.9A1.4 1.4 0 0 1 10.4 2.5h3.2A1.4 1.4 0 0 1 15 3.9v.6z'/%3E%3Cpath d='M9 10h6'/%3E%3Cpath d='M9 13.5h6'/%3E%3Cpath d='M9 17h4'/%3E%3C/svg%3E");mask-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='5.5' y='4.5' width='13' height='15.5' rx='2'/%3E%3Cpath d='M9 4.5V3.9A1.4 1.4 0 0 1 10.4 2.5h3.2A1.4 1.4 0 0 1 15 3.9v.6z'/%3E%3Cpath d='M9 10h6'/%3E%3Cpath d='M9 13.5h6'/%3E%3Cpath d='M9 17h4'/%3E%3C/svg%3E")}
.ms-ico-expenses{-webkit-mask-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 3.5h12v17l-2-1.3-2 1.3-2-1.3-2 1.3-2-1.3-2 1.3z'/%3E%3Cpath d='M9 8h6'/%3E%3Cpath d='M9 11.5h6'/%3E%3Cpath d='M9 15h4'/%3E%3C/svg%3E");mask-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 3.5h12v17l-2-1.3-2 1.3-2-1.3-2 1.3-2-1.3-2 1.3z'/%3E%3Cpath d='M9 8h6'/%3E%3Cpath d='M9 11.5h6'/%3E%3Cpath d='M9 15h4'/%3E%3C/svg%3E")}
.ms-ico-reports{-webkit-mask-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M4 20h16'/%3E%3Crect x='5.4' y='12' width='3.2' height='6' rx='0.8'/%3E%3Crect x='10.4' y='8' width='3.2' height='10' rx='0.8'/%3E%3Crect x='15.4' y='5' width='3.2' height='13' rx='0.8'/%3E%3C/svg%3E");mask-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M4 20h16'/%3E%3Crect x='5.4' y='12' width='3.2' height='6' rx='0.8'/%3E%3Crect x='10.4' y='8' width='3.2' height='10' rx='0.8'/%3E%3Crect x='15.4' y='5' width='3.2' height='13' rx='0.8'/%3E%3C/svg%3E")}
/* Finance icons — added for Milestone. Same 24x24 stroke grid as the rest so
   they sit at identical optical weight in the rail. */
.ms-ico-building{-webkit-mask-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M4 20.5V6.5a1 1 0 0 1 1-1h6a1 1 0 0 1 1 1v14'/%3E%3Cpath d='M12 20.5V10h6.5a1 1 0 0 1 1 1v9.5'/%3E%3Cpath d='M2.5 20.5h19'/%3E%3Cpath d='M6.5 9h3M6.5 12.5h3M6.5 16h3M15 13.5h1.5M15 17h1.5'/%3E%3C/svg%3E");mask-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M4 20.5V6.5a1 1 0 0 1 1-1h6a1 1 0 0 1 1 1v14'/%3E%3Cpath d='M12 20.5V10h6.5a1 1 0 0 1 1 1v9.5'/%3E%3Cpath d='M2.5 20.5h19'/%3E%3Cpath d='M6.5 9h3M6.5 12.5h3M6.5 16h3M15 13.5h1.5M15 17h1.5'/%3E%3C/svg%3E")}
.ms-ico-trend{-webkit-mask-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M3.5 16.5 9 11l3.5 3.5L20.5 6.5'/%3E%3Cpath d='M15.5 6.5h5v5'/%3E%3Cpath d='M3.5 20.5h17'/%3E%3C/svg%3E");mask-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M3.5 16.5 9 11l3.5 3.5L20.5 6.5'/%3E%3Cpath d='M15.5 6.5h5v5'/%3E%3Cpath d='M3.5 20.5h17'/%3E%3C/svg%3E")}
.ms-ico-layers{-webkit-mask-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M12 3.2 21 8l-9 4.8L3 8z'/%3E%3Cpath d='M3 12.4 12 17.2 21 12.4'/%3E%3Cpath d='M3 16.6 12 21.4 21 16.6'/%3E%3C/svg%3E");mask-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M12 3.2 21 8l-9 4.8L3 8z'/%3E%3Cpath d='M3 12.4 12 17.2 21 12.4'/%3E%3Cpath d='M3 16.6 12 21.4 21 16.6'/%3E%3C/svg%3E")}
.ms-ico-link{-webkit-mask-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M10.2 13.8a3.6 3.6 0 0 0 5.2 0l3-3a3.6 3.6 0 0 0-5.1-5.1l-1.4 1.4'/%3E%3Cpath d='M13.8 10.2a3.6 3.6 0 0 0-5.2 0l-3 3a3.6 3.6 0 0 0 5.1 5.1l1.4-1.4'/%3E%3C/svg%3E");mask-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M10.2 13.8a3.6 3.6 0 0 0 5.2 0l3-3a3.6 3.6 0 0 0-5.1-5.1l-1.4 1.4'/%3E%3Cpath d='M13.8 10.2a3.6 3.6 0 0 0-5.2 0l-3 3a3.6 3.6 0 0 0 5.1 5.1l1.4-1.4'/%3E%3C/svg%3E")}
.ms-ico-statement{-webkit-mask-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M5.5 3.5h9l4.5 4.5v12.5h-13.5z'/%3E%3Cpath d='M14.5 3.5V8h4.5'/%3E%3Cpath d='M8.5 11.5h7M8.5 14.5h7M8.5 17.5h4'/%3E%3C/svg%3E");mask-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M5.5 3.5h9l4.5 4.5v12.5h-13.5z'/%3E%3Cpath d='M14.5 3.5V8h4.5'/%3E%3Cpath d='M8.5 11.5h7M8.5 14.5h7M8.5 17.5h4'/%3E%3C/svg%3E")}
.ms-ico-scale{-webkit-mask-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M12 4.5v15'/%3E%3Cpath d='M7 19.5h10'/%3E%3Cpath d='M4 8.5h16'/%3E%3Cpath d='M4 8.5 1.8 13.5h4.4z'/%3E%3Cpath d='M20 8.5 17.8 13.5h4.4z'/%3E%3Ccircle cx='12' cy='5' r='1.3'/%3E%3C/svg%3E");mask-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M12 4.5v15'/%3E%3Cpath d='M7 19.5h10'/%3E%3Cpath d='M4 8.5h16'/%3E%3Cpath d='M4 8.5 1.8 13.5h4.4z'/%3E%3Cpath d='M20 8.5 17.8 13.5h4.4z'/%3E%3Ccircle cx='12' cy='5' r='1.3'/%3E%3C/svg%3E")}
.ms-ico-cashflow{-webkit-mask-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M3.5 7.5h13'/%3E%3Cpath d='M13.5 4.5 16.8 7.5 13.5 10.5'/%3E%3Cpath d='M20.5 16.5h-13'/%3E%3Cpath d='M10.5 13.5 7.2 16.5 10.5 19.5'/%3E%3C/svg%3E");mask-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M3.5 7.5h13'/%3E%3Cpath d='M13.5 4.5 16.8 7.5 13.5 10.5'/%3E%3Cpath d='M20.5 16.5h-13'/%3E%3Cpath d='M10.5 13.5 7.2 16.5 10.5 19.5'/%3E%3C/svg%3E")}
.ms-ico-bids{-webkit-mask-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='8.5'/%3E%3Ccircle cx='12' cy='12' r='4.5'/%3E%3Ccircle cx='12' cy='12' r='1.1' fill='%23000' stroke='none'/%3E%3C/svg%3E");mask-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='8.5'/%3E%3Ccircle cx='12' cy='12' r='4.5'/%3E%3Ccircle cx='12' cy='12' r='1.1' fill='%23000' stroke='none'/%3E%3C/svg%3E")}
.ms-ico-admin{-webkit-mask-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M12 3 5 6v5.5c0 4.3 3 7.7 7 9.5 4-1.8 7-5.2 7-9.5V6z'/%3E%3Cpath d='M9 12l2.2 2.2L15 10.3'/%3E%3C/svg%3E");mask-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M12 3 5 6v5.5c0 4.3 3 7.7 7 9.5 4-1.8 7-5.2 7-9.5V6z'/%3E%3Cpath d='M9 12l2.2 2.2L15 10.3'/%3E%3C/svg%3E")}
.ms-ico-guide{-webkit-mask-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='8.5'/%3E%3Cpath d='M9.6 9.2a2.5 2.5 0 0 1 4.2 1.6c0 1.7-2.3 2-2.3 3.4'/%3E%3Ccircle cx='11.5' cy='16.9' r='0.5' fill='%23000' stroke='none'/%3E%3C/svg%3E");mask-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='8.5'/%3E%3Cpath d='M9.6 9.2a2.5 2.5 0 0 1 4.2 1.6c0 1.7-2.3 2-2.3 3.4'/%3E%3Ccircle cx='11.5' cy='16.9' r='0.5' fill='%23000' stroke='none'/%3E%3C/svg%3E")}
.ms-ico-bell{-webkit-mask-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6.5 10.5a5.5 5.5 0 0 1 11 0c0 4 1.5 5.5 1.5 5.5H5s1.5-1.5 1.5-5.5z'/%3E%3Cpath d='M10 19a2 2 0 0 0 4 0'/%3E%3C/svg%3E");mask-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6.5 10.5a5.5 5.5 0 0 1 11 0c0 4 1.5 5.5 1.5 5.5H5s1.5-1.5 1.5-5.5z'/%3E%3Cpath d='M10 19a2 2 0 0 0 4 0'/%3E%3C/svg%3E")}
.ms-ico-feedback{-webkit-mask-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M4.5 5.5A1.5 1.5 0 0 1 6 4h12a1.5 1.5 0 0 1 1.5 1.5v8A1.5 1.5 0 0 1 18 15H9l-4 3.5V15H6a1.5 1.5 0 0 1-1.5-1.5z'/%3E%3Ccircle cx='9' cy='9.5' r='0.6' fill='%23000' stroke='none'/%3E%3Ccircle cx='12' cy='9.5' r='0.6' fill='%23000' stroke='none'/%3E%3Ccircle cx='15' cy='9.5' r='0.6' fill='%23000' stroke='none'/%3E%3C/svg%3E");mask-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M4.5 5.5A1.5 1.5 0 0 1 6 4h12a1.5 1.5 0 0 1 1.5 1.5v8A1.5 1.5 0 0 1 18 15H9l-4 3.5V15H6a1.5 1.5 0 0 1-1.5-1.5z'/%3E%3Ccircle cx='9' cy='9.5' r='0.6' fill='%23000' stroke='none'/%3E%3Ccircle cx='12' cy='9.5' r='0.6' fill='%23000' stroke='none'/%3E%3Ccircle cx='15' cy='9.5' r='0.6' fill='%23000' stroke='none'/%3E%3C/svg%3E")}
.ms-ico-menu{-webkit-mask-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M4 7h16'/%3E%3Cpath d='M4 12h16'/%3E%3Cpath d='M4 17h16'/%3E%3C/svg%3E");mask-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M4 7h16'/%3E%3Cpath d='M4 12h16'/%3E%3Cpath d='M4 17h16'/%3E%3C/svg%3E")}

.ms-ico-activity{-webkit-mask-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M3 12h4l2.5 7 5-14 2.5 7h4'/%3E%3C/svg%3E");mask-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M3 12h4l2.5 7 5-14 2.5 7h4'/%3E%3C/svg%3E")}
.ms-ico-map{-webkit-mask-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M12 21s-6-5.4-6-10a6 6 0 0 1 12 0c0 4.6-6 10-6 10z'/%3E%3Ccircle cx='12' cy='11' r='2.3'/%3E%3C/svg%3E");mask-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M12 21s-6-5.4-6-10a6 6 0 0 1 12 0c0 4.6-6 10-6 10z'/%3E%3Ccircle cx='12' cy='11' r='2.3'/%3E%3C/svg%3E")}
.ms-ico-crew{-webkit-mask-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='8.5' cy='8' r='3'/%3E%3Cpath d='M3 19v-1a4.5 4.5 0 0 1 4.5-4.5h2A4.5 4.5 0 0 1 14 18v1'/%3E%3Cpath d='M16 5.2a3 3 0 0 1 0 5.6'/%3E%3Cpath d='M17.5 13.6A4 4 0 0 1 21 17.5V19'/%3E%3C/svg%3E");mask-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='8.5' cy='8' r='3'/%3E%3Cpath d='M3 19v-1a4.5 4.5 0 0 1 4.5-4.5h2A4.5 4.5 0 0 1 14 18v1'/%3E%3Cpath d='M16 5.2a3 3 0 0 1 0 5.6'/%3E%3Cpath d='M17.5 13.6A4 4 0 0 1 21 17.5V19'/%3E%3C/svg%3E")}
.ms-ico-plus{-webkit-mask-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M12 5v14'/%3E%3Cpath d='M5 12h14'/%3E%3C/svg%3E");mask-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M12 5v14'/%3E%3Cpath d='M5 12h14'/%3E%3C/svg%3E")}
.ms-ico-wrench{-webkit-mask-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M14.7 6.3a1 1 0 0 0 0 1.4l1.6 1.6a1 1 0 0 0 1.4 0l3.77-3.77a6 6 0 0 1-7.94 7.94l-6.91 6.91a2.12 2.12 0 0 1-3-3l6.91-6.91a6 6 0 0 1 7.94-7.94l-3.76 3.76z'/%3E%3C/svg%3E");mask-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M14.7 6.3a1 1 0 0 0 0 1.4l1.6 1.6a1 1 0 0 0 1.4 0l3.77-3.77a6 6 0 0 1-7.94 7.94l-6.91 6.91a2.12 2.12 0 0 1-3-3l6.91-6.91a6 6 0 0 1 7.94-7.94l-3.76 3.76z'/%3E%3C/svg%3E")}
.ms-ico-boxes{-webkit-mask-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M21 8.2v7.6a1 1 0 0 1-.5.87l-8 4.55a1 1 0 0 1-1 0l-8-4.55a1 1 0 0 1-.5-.87V8.2a1 1 0 0 1 .5-.87l8-4.55a1 1 0 0 1 1 0l8 4.55a1 1 0 0 1 .5.87z'/%3E%3Cpath d='M3.3 7.7 12 12.6l8.7-4.9'/%3E%3Cpath d='M12 12.6V21.5'/%3E%3C/svg%3E");mask-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M21 8.2v7.6a1 1 0 0 1-.5.87l-8 4.55a1 1 0 0 1-1 0l-8-4.55a1 1 0 0 1-.5-.87V8.2a1 1 0 0 1 .5-.87l8-4.55a1 1 0 0 1 1 0l8 4.55a1 1 0 0 1 .5.87z'/%3E%3Cpath d='M3.3 7.7 12 12.6l8.7-4.9'/%3E%3Cpath d='M12 12.6V21.5'/%3E%3C/svg%3E")}
.ms-ico-bag{-webkit-mask-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 2 3.5 6v13.5a1.5 1.5 0 0 0 1.5 1.5h14a1.5 1.5 0 0 0 1.5-1.5V6L18 2z'/%3E%3Cpath d='M3.5 6h17'/%3E%3Cpath d='M16 10a4 4 0 0 1-8 0'/%3E%3C/svg%3E");mask-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 2 3.5 6v13.5a1.5 1.5 0 0 0 1.5 1.5h14a1.5 1.5 0 0 0 1.5-1.5V6L18 2z'/%3E%3Cpath d='M3.5 6h17'/%3E%3Cpath d='M16 10a4 4 0 0 1-8 0'/%3E%3C/svg%3E")}

/* Quick-add popover (the topbar "+" — fast field capture) */
.ms-qa-pop{position:fixed;top:calc(var(--topbar-h) + 4px);right:8px;z-index:180;background:var(--surface);border:1px solid var(--border);border-radius:12px;box-shadow:0 12px 32px rgba(0,0,0,.18);padding:6px;display:flex;flex-direction:column;gap:2px;min-width:250px;max-width:calc(100vw - 16px)}
.ms-qa-item{display:flex;align-items:center;gap:11px;padding:10px 12px;background:none;border:0;border-radius:9px;cursor:pointer;text-align:left;color:var(--ink);width:100%;min-height:48px}
.ms-qa-item:hover,.ms-qa-item:focus{background:var(--surface-2);outline:none}
.ms-qa-item .ic{font-size:22px;flex:0 0 auto;line-height:1}
.ms-qa-item .tx b{display:block;font-size:14px;font-weight:700}
.ms-qa-item .tx small{display:block;font-size:12px;color:var(--muted);margin-top:1px}

/* Pull-to-refresh indicator (touch) */
#ms-ptr{position:fixed;top:0;left:50%;transform:translateX(-50%);z-index:150;display:none;align-items:center;gap:7px;padding:7px 14px;background:var(--surface);border:1px solid var(--border);border-radius:999px;box-shadow:var(--shadow-sm);font-size:12px;font-weight:700;color:var(--muted);pointer-events:none;white-space:nowrap}
#ms-ptr.show{display:inline-flex}
#ms-ptr.armed{color:var(--ink)}
#ms-ptr .ico{font-size:14px;display:inline-block}
#ms-ptr.busy .ico{animation:ms-ptr-spin .8s linear infinite}
@keyframes ms-ptr-spin{to{transform:rotate(360deg)}}

/* ============================================================================
 * Contour shell — persistent left rail (desktop/tablet), grouped section nav,
 * command search, company chip, and the crew bottom tab bar (phones).
 * The rail is the primary desktop nav; the slide-out drawer (above) stays as
 * the phone/tablet nav so nothing is lost on small screens.
 * ========================================================================== */
:root {
  --rail-w: 236px;
  --shadow-lg: 0 10px 40px rgba(28,66,99,.20), 0 2px 8px rgba(28,66,99,.10);
  --tabbar-h: 60px;
}

/* -- rail ------------------------------------------------------------------ */
.ms-rail {
  position: fixed; top: 0; left: 0; bottom: 0; width: var(--rail-w); z-index: 60;
  background: linear-gradient(180deg, var(--shell), var(--shell-2));
  color: #fff; display: none; flex-direction: column;
  box-shadow: 1px 0 0 rgba(255,255,255,.06), 4px 0 24px rgba(0,0,0,.22);
}
.ms-rail .rail-top { padding: 14px 14px 10px; display: flex; align-items: center; gap: 10px; }
/* The home link takes the room left over once the toggle has its 34px, so the
   two can never collide however wide the rail is. */
.ms-rail .rail-home { flex: 1 1 auto; min-width: 0; display: block; border-radius: 8px; padding: 2px; margin: -2px; }
.ms-rail .rail-home:hover { background: rgba(255,255,255,.08); text-decoration: none; }
.ms-rail .rail-home:focus-visible { outline: 2px solid var(--brand); outline-offset: 1px; }
.ms-rail .rail-top img.rail-logo { width: 100%; max-width: 100%; height: auto; display: block; }
.ms-rail .rail-search {
  margin: 2px 12px 10px; display: flex; align-items: center; gap: 8px;
  background: rgba(255,255,255,.09); border: 1px solid rgba(255,255,255,.14);
  border-radius: 9px; padding: 8px 10px; cursor: pointer; color: var(--steel-3);
  font-size: 13px; min-height: 40px; width: calc(100% - 24px);
  text-align: left; font-family: inherit;
}
.ms-rail .rail-search:hover { background: rgba(255,255,255,.15); }
.ms-rail .rail-search .kbd {
  margin-left: auto; font-size: 10.5px; font-weight: 700; letter-spacing: .04em;
  border: 1px solid rgba(255,255,255,.22); border-radius: 5px; padding: 1px 5px; color: var(--steel-2);
}
.ms-rail .rail-scroll { flex: 1; overflow-y: auto; padding: 2px 0 10px; -webkit-overflow-scrolling: touch; }
.ms-rail .rail-group {
  padding: 14px 18px 5px; font-size: 10.5px; font-weight: 800; letter-spacing: .12em;
  text-transform: uppercase; color: rgba(255,255,255,.42);
}
.ms-rail a.rail-link {
  display: flex; align-items: center; gap: 11px; min-height: 38px;
  padding: 7px 16px 7px 18px; color: #dbe4ee; text-decoration: none;
  font-size: 14px; font-weight: 500; border-left: 3px solid transparent;
}
.ms-rail a.rail-link:hover { background: rgba(255,255,255,.07); color: #fff; text-decoration: none; }
.ms-rail a.rail-link.active {
  background: rgba(255,255,255,.12); color: #fff; font-weight: 700;
  border-left-color: var(--brand);
}
.ms-rail a.rail-link .ms-ico { width: 17px; height: 17px; flex: none; opacity: .85; }
.ms-rail a.rail-link.active .ms-ico { opacity: 1; }
.ms-rail .rail-count {
  margin-left: auto; min-width: 19px; height: 19px; padding: 0 5px; border-radius: 999px;
  background: var(--brand); color: #fff; font-size: 11px; font-weight: 800;
  line-height: 19px; text-align: center;
}
.ms-rail .rail-count.quiet { background: rgba(255,255,255,.18); color: #e7eef6; }
.ms-rail .rail-foot {
  border-top: 1px solid rgba(255,255,255,.12); padding: 11px 14px;
  display: flex; align-items: center; gap: 10px; font-size: 12.5px; color: var(--steel-2);
}
.ms-rail .rail-foot .co {
  width: 30px; height: 30px; border-radius: 8px; flex: none;
  background: rgba(255,255,255,.12); display: flex; align-items: center; justify-content: center;
  font-family: var(--font-cond); font-weight: 800; color: #fff; font-size: 13px;
}
.ms-rail .rail-foot .co-name { display: block; color: #fff; font-weight: 700; font-size: 13px; line-height: 1.2; }
.ms-rail .rail-foot .co-sub { display: block; color: var(--steel-2); font-size: 11.5px; line-height: 1.2; }

/* Rail on wide screens: show it, inset the page, and drop the redundant topbar
   hamburger (the drawer stays reachable on narrow screens). */
@media (min-width: 1080px) {
  body.ms-has-rail .ms-rail { display: flex; }
  body.ms-has-rail { padding-left: var(--rail-w); }
  body.ms-has-rail header.topbar { padding-left: 18px; }
  body.ms-has-rail header.topbar a.home { display: none; }
  body.ms-has-rail #ms-navbtn { display: none; }
}

/* -- crew bottom tab bar (phones) ----------------------------------------- */
.ms-tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 70;
  display: none; align-items: stretch;
  background: var(--surface); border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom, 0);
  box-shadow: 0 -2px 14px rgba(0,0,0,.12);
}
.ms-tabbar a, .ms-tabbar button {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 3px; min-height: var(--tabbar-h); border: 0; background: none; cursor: pointer;
  color: var(--muted); font: inherit; font-size: 10.5px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .04em; text-decoration: none;
}
.ms-tabbar a.active { color: var(--shell); }
.ms-tabbar a.active .ms-ico { opacity: 1; }
.ms-tabbar .ms-ico { width: 21px; height: 21px; opacity: .7; }
.ms-tabbar .tab-count {
  position: absolute; transform: translate(14px, -10px);
  min-width: 16px; height: 16px; padding: 0 4px; border-radius: 999px;
  background: var(--brand); color: #fff; font-size: 10px; line-height: 16px; text-align: center;
}
@media (max-width: 700px) {
  body.ms-crew-tabs .ms-tabbar { display: flex; }
  body.ms-crew-tabs .page { padding-bottom: calc(var(--tabbar-h) + 26px); }
}

/* -- command palette (Ctrl/Cmd-K) ---------------------------------------- */
.ms-cmd-bg {
  position: fixed; inset: 0; z-index: 120; background: rgba(0,0,0,.42);
  display: none; align-items: flex-start; justify-content: center; padding: 10vh 16px 16px;
  backdrop-filter: blur(2px);
}
.ms-cmd-bg.open { display: flex; }
.ms-cmd {
  width: 100%; max-width: 560px; background: var(--surface);
  border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow-lg);
  overflow: hidden; display: flex; flex-direction: column; max-height: 70vh;
}
.ms-cmd input {
  border: 0; border-bottom: 1px solid var(--border); padding: 15px 17px;
  font: inherit; font-size: 16px; outline: none; color: var(--text); background: var(--surface);
}
.ms-cmd .ms-cmd-list { overflow-y: auto; padding: 6px; }
.ms-cmd .ms-cmd-item {
  display: flex; align-items: center; gap: 11px; padding: 10px 12px; border-radius: 9px;
  cursor: pointer; color: var(--text); text-decoration: none; min-height: 44px;
}
.ms-cmd .ms-cmd-item:hover, .ms-cmd .ms-cmd-item.sel { background: var(--surface-2); text-decoration: none; }
.ms-cmd .ms-cmd-item .grp { margin-left: auto; font-size: 11px; color: var(--faint); text-transform: uppercase; letter-spacing: .06em; }
.ms-cmd .ms-cmd-empty { padding: 22px 16px; text-align: center; color: var(--muted); font-size: 14px; }

/* Contour section icons (rail + tab bar) */
.ms-ico-check{-webkit-mask-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M4.5 12.5 9.5 17.5 19.5 6.5'/%3E%3C/svg%3E");mask-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M4.5 12.5 9.5 17.5 19.5 6.5'/%3E%3C/svg%3E")}
.ms-ico-lead{-webkit-mask-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6.2 3.8h3l1.6 4-2 1.4a12 12 0 0 0 5.9 5.9l1.4-2 4 1.6v3a1.8 1.8 0 0 1-2 1.8A16.5 16.5 0 0 1 4.4 5.8a1.8 1.8 0 0 1 1.8-2z'/%3E%3C/svg%3E");mask-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6.2 3.8h3l1.6 4-2 1.4a12 12 0 0 0 5.9 5.9l1.4-2 4 1.6v3a1.8 1.8 0 0 1-2 1.8A16.5 16.5 0 0 1 4.4 5.8a1.8 1.8 0 0 1 1.8-2z'/%3E%3C/svg%3E")}
.ms-ico-estimate{-webkit-mask-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='4.5' y='3.5' width='15' height='17' rx='2'/%3E%3Cpath d='M8 8h8'/%3E%3Cpath d='M8 12h8'/%3E%3Cpath d='M8 16h5'/%3E%3C/svg%3E");mask-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='4.5' y='3.5' width='15' height='17' rx='2'/%3E%3Cpath d='M8 8h8'/%3E%3Cpath d='M8 12h8'/%3E%3Cpath d='M8 16h5'/%3E%3C/svg%3E")}
.ms-ico-dollar{-webkit-mask-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M12 3.5v17'/%3E%3Cpath d='M16 7.5H10a2.75 2.75 0 0 0 0 5.5h4a2.75 2.75 0 0 1 0 5.5H8'/%3E%3C/svg%3E");mask-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M12 3.5v17'/%3E%3Cpath d='M16 7.5H10a2.75 2.75 0 0 0 0 5.5h4a2.75 2.75 0 0 1 0 5.5H8'/%3E%3C/svg%3E")}
.ms-ico-truck{-webkit-mask-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M2.5 6.5h10v9h-10z'/%3E%3Cpath d='M12.5 10h3.6l2.9 3v2.5h-6.5z'/%3E%3Ccircle cx='7' cy='18' r='1.8'/%3E%3Ccircle cx='16.5' cy='18' r='1.8'/%3E%3C/svg%3E");mask-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M2.5 6.5h10v9h-10z'/%3E%3Cpath d='M12.5 10h3.6l2.9 3v2.5h-6.5z'/%3E%3Ccircle cx='7' cy='18' r='1.8'/%3E%3Ccircle cx='16.5' cy='18' r='1.8'/%3E%3C/svg%3E")}
.ms-ico-people{-webkit-mask-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='9' cy='8' r='3.2'/%3E%3Cpath d='M3.5 19.5c0-3 2.5-5 5.5-5s5.5 2 5.5 5'/%3E%3Cpath d='M16 5.4a3.2 3.2 0 0 1 0 5.2'/%3E%3Cpath d='M17.5 14.9c1.9.6 3.2 2.3 3.2 4.6'/%3E%3C/svg%3E");mask-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='9' cy='8' r='3.2'/%3E%3Cpath d='M3.5 19.5c0-3 2.5-5 5.5-5s5.5 2 5.5 5'/%3E%3Cpath d='M16 5.4a3.2 3.2 0 0 1 0 5.2'/%3E%3Cpath d='M17.5 14.9c1.9.6 3.2 2.3 3.2 4.6'/%3E%3C/svg%3E")}
.ms-ico-clock{-webkit-mask-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='8.5'/%3E%3Cpath d='M12 7v5.2l3.4 2'/%3E%3C/svg%3E");mask-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='8.5'/%3E%3Cpath d='M12 7v5.2l3.4 2'/%3E%3C/svg%3E")}
.ms-ico-calendar{-webkit-mask-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='3.5' y='5' width='17' height='15' rx='2'/%3E%3Cpath d='M3.5 9.5h17'/%3E%3Cpath d='M8 3v4'/%3E%3Cpath d='M16 3v4'/%3E%3C/svg%3E");mask-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='3.5' y='5' width='17' height='15' rx='2'/%3E%3Cpath d='M3.5 9.5h17'/%3E%3Cpath d='M8 3v4'/%3E%3Cpath d='M16 3v4'/%3E%3C/svg%3E")}
.ms-ico-receipt{-webkit-mask-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 3.5h12v17l-2.4-1.6-2.4 1.6-2.4-1.6L8.4 20.5 6 18.9z'/%3E%3Cpath d='M9 8h6'/%3E%3Cpath d='M9 12h6'/%3E%3C/svg%3E");mask-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 3.5h12v17l-2.4-1.6-2.4 1.6-2.4-1.6L8.4 20.5 6 18.9z'/%3E%3Cpath d='M9 8h6'/%3E%3Cpath d='M9 12h6'/%3E%3C/svg%3E")}
.ms-ico-pricetag{-webkit-mask-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M11.2 3.5H20v8.8l-8.7 8.7a1.6 1.6 0 0 1-2.3 0l-6.5-6.5a1.6 1.6 0 0 1 0-2.3z'/%3E%3Ccircle cx='16.3' cy='7.7' r='1.4'/%3E%3C/svg%3E");mask-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M11.2 3.5H20v8.8l-8.7 8.7a1.6 1.6 0 0 1-2.3 0l-6.5-6.5a1.6 1.6 0 0 1 0-2.3z'/%3E%3Ccircle cx='16.3' cy='7.7' r='1.4'/%3E%3C/svg%3E")}
.ms-ico-customers{-webkit-mask-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M4 20.5V6.2l7-2.7 7 2.7v14.3'/%3E%3Cpath d='M2.5 20.5h19'/%3E%3Cpath d='M8.5 20.5v-4.6h5v4.6'/%3E%3Cpath d='M8.5 9h2'/%3E%3Cpath d='M13.5 9h2'/%3E%3Cpath d='M8.5 12.5h2'/%3E%3Cpath d='M13.5 12.5h2'/%3E%3C/svg%3E");mask-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M4 20.5V6.2l7-2.7 7 2.7v14.3'/%3E%3Cpath d='M2.5 20.5h19'/%3E%3Cpath d='M8.5 20.5v-4.6h5v4.6'/%3E%3Cpath d='M8.5 9h2'/%3E%3Cpath d='M13.5 9h2'/%3E%3Cpath d='M8.5 12.5h2'/%3E%3Cpath d='M13.5 12.5h2'/%3E%3C/svg%3E")}
.ms-ico-field{-webkit-mask-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M3.5 14.5a8.5 8.5 0 0 1 17 0z'/%3E%3Cpath d='M2.5 14.5h19'/%3E%3Cpath d='M12 6V3.5'/%3E%3Cpath d='M9 20.5h6'/%3E%3C/svg%3E");mask-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M3.5 14.5a8.5 8.5 0 0 1 17 0z'/%3E%3Cpath d='M2.5 14.5h19'/%3E%3Cpath d='M12 6V3.5'/%3E%3Cpath d='M9 20.5h6'/%3E%3C/svg%3E")}
.ms-ico-search{-webkit-mask-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='11' cy='11' r='6.5'/%3E%3Cpath d='M15.8 15.8 20.5 20.5'/%3E%3C/svg%3E");mask-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='11' cy='11' r='6.5'/%3E%3Cpath d='M15.8 15.8 20.5 20.5'/%3E%3C/svg%3E")}
.ms-ico-project{-webkit-mask-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='3.5' y='4.5' width='17' height='15' rx='2'/%3E%3Cpath d='M3.5 9h17'/%3E%3Cpath d='M9 13h6'/%3E%3C/svg%3E");mask-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='3.5' y='4.5' width='17' height='15' rx='2'/%3E%3Cpath d='M3.5 9h17'/%3E%3Cpath d='M9 13h6'/%3E%3C/svg%3E")}

/* Drawer group headings + badges (the phone nav renders the same NAV_GROUPS) */
.ms-nav-drawer .ms-nav-group {
  padding: 14px 18px 4px; font-size: 10.5px; font-weight: 800; letter-spacing: .12em;
  text-transform: uppercase; color: rgba(255,255,255,.42);
}
.ms-nav-drawer .ms-nav-count {
  margin-left: auto; min-width: 19px; height: 19px; padding: 0 5px; border-radius: 999px;
  background: var(--brand); color: #fff; font-size: 11px; font-weight: 800;
  line-height: 19px; text-align: center;
}
.ms-nav-drawer a.link { position: relative; }
.ms-tabbar a { position: relative; }

/* ============================================================================
 * Contour page kit — the shared furniture every new Contour page is built from
 * (KPI strip, tab strip, split list/detail, data table, stage rail, pill chips).
 * Pages reach for these instead of inventing per-page CSS, so the app keeps one
 * look as it grows.
 * ========================================================================== */
.ms-sub { color: var(--muted); font-size: 13.5px; margin: -6px 0 14px; }

/* KPI strip */
.ms-kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 10px; margin-bottom: 16px; }
.ms-kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 12px 14px; box-shadow: var(--shadow-sm); }
.ms-kpi .k { font-size: 10.5px; font-weight: 800; letter-spacing: .1em; text-transform: uppercase; color: var(--faint); }
.ms-kpi .v { font-family: var(--font-cond); font-weight: 800; font-size: 25px; line-height: 1.15; margin-top: 3px; }
.ms-kpi .s { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.ms-kpi.warn { border-left: 4px solid var(--st-yellow); }
.ms-kpi.bad  { border-left: 4px solid var(--st-red); }
.ms-kpi.good { border-left: 4px solid var(--st-green); }

/* Tab strip */
.ms-tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.ms-tabs button {
  border: 0; background: none; font: inherit; font-weight: 700; font-size: 14px; cursor: pointer;
  color: var(--muted); padding: 10px 13px; min-height: 44px; white-space: nowrap;
  border-bottom: 2.5px solid transparent; margin-bottom: -1px;
}
.ms-tabs button:hover { color: var(--text); }
.ms-tabs button.on { color: var(--shell); border-bottom-color: var(--brand); }
.ms-tabs button .n {
  display: inline-block; min-width: 18px; margin-left: 6px; padding: 0 5px; border-radius: 999px;
  background: var(--surface-2); border: 1px solid var(--border); color: var(--muted);
  font-size: 11px; line-height: 16px; text-align: center;
}
.ms-tabs button.on .n { background: var(--brand); border-color: var(--brand); color: #fff; }

/* Split: scrolling record list beside a detail panel */
.ms-split { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr); gap: 14px; align-items: start; }
@media (max-width: 1180px) { .ms-split { grid-template-columns: 1fr; } }
.ms-panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-sm); overflow: hidden; }
.ms-panel > header { display: flex; align-items: center; gap: 10px; padding: 12px 15px; border-bottom: 1px solid var(--border); }
.ms-panel > header h2 { margin: 0; font-size: 15px; text-transform: uppercase; letter-spacing: .03em; }
.ms-panel > header .spacer { flex: 1; }
.ms-panel .pad { padding: 14px 15px; }

/* Record rows */
.ms-rec { display: flex; align-items: center; gap: 12px; padding: 12px 15px; border-bottom: 1px solid var(--border); cursor: pointer; min-height: 56px; }
.ms-rec:last-child { border-bottom: 0; }
.ms-rec:hover { background: var(--surface-2); }
.ms-rec.on { background: var(--st-blue-t); box-shadow: inset 3px 0 0 var(--accent); }
.ms-rec .av { width: 36px; height: 36px; border-radius: 9px; flex: none; background: var(--shell); color: #fff; display: flex; align-items: center; justify-content: center; font-family: var(--font-cond); font-weight: 800; font-size: 13px; }
.ms-rec .bd { min-width: 0; flex: 1; }
.ms-rec .t { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ms-rec .m { font-size: 12.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ms-rec .r { text-align: right; flex: none; }
.ms-rec .r .amt { font-weight: 800; font-variant-numeric: tabular-nums; }

/* Data table */
.ms-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.ms-table th {
  text-align: left; font-size: 10.5px; font-weight: 800; letter-spacing: .09em; text-transform: uppercase;
  color: var(--faint); padding: 9px 12px; border-bottom: 1px solid var(--border); white-space: nowrap;
}
.ms-table td { padding: 11px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.ms-table tbody tr:last-child td { border-bottom: 0; }
.ms-table tbody tr.click { cursor: pointer; }
.ms-table tbody tr.click:hover { background: var(--surface-2); }
.ms-table td.num, .ms-table th.num { text-align: right; font-variant-numeric: tabular-nums; }
.ms-table .sub { font-size: 12px; color: var(--muted); }
.ms-tablewrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* Pills */
.ms-pill { display: inline-flex; align-items: center; gap: 5px; font-size: 10.5px; font-weight: 800; letter-spacing: .04em; text-transform: uppercase; padding: 3px 9px; border-radius: 999px; white-space: nowrap; }
.p-ok       { background: var(--st-green-t); color: #0d6b3d; }
.p-warn     { background: var(--st-yellow-t); color: #8a5a00; }
.p-bad      { background: var(--st-red-t);   color: #a11e1e; }
.p-info     { background: var(--st-blue-t);  color: #1d5580; }
.p-quiet    { background: var(--st-gray-t);  color: var(--muted); }
.p-orange   { background: var(--brand-t);   color: #a34300; }

/* Stage rail (estimate steps, billing flow, sync pipeline) */
.ms-steps { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.ms-steps .st { display: flex; align-items: center; gap: 8px; padding: 8px 13px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface); font-size: 13px; font-weight: 600; color: var(--muted); min-height: 40px; }
.ms-steps .st .n { width: 20px; height: 20px; border-radius: 50%; background: var(--surface-2); border: 1px solid var(--border-2); display: flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 800; }
.ms-steps .st.on { border-color: var(--shell); color: var(--shell); background: #fff; box-shadow: var(--shadow-sm); }
.ms-steps .st.on .n { background: var(--shell); border-color: var(--shell); color: #fff; }
.ms-steps .st.done { color: var(--ok); border-color: var(--st-green); }
.ms-steps .st.done .n { background: var(--st-green); border-color: var(--st-green); color: #fff; }
.ms-steps button.st { cursor: pointer; font-family: inherit; }

/* Banner: the one thing on this page that needs a decision */
.ms-banner { display: flex; align-items: center; gap: 12px; padding: 13px 16px; border-radius: var(--radius-lg); border: 1px solid var(--border); background: var(--surface); box-shadow: var(--shadow-sm); margin-bottom: 14px; border-left: 4px solid var(--brand); }
.ms-banner.bad { border-left-color: var(--st-red); }
.ms-banner.info { border-left-color: var(--accent); }
.ms-banner .bd { flex: 1; min-width: 0; }
.ms-banner .bd b { display: block; }
.ms-banner .bd span { font-size: 13px; color: var(--muted); }

/* QuickBooks connection strip — used everywhere money crosses the boundary */
.ms-qb { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; padding: 12px 15px; border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--surface-2); margin-top: 16px; }
.ms-qb .qb-mark { width: 30px; height: 30px; border-radius: 8px; background: #2ca01c; color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 800; font-size: 12px; flex: none; }
.ms-qb .qb-t { font-weight: 700; }
.ms-qb .qb-s { font-size: 12.5px; color: var(--muted); }
.ms-qb .qb-facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px 18px; width: 100%; }
.ms-qb .qb-facts div span { display: block; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--faint); }
.ms-qb .qb-facts div b { font-size: 13.5px; }

/* Definition grid used in detail panels */
.ms-dl { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px 16px; }
.ms-dl > div span { display: block; font-size: 10.5px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; color: var(--faint); }
.ms-dl > div b { font-weight: 700; font-size: 14px; }
.ms-empty { color: var(--faint); text-align: center; padding: 28px 12px; font-size: 14px; }
.ms-note { font-size: 12.5px; color: var(--muted); line-height: 1.5; }
.ms-searchbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.ms-searchbar input[type=search], .ms-searchbar input[type=text] { flex: 1; min-width: 180px; }
.ms-chips { display: flex; gap: 6px; flex-wrap: wrap; }
.ms-chip { border: 1px solid var(--border-2); background: var(--surface); border-radius: 999px; padding: 6px 12px; font: inherit; font-size: 13px; font-weight: 600; color: var(--muted); cursor: pointer; min-height: 36px; }
.ms-chip.on { background: var(--shell); border-color: var(--shell); color: #fff; }
@media (pointer: coarse) { .ms-chip { min-height: 44px; } }

/* ============================================================================
 * Scroll surfaces.
 *
 * Windows paints a permanent 17px classic scrollbar on any element with
 * overflow:auto, even when nothing overflows — which is what put a fat grey bar
 * under the tab strip and beside every panel. Three rules fix it everywhere:
 *
 *   1. Anything that scrolls only to rescue a narrow screen (tab strips, chip
 *      rows, the board's column strip) hides its bar entirely and stays
 *      swipeable/keyboard-scrollable.
 *   2. Anything that genuinely scrolls (tables, drawers, long lists) gets a
 *      thin bar tinted to the UI instead of the OS default.
 *   3. Nothing scrolls that does not need to: table wrappers only become
 *      scrollable when their content is actually wider than the panel.
 * ========================================================================== */

/* -- 1. utility scrollers: keep the scrolling, drop the furniture ---------- */
.ms-tabs,
.ms-chips,
.ms-searchbar,
.board,
.cardgrid,
.ms-rail .rail-scroll,
.ms-nav-drawer,
.ms-scroll-quiet {
  scrollbar-width: none;              /* Firefox */
  -ms-overflow-style: none;           /* legacy Edge */
}
.ms-tabs::-webkit-scrollbar,
.ms-chips::-webkit-scrollbar,
.ms-searchbar::-webkit-scrollbar,
.board::-webkit-scrollbar,
.cardgrid::-webkit-scrollbar,
.ms-rail .rail-scroll::-webkit-scrollbar,
.ms-nav-drawer::-webkit-scrollbar,
.ms-scroll-quiet::-webkit-scrollbar { width: 0; height: 0; display: none; }

/* A tab strip that has been scrolled should hint that there is more, without a
   scrollbar: fade the trailing edge. */
.ms-tabs { position: relative; -webkit-mask-image: linear-gradient(90deg, #000 calc(100% - 22px), transparent); mask-image: linear-gradient(90deg, #000 calc(100% - 22px), transparent); }
@media (min-width: 700px) { .ms-tabs { -webkit-mask-image: none; mask-image: none; } }

/* -- 2. real scrollers: thin, tinted, out of the way ---------------------- */
.ms-tablewrap,
.ms-cmd-list,
.modal,
.ck-mem-list,
.ms-panel .pad,
textarea {
  scrollbar-width: thin;
  scrollbar-color: var(--border-2) transparent;
}
.ms-tablewrap::-webkit-scrollbar,
.ms-cmd-list::-webkit-scrollbar,
.modal::-webkit-scrollbar,
.ck-mem-list::-webkit-scrollbar,
textarea::-webkit-scrollbar { width: 9px; height: 9px; }
.ms-tablewrap::-webkit-scrollbar-track,
.ms-cmd-list::-webkit-scrollbar-track,
.modal::-webkit-scrollbar-track,
.ck-mem-list::-webkit-scrollbar-track,
textarea::-webkit-scrollbar-track { background: transparent; }
.ms-tablewrap::-webkit-scrollbar-thumb,
.ms-cmd-list::-webkit-scrollbar-thumb,
.modal::-webkit-scrollbar-thumb,
.ck-mem-list::-webkit-scrollbar-thumb,
textarea::-webkit-scrollbar-thumb {
  background: var(--border-2); border-radius: 999px;
  border: 2px solid transparent; background-clip: content-box;
}
.ms-tablewrap:hover::-webkit-scrollbar-thumb,
.ms-cmd-list:hover::-webkit-scrollbar-thumb,
.modal:hover::-webkit-scrollbar-thumb { background: var(--steel-2); background-clip: content-box; }

/* The page itself keeps the OS bar (people expect it) but tinted to the app. */
html { scrollbar-width: thin; scrollbar-color: var(--border-2) transparent; }
html::-webkit-scrollbar { width: 12px; }
html::-webkit-scrollbar-track { background: var(--bg); }
html::-webkit-scrollbar-thumb { background: var(--border-2); border-radius: 999px; border: 3px solid var(--bg); background-clip: content-box; }
html::-webkit-scrollbar-thumb:hover { background: var(--steel-2); background-clip: content-box; }

/* -- 3. tables only scroll when they must -------------------------------- */
/* A table that fits should not create a scroll context at all. Letting the
   table shrink to the panel and only scrolling past a sensible minimum means
   the bar appears when it is earned, and never otherwise. */
.ms-tablewrap { overflow-x: auto; overscroll-behavior-x: contain; }
.ms-table { min-width: 100%; }
@media (min-width: 700px) { .ms-table { min-width: 560px; } }

/* Tab strips wrap on a roomy screen instead of scrolling, so nothing is hidden
   behind an invisible overflow. */
@media (min-width: 700px) {
  .ms-tabs { flex-wrap: wrap; overflow-x: visible; }
}

/* ============================================================================
 * Collapsible rail.
 *
 * Expanded is the default on a wide screen. Collapsed drops to 66px of icons
 * and shows the label on hover or keyboard focus, so nothing becomes
 * unreachable — the choice is stored per user (ms-user-prefs-v1), so it
 * follows the person between the office desktop and a laptop.
 * ========================================================================== */
:root { --rail-w-collapsed: 66px; }

.ms-rail .rail-top { position: relative; align-items: center; }
.ms-rail .rail-mark { display: none; width: 34px; height: 34px; border-radius: 9px; }
.ms-rail .rail-toggle {
  width: 34px; height: 34px; min-width: 34px; flex: none;
  display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid rgba(255,255,255,.16); background: rgba(255,255,255,.06);
  border-radius: 9px; color: #fff; cursor: pointer; padding: 0;
}
.ms-rail .rail-toggle:hover { background: rgba(255,255,255,.16); }
.ms-rail .rail-toggle:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
.ms-rail .rail-toggle .ms-ico { width: 17px; height: 17px; }
@media (pointer: coarse) { .ms-rail .rail-toggle { width: 44px; height: 44px; min-width: 44px; } }

/* -- collapsed ------------------------------------------------------------ */
body.ms-rail-collapsed .ms-rail { width: var(--rail-w-collapsed); }
@media (min-width: 1080px) {
  body.ms-has-rail.ms-rail-collapsed { padding-left: var(--rail-w-collapsed); }
}
body.ms-rail-collapsed .ms-rail .rail-logo { display: none; }
body.ms-rail-collapsed .ms-rail .rail-mark { display: block; margin: 0 auto; }
body.ms-rail-collapsed .ms-rail .rail-home { flex: none; }
body.ms-rail-collapsed .ms-rail .rail-top { flex-direction: column; gap: 8px; padding: 12px 8px 8px; }
body.ms-rail-collapsed .ms-rail .rail-group { text-align: center; padding: 12px 4px 4px; font-size: 9px; letter-spacing: .06em; }
body.ms-rail-collapsed .ms-rail .rail-search {
  width: calc(100% - 16px); margin: 0 8px 10px; justify-content: center; padding: 8px 0;
}
body.ms-rail-collapsed .ms-rail .rail-search .kbd { display: none; }
/* display:none would drop the name from the accessibility tree and leave every
   collapsed item an unlabelled icon. Hide it visually instead. */
body.ms-rail-collapsed .ms-rail .rail-lbl {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0;
  overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap;
}
body.ms-rail-collapsed .ms-rail a.rail-link { justify-content: center; padding: 9px 4px; border-left-width: 3px; }

body.ms-rail-collapsed .ms-rail .rail-count {
  position: absolute; margin-left: 0; transform: translate(14px, -12px);
  min-width: 17px; height: 17px; line-height: 17px; font-size: 10px; padding: 0 4px;
}
body.ms-rail-collapsed .ms-rail a.rail-link { position: relative; }
body.ms-rail-collapsed .ms-rail .rail-foot { justify-content: center; padding: 11px 6px; }
body.ms-rail-collapsed .ms-rail .rail-foot span:not(.co) { display: none; }

/* The label returns as a tooltip on hover or keyboard focus, so a collapsed rail
   is still navigable without guessing at icons. It lives on the body, not inside
   the rail: .rail-scroll is a scroll container and would clip it. */
#ms-rail-tip {
  position: fixed; z-index: 130; pointer-events: none;
  background: var(--shell-2); color: #fff;
  font-family: var(--font-sans); font-size: 12.5px; font-weight: 600; line-height: 1.3;
  padding: 7px 11px; border-radius: 8px; white-space: nowrap;
  border: 1px solid rgba(255,255,255,.14); box-shadow: var(--shadow-lg);
  opacity: 0; transform: translateX(-4px);
  transition: opacity .12s ease, transform .12s ease;
  visibility: hidden;
}
#ms-rail-tip.on { opacity: 1; transform: none; visibility: visible; }
/* Only the collapsed rail needs them — expanded, the label is already there. */
body:not(.ms-rail-collapsed) #ms-rail-tip { display: none; }
/* Touch has no hover, and a tooltip that follows a tap is just in the way. */
@media (pointer: coarse) { #ms-rail-tip { display: none; } }
@media (prefers-reduced-motion: reduce) { #ms-rail-tip { transition: none; } }

/* Below the rail breakpoint the drawer is the nav, so the collapsed state must
   not leak into the phone layout. */
@media (max-width: 1079px) {
  body.ms-rail-collapsed .ms-rail { width: var(--rail-w); }
}

/* At 66px a group heading wraps into an unreadable stack, so the collapsed rail
   marks the boundary with a hairline instead of words. The names are still
   announced to screen readers. */
body.ms-rail-collapsed .ms-rail .rail-group {
  height: 0; padding: 0; margin: 10px 14px; overflow: hidden;
  border-top: 1px solid rgba(255,255,255,.14); color: transparent;
}
body.ms-rail-collapsed .ms-rail .rail-group:first-of-type { border-top: 0; margin-top: 4px; }

/* ============================================================================
 * Small-screen page chrome.
 *
 * The page head is a wrapping flex row: title, then actions. On a phone the
 * actions wrap to their own line, and the subtitle's negative top margin then
 * pulled it up UNDER them. Give the head its own bottom margin on narrow
 * screens, drop the negative pull, and let the actions sit as a full-width row
 * that is easy to hit.
 * ========================================================================== */
@media (max-width: 640px) {
  .page-head { margin-bottom: 10px; row-gap: 8px; }
  .page-head h1 { flex: 1 1 100%; }
  .page-head .grow { display: none; }          /* the title already took the row */
  .page-head .btn { flex: 1 1 auto; }          /* actions share the width evenly */
  .ms-sub { margin-top: 0; }
}

/* Two KPI tiles fit a phone; one per row wastes most of the screen and buries
   the content people actually came for. */
@media (max-width: 640px) {
  .ms-kpis { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 8px; }
  .ms-kpi { padding: 10px 12px; }
  .ms-kpi .v { font-size: 21px; }
  .ms-kpi .s { font-size: 11.5px; }
}
@media (max-width: 380px) {
  .ms-kpis { grid-template-columns: 1fr 1fr; }
  .ms-kpi .v { font-size: 19px; }
}

/* Detail panels and definition grids get tight on a phone. */
@media (max-width: 640px) {
  .ms-dl { grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px 12px; }
  .ms-panel .pad { padding: 12px; }
  .ms-rec { padding: 11px 12px; }
  .ms-banner { padding: 11px 12px; flex-wrap: wrap; }
  .ms-banner .btn { width: 100%; }
}

/* ============================================================================
 * Tables on a phone.
 *
 * A six-column financial table at 375px is either unreadable or a sideways
 * scroll hunt. Below 640px each row becomes a card: the first column is the
 * title, every other cell shows its column name beside the value. Nothing is
 * hidden and nothing needs horizontal scrolling.
 * ========================================================================== */
@media (max-width: 640px) {
  .ms-tablewrap { overflow-x: visible; }
  .ms-table { min-width: 0; display: block; }
  .ms-table thead { display: none; }
  .ms-table tbody, .ms-table tr, .ms-table td { display: block; width: auto; }

  .ms-table tbody tr {
    border: 1px solid var(--border); border-radius: var(--radius);
    padding: 11px 12px; margin: 0 0 8px; background: var(--surface);
  }
  .ms-table tbody tr:last-child { margin-bottom: 0; }
  .ms-table tbody tr.click:active { background: var(--surface-2); }

  .ms-table td {
    border: 0; padding: 4px 0;
    display: flex; align-items: baseline; justify-content: space-between; gap: 12px;
    text-align: right;
  }
  .ms-table td::before {
    content: attr(data-label);
    flex: none; text-align: left;
    font-size: 10.5px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase;
    color: var(--faint);
  }
  /* The lead cell is the card's heading: no label, full width, left aligned. */
  .ms-table td.cell-lead {
    display: block; text-align: left; padding: 0 0 6px;
    border-bottom: 1px solid var(--border); margin-bottom: 6px;
  }
  .ms-table td.cell-lead::before { content: none; }
  /* An action cell (no column name) spans and sits right. */
  .ms-table td.cell-actions { justify-content: flex-end; padding-top: 8px; }
  .ms-table td.cell-actions::before { content: none; }
  /* A cell with nothing in it is noise on a card. */
  .ms-table td:empty { display: none; }
  .ms-table td .sub { display: block; text-align: right; }
  .ms-table td.cell-lead .sub { text-align: left; }
}

@media (max-width: 640px) {
  /* A long secondary line (an invoice summary, an address) should take its own
     row rather than squeeze into the value column. */
  .ms-table td { flex-wrap: wrap; }
  .ms-table td .sub { flex: 1 0 100%; text-align: right; margin-top: 2px; }
  .ms-table td.cell-lead .sub { flex: none; text-align: left; }
}

/* Touch devices: anything tappable clears 44px. The board's Move control, the
   small × buttons on cards and bare selects were all under it, which is a real
   problem for someone wearing gloves on a jobsite. */
@media (pointer: coarse) {
  select,
  input[type="date"], input[type="time"], input[type="number"],
  .jcard select,
  .ms-chip,
  button.btn-sm,
  a.btn-sm { min-height: 44px; }
  .ms-tabs button { min-height: 46px; }
  /* Tiny icon buttons (×, ✎) get a real hit area without growing visually. */
  button.btn-ghost, .modal-x { min-width: 44px; min-height: 44px; }
}

/* ============================================================================
 * Board zoom control + drag-to-scroll.
 * ========================================================================== */
.ms-zoom { display: inline-flex; align-items: center; border: 1px solid var(--border-2); border-radius: var(--radius-sm); overflow: hidden; background: var(--surface); }
.ms-zoom button { border: 0; background: none; font: inherit; cursor: pointer; color: var(--text); min-height: 32px; padding: 0 10px; }
.ms-zoom .zbtn { font-size: 16px; font-weight: 700; line-height: 1; width: 32px; padding: 0; }
.ms-zoom .zlbl { font-size: 12.5px; font-weight: 700; font-variant-numeric: tabular-nums; min-width: 50px; border-left: 1px solid var(--border); border-right: 1px solid var(--border); color: var(--muted); }
.ms-zoom button:hover { background: var(--surface-2); }
.ms-zoom button:focus-visible { outline: 2px solid var(--brand); outline-offset: -2px; }
@media (pointer: coarse) { .ms-zoom button { min-height: 44px; } .ms-zoom .zbtn { width: 44px; } }

/* Drag to scroll. The grab cursor only appears where a drag would actually pan —
   over a card or a control the pointer keeps its normal meaning. */
.ms-pannable { cursor: grab; }
.ms-pannable:active { cursor: grabbing; }
.ms-pannable a, .ms-pannable button, .ms-pannable select, .ms-pannable input,
.ms-pannable textarea, .ms-pannable [draggable="true"] { cursor: auto; }
.ms-pannable [draggable="true"] { cursor: grab; }
.ms-panning { cursor: grabbing !important; user-select: none; scroll-behavior: auto; }
.ms-panning * { cursor: grabbing !important; }
/* Touch keeps native momentum scrolling; the grab cursor is meaningless there. */
@media (pointer: coarse) { .ms-pannable { cursor: auto; } }

/* ============================ Contour AI ============================
 * The ask bar and every assistant answer. One rule drives the look: a step the
 * assistant is NOT allowed to take is drawn as a draft with the approver named
 * (.needs-person), never as something that looks actionable. */
.ai-bar {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border: 1px solid var(--border); border-radius: 12px;
  background: linear-gradient(180deg, var(--surface), var(--surface-2));
  box-shadow: var(--shadow-sm, 0 1px 2px rgba(0,0,0,.05));
}
.ai-spark { color: var(--brand); font-size: 18px; line-height: 1; flex: 0 0 auto; }
.ai-field { display: flex; flex-direction: column; gap: 2px; flex: 1 1 auto; min-width: 0; }
.ai-field strong { font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
/* 16px keeps iOS from zooming the whole page when the field takes focus. */
.ai-field input { border: 0; background: transparent; font-size: 16px; color: var(--text); padding: 2px 0; width: 100%; }
.ai-field input:focus { outline: none; }
.ai-mic, .ai-bar .btn { flex: 0 0 auto; }
.ai-mic {
  width: 44px; height: 44px; border-radius: 50%; border: 1px solid var(--border-2);
  background: var(--surface); color: var(--muted); font-size: 12px; cursor: pointer;
}
.ai-mic.listening { background: var(--brand); border-color: var(--brand); color: #fff; }

.ai-out:empty { display: none; }
.ai-answer {
  margin-top: 10px; padding: 12px 14px; border: 1px solid var(--border); border-radius: 12px;
  background: var(--surface); border-left: 3px solid var(--brand);
}
.ai-answer p { margin: 0; font-size: 15px; line-height: 1.55; color: var(--text); }
.ai-thinking p { color: var(--muted); }
.ai-error { border-left-color: var(--steel-2); }
.ai-error p { color: var(--muted); }

.ai-basis { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 10px; }
.ai-basis span { font-size: 11px; letter-spacing: .06em; text-transform: uppercase; color: var(--faint); }
.ai-basis b {
  font-size: 12px; font-weight: 600; color: var(--muted);
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px; padding: 2px 9px;
}

.ai-next { list-style: none; margin: 12px 0 0; padding: 0; display: grid; gap: 6px; }
.ai-next li {
  display: flex; flex-wrap: wrap; align-items: baseline; gap: 8px;
  font-size: 14px; color: var(--text);
  padding: 8px 10px; border-radius: 9px; background: var(--surface-2);
}
.ai-next li::before { content: '→'; color: var(--muted); }
/* A step touching money, payroll, safety or anything leaving the company. */
.ai-next li.needs-person { background: var(--brand-t); }
.ai-gate {
  font-size: 12px; font-style: normal; font-weight: 600; color: var(--brand);
  width: 100%; padding-left: 18px;
}

/* The assistant's standing promise, shown wherever it is introduced. */
.ai-promise {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 12px 14px; border: 1px dashed var(--border-2); border-radius: 12px;
  background: var(--surface-2); color: var(--muted); font-size: 13px; line-height: 1.5;
}
.ai-promise b { color: var(--text); }

@media (max-width: 640px) {
  .ai-bar { flex-wrap: wrap; }
  .ai-field { order: 1; flex: 1 1 100%; }
  .ai-spark { order: 0; }
  .ai-mic, .ai-bar .btn { order: 2; }
}

/* Assistant panel (shared by the estimating, inspection and call assistants). */
.ai-assist-head { padding-right: 40px; margin-bottom: 12px; }
.ai-assist-head small { display: block; font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: var(--brand); font-weight: 700; }
.ai-assist-head h2 { margin: 4px 0 0; font-size: 20px; }
.ai-prompt textarea {
  width: 100%; border: 1px solid var(--border-2); border-radius: 10px; padding: 10px 12px;
  font: inherit; font-size: 16px; color: var(--text); background: var(--surface); resize: vertical;
}
.ai-prompt textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.ai-prompt-row { display: flex; gap: 8px; align-items: center; margin-top: 10px; flex-wrap: wrap; }
.ai-prompt-row .btn-primary { margin-left: auto; }
.ai-apply { margin-top: 12px; display: flex; justify-content: flex-end; }

/* Assistant results. */
.ai-lines { width: 100%; border-collapse: collapse; margin-top: 10px; font-size: 14px; }
.ai-lines th { text-align: left; font-size: 11px; letter-spacing: .06em; text-transform: uppercase; color: var(--faint); padding: 4px 8px 4px 0; }
.ai-lines td { padding: 6px 8px 6px 0; border-top: 1px solid var(--border); vertical-align: top; }
.ai-lines td.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.ai-facts { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.ai-facts b {
  font-size: 12px; font-weight: 600; color: var(--text);
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px; padding: 3px 10px;
}
.ai-flag {
  margin-top: 10px; padding: 8px 12px; border-radius: 9px;
  background: var(--st-red-t, #fdecec); color: var(--st-red, #b3261e); font-size: 13px; font-weight: 600;
}
.ai-conf { font-size: 12px; color: var(--muted); margin-top: 8px; }
.ai-dropped { font-size: 12px; color: var(--brand); margin-top: 6px; }

/* ============================================================================
 * MILESTONE ADDITIONS
 * Everything below is new for Milestone: the brand lockup, the company
 * switcher, the access gate, and — the part that matters — the financial
 * component kit every statement, KPI and variance screen is built from.
 * ========================================================================== */

/* ------------------------------- the mark ------------------------------- */
/* One inline SVG serves both treatments: the M inherits `color`, so it is white
   on the navy rail and navy on a light surface. The swoosh is fixed grey. */
.ms-mark { display: block; width: auto; height: 28px; flex: none; }
.topbar .home { display: flex; align-items: center; color: #fff; padding: 4px; border-radius: 8px; }
.topbar .home:hover { background: rgba(255,255,255,.08); }
.topbar .ms-mark { height: 26px; }

/* Rail header lockup: mark + wordmark set in real text, so the typography always
   matches the app (an SVG loaded through <img> cannot reach the webfonts). */
.ms-rail .rail-lockup { display: flex; align-items: center; gap: 10px; color: #fff; min-width: 0; }
.ms-rail .rail-lockup .ms-mark { height: 32px; }
.ms-rail .rail-wordmark { line-height: 1; min-width: 0; }
.ms-rail .rail-wordmark .n {
  display: block; font-family: var(--font-cond); font-weight: 800; letter-spacing: .055em;
  font-size: 15px; color: #fff; white-space: nowrap;
}
.ms-rail .rail-wordmark .s {
  display: block; font-weight: 500; letter-spacing: .26em; font-size: 8.5px;
  color: var(--steel-2); margin-top: 3px; white-space: nowrap;
}
/* Collapsed: the wordmark goes, the mark centres. */
body.ms-rail-collapsed .ms-rail .rail-wordmark { display: none; }
body.ms-rail-collapsed .ms-rail .rail-lockup { justify-content: center; gap: 0; }

/* The rail foot is the COMPANY SWITCHER, so it is a button, not a caption. */
.ms-rail button.rail-foot {
  width: 100%; background: none; border: 0; border-top: 1px solid rgba(255,255,255,.12);
  text-align: left; cursor: pointer; font: inherit; min-height: 52px;
}
.ms-rail button.rail-foot:hover { background: rgba(255,255,255,.07); }
.ms-rail button.rail-foot:focus-visible { outline: 2px solid var(--brand); outline-offset: -2px; }

/* ------------------------------- popovers ------------------------------- */
.ms-pop {
  position: fixed; z-index: 200; min-width: 268px; max-width: min(92vw, 340px);
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  box-shadow: var(--shadow-lg); padding: 6px; max-height: 70vh; overflow-y: auto;
}
.ms-pop-head {
  padding: 8px 10px 6px; font-size: 11px; font-weight: 700; letter-spacing: .07em;
  text-transform: uppercase; color: var(--faint);
}
.ms-pop-empty { padding: 18px 12px; text-align: center; color: var(--muted); font-size: 13.5px; }
.ms-co-opt {
  display: flex; align-items: center; gap: 11px; width: 100%; min-height: 46px;
  padding: 9px 10px; border: 0; border-radius: 9px; background: none; cursor: pointer;
  font: inherit; text-align: left; color: var(--text);
}
.ms-co-opt:hover { background: var(--surface-2); }
.ms-co-opt:focus-visible { outline: 2px solid var(--brand); outline-offset: -2px; }
.ms-co-opt.on { background: var(--brand-t); }
.ms-co-opt.on b { color: var(--accent); }
.ms-co-opt b { display: block; font-size: 14px; font-weight: 650; }
.ms-co-opt small { display: block; font-size: 11.5px; color: var(--muted); margin-top: 1px; }
.ms-co-opt .ms-ico { width: 18px; height: 18px; color: var(--muted); }
/* The company's own accent, so a subsidiary is recognisable before its name is read. */
.ms-co-dot { width: 18px; height: 18px; border-radius: 5px; flex: none; }

/* ------------------------------ access gate ------------------------------ */
.ms-gate {
  position: fixed; inset: 0; z-index: 400; background: rgba(21,37,52,.55);
  display: flex; align-items: center; justify-content: center; padding: 20px;
  backdrop-filter: blur(3px);
}
.ms-gate-card {
  background: var(--surface); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg);
  padding: 28px 26px; max-width: 460px; text-align: center;
}
.ms-gate-card h2 { margin: 0 0 10px; font-family: var(--font-cond); font-size: 21px; color: var(--text); }
.ms-gate-card p { margin: 0 0 10px; color: var(--text); font-size: 14.5px; }
.ms-gate-card p.muted { color: var(--muted); font-size: 13.5px; }
.ms-gate-card .btn { margin-top: 12px; }

.ms-toast.out { opacity: 0; transform: translateY(6px); transition: opacity .22s ease, transform .22s ease; }

/* ============================================================================
 * FINANCIAL COMPONENT KIT
 *
 * Two rules govern everything here and they are not stylistic:
 *
 *  1. FIGURES ARE TABULAR. Money is set in --font-num with tabular-nums and
 *     right-aligned, so a column of numbers lines up digit-for-digit and the eye
 *     can compare magnitudes down the page. A proportional-figure statement is a
 *     statement nobody can scan.
 *
 *  2. COLOUR IS SEMANTIC, NEVER DECORATIVE. --fav and --unfav mean "better than
 *     plan/prior" and "worse". They are NOT green=positive/red=negative: on an
 *     expense line, spending LESS than plan is favourable, so a negative variance
 *     is green. ms-fin.js decides polarity per line; the CSS only paints what it
 *     is told. Never hard-code a colour on a number.
 * ========================================================================== */

/* Any figure. Use on <td>, <span>, anywhere a number appears. */
.num, .money {
  font-family: var(--font-num); font-variant-numeric: tabular-nums;
  text-align: right; white-space: nowrap;
}
.money.neg { color: var(--unfav); }              /* an accounting negative, not a judgement */
.num.fav,   .money.fav   { color: var(--fav); }
.num.unfav, .money.unfav { color: var(--unfav); }
.num.flat,  .money.flat  { color: var(--muted); }

/* ------------------------------- KPI tiles ------------------------------- */
.kpi-grid {
  display: grid; gap: 12px; margin: 14px 0;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
}
.kpi {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 15px; box-shadow: var(--shadow-sm); min-width: 0;
}
.kpi .lbl {
  display: block; font-size: 11.5px; font-weight: 700; letter-spacing: .06em;
  text-transform: uppercase; color: var(--faint); margin-bottom: 7px;
}
.kpi .val {
  display: block; font-family: var(--font-num); font-variant-numeric: tabular-nums;
  font-size: 26px; font-weight: 600; color: var(--text); line-height: 1.1;
  overflow-wrap: anywhere;
}
.kpi .val .unit { font-size: 15px; color: var(--muted); font-weight: 500; margin-left: 2px; }
.kpi .delta {
  display: inline-flex; align-items: center; gap: 4px; margin-top: 8px;
  font-size: 12.5px; font-weight: 650; font-variant-numeric: tabular-nums;
  padding: 2px 8px; border-radius: 999px;
}
.kpi .delta.fav   { color: var(--fav);     background: var(--fav-t); }
.kpi .delta.unfav { color: var(--unfav);   background: var(--unfav-t); }
.kpi .delta.flat  { color: var(--neutral); background: var(--neutral-t); }
.kpi .vs { display: block; font-size: 11.5px; color: var(--faint); margin-top: 6px; }
/* A KPI built on incomplete or stale inputs must SAY SO rather than render a
   confident number over a hole. ms-fin.js sets this; never style around it. */
.kpi.stale { border-color: var(--st-yellow); }
.kpi .warn-flag {
  display: block; margin-top: 8px; font-size: 11.5px; font-weight: 600;
  color: #8a6206; background: var(--st-yellow-t); border-radius: 6px; padding: 4px 8px;
}

/* --------------------------- statement tables ---------------------------
   A P&L, balance sheet or cash flow. Wide statements scroll INSIDE .stmt-wrap;
   the page itself never scrolls sideways. */
.stmt-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; border-radius: var(--radius); }
table.stmt { width: 100%; border-collapse: collapse; font-size: 14px; background: var(--surface); }
table.stmt th, table.stmt td { padding: 7px 12px; border-bottom: 1px solid var(--border); }
table.stmt thead th {
  position: sticky; top: 0; z-index: 2; background: var(--surface-2);
  font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase;
  color: var(--faint); text-align: right; white-space: nowrap;
  border-bottom: 1px solid var(--border-2);
}
table.stmt thead th:first-child { text-align: left; }
/* The account column stays put while the period columns scroll — without this a
   consolidated statement across six companies is unreadable past column three. */
table.stmt th.acct, table.stmt td.acct {
  text-align: left; position: sticky; left: 0; z-index: 1;
  background: var(--surface); min-width: 220px;
}
table.stmt thead th.acct { background: var(--surface-2); z-index: 3; }
table.stmt tbody tr:hover td { background: var(--surface-2); }

/* Statement hierarchy. Depth is data, not decoration — ms-fin.js emits it. */
table.stmt td.acct.d1 { padding-left: 26px; }
table.stmt td.acct.d2 { padding-left: 40px; }
table.stmt td.acct.d3 { padding-left: 54px; }
table.stmt tr.section td { font-weight: 700; color: var(--text); background: var(--surface-2); }
table.stmt tr.subtotal td { font-weight: 650; border-top: 1px solid var(--border-2); }
table.stmt tr.total td {
  font-weight: 800; border-top: 2px solid var(--ink-2); border-bottom: 2px solid var(--ink-2);
  background: var(--surface);
}
table.stmt tr.spacer td { height: 10px; border: 0; background: transparent; }

/* An account that could not be mapped to the group chart of accounts. It is
   shown ON THE FACE of the statement — never dropped, never bucketed silently. */
table.stmt tr.unmapped td { background: var(--st-yellow-t); }
table.stmt tr.unmapped td.acct::after {
  content: "unmapped"; margin-left: 8px; font-family: var(--font-sans);
  font-size: 10px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase;
  color: #8a6206; background: #fdf3d6; border-radius: 4px; padding: 1px 5px;
}
/* An intercompany elimination that did not net to zero. Shown, never plugged. */
table.stmt tr.unreconciled td { background: var(--unfav-t); }
table.stmt tr.unreconciled td.acct { color: var(--unfav); font-weight: 650; }

/* ------------------------------- variance ------------------------------- */
.var-pill {
  display: inline-block; min-width: 58px; padding: 1px 7px; border-radius: 5px;
  font-family: var(--font-num); font-variant-numeric: tabular-nums;
  font-size: 12.5px; font-weight: 650; text-align: right;
}
.var-pill.fav   { color: var(--fav);     background: var(--fav-t); }
.var-pill.unfav { color: var(--unfav);   background: var(--unfav-t); }
.var-pill.flat  { color: var(--neutral); background: var(--neutral-t); }

/* ------------------------------ provenance ------------------------------
   Every figure must be explainable: which company, which QuickBooks realm,
   which report, which period, pulled when. This is the footer that says so. */
.provenance {
  display: flex; flex-wrap: wrap; gap: 6px 14px; align-items: center;
  margin-top: 12px; padding: 9px 12px; border-radius: 8px;
  background: var(--surface-2); border: 1px solid var(--border);
  font-size: 11.5px; color: var(--muted);
}
.provenance b { font-weight: 650; color: var(--text); }
.provenance .stale { color: #8a6206; font-weight: 650; }
.provenance .missing { color: var(--unfav); font-weight: 650; }

/* A company's colour chip, used in legends and consolidated statements so a
   column can be traced to a subsidiary without reading the header. */
.co-chip { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--muted); }
.co-chip i { width: 10px; height: 10px; border-radius: 3px; flex: none; display: block; }

/* ----------------------------- period picker ----------------------------- */
.period-bar {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  margin: 0 0 14px; padding: 10px 12px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
}
.period-bar .grow { flex: 1 1 auto; }
.period-bar select, .period-bar input[type="month"], .period-bar input[type="date"] {
  min-height: 40px; font-size: 16px;   /* >=16px: never let iOS zoom the page on focus */
}
@media (max-width: 640px) { .period-bar { position: sticky; top: var(--topbar-h); z-index: 5; } }

/* ============================================================================
 * RESPONSIVE — DESKTOP, TABLET AND MOBILE ARE ALL FIRST-CLASS
 *
 * Not a phone afterthought. An owner reads the consolidated P&L on a laptop,
 * a controller checks a variance on a tablet in a meeting, and a company
 * president looks up last month's margin on a phone in a truck. All three are
 * real, and _t_responsive.js fails the build if this file stops honouring them.
 *
 * The breakpoints, matching the rest of the system:
 *   >= 1080px   desktop — the left rail is visible
 *   700-1079px  tablet  — rail collapses to the slide-out drawer
 *   < 700px     phone
 *   pointer:coarse — touch, regardless of width
 *
 * THE HARD CASE is a financial statement: a dozen account rows by six company
 * columns will never fit a 375px screen, and squeezing it makes it unreadable
 * rather than responsive. So the table scrolls sideways INSIDE its own
 * container with the account name pinned — the layout accountants already
 * expect — and the PAGE never scrolls sideways. Those are different things and
 * only one of them is a bug.
 * ========================================================================== */

/* A scroll affordance. A table that scrolls with no visible hint reads as a
   table that is simply cut off, and the columns past the edge are never found.
   The shadow is painted by the container's own background-attachment trick, so
   it appears only while there is actually more to scroll to. */
.stmt-wrap {
  background:
    linear-gradient(to right, var(--surface) 30%, rgba(255,255,255,0)) left center,
    linear-gradient(to left,  var(--surface) 30%, rgba(255,255,255,0)) right center,
    radial-gradient(farthest-side at 0 50%, rgba(21,37,52,.16), rgba(0,0,0,0)) left center,
    radial-gradient(farthest-side at 100% 50%, rgba(21,37,52,.16), rgba(0,0,0,0)) right center;
  background-repeat: no-repeat;
  background-size: 36px 100%, 36px 100%, 14px 100%, 14px 100%;
  background-attachment: local, local, scroll, scroll;
}
/* Keyboard users must be able to scroll it too — a mouse-only scroll container
   is unreachable without a pointer. Pages set tabindex="0" on .stmt-wrap. */
.stmt-wrap:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }

/* ------------------------------- tablet ------------------------------- */
@media (max-width: 1079px) {
  /* The rail is gone (drawer takes over), so the page reclaims its width. */
  .kpi-grid { grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 10px; }
  .kpi .val { font-size: 23px; }
  table.stmt th.acct, table.stmt td.acct { min-width: 190px; }
}

/* -------------------------------- phone -------------------------------- */
@media (max-width: 700px) {
  /* Two tiles across still beats one: a KPI is a glance, and a single column
     turns six of them into a scroll. Below 360px it drops to one. */
  .kpi-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 9px; }
  .kpi { padding: 11px 12px; }
  .kpi .lbl { font-size: 10.5px; margin-bottom: 5px; }
  .kpi .val { font-size: 20px; }
  .kpi .val .unit { font-size: 13px; }
  .kpi .delta { font-size: 11.5px; padding: 2px 7px; }
  .kpi .vs { font-size: 10.5px; }

  /* The statement stays a table and stays scrollable — but tighter, so more
     of it is visible before the first swipe. */
  table.stmt { font-size: 13px; }
  table.stmt th, table.stmt td { padding: 6px 9px; }
  table.stmt th.acct, table.stmt td.acct { min-width: 148px; }
  table.stmt td.acct.d1 { padding-left: 18px; }
  table.stmt td.acct.d2 { padding-left: 27px; }
  table.stmt td.acct.d3 { padding-left: 36px; }
  table.stmt thead th { font-size: 10px; }
  /* The "unmapped" tag costs a line of width the phone does not have; the row
     tint still marks it and the desktop view carries the label. */
  table.stmt tr.unmapped td.acct::after { content: none; }

  .provenance { font-size: 11px; gap: 4px 10px; padding: 8px 10px; }
  .var-pill { min-width: 0; font-size: 11.5px; padding: 1px 5px; }

  /* The company picker becomes a bottom sheet — a popover anchored to a rail
     that is not on screen has nothing to point at. */
  .ms-pop.ms-co-pop {
    left: 0 !important; right: 0; top: auto !important; bottom: 0;
    max-width: none; width: 100%;
    border-radius: 16px 16px 0 0; padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
    max-height: 72vh;
  }
  .ms-co-opt { min-height: 52px; }
}

@media (max-width: 360px) {
  .kpi-grid { grid-template-columns: 1fr; }
}

/* ------------------------------- touch ------------------------------- */
@media (pointer: coarse) {
  /* >=44px targets and >=16px inputs. The 16px is not cosmetic: iOS Safari
     zooms the whole page when a smaller input is focused, and the user is then
     stranded at 1.3x with the layout off-screen. */
  .ms-co-opt { min-height: 48px; }
  .period-bar select,
  .period-bar input[type="month"],
  .period-bar input[type="date"],
  .period-bar input[type="text"] { min-height: 44px; font-size: 16px; }
  .stmt-wrap { -webkit-overflow-scrolling: touch; }
  /* Row height on a statement: comfortably tappable when a row opens a drill-down. */
  table.stmt tbody td { padding-top: 10px; padding-bottom: 10px; }
}

/* --------------------------- printing / export ---------------------------
   A statement is going to be printed and emailed. The chrome is not part of it,
   and the sideways scroll must become a full, flat table on paper. */
@media print {
  .ms-rail, .ms-nav-drawer, .ms-nav-overlay, .topbar, .ms-toasts,
  #ms-progress, #ms-rail-tip, .ms-pop, .period-bar { display: none !important; }
  body.ms-has-rail, body.ms-has-rail.ms-rail-collapsed { padding-left: 0 !important; }
  .stmt-wrap { overflow: visible !important; background: none !important; }
  table.stmt th.acct, table.stmt td.acct { position: static !important; }
  table.stmt thead th { position: static !important; }
  table.stmt { font-size: 10.5pt; }
  /* Never break a total away from the lines it totals. */
  table.stmt tr.total, table.stmt tr.subtotal { break-inside: avoid; page-break-inside: avoid; }
  .kpi { break-inside: avoid; page-break-inside: avoid; border: 1px solid #ccc; box-shadow: none; }
  .provenance { border: 1px solid #ccc; }
  a[href]::after { content: none !important; }
}

/* Visually hidden but available to a screen reader. Used for labels whose
   visible text lives in an adjacent control (a period picker, a search box). */
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ============================================================================
 * SAMPLE DATA BANNER
 *
 * Deliberately loud, and deliberately on EVERY page. Sample figures that can be
 * read without being labelled are the one thing this app must never produce, so
 * the banner sits above the chrome, is not dismissible, and leaves with the data.
 * ========================================================================== */
.ms-sample-bar {
  position: sticky; top: 0; z-index: 95;
  display: flex; align-items: center; gap: 10px 14px; flex-wrap: wrap;
  padding: 9px 16px; background: #2b1d05; color: #f6d99a;
  font-size: 12.5px; line-height: 1.45;
  border-bottom: 1px solid #4a3410;
}
.ms-sample-bar b { color: #ffd88a; font-weight: 700; }
.ms-sample-bar .grow { flex: 1 1 auto; min-width: 120px; }
.ms-sample-bar button {
  background: #7a2d22; border: 1px solid #a8483a; color: #ffe4de;
  border-radius: 7px; padding: 6px 12px; font: inherit; font-size: 12.5px;
  font-weight: 650; cursor: pointer; min-height: 34px; flex: none;
}
.ms-sample-bar button:hover { background: #983728; }
.ms-sample-bar button:focus-visible { outline: 2px solid #ffd88a; outline-offset: 2px; }
.ms-sample-bar button:disabled { opacity: .6; cursor: progress; }
body.ms-has-rail .ms-sample-bar { }
@media (pointer: coarse) { .ms-sample-bar button { min-height: 44px; padding: 8px 14px; } }
@media (max-width: 700px) { .ms-sample-bar { font-size: 11.5px; padding: 8px 12px; } }

/* The confirmation. A destructive action that reports "done" and nothing else
   leaves you wondering what it actually did. */
.ms-sample-done {
  position: fixed; inset: 0; z-index: 400; background: rgba(21,37,52,.6);
  display: grid; place-items: center; padding: 20px; backdrop-filter: blur(3px);
}
.ms-sample-done .card { max-width: 460px; margin: 0; }
.ms-sample-done dl { display: grid; grid-template-columns: 1fr auto; gap: 4px 16px; margin: 12px 0 0; }
.ms-sample-done dt { color: var(--muted); font-size: 13px; }
.ms-sample-done dd { margin: 0; font-family: var(--font-num); font-variant-numeric: tabular-nums; font-size: 13px; }

/* ============================================================================
 * WHAT'S NEW
 *
 * A floating button, bottom-right. It sits above the page but must never cover
 * a control: on a phone it shrinks to the icon, and it clears the safe-area
 * inset so it does not land under the iOS home indicator.
 * ========================================================================== */
.ms-wn-btn {
  position: fixed; z-index: 92;
  right: max(16px, env(safe-area-inset-right));
  bottom: max(16px, env(safe-area-inset-bottom));
  display: inline-flex; align-items: center; gap: 8px;
  min-height: 44px; padding: 10px 16px;
  border: 1px solid var(--ink-3); border-radius: 999px;
  background: var(--shell); color: #fff;
  font: inherit; font-size: 13.5px; font-weight: 650;
  cursor: pointer; box-shadow: var(--shadow-lg);
}
.ms-wn-btn:hover { background: var(--ink-3); }
.ms-wn-btn:focus-visible { outline: 2px solid var(--brand); outline-offset: 3px; }
.ms-wn-btn .ms-ico { width: 16px; height: 16px; }
.ms-wn-btn .n {
  min-width: 18px; height: 18px; padding: 0 5px; border-radius: 999px;
  background: var(--brand); color: #fff; font-size: 11px; font-weight: 800;
  line-height: 18px; text-align: center;
}
@media (max-width: 700px) {
  /* Icon only: a pill wide enough for a word covers content on a narrow screen. */
  .ms-wn-btn { padding: 12px; gap: 0; }
  .ms-wn-btn .lbl { display: none; }
  .ms-wn-btn .n { position: absolute; top: -4px; right: -4px; }
}
@media print { .ms-wn-btn { display: none; } }

/* The panel. A right-hand sheet on desktop, a bottom sheet on a phone — the
   same content, arriving from wherever there is room for it. */
.ms-wn-bg {
  position: fixed; inset: 0; z-index: 300; background: rgba(21,37,52,.5);
  display: flex; justify-content: flex-end; backdrop-filter: blur(2px);
}
.ms-wn {
  background: var(--surface); width: min(460px, 100%); height: 100%;
  display: flex; flex-direction: column; box-shadow: var(--shadow-lg);
}
.ms-wn header {
  display: flex; align-items: center; gap: 10px; flex: none;
  padding: 14px 16px; border-bottom: 1px solid var(--border);
}
.ms-wn header h2 {
  margin: 0; font-size: 16px; font-family: var(--font-cond);
  text-transform: none; letter-spacing: 0; flex: 1 1 auto;
}
.ms-wn header button {
  border: 0; background: none; font: inherit; font-size: 20px; line-height: 1;
  cursor: pointer; color: var(--muted); min-width: 44px; min-height: 44px;
}
.ms-wn .scroll { overflow-y: auto; padding: 4px 16px 20px; -webkit-overflow-scrolling: touch; }
.ms-wn .entry { padding: 16px 0; border-bottom: 1px solid var(--border); }
.ms-wn .entry:last-child { border-bottom: 0; }
.ms-wn .entry.fresh { position: relative; }
/* A quiet marker on entries the reader has not seen, rather than a loud NEW
   badge on each one — the count on the button already said how many. */
.ms-wn .entry.fresh::before {
  content: ''; position: absolute; left: -10px; top: 22px;
  width: 5px; height: 5px; border-radius: 50%; background: var(--brand);
}
.ms-wn .entry .when {
  font-size: 11.5px; color: var(--faint); font-variant-numeric: tabular-nums;
}
.ms-wn .entry h3 {
  margin: 3px 0 8px; font-size: 15px; font-family: var(--font-sans);
  font-weight: 700; text-transform: none; letter-spacing: 0; line-height: 1.35;
}
.ms-wn .entry ul { margin: 0; padding-left: 18px; }
.ms-wn .entry li { font-size: 13.5px; line-height: 1.6; color: var(--muted); margin-bottom: 5px; }
.ms-wn .tag {
  display: inline-block; font-size: 10px; font-weight: 800; letter-spacing: .06em;
  text-transform: uppercase; border-radius: 4px; padding: 2px 6px; margin-left: 8px;
  vertical-align: 2px;
}
.ms-wn .tag.feature     { background: var(--brand-t);   color: var(--accent); }
.ms-wn .tag.fix         { background: var(--unfav-t);   color: var(--unfav); }
.ms-wn .tag.improvement { background: var(--neutral-t); color: var(--neutral); }
.ms-wn .foot {
  flex: none; padding: 12px 16px; border-top: 1px solid var(--border);
  font-size: 12px; color: var(--faint);
}
@media (max-width: 700px) {
  .ms-wn-bg { align-items: flex-end; justify-content: center; }
  .ms-wn { width: 100%; height: auto; max-height: 82vh; border-radius: 16px 16px 0 0; }
}
@media (prefers-reduced-motion: no-preference) {
  .ms-wn { animation: msWnIn .18s ease; }
  @keyframes msWnIn { from { transform: translateX(16px); opacity: 0; } to { transform: none; opacity: 1; } }
}

/* ============================================================================
 * PAGE LOCK — the Activity Log's second door
 * ========================================================================== */
.ms-lock {
  position: fixed; inset: 0; z-index: 350; background: var(--shell);
  display: grid; place-items: center; padding: 20px;
}
.ms-lock .card { max-width: 380px; width: 100%; margin: 0; text-align: center; }
.ms-lock h2 {
  margin: 0 0 6px; font-size: 18px; font-family: var(--font-cond);
  text-transform: none; letter-spacing: 0;
}
.ms-lock p { margin: 0 0 14px; font-size: 13.5px; color: var(--muted); line-height: 1.55; }
.ms-lock input {
  width: 100%; text-align: center; letter-spacing: .18em;
  font-size: 16px;           /* >=16px: never let iOS zoom the page on focus */
  min-height: 46px;
}
.ms-lock .err { color: var(--unfav); font-size: 13px; font-weight: 600; margin: 10px 0 0; min-height: 18px; }

/* ============================================================================
 * BUTTONS ON DARK CHROME
 *
 * The drawer, the rail and the sign-in page are dark. `.btn` is a LIGHT control
 * — white ground, dark ink — so dropping one onto dark chrome relies on the
 * cascade to sort out the text colour, and it does not: `.ms-nav-foot a` sets
 * `color:#fff`, which is more specific than `.btn`'s own colour. The Sign out
 * button rendered as a white box with white text on it, and simply vanished.
 *
 * So dark chrome gets its own button treatment, stated rather than inherited.
 * ========================================================================== */
.ms-nav-drawer .ms-nav-foot { padding-bottom: max(14px, env(safe-area-inset-bottom)); }
.ms-nav-drawer .ms-nav-foot .who {
  flex: 1 1 100%; color: var(--steel-2); font-size: 12.5px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.ms-nav-drawer .ms-nav-foot .btn,
.ms-nav-drawer .ms-nav-foot a.btn {
  background: rgba(255,255,255,.10);
  border-color: rgba(255,255,255,.22);
  color: #fff;
  min-height: 44px; padding: 8px 16px;
  flex: 1 1 auto; justify-content: center;
}
.ms-nav-drawer .ms-nav-foot .btn:hover,
.ms-nav-drawer .ms-nav-foot a.btn:hover { background: rgba(255,255,255,.18); }
.ms-nav-drawer .ms-nav-foot .btn:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }

/* ============================================================================
 * MOBILE PASS
 *
 * Findings from measuring the real chrome at 375x812 with touch emulation on,
 * rather than from reading the stylesheet and hoping. Each fix below names the
 * thing that was actually wrong.
 * ========================================================================== */

/* ---------------------------------------------------------------------------
 * 1. THE TOPBAR WAS DISAPPEARING UNDER THE SAMPLE-DATA BANNER
 *
 * Both were `position: sticky; top: 0`, and the banner sat at z-index 95 against
 * the topbar's 50. Scroll down with sample data loaded and the topbar slid
 * underneath it — taking the menu button, the search button and the feedback
 * button with it. On a phone that is the entire navigation, gone.
 *
 * The banner's height is not knowable in CSS (its text wraps differently at
 * every width), so ms-api.js measures it and publishes --ms-banner-h. Everything
 * that sticks to the top offsets by it. With no banner the variable is 0 and
 * nothing moves.
 * ------------------------------------------------------------------------- */
:root { --ms-banner-h: 0px; }
header.topbar { top: var(--ms-banner-h); }
@media (max-width: 640px) {
  .period-bar { top: calc(var(--ms-banner-h) + var(--topbar-h)); }
}

/* ---------------------------------------------------------------------------
 * 2. THE COMPANY SWITCHER IN THE DRAWER WAS A 31px TARGET
 *
 * Every drawer rule was written for `a.link`. The switcher is a <button
 * class="link"> and matched none of them: no padding, no min-height, browser
 * default typography. It is the control that decides whose figures you are
 * looking at, and it was half the size of everything around it.
 *
 * The selectors now match the CLASS rather than the element, and buttons get the
 * reset they need to sit level with the anchors.
 * ------------------------------------------------------------------------- */
.ms-nav-drawer button.link {
  display: flex; align-items: center; gap: 12px;
  width: 100%; padding: 13px 18px; min-height: 48px;
  border: 0; background: none; font: inherit; font-size: 15px;
  color: #e5e5e5; text-align: left; cursor: pointer;
}
.ms-nav-drawer button.link:hover { background: rgba(255,255,255,.07); }
.ms-nav-drawer button.link:focus-visible { outline: 2px solid var(--brand); outline-offset: -2px; }
.ms-nav-drawer button.link .ms-ico { opacity: .78; }

/* ---------------------------------------------------------------------------
 * 3. CHECKBOXES WERE 13px
 *
 * A browser-default checkbox is about 13px square. That is not a touch target,
 * and "Show account detail" sits in the period bar on every statement. The
 * control is enlarged and its label is made part of the target, so the whole
 * phrase is tappable rather than one tiny square.
 * ------------------------------------------------------------------------- */
@media (pointer: coarse) {
  input[type="checkbox"], input[type="radio"] {
    width: 22px; height: 22px; flex: none;
  }
  label.row, label:has(> input[type="checkbox"]) { min-height: 44px; }
}

/* ---------------------------------------------------------------------------
 * 4. A ROW OF BUTTONS COULD NOT WRAP
 *
 * `.row` is flex with no wrap, so Delete / Cancel / Save in a modal footer had
 * to squeeze rather than stack. They shrank instead of overflowing, so nothing
 * looked broken — the labels just got tight enough to be hard to hit.
 * ------------------------------------------------------------------------- */
@media (max-width: 560px) {
  .row.end, .row.gap { flex-wrap: wrap; }
  .row.end > .btn { flex: 1 1 auto; min-width: 44%; }
  /* A destructive action must not end up adjacent to the confirm button once
     they wrap — it gets its own line. */
  .row.end > .btn-danger { flex: 1 1 100%; order: 1; }
}

/* ---------------------------------------------------------------------------
 * 5. MODALS ON A PHONE
 *
 * `90vh` is the wrong unit on mobile: `vh` ignores the browser chrome, so a
 * modal sized to it is taller than the visible area and its buttons sit under
 * the address bar. `dvh` tracks the space actually available.
 *
 * Below 560px a modal becomes a bottom sheet — the reachable half of a phone
 * screen — and clears the home indicator.
 * ------------------------------------------------------------------------- */
.modal { max-height: 90dvh; }
@media (max-width: 560px) {
  .modal-bg { align-items: flex-end; padding: 0; }
  .modal {
    max-width: 100%; width: 100%;
    border-radius: 16px 16px 0 0;
    max-height: 88dvh;
    padding: 18px 16px calc(18px + env(safe-area-inset-bottom));
  }
  .modal h3 { margin-top: 0; }
}

/* ---------------------------------------------------------------------------
 * 6. THE FLOATING BUTTON OVERLAPPED THE DRAWER AND MODALS
 *
 * It sits bottom-right; so does the drawer, and so does a bottom-sheet modal.
 * The drawer's z-index happened to cover it, which is luck rather than design —
 * and over a modal it would have floated on top. It is hidden outright whenever
 * something else owns the screen.
 * ------------------------------------------------------------------------- */
body.ms-drawer-open .ms-wn-btn,
body.ms-modal-open .ms-wn-btn { display: none; }

/* The last control on a page must not sit under the floating button. */
.page { padding-bottom: calc(76px + env(safe-area-inset-bottom)); }

/* ---------------------------------------------------------------------------
 * 7. NOTCHES AND ROUNDED CORNERS
 *
 * Landscape on a notched phone puts the safe-area inset on the side, and fixed
 * chrome runs underneath it.
 * ------------------------------------------------------------------------- */
header.topbar { padding-left: max(14px, env(safe-area-inset-left)); padding-right: max(14px, env(safe-area-inset-right)); }
.page { padding-left: max(16px, env(safe-area-inset-left)); padding-right: max(16px, env(safe-area-inset-right)); }
.ms-nav-drawer { padding-right: env(safe-area-inset-right); }
.ms-sample-bar { padding-left: max(16px, env(safe-area-inset-left)); padding-right: max(16px, env(safe-area-inset-right)); }

/* ---------------------------------------------------------------------------
 * 8. SMALL-SCREEN TYPOGRAPHY AND CHROME
 * ------------------------------------------------------------------------- */
@media (max-width: 700px) {
  .page-head h1 { font-size: 21px; }
  .page-head { gap: 8px; margin-bottom: 14px; }
  /* The email in the topbar squeezed the buttons that actually do something.
     It is in the drawer footer, which is where it belongs on a phone. */
  .ms-userchip { display: none; }
  .card { padding: 14px; }
  .period-bar { gap: 6px; padding: 8px 10px; }
  .period-bar select { flex: 1 1 auto; min-width: 0; }
}
@media (max-width: 380px) {
  /* Three icon buttons plus the wordmark is tight at 375px and impossible at
     360px. The topbar keeps the two that cannot live anywhere else. */
  .topbar .module { display: none; }
}

/* A long email or company name must wrap rather than push the page sideways. */
.ms-nav-foot .who, .ms-userchip, .ms-co-opt b, .ms-co-opt small { overflow-wrap: anywhere; }
