/* =====================================================================
   ERPSYS · Sprint 10 — immersive per-application themes + accessibility layer (WCAG 2.2 AA)
   Loaded after app.css on every layout. Every colour pair used for text was contrast-checked (≥ 4.5:1).
   ===================================================================== */

/* ---------- 1. Application themes ------------------------------------------------------------ */
:root {
  --muted: #56666E;                 /* ≥ 4.5:1 on white and on the page background */
  --accent-strong: #8A6A14;         /* gold that carries white text */
  --glow-1: #2BB3A3; --glow-2: #D9B45A; --glow-3: #0F6B7A;
  --hero-1: #062F37; --hero-2: #0B5563;
  --ease-out: cubic-bezier(.16, 1, .3, 1);
  --ring: 0 0 0 3px #fff, 0 0 0 6px var(--brand-700);
  --radius: 16px;
  --shadow-lift: 0 2px 4px rgba(20,35,43,.05), 0 18px 40px -12px rgba(20,35,43,.18);
}
[data-app="sapphire"] { --brand-900:#0A1A3F; --brand-800:#12296B; --brand-700:#1D4ED8; --brand-600:#1E4FC9; --brand-100:#DCE6FD; --brand-50:#EFF4FF;
  --glow-1:#5B8DEF; --glow-2:#38BDF8; --glow-3:#1D4ED8; --hero-1:#0A1A3F; --hero-2:#1D3FA8; }
[data-app="sand"]     { --brand-900:#3A1C0B; --brand-800:#5E2C10; --brand-700:#9A3412; --brand-600:#A43A13; --brand-100:#FBE5D3; --brand-50:#FFF4EA;
  --glow-1:#F59E0B; --glow-2:#F97362; --glow-3:#C2410C; --hero-1:#3A1C0B; --hero-2:#8A3413; --accent:#C58A1F; }
[data-app="tech"]     { --brand-900:#072A40; --brand-800:#0A3D5C; --brand-700:#0369A1; --brand-600:#036496; --brand-100:#D8EEFA; --brand-50:#EDF7FD;
  --glow-1:#22D3EE; --glow-2:#60A5FA; --glow-3:#0369A1; --hero-1:#072A40; --hero-2:#075985; }
[data-app="night"]    { --brand-900:#0A1222; --brand-800:#101B33; --brand-700:#0E7490; --brand-600:#0C6C86; --brand-100:#D5F1F6; --brand-50:#ECF8FA;
  --glow-1:#22D3EE; --glow-2:#818CF8; --glow-3:#0E7490; --hero-1:#0A1222; --hero-2:#123049; }
[data-app="emerald"]  { --brand-900:#052E22; --brand-800:#064232; --brand-700:#047857; --brand-600:#046C4E; --brand-100:#D6F3E7; --brand-50:#ECFAF3;
  --glow-1:#34D399; --glow-2:#FBBF24; --glow-3:#047857; --hero-1:#052E22; --hero-2:#07573F; }
[data-app="sea"]      { --brand-900:#042F2E; --brand-800:#063F3D; --brand-700:#0F766E; --brand-600:#0D6C65; --brand-100:#D3F2EE; --brand-50:#EBFAF7;
  --glow-1:#2DD4BF; --glow-2:#38BDF8; --glow-3:#0F766E; --hero-1:#042F2E; --hero-2:#0B5E58; }
[data-app="slate"]    { --brand-900:#0F172A; --brand-800:#1E293B; --brand-700:#334155; --brand-600:#3F4E63; --brand-100:#E2E8F0; --brand-50:#F1F5F9;
  --glow-1:#94A3B8; --glow-2:#60A5FA; --glow-3:#475569; --hero-1:#0F172A; --hero-2:#27354D; }

/* ---------- 2. Base accessibility ------------------------------------------------------------- */
html { background: var(--bg); scroll-padding-top: 88px; font-size: 100%; }
body { font-size: .9375rem; background: transparent; }
:focus-visible { outline: 3px solid var(--brand-700); outline-offset: 2px; box-shadow: 0 0 0 5px rgba(255,255,255,.9); border-radius: 6px; }
.sidebar :focus-visible, .dash-hero :focus-visible, .hero :focus-visible, .auth-aside :focus-visible, .page-hero :focus-visible, .site-footer :focus-visible { outline-color: #FFE29A; box-shadow: 0 0 0 5px rgba(0,0,0,.45); }
.skip-link { top: -80px; font-weight: 800; box-shadow: var(--shadow); transition: top .15s; }
.skip-link:focus { top: .75rem; outline: 3px solid #FFE29A; }
.btn-icon { min-height: 44px; width: 44px; }
.btn { min-height: 44px; }
.btn-sm { min-height: 36px; }
.btn-accent { background: var(--accent-strong); }
.btn-accent:hover { background: #6F550F; }
.nav-group-title { color: rgba(255,255,255,.66); }
.sidebar-foot { color: rgba(255,255,255,.62); }
.nav-link { color: rgba(255,255,255,.86); min-height: 44px; }
.brand small, .sidebar .brand small, .auth-aside .brand small, .site-footer .brand small { color: rgba(255,255,255,.72); }
.brand small { color: var(--muted); }
.site-header .brand small { color: var(--muted); }
.table th { color: #4B5A61; }
a:not(.btn):not(.nav-link):not(.app-tile):not(.brand) { text-underline-offset: 3px; }
input::placeholder, textarea::placeholder { color: #6B7A81; opacity: 1; }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; scroll-behavior: auto !important; }
}

/* ---------- 3. Immersive shell -------------------------------------------------------------- */
.ambient-layer { position: fixed; inset: 0; z-index: -1; pointer-events: none; overflow: hidden; }
.ambient-layer canvas, .ambient-host > canvas.ambient-canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.ambient-layer::after { content: ""; position: absolute; inset: 0; background: linear-gradient(to bottom, rgba(246,244,239,0) 0%, rgba(246,244,239,.35) 45%, var(--bg) 92%); }
.ambient-host { position: relative; isolation: isolate; overflow: hidden; }
.ambient-host > canvas.ambient-canvas { z-index: -1; pointer-events: none; }

.sidebar {
  background:
    radial-gradient(420px 260px at 0% 0%, color-mix(in srgb, var(--glow-1) 26%, transparent), transparent 70%),
    radial-gradient(380px 300px at 100% 100%, color-mix(in srgb, var(--glow-2) 18%, transparent), transparent 70%),
    linear-gradient(180deg, var(--brand-900), color-mix(in srgb, var(--brand-900) 82%, #000));
  border-inline-end: 1px solid rgba(255,255,255,.06);
}
.sidebar .brand-mark { background: linear-gradient(145deg, var(--glow-1), var(--brand-700)); box-shadow: 0 6px 18px -6px var(--glow-1); }
.nav-link { position: relative; transition: background .2s var(--ease-out), color .2s, transform .2s var(--ease-out); }
.nav-link:hover { background: rgba(255,255,255,.09); transform: translateX(2px); }
[dir="rtl"] .nav-link:hover { transform: translateX(-2px); }
.nav-link.active { background: linear-gradient(90deg, rgba(255,255,255,.16), rgba(255,255,255,.06)); box-shadow: inset 3px 0 0 var(--glow-1); }
[dir="rtl"] .nav-link.active { background: linear-gradient(-90deg, rgba(255,255,255,.16), rgba(255,255,255,.06)); box-shadow: inset -3px 0 0 var(--glow-1); }
.nav-link .icon { transition: transform .25s var(--ease-out); }
.nav-link:hover .icon, .nav-link.active .icon { transform: scale(1.12); color: #fff; }

.topbar { background: rgba(255,255,255,.72); backdrop-filter: saturate(1.6) blur(14px); -webkit-backdrop-filter: saturate(1.6) blur(14px); border-bottom-color: rgba(20,35,43,.08); }
.topbar .title { position: relative; padding-inline-start: .85rem; }
.topbar .title::before { content: ""; position: absolute; inset-inline-start: 0; top: 15%; bottom: 15%; width: 4px; border-radius: 4px; background: linear-gradient(var(--glow-1), var(--brand-700)); }
.main { position: relative; }
.content { position: relative; }

.page-head { position: relative; padding: 1.25rem 1.4rem; margin-bottom: 1.4rem; border-radius: 20px; border: 1px solid rgba(255,255,255,.7);
  background: linear-gradient(120deg, rgba(255,255,255,.92), rgba(255,255,255,.72)); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  box-shadow: 0 1px 2px rgba(20,35,43,.04), 0 12px 32px -18px color-mix(in srgb, var(--brand-700) 45%, transparent); overflow: hidden; }
.page-head::before { content: ""; position: absolute; inset-block: 0; inset-inline-start: 0; width: 5px; background: linear-gradient(var(--glow-1), var(--brand-700), var(--glow-2)); }
.page-head h1 { color: var(--brand-900); }

.card { border-color: rgba(20,35,43,.08); box-shadow: 0 1px 2px rgba(20,35,43,.04), 0 8px 24px -16px rgba(20,35,43,.16); transition: box-shadow .3s var(--ease-out), transform .3s var(--ease-out), border-color .3s; }
.card:hover { box-shadow: var(--shadow-lift); }
.card-header h2 .icon, .card-header h3 .icon { color: var(--brand-700); }
.kpi .value, .stat b { background: linear-gradient(120deg, var(--brand-800), var(--brand-600)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.btn-primary { background: linear-gradient(135deg, var(--brand-600), var(--brand-800)); box-shadow: 0 6px 16px -8px color-mix(in srgb, var(--brand-700) 70%, transparent); position: relative; overflow: hidden; }
.btn-primary:hover { background: linear-gradient(135deg, var(--brand-700), var(--brand-900)); transform: translateY(-1px); }
.btn-primary::after { content: ""; position: absolute; inset: 0; background: linear-gradient(110deg, transparent 30%, rgba(255,255,255,.28) 50%, transparent 70%); transform: translateX(-120%); transition: transform .7s var(--ease-out); pointer-events: none; }
.btn-primary:hover::after { transform: translateX(120%); }
.btn-ghost:hover { border-color: var(--brand-600); color: var(--brand-800); }
.app-tile, .service { overflow: hidden; }
a.app-tile:hover, .service:hover { transform: translateY(-4px); box-shadow: var(--shadow-lift); }
.app-tile .ico, .service .ico, .contact-info .ico { background: linear-gradient(145deg, var(--brand-50), var(--brand-100)); box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--brand-700) 12%, transparent); transition: transform .35s var(--ease-out); }
a.app-tile:hover .ico, .service:hover .ico { transform: rotate(-6deg) scale(1.08); }
.table tbody tr { transition: background .15s; }

/* entrance choreography — content only animates when the user allows motion */
@media (prefers-reduced-motion: no-preference) {
  html:not(.a11y-motion-off) .content > *, html:not(.a11y-motion-off) .reveal { animation: erp-rise .6s var(--ease-out) both; }
  html:not(.a11y-motion-off) .content > *:nth-child(2) { animation-delay: .06s; }
  html:not(.a11y-motion-off) .content > *:nth-child(3) { animation-delay: .12s; }
  html:not(.a11y-motion-off) .content > *:nth-child(4) { animation-delay: .18s; }
  html:not(.a11y-motion-off) .content > *:nth-child(n+5) { animation-delay: .24s; }
  html:not(.a11y-motion-off) .app-grid > *, html:not(.a11y-motion-off) .kpis > *, html:not(.a11y-motion-off) .service-grid > * { animation: erp-pop .55s var(--ease-out) both; }
  html:not(.a11y-motion-off) .app-grid > *:nth-child(2n), html:not(.a11y-motion-off) .kpis > *:nth-child(2n), html:not(.a11y-motion-off) .service-grid > *:nth-child(2n) { animation-delay: .07s; }
  html:not(.a11y-motion-off) .app-grid > *:nth-child(3n), html:not(.a11y-motion-off) .kpis > *:nth-child(3n), html:not(.a11y-motion-off) .service-grid > *:nth-child(3n) { animation-delay: .14s; }
}
@keyframes erp-rise { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
@keyframes erp-pop { from { opacity: 0; transform: translateY(10px) scale(.97); } to { opacity: 1; transform: none; } }

/* ---------- 4. Vivid hero surfaces (canvas painted by ambient.js) ---------------------------- */
.hero, .auth-aside, .page-hero, .welcome, .dash-hero, .cta { background: linear-gradient(150deg, var(--hero-1) 0%, var(--hero-2) 100%); }
.hero::after { opacity: .5; }
.welcome, .cta { position: relative; isolation: isolate; overflow: hidden; }
.auth-aside { position: relative; isolation: isolate; overflow: hidden; }
.site-header { background: rgba(255,255,255,.78); backdrop-filter: saturate(1.6) blur(14px); -webkit-backdrop-filter: saturate(1.6) blur(14px); }
.site-footer { background: linear-gradient(180deg, var(--brand-900), color-mix(in srgb, var(--brand-900) 80%, #000)); color: rgba(255,255,255,.8); }
.stat { border-color: rgba(20,35,43,.08); }
.auth-page { background: transparent; }

/* ---------- 5. Accessibility panel ---------------------------------------------------------- */
.a11y-fab { position: fixed; inset-inline-start: 1rem; bottom: 1rem; z-index: 90; width: 48px; height: 48px; border-radius: 50%; border: 2px solid #fff; cursor: pointer;
  background: linear-gradient(145deg, var(--brand-600), var(--brand-900)); color: #fff; display: grid; place-items: center; box-shadow: 0 10px 24px -8px rgba(0,0,0,.45); }
.a11y-fab svg { width: 26px; height: 26px; }
.a11y-fab:hover { transform: scale(1.06); }
.a11y-dialog { position: fixed; inset-inline-start: 1rem; bottom: 4.5rem; z-index: 95; width: min(380px, calc(100vw - 2rem)); max-height: calc(100vh - 6rem); overflow: auto;
  background: var(--surface); color: var(--ink); border: 1px solid var(--border); border-radius: 18px; box-shadow: 0 24px 60px -18px rgba(0,0,0,.4); padding: 1rem 1.1rem 1.1rem; }
.a11y-dialog[hidden] { display: none; }
.a11y-dialog h2 { font-size: 1.1rem; margin: 0; display: flex; gap: .5rem; align-items: center; }
.a11y-dialog .a11y-head { display: flex; align-items: center; justify-content: space-between; gap: .5rem; margin-bottom: .6rem; }
.a11y-dialog fieldset { border: 0; padding: 0; margin: .75rem 0 0; }
.a11y-dialog legend { font-weight: 800; font-size: .9rem; margin-bottom: .4rem; }
.a11y-seg { display: grid; grid-template-columns: repeat(3, 1fr); gap: .35rem; }
.a11y-seg button, .a11y-opt { min-height: 44px; border: 1px solid var(--border-2); background: var(--surface-2); color: var(--ink); border-radius: 10px; font: inherit; font-weight: 700; cursor: pointer; }
.a11y-seg button[aria-pressed="true"], .a11y-opt[aria-pressed="true"] { background: var(--brand-700); color: #fff; border-color: var(--brand-700); }
.a11y-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .45rem; }
.a11y-opt { display: flex; align-items: center; gap: .45rem; padding: .5rem .6rem; text-align: start; font-size: .88rem; line-height: 1.25; }
.a11y-opt svg { width: 20px; height: 20px; flex-shrink: 0; }
.a11y-actions { display: flex; gap: .5rem; flex-wrap: wrap; margin-top: .9rem; }
.a11y-actions .btn { flex: 1; }
.a11y-reading { position: fixed; inset-inline: 0; height: 2.6em; pointer-events: none; z-index: 80; background: color-mix(in srgb, #FFE29A 30%, transparent); border-block: 2px solid #B8912F; display: none; }
html.a11y-guide .a11y-reading { display: block; }
.a11y-speaking { outline: 3px dashed var(--brand-700); outline-offset: 4px; }

/* ---------- 6. User-selected accessibility modes -------------------------------------------- */
html.a11y-text-1 { font-size: 112.5%; }
html.a11y-text-2 { font-size: 125%; }
html.a11y-text-1 .app, html.a11y-text-2 .app { --sidebar-w: 300px; }
html.a11y-spacing body { line-height: 1.9 !important; letter-spacing: .06em; word-spacing: .16em; }
html.a11y-spacing p { margin-bottom: 1.6em; }
html.a11y-font body, html.a11y-font .btn, html.a11y-font input, html.a11y-font select, html.a11y-font textarea { font-family: Verdana, 'Tajawal', Tahoma, sans-serif !important; }
html.a11y-links a:not(.btn) { text-decoration: underline !important; text-decoration-thickness: 2px !important; }
html.a11y-focus :focus-visible, html.a11y-focus :focus { outline: 4px solid #FFB000 !important; outline-offset: 3px !important; box-shadow: 0 0 0 7px #000 !important; }
html.a11y-motion-off *, html.a11y-motion-off *::before, html.a11y-motion-off *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
html.a11y-contrast { --ink:#000; --ink-2:#111; --muted:#2B2B2B; --bg:#FFFFFF; --surface:#FFFFFF; --surface-2:#F2F2F2; --border:#1A1A1A; --border-2:#000;
  --brand-700:#00384A; --brand-600:#003040; --brand-800:#00252F; --brand-50:#E5F4F8; --brand-100:#CBE9F1; }
html.a11y-contrast body { background: #fff !important; }
html.a11y-contrast .ambient-layer, html.a11y-contrast canvas.ambient-canvas { display: none !important; }
html.a11y-contrast .card, html.a11y-contrast .page-head, html.a11y-contrast .topbar, html.a11y-contrast .input, html.a11y-contrast .select, html.a11y-contrast .btn-ghost { border-width: 2px !important; border-color: #000 !important; backdrop-filter: none !important; background: #fff !important; box-shadow: none !important; }
html.a11y-contrast .kpi .value, html.a11y-contrast .stat b { background: none; color: #000; }
html.a11y-contrast .sidebar, html.a11y-contrast .hero, html.a11y-contrast .auth-aside, html.a11y-contrast .page-hero, html.a11y-contrast .dash-hero, html.a11y-contrast .welcome, html.a11y-contrast .cta, html.a11y-contrast .site-footer { background: #000 !important; }
html.a11y-contrast .nav-link, html.a11y-contrast .nav-group-title, html.a11y-contrast .sidebar-foot { color: #fff !important; }
html.a11y-contrast a:not(.btn):not(.nav-link) { text-decoration: underline; }
html.a11y-contrast .muted, html.a11y-contrast .small.muted { color: #2B2B2B !important; }
@media print { .a11y-fab, .a11y-dialog, .ambient-layer, canvas.ambient-canvas { display: none !important; } }

/* keep the accessibility button clear of the sidebar and the assistant button */
@media (min-width: 981px) { .app ~ .a11y-fab { inset-inline-start: calc(var(--sidebar-w) + 1rem); } .app ~ .a11y-dialog { inset-inline-start: calc(var(--sidebar-w) + 1rem); } }
@media (max-width: 980px) { .app ~ .a11y-fab { bottom: 5.2rem; width: 44px; height: 44px; } .app ~ .a11y-dialog { bottom: 9.5rem; } }
.auth-page ~ .a11y-fab, .auth-page ~ .a11y-dialog { inset-inline-start: auto; inset-inline-end: 1rem; }
