/*
  The console's dark theme (issue 1916). Loaded last, and only takes effect under data-theme="night",
  which the layouts render from the theme cookie (OperatorThemeCookie).

  Why it exists: the brand night set in tokens.css flips the semantic tokens (--th-surface,
  --th-text, --th-line, …), but the console's stylesheets paint most surfaces, borders and chip text
  with raw palette steps (--Tolopea-50 backgrounds, --Tolopea-100 borders, --Mariner-800 chip text…),
  which the night set leaves light. So under night the text turned light while the surfaces stayed
  light — count chips at 1.14:1. tokens.css is byte-pinned to the approved prototype, so the night
  values of those steps live here instead.

  The rule: the light steps a surface or border is drawn with (50–300) become low-contrast tints of
  the night surface (Tolopea, as tokens.css's night set has it); the dark steps text is drawn with become light tints. Every value is mixed from
  the base colours, never from a step this file redefines, so nothing
  refers to itself. Steps left alone on purpose:
    - Mariner-700, Tolopea-800 — hovers on brand chrome (sidebar, primary and grave buttons), dark
      in both themes;
    - Pampas-950 — app.css's dark rules already use it as text on bright fills;
    - Blueberry-200/300, Pear-200+ — fills that carry dark text in both themes (subject chips,
      progress segments).
*/
[data-theme="night"] {
  /* Neutral surfaces and lines. */
  --Tolopea-50: color-mix(in srgb, var(--Pampas) 5%, var(--Tolopea));
  --Tolopea-100: color-mix(in srgb, var(--Pampas) 14%, var(--Tolopea));
  --Tolopea-200: color-mix(in srgb, var(--Pampas) 22%, var(--Tolopea));
  --Tolopea-300: color-mix(in srgb, var(--Pampas) 34%, var(--Tolopea));
  --Pampas-50: color-mix(in srgb, var(--Pampas) 6%, var(--Tolopea));
  --Pampas-200: color-mix(in srgb, var(--Pampas) 16%, var(--Tolopea));
  --Pampas-300: color-mix(in srgb, var(--Pampas) 26%, var(--Tolopea));

  /* Tinted surfaces: selection, info and success chips. */
  --Mariner-50: color-mix(in srgb, var(--Mariner) 16%, var(--Tolopea));
  --Mariner-100: color-mix(in srgb, var(--Mariner) 28%, var(--Tolopea));
  --Mariner-200: color-mix(in srgb, var(--Mariner) 40%, var(--Tolopea));
  --Mariner-300: color-mix(in srgb, var(--Mariner) 55%, var(--Tolopea));
  --Blueberry-100: color-mix(in srgb, var(--Blueberry) 26%, var(--Tolopea));
  --Pear-50: color-mix(in srgb, var(--Pear) 10%, var(--Tolopea));
  --Pear-100: color-mix(in srgb, var(--Pear) 20%, var(--Tolopea));
  --th-ice: color-mix(in srgb, var(--Blueberry) 14%, var(--Tolopea));

  /* Text steps, lightened to read on the surfaces above. */
  --Tolopea-500: color-mix(in srgb, var(--Pampas) 58%, var(--Tolopea));
  --Tolopea-600: color-mix(in srgb, var(--Pampas) 66%, var(--Tolopea));
  --Tolopea-700: color-mix(in srgb, var(--Pampas) 76%, var(--Tolopea));
  --Tolopea-950: var(--Pampas);
  --Pampas-500: color-mix(in srgb, var(--Pampas) 62%, var(--Tolopea));
  --Pampas-600: color-mix(in srgb, var(--Pampas) 70%, var(--Tolopea));
  --Pampas-900: color-mix(in srgb, var(--Pampas) 90%, var(--Tolopea));
  --Mariner-800: color-mix(in srgb, var(--Blueberry) 55%, var(--Pampas));
  --Blueberry-800: color-mix(in srgb, var(--Blueberry) 55%, var(--Pampas));
  --Pear-800: var(--Pear);
  --Pear-900: var(--Pear);

  /*
    Tokens.css derives these from steps redefined above, and a var() resolves on the element that
    declares it, so they would follow the remap. Muted text and control borders stay light.
  */
  --th-mist: color-mix(in srgb, var(--Pampas) 72%, var(--Tolopea));
  --th-slate: color-mix(in srgb, var(--Pampas) 76%, var(--Tolopea));

  color-scheme: dark;
}

/*
  Mariner-800 is chip text above, but a few places fill with it: the current navigation row and the
  meters' tracks. Those keep a dark fill.
*/
[data-theme="night"] :is(.nav-row[aria-current="page"], .nav-module[aria-current="page"],
  .navbar-menu .navbar-nav .nav-link.menu-link:not([data-bs-toggle]).active,
  .navbar-menu .navbar-nav .nav-sm .nav-link.active, .meter, .oc-meter) {
  background: color-mix(in srgb, var(--Mariner) 45%, var(--Tolopea));
}

/*
  A certificate preview is a printed page: white in both themes, so inside it the steps it draws
  with go back to light-theme values (approximated from the base colours; tokens.css holds the
  exact ones only under :root).
*/
[data-theme="night"] .cert {
  color-scheme: light;
  --Tolopea-50: color-mix(in srgb, var(--Tolopea) 3%, var(--th-white));
  --Tolopea-100: color-mix(in srgb, var(--Tolopea) 9%, var(--th-white));
  --Tolopea-200: color-mix(in srgb, var(--Tolopea) 18%, var(--th-white));
  --Tolopea-300: color-mix(in srgb, var(--Tolopea) 30%, var(--th-white));
  --Tolopea-500: color-mix(in srgb, var(--Tolopea) 55%, var(--th-white));
  --Tolopea-600: color-mix(in srgb, var(--Tolopea) 68%, var(--th-white));
  --Tolopea-700: color-mix(in srgb, var(--Tolopea) 78%, var(--th-white));
  --Mariner-100: color-mix(in srgb, var(--Mariner) 12%, var(--th-white));
  --Mariner-800: color-mix(in srgb, var(--Mariner) 60%, var(--Tolopea));
  --Blueberry-100: color-mix(in srgb, var(--Blueberry) 14%, var(--th-white));
}
