/* Figma fidelity layer. Loaded after every family stylesheet.
   Values come from the Design System page (Figma file nReMKvkNpUXqxy4IbSuQJe):
   MobileTopBar 36:160, TabletTopBar 36:239, Field 3:64, Button 3:18. */

/* Tablet top bar (TabletTopBar): 56 high, padding 12/24, gap 16, Menu hit area 44 at x=24,
   wordmark 14/500, selector 44 high 13/400, Settings 14/400 in a 44 high hit area. */
@media (min-width: 768px) and (max-width: 1024px) {
  .topbar { padding: 12px 24px; gap: 16px; }
  .topbar .wordmark { font-weight: 500; }
  body .topbar .selector { height: 44px; padding: 8px 16px; gap: 12px; font-size: 13px; font-weight: 400; line-height: 18px; }
  .topbar .selector .caret { font-size: 0; line-height: 16px; }
  .topbar .top-link { display: inline-flex; align-items: center; min-height: 44px; font-weight: 400; }
  .topbar .top-link.campaigns-link { display: none; }
}

/* Mobile top bar (MobileTopBar): padding 12/16, gap 12, Menu 44x44 14/500, selector 44 high
   13/400, "Demo · 14 Oct" as plain 12/400 text on the right. */
@media (max-width: 767px) {
  .topbar { padding: 12px 16px; gap: 12px; }
  .topbar .menu { text-decoration: none; align-items: center; justify-content: center; padding: 0; font-size: 14px; font-weight: 500; line-height: 20px; }
  body .topbar .selector { height: 44px; padding: 8px 12px; gap: 8px; font-size: 13px; font-weight: 400; line-height: 18px; }
  .topbar .selector .caret { font-size: 0; line-height: 16px; }
  .topbar .demo-chip { margin-left: auto; padding: 0; border: 0; border-radius: 0; background: transparent; color: var(--text-secondary); font-size: 12px; font-weight: 400; line-height: 16px; }
}

/* Menu button: 14/500 on tablet and mobile (MobileTopBar and TabletTopBar, Menu hit area 44x44). */
@media (max-width: 1024px) {
  .topbar .menu { padding: 0; font-size: 14px; font-weight: 500; line-height: 20px; text-decoration: none; align-items: center; justify-content: center; }
}

/* Caret: Figma draws a 5px wide glyph. The system glyph is 8px, so the glyph is replaced by a 5x4 triangle. */
.caret { position: relative; display: inline-block; width: 5px; font-size: 0; line-height: 16px; }
.caret::before { content: ""; position: absolute; left: 0; top: 6px; border-left: 2.5px solid transparent; border-right: 2.5px solid transparent; border-top: 3.5px solid currentColor; }

/* Touch rule: every button is 44 high on tablet and mobile. */
@media (max-width: 1024px) {
  .secondary, .primary, .danger { min-height: 44px; height: 44px; }
}

/* Field (Design System 3:64): label 12/500 #55544f, 4 gap, box 38 high, 1px #858480, radius 6,
   padding 8/12, value 14/400 on 20. The caret is part of the value text, placed by design-fidelity.js. */
.field, .dialog label:not(.choice):not(.check) { font-size: 12px; font-weight: 500; line-height: 16px; color: var(--text-secondary); }
.dialog .include label:not(.choice):not(.check) { font-size: 14px; font-weight: 400; line-height: 20px; color: var(--text-primary); }
select, .control, .field input:not([type="checkbox"]):not([type="radio"]), .dialog label input:not([type="checkbox"]):not([type="radio"]) {
  height: 38px; padding: 8px 12px; font: 400 14px/20px var(--font); color: var(--text-primary);
  border: 1px solid var(--border-control); border-radius: var(--radius-md); background-color: var(--bg-surface);
}
.field textarea, .dialog label textarea { font: 400 14px/20px var(--font); color: var(--text-primary); }
select, select.control { -webkit-appearance: none; appearance: none; background-repeat: no-repeat; background-position: var(--caret-x, calc(100% - 12px)) 17px; background-size: 5px 4px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='5' height='4' viewBox='0 0 5 4'%3E%3Cpath d='M0 0h5L2.5 4z' fill='%231b1b1a'/%3E%3C/svg%3E"); }
select:disabled, select.control:disabled { background-color: var(--bg-subtle); color: var(--text-muted); cursor: default; }
select:disabled, select.control:disabled { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='5' height='4' viewBox='0 0 5 4'%3E%3Cpath d='M0 0h5L2.5 4z' fill='%236a6963'/%3E%3C/svg%3E"); }
.field input:disabled, .control:disabled { background-color: var(--bg-subtle); color: var(--text-muted); }
.field [aria-invalid="true"], .field.error select, .field.error input, select[aria-invalid="true"] { border-color: var(--status-error); }

/* Button (Design System 3:18): Primary, Danger and Ghost have no border and are 34 high; Secondary and
   disabled variants carry a 1px border and are 36 high. Radius 6, label 13/500 on 18, padding 8/16. */
@media (min-width: 1025px) {
  .primary:not(:disabled), .danger:not(:disabled) { height: 34px; }
}
.primary:disabled, .danger:disabled, .secondary:disabled { background: var(--bg-subtle); border: 1px solid var(--border-default); color: var(--text-muted); cursor: default; }

/* Overlays. Scrim is black at 40% in every frame. Dialogs: 480 wide on tablet at x=144 and 342 wide
   on mobile at x=24, centred vertically with at least 40 above (Figma 83:20516, 83:20250). Tablet
   drawer: 440 wide, full height, right. Mobile sheet: full width from y=84 to the bottom, top radius
   10, no border (Figma 85:27407). Family stylesheets refine these with body-scoped rules. */
.scrim, .dialog-scrim, .scrim.dim, .collect-scrim { background: rgba(0, 0, 0, 0.4); }
.scrim, .dialog-scrim { z-index: 30; }
.drawer { z-index: 31; box-shadow: -6px 0 24px rgba(0, 0, 0, 0.18); }
@media (max-width: 1024px) {
  .dialog-scrim.dialog-scrim { align-items: flex-start; justify-content: center; padding: 40px 24px; overflow: auto; }
  .dialog-scrim .dialog { flex: none; width: 480px; max-width: 100%; margin: auto 0; }
  .drawer.drawer.drawer { width: 440px; }
}
@media (max-width: 767px) {
  .dialog-scrim .dialog { width: 100%; }
  .drawer.drawer.drawer { top: 84px; width: 100%; height: calc(100vh - 84px); border: 0; border-radius: 10px 10px 0 0; }
}

/* Field label to box gap is 4 on every size (Field 3:64); design.css set 2 on tablet. */
.field.target, .field.range, .field.compact { gap: 4px; }

/* Long campaign names must not wrap inside the top-bar selector. */
.topbar .selector { white-space: nowrap; }

/* Shared requests from the family passes, all measured against Figma:
   side-nav group labels sit 4 lower than the links above (RESEARCH y219, SITE 359, DECISIONS 499, REPORTS 559);
   table header rows are 32 high; the active bottom tab has a 2px accent top line;
   a field hint adds nothing to the 4px label gap; disabled inputs use the subtle fill. */
.sidenav .nav-label:not(:first-child) { margin-top: 4px; }
@media (max-width: 767px) { .bottom-tabs a.here { box-shadow: inset 0 2px 0 var(--accent); } }
.field .hint { margin-top: 0; }
.field input:disabled:not([type="checkbox"]):not([type="radio"]), .control:disabled { background-color: var(--bg-subtle); color: var(--text-muted); }

/* Review fixes shared by every family (independent review, 2026-10-22):
   - A table wider than its panel scrolls inside the panel instead of being cut off.
   - A desktop dialog that is taller than the window scrolls inside its scrim, so its actions stay reachable. */
.table-wrap { overflow-x: auto; }
.dialog-scrim { overflow-y: auto; overscroll-behavior: contain; }
@media (min-width: 1025px) { .dialog-scrim .dialog { margin-bottom: 24px; flex: none; } }

/* Menu hit area is 44x44 on tablet and mobile (TabletTopBar, MobileTopBar). */
@media (max-width: 1024px) { body .topbar .menu { min-width: 44px; min-height: 44px; } }

/* BottomTabs (Figma 82:29949): inactive labels 12/Regular, the active label 12/Medium. */
@media (max-width: 767px) { .bottom-tabs a { font-weight: 400; } .bottom-tabs a.here { font-weight: 500; } }

/* Tablet wordmark link: 44 high hit area without moving it (touch rule). Dialogs sit above drawers. */
@media (min-width: 768px) and (max-width: 1024px) { .topbar .wordmark { display: inline-flex; align-items: center; min-height: 44px; } }
.dialog-scrim { z-index: 40; }

/* Focus placed by script after a pointer click does not draw the keyboard ring until a key is pressed. */
[data-fid-quiet="1"]:focus-visible { outline: none; }

/* A desktop dialog never grows past the window: its own content scrolls, so the actions stay reachable. */
@media (min-width: 1025px) { .dialog-scrim .dialog { max-height: calc(100vh - 48px); overflow-y: auto; } }

/* Top-bar selector: the name truncates, the caret stays. */
body .topbar .selector { max-width: 100%; min-width: 0; }
body .topbar .selector .selector-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
body .topbar .selector-wrap { min-width: 0; flex: 0 1 auto; }

/* The wordmark never wraps; a long campaign name shortens in the selector instead. */
.topbar .wordmark { white-space: nowrap; flex: none; }

/* The selector may shrink (a family rule must not pin it at its content width); the chip never does. */
body .topbar .selector { flex: 0 1 auto; }
body .topbar .demo-chip, body .topbar .full-chip { flex: none; }

/* Real phones are 360 wide and narrower: the page may be as narrow as 320 before it scrolls sideways
   (design.css holds the rule). A sweep of 151 routes at 360 finds no overflow with this. */

/* Error pages inside the accepted interface (not found, database unavailable, setup, bad address). */
body.error-page { background: var(--bg-canvas); }
.error-main { display: flex; justify-content: center; padding: 64px 24px; }
.error-panel { width: 100%; max-width: 560px; display: flex; flex-direction: column; gap: 12px; padding: 24px; border: 1px solid var(--border-default); border-radius: var(--radius-md); background: var(--bg-surface); }
.error-panel h1 { margin: 0; font-size: 24px; font-weight: 600; line-height: 32px; overflow-wrap: anywhere; }
.error-panel p { margin: 0; color: var(--text-secondary); font-size: 14px; line-height: 20px; overflow-wrap: anywhere; }
.error-actions { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 8px; }
@media (max-width: 1024px) { .error-main { padding: 24px 16px; } }

/* The error page keeps its wordmark and links on mobile (the other pages hide them behind the Menu). */
@media (max-width: 767px) { body.error-page .wordmark, body.error-page .top-link { display: inline-flex; align-items: center; min-height: 44px; } body.error-page .topbar { gap: 16px; } }
