/* Watheeq design system - extracted from templates/base.html.
 *
 * Lived inline until now, which meant ~41 KB of identical CSS was
 * re-sent inside the HTML of every single page and could never be
 * cached. As a static file it is fetched once and reused, and
 * url_for() stamps it with ?v=<mtime> so a redeploy still busts it.
 *
 * Loaded AFTER dist/app.css so these rules keep overriding Tailwind,
 * exactly as they did when inline. The @font-face rules for Thmanyah
 * Sans stay in base.html because their src needs url_for().
 */

/* Cross-document view transitions: the browser cross-fades the old page
       into the new one instead of flashing white between them. Progressive
       enhancement — browsers without support just navigate as before. */
    @view-transition { navigation: auto; }

    /* Keep the chrome visually anchored while the body cross-fades, so
       navigation reads as "the page changed", not "everything reloaded". */
    .nav-header, body > nav { view-transition-name: site-nav; }
    body > footer { view-transition-name: site-footer; }

    @media (prefers-reduced-motion: reduce) {
      ::view-transition-group(*),
      ::view-transition-old(*),
      ::view-transition-new(*) { animation: none !important; }
    }

    /* Local Arabic display + body font — Thmanyah Sans
       Two weights (Regular 400, Bold 700) so headings render with real bold
       glyphs instead of synthesized faux-bold. unicode-range scopes the font
       to Arabic codepoints + basic Latin so it's only loaded when needed. */
    
    

    /* Wrapped in @layer base so Tailwind utilities (in @layer utilities)
       can override these resets. Without the layer, the universal `*`
       selector is in the unlayered "anonymous" cascade — which in v4 wins
       over every layered utility regardless of specificity. That silently
       broke `mx-auto`, `ml-*`, `mr-*` everywhere (centered containers
       were sticking to `left: 0`). */
    @layer base {
      * { box-sizing: border-box; margin: 0; padding: 0; }
    }

    /* === Watheeq Design Tokens — shared by app and landing === */
    :root {
      /* Surfaces (subtly warm to feel paper-adjacent without being parchment) */
      --bg: #fafaf7;
      --bg-card: #ffffff;
      --bg-subtle: #f3f0e8;

      /* Text */
      --text: #14110d;
      --text-secondary: #5c5448;
      --text-muted: #9c9994;

      /* Borders */
      --border: #e8e4dc;
      --border-strong: #d2cdc1;

      /* Brand */
      --primary: #14110d;
      --primary-hover: #2a261f;

      /* Accent — used sparingly: key CTAs, link hover, marketing flourish.
         A refined terracotta. Replaces both vermillion and brass. */
      --accent: #a0593f;
      --accent-hover: #8a4a32;
      --accent-soft: rgba(160, 89, 63, 0.10);

      --focus-ring: rgba(160, 89, 63, 0.18);
    }

    .dark {
      --bg: #0e0d0b;
      --bg-card: #161512;
      --bg-subtle: #1a1814;
      --text: #f5f2ea;
      --text-secondary: #b5b0a4;
      --text-muted: #6a6760;
      --border: #2a2620;
      --border-strong: #3a3530;
      --primary: #f5f2ea;
      --primary-hover: #e0dcd2;
      --accent: #c5754d;
      --accent-hover: #d68b65;
      --accent-soft: rgba(197, 117, 77, 0.12);
      --focus-ring: rgba(197, 117, 77, 0.22);
    }

    /* Display serif — used on marketing pages for headlines only.
       App surfaces (dashboard, manage_files, etc.) keep Inter. */
    .font-display {
      font-family: 'Fraunces', Georgia, serif;
      font-optical-sizing: auto;
      font-feature-settings: 'ss01' on, 'liga' on;
      letter-spacing: -0.018em;
    }
    [lang="ar"] .font-display {
      font-family: 'Thmanyah Sans', 'Noto Sans Arabic', serif;
      font-weight: 600;
      letter-spacing: 0;
    }
    .font-mono { font-family: 'JetBrains Mono', ui-monospace, monospace; }

    html {
      font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
      font-size: 15px;
      line-height: 1.6;
      -webkit-font-smoothing: antialiased;
      scroll-behavior: smooth;
    }

    body {
      background: var(--bg);
      color: var(--text);
      min-height: 100vh;
    }

    /* RTL (Right-to-Left) Support for Arabic and other RTL languages */
    [lang="ar"], [dir="rtl"] {
      font-family: 'Thmanyah Sans', 'Noto Sans Arabic', 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    }

    /* RTL spacing utilities - reverse horizontal spacing */
    [dir="rtl"] .space-x-1 > :not([hidden]) ~ :not([hidden]),
    [dir="rtl"] .space-x-2 > :not([hidden]) ~ :not([hidden]),
    [dir="rtl"] .space-x-3 > :not([hidden]) ~ :not([hidden]),
    [dir="rtl"] .space-x-4 > :not([hidden]) ~ :not([hidden]),
    [dir="rtl"] .space-x-6 > :not([hidden]) ~ :not([hidden]) {
      --tw-space-x-reverse: 1;
    }

    /* RTL margin utilities */
    [dir="rtl"] .ml-1 { margin-left: 0; margin-right: 0.25rem; }
    [dir="rtl"] .ml-2 { margin-left: 0; margin-right: 0.5rem; }
    [dir="rtl"] .ml-3 { margin-left: 0; margin-right: 0.75rem; }
    [dir="rtl"] .ml-4 { margin-left: 0; margin-right: 1rem; }
    [dir="rtl"] .mr-1 { margin-right: 0; margin-left: 0.25rem; }
    [dir="rtl"] .mr-2 { margin-right: 0; margin-left: 0.5rem; }
    [dir="rtl"] .mr-3 { margin-right: 0; margin-left: 0.75rem; }
    [dir="rtl"] .mr-4 { margin-right: 0; margin-left: 1rem; }

    /* RTL padding utilities */
    [dir="rtl"] .pl-2 { padding-left: 0; padding-right: 0.5rem; }
    [dir="rtl"] .pl-4 { padding-left: 0; padding-right: 1rem; }
    [dir="rtl"] .pr-2 { padding-right: 0; padding-left: 0.5rem; }
    [dir="rtl"] .pr-4 { padding-right: 0; padding-left: 1rem; }

    /* RTL border radius utilities */
    [dir="rtl"] .rounded-l-lg { border-radius: 0 0.5rem 0.5rem 0; }
    [dir="rtl"] .rounded-r-lg { border-radius: 0.5rem 0 0 0.5rem; }

    /* RTL text alignment */
    [dir="rtl"] .text-left { text-align: right; }
    [dir="rtl"] .text-right { text-align: left; }

    /* RTL flex direction */
    [dir="rtl"] .rtl\:flex-row-reverse { flex-direction: row-reverse; }

    [x-cloak] { display: none !important; }

    /* Input */
    .input {
      width: 100%;
      height: 40px;
      padding: 0 12px;
      font-size: 14px;
      color: var(--text);
      background: var(--bg-card);
      border: 1px solid var(--border);
      border-radius: 6px;
      outline: none;
      transition: border-color 0.15s, box-shadow 0.15s;
    }
    .input:focus {
      border-color: var(--text);
      box-shadow: 0 0 0 3px var(--focus-ring);
    }
    .input::placeholder { color: var(--text-muted); }

    /* Button */
    .btn {
      display: inline-flex;
      align-items: center;
      justify-content: center;
      height: 40px;
      padding: 0 16px;
      font-size: 14px;
      font-weight: 500;
      border-radius: 6px;
      border: none;
      cursor: pointer;
      transition: all 0.15s;
    }
    .btn-primary {
      background: var(--primary);
      color: var(--bg);
    }
    .btn-primary:hover { background: var(--primary-hover); }

    /* Card */
    .card {
      background: var(--bg-card);
      border: 1px solid var(--border);
      border-radius: 8px;
    }

    /* Login specific */
    .login-wrap {
      min-height: 100vh;
      display: flex;
      align-items: center;
      justify-content: center;
      padding: 24px;
    }
    .login-card {
      width: 100%;
      max-width: 360px;
      padding: 32px;
      background: var(--bg-card);
      border: 1px solid var(--border);
      border-radius: 12px;
    }
    .login-title {
      font-size: 20px;
      font-weight: 600;
      color: var(--text);
      margin-bottom: 4px;
    }
    .login-subtitle {
      font-size: 14px;
      color: var(--text-secondary);
      margin-bottom: 24px;
    }
    .login-label {
      display: block;
      font-size: 13px;
      font-weight: 500;
      color: var(--text);
      margin-bottom: 6px;
    }
    .login-field { margin-bottom: 16px; }
    .login-input {
      width: 100%;
      height: 40px;
      padding: 0 12px;
      font-size: 14px;
      color: var(--text);
      background: var(--bg);
      border: 1px solid var(--border);
      border-radius: 6px;
      outline: none;
    }
    .login-input:focus {
      border-color: var(--text);
      box-shadow: 0 0 0 3px var(--focus-ring);
    }
    .login-input::placeholder { color: var(--text-muted); }
    .login-btn {
      width: 100%;
      height: 40px;
      font-size: 14px;
      font-weight: 500;
      color: var(--bg);
      background: var(--primary);
      border: none;
      border-radius: 6px;
      cursor: pointer;
      transition: background 0.15s;
    }
    .login-btn:hover { background: var(--primary-hover); }
    .login-footer {
      margin-top: 24px;
      padding-top: 16px;
      border-top: 1px solid var(--border);
      text-align: center;
      font-size: 13px;
      color: var(--text-muted);
    }

    /* Checkbox */
    .checkbox {
      width: 16px;
      height: 16px;
      accent-color: var(--primary);
      cursor: pointer;
    }

    /* Utilities */
    .flex { display: flex; }
    .items-center { align-items: center; }
    .gap-2 { gap: 8px; }
    .mb-4 { margin-bottom: 16px; }
    .mt-4 { margin-top: 16px; }
    .text-center { text-align: center; }
    .text-sm { font-size: 13px; }
    .text-muted { color: var(--text-muted); }

    /* Animation */
    @keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
    .animate-in { animation: fadeIn 0.3s ease; }

    /* Legacy support */
    .glass-light, .card-modern, .card-elevated { background: var(--bg-card); border: 1px solid var(--border); border-radius: 8px; }
    .btn-loading { opacity: 0.7; pointer-events: none; }
    .input-modern { width: 100%; height: 40px; padding: 0 12px 0 40px; font-size: 14px; background: var(--bg); border: 1px solid var(--border); border-radius: 6px; color: var(--text); }
    .input-modern:focus { border-color: var(--text); box-shadow: 0 0 0 3px var(--focus-ring); outline: none; }
    .input-icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--text-muted); }
    .input-group { position: relative; }
    .checkbox-modern { width: 16px; height: 16px; accent-color: var(--primary); }
    .login-container { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; }
    .w-full { width: 100%; }
    .bg-gradient-mesh { background: var(--bg); }
    /* Typography */
    .text-title { font-size: 22px; font-weight: 600; line-height: 1.3; }
    .text-heading { font-size: 15px; font-weight: 600; line-height: 1.4; }
    .text-body { font-size: 14px; line-height: 1.6; }
    .text-small { font-size: 13px; line-height: 1.5; }
    .text-caption { font-size: 12px; font-weight: 500; text-transform: uppercase; letter-spacing: 0.02em; }

    /* Card variants */
    .card-elevated { background: var(--bg-card); border: 1px solid var(--border); border-radius: 12px; box-shadow: 0 4px 12px rgba(0,0,0,0.08); }
    .card-elevated:hover { box-shadow: 0 8px 24px rgba(0,0,0,0.12); transform: translateY(-2px); }
    .card-interactive { background: var(--bg-card); border: 1px solid var(--border); border-radius: 8px; cursor: pointer; transition: all 0.15s; }
    .card-interactive:hover { background: var(--bg); border-color: var(--text-muted); }

    /* Button variants */
    .btn-secondary { background: var(--bg-card); color: var(--text); border: 1px solid var(--border); }
    .btn-secondary:hover { background: var(--bg); border-color: var(--text-muted); }
    .btn-ghost { background: transparent; color: var(--text-secondary); }
    .btn-ghost:hover { background: var(--bg); color: var(--text); }
    .btn-sm { height: 32px; padding: 0 12px; font-size: 13px; }
    .btn-lg { height: 48px; padding: 0 24px; font-size: 15px; }

    /* Input with icon */
    .input-with-icon { padding-left: 44px; }
    .input-error { border-color: #ef4444; }
    .input-error:focus { box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.15); }

    /* Status indicators */
    .status-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
    .status-dot-success { background: #22c55e; }
    .status-dot-warning { background: #f59e0b; }
    .status-dot-danger { background: #ef4444; }
    .status-dot-neutral { background: var(--text-muted); }

    /* Badges */
    .badge { display: inline-flex; align-items: center; gap: 4px; padding: 4px 8px; font-size: 12px; font-weight: 500; border-radius: 4px; }
    .badge-success { background: #dcfce7; color: #166534; }
    .badge-warning { background: #fef3c7; color: #92400e; }
    .badge-danger { background: #fee2e2; color: #991b1b; }
    .badge-neutral { background: var(--bg); color: var(--text-secondary); }
    .dark .badge-success { background: rgba(34, 197, 94, 0.15); color: #4ade80; }
    .dark .badge-warning { background: rgba(245, 158, 11, 0.15); color: #fbbf24; }
    .dark .badge-danger { background: rgba(239, 68, 68, 0.15); color: #f87171; }

    /* Tables */
    .table { width: 100%; border-collapse: collapse; }
    .table th { padding: 12px 16px; text-align: left; font-size: 12px; font-weight: 500; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; border-bottom: 1px solid var(--border); }
    .table td { padding: 16px; font-size: 14px; color: var(--text); border-bottom: 1px solid var(--border); height: 56px; vertical-align: middle; }
    .table tr:hover td { background: var(--bg); }

    /* Extra animations */
    @keyframes slideUp { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
    @keyframes scaleIn { from { opacity: 0; transform: scale(0.97); } to { opacity: 1; transform: scale(1); } }
    .animate-fade-in { animation: fadeIn 0.25s ease-out; }
    .animate-slide-up { animation: slideUp 0.25s ease-out; }
    .animate-scale-in { animation: scaleIn 0.25s ease-out; }

    /* Login extras */
    .login-header { text-align: center; margin-bottom: 32px; }
    .login-logo { width: 48px; height: 48px; margin: 0 auto 20px; border-radius: 8px; }
    .login-form { display: flex; flex-direction: column; gap: 20px; }
    .login-footer-text { font-size: 13px; color: var(--text-muted); }

    /* Navigation */
    .nav-header { position: sticky; top: 0; z-index: 50; height: 56px; background: rgba(255,255,255,0.95); backdrop-filter: blur(8px); border-bottom: 1px solid var(--border); }
    .dark .nav-header { background: rgba(10,10,10,0.95); }
    .nav-container { max-width: 1280px; margin: 0 auto; padding: 0 24px; height: 100%; display: flex; align-items: center; justify-content: space-between; }

    /* Utility overrides */
    .flex-col { flex-direction: column; }
    .justify-between { justify-content: space-between; }
    .justify-center { justify-content: center; }
    .gap-1 { gap: 4px; }
    .gap-3 { gap: 12px; }
    .gap-4 { gap: 16px; }
    .gap-5 { gap: 20px; }

    /* Legacy support */
    .card-modern { background: var(--bg-card); border: 1px solid var(--border); border-radius: 12px; }
    .input-modern { width: 100%; height: 44px; padding: 0 16px 0 44px; font-size: 14px; color: var(--text); background: var(--bg); border: 1px solid var(--border); border-radius: 6px; }
    .input-modern:focus { border-color: var(--text); box-shadow: 0 0 0 3px var(--focus-ring); outline: none; }
    .input-modern::placeholder { color: var(--text-muted); }
    .input-group:focus-within .input-icon { color: var(--text); }
    .checkbox-modern { appearance: none; width: 16px; height: 16px; background: var(--bg-card); border: 1.5px solid var(--border); border-radius: 4px; cursor: pointer; }
    .checkbox-modern:checked { background: var(--primary); border-color: var(--primary); }
    .checkbox-modern:checked::after { content: ''; position: absolute; left: 5px; top: 2px; width: 5px; height: 9px; border: solid var(--bg); border-width: 0 2px 2px 0; transform: rotate(45deg); }

    /* Button loading */
    .btn-loading .btn-text { visibility: hidden; }
    .btn-loading::after { content: ''; position: absolute; width: 16px; height: 16px; border: 2px solid rgba(255,255,255,0.3); border-top-color: white; border-radius: 50%; animation: spin 0.7s linear infinite; }
    @keyframes spin {
      to { transform: rotate(360deg); }
    }
    .glass-light {
      background: rgba(255, 255, 255, 0.85);
      backdrop-filter: blur(12px);
      -webkit-backdrop-filter: blur(12px);
    }
    .dark .glass-light {
      background: rgba(15, 20, 25, 0.85);
    }
    .bg-gradient-mesh { background: var(--bg); }

    /* Fix modal form inputs visibility in light mode */
    input[type="text"], input[type="email"], input[type="password"], input[type="number"], input[type="date"], input[type="url"], input[type="tel"], textarea, select {
      background: var(--bg) !important;
      color: var(--text) !important;
      border-color: var(--border) !important;
    }
    input[type="text"]:focus, input[type="email"]:focus, input[type="password"]:focus, input[type="number"]:focus, input[type="date"]:focus, input[type="url"]:focus, input[type="tel"]:focus, textarea:focus, select:focus {
      border-color: var(--text) !important;
      outline: none;
      box-shadow: 0 0 0 3px var(--focus-ring);
    }
    input::placeholder, textarea::placeholder { color: var(--text-muted) !important; }

    /* ===========================================================
       EDITORIAL APP SURFACES — pulls authenticated pages into the
       same visual language as the landing. Adds:
         • Fraunces page titles (.page-title)
         • Mono uppercase eyebrows (.eyebrow)
         • Terracotta hover on primary CTAs
         • Hand-drawn underline accent (.ink-underline)
         • Refined card / login surfaces
       Auto-applies to existing .login-title, .login-subtitle, etc.
       =========================================================== */

    /* Page-level editorial heading utility */
    .page-title {
      font-family: 'Fraunces', Georgia, serif;
      font-optical-sizing: auto;
      font-weight: 500;
      letter-spacing: -0.018em;
      font-size: 24px;
      line-height: 1.1;
      color: var(--text);
    }
    .page-title em { font-style: italic; font-weight: 480; }
    [lang="ar"] .page-title {
      font-family: 'Thmanyah Sans', 'Noto Sans Arabic', serif;
      font-weight: 700;
      letter-spacing: 0;
    }

    .page-subtitle {
      font-family: 'Fraunces', Georgia, serif;
      font-style: italic;
      font-weight: 400;
      font-size: 14px;
      color: var(--text-secondary);
      line-height: 1.5;
      margin-top: 4px;
    }

    /* Mono uppercase eyebrow — for section labels in dashboards */
    .eyebrow {
      font-family: 'JetBrains Mono', ui-monospace, monospace;
      font-size: 10.5px;
      font-weight: 500;
      letter-spacing: 0.18em;
      text-transform: uppercase;
      color: var(--text-secondary);
    }

    /* Hand-drawn underline — matches the hero keyword underline */
    .ink-underline {
      position: relative;
      display: inline-block;
    }
    .ink-underline::after {
      content: '';
      position: absolute;
      left: -2px; right: -2px;
      bottom: -0.18em;
      height: 0.22em;
      background: var(--accent);
      border-radius: 3px;
      opacity: 0.78;
      transform: skewY(-1deg);
      z-index: -1;
    }

    /* Brand-color link */
    .accent-link {
      color: var(--accent);
      text-decoration: none;
      border-bottom: 1px solid currentColor;
      transition: color 0.15s ease;
    }
    .accent-link:hover { color: var(--accent-hover); }

    /* Refine .btn-primary: terracotta hover (matches landing CTAs) */
    .btn-primary {
      background: var(--primary);
      color: var(--bg);
      transition: background 0.15s ease, transform 0.15s ease,
                  box-shadow 0.15s ease;
      box-shadow: 0 1px 2px rgba(20,17,13,0.06),
                  0 2px 6px -2px rgba(20,17,13,0.10);
    }
    .btn-primary:hover {
      background: var(--accent);
      color: var(--bg);
      transform: translateY(-1px);
      box-shadow: 0 2px 4px rgba(160,89,63,0.15),
                  0 6px 14px -4px rgba(160,89,63,0.22);
    }
    .btn-primary:active { transform: translateY(0); }

    /* Refine .card: hairline border, gentle warmer shadow on hover */
    .card {
      background: var(--bg-card);
      border: 1px solid var(--border);
      border-radius: 10px;
      transition: border-color 0.18s ease, box-shadow 0.18s ease;
    }
    .card-elevated {
      background: var(--bg-card);
      border: 1px solid var(--border);
      border-radius: 12px;
      box-shadow: 0 1px 2px rgba(20,17,13,0.04),
                  0 4px 14px -6px rgba(20,17,13,0.10);
      transition: border-color 0.18s ease, box-shadow 0.18s ease,
                  transform 0.18s ease;
    }
    .card-elevated:hover {
      border-color: var(--border-strong);
      box-shadow: 0 2px 4px rgba(20,17,13,0.06),
                  0 12px 28px -8px rgba(20,17,13,0.14);
      transform: translateY(-1px);
    }
    .dark .card-elevated {
      box-shadow: 0 1px 2px rgba(0,0,0,0.3),
                  0 4px 14px -6px rgba(0,0,0,0.4);
    }
    .dark .card-elevated:hover {
      box-shadow: 0 2px 4px rgba(0,0,0,0.4),
                  0 12px 28px -8px rgba(0,0,0,0.55);
    }

    /* Login surfaces — promote to editorial language */
    .login-card {
      background: var(--bg-card);
      border: 1px solid var(--border);
      border-radius: 12px;
      padding: 40px 32px 32px;
      box-shadow: 0 1px 2px rgba(20,17,13,0.04),
                  0 12px 32px -10px rgba(20,17,13,0.10);
    }
    .dark .login-card {
      box-shadow: 0 1px 2px rgba(0,0,0,0.3),
                  0 12px 32px -10px rgba(0,0,0,0.55);
    }

    .login-title {
      font-family: 'Fraunces', Georgia, serif;
      font-optical-sizing: auto;
      font-weight: 500;
      font-size: 28px;
      letter-spacing: -0.02em;
      line-height: 1.05;
      color: var(--text);
      margin-bottom: 6px;
    }
    [lang="ar"] .login-title {
      font-family: 'Thmanyah Sans', 'Noto Sans Arabic', serif;
      font-weight: 700;
      letter-spacing: 0;
    }

    .login-subtitle {
      font-family: 'Fraunces', Georgia, serif;
      font-style: italic;
      font-weight: 400;
      font-size: 15px;
      line-height: 1.5;
      color: var(--text-secondary);
      margin-bottom: 28px;
    }
    [lang="ar"] .login-subtitle {
      font-family: 'Thmanyah Sans', 'Noto Sans Arabic', serif;
      font-style: normal;
      font-weight: 500;
    }

    .login-logo {
      width: 56px;
      height: 56px;
      margin: 0 auto 22px;
      border-radius: 0;
      background: transparent;
      color: var(--text);
      font-size: 56px;
      line-height: 0;
      display: flex;
      align-items: center;
      justify-content: center;
    }

    /* Refine login button to match brand CTA */
    .login-btn {
      background: var(--primary);
      color: var(--bg);
      border-radius: 8px;
      transition: background 0.15s ease, transform 0.15s ease,
                  box-shadow 0.15s ease;
      box-shadow: 0 1px 2px rgba(20,17,13,0.06),
                  0 4px 10px -4px rgba(20,17,13,0.18);
    }
    .login-btn:hover {
      background: var(--accent);
      transform: translateY(-1px);
      box-shadow: 0 2px 4px rgba(160,89,63,0.15),
                  0 8px 16px -4px rgba(160,89,63,0.25);
    }

    /* Refined badges — use accent for "verified/positive" status */
    .badge-success { background: var(--accent-soft); color: var(--accent-hover); }
    .dark .badge-success { background: var(--accent-soft); color: var(--accent); }

    /* Common "primary action" button hover override on app pages —
       converts hard-coded zinc-900 buttons used in dashboards/forms */
    button.bg-zinc-900:hover,
    a.bg-zinc-900:hover,
    button.dark\\:bg-zinc-100:hover,
    a.dark\\:bg-zinc-100:hover {
      background: var(--accent) !important;
    }

    /* Realm icons / headers in nav: tighter brand alignment */
    nav h1, nav h2 {
      font-family: 'Fraunces', Georgia, serif;
      font-weight: 500;
      letter-spacing: -0.018em;
    }
    [lang="ar"] nav h1, [lang="ar"] nav h2 {
      font-family: 'Thmanyah Sans', 'Noto Sans Arabic', serif;
      font-weight: 700;
      letter-spacing: 0;
    }

    /* Subtle warm grain on body — same texture as landing for cohesion.
       Very faint (4% opacity) so it doesn't interfere with reading. */
    body::before {
      content: '';
      position: fixed; inset: 0;
      background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.04 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
      background-size: 140px 140px;
      opacity: 0.55;
      mix-blend-mode: multiply;
      pointer-events: none;
      z-index: 1;
    }
    .dark body::before { mix-blend-mode: screen; opacity: 0.30; }

    /* Make sure interactive content sits above the grain overlay */
    body > * { position: relative; z-index: 2; }
    /* The footer is decorative chrome. Because every body child gets its own
       stacking context above, a fixed modal/popup that lives inside <main>
       (z-index:2) cannot escape past a sibling at the same z-index — and the
       footer comes later in the DOM, so it would paint ON TOP of the popup.
       Drop the footer below <main> so popups always win. It still renders
       above the grain overlay (z-index:1) since it paints later than ::before. */
    body > footer { z-index: 1; }

    /* ===========================================================
       APP SURFACES — global brand overrides for authenticated pages
       (dashboard, manage_files, signatures, etc.) Converts the
       inline Tailwind rainbow colors into the warm brand palette.
       The marketing landing page is unaffected because .archive-page
       has higher-specificity !important rules that win.
       =========================================================== */

    /* — Decorative colored backgrounds (chips, icon containers, banners) —
       Bright Tailwind tints become a warm neutral, in both light and dark mode.
       Light: bg-{color}-{50/100/200}.  Dark: dark:bg-{color}-{800/900}/{X}. */
    .bg-blue-50, .bg-blue-100, .bg-blue-200,
    .bg-indigo-50, .bg-indigo-100, .bg-indigo-200,
    .bg-violet-50, .bg-violet-100, .bg-violet-200,
    .bg-purple-50, .bg-purple-100, .bg-purple-200,
    .bg-fuchsia-50, .bg-fuchsia-100, .bg-fuchsia-200,
    .bg-pink-50, .bg-pink-100, .bg-pink-200,
    .bg-cyan-50, .bg-cyan-100, .bg-cyan-200,
    .bg-sky-50, .bg-sky-100, .bg-sky-200,
    .bg-teal-50, .bg-teal-100, .bg-teal-200,
    .bg-emerald-50, .bg-emerald-100, .bg-emerald-200,
    .bg-green-50, .bg-green-100, .bg-green-200,
    .bg-lime-50, .bg-lime-100, .bg-lime-200,
    .bg-yellow-50, .bg-yellow-100, .bg-yellow-200,
    .bg-amber-50, .bg-amber-100, .bg-amber-200,
    .bg-orange-50, .bg-orange-100, .bg-orange-200,
    .bg-rose-50, .bg-rose-100, .bg-rose-200,
    .bg-red-50, .bg-red-100, .bg-red-200,
    .bg-gray-50, .bg-gray-100, .bg-gray-200,
    .bg-slate-50, .bg-slate-100, .bg-slate-200,
    .bg-stone-50, .bg-stone-100, .bg-stone-200,
    .bg-neutral-50, .bg-neutral-100, .bg-neutral-200,
    .bg-zinc-50, .bg-zinc-100, .bg-zinc-200,
    /* Dark-mode 800/900 shades + opacity variants */
    [class*="dark:bg-blue-9"], [class*="dark:bg-blue-8"],
    [class*="dark:bg-indigo-9"], [class*="dark:bg-indigo-8"],
    [class*="dark:bg-violet-9"], [class*="dark:bg-violet-8"],
    [class*="dark:bg-purple-9"], [class*="dark:bg-purple-8"],
    [class*="dark:bg-fuchsia-9"], [class*="dark:bg-fuchsia-8"],
    [class*="dark:bg-pink-9"], [class*="dark:bg-pink-8"],
    [class*="dark:bg-cyan-9"], [class*="dark:bg-cyan-8"],
    [class*="dark:bg-sky-9"], [class*="dark:bg-sky-8"],
    [class*="dark:bg-teal-9"], [class*="dark:bg-teal-8"],
    [class*="dark:bg-emerald-9"], [class*="dark:bg-emerald-8"],
    [class*="dark:bg-green-9"], [class*="dark:bg-green-8"],
    [class*="dark:bg-lime-9"], [class*="dark:bg-lime-8"],
    [class*="dark:bg-yellow-9"], [class*="dark:bg-yellow-8"],
    [class*="dark:bg-amber-9"], [class*="dark:bg-amber-8"],
    [class*="dark:bg-orange-9"], [class*="dark:bg-orange-8"],
    [class*="dark:bg-rose-9"], [class*="dark:bg-rose-8"],
    [class*="dark:bg-red-9"], [class*="dark:bg-red-8"],
    [class*="dark:bg-gray-9"], [class*="dark:bg-gray-8"],
    [class*="dark:bg-slate-9"], [class*="dark:bg-slate-8"],
    [class*="dark:bg-stone-9"], [class*="dark:bg-stone-8"],
    [class*="dark:bg-neutral-9"], [class*="dark:bg-neutral-8"],
    [class*="dark:bg-zinc-9"], [class*="dark:bg-zinc-8"] {
      background-color: var(--bg-subtle) !important;
    }
    /* Saturated backgrounds (badges, primary buttons) → ink */
    .bg-blue-500, .bg-blue-600, .bg-blue-700,
    .bg-indigo-500, .bg-indigo-600, .bg-indigo-700,
    .bg-violet-500, .bg-violet-600, .bg-violet-700,
    .bg-purple-500, .bg-purple-600, .bg-purple-700,
    .bg-emerald-500, .bg-emerald-600,
    .bg-green-500, .bg-green-600, .bg-green-700,
    .bg-yellow-500, .bg-yellow-600,
    .bg-amber-500, .bg-amber-600,
    .bg-orange-500, .bg-orange-600,
    .bg-pink-500, .bg-pink-600,
    .bg-teal-500, .bg-teal-600 {
      background-color: var(--text) !important;
      color: var(--bg) !important;
    }
    /* Errors stay red — functional safety color */
    /* (red-500/600 intentionally not overridden) */

    /* — Decorative colored text (icons, labels, captions) —
       Becomes warm secondary text. Covers light AND dark mode variants
       so icons in dark mode (which use dark:text-{color}-{200/300/400})
       also get neutralized. Red is included for decorative card icons;
       error message text uses different patterns. */
    .text-blue-400, .text-blue-500, .text-blue-600, .text-blue-700,
    .text-indigo-400, .text-indigo-500, .text-indigo-600, .text-indigo-700,
    .text-violet-400, .text-violet-500, .text-violet-600, .text-violet-700,
    .text-purple-400, .text-purple-500, .text-purple-600, .text-purple-700,
    .text-fuchsia-500, .text-fuchsia-600,
    .text-pink-400, .text-pink-500, .text-pink-600,
    .text-cyan-500, .text-cyan-600,
    .text-sky-500, .text-sky-600,
    .text-teal-500, .text-teal-600,
    .text-emerald-400, .text-emerald-500, .text-emerald-600,
    .text-green-400, .text-green-500, .text-green-600, .text-green-700,
    .text-lime-500, .text-lime-600,
    .text-yellow-400, .text-yellow-500, .text-yellow-600,
    .text-amber-400, .text-amber-500, .text-amber-600,
    .text-orange-400, .text-orange-500, .text-orange-600,
    .text-rose-400, .text-rose-500, .text-rose-600,
    .text-red-400, .text-red-500, .text-red-600, .text-red-700,
    /* Dark-mode variants */
    [class*="dark:text-blue-"], [class*="dark:text-indigo-"], [class*="dark:text-violet-"],
    [class*="dark:text-purple-"], [class*="dark:text-fuchsia-"], [class*="dark:text-pink-"],
    [class*="dark:text-cyan-"], [class*="dark:text-sky-"], [class*="dark:text-teal-"],
    [class*="dark:text-emerald-"], [class*="dark:text-green-"], [class*="dark:text-lime-"],
    [class*="dark:text-yellow-"], [class*="dark:text-amber-"], [class*="dark:text-orange-"],
    [class*="dark:text-rose-"], [class*="dark:text-red-"],
    [class*="dark:text-gray-4"], [class*="dark:text-gray-3"],
    [class*="dark:text-slate-4"], [class*="dark:text-slate-3"],
    [class*="dark:text-stone-4"], [class*="dark:text-stone-3"],
    [class*="dark:text-neutral-4"], [class*="dark:text-neutral-3"] {
      color: var(--text-secondary) !important;
    }

    /* — Decorative colored borders → neutral hairline.
       Attribute selectors catch every shade (50, 100, 200, 300, 400, 500, 600, 700, 800, 900)
       and every hover: variant (so card hover edges stay neutral too). */
    [class*="border-blue-"], [class*="border-indigo-"], [class*="border-violet-"],
    [class*="border-purple-"], [class*="border-fuchsia-"], [class*="border-pink-"],
    [class*="border-cyan-"], [class*="border-sky-"], [class*="border-teal-"],
    [class*="border-emerald-"], [class*="border-green-"], [class*="border-lime-"],
    [class*="border-yellow-"], [class*="border-amber-"], [class*="border-orange-"],
    [class*="border-rose-"], [class*="border-red-"] {
      border-color: var(--border) !important;
    }
    /* Hover state — slightly stronger neutral border for affordance */
    [class*="border-blue-"]:hover, [class*="border-indigo-"]:hover, [class*="border-violet-"]:hover,
    [class*="border-purple-"]:hover, [class*="border-fuchsia-"]:hover, [class*="border-pink-"]:hover,
    [class*="border-cyan-"]:hover, [class*="border-sky-"]:hover, [class*="border-teal-"]:hover,
    [class*="border-emerald-"]:hover, [class*="border-green-"]:hover, [class*="border-lime-"]:hover,
    [class*="border-yellow-"]:hover, [class*="border-amber-"]:hover, [class*="border-orange-"]:hover,
    [class*="border-rose-"]:hover, [class*="border-red-"]:hover {
      border-color: var(--border-strong) !important;
    }

    /* Directional colored border accents (border-l-blue-500, border-r-purple-300,
       border-t-green-400, border-b-amber-500, etc) — strip them. These are
       used as side-only "category color" stripes on stat cards and don't
       fit the brand. */
    main [class*="border-l-blue-"], main [class*="border-l-indigo-"], main [class*="border-l-violet-"],
    main [class*="border-l-purple-"], main [class*="border-l-fuchsia-"], main [class*="border-l-pink-"],
    main [class*="border-l-cyan-"], main [class*="border-l-sky-"], main [class*="border-l-teal-"],
    main [class*="border-l-emerald-"], main [class*="border-l-green-"], main [class*="border-l-lime-"],
    main [class*="border-l-yellow-"], main [class*="border-l-amber-"], main [class*="border-l-orange-"],
    main [class*="border-l-rose-"], main [class*="border-l-red-"],
    main [class*="border-r-blue-"], main [class*="border-r-indigo-"], main [class*="border-r-violet-"],
    main [class*="border-r-purple-"], main [class*="border-r-pink-"], main [class*="border-r-cyan-"],
    main [class*="border-r-sky-"], main [class*="border-r-teal-"], main [class*="border-r-emerald-"],
    main [class*="border-r-green-"], main [class*="border-r-yellow-"], main [class*="border-r-amber-"],
    main [class*="border-r-orange-"], main [class*="border-r-rose-"], main [class*="border-r-red-"],
    main [class*="border-t-blue-"], main [class*="border-t-purple-"], main [class*="border-t-green-"],
    main [class*="border-t-yellow-"], main [class*="border-t-orange-"], main [class*="border-t-red-"],
    main [class*="border-b-blue-"], main [class*="border-b-purple-"], main [class*="border-b-green-"],
    main [class*="border-b-yellow-"], main [class*="border-b-orange-"], main [class*="border-b-red-"] {
      border-left-color: var(--border) !important;
      border-right-color: var(--border) !important;
      border-top-color: var(--border) !important;
      border-bottom-color: var(--border) !important;
      border-left-width: 0 !important;
      border-right-width: 0 !important;
      border-top-width: 0 !important;
      border-bottom-width: 0 !important;
    }

    /* Dashboard action cards — borderless. Let bg + subtle shadow define
       the edge so the grid reads as a clean tile field, not a frame stack. */
    main [data-card-key] {
      border: 0 !important;
      box-shadow:
        0 1px 2px rgba(20, 17, 13, 0.04),
        0 4px 14px -6px rgba(20, 17, 13, 0.06) !important;
    }
    main [data-card-key]:hover {
      box-shadow:
        0 2px 4px rgba(20, 17, 13, 0.06),
        0 10px 24px -8px rgba(20, 17, 13, 0.10) !important;
    }
    .dark main [data-card-key] {
      box-shadow:
        0 1px 2px rgba(0, 0, 0, 0.3),
        0 4px 14px -6px rgba(0, 0, 0, 0.4) !important;
    }
    .dark main [data-card-key]:hover {
      box-shadow:
        0 2px 4px rgba(0, 0, 0, 0.4),
        0 10px 24px -8px rgba(0, 0, 0, 0.55) !important;
    }

    /* — Soft colored shadows → warm neutral shadow */
    [class*="shadow-blue-"], [class*="shadow-indigo-"], [class*="shadow-violet-"],
    [class*="shadow-purple-"], [class*="shadow-pink-"], [class*="shadow-cyan-"],
    [class*="shadow-sky-"], [class*="shadow-teal-"], [class*="shadow-emerald-"],
    [class*="shadow-green-"], [class*="shadow-yellow-"], [class*="shadow-amber-"],
    [class*="shadow-orange-"], [class*="shadow-rose-"] {
      --tw-shadow-color: rgba(20, 17, 13, 0.10) !important;
      --tw-shadow-colored: 0 4px 12px var(--tw-shadow-color) !important;
    }

    /* — Table headers + data cells centered (both LTR and RTL) for consistency */
    table th,
    table td {
      text-align: center !important;
    }
    /* Flex containers inside td default to start-aligned; center them too */
    table td > .flex {
      justify-content: center !important;
    }
    /* The action-icon grid: center inside its cell */
    table td > .inline-grid {
      margin-inline: auto;
      display: grid !important;
    }
    /* User column (first cell) — push to start of writing direction
       (right in RTL, left in LTR) so the avatar+name read naturally */
    table tbody td:first-child > .flex {
      justify-content: flex-start !important;
    }

    /* — Tailwind gradient backgrounds → solid ink (matches saturated buttons).
       Catches any element using `bg-gradient-to-*` (regardless of from/via/to colors)
       so colorful CTA buttons and tab pills become consistent neutrals. */
    [class*="bg-gradient-to-"] {
      background-image: none !important;
      background-color: var(--text) !important;
      color: var(--bg) !important;
    }
    /* Exception: ledger/page hero gradients on the marketing landing keep their
       existing treatment because .archive-page rules win via higher specificity. */

    /* — Tone down playful rounded-3xl chrome on app pages (too cute for product UI).
       Keep the radius but reduce from 24px to 12px (matches .card style). */
    main .rounded-3xl, .glass-light.rounded-3xl {
      border-radius: 12px !important;
    }

    /* — Dashboard-specific refinements — */
    /* Welcome / page heading: promote oversize bold-Inter to Fraunces */
    main h1.text-2xl, main h1.text-3xl,
    main h2.text-2xl, main h2.text-3xl,
    main .text-3xl.font-bold, main .text-3xl.font-extrabold,
    main .text-2xl.font-bold, main .text-2xl.font-extrabold {
      font-family: 'Fraunces', Georgia, serif !important;
      font-optical-sizing: auto !important;
      font-weight: 500 !important;
      letter-spacing: -0.018em !important;
    }
    [lang="ar"] main h1.text-2xl, [lang="ar"] main h1.text-3xl,
    [lang="ar"] main h2.text-2xl, [lang="ar"] main h2.text-3xl,
    [lang="ar"] main .text-3xl.font-bold, [lang="ar"] main .text-3xl.font-extrabold,
    [lang="ar"] main .text-2xl.font-bold, [lang="ar"] main .text-2xl.font-extrabold {
      font-family: 'Thmanyah Sans', 'Noto Sans Arabic', serif !important;
      font-weight: 700 !important;
      letter-spacing: 0 !important;
    }

    /* Stat-card "BIG NUMBER" treatment — Fraunces for figures */
    .text-4xl.font-bold, .text-4xl.font-extrabold,
    .text-3xl.font-bold span, .text-3xl.font-extrabold span {
      font-feature-settings: 'tnum' on;
    }

    /* Caption / eyebrow labels — uppercase tracked mono (Latin) */
    main .uppercase.tracking-wide,
    main .uppercase.tracking-wider,
    main .uppercase.tracking-widest {
      font-family: 'JetBrains Mono', ui-monospace, monospace !important;
      letter-spacing: 0.18em !important;
      font-size: 10.5px !important;
      font-weight: 500 !important;
      color: var(--text-secondary) !important;
    }
    /* Arabic eyebrow labels — Arabic doesn't suit mono fonts or wide tracking.
       Use Thmanyah Sans, drop letter-spacing, bump size for legibility. */
    [lang="ar"] main .uppercase.tracking-wide,
    [lang="ar"] main .uppercase.tracking-wider,
    [lang="ar"] main .uppercase.tracking-widest,
    [dir="rtl"] main .uppercase.tracking-wide,
    [dir="rtl"] main .uppercase.tracking-wider,
    [dir="rtl"] main .uppercase.tracking-widest {
      font-family: 'Thmanyah Sans', 'Noto Sans Arabic', sans-serif !important;
      letter-spacing: 0 !important;
      font-size: 13px !important;
      font-weight: 500 !important;
      text-transform: none !important;
    }

    /* — Nav: realm name in Fraunces italic — */
    nav span.font-bold, nav span.font-extrabold,
    nav span.font-semibold[class*="text-xl"],
    nav span[class*="text-lg"][class*="font-"] {
      font-family: 'Fraunces', Georgia, serif !important;
      font-weight: 500 !important;
      font-style: italic !important;
      letter-spacing: -0.012em !important;
    }
    [lang="ar"] nav span.font-bold,
    [lang="ar"] nav span.font-extrabold {
      font-family: 'Thmanyah Sans', 'Noto Sans Arabic', serif !important;
      font-style: normal !important;
      font-weight: 700 !important;
      letter-spacing: 0 !important;
    }

    /* — Welcome banner (top of dashboard, success flash) — softer green */
    .bg-green-50.border, .bg-emerald-50.border {
      background-color: color-mix(in srgb, var(--accent-soft) 60%, var(--bg-card)) !important;
      border-color: var(--accent-soft) !important;
      color: var(--text) !important;
    }
