/* ============================================================================
   static/css/base.css
   ========================================================================== */
/* ============================================================================
   BASE.CSS
   Global tokens, resets, layout shell, topbar, generic utilities & components.
   This file should be included on every page.
   ========================================================================== */

/* 1) Design Tokens (CSS Custom Properties)
   Aligned to the EPI-USE web style guide. Every value below is either a
   literal brand colour (§1) or derived from one — never introduce a new hex.
   The legacy token names (--color-primary etc.) are kept so the existing
   component CSS keeps working; only their values moved onto the brand. */
:root {
  /* Brand core (§1) — the canonical palette. */
  --brand-navy: #002354;       /* primary field, buttons, headings */
  --brand-navy-deep: #001844;  /* hover / press only */
  --brand-blue-dark: #003A6B;
  --brand-blue-mid: #6897B8;
  --brand-taupe: #D7DAD6;      /* rules, light fills */
  --brand-grey: #F2F2F2;       /* section field */
  --brand-white: #FFFFFF;
  --brand-red: #CE181E;        /* accent only — never a field */

  /* Brand text (§1) */
  --brand-text: #333333;
  --brand-text-muted: #797979;
  --brand-heading: #24356A;
  --brand-heading-alt: #002354;
  --brand-link: #2B3C98;
  --brand-link-visited: #6950A1;

  /* Brand borders (§1) — always 1px, 2px only for a focus ring. */
  --brand-border-hairline: #D7DAD6;
  --brand-border-card: #D9DEE5;
  --brand-border-strong: #002354;
  --brand-border-on-dark: rgba(255,255,255,.35);

  /* Brand status (§1) */
  --brand-status-high: #CE181E;
  --brand-status-medium: #6897B8;
  --brand-status-low: #D7DAD6;
  --brand-status-positive: #00B050;
  --brand-status-warning: #FF9300;

  /* The only four approved gradients/tints (§1). */
  --gradient-sphere: linear-gradient(145deg,#6897B8 0%,#003A6B 100%);
  --gradient-navy: linear-gradient(180deg,#002354 0%,#001844 100%);
  --gradient-photo-scrim: linear-gradient(180deg,rgba(0,35,84,0) 0%,rgba(0,35,84,.55) 100%);
  --tint-photo-blue: rgba(0,58,107,.55);

  /* Legacy aliases — remapped onto the brand palette. */
  --color-primary: var(--brand-navy);
  --color-secondary: var(--brand-blue-dark);
  --color-accent: var(--brand-blue-mid);
  --color-bg: var(--brand-white);      /* content cards bg */
  --color-bg-2: var(--brand-grey);     /* app shell bg */

  --color-text: var(--brand-text);
  --color-text-dim: var(--brand-text-muted);

  /* Shape (§4): square-cornered, flat. 6px is the maximum on a card. */
  --radius-xl: 6px;
  --radius-lg: 6px;
  --radius-sm: 0px;

  /* Elevation (§4): 1px hairlines instead of shadows; only these three. */
  --shadow-1: 0 1px 3px rgba(0,24,68,.10);
  --shadow-2: 0 6px 18px rgba(0,24,68,.14);
  --shadow-sphere: 0 2px 6px rgba(0,24,68,.18);
  --ring: 0 1px 3px rgba(0,24,68,.10);

  /* Motion (§5): functional only — fades and colour. */
  --duration-fast: 120ms;
  --duration-base: 180ms;
  --duration-slow: 280ms;
  --ease-standard: cubic-bezier(.4,0,.2,1);
  --transition-fast: var(--duration-base) var(--ease-standard);
  --transition-slow: var(--duration-slow) var(--ease-standard);

  /* Type (§2) */
  --font-body: Verdana, Tahoma, sans-serif;

  --sidebar-w: 210px;
  --sidebar-w-collapsed: 80px;
  --topbar-h: 64px;

  --shell-pad: clamp(10px, 2.2vw, 18px);
  --gap: 12px;
}

/* Motion is functional only; honour the user's system preference (§5). */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
    scroll-behavior: auto !important;
  }
}

/* 2) Resets */
* { box-sizing: border-box; }
html, body { height: 100%; background: var(--color-bg-2); }
body {
  margin: 0;
  /* Verdana for the whole page, headings included (§2). */
  font-family: var(--font-body);
  font-size: 14px;
  line-height: 1.5;
  color: var(--color-text);
}

/* Headings: 1.35 line height, sentence case, no italics (§2). */
h1, h2, h3, h4, h5, h6 {
  line-height: 1.35;
  text-wrap: pretty;
  font-weight: 700;
  color: var(--brand-heading);
}

/* Safety net for headings on dark fields.
   The rule above sets the navy heading colour on every heading, and a direct
   match beats an inherited one — so a heading inside a navy panel rendered
   #24356A on #002354 at 1.31:1, far under the 3:1 minimum (§9).
   These blocks paint a dark field, so their headings are white. Using an
   explicit colour rather than `inherit` matters: `inherit` only works if the
   container declares a colour of its own, and a panel that sets just a
   background would otherwise pull the page body colour (#333333) down into
   the heading — the same failure in a different disguise.
   `:where()` keeps specificity at zero for the heading part, so a component's
   own title class still wins. */
.topbar :where(h1,h2,h3,h4,h5,h6),
.sidebar :where(h1,h2,h3,h4,h5,h6),
.contact-hero :where(h1,h2,h3,h4,h5,h6),
.ct-hero :where(h1,h2,h3,h4,h5,h6),
.login-card :where(h1,h2,h3,h4,h5,h6),
.home-outputs__hdr :where(h1,h2,h3,h4,h5,h6),
.home-activation__hdr :where(h1,h2,h3,h4,h5,h6),
.gd-principle :where(h1,h2,h3,h4,h5,h6) {
  color: var(--brand-white);
}

/* Links (§6): navy-blue, underline on hover only.
   IMPORTANT: this is deliberately scoped to bare <a> elements only. A styled
   link (a button, a nav item, a card row) carries its own colour, and
   `a:visited` — a class plus a pseudo-class — outranks a single component
   class, so an unscoped rule here repaints those components with the visited
   purple. That put #6950A1 on navy buttons at 2.38:1 contrast, well under the
   4.5:1 minimum (§9). Components opt in by leaving their <a> unclassed. */
a:not([class]) { color: var(--brand-link); }
a:not([class]):visited { color: var(--brand-link-visited); }

/* Prose links inside body copy still get the link treatment even when the
   surrounding block is classed. */
p > a:not([class]),
li > a:not([class]) { text-decoration: none; }
p > a:not([class]):hover,
li > a:not([class]):hover { text-decoration: underline; }

/* Focus is a 2px navy outline offset 2px and is never removed (§9). */
:focus-visible {
  outline: 2px solid var(--brand-navy);
  outline-offset: 2px;
}

/* 3) Shell & App Layout */
.shell {
  min-height: 100vh; height: 100dvh;
  padding: var(--shell-pad);
  /* The app frame owns its own scrolling; the page itself never scrolls
     sideways at any width (section 3). */
  max-width: 100%;
  overflow-x: hidden;
}

.app {
  display: grid;
  grid-template-rows: var(--topbar-h) minmax(0, 1fr);
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  grid-template-areas:
    "topbar topbar"
    "sidebar content";
  gap: var(--gap);
  height: 100%;
  min-height: 0;
  min-width: 0;
  overflow: hidden;
  transition: grid-template-columns var(--transition-slow);
}

.topbar { grid-area: topbar; min-width: 0; overflow: hidden; }
.sidebar { grid-area: sidebar; min-height: 0; min-width: 0; }
.content-area {
  grid-area: content;
  min-height: 0;
  min-width: 0;
  overflow: auto;
  padding: 20px;
  position: relative;
  /* Named container so page grids can respond to the width of the content
     column itself rather than the viewport (the rail takes the difference). */
  container: content / inline-size;
}

/* 4) Cards & Buttons
   Cards (§6): white on a grey field, 1px #D9DEE5 border, 6px radius. A
   hairline carries the edge — the shadow is a whisper, not a lift. */
.card {
  background: var(--color-bg);
  border: 1px solid var(--brand-border-card);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-1);
}

/* Buttons (§6): square corners, no gradient, no shadow, no transform on
   press. 14px Verdana, padding 12px 24px. Press deepens colour one step. */
.btn {
  cursor: pointer;
  border: 1px solid transparent;
  border-radius: 0;
  padding: 12px 24px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 700;
  transition: background var(--transition-fast), color var(--transition-fast),
              border-color var(--transition-fast);
}
.btn-primary,
a.btn-primary,
a.btn-primary:visited {
  background: var(--brand-navy);
  border-color: var(--brand-navy);
  color: var(--brand-white);
}
.btn-primary:hover,
a.btn-primary:hover { background: var(--brand-navy-deep); border-color: var(--brand-navy-deep); color: var(--brand-white); }
.btn-primary:active { background: var(--brand-navy-deep); }

/* Secondary: transparent with a navy hairline; hover fills navy. */
.btn-ghost,
a.btn-ghost,
a.btn-ghost:visited {
  background: transparent;
  border-color: var(--brand-navy);
  color: var(--brand-navy);
}
.btn-ghost:hover,
a.btn-ghost:hover { background: var(--brand-navy); color: var(--brand-white); }

.btn-secondary,
a.btn-secondary,
a.btn-secondary:visited {
  background: var(--brand-blue-dark);
  border-color: var(--brand-blue-dark);
  color: var(--brand-white);
}
.btn-secondary:hover,
a.btn-secondary:hover { background: var(--brand-navy); border-color: var(--brand-navy); color: var(--brand-white); }

/* Disabled is 40% opacity (§6). */
.btn:disabled, .btn[aria-disabled="true"] { opacity: .4; cursor: not-allowed; }

.muted { color: var(--color-text-dim); }
/* Status pills are the one place 999px is allowed (§4). */
.chip {
  background: var(--brand-grey);
  color: var(--brand-navy);
  border: 1px solid var(--brand-border-hairline);
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
}
.icon { width: 20px; height: 20px; color: currentColor; }
.icon-lg { width: 24px; height: 24px; }

/* ── Brand icon (§7) ──────────────────────────────────────────────────────
   Official navy line art from the design system's icon set. One treatment
   per page, held consistently: a navy glyph in a grey or gradient sphere.
   The sphere is the one round element in the system (§4). */
.brand-icon {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}
.brand-sphere {
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--brand-grey);
  flex-shrink: 0;
}
.brand-sphere--gradient { background: var(--gradient-sphere); }
/* Sphere sizes from the spacing scale (§3): 40 / 56 / 72px. */
.brand-sphere--40 { width: 40px; height: 40px; }
.brand-sphere--56 { width: 56px; height: 56px; }
.brand-sphere--72 { width: 72px; height: 72px; }
/* The glyph sits inside the sphere with breathing room. */
.brand-sphere .brand-icon { width: 60%; height: 60%; }

/* Eyebrow label (§2): 11px, all-caps, .14em tracking, brand red. */
.eyebrow {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .14em;
  color: var(--brand-red);
}

/* 5) Inverted Topbar (dark bg, white content) */
.topbar {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; gap: 12px;
  background: var(--brand-navy);
  border: 1px solid var(--brand-border-on-dark);
  height: var(--topbar-h);
  padding: 0 16px;
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-1);
  color: #fff;
  overflow: visible;
}
/* min-width:0 lets the brand name ellipsise so topbar buttons keep full width. */
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; flex: 1 1 auto; overflow: hidden; }
.brand-toggle {
  width: 36px; height: 36px; border-radius: 0; background: rgba(255,255,255,0.12);
  display: grid; place-items: center;
  border: 1px solid var(--brand-border-on-dark); cursor: pointer;
  transition: background var(--transition-fast);
}
.brand-toggle:hover { background: rgba(255,255,255,0.20); }
.brand-toggle:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }
.brand-toggle svg { width: 22px; height: 22px; color: #fff; }
.brand-name {
  font-size: 17px;
  font-weight: 700;
  letter-spacing: 0;
  color: #fff;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.topbar .chip { background: transparent; color: var(--brand-white); border-color: var(--brand-border-on-dark); }

.topbar-right { margin-left: auto; display:flex; align-items:center; gap: 12px; flex: 0 1 auto; min-width: 0; }
.topbar-actions { display:flex; align-items:center; gap: 8px; flex: 0 1 auto; min-width: 0; }
/* Topbar labels must always render in full — never clipped or ellipsised. */
.topbar-action {
  white-space: nowrap;
  overflow: visible;
  text-overflow: clip;
  flex-shrink: 0;
}
.topbar-form { margin: 0; display: inline-flex; }
/* On the navy topbar these are "on photography or navy" buttons (§6): white
   border, white label, transparent fill; hover fills white with a navy label.
   The selectors are element-qualified so they outrank the generic
   `a.btn-ghost:hover` rule earlier in this file, which has the same
   specificity and would otherwise leave a white label on a white fill. */
.topbar-actions a.btn-ghost,
.topbar-actions button.btn-ghost,
.topbar-actions a.btn-ghost:visited {
  color: var(--brand-white);
  border-color: var(--brand-border-on-dark);
  background: transparent;
}
.topbar-actions a.btn-ghost:hover,
.topbar-actions button.btn-ghost:hover,
.topbar-actions a.btn-ghost:focus-visible,
.topbar-actions button.btn-ghost:focus-visible {
  background: var(--brand-white);
  color: var(--brand-navy);
  border-color: var(--brand-white);
}
.topbar-actions a.btn-primary,
.topbar-actions button.btn-primary,
.topbar-actions a.btn-primary:visited {
  background: var(--brand-white);
  border-color: var(--brand-white);
  color: var(--brand-navy);
}
.topbar-actions a.btn-primary:hover,
.topbar-actions button.btn-primary:hover {
  background: var(--brand-taupe);
  border-color: var(--brand-taupe);
  color: var(--brand-navy);
}

.topbar-user {
  position: relative;
  display: flex;
  align-items: center;
  /* Keeps the sphere off the topbar's right edge. */
  margin-left: 4px;
}

.topbar-user__trigger {
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex: 0 0 auto;
}

/* The sphere itself carries the hover, so the icon stays the only shape. */
.topbar-user__trigger:hover .topbar-user__avatar,
.topbar-user.is-open .topbar-user__avatar {
  box-shadow: 0 0 0 2px var(--brand-white);
}

.topbar-user__trigger:focus-visible {
  outline: 2px solid rgba(255,255,255,0.9);
  outline-offset: 2px;
}

.topbar-user__avatar {
  position: relative;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--gradient-sphere);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--brand-white);
  overflow: hidden;
  flex: 0 0 auto;
  transition: box-shadow var(--transition-fast);
}

.topbar-user__avatar::after {
  content: "";
  position: absolute;
  right: 3px;
  bottom: 3px;
  width: 9px;
  height: 9px;
  border-radius: 999px;
  background: var(--brand-status-low);
  border: 2px solid var(--brand-white);
}

.topbar-user.is-authenticated .topbar-user__avatar::after {
  background: var(--brand-status-positive);
}

.topbar-user__avatar--large {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  flex: 0 0 auto;
}

.topbar-user__avatar--large::after {
  width: 11px;
  height: 11px;
  right: 4px;
  bottom: 4px;
  border-color: #ffffff;
}

.topbar-user__avatar-fallback {
  width: 22px;
  height: 22px;
  display: inline-flex;
}

.topbar-user__avatar--large .topbar-user__avatar-fallback {
  width: 28px;
  height: 28px;
}

.topbar-user__avatar-fallback svg {
  width: 100%;
  height: 100%;
}

.topbar-user__avatar-image {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.topbar-user__menu {
  position: absolute;
  top: calc(100% + 14px);
  right: 0;
  width: min(320px, calc(100vw - 32px));
  padding: 16px;
  border: 1px solid var(--brand-border-card);
  border-radius: var(--radius-xl);
  background: var(--brand-white);
  box-shadow: var(--shadow-2);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  /* A single fade is the maximum motion allowed (§5). */
  transition:
    opacity var(--transition-fast),
    visibility var(--transition-fast);
}

.topbar-user__menu::before {
  content: "";
  position: absolute;
  top: -8px;
  right: 18px;
  width: 16px;
  height: 16px;
  background: var(--brand-white);
  border-top: 1px solid var(--brand-border-card);
  border-left: 1px solid var(--brand-border-card);
  transform: rotate(45deg);
}

.topbar-user.is-open .topbar-user__menu {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

.topbar-user__summary {
  display: flex;
  align-items: center;
  gap: 14px;
  padding-bottom: 14px;
  margin-bottom: 14px;
  border-bottom: 1px solid var(--brand-border-hairline);
}

.topbar-user__details {
  min-width: 0;
}

.topbar-user__name,
.topbar-user__email {
  margin: 0;
}

.topbar-user__name {
  font-size: 14px;
  font-weight: 700;
  color: var(--brand-heading);
}

.topbar-user__email {
  margin-top: 4px;
  min-height: 1.2em;
  font-size: 12px;
  color: var(--color-text-dim);
  word-break: break-word;
}

.topbar-user__email.is-empty::before {
  content: "\00a0";
}

.topbar-user__menu-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.topbar-user__status {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 0 12px;
  border-radius: 999px;
  background: transparent;
  border: 1px solid var(--brand-border-hairline);
  color: var(--brand-text-muted);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
  padding: 0 10px;
}

.topbar-user__action {
  min-width: 108px;
}

.topbar-user__action--logout {
  background: transparent;
  color: var(--brand-navy);
  border: 1px solid var(--brand-navy);
  box-shadow: none;
}

.topbar-user__action--logout:hover {
  background: var(--brand-navy);
  color: var(--brand-white);
}

/* 6) Responsive Tweaks */
@media (max-width: 1200px) {
  :root{ --sidebar-w: 260px; --sidebar-w-collapsed: 78px; }
}
/* Free up room for the topbar actions before hiding them outright. */
@media (max-width: 1320px) {
  .topbar .chip { display: none; }
}
@media (max-width: 1180px) {
  /* Long secondary labels are the first thing to go; the sidebar and the
     Help Center page still expose these destinations.
     The selector is qualified because the generic `a.btn, button.btn` rule
     later in this file is more specific than a lone class and would otherwise
     win, leaving these buttons visible and widening the shell on a phone. */
  a.topbar-action--secondary,
  button.topbar-action--secondary,
  .topbar-form:has(.topbar-action--secondary) { display: none; }
}
@media (max-width: 760px) {
  .topbar-right { gap: 8px; }
  .topbar-actions { gap: 6px; }
  .topbar-action--primary {
    padding: 0.45rem 0.85rem;
    font-size: 13px;
  }
  .topbar-user__trigger {
    width: 44px;
    height: 44px;
    border-radius: 0;
  }
  .topbar-user__avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
  }
  .brand-name { font-size: 16px; }
}
@media (max-width: 560px) {
  /* On a phone the brand name alone carries the topbar; the chip and the
     New Quote label would otherwise force the shell wider than the screen.
     The avatar keeps its place, so the primary action gives way to it. */
  .topbar .brand-name { font-size: 14px; }
  .topbar-action--primary { padding: 0.42rem 0.6rem; }
  .topbar-actions { min-width: 0; overflow: hidden; }
  .topbar-right { gap: 8px; }

  .topbar {
    padding: 0 10px;
  }

  .topbar-right {
    gap: 6px;
  }

  .topbar-action--primary {
    padding: 0.42rem 0.72rem;
    font-size: 12px;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .topbar-user__menu {
    width: min(300px, calc(100vw - 20px));
    right: -2px;
  }
}
@media (max-width: 720px) {
  :root{ --shell-pad: 8px; --gap: 10px; }
}

/* Below 640px the fixed rail leaves too little room for content, which forced
   a horizontal scroll. Fall back to the collapsed icon rail so the layout
   still reflows cleanly at 640 / 375px (section 3). */
@media (max-width: 640px) {
  :root { --sidebar-w: var(--sidebar-w-collapsed); }
  .sidebar .text,
  .sidebar .nav-label { display: none; }
  .sidebar .nav-link { justify-content: center; }
}

@media (max-height: 860px) {
  :root { --topbar-h: 56px; --shell-pad: 8px; --gap: 8px; }

  .topbar { padding: 0 12px; }
  .brand-name { font-size: 16px; }
  .topbar .chip { display: none; }

  .topbar .btn {
    padding: 0.4rem 0.75rem;
    font-size: 13px;
  }
}
a.btn,
button.btn {
  display: inline-flex;         /* consistent layout */
  align-items: center;          /* vertical centering */
  justify-content: center;      /* horizontal centering */
  padding: 0.5rem 1rem;         /* same spacing */
  font-size: 14px;              /* lock in font size */
  line-height: 1.2;             /* avoid inherited line-height issues */
  /* Borders are part of the button system (a secondary button is a navy
     hairline), so they are NOT reset here. */
  text-decoration: none;        /* remove underline */
  cursor: pointer;              /* make link behave like button */
  white-space: nowrap;          /* never wrap or clip the label */
  overflow: visible;            /* label must stay fully readable */
  text-overflow: clip;          /* no ellipsis truncation on buttons */
  flex-shrink: 0;               /* don’t let flex parents squeeze the label */
  min-width: fit-content;       /* width always follows the full label */
}

/* On a phone the non-shrinking labels are what forced a horizontal scroll.
   Below 640px they may wrap and shrink so the page still fits (section 3). */
@media (max-width: 640px) {
  a.btn,
  button.btn {
    white-space: normal;
    min-width: 0;
    flex-shrink: 1;
  }
}

/* remove padding for specific pages */
.content-area.no-pad { padding: 0; }


/* ── Impersonation banner ────────────────────────────────────────────────── */
.impersonate-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 20px;
  background: var(--brand-grey);
  border-bottom: 1px solid var(--brand-status-warning);
  font-size: 12px;
  font-weight: 700;
  color: var(--brand-navy);
}

.impersonate-bar__btn {
  padding: 7px 14px;
  border-radius: 0;
  border: 1px solid var(--brand-navy);
  background: transparent;
  color: var(--brand-navy);
  font: inherit;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
  transition: background var(--transition-fast), color var(--transition-fast);
}
.impersonate-bar__btn:hover { background: var(--brand-navy); color: var(--brand-white); }
