/* Luke's App — Material 3 shared component layer (SPEC.md §8).
   Loaded right after app.css, before the per-screen files, so screens can still override.
   EVERY rule here is scoped under [data-md3]: with the Draft/Live pill off the file is inert and the
   live look is byte-for-byte unchanged. Only truly shared pieces live here (buttons/chips/fields are
   refined in app.css + crm.css in place, because .la and .crm share class names — SPEC §9.3).
   New M3 classes (.fab, top app bar, .md-menu, state layer, type utilities) are added alongside the
   existing DOM, never renamed. */

/* ---- M3 type-scale utility classes (used by new screen chrome) ---- */
[data-md3] .md-display-small { font: var(--md-sys-typescale-display-small-weight) var(--md-sys-typescale-display-small-size)/var(--md-sys-typescale-display-small-line) var(--f-display); }
[data-md3] .md-headline-small { font: var(--md-sys-typescale-headline-small-weight) var(--md-sys-typescale-headline-small-size)/var(--md-sys-typescale-headline-small-line) var(--f-display); }
[data-md3] .md-title-large { font: var(--md-sys-typescale-title-large-weight) var(--md-sys-typescale-title-large-size)/var(--md-sys-typescale-title-large-line) var(--f-title); }
[data-md3] .md-title-medium { font: var(--md-sys-typescale-title-medium-weight) var(--md-sys-typescale-title-medium-size)/var(--md-sys-typescale-title-medium-line) var(--f-title); }
[data-md3] .md-title-small { font: var(--md-sys-typescale-title-small-weight) var(--md-sys-typescale-title-small-size)/var(--md-sys-typescale-title-small-line) var(--f-title); }
[data-md3] .md-body-large { font: var(--md-sys-typescale-body-large-weight) var(--md-sys-typescale-body-large-size)/var(--md-sys-typescale-body-large-line) var(--f-body); }
[data-md3] .md-body-medium { font: var(--md-sys-typescale-body-medium-weight) var(--md-sys-typescale-body-medium-size)/var(--md-sys-typescale-body-medium-line) var(--f-body); }
[data-md3] .md-body-small { font: var(--md-sys-typescale-body-small-weight) var(--md-sys-typescale-body-small-size)/var(--md-sys-typescale-body-small-line) var(--f-body); }
[data-md3] .md-label-medium { font: var(--md-sys-typescale-label-medium-weight) var(--md-sys-typescale-label-medium-size)/var(--md-sys-typescale-label-medium-line) var(--f-util); }

/* ---- State layer: a ::before overlay tinted with the content colour (SPEC §1 state layers) ---- */
[data-md3] .md-state { position: relative; isolation: isolate; }
[data-md3] .md-state::before {
  content: ''; position: absolute; inset: 0; border-radius: inherit; background: currentColor;
  opacity: 0; pointer-events: none; transition: opacity 100ms var(--md-sys-motion-easing-standard); z-index: -1;
}
@media (hover: hover) { [data-md3] .md-state:hover::before { opacity: .08; } }
[data-md3] .md-state:focus-visible::before { opacity: .10; }
[data-md3] .md-state:active::before { opacity: .10; }

/* ==================================================================
   Top app bar — one per screen (SPEC §6.2), built by lib/ui/nav.js appBar()
   ================================================================== */
[data-md3] .md-topbar {
  position: sticky; top: 0; z-index: var(--z-topbar); height: var(--top-h); flex: none;
  display: flex; align-items: center; gap: .25rem; min-width: 0;
  padding: env(safe-area-inset-top) max(.5rem, env(safe-area-inset-left)) 0 max(.5rem, env(safe-area-inset-right));
  background: var(--md-sys-color-surface); color: var(--md-sys-color-on-surface);
  transition: background 200ms var(--md-sys-motion-easing-standard);
}
[data-md3] .md-topbar[data-scrolled="1"] { background: var(--md-sys-color-surface-container); }
[data-md3] .md-topbar.medium { height: calc(var(--top-h) + 2.25rem); align-items: flex-end; padding-bottom: .5rem; }
[data-md3] .md-topbar .md-topbar-title {
  flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font: var(--md-sys-typescale-title-large-weight) var(--md-sys-typescale-title-large-size)/var(--md-sys-typescale-title-large-line) var(--f-title);
  color: var(--md-sys-color-on-surface); padding-inline: .25rem;
}
[data-md3] .md-topbar.toplevel .md-topbar-title { padding-left: .75rem; }
[data-md3] .md-topbar.medium .md-topbar-title { font: var(--md-sys-typescale-headline-small-weight) var(--md-sys-typescale-headline-small-size)/var(--md-sys-typescale-headline-small-line) var(--f-display); white-space: normal; }
[data-md3] .md-iconbtn {
  flex: none; width: 2.5rem; height: 2.5rem; border: 0; background: none; border-radius: var(--md-sys-shape-corner-full);
  color: var(--md-sys-color-on-surface-variant); cursor: pointer; display: grid; place-items: center; padding: 0;
}
[data-md3] .md-iconbtn .ic { width: 1.5rem; height: 1.5rem; }
[data-md3] .md-iconbtn[aria-pressed="true"] { background: var(--md-sys-color-secondary-container); color: var(--md-sys-color-on-secondary-container); }
[data-md3] .md-iconbtn:focus-visible { outline: 3px solid var(--md-sys-color-primary); outline-offset: 2px; }

/* ==================================================================
   Primary tabs along the TOP — the 4 destinations stay at the top on
   phone, laptop and TV (Luke, 2026-11-17: tabs at the top, no bottom
   bar, no rail). Restyles the existing .topnav / .links / .nav-link;
   nav.js keeps the elements and the .nav-link class.
   ================================================================== */
[data-md3] .topnav {
  height: var(--top-h); padding: 0; align-items: stretch; justify-content: stretch;
  background: var(--md-sys-color-surface); backdrop-filter: none; -webkit-backdrop-filter: none;
  border-bottom: 1px solid var(--md-sys-color-surface-variant);
  transition: background 200ms var(--md-sys-motion-easing-standard);
}
[data-md3] .topnav .links { width: 100%; max-width: none; gap: 0; margin: 0; padding: 0; background: none; border-radius: 0; }
[data-md3] .topnav .nav-link {
  position: relative; isolation: isolate; flex: 1 1 0; min-width: 0; min-height: var(--top-h);
  display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
  padding: 0 .5rem; border: 0; border-radius: 0; background: none; box-shadow: none; cursor: pointer;
  color: var(--md-sys-color-on-surface-variant);
  font: var(--md-sys-typescale-label-large-weight) var(--md-sys-typescale-label-large-size)/1 var(--f-util);
  letter-spacing: var(--md-sys-typescale-label-large-track); text-transform: none; white-space: nowrap;
  transition: color 100ms var(--md-sys-motion-easing-standard);
}
[data-md3] .topnav .nav-link::before { /* state layer */
  content: ''; position: absolute; inset: 0; background: currentColor; opacity: 0;
  transition: opacity 100ms var(--md-sys-motion-easing-standard); pointer-events: none; z-index: -1;
}
@media (hover: hover) { [data-md3] .topnav .nav-link:hover::before { opacity: .08; } }
[data-md3] .topnav .nav-link:active::before { opacity: .10; }
[data-md3] .topnav .nav-link::after { /* active indicator */
  content: ''; position: absolute; left: 50%; bottom: 0; transform: translateX(-50%);
  width: 0; height: 3px; border-radius: 3px 3px 0 0; background: var(--md-sys-color-primary);
  transition: width 200ms var(--md-sys-motion-easing-emphasized-decelerate);
}
[data-md3] .topnav .nav-link[aria-current="page"] { color: var(--md-sys-color-primary); background: none; box-shadow: none; }
[data-md3] .topnav .nav-link[aria-current="page"]::after { width: min(100%, 6rem); }
[data-md3] .topnav .nav-link:focus-visible { outline: 3px solid var(--md-sys-color-primary); outline-offset: -3px; }
[data-md3] .topnav .nav-link .md-badge {
  position: absolute; top: .55rem; left: calc(50% + 1.6rem); min-width: 1rem; height: 1rem; padding: 0 .25rem;
  border-radius: var(--md-sys-shape-corner-full); background: var(--md-sys-color-error); color: var(--md-sys-color-on-error);
  display: grid; place-items: center; font: 500 .625rem/1 var(--f-util); font-variant-numeric: tabular-nums;
}
[data-md3] .topnav .nav-link .md-badge.dot { min-width: .5rem; width: .5rem; height: .5rem; padding: 0; }

/* ==================================================================
   FAB / extended FAB — SPEC §8
   ================================================================== */
[data-md3] .fab {
  position: fixed; z-index: var(--z-fab); right: calc(1rem + env(safe-area-inset-right));
  bottom: calc(1rem + env(safe-area-inset-bottom) + var(--tab-h, 0rem));
  display: inline-flex; align-items: center; gap: .5rem; min-height: 3.5rem; padding: 0 1rem; border: 0; cursor: pointer;
  background: var(--md-sys-color-primary-container); color: var(--md-sys-color-on-primary-container);
  border-radius: var(--md-sys-shape-corner-lg); box-shadow: var(--md-elev-3);
  font: var(--md-sys-typescale-label-large-weight) var(--md-sys-typescale-label-large-size)/1 var(--f-util); letter-spacing: var(--md-sys-typescale-label-large-track);
}
[data-md3] .fab.plain { width: 3.5rem; padding: 0; justify-content: center; }
[data-md3] .fab .ic { width: 1.5rem; height: 1.5rem; flex: none; }
[data-md3] .fab:focus-visible { outline: 3px solid var(--md-sys-color-primary); outline-offset: 2px; }
@media (min-width: 840px) { [data-md3] .fab { right: calc(1.5rem + env(safe-area-inset-right)); } }

/* ==================================================================
   M3 menu (overflow ⋮, name menus) — SPEC §8
   ================================================================== */
[data-md3] .md-menu {
  position: absolute; z-index: var(--z-menu); min-width: 11rem; max-width: 18rem; padding: .5rem 0;
  background: var(--md-sys-color-surface-container); color: var(--md-sys-color-on-surface);
  border-radius: var(--md-sys-shape-corner-xs); box-shadow: var(--md-elev-2);
}
[data-md3] .md-menu button, [data-md3] .md-menu a {
  display: flex; align-items: center; gap: .75rem; width: 100%; min-height: 3rem; padding: 0 .75rem; border: 0; background: none; cursor: pointer;
  color: inherit; text-align: left; text-decoration: none;
  font: var(--md-sys-typescale-body-large-weight) var(--md-sys-typescale-body-large-size)/1.2 var(--f-body);
}
[data-md3] .md-menu button .ic, [data-md3] .md-menu a .ic { width: 1.5rem; height: 1.5rem; flex: none; color: var(--md-sys-color-on-surface-variant); }
[data-md3] .md-menu button:hover, [data-md3] .md-menu a:hover { background: color-mix(in srgb, var(--md-sys-color-on-surface) 8%, transparent); }
[data-md3] .md-menu button.danger { color: var(--md-sys-color-error); }
[data-md3] .md-menu .md-menu-div { height: 1px; margin: .5rem 0; background: var(--md-sys-color-outline-variant); }

/* ==================================================================
   Snackbar — restyle the shared .toast to M3 (SPEC §8)
   ================================================================== */
[data-md3] .toast {
  background: var(--md-sys-color-inverse-surface); color: var(--md-sys-color-inverse-on-surface);
  border-radius: var(--md-sys-shape-corner-xs); box-shadow: var(--md-elev-3);
  font: var(--md-sys-typescale-body-medium-weight) var(--md-sys-typescale-body-medium-size)/var(--md-sys-typescale-body-medium-line) var(--f-body);
  padding: .9rem 1rem; z-index: var(--z-snackbar);
}
[data-md3] .toast button { color: var(--md-sys-color-inverse-primary); border: 0; background: none; font-weight: 500; padding: .3rem .5rem; border-radius: var(--md-sys-shape-corner-full); }

@media (prefers-reduced-motion: reduce) {
  [data-md3] .md-state::before, [data-md3] .md-topbar, [data-md3] .topnav, [data-md3] .topnav .nav-link, [data-md3] .topnav .nav-link::before, [data-md3] .topnav .nav-link::after { transition-duration: 0ms; }
}

/* ==================================================================
   Per-screen top app bar under the tabs (lib/ui/appbar.js; restructure chunk 1)
   ← parent · title · ≤2 text actions · ⋮. The in-body Back buttons / header
   buttons it drives are hidden here, never removed (the bar clicks them).
   ================================================================== */
[data-md3] .shell { --ab-h: 0rem; }
[data-md3] .shell[data-appbar] { --ab-h: 3.5rem; }
[data-md3] .md-appbar {
  position: sticky; top: var(--top-h); z-index: calc(var(--z-topbar) - 1); flex: none;
  display: flex; align-items: center; gap: .25rem; height: var(--ab-h); min-width: 0;
  padding: 0 max(.25rem, env(safe-area-inset-right)) 0 max(.25rem, env(safe-area-inset-left));
  background: var(--md-sys-color-surface); color: var(--md-sys-color-on-surface);
}
[data-md3] .md-appbar-title {
  flex: 1 1 auto; min-width: 0; margin: 0; padding-inline: .5rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font: var(--md-sys-typescale-title-large-weight) var(--md-sys-typescale-title-large-size)/var(--md-sys-typescale-title-large-line) var(--f-title);
}
[data-md3] .md-appbar .md-iconbtn[hidden] { display: none; }
[data-md3] .md-appbar-acts { display: flex; gap: .125rem; flex: none; }
[data-md3] .md-textbtn {
  min-height: 2.5rem; padding: 0 .75rem; border: 0; border-radius: var(--md-sys-shape-corner-full); background: none; cursor: pointer;
  color: var(--md-sys-color-primary); white-space: nowrap;
  font: var(--md-sys-typescale-label-large-weight) var(--md-sys-typescale-label-large-size)/1 var(--f-util);
}
[data-md3] .md-appbar-menu { top: calc(100% - .25rem); right: .5rem; }
[data-md3] .md-appbar-menu[hidden] { display: none; }
[data-md3] #crm-host .crm { height: calc(100dvh - env(safe-area-inset-top) - env(safe-area-inset-bottom) - var(--top-h) - var(--ab-h)); }

/* in-body Back + header buttons the bar took over */
[data-md3] .shell[data-appbar] #view .crumbs,
[data-md3] .shell[data-appbar] #view :is(.cg-head, .sc-head, .zd-head) > :is(.back, h1),
[data-md3] .shell[data-appbar] #view .sms-back,
[data-md3] .shell[data-appbar] #view .crt-back,
[data-md3] .shell[data-appbar] #view .crt-coname,
[data-md3] .shell[data-appbar] #crm-host :is([data-k="tpl-back"], [data-k="lb-back"], [data-k="ib-back"]) { display: none !important; }
[data-md3] .shell[data-appbar] #view :is(.cg-head, .sc-head, .zd-head):not(:has(> :not(.back, h1))) { display: none; }

/* the full CRM's company / contact overlays carry their own bar: style it as one (icon ←, actions right) */
[data-md3] .cp-bar { min-height: 3.5rem; display: flex; align-items: center; gap: .25rem; padding: 0 .25rem; }
[data-md3] .cp-bar .cp-close { font-size: 0; width: 2.5rem; height: 2.5rem; padding: 0; border-radius: var(--md-sys-shape-corner-full); display: grid; place-items: center; background: none; box-shadow: none; }
[data-md3] .cp-bar .cp-close .ic { width: 1.5rem; height: 1.5rem; }
[data-md3] .cp-bar .cp-bar-r { margin-left: auto; }

/* ==================================================================
   Shared M3 bits for the restructure: filled button, segmented button,
   filter chip, bottom sheet (chunk 2+)
   ================================================================== */
[data-md3] .md-filled {
  min-height: 2.5rem; padding: 0 1.5rem; border: 0; border-radius: var(--md-sys-shape-corner-full); cursor: pointer;
  background: var(--md-sys-color-primary); color: var(--md-sys-color-on-primary);
  font: var(--md-sys-typescale-label-large-weight) var(--md-sys-typescale-label-large-size)/1 var(--f-util);
}
[data-md3] .md-filled:disabled { opacity: .5; }
[data-md3] .md-seg { display: flex; border: 1px solid var(--md-sys-color-outline); border-radius: var(--md-sys-shape-corner-full); overflow: hidden; }
[data-md3] .md-seg-b {
  flex: 1 1 0; min-height: 2.5rem; border: 0; border-left: 1px solid var(--md-sys-color-outline); background: none; cursor: pointer;
  color: var(--md-sys-color-on-surface); font: var(--md-sys-typescale-label-large-weight) var(--md-sys-typescale-label-large-size)/1 var(--f-util);
}
[data-md3] .md-seg-b:first-child { border-left: 0; }
[data-md3] .md-seg-b[aria-pressed="true"] { background: var(--md-sys-color-secondary-container); color: var(--md-sys-color-on-secondary-container); }
[data-md3] .md-seg-b[aria-pressed="true"]::before { content: '✓ '; }
[data-md3] .md-fchip {
  display: inline-flex; align-items: center; gap: .4rem; min-height: 2rem; padding: 0 .75rem; cursor: pointer;
  border: 1px solid var(--md-sys-color-outline-variant); border-radius: var(--md-sys-shape-corner-sm); background: none;
  color: var(--md-sys-color-on-surface-variant); font: var(--md-sys-typescale-label-large-weight) var(--md-sys-typescale-label-large-size)/1 var(--f-util);
}
[data-md3] .md-fchip[aria-pressed="true"] { border-color: transparent; background: var(--md-sys-color-secondary-container); color: var(--md-sys-color-on-secondary-container); }
[data-md3] .md-fchip[aria-pressed="true"]::before { content: '✓'; }

/* ---- CRM tab company page (crm-tab.js drawCompanyMd3) ---- */
[data-md3] .la .crt-m3head { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem .75rem; margin: .25rem 0 1rem; }
[data-md3] .la .crt-m3head .crt-sub { margin: 0; }
[data-md3] .la .crt-stagewrap { position: relative; }
[data-md3] .la .crt-stagechip { min-height: 2.25rem; border-color: var(--md-sys-color-outline); color: var(--md-sys-color-on-surface); }
[data-md3] .la .crt-sdot { width: .625rem; height: .625rem; border-radius: 50%; background: var(--st, var(--md-sys-color-outline)); flex: none; }
[data-md3] .la .crt-stmenu { top: calc(100% + .25rem); left: 0; }
[data-md3] .la .crt-stmenu [aria-checked="true"] { background: var(--md-sys-color-secondary-container); }
[data-md3] .la .crt-sec { border-top: 1px solid var(--md-sys-color-outline-variant); padding: 0 0 .5rem; }
[data-md3] .la .crt-sec > summary {
  display: flex; align-items: center; gap: .5rem; min-height: 3.5rem; cursor: pointer; list-style: none;
  font: var(--md-sys-typescale-title-small-weight) var(--md-sys-typescale-title-small-size)/1.3 var(--f-title); color: var(--md-sys-color-on-surface);
}
[data-md3] .la .crt-sec > summary::-webkit-details-marker { display: none; }
[data-md3] .la .crt-sec > summary::after { content: '⌄'; font-size: 1.25rem; line-height: 1; color: var(--md-sys-color-on-surface-variant); transition: transform 200ms; order: 9; }
[data-md3] .la .crt-sec[open] > summary::after { transform: rotate(180deg); }
[data-md3] .la .crt-sec-n { color: var(--md-sys-color-on-surface-variant); font-weight: 400; }
[data-md3] .la .crt-sec-t { flex: 0 1 auto; }
[data-md3] .la .crt-sec-n { flex: 1 1 auto; }
[data-md3] .la .crt-sec .crt-plus { font-size: 1.4rem; color: var(--md-sys-color-primary); }
[data-md3] .la .crt-sec:not([open]) .crt-plus { display: none; }
[data-md3] .la .crt-sec .crt-btn { background: var(--md-sys-color-secondary-container); color: var(--md-sys-color-on-secondary-container); box-shadow: none; }
[data-md3] .la .crt-fabpad { height: 5.5rem; }
[data-md3] .la .crt-fab { gap: .5rem; padding: 0 1.25rem 0 1rem; }
[data-md3] .la .crt-fab-ic { font-size: 1.3rem; line-height: 1; }
[data-md3] .la .crt-sheet-wrap { position: fixed; inset: 0; z-index: var(--z-scrim); display: flex; flex-direction: column; justify-content: flex-end; }
[data-md3] .la .crt-scrim { position: absolute; inset: 0; background: color-mix(in srgb, var(--md-sys-color-scrim, #000) 32%, transparent); }
[data-md3] .la .crt-sheet {
  position: relative; display: flex; flex-direction: column; gap: 1rem; max-height: 90dvh; overflow: auto;
  width: min(100%, 40rem); margin: 0 auto; padding: .5rem 1rem calc(1rem + env(safe-area-inset-bottom));
  background: var(--md-sys-color-surface-container-low); border-radius: var(--md-sys-shape-corner-xl, 1.75rem) var(--md-sys-shape-corner-xl, 1.75rem) 0 0; box-shadow: var(--md-elev-1);
}
[data-md3] .la .crt-sheet-handle { width: 2rem; height: .25rem; margin: .5rem auto 0; border-radius: 2px; background: var(--md-sys-color-on-surface-variant); opacity: .4; }
[data-md3] .la .crt-sheet-title { margin: 0; font: var(--md-sys-typescale-title-large-weight) var(--md-sys-typescale-title-large-size)/1.3 var(--f-title); }
[data-md3] .la .crt-outs { display: flex; flex-wrap: wrap; gap: .5rem; }
[data-md3] .la .crt-sheet-acts { display: flex; justify-content: flex-end; gap: .5rem; }
[data-md3] .la .crt-fab { right: calc(4.25rem + env(safe-area-inset-right)); }
[data-md3] .la .crt-sec > summary:not(:has(.crt-sec-n))::after { margin-left: auto; }

/* ---- restructure 3: one primary per screen (the rest in the app bar / ⋮ / sheets) ---- */
/* app bar took these over: header action buttons, the SMS thread's name header, the Archive's Sign out */
[data-md3] .shell[data-appbar] #view .cg-head > button:not(.back),
[data-md3] .shell[data-appbar] #view .sms-thead,
[data-md3] .shell[data-appbar] #view .hm-signout { display: none !important; }
/* campaigns: FAB "New campaign"; one filled state button (Start / Resume / Pause); Finish lives in ⋮ */
[data-md3] .la .cg-fab { gap: .5rem; padding: 0 1.25rem 0 1rem; right: calc(4.75rem + env(safe-area-inset-right)); }
[data-md3] .la .cg-fab-ic { font-size: 1.3rem; line-height: 1; }
[data-md3] .la .cg-list:last-child, [data-md3] .la .cg-clients { padding-bottom: 5.5rem; }
[data-md3] .la .cg-actions [data-k="cg-finish"] { display: none; }
[data-md3] .la .cg-actions :is([data-k="cg-start"], [data-k="cg-pause"]) {
  background: var(--md-sys-color-primary); color: var(--md-sys-color-on-primary); border-color: transparent; box-shadow: none;
}
/* the CRM list: the sync time and sort get quieter; the FAB is the one filled thing */
[data-md3] .la #crt[data-mode="list"] .crt-sort, [data-md3] .la #crt[data-mode="pipe"] .crt-sort { border-color: transparent; background: var(--md-sys-color-surface-container-high); }
/* edit sheet: Save filled, Cancel a text button, Delete a quiet error text button at the start */
[data-md3] .es [data-k="es-cancel"] { background: none; border-color: transparent; box-shadow: none; color: var(--md-sys-color-primary); }
[data-md3] .es [data-k="es-del"] { background: none; border-color: transparent; box-shadow: none; color: var(--md-sys-color-error); margin-right: auto; }
[data-md3] .shell[data-appbar] #view .cg-head:not(:has(> :not(.back, h1, button))) { display: none; }
