/* Vertex Books dark mode, only under prefers-color-scheme: dark.
   PDFs are server-rendered and stay light. Edit in staging only.
   Strategy: the whole app reads --color-gray-* / --color-white / --color-primary-* variables,
   so flipping those at :root turns most of the UI dark in one place. The rules below then fix
   the components that hard-code #fff / #000 in the built CSS (popper menus, date picker,
   inputs, content placeholders). Expect "mostly dark". */

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;

    /* Surfaces: light greys become dark blues, near-black text becomes light. */
    --color-white: #0f1b26;        /* cards, panels, modals (was #fff) */
    --color-gray-50: #14222e;      /* page background / stripes */
    --color-gray-100: #16252f;     /* body background (was very light grey) */
    --color-gray-200: #22333f;     /* borders, dividers */
    --color-gray-300: #2e4351;     /* stronger borders */
    --color-gray-400: #6b8394;     /* placeholders */
    --color-gray-500: #8fa3b2;     /* muted text */
    --color-gray-600: #b6c5d1;     /* secondary text */
    --color-gray-700: #d2dde6;     /* body text */
    --color-gray-800: #e3ebf1;
    --color-gray-900: #f1f5f8;     /* headings */

    /* Lighter navy for dark mode so buttons and links keep contrast on a dark page. */
    --color-primary-50: #10202c;
    --color-primary-100: #162c3c;
    --color-primary-200: #21384a;
    --color-primary-300: #4a6d88;
    --color-primary-400: #7fa3c0;
    --color-primary-500: #9dc0da;
    --color-primary-600: #b8d4e8;  /* links: light on dark */
    --color-primary-700: #6ea8d4;  /* primary buttons stay readable on dark */
    --color-primary-800: #a8cbee;
    --color-primary-900: #c9def2;
    --color-primary-950: #e2eefa;
  }

  /* Primary buttons: the light-on-dark primary would vanish as a button fill, so give
     filled primary buttons a solid mid navy and white text. */
  .bg-primary-700,
  .bg-primary-600 {
    background-color: #2f6f9e !important;
    color: #ffffff !important;
  }

  /* Body and page shells that hard-code the light background. */
  body,
  .bg-gray-100 {
    background-color: var(--color-gray-100) !important;
    color: var(--color-gray-800);
  }

  /* text-black is used by the sidebar menu items and the header avatar chip.
     On a navy/dark background it rendered near-black and unreadable (M-J, iPhone, 07:54).
     Make it light everywhere; real black text only ever came from the light theme. */
  .text-black {
    color: #ffffff !important;
  }

  /* Sidebar menu (M-J, iPhone dark mode, 07:54): inactive items are `text-black`, the active
     one `text-primary-500` on `bg-gray-100`. On the dark sidebar the inactive labels rendered
     near-black and unreadable. Target the real markup: <nav class="mt-5 space-y-1"> <a> items. */
  nav a {
    color: #ffffff !important;
  }
  nav a.text-primary-500 {
    color: #ffffff !important;
    background-color: #24405a !important;
    border-left-color: #7fb3d9 !important;
  }
  nav a:hover {
    color: #ffffff !important;
    background-color: #1d3040 !important;
  }
  /* Icons: dark grey-400 icons on navy were barely visible too. */
  nav a .text-gray-400,
  nav a svg {
    color: #c6d6e3 !important;
  }
  nav a.text-primary-500 .text-gray-400,
  nav a.text-primary-500 svg {
    color: #ffffff !important;
  }

  /* Grouped (sub)menu rows use hover:bg-gray-50 and text-primary-500. */
  .hover\:bg-gray-50:hover {
    background-color: #1d3040 !important;
  }

  /* Anything still carrying a dark text colour on a dark panel:
     headings, labels and table cells that were #000 / near-black. */
  h1, h2, h3, h4, h5, h6 {
    color: var(--color-gray-900);
  }
  label,
  th,
  td,
  .font-bold,
  .font-semibold {
    color: inherit;
  }

  /* Top bar / sidebar headers drawn with a gradient instead of a variable. */
  .bg-linear-to-r,
  [class*="from-primary-500"] {
    background-image: none !important;
    background-color: #0a1622 !important;
  }

  /* Dropdown / tooltip menus: built CSS hard-codes #fff background, #000 text, #ddd border. */
  .v-popper--theme-dropdown .v-popper__inner {
    color: var(--color-gray-800) !important;
    background: #16252f !important;
    border-color: #2e4351 !important;
    box-shadow: 0 6px 30px #00000080 !important;
  }
  .v-popper--theme-tooltip .v-popper__inner {
    color: #f1f5f8 !important;
    background: #22333f !important;
  }
  .v-popper__arrow-outer {
    border-color: #2e4351 !important;
  }
  .v-popper__arrow-inner {
    border-color: #16252f !important;
  }

  /* Inputs, selects, textareas, and the date picker panels: all hard-code white. */
  input:not([type="checkbox"]):not([type="radio"]):not([type="range"]),
  select,
  textarea {
    background-color: #0c1721 !important;
    color: var(--color-gray-800) !important;
    border-color: #2e4351 !important;
  }
  input::placeholder,
  textarea::placeholder {
    color: #6b8394 !important;
  }

  /* Tables keep readable stripes. */
  table,
  thead,
  tbody,
  tr {
    background-color: transparent;
  }
  .divide-gray-100 > * + *,
  .divide-gray-200 > * + * {
    border-color: #22333f !important;
  }

  /* Loading skeleton shimmer was light grey on white. */
  .base-content-placeholders-is-animated .base-content-placeholders-heading__title:before,
  .base-content-placeholders-is-animated .base-content-placeholders-heading__subtitle:before,
  .base-content-placeholders-is-animated .base-content-placeholders-text__line:before,
  .base-content-placeholders-is-animated .base-content-placeholders-box:before {
    background: linear-gradient(90deg, #0000 0%, #22333f 15%, #0000 30%) !important;
  }

  /* Focus rings stay visible. */
  .ring-gray-200 {
    --tw-ring-color: #2e4351;
  }
}
