/*
  Congregate Convention app: fonts, design tokens, reset and base element styles, copied from the Portal
  and kept the same; the one addition is the last block of this file.
  Source of truth: docs/dev_handoff.md section 3. Everything else lives in component styles (.razor.css).

  Layers, lowest priority first. Component styles are not layered, so they win over all of these.
*/
@layer reset, tokens, base;

/* ---------------------------------------------------------------------------
   Fonts: self-hosted woff2, latin and latin-ext subsets, swap over system fonts.
   IBM Plex Sans is one variable file covering 400 to 700.
   --------------------------------------------------------------------------- */
@font-face {
  font-family: "IBM Plex Sans";
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: url("fonts/ibm-plex-sans-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "IBM Plex Sans";
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: url("fonts/ibm-plex-sans-latin-ext.woff2") format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C4, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: "Poppins";
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url("fonts/poppins-600-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Poppins";
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url("fonts/poppins-600-latin-ext.woff2") format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C4, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: "Poppins";
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url("fonts/poppins-700-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Poppins";
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url("fonts/poppins-700-latin-ext.woff2") format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C4, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: "IBM Plex Mono";
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url("fonts/ibm-plex-mono-500-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "IBM Plex Mono";
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url("fonts/ibm-plex-mono-500-latin-ext.woff2") format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C4, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: "IBM Plex Mono";
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url("fonts/ibm-plex-mono-600-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "IBM Plex Mono";
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url("fonts/ibm-plex-mono-600-latin-ext.woff2") format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C4, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

/* ---------------------------------------------------------------------------
   Reset: targeted element resets only.
   --------------------------------------------------------------------------- */
@layer reset {
  html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
  body { margin: 0; }
  :where(h1, h2, h3, p, ul, ol, dl, dd, figure, fieldset) { margin: 0; }
  :where(ul, ol)[role="list"] { padding: 0; list-style: none; }
  :where(fieldset) { padding: 0; border: 0; min-inline-size: 0; }
  :where(svg, img) { display: block; flex-shrink: 0; max-inline-size: 100%; }
  :where(input, select, textarea, button) { font: inherit; color: inherit; }
  :where(button, [type="submit"]) { cursor: pointer; }
  :where(table) { border-collapse: collapse; }
  :where(*, ::before, ::after) { box-sizing: border-box; }
}

/* ---------------------------------------------------------------------------
   Design tokens.

   Each colour has a raw -light and -dark value. The theme is picked in two steps:
   1. Fallback for every browser: light by default, dark through prefers-color-scheme,
      and data-theme on <html> (written by the server from the theme cookie) overrides the system.
   2. Where light-dark() is supported, the same tokens resolve through color-scheme.
   --------------------------------------------------------------------------- */
@layer tokens {
  :root {
    --bg-light: #EDF1F6; --bg-dark: #172a40;
    --surface-light: #FFFFFF; --surface-dark: #2e5077;
    --surface-sunken-light: #F4F7FB; --surface-sunken-dark: #213a57;
    --field-bg-light: #FFFFFF; --field-bg-dark: #213a57;
    --nav-light: #2e5077; --nav-dark: #0f1e2e;
    --on-nav-light: #FFFFFF; --on-nav-dark: #ebebd3;
    --on-nav-2-light: #E3ECF5; --on-nav-2-dark: #E3ECF5;
    --on-nav-3-light: #C9D7E5; --on-nav-3-dark: #C9D7E5;
    --text-light: #13263d; --text-dark: #ebebd3;
    --text-2-light: #33465c; --text-2-dark: #d9d9c4;
    --text-3-light: #4d5f73; --text-3-dark: #c9c9b4;
    --primary-light: #2e5077; --primary-dark: #63adf2;
    --on-primary-light: #FFFFFF; --on-primary-dark: #13263d;
    --accent-light: #63adf2; --accent-dark: #63adf2;
    --link-light: #2e5077; --link-dark: #9fcdf7;
    --link-hover-light: #1d3552; --link-hover-dark: #cfe6fb;
    --border-light: #6d8aa8; --border-dark: #82a0bc;
    --divider-light: #D6E0EA; --divider-dark: #3a5f88;
    --row-line-light: #DCE4EE; --row-line-dark: #4f7299;
    --modal-line-light: #EEF3F8; --modal-line-dark: #3a5f88;
    --track-light: #D6E0EA; --track-dark: #24405f;
    --chip-ok-bg-light: #EEF3F8; --chip-ok-bg-dark: #3a5f88;
    --chip-ok-fg-light: #2e5077; --chip-ok-fg-dark: #9fcdf7;
    --chip-muted-bg-light: #D6E0EA; --chip-muted-bg-dark: #24405f;
    --chip-muted-fg-light: #33465c; --chip-muted-fg-dark: #d9d9c4;
    --chip-lead-bg-light: #13263d; --chip-lead-bg-dark: #ebebd3;
    --chip-lead-fg-light: #FFFFFF; --chip-lead-fg-dark: #13263d;
    --warn-light: #8A4B06; --warn-dark: #f6c77e;
    --warn-bg-light: #FDF0DC; --warn-bg-dark: #5a4320;
    --logo-mark-light: #2e5077; --logo-mark-dark: #ebebd3;
    --focus-light: #2e5077; --focus-dark: #63adf2;
    --shadow-light: 0 1px 2px rgba(46, 80, 119, 0.06);
    --shadow-dark: 0 1px 2px rgba(0, 0, 0, 0.25);

    /* Step 1: fallback resolution (light) */
    --bg: var(--bg-light);
    --surface: var(--surface-light);
    --surface-sunken: var(--surface-sunken-light);
    --field-bg: var(--field-bg-light);
    --nav: var(--nav-light);
    --on-nav: var(--on-nav-light);
    --on-nav-2: var(--on-nav-2-light);
    --on-nav-3: var(--on-nav-3-light);
    --text: var(--text-light);
    --text-2: var(--text-2-light);
    --text-3: var(--text-3-light);
    --primary: var(--primary-light);
    --on-primary: var(--on-primary-light);
    --accent: var(--accent-light);
    --link: var(--link-light);
    --link-hover: var(--link-hover-light);
    --border: var(--border-light);
    --divider: var(--divider-light);
    --row-line: var(--row-line-light);
    --modal-line: var(--modal-line-light);
    --track: var(--track-light);
    --chip-ok-bg: var(--chip-ok-bg-light);
    --chip-ok-fg: var(--chip-ok-fg-light);
    --chip-muted-bg: var(--chip-muted-bg-light);
    --chip-muted-fg: var(--chip-muted-fg-light);
    --chip-lead-bg: var(--chip-lead-bg-light);
    --chip-lead-fg: var(--chip-lead-fg-light);
    --warn: var(--warn-light);
    --warn-bg: var(--warn-bg-light);
    --logo-mark: var(--logo-mark-light);
    --focus: var(--focus-light);
    --shadow: var(--shadow-light);

    color-scheme: light dark;

    /* The same in both themes */
    --scrim: rgba(19, 38, 61, 0.55);
    --shadow-modal: 0 24px 60px rgba(0, 0, 0, 0.35);
    --shadow-toast: 0 8px 24px rgba(0, 0, 0, 0.18);
    --shadow-drawer: 0 0 40px rgba(0, 0, 0, 0.35);
    /* On the navy sidebar and the phone menu */
    --nav-card: rgba(255, 255, 255, 0.10);
    --nav-track: rgba(255, 255, 255, 0.14);
    --nav-active: rgba(255, 255, 255, 0.18);
    --nav-selected: rgba(255, 255, 255, 0.30);

    /* Type */
    --font-body: "IBM Plex Sans", system-ui, sans-serif;
    --font-heading: "Poppins", "IBM Plex Sans", system-ui, sans-serif;
    --font-mono: "IBM Plex Mono", ui-monospace, monospace;
    --fs-title: 1.625rem;   /* 26: page title */
    --fs-modal: 1.125rem;   /* 18: modal title */
    --fs-card: 1rem;        /* 16: card title */
    --fs-input: 0.9375rem;  /* 15: input text (16 on a phone) */
    --fs-lead: 0.9375rem;   /* 15: phone list title, toast, phone menu item */
    --fs-body: 0.875rem;    /* 14 */
    --fs-hint: 0.8125rem;   /* 13 */
    --fs-tag: 0.75rem;      /* 12 */
    --fs-caption: 0.6875rem; /* 11: sidebar captions */

    /* Radius */
    --r-tag: 0.375rem;    /* 6 */
    --r-small: 0.5rem;    /* 8: small button, menu item, segment */
    --r-input: 0.5625rem; /* 9 */
    --r-button: 0.625rem; /* 10: button, note, code box */
    --r-card: 0.875rem;   /* 14: card, modal, toast */

    /* Sizes */
    --control: 2.625rem;       /* 42: button */
    --control-small: 2.125rem; /* 34 */
    --field-h: 2.75rem;        /* 44: input, select, dashboard app tab, smallest touch target */
    --content-max: 72.5rem;    /* 1160 */

    /* Motion */
    --ease-out: cubic-bezier(0.2, 0, 0, 1);
    --t-colour: 120ms;
    --t-fold: 320ms;  /* the sidebar folding or opening */
    --ease-fold: cubic-bezier(0.4, 0, 0.2, 1);  /* gentle at both ends, for a large move */
  }

  /* The phone layout starts below 800 px (dev_handoff.md section 9). */
  @media (width < 50rem) {
    :root {
      --fs-title: 1.375rem; /* 22 */
      --fs-input: 1rem;     /* 16 stops iOS from zooming on focus */
      --control: 2.875rem;  /* 46 */
    }
  }

  @media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
      --bg: var(--bg-dark);
      --surface: var(--surface-dark);
      --surface-sunken: var(--surface-sunken-dark);
      --field-bg: var(--field-bg-dark);
      --nav: var(--nav-dark);
      --on-nav: var(--on-nav-dark);
      --on-nav-2: var(--on-nav-2-dark);
      --on-nav-3: var(--on-nav-3-dark);
      --text: var(--text-dark);
      --text-2: var(--text-2-dark);
      --text-3: var(--text-3-dark);
      --primary: var(--primary-dark);
      --on-primary: var(--on-primary-dark);
      --accent: var(--accent-dark);
      --link: var(--link-dark);
      --link-hover: var(--link-hover-dark);
      --border: var(--border-dark);
      --divider: var(--divider-dark);
      --row-line: var(--row-line-dark);
      --modal-line: var(--modal-line-dark);
      --track: var(--track-dark);
      --chip-ok-bg: var(--chip-ok-bg-dark);
      --chip-ok-fg: var(--chip-ok-fg-dark);
      --chip-muted-bg: var(--chip-muted-bg-dark);
      --chip-muted-fg: var(--chip-muted-fg-dark);
      --chip-lead-bg: var(--chip-lead-bg-dark);
      --chip-lead-fg: var(--chip-lead-fg-dark);
      --warn: var(--warn-dark);
      --warn-bg: var(--warn-bg-dark);
      --logo-mark: var(--logo-mark-dark);
      --focus: var(--focus-dark);
      --shadow: var(--shadow-dark);
    }
  }

  :root[data-theme="light"] { color-scheme: light; }

  :root[data-theme="dark"] {
    color-scheme: dark;
    --bg: var(--bg-dark);
    --surface: var(--surface-dark);
    --surface-sunken: var(--surface-sunken-dark);
    --field-bg: var(--field-bg-dark);
    --nav: var(--nav-dark);
    --on-nav: var(--on-nav-dark);
    --on-nav-2: var(--on-nav-2-dark);
    --on-nav-3: var(--on-nav-3-dark);
    --text: var(--text-dark);
    --text-2: var(--text-2-dark);
    --text-3: var(--text-3-dark);
    --primary: var(--primary-dark);
    --on-primary: var(--on-primary-dark);
    --accent: var(--accent-dark);
    --link: var(--link-dark);
    --link-hover: var(--link-hover-dark);
    --border: var(--border-dark);
    --divider: var(--divider-dark);
    --row-line: var(--row-line-dark);
    --modal-line: var(--modal-line-dark);
    --track: var(--track-dark);
    --chip-ok-bg: var(--chip-ok-bg-dark);
    --chip-ok-fg: var(--chip-ok-fg-dark);
    --chip-muted-bg: var(--chip-muted-bg-dark);
    --chip-muted-fg: var(--chip-muted-fg-dark);
    --chip-lead-bg: var(--chip-lead-bg-dark);
    --chip-lead-fg: var(--chip-lead-fg-dark);
    --warn: var(--warn-dark);
    --warn-bg: var(--warn-bg-dark);
    --logo-mark: var(--logo-mark-dark);
    --focus: var(--focus-dark);
    --shadow: var(--shadow-dark);
  }

  /* Step 2: light-dark() where supported. Placed last so it wins over step 1 at equal specificity. */
  @supports (color: light-dark(white, black)) {
    :root, :root[data-theme] {
      --bg: light-dark(var(--bg-light), var(--bg-dark));
      --surface: light-dark(var(--surface-light), var(--surface-dark));
      --surface-sunken: light-dark(var(--surface-sunken-light), var(--surface-sunken-dark));
      --field-bg: light-dark(var(--field-bg-light), var(--field-bg-dark));
      --nav: light-dark(var(--nav-light), var(--nav-dark));
      --on-nav: light-dark(var(--on-nav-light), var(--on-nav-dark));
      --on-nav-2: light-dark(var(--on-nav-2-light), var(--on-nav-2-dark));
      --on-nav-3: light-dark(var(--on-nav-3-light), var(--on-nav-3-dark));
      --text: light-dark(var(--text-light), var(--text-dark));
      --text-2: light-dark(var(--text-2-light), var(--text-2-dark));
      --text-3: light-dark(var(--text-3-light), var(--text-3-dark));
      --primary: light-dark(var(--primary-light), var(--primary-dark));
      --on-primary: light-dark(var(--on-primary-light), var(--on-primary-dark));
      --accent: light-dark(var(--accent-light), var(--accent-dark));
      --link: light-dark(var(--link-light), var(--link-dark));
      --link-hover: light-dark(var(--link-hover-light), var(--link-hover-dark));
      --border: light-dark(var(--border-light), var(--border-dark));
      --divider: light-dark(var(--divider-light), var(--divider-dark));
      --row-line: light-dark(var(--row-line-light), var(--row-line-dark));
      --modal-line: light-dark(var(--modal-line-light), var(--modal-line-dark));
      --track: light-dark(var(--track-light), var(--track-dark));
      --chip-ok-bg: light-dark(var(--chip-ok-bg-light), var(--chip-ok-bg-dark));
      --chip-ok-fg: light-dark(var(--chip-ok-fg-light), var(--chip-ok-fg-dark));
      --chip-muted-bg: light-dark(var(--chip-muted-bg-light), var(--chip-muted-bg-dark));
      --chip-muted-fg: light-dark(var(--chip-muted-fg-light), var(--chip-muted-fg-dark));
      --chip-lead-bg: light-dark(var(--chip-lead-bg-light), var(--chip-lead-bg-dark));
      --chip-lead-fg: light-dark(var(--chip-lead-fg-light), var(--chip-lead-fg-dark));
      --warn: light-dark(var(--warn-light), var(--warn-dark));
      --warn-bg: light-dark(var(--warn-bg-light), var(--warn-bg-dark));
      --logo-mark: light-dark(var(--logo-mark-light), var(--logo-mark-dark));
      --focus: light-dark(var(--focus-light), var(--focus-dark));
    }
  }
}

/* ---------------------------------------------------------------------------
   Base element styles.
   --------------------------------------------------------------------------- */
@layer base {
  html {
    /* Keeps the page from shifting sideways when a modal locks scrolling. */
    scrollbar-gutter: stable;
  }

  body {
    min-block-size: 100dvb;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font-body);
    font-size: var(--fs-body);
  }

  h1, h2, h3 { font-family: var(--font-heading); }
  h1 { font-size: var(--fs-title); font-weight: 700; }
  h2 { font-size: var(--fs-card); font-weight: 600; }

  a {
    color: var(--link);
    transition: color var(--t-colour);
  }
  a:hover { color: var(--link-hover); }

  /* Form controls. Field, Select and TextArea add the label, hint and refusal around them. */
  :where(input:not([type="checkbox"], [type="radio"], [type="file"]), select, textarea) {
    inline-size: 100%;
    min-inline-size: 0;
    block-size: var(--field-h);
    padding: 0 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--r-input);
    background: var(--field-bg);
    color: var(--text);
    font-size: var(--fs-input);
  }
  :where(textarea) {
    block-size: auto;
    padding-block: 0.625rem;
    line-height: 1.5;
    resize: vertical;
  }
  :where(input[readonly]) { background: var(--surface-sunken); }
  :where(input, select, textarea)[aria-invalid="true"] { border-color: var(--warn); }

  :focus-visible {
    outline: 2px solid var(--focus);
    outline-offset: 2px;
  }

  /* The page behind an open modal or the phone menu does not scroll. The dialog rules cover the
     browsers that contain scrolling by themselves; the :has() rule covers the others. */
  dialog:modal { overscroll-behavior: contain; }
  dialog::backdrop { overflow: hidden; overscroll-behavior: contain; }
  html:has(dialog:modal) { overflow: hidden; }

  .visually-hidden {
    position: absolute;
    inline-size: 1px;
    block-size: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }

  /* Folding the sidebar (js/sidebar.js) is a view transition: the sidebar and the page beside it
     (view-transition-name in PortalLayout.razor.css) change width together. Each side's picture keeps
     its size and is cut at the moving edge, so nothing stretches. The page shows only its new layout
     (its old and new layouts differ, so a cross-fade doubles the text); the sidebar's old picture
     fades over the first 60%. These are document-level pseudo-elements, which scoped CSS cannot reach, hence
     here. */
  ::view-transition-group(sidebar),
  ::view-transition-group(page) {
    animation-duration: var(--t-fold);
    animation-timing-function: var(--ease-fold);
  }

  ::view-transition-old(sidebar), ::view-transition-new(sidebar),
  ::view-transition-old(page), ::view-transition-new(page) {
    block-size: 100%;
    object-fit: none;
    object-position: left top;
    animation-duration: var(--t-fold);
  }

  /* Closing has more to fold away, so it takes longer (js/sidebar.js sets data-fold while it runs). */
  :root[data-fold="closing"] { --t-fold: 520ms; }

  ::view-transition-old(sidebar) { animation-duration: calc(var(--t-fold) * 0.6); }
  ::view-transition-old(page) { display: none; }
  ::view-transition-new(page) { animation: none; }

  @media (prefers-reduced-motion: reduce) {
    ::view-transition-group(*), ::view-transition-old(*), ::view-transition-new(*) { animation: none; }
  }
}

/* ---------------------------------------------------------------------------
   The Convention app's own addition (not in the Portal). On a phone the volunteer shell holds its tabs in a
   bar at the bottom of the screen (Layout/VolunteerLayout.razor). When the keyboard moves focus, the browser
   scrolls the focused control clear of that bar. A document-level rule, which scoped CSS cannot reach.
   --------------------------------------------------------------------------- */
@media (width < 50rem) {
  html:has(.volunteer-tabs) { scroll-padding-block-end: calc(4rem + env(safe-area-inset-bottom, 0px)); }
}
