/*
 * Purpose: Sets the shared text colours and typography for every staff portal page.
 * Where it fits: Loaded on all admin pages through config/unfold.py STYLES; page stylesheets build on its tokens.
 * Author: Imre Draskovits <imre.draskovits@newcastle.ac.uk>
 * Created: 2026-07-23
 */

/* This is the base layer every other portal stylesheet builds on, so the
 * hub, overview, setup wizard and stock dashboard read the same on the warm
 * cream panels. It is loaded on every admin page through STYLES in
 * config/unfold.py.
 *
 * - Baseline typography, plus the shared phone-width rules and the mobile
 *   sidebar backdrop.
 *
 * Palette: warm taupe with the Wada blue primary. A grey that is one of the
 * taupe steps is written var(--color-base-*, <hex>), which Unfold defines
 * from COLORS in config/unfold.py.
 */

/* The portal's colour palette, defined here once and loaded on every staff
 * page (the document previews included). It is Wada Sanzo's combination
 * No. 172 (colors.imre.app), the same as on the participant profile's trial
 * schema and in the app:
 * - --antwarp-blue: listening, progress;
 * - --cinnamon-rufous: washout, a pause;
 * - --red-violet: the end of the trial;
 * - each with a -tint for lighter fills;
 * - --accent-today: the app's Yellow Orange, for "today". */
:root {
  --antwarp-blue: #008299;
  --antwarp-blue-tint: #99d0d9;
  --cinnamon-rufous: #bc5b25;
  --cinnamon-rufous-tint: #e7c0ab;
  --red-violet: #3400a3;
  --red-violet-tint: #ae99da;
  --accent-today: #ff8c00;
}

/* Colours used in more than one place, named once. The study colours are
 * shades of the palette above:
 * -hover darkens a filled control, -ink is text on a pale fill, -wash and
 * -faint are pale fills. */
:root {
  --antwarp-blue-hover: #00707f;
  --antwarp-blue-ink: #005f6f;
  --antwarp-blue-wash: #e0f1f4;
  --antwarp-blue-faint: #f0f9fa;
  --cinnamon-rufous-wash: #f8ece5;
  --cinnamon-rufous-ink: #8f441c;
  --red-violet-wash: #efeaf8;

  /* The border of a form field: input, select, textarea, checkbox. Dark
     enough for 3:1 against white (WCAG 1.4.11); dividers and card lines keep
     the lighter base greys. */
  --control-border: #9f9380;

  /* Corners, three sizes: sm for small chips, md for buttons, fields, alerts
     and menus, lg for cards, panels and dialogs. Two shapes besides: the pill
     (--radius-full) for badges and pill chips, and the circle (50%). Progress
     tracks keep their own shapes; Unfold's own widgets keep its BORDER_RADIUS
     (config/unfold.py). */
  --radius-sm: 4px;
  --radius-md: 7px;
  --radius-lg: 12px;
  --radius-full: 999px;

  /* Danger: removals and other irreversible actions. One token per red in
     use, from the strongest to the palest. */
  --danger-strong: #991b1b;
  --danger: #b91c1c;
  --danger-bright: #ef4444;
  --danger-line: #fca5a5;
  --danger-line-soft: #fecaca;
  --danger-wash: #fee2e2;
  --danger-faint: #fef2f2;
  --danger-mist: #fff5f5;

  /* The light hover of a secondary button (Cancel, Close). */
  --neutral-hover-bg: var(--color-base-100, #f6f3ed);
  --neutral-hover-border: var(--color-base-400, #b8a993);

  /* Modals drawn as a fixed overlay. A <dialog>'s ::backdrop keeps its own
     literal: older browsers do not pass custom properties to ::backdrop. */
  --modal-shadow: 0 20px 60px rgba(0, 0, 0, 0.25);
  --modal-backdrop: rgba(0, 0, 0, 0.5);
}

/* Unfold's own form fields draw their border in base-200 or base-300, too
 * light to see against white. These rules sit in Unfold's utilities layer
 * (declared in the same order as its stylesheet, which loads after this one),
 * so its checked, error and disabled states, being more specific, still win. */
@layer properties, theme, base, components, utilities;
@layer utilities {
  input.border-base-200, select.border-base-200, textarea.border-base-200,
  input.border-base-300, select.border-base-300, textarea.border-base-300 {
    border-color: var(--control-border);
  }
}

/* Crisper glyph rendering for the system-ui stack on the light theme. */
body {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

/* Unfold 0.110 styles every <dialog> as its own modal: moved by translate,
 * no border, a blurred tinted backdrop. The portal's dialogs centre the
 * browser's way and draw their own frame and backdrop, so take that back.
 * `html dialog` outranks Unfold's `dialog`, whose sheet loads after this one;
 * a dialog's own class or id still wins. The !important answers Unfold's. */
html dialog {
  position: fixed;
  inset: 0;
  margin: auto;
  translate: none;
}
html dialog:not(.tr-alert-dialog) { border-width: 1px !important; }
html dialog::backdrop {
  background-color: transparent;
  -webkit-backdrop-filter: none;
  backdrop-filter: none;
}

/* Shared mobile shell. Unfold supplies the drawer; these rules keep custom
 * portal pages usable once the drawer is opened on a phone-sized viewport. */
@media (max-width: 1279px) {
  #main,
  #content,
  #header-inner {
    min-width: 0;
  }

  #main > .bg-white,
  #main > .bg-white > .container,
  #main > .px-4 {
    max-width: 100%;
  }

  .to-mobile-sidebar-backdrop {
    position: fixed;
    inset: 0;
    /* Below the drawer, not above it. Unfold's drawer is `fixed` with no
     * z-index, and `position: fixed` creates a stacking context on its own, so
     * the drawer sits at z-index auto (0) inside its wrapper -- the z-30 on its
     * child is trapped inside that context and cannot lift it. A backdrop at
     * z-index 20 therefore painted over the drawer, leaving a full grey screen
     * with no navigation on it. Matching z-index 0 and coming first in DOM
     * order puts the backdrop behind, which is what a backdrop is for. */
    z-index: 0;
    border: 0;
    padding: 0;
    background: rgba(37, 33, 29, 0.38);
    cursor: pointer;
  }

  .to-mobile-sidebar-backdrop[hidden] {
    display: none;
  }
}

@media (max-width: 640px) {
  #main > .bg-white > .container,
  #main > .px-4 {
    padding-left: 0.75rem;
    padding-right: 0.75rem;
  }

  #header-inner {
    align-items: flex-start;
    flex-wrap: wrap;
    gap: 0.5rem;
  }

  #header-inner > div {
    min-width: 0;
  }

  #header-inner h1 {
    max-width: calc(100vw - 7rem);
    overflow: hidden;
    text-overflow: ellipsis;
  }

  #header-inner .ml-auto {
    width: 100%;
    margin-left: 0;
    justify-content: flex-end;
    gap: 0.5rem;
  }

  .tr-table,
  .ts-form-grid,
  .hub-page-wrap {
    max-width: 100%;
  }

  .tr-table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
}

/* Sidebar brand icon (SITE_ICON): round the app icon's corners to match the
   portal's 10px radius. Matches the hashed filename in production too. */
img[src*="trial/admin/img/app-icon"] {
  border-radius: 10px;
}
