/* ========================================================
   ATLAS INTELLIGENCE SYSTEM // DESIGN SYSTEM & TOKENS
   Classified Corporate Command Center Architecture
   ======================================================== */

@import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;500;600;700;800&family=Inter:wght@300;400;500;600;700;800&family=JetBrains+Mono:wght@400;500;600;700&family=IBM+Plex+Sans+Arabic:wght@400;500;600;700;800&family=Noto+Sans+Arabic:wght@400;500;600;700;800&display=swap');

:root {
    /* Color Palette - Dark Premium (Exclusive) */
    --background: #0B1017;
    --background-subtle: #0E1621;
    --surface: #121C28;
    --surface-secondary: #162230;
    --surface-elevated: #1B2B3D;
    --border: rgba(255, 255, 255, 0.07);
    --border-hover: rgba(255, 255, 255, 0.15);
    --border-active: rgba(37, 99, 235, 0.5);
    
    --text: #F8FAFC;
    --text-muted: #94A3B8;
    --text-subtle: #64748B;
    
    /* Primary Action = Blue */
    --primary: #2563EB;
    --primary-hover: #1D4ED8;
    --primary-subtle: rgba(37, 99, 235, 0.15);
    --primary-glow: rgba(37, 99, 235, 0.25);

    /* Emerald = Revenues & Positive */
    --emerald: #10B981;
    --emerald-hover: #059669;
    --emerald-subtle: rgba(16, 185, 129, 0.15);

    /* Cyan = Highlights & Projects */
    --cyan: #06B6D4;
    --cyan-subtle: rgba(6, 182, 212, 0.15);
    
    /* Warning = Soft Amber */
    --warning: #F59E0B;
    --warning-subtle: rgba(245, 158, 11, 0.15);
    
    /* Danger = Soft Red */
    --danger: #EF4444;
    --danger-hover: #DC2626;
    --danger-subtle: rgba(239, 68, 68, 0.15);
    
    --info: #3B82F6;
    --info-subtle: rgba(59, 130, 246, 0.15);
    --success: #10B981;

    /* Layout & Typography */
    --font-sans: 'Inter', system-ui, -apple-system, sans-serif;
    --font-num: 'Plus Jakarta Sans', 'Inter', -apple-system, system-ui, sans-serif;
    --font-mono: 'JetBrains Mono', monospace;
    --font-arabic: 'IBM Plex Sans Arabic', 'Noto Sans Arabic', 'Tajawal', system-ui, -apple-system, sans-serif;

    --sidebar-width: 260px;
    --sidebar-collapsed-width: 76px;
    --topbar-height: 70px;
    
    --radius-sm: 6px;
    --radius: 10px;
    --radius-lg: 16px;
    --radius-full: 9999px;

    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.3);
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.4), 0 2px 4px -1px rgba(0, 0, 0, 0.2);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.5), 0 4px 6px -2px rgba(0, 0, 0, 0.3);

    --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition: 200ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-slow: 300ms cubic-bezier(0.4, 0, 0.2, 1);
}

/* ========================================================
   PREMIUM ARABIC TYPOGRAPHY & RTL DESIGN SYSTEM
   ======================================================== */
html[dir="rtl"], body.rtl {
    font-family: var(--font-arabic);
    line-height: 1.72;
    letter-spacing: normal;
    text-align: right;
}

html[dir="rtl"] h1, 
html[dir="rtl"] h2, 
html[dir="rtl"] h3, 
html[dir="rtl"] h4, 
html[dir="rtl"] h5, 
html[dir="rtl"] h6 {
    font-family: var(--font-arabic);
    font-weight: 750;
    letter-spacing: 0 !important;
    line-height: 1.45;
}

html[dir="rtl"] .btn, 
html[dir="rtl"] .form-label, 
html[dir="rtl"] .nav-text, 
html[dir="rtl"] .modal-title,
html[dir="rtl"] .card-title,
html[dir="rtl"] .kpi-label {
    font-family: var(--font-arabic);
    letter-spacing: 0;
}

html[dir="rtl"] .form-label {
    font-size: 0.92rem;
    font-weight: 600;
    display: block;
    margin-bottom: 0.4rem;
}

html[dir="rtl"] .nav-section-title {
    font-family: var(--font-arabic);
    letter-spacing: 0.02em;
    font-size: 0.74rem;
    font-weight: 750;
}

html[dir="rtl"] .badge {
    letter-spacing: 0;
    font-weight: 600;
}

/* BiDi Numerical Protection & Tabular Numbers */
.numeric-value,
.currency-suffix,
.currency-unit,
.financial-col,
.num-col,
.badge.mono,
.date-value,
.percent-value,
.code-value,
.mono,
[dir="ltr"],
.force-ltr {
    direction: ltr !important;
    unicode-bidi: isolate !important;
    font-variant-numeric: tabular-nums lining-nums;
}

html[dir="rtl"] .numeric-value,
html[dir="rtl"] .badge.mono,
html[dir="rtl"] .date-value,
html[dir="rtl"] .percent-value,
html[dir="rtl"] .code-value,
html[dir="rtl"] .mono,
html[dir="rtl"] [dir="ltr"],
html[dir="rtl"] .force-ltr {
    direction: ltr !important;
    unicode-bidi: isolate !important;
    display: inline-block;
}

html[dir="rtl"] .kpi-tile {
    text-align: right;
}

html[dir="rtl"] .kpi-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

html[dir="rtl"] .kpi-value {
    direction: ltr !important;
    unicode-bidi: isolate !important;
    display: inline-flex;
    align-items: baseline;
    justify-content: flex-start;
    gap: 0.35rem;
    font-family: var(--font-num);
}

html[dir="rtl"] .kpi-sub {
    direction: rtl;
    text-align: right;
    display: flex;
    align-items: center;
    gap: 0.4rem;
    flex-wrap: wrap;
}

html[dir="rtl"] .kpi-sub .numeric-value,
html[dir="rtl"] .kpi-sub strong {
    direction: ltr !important;
    unicode-bidi: isolate !important;
    display: inline-block;
}

html[dir="rtl"] .table th,
html[dir="rtl"] .table td {
    text-align: right;
}

html[dir="rtl"] .table th.financial-col,
html[dir="rtl"] .table td.financial-col,
html[dir="rtl"] .table th.num-col,
html[dir="rtl"] .table td.num-col {
    text-align: left !important;
    direction: ltr !important;
    unicode-bidi: isolate !important;
}

html[dir="rtl"] .table th:last-child,
html[dir="rtl"] .table td:last-child {
    text-align: left;
}

html[dir="rtl"] .dropdown-menu {
    right: auto;
    left: 0;
}

/* Directional Icon Inversion (Chevrons / Arrows only) */
html[dir="rtl"] .icon-directional,
html[dir="rtl"] .icon-arrow-right,
html[dir="rtl"] .icon-arrow-left,
html[dir="rtl"] .icon-chevron-right,
html[dir="rtl"] .icon-chevron-left {
    transform: scaleX(-1);
}

/* Form Controls & Inputs */
html[dir="rtl"] .form-control {
    text-align: right;
}

html[dir="rtl"] .form-control.mono,
html[dir="rtl"] input[type="number"],
html[dir="rtl"] input[type="date"],
html[dir="rtl"] input[type="email"],
html[dir="rtl"] input[type="tel"] {
    direction: ltr !important;
    text-align: left;
    font-family: var(--font-mono);
}

html[dir="rtl"] .input-group-suffix {
    border-left: none;
    border-right: 1px solid var(--border);
    border-radius: var(--radius) 0 0 var(--radius);
}

html[dir="rtl"] .input-group .form-control {
    border-radius: 0 var(--radius) var(--radius) 0;
}

/* Reset & Box Sizing */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html, body {
    height: 100%;
    background-color: var(--background);
    color: var(--text);
    font-family: var(--font-sans);
    font-size: 16px;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    overflow-x: hidden;
}

/* ========================================================
   LIVING AMBIENT BACKGROUND SYSTEM (5 LAYERS)
   ======================================================== */
.ambient-background {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    overflow: hidden;
    pointer-events: none !important;
    z-index: 0;
    background-color: var(--background);
}

/* Layer 2 & 4: Slow Floating Ambient Blobs */
.ambient-blob {
    position: absolute;
    border-radius: 50%;
    pointer-events: none;
    will-change: transform, opacity;
}

.ambient-blob-1 {
    width: 720px;
    height: 720px;
    top: -120px;
    left: 10%;
    background: radial-gradient(circle, rgba(37, 99, 235, 0.11) 0%, rgba(37, 99, 235, 0) 70%);
    filter: blur(100px);
    animation: ambientFloat1 34s ease-in-out infinite alternate;
    transform: translate3d(var(--parallax-x1, 0px), var(--parallax-y1, 0px), 0);
}

.ambient-blob-2 {
    width: 680px;
    height: 680px;
    bottom: -160px;
    right: 8%;
    background: radial-gradient(circle, rgba(6, 182, 212, 0.08) 0%, rgba(6, 182, 212, 0) 70%);
    filter: blur(120px);
    animation: ambientFloat2 28s ease-in-out infinite alternate;
    transform: translate3d(var(--parallax-x2, 0px), var(--parallax-y2, 0px), 0);
}

.ambient-blob-3 {
    width: 520px;
    height: 520px;
    top: 40%;
    left: 50%;
    background: radial-gradient(circle, rgba(16, 185, 129, 0.045) 0%, rgba(16, 185, 129, 0) 70%);
    filter: blur(110px);
    animation: ambientFloat3 38s ease-in-out infinite alternate;
    transform: translate3d(var(--parallax-x3, 0px), var(--parallax-y3, 0px), 0);
}

@keyframes ambientFloat1 {
    0% { transform: translate3d(0, 0, 0) scale(1) rotate(0deg); opacity: 0.9; }
    50% { transform: translate3d(60px, 45px, 0) scale(1.08) rotate(12deg); opacity: 1; }
    100% { transform: translate3d(-35px, 80px, 0) scale(0.94) rotate(-8deg); opacity: 0.85; }
}

@keyframes ambientFloat2 {
    0% { transform: translate3d(0, 0, 0) scale(1) rotate(0deg); opacity: 0.85; }
    50% { transform: translate3d(-65px, -50px, 0) scale(1.06) rotate(-15deg); opacity: 1; }
    100% { transform: translate3d(45px, -35px, 0) scale(0.93) rotate(12deg); opacity: 0.8; }
}

@keyframes ambientFloat3 {
    0% { transform: translate3d(0, 0, 0) scale(1); opacity: 0.7; }
    50% { transform: translate3d(40px, -55px, 0) scale(1.1); opacity: 0.95; }
    100% { transform: translate3d(-45px, 35px, 0) scale(0.95); opacity: 0.75; }
}

/* Layer 3: Technical Micro-Grid Pattern */
.technical-grid {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-image: radial-gradient(rgba(255, 255, 255, 0.032) 1px, transparent 1px);
    background-size: 32px 32px;
    opacity: 0.55;
    pointer-events: none;
}

/* Layer 5: Interactive Mouse Follow Glow */
.mouse-glow {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: radial-gradient(
        650px circle at var(--mouse-glow-x, -2000px) var(--mouse-glow-y, -2000px),
        rgba(6, 182, 212, 0.065) 0%,
        rgba(37, 99, 235, 0.035) 35%,
        transparent 70%
    );
    pointer-events: none;
    will-change: background;
}

/* Prefers Reduced Motion */
@media (prefers-reduced-motion: reduce) {
    .ambient-blob {
        animation: none !important;
    }
    .mouse-glow {
        display: none !important;
    }
}

/* Typography - Clean, High Readability */
h1, h2, h3, h4, h5, h6 {
    color: var(--text);
    font-weight: 700;
    letter-spacing: -0.02em;
    line-height: 1.3;
}

h1 { font-size: 2.15rem; } /* 34px */
h2 { font-size: 1.65rem; } /* 26px */
h3 { font-size: 1.25rem; } /* 20px */
h4 { font-size: 1.1rem; }  /* 17.5px */

p { color: var(--text-muted); font-size: 1rem; line-height: 1.6; }

a {
    color: var(--primary);
    text-decoration: none;
    transition: color var(--transition);
}
a:hover { color: var(--primary-hover); }

.mono {
    font-family: var(--font-mono);
}

/* App Shell Layout */
.app-layout {
    display: flex;
    min-height: 100vh;
    width: 100%;
    position: relative;
}

/* Sidebar */
.app-sidebar {
    width: var(--sidebar-width);
    background-color: rgba(14, 22, 33, 0.96);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 100;
    transition: width var(--transition), transform var(--transition);
    overflow: hidden;
}

html[dir="rtl"] .app-sidebar {
    left: auto;
    right: 0;
    border-right: none;
    border-left: 1px solid var(--border);
}

.sidebar-brand {
    height: var(--topbar-height);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.25rem;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
    flex-shrink: 0;
    position: sticky;
    top: 0;
    z-index: 10;
}

.atlas-brand-link, .brand-logo {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    color: var(--text);
    text-decoration: none;
    transition: transform 0.2s ease, opacity 0.2s ease;
}

.atlas-brand-link:hover, .brand-logo:hover {
    transform: translateX(2px);
    opacity: 0.95;
}

.atlas-emblem-wrap {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1), filter 0.25s ease;
}

.atlas-brand-link:hover .atlas-emblem-wrap {
    transform: scale(1.05);
    filter: drop-shadow(0 0 10px rgba(56, 189, 248, 0.4));
}

.atlas-brand-text {
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 0.1rem;
    line-height: 1.2;
}

.atlas-brand-row {
    display: flex;
    align-items: center;
    gap: 0.45rem;
}

.atlas-brand-title {
    font-size: 1.15rem;
    font-weight: 850;
    letter-spacing: 0.05em;
    color: #F8FAFC;
}

.atlas-badge {
    font-family: var(--font-mono);
    font-size: 0.65rem;
    font-weight: 750;
    letter-spacing: 0.05em;
    padding: 1px 5px;
    background: rgba(6, 182, 212, 0.12);
    color: var(--cyan);
    border: 1px solid rgba(6, 182, 212, 0.35);
    border-radius: 4px;
}

.atlas-brand-sub {
    font-size: 0.65rem;
    font-weight: 650;
    letter-spacing: 0.07em;
    color: var(--text-subtle);
    text-transform: uppercase;
}

/* Auth View Special Branding */
.atlas-logo-auth {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    margin-bottom: 2rem;
}

.atlas-emblem-glow-wrap {
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 1rem;
    filter: drop-shadow(0 0 20px rgba(37, 99, 235, 0.35));
    transition: transform 0.3s ease;
}

.atlas-logo-auth:hover .atlas-emblem-glow-wrap {
    transform: scale(1.05);
    filter: drop-shadow(0 0 25px rgba(56, 189, 248, 0.5));
}

.atlas-auth-wordmark .atlas-brand-title {
    font-size: 1.5rem;
    font-weight: 850;
    letter-spacing: 0.06em;
}

.atlas-auth-wordmark .atlas-brand-sub {
    font-size: 0.78rem;
    color: var(--text-muted);
    margin-top: 0.35rem;
    letter-spacing: 0.08em;
}

.brand-icon {
    width: 34px;
    height: 34px;
    background: linear-gradient(135deg, var(--primary), var(--cyan));
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #080A0D;
    font-weight: 800;
    box-shadow: 0 0 15px var(--primary-glow);
}

.classified-banner {
    padding: 0.5rem 1.25rem;
    background-color: rgba(0,0,0,0.3);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 0.7rem;
    font-family: var(--font-mono);
    color: var(--text-subtle);
    letter-spacing: 0.08em;
}

.status-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background-color: var(--primary);
    display: inline-block;
    box-shadow: 0 0 8px var(--primary);
    animation: pulse 2s infinite;
}

.status-dot.danger {
    background-color: var(--danger);
    box-shadow: 0 0 8px var(--danger);
}

.status-dot.warning {
    background-color: var(--warning);
    box-shadow: 0 0 8px var(--warning);
}

@keyframes pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.4; transform: scale(0.85); }
}

.sidebar-nav {
    flex: 1 1 auto;
    min-height: 0;
    padding: 1rem 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    overflow-y: auto;
    overflow-x: hidden;
    scrollbar-width: none; /* Firefox */
    -ms-overflow-style: none; /* IE / Edge */
    overscroll-behavior: contain;
}

.sidebar-nav::-webkit-scrollbar {
    display: none;
    width: 0;
    height: 0;
}

.nav-section-title {
    font-size: 0.68rem;
    font-family: var(--font-mono);
    color: var(--text-subtle);
    padding: 0.75rem 0.75rem 0.25rem;
    letter-spacing: 0.1em;
    text-transform: uppercase;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.65rem 0.85rem;
    color: var(--text-muted);
    border-radius: var(--radius);
    font-weight: 500;
    transition: var(--transition-fast);
    position: relative;
}

.nav-item:hover {
    color: var(--text);
    background-color: var(--surface-secondary);
}

.nav-item.active {
    color: var(--text);
    background-color: var(--surface-secondary);
    border-left: 3px solid var(--primary);
}

html[dir="rtl"] .nav-item.active {
    border-left: none;
    border-right: 3px solid var(--primary);
}

.nav-icon {
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0.8;
}

.nav-item.active .nav-icon {
    opacity: 1;
    color: var(--primary);
}

.nav-badge {
    margin-left: auto;
    padding: 0.15rem 0.45rem;
    font-size: 0.7rem;
    font-family: var(--font-mono);
    border-radius: var(--radius-full);
    background-color: var(--surface-elevated);
    color: var(--text-muted);
}

html[dir="rtl"] .nav-badge {
    margin-left: 0;
    margin-right: auto;
}

.nav-badge.danger {
    background-color: var(--danger-subtle);
    color: var(--danger);
    font-weight: 700;
}

.sidebar-user {
    padding: 0.85rem 1rem;
    border-top: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 0.75rem;
    background-color: var(--surface);
    flex-shrink: 0;
    position: sticky;
    bottom: 0;
    z-index: 10;
}

.user-avatar {
    width: 36px;
    height: 36px;
    border-radius: var(--radius);
    background: linear-gradient(135deg, #1e293b, #334155);
    border: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    color: var(--text);
    font-size: 0.85rem;
}

.user-info {
    flex: 1;
    overflow: hidden;
}

.user-name {
    font-weight: 600;
    font-size: 0.85rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-clearance {
    font-size: 0.68rem;
    font-family: var(--font-mono);
    color: var(--primary);
}

/* Main Content Area */
.app-main {
    flex: 1;
    margin-left: var(--sidebar-width);
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    width: calc(100% - var(--sidebar-width));
    transition: margin var(--transition), width var(--transition);
}

html[dir="rtl"] .app-main {
    margin-left: 0;
    margin-right: var(--sidebar-width);
}

/* Topbar */
.app-topbar {
    height: var(--topbar-height);
    background-color: rgba(14, 22, 33, 0.88);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.5rem;
    position: sticky;
    top: 0;
    z-index: 90;
}

.topbar-left, .topbar-right {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.mobile-toggle-btn {
    display: none;
    background: none;
    border: 1px solid var(--border);
    color: var(--text);
    padding: 0.5rem;
    border-radius: var(--radius);
    cursor: pointer;
}

.system-telemetry {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-family: var(--font-mono);
    font-size: 0.75rem;
    color: var(--text-muted);
    background-color: var(--surface);
    padding: 0.35rem 0.75rem;
    border-radius: var(--radius);
    border: 1px solid var(--border);
}

/* Content Body */
.app-content {
    flex: 1;
    padding: 1.5rem;
    max-width: 1600px;
    width: 100%;
    margin: 0 auto;
}

/* Tactical Cards */
.card {
    background-color: rgba(18, 28, 40, 0.88);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    transition: border-color var(--transition), box-shadow var(--transition);
    position: relative;
    overflow: hidden;
}

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

.card-header {
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.card-title {
    font-size: 1.05rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.card-body {
    padding: 1.5rem;
}

.card-footer {
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--border);
    background-color: var(--surface-secondary);
}

/* KPI Grid */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.kpi-tile {
    background-color: rgba(18, 28, 40, 0.88);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.25rem;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    position: relative;
    overflow: hidden;
    transition: transform var(--transition), border-color var(--transition), box-shadow var(--transition);
}

.kpi-tile:hover {
    transform: translateY(-2px);
    border-color: var(--border-hover);
    box-shadow: var(--shadow);
}

.kpi-tile::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 2px;
    background: transparent;
}

.kpi-tile.primary::before { background: var(--primary); }
.kpi-tile.cyan::before { background: var(--cyan); }
.kpi-tile.warning::before { background: var(--warning); }
.kpi-tile.danger::before { background: var(--danger); }

/* ========================================================
   NUMERICAL TYPOGRAPHY SYSTEM (FINANCIAL SAAS & CRM)
   ======================================================== */
.num, .num-val, .kpi-value, .financial-amount, .pct-val,
.counter-val, .stat-number, .currency-val, .badge-num {
    font-family: var(--font-num);
    font-variant-numeric: tabular-nums lining-nums;
    font-feature-settings: "tnum" 1, "lnum" 1, "cv02" 1, "cv03" 1, "cv04" 1, "cv11" 1;
    letter-spacing: -0.025em;
}

.mono {
    font-family: var(--font-mono);
    font-variant-numeric: tabular-nums lining-nums;
    font-feature-settings: "tnum" 1, "lnum" 1;
}

.kpi-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.75rem;
}

.kpi-label {
    font-size: 0.92rem;
    font-family: var(--font-sans);
    font-weight: 600;
    color: var(--text-muted);
    letter-spacing: 0.05em;
    text-transform: uppercase;
}

.kpi-icon {
    width: 36px;
    height: 36px;
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: var(--surface-secondary);
    color: var(--text-muted);
    font-size: 1.15rem;
}

.kpi-value {
    font-family: var(--font-num);
    font-size: 2.5rem; /* ~40px */
    font-weight: 750;
    line-height: 1.15;
    letter-spacing: -0.035em;
    font-variant-numeric: tabular-nums lining-nums;
    font-feature-settings: "tnum" 1, "lnum" 1;
    display: flex;
    align-items: baseline;
    gap: 0.35rem;
    margin: 0.35rem 0;
}

.kpi-value small, 
.kpi-value .currency-suffix {
    font-size: 1.05rem;
    font-weight: 600;
    letter-spacing: 0.03em;
    color: var(--text-muted);
    opacity: 0.85;
    text-transform: uppercase;
}

.kpi-sub {
    font-size: 0.92rem;
    font-weight: 500;
    color: var(--text-subtle);
    display: flex;
    align-items: baseline;
    gap: 0.45rem;
    margin-top: 0.45rem;
}

.kpi-sub span:first-child,
.kpi-sub strong,
.kpi-sub .num-val {
    font-family: var(--font-num);
    font-weight: 600;
    font-variant-numeric: tabular-nums lining-nums;
    letter-spacing: -0.02em;
}

/* Strategic Badges */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.3rem 0.75rem;
    border-radius: var(--radius-sm);
    font-size: 0.82rem;
    font-family: var(--font-mono);
    font-weight: 600;
    letter-spacing: 0.03em;
    text-transform: uppercase;
}

.badge-primary { background: var(--primary-subtle); color: var(--primary); border: 1px solid rgba(37,99,235,0.3); }
.badge-emerald { background: var(--emerald-subtle); color: var(--emerald); border: 1px solid rgba(16,185,129,0.3); }
.badge-cyan { background: var(--cyan-subtle); color: var(--cyan); border: 1px solid rgba(6,182,212,0.3); }
.badge-warning { background: var(--warning-subtle); color: var(--warning); border: 1px solid rgba(245,158,11,0.3); }
.badge-danger { background: var(--danger-subtle); color: var(--danger); border: 1px solid rgba(239,68,68,0.3); }
.badge-secondary { background: var(--surface-elevated); color: var(--text-muted); border: 1px solid var(--border); }

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.65rem 1.25rem;
    font-size: 0.95rem; /* ~15.5px */
    font-weight: 600;
    border-radius: var(--radius);
    border: 1px solid transparent;
    cursor: pointer;
    transition: var(--transition-fast);
    font-family: var(--font-sans);
    line-height: 1.25;
    text-decoration: none;
}

.btn:active { transform: scale(0.98); }

.btn-primary {
    background-color: var(--primary);
    color: #FFFFFF;
}
.btn-primary:hover {
    background-color: var(--primary-hover);
    box-shadow: 0 4px 14px var(--primary-glow);
    color: #FFFFFF;
}

.btn-emerald, .btn-success {
    background-color: var(--emerald);
    color: #FFFFFF;
}
.btn-emerald:hover, .btn-success:hover {
    background-color: var(--emerald-hover);
    box-shadow: 0 4px 14px rgba(16, 185, 129, 0.3);
    color: #FFFFFF;
}

.btn-secondary {
    background-color: var(--surface-secondary);
    color: var(--text);
    border-color: var(--border);
}
.btn-secondary:hover {
    background-color: var(--surface-elevated);
    border-color: var(--border-hover);
    color: var(--text);
}

.btn-danger {
    background-color: var(--danger);
    color: #FFFFFF;
}
.btn-danger:hover {
    background-color: var(--danger-hover);
    box-shadow: 0 4px 14px rgba(239, 68, 68, 0.3);
    color: #FFFFFF;
}

.btn-sm {
    padding: 0.45rem 0.85rem;
    font-size: 0.88rem; /* 14px */
}

.btn-icon {
    padding: 0.6rem;
    border-radius: var(--radius);
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

/* Forms & Inputs */
.form-group {
    margin-bottom: 1.25rem;
}

.form-group {
    margin-bottom: 1.25rem;
}

.form-label {
    display: block;
    font-size: 0.92rem;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 0.45rem;
    letter-spacing: 0.01em;
}

.form-control {
    width: 100%;
    min-height: 46px;
    padding: 0.75rem 1rem;
    background-color: var(--surface-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-family: var(--font-sans);
    font-size: 0.98rem;
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

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

.form-control:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-subtle);
}

.form-control.is-invalid {
    border-color: var(--danger);
}

.form-control.is-invalid:focus {
    box-shadow: 0 0 0 3px var(--danger-subtle);
}

.invalid-feedback {
    font-size: 0.82rem;
    color: var(--danger);
    margin-top: 0.35rem;
    display: block;
}

.form-text {
    font-size: 0.82rem;
    color: var(--text-muted);
    margin-top: 0.35rem;
}

/* Input Group with Suffix (e.g., MAD, %, etc.) */
.input-group {
    display: flex;
    position: relative;
    width: 100%;
}

.input-group .form-control {
    flex: 1;
    border-top-right-radius: 0;
    border-bottom-right-radius: 0;
}

.input-group-suffix {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 1.15rem;
    background-color: var(--surface);
    border: 1px solid var(--border);
    border-left: none;
    border-top-right-radius: var(--radius);
    border-bottom-right-radius: var(--radius);
    color: var(--text-muted);
    font-size: 0.9rem;
    font-weight: 700;
    font-family: var(--font-mono);
    user-select: none;
}

textarea.form-control {
    min-height: 90px;
    resize: vertical;
}

select.form-control {
    cursor: pointer;
}

/* Progress Bars */
.progress-bar-container {
    width: 100%;
    height: 8px;
    background-color: var(--surface-secondary);
    border-radius: var(--radius-full);
    overflow: hidden;
    position: relative;
}

.progress-bar-fill {
    height: 100%;
    background: var(--primary);
    border-radius: var(--radius-full);
    transition: width var(--transition-slow);
}

/* Table Styles */
.table-responsive {
    width: 100%;
    overflow-x: auto;
}

.table {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
}

html[dir="rtl"] .table {
    text-align: right;
}

.table th {
    padding: 0.85rem 1.15rem;
    background-color: var(--surface-secondary);
    font-size: 0.85rem;
    font-family: var(--font-sans);
    color: var(--text-muted);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    border-bottom: 1px solid var(--border);
}

.table td {
    padding: 1rem 1.15rem;
    border-bottom: 1px solid var(--border);
    font-size: 0.95rem;
    vertical-align: middle;
}

.table tbody tr {
    transition: background-color var(--transition-fast);
}

.table tbody tr:hover {
    background-color: rgba(255, 255, 255, 0.03);
}

/* Financial Columns & Data Alignment */
.table th.financial-col, .table td.financial-col,
.table th.num-col, .table td.num-col {
    text-align: right;
    font-family: var(--font-num);
    font-variant-numeric: tabular-nums lining-nums;
    font-feature-settings: "tnum" 1, "lnum" 1;
    font-weight: 650;
    letter-spacing: -0.02em;
}

html[dir="rtl"] .table th.financial-col, html[dir="rtl"] .table td.financial-col,
html[dir="rtl"] .table th.num-col, html[dir="rtl"] .table td.num-col {
    text-align: left;
}

.table td.financial-col {
    font-size: 0.98rem;
}

.table td.financial-col.positive {
    color: var(--emerald);
}

.table td.financial-col.negative {
    color: var(--danger);
}

.financial-amount {
    font-family: var(--font-num);
    font-variant-numeric: tabular-nums lining-nums;
    font-weight: 650;
    letter-spacing: -0.02em;
}

.currency-unit {
    font-size: 0.8em;
    font-weight: 600;
    color: var(--text-subtle);
    margin-left: 0.25rem;
    text-transform: uppercase;
    letter-spacing: 0.02em;
}

.pct-badge {
    font-family: var(--font-num);
    font-weight: 700;
    font-variant-numeric: tabular-nums lining-nums;
    letter-spacing: -0.02em;
    display: inline-flex;
    align-items: center;
    padding: 0.2rem 0.55rem;
    border-radius: var(--radius-sm);
}

/* Kanban Board */
.kanban-board {
    display: grid;
    grid-template-columns: repeat(5, minmax(280px, 1fr));
    gap: 1rem;
    overflow-x: auto;
    padding-bottom: 1rem;
}

.kanban-col {
    background-color: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    display: flex;
    flex-direction: column;
    max-height: calc(100vh - 220px);
}

.kanban-header {
    padding: 0.85rem 1rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.kanban-body {
    padding: 0.85rem;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    flex: 1;
}

.kanban-card {
    background-color: var(--surface-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.85rem;
    transition: transform var(--transition-fast), border-color var(--transition-fast);
    cursor: grab;
}

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

/* Flash Alerts */
.alert {
    padding: 0.85rem 1.25rem;
    border-radius: var(--radius);
    margin-bottom: 1.25rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: 0.85rem;
    border: 1px solid transparent;
}

.alert-success { background: var(--primary-subtle); color: var(--primary); border-color: rgba(16,185,129,0.3); }
.alert-danger { background: var(--danger-subtle); color: var(--danger); border-color: rgba(239,68,68,0.3); }
.alert-warning { background: var(--warning-subtle); color: var(--warning); border-color: rgba(245,158,11,0.3); }
.alert-info { background: var(--info-subtle); color: var(--info); border-color: rgba(59,130,246,0.3); }

/* Modal & Drawer Global Robust Architecture */
.modal,
.modal-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    background-color: rgba(4, 7, 12, 0.84);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    padding: max(16px, 2.5dvh) max(12px, 2.5dvw);
    box-sizing: border-box;
    overflow: hidden;
}

.modal.active,
.modal-backdrop.active {
    display: flex;
}

.modal-dialog {
    width: 100%;
    max-width: 640px;
    max-height: calc(100dvh - 32px);
    max-height: calc(100vh - 32px);
    margin: auto;
    display: flex;
    flex-direction: column;
    min-height: 0;
    position: relative;
    z-index: 1;
}

.modal-dialog-sm {
    max-width: 520px;
}

.modal-dialog-lg {
    max-width: 780px;
}

.modal-content {
    background-color: var(--surface);
    border: 1px solid rgba(255, 255, 255, 0.14);
    border-radius: var(--radius-lg);
    width: 100%;
    max-height: calc(100dvh - 32px);
    max-height: calc(100vh - 32px);
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
    box-shadow: 0 24px 60px rgba(0, 0, 0, 0.8), 0 0 1px rgba(255, 255, 255, 0.2);
    animation: modalIn 180ms cubic-bezier(0.16, 1, 0.3, 1);
    position: relative;
}

/* Ensure forms inside modals stretch and constrain their bodies */
.modal form,
.modal-content form,
.modal-dialog form,
.modal-dialog > .modal-content > form {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    min-height: 0;
    overflow: hidden;
    margin: 0;
}

.modal-header {
    padding: 1.25rem 1.75rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    background: var(--surface);
    flex-shrink: 0;
    position: sticky;
    top: 0;
    z-index: 10;
}

.modal-title {
    font-size: 1.35rem;
    font-weight: 750;
    color: var(--text);
    letter-spacing: -0.02em;
    margin: 0;
    display: flex;
    align-items: center;
    gap: 0.6rem;
}

.modal-subtitle {
    font-size: 0.92rem;
    color: var(--text-muted);
    margin-top: 0.35rem;
    font-weight: 400;
    line-height: 1.4;
}

.modal-close {
    background: none;
    border: 1px solid var(--border);
    color: var(--text-muted);
    font-size: 1.25rem;
    width: 34px;
    height: 34px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition-fast);
    flex-shrink: 0;
    margin-left: 1rem;
}

.modal-close:hover {
    color: var(--text);
    border-color: var(--border-hover);
    background: var(--surface-secondary);
}

.modal-body {
    padding: 1.5rem 1.75rem;
    overflow-y: auto !important;
    overflow-x: hidden;
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
}

.modal-footer {
    padding: 1rem 1.75rem;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--surface);
    flex-shrink: 0;
    position: sticky;
    bottom: 0;
    z-index: 10;
    box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.35);
}

@media (max-width: 640px) {
    .modal,
    .modal-backdrop {
        padding: 8px;
        align-items: flex-end;
    }
    .modal-dialog {
        max-width: 100%;
        max-height: calc(100dvh - 16px);
        max-height: calc(100vh - 16px);
        margin: 0;
    }
    .modal-content {
        max-height: calc(100dvh - 16px);
        max-height: calc(100vh - 16px);
        border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    }
    .modal-header {
        padding: 1rem 1.25rem;
    }
    .modal-body {
        padding: 1.25rem;
        gap: 1rem;
    }
    .modal-footer {
        padding: 0.85rem 1.25rem;
        flex-wrap: wrap;
        gap: 0.5rem;
    }
}

/* Logical Form Section Divider */
.form-section {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    padding-bottom: 1.25rem;
    border-bottom: 1px solid var(--border);
}

.form-section:last-child {
    border-bottom: none;
    padding-bottom: 0;
}

.form-section-title {
    font-size: 0.82rem;
    font-weight: 750;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    display: flex;
    align-items: center;
    gap: 0.45rem;
}

/* Form Details / Accordion */
details.form-accordion {
    background: var(--surface-secondary);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    padding: 0.85rem 1.25rem;
}

details.form-accordion summary {
    cursor: pointer;
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--text-muted);
    user-select: none;
}

details.form-accordion summary:hover {
    color: var(--text);
}

@keyframes modalIn {
    from { opacity: 0; transform: scale(0.96) translateY(-10px); }
    to { opacity: 1; transform: scale(1) translateY(0); }
}

/* Toasts */
#toast-container {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

html[dir="rtl"] #toast-container {
    right: auto;
    left: 1.5rem;
}

.toast {
    background-color: var(--surface-elevated);
    border: 1px solid var(--border);
    padding: 0.75rem 1.25rem;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    color: var(--text);
    font-size: 0.85rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    animation: toastSlideIn 200ms ease-out;
}

@keyframes toastSlideIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Empty State */
.empty-state {
    padding: 3.5rem 1.5rem;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.empty-icon {
    width: 56px;
    height: 56px;
    border-radius: var(--radius-lg);
    background-color: var(--surface-secondary);
    color: var(--text-subtle);
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 1rem;
}

/* Responsive Rules */
@media (max-width: 1024px) {
    .app-sidebar {
        width: var(--sidebar-collapsed-width);
    }
    .app-sidebar .atlas-brand-text,
    .app-sidebar .brand-text, 
    .app-sidebar .nav-text, 
    .app-sidebar .classified-banner, 
    .app-sidebar .user-info, 
    .app-sidebar .nav-section-title {
        display: none;
    }
    .app-sidebar .nav-item {
        justify-content: center;
        padding: 0.75rem;
    }
    .app-sidebar .sidebar-brand {
        justify-content: center;
        padding: 0;
    }
    .app-sidebar .atlas-brand-link {
        justify-content: center;
        width: 100%;
    }
    .app-main {
        margin-left: var(--sidebar-collapsed-width);
        width: calc(100% - var(--sidebar-collapsed-width));
    }
    html[dir="rtl"] .app-main {
        margin-left: 0;
        margin-right: var(--sidebar-collapsed-width);
    }
}

@media (max-width: 768px) {
    .mobile-toggle-btn {
        display: block;
    }
    .app-sidebar {
        transform: translateX(-100%);
        width: 270px;
    }
    .app-sidebar.open {
        transform: translateX(0);
    }
    html[dir="rtl"] .app-sidebar {
        transform: translateX(100%);
    }
    html[dir="rtl"] .app-sidebar.open {
        transform: translateX(0);
    }
    .app-sidebar .brand-text, 
    .app-sidebar .nav-text, 
    .app-sidebar .classified-banner, 
    .app-sidebar .user-info, 
    .app-sidebar .nav-section-title {
        display: block;
    }
    .app-sidebar .nav-item {
        justify-content: flex-start;
        padding: 0.65rem 0.85rem;
    }
    .app-sidebar .sidebar-brand {
        justify-content: space-between;
        padding: 0 1.25rem;
    }
    .app-main {
        margin-left: 0 !important;
        margin-right: 0 !important;
        width: 100% !important;
    }
    .kpi-grid {
        grid-template-columns: 1fr;
    }
    .app-content {
        padding: 1rem;
    }
}

/* Dropdown Menu Utility */
.dropdown-container {
    position: relative;
}

.dropdown-menu.show {
    display: block !important;
    animation: fadeIn 0.15s ease-out;
}

/* Dashboard Post-Login Entrance Stagger Animation */
.dashboard-entrance-active {
    animation: dashboardEnter 0.4s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

.dashboard-entrance-active .app-topbar {
    animation: headerEnter 0.4s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

.dashboard-entrance-active .kpi-grid {
    animation: kpiGridEnter 0.45s cubic-bezier(0.16, 1, 0.3, 1) 0.08s backwards;
}

.dashboard-entrance-active .card, 
.dashboard-entrance-active .dashboard-section {
    animation: sectionEnter 0.5s cubic-bezier(0.16, 1, 0.3, 1) 0.16s backwards;
}

@keyframes dashboardEnter {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes headerEnter {
    from { opacity: 0; transform: translateY(-6px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes kpiGridEnter {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes sectionEnter {
    from { opacity: 0; transform: translateY(12px); }
    to { opacity: 1; transform: translateY(0); }
}

/* 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;
    }
    .dashboard-entrance-active,
    .dashboard-entrance-active * {
        animation: none !important;
    }
}

