/*
 * Portal colour themes (light and dark). Loaded by the portal, the Task tracker and
 * Tracker admin, after /shared/base.css. The public website does not load this file,
 * so it stays light.
 *
 * theme-init.js sets <html data-theme="light|dark"> before first paint.
 * Paper stays white in both themes: document and deck previews, P&ID sheets, the
 * whiteboard canvas (user-chosen note colours) and anything printed or exported.
 */

/* ---------- Portal-only tokens (light values) ---------- */
:root {
  --ink-3: #626973;                 /* muted text: 4.9:1 on the page background, 5.5:1 on white (base.css: #8a919c) */
  --scarlet-ink: #ba0c2f;           /* scarlet used as text on a surface */
  --surface-3: #fcfcfd;             /* sub-rows, quiet stripes */
  --hover: #fafbfc;                 /* row hover */
  --on-dark: #ffffff;
  --overlay: rgba(17, 24, 39, .45);
  --focus: #ba0c2f;                 /* focus ring: 6.6:1 on white (WCAG non-text 3:1) */
  --toast-bg: #1f2328;
  --toast-error: #b91c1c;
  --btn-danger-line: #f1c2c2;
  --btn-danger-hover: #fdf0f0;
  /* paper and canvases: always light */
  --paper: #ffffff;
  --paper-ink: #1f1f1f;
  --paper-desk: #e6e8ea;
  --canvas: #f7f8f9;
  --canvas-dot: #cfd4d8;
  /* sidebar: dark in both themes */
  --side-bg: #2b2f30;
  --side-ink: #d6d9de;
  --side-ink-strong: #ffffff;
  --side-ink-2: #9ea5ae;
  --side-hover: #3f4443;
  --side-line: #3f4443;
  /* status tints (badges, chips, notices) */
  --red-tint: #fde8e8;    --red-ink: #b91c1c;
  --amber-tint: #fdf1dc;  --amber-ink: #8a5205;  --amber-line: #f3d19e;  --amber-soft: #fffaf0;
  --blue-tint: #e3ecfd;   --blue-ink: #1d4ed8;
  --green-tint: #e0f4e6;  --green-ink: #166534;
  --grey-tint: #eceef1;   --grey-ink: #4b5563;
  --indigo-tint: #e0e7ff; --indigo-ink: #3730a3;
  /* banner notifications */
  --banner-info-bg: #e8f1fb;    --banner-info-ink: #123a63;
  --banner-success-bg: #e7f6ec; --banner-success-ink: #14532d;
  --banner-warning-bg: #fff5d6; --banner-warning-ink: #6b4a00;
  --banner-urgent-bg: #ba0c2f;  --banner-urgent-ink: #ffffff;
  /* review diffs */
  --diff-add: #15803d;
  --diff-del: #b91c1c;
}

/* ---------- Dark (screen only: printing always uses the light values) ---------- */
@media screen {
  :root[data-theme="dark"] {
    color-scheme: dark;
    --bg: #1b1d1f;
    --surface: #26292c;
    --surface-2: #303336;
    --surface-3: #2a2d30;
    --ink: #eef0f2;
    --ink-2: #c4cad0;
    --ink-3: #a0a8ae;
    --line: #3c4044;
    --line-2: #565c61;
    --grey: #6b7378;
    --grey-dark: #d9dee1;     /* headings */
    --grey-darker: #141517;   /* sidebar */
    --scarlet: #ba0c2f;       /* fills keep the brand colour (white text stays AA) */
    --scarlet-dark: #8f0922;
    --scarlet-tint: #45121c;
    --scarlet-ink: #ff8fa3;
    --accent: #ba0c2f;
    --blue: #8ab4ff;
    --green: #4ade80;
    --amber: #fbbf24;
    --red: #fb8080;
    --axis: #3f4443;
    --shadow: 0 1px 2px rgba(0, 0, 0, .45), 0 4px 14px rgba(0, 0, 0, .35);
    --hover: #2d3034;
    --overlay: rgba(0, 0, 0, .62);
    --focus: #ff8fa3;
    --toast-bg: #3f4443;
    --toast-error: #a31a1a;
    --btn-danger-line: #74302f;
    --btn-danger-hover: #3a1f20;
    --paper-desk: #3a3e42;
    --side-bg: #141517;
    --side-hover: #2c3033;
    --side-line: #2c3033;
    --red-tint: #4a1d20;    --red-ink: #ffb4b4;
    --amber-tint: #43320c;  --amber-ink: #fcd58a;  --amber-line: #7a5a1a;  --amber-soft: #2f2710;
    --blue-tint: #1b2d4d;   --blue-ink: #b9d1ff;
    --green-tint: #153823;  --green-ink: #a2e9bd;
    --grey-tint: #34383c;   --grey-ink: #d0d6db;
    --indigo-tint: #292b55; --indigo-ink: #c9ccff;
    --banner-info-bg: #16304d;    --banner-info-ink: #d8e9fc;
    --banner-success-bg: #153823; --banner-success-ink: #cdeed8;
    --banner-warning-bg: #41340b; --banner-warning-ink: #ffe9a8;
    --banner-urgent-bg: #ba0c2f;  --banner-urgent-ink: #ffffff;
    --diff-add: #6ee7a0;
    --diff-del: #ff9b9b;
  }

  /* Paper and canvases keep light colours inside the dark UI (like Word's dark mode). */
  :root[data-theme="dark"] :is(.wb-viewport, .pid-stage, .pid-preview, .pid-sym, .docpage, .slide, .paper-light) {
    color-scheme: light;
    --surface: #ffffff; --surface-2: #eceeef; --surface-3: #fcfcfd; --bg: #f1f2f3;
    --ink: #1f2328; --ink-2: #4b5563; --ink-3: #6b7280;
    --line: #dcdfe1; --line-2: #c3c9cd;
    --grey-dark: #3f4443; --grey-darker: #2b2f30;
    --blue: #2563eb; --green: #16a34a; --amber: #d97706; --red: #b91c1c;
    --scarlet-ink: #ba0c2f; --scarlet-tint: #fbeef1;
    color: var(--ink);
  }
}

/* ---------- base.css components switched to tokens (portal pages only) ---------- */
.btn.danger { border-color: var(--btn-danger-line); }
.btn.danger:hover { background: var(--btn-danger-hover); }
.btn.primary, .btn.primary:hover { color: var(--on-dark); }
.badge.red { background: var(--red-tint); color: var(--red-ink); }
.badge.amber { background: var(--amber-tint); color: var(--amber-ink); }
.badge.blue { background: var(--blue-tint); color: var(--blue-ink); }
.badge.green { background: var(--green-tint); color: var(--green-ink); }
.badge.gray { background: var(--grey-tint); color: var(--grey-ink); }
input:focus, select:focus, textarea:focus, .btn:focus-visible { outline-color: var(--focus); }
.modal-back { background: var(--overlay); }
.toast { background: var(--toast-bg); color: var(--on-dark); }
.toast.error { background: var(--toast-error); }
.login h1, .tabs button.active { color: var(--scarlet-ink); }
.tl-today-label, .agenda-day .d.today { color: var(--scarlet-ink); }
.cal-dows { background: var(--axis); }
.cal-day.click:hover, table.data tr.click:hover td { background: var(--hover); }
.cal-day.other { background: var(--surface-3); }
.tl-label:not(.inside) { background: color-mix(in srgb, var(--surface) 84%, transparent); }
.tl-grid-line { background: color-mix(in srgb, var(--ink) 7%, transparent); }

/* Muted text in the dark sidebar (and on the active scarlet link) */
.sidebar .muted { color: var(--side-ink-2); }
.sidebar a.active .muted { color: var(--on-dark); }

/* ---------- Theme switch ---------- */
.theme-toggle { display: inline-flex; align-items: center; gap: 6px; border: 0; background: transparent; color: inherit; cursor: pointer; padding: 6px 0; font-size: 13px; }
.theme-toggle:hover { color: var(--side-ink-strong); }
.theme-choice { display: inline-flex; gap: 2px; padding: 3px; border-radius: 8px; background: var(--surface-2); }
.theme-choice button { display: inline-flex; align-items: center; gap: 6px; border: 0; background: transparent; padding: 6px 12px; border-radius: 6px; cursor: pointer; color: var(--ink-2); }
.theme-choice button[aria-pressed="true"] { background: var(--surface); color: var(--ink); font-weight: 600; box-shadow: var(--shadow); }

@media (prefers-reduced-motion: no-preference) {
  body, .main, .card, .sidebar { transition: background-color .16s ease, color .16s ease, border-color .16s ease; }
}
