/* SanMarcSoft Comms Hub — Design System
   Built with Impeccable design principles:
   - OKLCH color space with tinted neutrals
   - 4pt spatial grid with semantic tokens
   - Mobile-first, touch-native
   - Reduced motion support
   - No AI slop: no purple gradients, no Inter, no cards-in-cards

   ════════════════════════════════════════════════════════════
   COLOUR & INTERACTION RULES — Non-Negotiable
   Violations of these rules produce broken UX. Read before editing.
   ════════════════════════════════════════════════════════════

   R1. NO WHITE TEXT ON HOVER — EVER.
       --color-text-primary (near-white in dark mode) must NEVER appear
       as a :hover colour. Hover text uses --color-text-hover (dark text
       on inverted bg) or stays at --color-text-secondary.

   R2. NAVIGATION HOVER = SWAP PATTERN.
       Sidebar/header nav links: on hover, the background becomes the
       text colour and vice versa.
       hover bg  = --color-surface-hover  (= text-secondary, oklch 0.70)
       hover text = --color-text-hover     (= surface-0, oklch 0.15)
       Active/current page: brand bg + brand-text (full colour).

   R3. BUTTONS & INTERACTIVE ELEMENTS = SUBTLE HOVER.
       bg → --color-surface-hover-subtle (= surface-3, oklch 0.28)
       text stays --color-text-secondary. No colour jump.

   R4. BRAND ELEMENTS HOVER TO BRAND-BRIGHT.
       btn-primary, cta-button: hover bg → --color-brand-bright.
       Text stays --color-brand-text. Never changes.

   R5. MINIMUM HOVER DELTA = 0.10 OKLCH LIGHTNESS.
       The bg lightness difference between normal and hover states must
       be >= 0.10 in OKLCH L. Anything less is imperceptible.
       surface-0 (0.15) → hover-subtle (0.28) = 0.13 ✓
       surface-1 (0.19) → hover (0.70) = 0.51 ✓
       surface-1 (0.19) → surface-2 (0.23) = 0.04 ✗ BANNED

   R6. EVERY TAILWIND UTILITY CLASS MUST HAVE A CSS OVERRIDE.
       If you use hover:text-foo or hover:bg-bar in HTML/JS, a matching
       .hover\:text-foo:hover {} rule MUST exist in the "Hover overrides"
       section below. No orphaned Tailwind classes. Same for static
       classes: .text-foo, .bg-foo must have overrides here.

   R7. NO HARDCODED OKLCH IN INTERACTIVE STATES.
       All :hover, :active, :focus colours must reference CSS variables
       (--color-*). Hardcoded oklch() values break when theme.js switches
       to light mode. Use oklch(from var(--token) ...) for derived colours.
       FIREFOX: oklch(from ...) is unsupported. Always add a pre-calculated
       fallback line BEFORE the oklch(from ...) line. CSS uses last valid value.

   R8. PREFER .text-primary OVER .text-white IN JS/HTML.
       The class .text-white is a legacy Tailwind name. Use .text-primary
       (same effect, semantic name). In JS-generated HTML, ALWAYS use
       .text-primary or .text-secondary — never .text-white.

   R9. SINGLE THEME — NO DYNAMIC COLOUR SWITCHING.
       The portal uses one professional dark theme. theme.js is a no-op
       stub that loads branding (logo, name) only. Never re-introduce
       dynamic colour switching — it caused FOUC, badge mismatches, and
       broken hover states across three production incidents.

   R10. ALL BADGE BACKGROUNDS USE var(--color-surface-2).
        Consistent neutral surface for all status badges. Colour
        differentiation comes from the TEXT colour (warning, success,
        info, brand), never the background.
*/

/* ===== DESIGN TOKENS ===== */

:root {
  /* --- Typography --- */
  --font-heading: 'DM Sans', system-ui, sans-serif;
  --font-body: 'Source Sans 3', system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, 'SF Mono', monospace;

  /* Modular type scale (1.25 ratio) */
  --text-xs: 0.75rem;    /* 12px */
  --text-sm: 0.875rem;   /* 14px */
  --text-base: 1rem;     /* 16px — minimum body */
  --text-lg: 1.25rem;    /* 20px */
  --text-xl: 1.5rem;     /* 24px */
  --text-2xl: 1.875rem;  /* 30px */
  --text-3xl: 2.25rem;   /* 36px */

  --leading-tight: 1.25;
  --leading-normal: 1.5;
  --leading-relaxed: 1.7;

  --weight-regular: 400;
  --weight-medium: 500;
  --weight-semibold: 600;
  --weight-bold: 700;

  /* --- Spatial grid (4pt base) --- */
  --space-1: 0.25rem;   /* 4px */
  --space-2: 0.5rem;    /* 8px */
  --space-3: 0.75rem;   /* 12px */
  --space-4: 1rem;      /* 16px */
  --space-6: 1.5rem;    /* 24px */
  --space-8: 2rem;      /* 32px */
  --space-12: 3rem;     /* 48px */
  --space-16: 4rem;     /* 64px */
  --space-24: 6rem;     /* 96px */

  /* --- Colors: OKLCH with tinted neutrals --- */
  /* Brand: warm amber — intentional, not default blue */
  --color-brand: oklch(0.75 0.15 70);
  --color-brand-dim: oklch(0.55 0.12 70);
  --color-brand-bright: oklch(0.85 0.12 70);
  --color-brand-subtle: oklch(0.30 0.04 70);
  --color-brand-text: oklch(0.15 0.01 70);  /* contrast text on brand bg — auto-set by theme.js */

  /* Tinted neutrals — warm undertone, never pure gray */
  --color-surface-0: oklch(0.15 0.01 70);   /* deepest bg */
  --color-surface-1: oklch(0.19 0.01 70);   /* card/panel bg */
  --color-surface-2: oklch(0.23 0.01 70);   /* elevated surface */
  --color-surface-3: oklch(0.28 0.01 70);   /* hover state */

  --color-border: oklch(0.32 0.01 70);
  --color-border-subtle: oklch(0.25 0.01 70);

  --color-text-primary: oklch(0.93 0.01 70);
  --color-text-secondary: oklch(0.70 0.01 70);
  --color-text-tertiary: oklch(0.58 0.01 70);  /* 0.52→0.58: pass 3:1 on surface-3 hover */

  /* Semantic */
  --color-success: oklch(0.72 0.17 145);
  --color-warning: oklch(0.78 0.15 80);
  --color-error: oklch(0.65 0.2 25);
  --color-info: oklch(0.70 0.12 240);

  /* Priority system */
  --color-priority-critical: oklch(0.637 0.237 25.331);   /* red — overdue */
  --color-priority-high: oklch(0.769 0.188 70.08);        /* amber — due today */
  --color-priority-medium: oklch(0.768 0.166 130.85);     /* green — on track */
  --color-priority-low: oklch(0.556 0.024 264.364);       /* slate — completed/low */

  /* Priority backgrounds (subtle) */
  --color-priority-critical-bg: oklch(0.637 0.237 25.331 / 0.1);
  --color-priority-high-bg: oklch(0.769 0.188 70.08 / 0.1);
  --color-priority-medium-bg: oklch(0.768 0.166 130.85 / 0.1);
  --color-priority-low-bg: oklch(0.556 0.024 264.364 / 0.1);

  /* Interactive hover — swap pattern: text↔bg inversion */
  --color-surface-hover: var(--color-text-secondary);   /* bg becomes the old text colour */
  --color-text-hover: var(--color-surface-0);            /* text becomes the old bg colour */
  --color-border-hover: var(--color-text-tertiary);

  /* Subtle hover — for cards/rows that shouldn't fully invert */
  --color-surface-hover-subtle: var(--color-surface-3);

  /* Primary alias for generic component use */
  --color-primary: var(--color-brand);

  /* --- Radius --- */
  --radius-sm: 0.375rem;  /* 6px */
  --radius-md: 0.5rem;    /* 8px */
  --radius-lg: 0.75rem;   /* 12px */
  --radius-xl: 1rem;      /* 16px */
  --radius-full: 9999px;

  /* --- Shadows (using lighter surfaces for depth in dark mode) --- */
  --shadow-sm: 0 1px 2px oklch(0 0 0 / 0.3);
  --shadow-md: 0 4px 12px oklch(0 0 0 / 0.4);
  --shadow-lg: 0 8px 24px oklch(0 0 0 / 0.5);

  /* --- Motion --- */
  --duration-instant: 100ms;
  --duration-fast: 200ms;
  --duration-normal: 300ms;
  --duration-slow: 500ms;
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-in: cubic-bezier(0.7, 0, 1, 0.5);
  --ease-in-out: cubic-bezier(0.65, 0, 0.35, 1);

  /* --- Layout --- */
  --content-width: 42rem;    /* ~672px — optimal reading */
  --sidebar-width: 16rem;    /* 256px */
  --bottom-nav-height: 3.5rem;
  --header-height: 3.5rem;
  --touch-target: 2.75rem;   /* 44px minimum */
}

/* ===== REDUCED MOTION ===== */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ===== RESET & BASE ===== */

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 100%; /* 16px base — never smaller */
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: var(--font-body);
  font-size: var(--text-base);
  line-height: var(--leading-normal);
  color: var(--color-text-primary);
  background-color: var(--color-surface-0);
  min-height: 100dvh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ===== TYPOGRAPHY ===== */

h1, h2, h3, h4 {
  font-family: var(--font-heading);
  font-weight: var(--weight-bold);
  line-height: var(--leading-tight);
  color: var(--color-text-primary);
}

h1 { font-size: var(--text-2xl); }
h2 { font-size: var(--text-xl); }
h3 { font-size: var(--text-lg); }
h4 { font-size: var(--text-base); font-weight: var(--weight-semibold); }

p { margin-bottom: var(--space-4); }
p:last-child { margin-bottom: 0; }

a {
  color: var(--color-brand);
  text-decoration: none;
  transition: color var(--duration-instant);
}
a:hover { color: var(--color-brand-bright); }

/* Focus-visible only — keyboard users */
:focus-visible {
  outline: 2px solid var(--color-brand);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

:focus:not(:focus-visible) {
  outline: none;
}

/* ===== LAYOUT: PUBLIC PAGES ===== */

.page-shell {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.page-header {
  position: sticky;
  top: 0;
  z-index: 20;
  height: var(--header-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-inline: var(--space-4);
  background-color: var(--color-surface-1);
  border-bottom: 1px solid var(--color-border-subtle);
  backdrop-filter: blur(12px);
}

.page-header .logo {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  text-decoration: none;
  color: var(--color-text-primary);
}

.page-header .logo-mark {
  width: 2rem;
  height: 2rem;
  border-radius: var(--radius-md);
  background-color: var(--color-brand);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-brand-text, oklch(0.15 0 0));
  font-family: var(--font-heading);
  font-weight: var(--weight-bold);
  font-size: var(--text-sm);
}

.page-header .logo-text {
  font-family: var(--font-heading);
  font-weight: var(--weight-bold);
  font-size: var(--text-base);
}

.page-header nav {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.page-header nav a {
  display: inline-flex;
  align-items: center;
  min-height: var(--touch-target);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: var(--color-text-secondary);
  transition: color var(--duration-instant), background-color var(--duration-instant);
}

.page-header nav a:hover {
  color: var(--color-text-hover);
  background-color: var(--color-surface-hover);
}

.page-header nav a[aria-current="page"] {
  color: var(--color-brand-text);
  background-color: var(--color-brand);
}

.page-main {
  flex: 1;
  width: 100%;
  max-width: var(--content-width);
  margin-inline: auto;
  padding: var(--space-6) var(--space-4);
}

@media (min-width: 640px) {
  .page-main {
    padding: var(--space-8) var(--space-6);
  }
}

.page-footer {
  padding: var(--space-4);
  text-align: center;
  font-size: var(--text-xs);
  color: var(--color-text-tertiary);
  border-top: 1px solid var(--color-border-subtle);
}

/* ===== LANDING PAGE ===== */

.landing {
  padding-top: var(--space-12);
  padding-bottom: var(--space-12);
}

.landing-header {
  margin-bottom: var(--space-12);
}

.landing-header h1 {
  font-size: var(--text-3xl);
  margin-bottom: var(--space-3);
  letter-spacing: -0.02em;
}

.landing-tagline {
  font-size: var(--text-lg);
  color: var(--color-text-secondary);
  max-width: 32rem;
}

.client-directory {
  margin-bottom: var(--space-12);
}

.client-directory h2 {
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  color: var(--color-text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: var(--space-4);
}

.client-list {
  list-style: none;
  display: grid;
  gap: var(--space-3);
}

@media (min-width: 640px) {
  .client-list {
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  }
}

.client-list li a {
  display: block;
  padding: var(--space-6);
  background-color: var(--color-surface-1);
  border: 1px solid var(--color-border-subtle);
  border-radius: var(--radius-lg);
  color: var(--color-text-primary);
  transition: border-color var(--duration-fast) var(--ease-out),
              transform var(--duration-fast) var(--ease-out);
  -webkit-tap-highlight-color: transparent;
}

.client-list li a:hover {
  border-color: var(--color-brand-dim);
  transform: translateY(-1px);
}

.client-list li a:active {
  transform: scale(0.98);
}

.client-list li h3 {
  font-size: var(--text-lg);
  margin-bottom: var(--space-2);
}

.client-list li p {
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
  margin-bottom: var(--space-3);
}

.item-count {
  font-size: var(--text-xs);
  color: var(--color-text-tertiary);
  font-weight: var(--weight-medium);
}

.portal-cta {
  padding: var(--space-8);
  background-color: var(--color-surface-1);
  border: 1px solid var(--color-border-subtle);
  border-radius: var(--radius-lg);
  text-align: left;
}

.portal-cta p {
  color: var(--color-text-secondary);
  margin-bottom: var(--space-4);
}

.cta-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--touch-target);
  padding: var(--space-3) var(--space-6);
  background-color: var(--color-brand);
  color: var(--color-brand-text, oklch(0.15 0 0));
  font-family: var(--font-heading);
  font-weight: var(--weight-semibold);
  font-size: var(--text-sm);
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background-color var(--duration-instant);
  -webkit-tap-highlight-color: transparent;
}

.cta-button:hover {
  background-color: var(--color-brand-bright);
  color: var(--color-brand-text, oklch(0.15 0 0));
}

.cta-button:active {
  transform: scale(0.97);
}

.cta-authenticated {
  background-color: var(--color-brand-dim);
}

.cta-authenticated:hover {
  background-color: var(--color-brand);
}

/* --- Landing auth indicator --- */

#landing-user-indicator {
  align-items: center;
}

.user-indicator {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: var(--color-text-secondary);
  text-decoration: none;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  transition: color var(--duration-instant), background-color var(--duration-instant);
}

.user-indicator:hover {
  color: var(--color-text-secondary);
  background-color: var(--color-surface-hover-subtle);
}

.user-avatar {
  width: 1.5rem;
  height: 1.5rem;
  border-radius: 50%;
  object-fit: cover;
}

/* ===== NEWS FEED ===== */

.news-feed {
  padding-bottom: var(--space-8);
}

.news-header {
  margin-bottom: var(--space-8);
}

.news-header h1 {
  font-size: var(--text-2xl);
  margin-bottom: var(--space-2);
}

.news-description {
  color: var(--color-text-secondary);
  font-size: var(--text-base);
}

.news-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.news-item {
  padding: var(--space-4) 0;
  border-bottom: 1px solid var(--color-border-subtle);
}

.news-item:first-child {
  padding-top: 0;
}

.news-item time {
  display: block;
  font-size: var(--text-xs);
  color: var(--color-text-tertiary);
  font-weight: var(--weight-medium);
  margin-bottom: var(--space-1);
  font-variant-numeric: tabular-nums;
}

.news-type-badge {
  display: inline-block;
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  color: var(--color-brand);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: var(--space-2);
}

.news-item h2 {
  font-size: var(--text-lg);
  margin-bottom: var(--space-2);
}

.news-item h2 a {
  color: var(--color-text-primary);
}

.news-item h2 a:hover {
  color: var(--color-brand);
}

.news-excerpt {
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
  line-height: var(--leading-relaxed);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.news-repos {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin-top: var(--space-3);
}

.repo-tag {
  display: inline-block;
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  color: var(--color-text-tertiary);
  background-color: var(--color-surface-2);
  padding: var(--space-1) var(--space-2);
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
}

/* ===== NEWS ARTICLE ===== */

.news-article {
  padding-bottom: var(--space-12);
}

.news-article-header {
  margin-bottom: var(--space-8);
  padding-bottom: var(--space-6);
  border-bottom: 1px solid var(--color-border-subtle);
}

.back-link {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  min-height: var(--touch-target);
  font-size: var(--text-sm);
  color: var(--color-text-tertiary);
  margin-bottom: var(--space-4);
}

.back-link::before {
  content: '\2190'; /* left arrow */
}

.back-link:hover {
  color: var(--color-brand);
}

.news-article-header time {
  display: block;
  font-size: var(--text-sm);
  color: var(--color-text-tertiary);
  font-variant-numeric: tabular-nums;
  margin-bottom: var(--space-2);
}

.news-article-header h1 {
  font-size: var(--text-2xl);
  margin-top: var(--space-3);
  margin-bottom: var(--space-3);
  letter-spacing: -0.01em;
}

.news-lede {
  font-size: var(--text-lg);
  color: var(--color-text-secondary);
  line-height: var(--leading-relaxed);
}

/* Article body — clean reading experience */
.news-body {
  font-size: var(--text-base);
  line-height: var(--leading-relaxed);
  max-width: var(--content-width);
}

.news-body h2 {
  font-size: var(--text-xl);
  margin-top: var(--space-8);
  margin-bottom: var(--space-4);
}

.news-body h3 {
  font-size: var(--text-lg);
  margin-top: var(--space-6);
  margin-bottom: var(--space-3);
}

.news-body p {
  margin-bottom: var(--space-4);
}

.news-body ul, .news-body ol {
  padding-left: var(--space-6);
  margin-bottom: var(--space-4);
}

.news-body li {
  margin-bottom: var(--space-2);
}

.news-body code {
  font-family: var(--font-mono);
  font-size: 0.9em;
  background-color: var(--color-surface-2);
  padding: 0.1em 0.35em;
  border-radius: var(--radius-sm);
}

.news-body pre {
  background-color: var(--color-surface-1);
  border: 1px solid var(--color-border-subtle);
  border-radius: var(--radius-md);
  padding: var(--space-4);
  overflow-x: auto;
  margin-bottom: var(--space-4);
}

.news-body pre code {
  background: none;
  padding: 0;
}

.news-body blockquote {
  border-left: 3px solid var(--color-brand-dim);
  padding-left: var(--space-4);
  margin: var(--space-4) 0;
  color: var(--color-text-secondary);
}

.news-body img {
  max-width: 100%;
  height: auto;
  border-radius: var(--radius-md);
}

.news-footer {
  margin-top: var(--space-8);
  padding-top: var(--space-6);
  border-top: 1px solid var(--color-border-subtle);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
}

.repos-label {
  font-size: var(--text-xs);
  color: var(--color-text-tertiary);
  font-weight: var(--weight-medium);
  margin-right: var(--space-2);
}

.share-button {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  min-height: var(--touch-target);
  padding: var(--space-2) var(--space-4);
  background: none;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  color: var(--color-text-secondary);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  font-family: var(--font-body);
  cursor: pointer;
  transition: border-color var(--duration-instant), color var(--duration-instant);
  -webkit-tap-highlight-color: transparent;
}

.share-button:hover {
  border-color: var(--color-brand-dim);
  color: var(--color-text-secondary);
  background-color: var(--color-surface-hover-subtle);
}

.share-button:active {
  transform: scale(0.97);
}

/* ===== CLIENT PORTAL LAYOUT ===== */

/* On mobile: bottom nav bar, no sidebar */
/* On desktop: sidebar nav */

.portal-shell {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* Mobile bottom nav */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 30;
  height: var(--bottom-nav-height);
  display: flex;
  align-items: stretch;
  background-color: var(--color-surface-1);
  border-top: 1px solid var(--color-border-subtle);
  padding-bottom: env(safe-area-inset-bottom, 0);
}

.bottom-nav a {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-height: var(--touch-target);
  color: var(--color-text-tertiary);
  font-size: 0.625rem;
  font-weight: var(--weight-medium);
  text-decoration: none;
  transition: color var(--duration-instant);
  -webkit-tap-highlight-color: transparent;
}

.bottom-nav a svg {
  width: 1.25rem;
  height: 1.25rem;
}

.bottom-nav a[aria-current="page"],
.bottom-nav a.active {
  color: var(--color-brand);
}

.bottom-nav a:active {
  color: var(--color-brand);
}

@media (min-width: 768px) {
  .bottom-nav {
    display: none;
  }
}

/* Desktop sidebar */
.portal-sidebar {
  display: none;
}

@media (min-width: 768px) {
  .portal-sidebar {
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: var(--sidebar-width);
    background-color: var(--color-surface-1);
    border-right: 1px solid var(--color-border-subtle);
    z-index: 20;
  }
}

.portal-sidebar-header {
  padding: var(--space-4) var(--space-4);
  border-bottom: 1px solid var(--color-border-subtle);
}

.portal-sidebar-header a {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  color: var(--color-text-primary);
}

.portal-sidebar-header .logo-mark {
  width: 2rem;
  height: 2rem;
  border-radius: var(--radius-md);
  background-color: var(--color-brand);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-brand-text, oklch(0.15 0 0));
  font-family: var(--font-heading);
  font-weight: var(--weight-bold);
  font-size: var(--text-sm);
  flex-shrink: 0;
}

.portal-sidebar-header .logo-text {
  font-family: var(--font-heading);
  font-weight: var(--weight-bold);
  font-size: var(--text-sm);
}

.portal-sidebar nav {
  flex: 1;
  padding: var(--space-3);
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.portal-sidebar nav a {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-height: var(--touch-target);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: var(--color-text-secondary);
  transition: color var(--duration-instant), background-color var(--duration-instant);
}

.portal-sidebar nav a:hover {
  color: var(--color-text-hover);
  background-color: var(--color-surface-hover);
}

.portal-sidebar nav a[aria-current="page"] {
  color: var(--color-brand-text);
  background-color: var(--color-brand);
}

.portal-sidebar nav a[aria-current="page"]:hover {
  color: var(--color-brand-text);
  background-color: var(--color-brand-bright);
}

.portal-sidebar nav a svg {
  width: 1.25rem;
  height: 1.25rem;
  flex-shrink: 0;
}

.portal-sidebar-footer {
  padding: var(--space-3) var(--space-4);
  border-top: 1px solid var(--color-border-subtle);
}

/* Portal main content area */
.portal-content {
  flex: 1;
  padding: var(--space-4);
  padding-bottom: calc(var(--bottom-nav-height) + var(--space-4) + env(safe-area-inset-bottom, 0));
}

@media (min-width: 768px) {
  .portal-content {
    margin-left: var(--sidebar-width);
    padding: var(--space-6);
    padding-bottom: var(--space-6);
  }
}

.portal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-6);
}

.portal-header h1 {
  font-size: var(--text-xl);
}

/* ===== BUTTONS (PORTAL) ===== */

.btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: var(--touch-target);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  background-color: var(--color-brand);
  color: var(--color-brand-text, oklch(0.15 0 0));
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  font-family: var(--font-heading);
  border: none;
  cursor: pointer;
  transition: background-color var(--duration-instant);
  -webkit-tap-highlight-color: transparent;
}

.btn-primary:hover { background-color: var(--color-brand-bright); }
.btn-primary:active { transform: scale(0.97); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-secondary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: var(--touch-target);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  background: none;
  color: var(--color-text-secondary);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  font-family: var(--font-body);
  border: 1px solid var(--color-border);
  cursor: pointer;
  transition: border-color var(--duration-instant), color var(--duration-instant);
  -webkit-tap-highlight-color: transparent;
}

.btn-secondary:hover {
  border-color: var(--color-text-secondary);
  color: var(--color-text-secondary);
  background-color: var(--color-surface-hover-subtle);
}
.btn-secondary:active { transform: scale(0.97); }
.btn-secondary:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-danger {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: var(--touch-target);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  background: none;
  color: var(--color-error);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  font-family: var(--font-body);
  border: 1px solid oklch(0.65 0.2 25 / 0.4);
  border: 1px solid oklch(from var(--color-error) l c h / 0.4);
  cursor: pointer;
  transition: background-color var(--duration-instant);
  -webkit-tap-highlight-color: transparent;
}

.btn-danger:hover {
  background-color: oklch(0.65 0.2 25 / 0.15);
  background-color: oklch(from var(--color-error) l c h / 0.15);
  border-color: var(--color-error);
}

/* ===== CARDS & SURFACES ===== */

.card {
  background-color: var(--color-surface-1);
  border: 1px solid var(--color-border-subtle);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
}

/* ===== STAT CARDS ===== */

.stat-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--space-3);
}

@media (min-width: 640px) {
  .stat-grid {
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  }
}

.stat-card {
  background-color: var(--color-surface-1);
  border: 1px solid var(--color-border-subtle);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
}

.stat-value {
  font-family: var(--font-heading);
  font-size: var(--text-2xl);
  font-weight: var(--weight-bold);
  font-variant-numeric: tabular-nums;
}

.stat-label {
  font-size: var(--text-xs);
  color: var(--color-text-tertiary);
  font-weight: var(--weight-medium);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-top: var(--space-1);
}

/* ===== FORM CONTROLS ===== */

.input,
.select,
.textarea {
  width: 100%;
  background-color: var(--color-surface-0);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-3);
  min-height: var(--touch-target);
  color: var(--color-text-primary);
  font-size: var(--text-base); /* prevent iOS zoom */
  font-family: var(--font-body);
  transition: border-color var(--duration-instant);
}

.input:focus,
.select:focus,
.textarea:focus {
  outline: none;
  border-color: var(--color-brand);
}

.textarea {
  resize: vertical;
  min-height: 7.5rem;
}

label {
  display: block;
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: var(--color-text-secondary);
  margin-bottom: var(--space-2);
}

/* ===== BADGES ===== */

.badge {
  display: inline-flex;
  align-items: center;
  padding: var(--space-1) var(--space-2);
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  white-space: nowrap;
}

.badge-draft     { background-color: var(--color-surface-2); color: var(--color-text-tertiary); }
.badge-review    { background-color: var(--color-surface-2); color: var(--color-warning); }
.badge-approved  { background-color: var(--color-surface-2); color: var(--color-success); }
.badge-scheduled { background-color: var(--color-surface-2); color: var(--color-info); }
.badge-published { background-color: var(--color-surface-2); color: var(--color-brand-bright); }
.badge-sent      { background-color: var(--color-surface-2); color: var(--color-brand-bright); }

/* ===== CONTENT ROWS ===== */

.content-row {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--color-border-subtle);
  cursor: pointer;
  transition: background-color var(--duration-instant);
  -webkit-tap-highlight-color: transparent;
}

.content-row:hover {
  background-color: var(--color-surface-hover-subtle);
}

.content-row:active {
  background-color: var(--color-surface-2);
}

/* ===== BOTTOM SHEET (mobile detail panel) ===== */

.bottom-sheet {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: flex-end;
  background: oklch(0 0 0 / 0.5);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--duration-normal) var(--ease-out);
}

.bottom-sheet.open {
  opacity: 1;
  pointer-events: auto;
}

.bottom-sheet-content {
  width: 100%;
  max-height: 85dvh;
  overflow-y: auto;
  background-color: var(--color-surface-1);
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  padding: var(--space-6) var(--space-4) calc(var(--space-6) + env(safe-area-inset-bottom, 0));
  transform: translateY(100%);
  transition: transform var(--duration-normal) var(--ease-out);
}

.bottom-sheet.open .bottom-sheet-content {
  transform: translateY(0);
}

.bottom-sheet-handle {
  width: 2.5rem;
  height: 0.25rem;
  background-color: var(--color-border);
  border-radius: var(--radius-full);
  margin: 0 auto var(--space-4);
}

@media (min-width: 768px) {
  .bottom-sheet {
    align-items: center;
    justify-content: center;
  }
  .bottom-sheet-content {
    max-width: 40rem;
    max-height: 80vh;
    border-radius: var(--radius-xl);
    margin: var(--space-4);
    padding: var(--space-6);
    transform: translateY(1rem);
  }
  .bottom-sheet.open .bottom-sheet-content {
    transform: translateY(0);
  }
}

/* ===== SKELETON LOADING ===== */

@keyframes skeleton-pulse {
  0%, 100% { opacity: 0.4; }
  50% { opacity: 0.8; }
}

.skeleton {
  background-color: var(--color-surface-2);
  border-radius: var(--radius-md);
  animation: skeleton-pulse 1.5s ease-in-out infinite;
}

.skeleton-text {
  height: 1em;
  margin-bottom: var(--space-2);
}

.skeleton-text:last-child {
  width: 60%;
}

.skeleton-card {
  height: 5rem;
}

/* ===== PROGRESS BAR ===== */

.progress-track {
  width: 100%;
  height: 6px;
  background-color: var(--color-surface-2);
  border-radius: var(--radius-full);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background-color: var(--color-brand);
  border-radius: var(--radius-full);
  transition: width var(--duration-slow) var(--ease-out);
}

/* ===== SECTION HEADERS ===== */

.section-label {
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  color: var(--color-text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: var(--space-3);
}

/* ===== UTILITY ===== */

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}

/* Flex/Grid utilities — minimal set */
.flex { display: flex; }
.flex-col { flex-direction: column; }
.flex-1 { flex: 1; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: var(--space-2); }
.gap-3 { gap: var(--space-3); }
.gap-4 { gap: var(--space-4); }
.gap-6 { gap: var(--space-6); }

.grid { display: grid; }

.hidden { display: none; }

.mb-3 { margin-bottom: var(--space-3); }
.mb-4 { margin-bottom: var(--space-4); }
.mb-6 { margin-bottom: var(--space-6); }

.space-y-2 > * + * { margin-top: var(--space-2); }
.space-y-3 > * + * { margin-top: var(--space-3); }

/* Safe areas for notched devices */
@supports (padding: env(safe-area-inset-bottom)) {
  .bottom-nav {
    padding-bottom: env(safe-area-inset-bottom);
  }
}

/* ===== FRESHNESS INDICATORS ===== */

.freshness-badge {
  font-size: var(--text-xs);
  padding: 0.125rem 0.5rem;
  border-radius: var(--radius-full);
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
}

.freshness-badge::before {
  content: '';
  width: 0.375rem;
  height: 0.375rem;
  border-radius: 50%;
}

.freshness-badge.fresh {
  color: var(--color-priority-medium);
}

.freshness-badge.fresh::before {
  background: var(--color-priority-medium);
}

.freshness-badge.stale {
  color: var(--color-priority-high);
}

.freshness-badge.stale::before {
  background: var(--color-priority-high);
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* ===== PRIORITY INDICATORS ===== */

.priority-dot {
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 50%;
  flex-shrink: 0;
}

.priority-dot.critical { background: var(--color-priority-critical); }
.priority-dot.high     { background: var(--color-priority-high); }
.priority-dot.medium   { background: var(--color-priority-medium); }
.priority-dot.low      { background: var(--color-priority-low); }

/* Action required card styling */
.action-card {
  border-left: 3px solid var(--color-priority-medium);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  background: var(--color-surface-1);
  transition: border-color var(--duration-fast);
}

.action-card.critical { border-left-color: var(--color-priority-critical); }
.action-card.high     { border-left-color: var(--color-priority-high); }

.action-card.overdue {
  border-left-color: var(--color-priority-critical);
  background: var(--color-priority-critical-bg);
}

/* ===== SECTION HEADER COMPONENT ===== */

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-3);
}

.section-header h2 {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-text-secondary);
}

.section-header .count-badge {
  font-size: var(--text-xs);
  padding: 0.125rem 0.5rem;
  border-radius: var(--radius-full);
  background: var(--color-primary);
  color: var(--color-brand-text, oklch(0.15 0 0));
  font-weight: var(--weight-semibold);
}

.section-header .refresh-btn {
  padding: var(--space-1);
  color: var(--color-text-tertiary);
  cursor: pointer;
  border: none;
  background: none;
  border-radius: var(--radius-sm);
  transition: color var(--duration-instant), background var(--duration-instant);
}

.section-header .refresh-btn:hover {
  color: var(--color-text-secondary);
  background: var(--color-surface-hover-subtle);
}

.section-header .refresh-btn.refreshing svg {
  animation: spin 1s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ===== INLINE ACTION BUTTONS ===== */

.inline-action {
  font-size: var(--text-xs);
  padding: 0.25rem 0.625rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--color-border);
  background: transparent;
  color: var(--color-text-secondary);
  cursor: pointer;
  transition: all var(--duration-instant);
  white-space: nowrap;
  font-family: var(--font-body);
  line-height: var(--leading-normal);
}

.inline-action:hover {
  background: var(--color-surface-hover-subtle);
  color: var(--color-text-secondary);
  border-color: var(--color-border-hover);
}

.inline-action:active {
  transform: scale(0.97);
}

.inline-action:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.inline-action.primary {
  background: var(--color-primary);
  color: var(--color-brand-text, oklch(0.15 0 0));
  border-color: var(--color-primary);
}

.inline-action.primary:hover {
  filter: brightness(1.1);
}

/* ===== POLISH: BUTTON FOCUS RINGS ===== */

.btn-primary:focus-visible,
.btn-secondary:focus-visible,
.btn-danger:focus-visible,
.cta-button:focus-visible,
.inline-action:focus-visible {
  outline: 2px solid var(--color-brand);
  outline-offset: 2px;
}

/* ===== POLISH: SKELETON REFINEMENT ===== */

.skeleton-row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
}

.skeleton-avatar {
  width: 2rem;
  height: 2rem;
  border-radius: var(--radius-full);
  flex-shrink: 0;
}

.skeleton-line {
  height: 0.75rem;
  border-radius: var(--radius-sm);
}

.skeleton-line.short { width: 40%; }
.skeleton-line.medium { width: 65%; }
.skeleton-line.long { width: 85%; }

/* ===== POLISH: CARD HOVER & TRANSITION ===== */

.card {
  transition: border-color var(--duration-fast) var(--ease-out),
              box-shadow var(--duration-fast) var(--ease-out);
}

.card:hover {
  border-color: var(--color-border);
}

.stat-card {
  transition: border-color var(--duration-fast) var(--ease-out),
              transform var(--duration-fast) var(--ease-out);
}

.stat-card:hover {
  border-color: var(--color-border);
  transform: translateY(-1px);
}

/* ===== POLISH: CONTENT ROW TOUCH FEEDBACK ===== */

.content-row {
  min-height: var(--touch-target);
}

/* ===== POLISH: BOTTOM NAV ACTIVE INDICATOR ===== */

.bottom-nav a {
  position: relative;
}

.bottom-nav a[aria-current="page"]::before,
.bottom-nav a.active::before {
  content: '';
  position: absolute;
  top: 0;
  left: 25%;
  right: 25%;
  height: 2px;
  background: var(--color-brand);
  border-radius: 0 0 var(--radius-full) var(--radius-full);
}

/* ===== POLISH: IMPROVED BADGE CONTRAST ===== */

.badge {
  line-height: 1;
  gap: var(--space-1);
}

/* ===== POLISH: PORTAL HEADER MOBILE SPACING ===== */

@media (max-width: 767px) {
  .portal-header h1 {
    font-size: var(--text-lg);
  }
}

/* ===== POLISH: SMOOTH SIDEBAR BORDER ON DESKTOP ===== */

@media (min-width: 768px) {
  .portal-sidebar {
    transition: width var(--duration-normal) var(--ease-out);
  }
}

/* ===== PRINT ===== */

@media print {
  .page-header,
  .page-footer,
  .bottom-nav,
  .portal-sidebar,
  .share-button {
    display: none;
  }
  body {
    background: white;
    color: black;
  }
}

/* ===== TAILWIND-COMPATIBLE UTILITY CLASSES =====
   Maps common Tailwind colour classes used in JS-rendered content
   to design system tokens for consistent contrast in all modes. */

/* Text colours — mapped to design system semantic tokens
   PREFER .text-primary/.text-secondary over .text-white/.text-slate-* */
.text-primary     { color: var(--color-text-primary); }
.text-secondary   { color: var(--color-text-secondary); }
.text-white       { color: var(--color-text-primary); }  /* legacy — use .text-primary */
.text-slate-300   { color: var(--color-text-primary); }
.text-slate-400   { color: var(--color-text-secondary); }
.text-slate-500   { color: var(--color-text-tertiary); }
.text-slate-600   { color: var(--color-text-tertiary); }
.text-blue-400    { color: var(--color-brand); }
.text-blue-500    { color: var(--color-brand); }
.text-red-400     { color: var(--color-error); }
.text-red-200     { color: var(--color-error); }
.text-green-400   { color: var(--color-success); }
.text-green-200   { color: var(--color-success); }
.text-amber-500   { color: var(--color-warning); }

/* Background colours */
.bg-slate-700     { background-color: var(--color-surface-2); }
.bg-slate-800     { background-color: var(--color-surface-1); }
.bg-slate-900     { background-color: var(--color-surface-0); }
.bg-slate-900\/50 { background-color: var(--color-surface-0); }
.bg-red-900\/30   { background-color: oklch(0.65 0.2 25 / 0.15); background-color: oklch(from var(--color-error) l c h / 0.15); }
.bg-green-900\/30 { background-color: oklch(0.72 0.17 145 / 0.15); background-color: oklch(from var(--color-success) l c h / 0.15); }
.bg-green-900\/90 { background-color: oklch(0.72 0.17 145 / 0.5); background-color: oklch(from var(--color-success) l c h / 0.5); }
.bg-red-900\/90   { background-color: oklch(0.65 0.2 25 / 0.5); background-color: oklch(from var(--color-error) l c h / 0.5); }
.bg-blue-900\/10  { background-color: oklch(0.75 0.15 70 / 0.1); background-color: oklch(from var(--color-brand) l c h / 0.1); }
.bg-amber-500     { background-color: var(--color-warning); }
.bg-green-500     { background-color: var(--color-success); }

/* Border colours */
.border-slate-600 { border-color: var(--color-border); }
.border-slate-700 { border-color: var(--color-border-subtle); }
.border-slate-800 { border-color: var(--color-border-subtle); }

/* Hover text overrides — never use white; use inverted bg colour or brand */
.hover\:text-white:hover        { color: var(--color-text-hover); }
.hover\:text-blue-300:hover     { color: var(--color-brand-bright); }
.hover\:text-blue-400:hover     { color: var(--color-brand); }
.hover\:text-red-400:hover      { color: var(--color-error); }
.hover\:text-green-300:hover    { color: var(--color-success); }
.hover\:text-slate-300:hover    { color: var(--color-text-hover); }
.hover\:underline:hover         { text-decoration: underline; }

/* Group hover — requires .group ancestor (Tailwind pattern) */
.group:hover .group-hover\:text-blue-400 { color: var(--color-brand); }

/* Hover background overrides */
.hover\:bg-slate-800:hover      { background-color: var(--color-surface-hover-subtle); }
.hover\:bg-slate-700:hover      { background-color: var(--color-surface-hover-subtle); }
.hover\:bg-slate-800\/80:hover  { background-color: oklch(0.28 0.01 70 / 0.8); background-color: oklch(from var(--color-surface-hover-subtle) l c h / 0.8); }
.hover\:bg-slate-800\/50:hover  { background-color: oklch(0.28 0.01 70 / 0.5); background-color: oklch(from var(--color-surface-hover-subtle) l c h / 0.5); }

/* Hover border overrides */
.hover\:border-slate-600:hover  { border-color: var(--color-border-hover); }

/* Accent colour for checkboxes */
.accent-blue-500 { accent-color: var(--color-brand); }

/* Sizing utilities (Tailwind-compatible) */
.w-1\.5  { width: 0.375rem; }
.h-1\.5  { height: 0.375rem; }
.w-2     { width: 0.5rem; }
.h-2     { height: 0.5rem; }
.w-3     { width: 0.75rem; }
.h-3     { height: 0.75rem; }
.w-3\.5  { width: 0.875rem; }
.h-3\.5  { height: 0.875rem; }
.w-4     { width: 1rem; }
.h-4     { height: 1rem; }
.w-5     { width: 1.25rem; }
.h-5     { height: 1.25rem; }
.w-6     { width: 1.5rem; }
.h-6     { height: 1.5rem; }
.w-7     { width: 1.75rem; }
.h-7     { height: 1.75rem; }
.w-8     { width: 2rem; }
.h-8     { height: 2rem; }
.w-16    { width: 4rem; }
.h-16    { height: 4rem; }
.shrink-0 { flex-shrink: 0; }
.flex-1   { flex: 1 1 0%; }
.min-w-0  { min-width: 0; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Animation */
.animate-spin {
  animation: ds-spin 1s linear infinite;
}
@keyframes ds-spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

/* ===== MOBILE/TOUCH: CONTENT ROW IMPROVEMENTS ===== */
@media (max-width: 767px) {
  .content-item-row {
    padding: var(--space-4);           /* larger touch target */
    gap: var(--space-2);
  }
  .content-item-row .text-sm {
    font-size: var(--text-base);       /* readable on small screens */
  }
}

/* Text overflow safety for dynamic content */
.content-item-row > div:first-child {
  overflow: hidden;
}
.content-item-row .text-sm.font-medium {
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
