:root {
    --bg-base: #0a0e17;
    --bg-surface: #101726;
    --bg-card: #151f33;
    --bg-card-hover: #1c2942;
    --bg-input: #0c1424;
    --border-subtle: #1e293b;
    --border-focus: #38bdf8;
    
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    
    --primary: #0284c7;
    --primary-hover: #0369a1;
    --primary-glow: rgba(2, 132, 199, 0.25);
    
    --accent-cyan: #38bdf8;
    --accent-emerald: #10b981;
    --accent-amber: #f59e0b;
    --accent-rose: #f43f5e;
    --accent-violet: #8b5cf6;
    
    --badge-active-bg: rgba(16, 185, 129, 0.12);
    --badge-active-text: #34d399;
    --badge-active-border: rgba(16, 185, 129, 0.3);
    
    --badge-inactive-bg: rgba(244, 63, 94, 0.12);
    --badge-inactive-text: #fb7185;
    --badge-inactive-border: rgba(244, 63, 94, 0.3);
    
    --badge-expired-bg: rgba(245, 158, 11, 0.12);
    --badge-expired-text: #fbbf24;
    --badge-expired-border: rgba(245, 158, 11, 0.3);
    
    --badge-sub-bg: rgba(56, 189, 248, 0.1);
    --badge-sub-text: #7dd3fc;
    --badge-sub-border: rgba(56, 189, 248, 0.25);
    
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 18px;
    --radius-xl: 24px;
    
    --shadow-card: 0 4px 20px -2px rgba(0, 0, 0, 0.5);
    --shadow-glow: 0 0 25px rgba(2, 132, 199, 0.15);
    --shadow-drawer: -10px 0 35px rgba(0, 0, 0, 0.65);
    --transition: all 0.22s cubic-bezier(0.4, 0, 0.2, 1);
    
    --sidebar-width: 270px;
    --topbar-height-mobile: 60px;
    --topbar-height-desktop: 70px;
    --touch-min: 44px;
}

/* =========================================================================
   1. BASE & RESET
   ========================================================================= */

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Tajawal', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    -webkit-tap-highlight-color: transparent;
}

html {
    font-size: 16px;
    direction: rtl;
    text-align: right;
    scroll-behavior: smooth;
    overflow-x: hidden;
}

body {
    background-color: var(--bg-base);
    color: var(--text-primary);
    min-height: 100vh;
    min-height: -webkit-fill-available;
    display: flex;
    flex-direction: column;
    overflow-x: hidden;
    line-height: 1.6;
    padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

/* Animations */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
}

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

@keyframes pulseGlow {
    0%, 100% { opacity: 0.8; transform: scale(1); }
    50% { opacity: 1; transform: scale(1.06); }
}

@keyframes skeletonShimmer {
    0% { background-position: -200% 0; }
    100% { background-position: 200% 0; }
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}
::-webkit-scrollbar-track {
    background: var(--bg-base);
}
::-webkit-scrollbar-thumb {
    background: var(--border-subtle);
    border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* =========================================================================
   2. APP SHELL & LAYOUT
   ========================================================================= */

#app {
    display: flex;
    min-height: 100vh;
    width: 100%;
    position: relative;
    overflow-x: hidden;
}

.dashboard-shell {
    width: 100%;
    min-height: 100vh;
    display: flex;
    position: relative;
}

/* =========================================================================
   3. LOGIN SCREEN (Responsive & Mobile-First)
   ========================================================================= */

.login-screen {
    width: 100vw;
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: radial-gradient(circle at 50% 20%, #15243d 0%, #0a0e17 80%);
    padding: clamp(1rem, 4vw, 2.5rem);
}

.login-card {
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-xl);
    padding: clamp(2rem, 5vw, 3rem) clamp(1.5rem, 4vw, 2.5rem);
    width: 100%;
    max-width: 440px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.7), var(--shadow-glow);
    text-align: center;
    animation: fadeIn 0.4s ease-out;
}

.brand-icon {
    width: 60px;
    height: 60px;
    margin: 0 auto 1.25rem;
    background: linear-gradient(135deg, #0284c7, #0ea5e9);
    border-radius: var(--radius-lg);
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 8px 24px rgba(14, 165, 233, 0.35);
}

.login-card h1 {
    font-size: clamp(1.5rem, 3vw, 1.85rem);
    font-weight: 800;
    margin-bottom: 0.4rem;
    color: var(--text-primary);
}

.login-card p.subtitle {
    color: var(--text-secondary);
    font-size: clamp(0.85rem, 2vw, 0.95rem);
    margin-bottom: 2rem;
    line-height: 1.5;
}

/* =========================================================================
   4. DESKTOP SIDEBAR (Persistent on >=1024px, hidden on mobile/tablet)
   ========================================================================= */

.sidebar {
    width: var(--sidebar-width);
    background-color: var(--bg-surface);
    border-inline-end: 1px solid var(--border-subtle);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    transition: var(--transition);
    position: sticky;
    top: 0;
    height: 100vh;
    z-index: 40;
}

.sidebar-header {
    padding: 1.5rem 1.25rem;
    border-bottom: 1px solid var(--border-subtle);
    display: flex;
    align-items: center;
    gap: 12px;
}

.sidebar-brand-name h2 {
    font-size: 1.2rem;
    font-weight: 800;
    line-height: 1.2;
    color: var(--text-primary);
}

.sidebar-brand-name p {
    font-size: 0.75rem;
    color: var(--accent-cyan);
    font-weight: 600;
    letter-spacing: 0.5px;
}

.sidebar-nav {
    flex: 1;
    padding: 1rem 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 6px;
    overflow-y: auto;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0.85rem 1rem;
    min-height: var(--touch-min);
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    text-decoration: none;
    font-weight: 600;
    font-size: 0.95rem;
    transition: var(--transition);
    cursor: pointer;
    border: 1px solid transparent;
}

.nav-link:hover {
    color: var(--text-primary);
    background-color: var(--bg-card);
    border-color: rgba(255, 255, 255, 0.05);
}

.nav-link.active {
    color: var(--accent-cyan);
    background-color: rgba(14, 165, 233, 0.12);
    border-color: rgba(14, 165, 233, 0.3);
}

.nav-link svg {
    flex-shrink: 0;
}

.sidebar-footer {
    padding: 1.25rem;
    border-top: 1px solid var(--border-subtle);
    background-color: rgba(0, 0, 0, 0.2);
}

.user-profile-badge {
    display: flex;
    align-items: center;
    gap: 10px;
}

.user-avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary), var(--accent-cyan));
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    color: #ffffff;
    font-size: 0.95rem;
    flex-shrink: 0;
}

.user-meta {
    flex: 1;
    min-width: 0;
}

.user-meta h4 {
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-meta span {
    font-size: 0.75rem;
    color: var(--accent-emerald);
    font-weight: 600;
}

/* =========================================================================
   5. MOBILE OFF-CANVAS DRAWER (Smooth Slide-In, Accessible)
   ========================================================================= */

.drawer-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.65);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: 90;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.28s ease;
}

.drawer-backdrop.open {
    opacity: 1;
    pointer-events: auto;
}

.mobile-drawer {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    width: min(320px, 86vw);
    background-color: var(--bg-surface);
    border-inline-start: 1px solid var(--border-subtle);
    box-shadow: var(--shadow-drawer);
    z-index: 100;
    display: flex;
    flex-direction: column;
    transform: translateX(105%);
    transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    overflow-y: auto;
    padding-bottom: max(1.5rem, env(safe-area-inset-bottom));
}

.mobile-drawer.open {
    transform: translateX(0);
}

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

.drawer-brand {
    display: flex;
    align-items: center;
    gap: 10px;
}

.drawer-brand-text h3 {
    font-size: 1.15rem;
    font-weight: 800;
    color: var(--text-primary);
    line-height: 1.2;
}

.drawer-brand-text p {
    font-size: 0.75rem;
    color: var(--accent-cyan);
    font-weight: 600;
}

.drawer-close-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.75rem;
    line-height: 1;
    cursor: pointer;
    min-width: var(--touch-min);
    min-height: var(--touch-min);
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
    transition: var(--transition);
}

.drawer-close-btn:hover {
    color: var(--text-primary);
    background-color: rgba(255, 255, 255, 0.08);
}

.drawer-profile {
    padding: 1rem 1.25rem;
    background-color: rgba(0, 0, 0, 0.2);
    border-bottom: 1px solid var(--border-subtle);
    display: flex;
    align-items: center;
    gap: 12px;
}

.drawer-avatar {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary), var(--accent-cyan));
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    color: #ffffff;
    font-size: 1.05rem;
    flex-shrink: 0;
}

.drawer-user-info h4 {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--text-primary);
}

.drawer-user-info span {
    font-size: 0.78rem;
    color: var(--accent-emerald);
    font-weight: 600;
}

.drawer-nav {
    flex: 1;
    padding: 1rem 0.85rem;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.drawer-nav .nav-link {
    font-size: 1rem;
    padding: 0.9rem 1.1rem;
    min-height: 48px;
}

.drawer-footer {
    padding: 1rem 1.25rem;
    border-top: 1px solid var(--border-subtle);
    background-color: rgba(0, 0, 0, 0.15);
}

/* =========================================================================
   6. MAIN WRAPPER & TOP BAR (Adaptive Header)
   ========================================================================= */

.main-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
    background-color: var(--bg-base);
    min-width: 0;
    overflow-y: auto;
    overflow-x: hidden;
}

.top-bar {
    height: var(--topbar-height-mobile);
    background-color: var(--bg-surface);
    border-bottom: 1px solid var(--border-subtle);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 clamp(1rem, 3vw, 2rem);
    position: sticky;
    top: 0;
    z-index: 30;
}

.top-bar-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.mobile-menu-btn {
    background: none;
    border: 1px solid var(--border-subtle);
    color: var(--text-primary);
    width: var(--touch-min);
    height: var(--touch-min);
    border-radius: var(--radius-md);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
}

.mobile-menu-btn:hover {
    background-color: var(--bg-card);
    border-color: var(--border-focus);
}

.mobile-brand {
    display: flex;
    align-items: center;
}

.mobile-brand-title {
    font-size: 1.15rem;
    font-weight: 800;
    color: var(--text-primary);
    letter-spacing: -0.3px;
}

.mfi-status-pill {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 0.35rem 0.85rem;
    background: rgba(16, 185, 129, 0.1);
    border: 1px solid rgba(16, 185, 129, 0.25);
    border-radius: 9999px;
    font-size: 0.8rem;
    color: #34d399;
    font-weight: 600;
    white-space: nowrap;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: var(--accent-emerald);
    box-shadow: 0 0 8px var(--accent-emerald);
    flex-shrink: 0;
}

.status-dot.pulsing {
    animation: pulseGlow 1.8s infinite;
}

.top-bar-right {
    display: flex;
    align-items: center;
    gap: 10px;
}

.page-container {
    padding: clamp(1rem, 2.5vw, 2rem);
    max-width: 1600px;
    margin: 0 auto;
    width: 100%;
    animation: fadeIn 0.3s ease-out;
}

/* =========================================================================
   7. PAGE HEADERS & METRICS (Adaptive)
   ========================================================================= */

.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.75rem;
    flex-wrap: wrap;
    gap: 1rem;
}

.page-header-titles h1 {
    font-size: clamp(1.3rem, 2.5vw, 1.85rem);
    font-weight: 800;
    color: var(--text-primary);
    line-height: 1.3;
}

.page-header-titles p {
    color: var(--text-secondary);
    font-size: clamp(0.85rem, 1.8vw, 0.95rem);
    margin-top: 4px;
}

/* KPI Cards Grid */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: clamp(0.75rem, 2vw, 1.25rem);
    margin-bottom: 2rem;
}

.kpi-card {
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    padding: clamp(1rem, 2vw, 1.5rem);
    box-shadow: var(--shadow-card);
    position: relative;
    overflow: hidden;
    transition: var(--transition);
}

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

.kpi-card::before {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    left: 0;
    height: 3px;
    background: linear-gradient(90deg, var(--accent-cyan), transparent);
    opacity: 0.6;
}

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

.kpi-title {
    color: var(--text-secondary);
    font-size: clamp(0.8rem, 1.5vw, 0.88rem);
    font-weight: 600;
}

.kpi-icon-badge {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-md);
    background-color: rgba(255, 255, 255, 0.05);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--accent-cyan);
    flex-shrink: 0;
}

.kpi-value {
    font-size: clamp(1.5rem, 3.5vw, 2.2rem);
    font-weight: 900;
    color: var(--text-primary);
    line-height: 1.1;
    margin-bottom: 0.4rem;
}

.kpi-meta {
    font-size: 0.78rem;
    color: var(--text-muted);
}

/* =========================================================================
   8. CARD SECTIONS & TOOLBARS
   ========================================================================= */

.card-section {
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    padding: clamp(1rem, 2vw, 1.5rem);
    box-shadow: var(--shadow-card);
    margin-bottom: 2rem;
}

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

.card-title h3 {
    font-size: clamp(1.05rem, 2vw, 1.2rem);
    font-weight: 700;
    color: var(--text-primary);
}

.card-title p {
    font-size: 0.82rem;
    color: var(--text-secondary);
    margin-top: 2px;
}

/* Responsive Filter Toolbar */
.filter-bar {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    margin-bottom: 1.5rem;
    background-color: rgba(0, 0, 0, 0.2);
    padding: 0.85rem;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-subtle);
}

.filter-search-row {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
}

.filter-toggle-btn {
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    color: var(--text-secondary);
    border-radius: var(--radius-md);
    padding: 0 0.85rem;
    height: 44px;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-weight: 600;
    font-size: 0.9rem;
    cursor: pointer;
    white-space: nowrap;
    transition: var(--transition);
}

.filter-toggle-btn:hover, .filter-toggle-btn.active {
    color: var(--text-primary);
    border-color: var(--border-focus);
    background-color: rgba(14, 165, 233, 0.1);
}

.filter-drawer-content {
    display: none;
    flex-wrap: wrap;
    gap: 0.65rem;
    padding-top: 0.5rem;
    border-top: 1px solid var(--border-subtle);
}

.filter-drawer-content.expanded {
    display: flex;
}

.filter-group {
    flex: 1;
    min-width: 140px;
}

/* =========================================================================
   9. DESKTOP / TABLET DATA TABLES
   ========================================================================= */

.data-table-wrapper {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-subtle);
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    text-align: right;
    font-size: 0.9rem;
}

.data-table th {
    background-color: var(--bg-surface);
    color: var(--text-secondary);
    font-weight: 700;
    padding: 0.9rem 1rem;
    border-bottom: 1px solid var(--border-subtle);
    white-space: nowrap;
    font-size: 0.82rem;
    letter-spacing: 0.3px;
}

.data-table td {
    padding: 1rem;
    border-bottom: 1px solid var(--border-subtle);
    color: var(--text-primary);
    vertical-align: middle;
}

.data-table tbody tr {
    transition: background-color 0.15s ease;
}

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

.data-table tbody tr:last-child td {
    border-bottom: none;
}

/* =========================================================================
   10. MOBILE RESPONSIVE CARDS (Transforms Table Rows to Cards on Mobile)
   ========================================================================= */

.mobile-card-list {
    display: flex;
    flex-direction: column;
    gap: 0.85rem;
    width: 100%;
}

.customer-card, .agent-card, .log-card {
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    padding: 1.15rem;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
    display: flex;
    flex-direction: column;
    gap: 0.85rem;
    transition: var(--transition);
}

.customer-card:hover, .agent-card:hover, .log-card:hover {
    border-color: rgba(14, 165, 233, 0.35);
}

.card-top-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.card-customer-name {
    font-size: 1.05rem;
    font-weight: 800;
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.card-code-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: rgba(0, 0, 0, 0.25);
    padding: 0.5rem 0.75rem;
    border-radius: var(--radius-sm);
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.card-code-text {
    font-family: monospace;
    font-weight: 700;
    color: var(--accent-cyan);
    font-size: 0.92rem;
    letter-spacing: 0.5px;
}

.card-meta-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.6rem;
    font-size: 0.82rem;
    padding-top: 0.25rem;
    border-top: 1px dashed rgba(255, 255, 255, 0.08);
}

.card-meta-item {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.card-meta-label {
    color: var(--text-muted);
    font-size: 0.75rem;
}

.card-meta-value {
    color: var(--text-primary);
    font-weight: 600;
}

.card-actions-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding-top: 0.6rem;
    border-top: 1px solid var(--border-subtle);
}

/* Contextual Dropdown Menu ([⋮]) */
.action-dropdown {
    position: relative;
    display: inline-block;
}

.action-menu-trigger {
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid var(--border-subtle);
    color: var(--text-primary);
    width: var(--touch-min);
    height: var(--touch-min);
    border-radius: var(--radius-sm);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 1.2rem;
    transition: var(--transition);
}

.action-menu-trigger:hover {
    background-color: var(--bg-card-hover);
    border-color: var(--border-focus);
}

.action-menu-popup {
    position: absolute;
    bottom: calc(100% + 6px);
    left: 0;
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.6);
    min-width: 170px;
    z-index: 50;
    display: none;
    flex-direction: column;
    padding: 0.4rem;
    gap: 2px;
}

.action-menu-popup.show {
    display: flex;
    animation: slideUp 0.18s ease-out;
}

.action-menu-item {
    background: none;
    border: none;
    color: var(--text-primary);
    padding: 0.65rem 0.85rem;
    min-height: 40px;
    border-radius: var(--radius-sm);
    text-align: right;
    font-size: 0.88rem;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: var(--transition);
    width: 100%;
}

.action-menu-item:hover {
    background-color: rgba(255, 255, 255, 0.08);
}

.action-menu-item.danger {
    color: var(--accent-rose);
}

.action-menu-item.danger:hover {
    background-color: rgba(244, 63, 94, 0.15);
}

/* =========================================================================
   11. BADGES & PILLS
   ========================================================================= */

.badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 0.28rem 0.65rem;
    border-radius: 9999px;
    font-size: 0.78rem;
    font-weight: 700;
    border: 1px solid transparent;
    line-height: 1.2;
    white-space: nowrap;
}

.badge.active {
    background-color: var(--badge-active-bg);
    color: var(--badge-active-text);
    border-color: var(--badge-active-border);
}

.badge.inactive {
    background-color: var(--badge-inactive-bg);
    color: var(--badge-inactive-text);
    border-color: var(--badge-inactive-border);
}

.badge.expired {
    background-color: var(--badge-expired-bg);
    color: var(--badge-expired-text);
    border-color: var(--badge-expired-border);
}

.badge.sub {
    background-color: var(--badge-sub-bg);
    color: var(--badge-sub-text);
    border-color: var(--badge-sub-border);
}

.badge.role-admin {
    background-color: rgba(139, 92, 246, 0.12);
    color: #c4b5fd;
    border-color: rgba(139, 92, 246, 0.3);
}

.badge.role-agent {
    background-color: rgba(14, 165, 233, 0.12);
    color: #7dd3fc;
    border-color: rgba(14, 165, 233, 0.3);
}

.badge.deleted {
    background-color: rgba(100, 116, 139, 0.16);
    color: #94a3b8;
    border-color: rgba(100, 116, 139, 0.35);
}

.action-menu-divider {
    height: 1px;
    background-color: var(--border-subtle);
    margin: 4px 0;
}

.alert-box {
    padding: 0.85rem 1.1rem;
    border-radius: var(--radius-md);
    font-size: 0.88rem;
    line-height: 1.5;
    border: 1px solid transparent;
}

.alert-box.alert-danger {
    background-color: rgba(244, 63, 94, 0.12);
    border-color: rgba(244, 63, 94, 0.35);
    color: #fda4af;
}

.alert-box.alert-warning {
    background-color: rgba(245, 158, 11, 0.12);
    border-color: rgba(245, 158, 11, 0.35);
    color: #fde68a;
}

.alert-box.alert-success {
    background-color: rgba(16, 185, 129, 0.12);
    border-color: rgba(16, 185, 129, 0.35);
    color: #a7f3d0;
}

/* =========================================================================
   12. BUTTONS & FORM INPUTS (Touch-Optimized)
   ========================================================================= */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 0.65rem 1.25rem;
    min-height: var(--touch-min);
    border-radius: var(--radius-md);
    font-size: 0.92rem;
    font-weight: 700;
    cursor: pointer;
    transition: var(--transition);
    border: 1px solid transparent;
    text-decoration: none;
    white-space: nowrap;
}

.btn-sm {
    padding: 0.4rem 0.85rem;
    min-height: 38px;
    font-size: 0.82rem;
}

.btn-icon {
    width: var(--touch-min);
    height: var(--touch-min);
    padding: 0;
    border-radius: var(--radius-md);
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary), #0284c7);
    color: #ffffff;
    box-shadow: 0 4px 14px rgba(2, 132, 199, 0.3);
}

.btn-primary:hover {
    background: linear-gradient(135deg, #0369a1, #0284c7);
    transform: translateY(-1px);
    box-shadow: 0 6px 20px rgba(2, 132, 199, 0.45);
}

.btn-secondary {
    background-color: rgba(255, 255, 255, 0.05);
    color: var(--text-primary);
    border-color: var(--border-subtle);
}

.btn-secondary:hover {
    background-color: var(--bg-card-hover);
    border-color: var(--text-muted);
}

.btn-danger {
    background: linear-gradient(135deg, #e11d48, #be123c);
    color: #ffffff;
    box-shadow: 0 4px 14px rgba(225, 29, 72, 0.3);
}

.btn-danger:hover {
    background: linear-gradient(135deg, #be123c, #9f1239);
    transform: translateY(-1px);
}

.btn-warning {
    background: linear-gradient(135deg, rgba(245, 158, 11, 0.18), rgba(217, 119, 6, 0.25));
    color: #fbbf24;
    border-color: rgba(245, 158, 11, 0.4);
}

.btn-warning:hover {
    background: linear-gradient(135deg, rgba(245, 158, 11, 0.28), rgba(217, 119, 6, 0.35));
    border-color: rgba(245, 158, 11, 0.6);
    color: #fef3c7;
}

.btn:disabled {
    opacity: 0.55;
    cursor: not-allowed;
    transform: none !important;
}

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

.form-group label {
    display: block;
    font-size: 0.88rem;
    font-weight: 700;
    color: var(--text-secondary);
    margin-bottom: 0.4rem;
}

.form-control {
    width: 100%;
    min-height: var(--touch-min);
    padding: 0.75rem 1rem;
    background-color: var(--bg-input);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-size: 0.95rem;
    outline: none;
    transition: var(--transition);
}

.form-control:focus {
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.18);
}

.code-input {
    font-family: monospace;
    letter-spacing: 1px;
    font-weight: 700;
    color: var(--accent-cyan);
}

/* =========================================================================
   13. MODALS & BOTTOM SHEETS (Adaptive)
   ========================================================================= */

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
    z-index: 200;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.modal-overlay.open {
    display: flex;
    animation: fadeIn 0.22s ease-out;
}

.modal-content {
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-xl);
    width: 100%;
    max-width: 540px;
    box-shadow: 0 25px 60px rgba(0, 0, 0, 0.8), var(--shadow-glow);
    display: flex;
    flex-direction: column;
    max-height: 90vh;
    animation: slideUp 0.25s ease-out;
    position: relative;
    overflow: hidden;
}

.modal-sheet-handle {
    display: none;
}

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

.modal-header h3 {
    font-size: 1.15rem;
    font-weight: 800;
    color: var(--text-primary);
}

.modal-close-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.75rem;
    line-height: 1;
    cursor: pointer;
    min-width: var(--touch-min);
    min-height: var(--touch-min);
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
    transition: var(--transition);
}

.modal-close-btn:hover {
    color: var(--text-primary);
    background-color: rgba(255, 255, 255, 0.08);
}

.modal-body {
    padding: 1.5rem;
    overflow-y: auto;
    flex: 1;
}

.modal-footer {
    padding: 1.25rem 1.5rem;
    border-top: 1px solid var(--border-subtle);
    background-color: rgba(0, 0, 0, 0.2);
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 10px;
}

/* =========================================================================
   14. PAGINATION (Adaptive)
   ========================================================================= */

.pagination-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-top: 1.25rem;
    margin-top: 1rem;
    border-top: 1px solid var(--border-subtle);
    color: var(--text-secondary);
    font-size: 0.88rem;
    flex-wrap: wrap;
    gap: 1rem;
}

.pagination-controls {
    display: flex;
    align-items: center;
    gap: 6px;
}

.pagination-btn {
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    color: var(--text-primary);
    min-width: var(--touch-min);
    height: var(--touch-min);
    border-radius: var(--radius-sm);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0 0.85rem;
    font-weight: 700;
    font-size: 0.85rem;
    cursor: pointer;
    transition: var(--transition);
}

.pagination-btn:hover:not(:disabled) {
    background-color: var(--bg-card-hover);
    border-color: var(--border-focus);
}

.pagination-btn.active {
    background-color: var(--primary);
    border-color: var(--primary);
    color: #ffffff;
}

.pagination-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* =========================================================================
   15. EMPTY, SKELETON & TOAST STATES
   ========================================================================= */

.empty-state {
    padding: 3rem 1.5rem;
    text-align: center;
    color: var(--text-muted);
}

.empty-state-icon {
    font-size: 2.5rem;
    margin-bottom: 0.75rem;
    opacity: 0.7;
}

.empty-state h4 {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text-secondary);
    margin-bottom: 0.35rem;
}

.empty-state p {
    font-size: 0.88rem;
    max-width: 400px;
    margin: 0 auto;
}

.skeleton-box {
    background: linear-gradient(90deg, rgba(255, 255, 255, 0.03) 25%, rgba(255, 255, 255, 0.08) 50%, rgba(255, 255, 255, 0.03) 75%);
    background-size: 200% 100%;
    animation: skeletonShimmer 1.6s infinite;
    border-radius: var(--radius-sm);
}

#toast-container {
    position: fixed;
    bottom: max(1.5rem, env(safe-area-inset-bottom));
    left: max(1.5rem, env(safe-area-inset-left));
    z-index: 300;
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-width: min(380px, calc(100vw - 32px));
    pointer-events: none;
}

.toast {
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    padding: 0.9rem 1.15rem;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.7);
    color: var(--text-primary);
    font-size: 0.9rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 10px;
    animation: slideUp 0.25s ease-out;
    pointer-events: auto;
}

.toast.success { border-color: var(--accent-emerald); }
.toast.error { border-color: var(--accent-rose); }
.toast.info { border-color: var(--accent-cyan); }

/* =========================================================================
   16. SETTINGS VIEW STYLES
   ========================================================================= */

.settings-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 1.5rem;
}

.settings-card {
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    box-shadow: var(--shadow-card);
}

.settings-card-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 1.25rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--border-subtle);
}

.settings-card-header h3 {
    font-size: 1.15rem;
    font-weight: 800;
    color: var(--text-primary);
}

.settings-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 0;
    border-bottom: 1px dashed rgba(255, 255, 255, 0.06);
    font-size: 0.9rem;
}

.settings-row:last-child {
    border-bottom: none;
}

.settings-label {
    color: var(--text-secondary);
    font-weight: 600;
}

.settings-val {
    color: var(--text-primary);
    font-weight: 700;
}

.whatsapp-card {
    border-color: rgba(16, 185, 129, 0.35);
    background: linear-gradient(135deg, rgba(16, 185, 129, 0.08), rgba(21, 31, 51, 0.95));
}

.whatsapp-link-btn {
    background: #10b981;
    color: #ffffff;
    padding: 0.85rem 1.25rem;
    border-radius: var(--radius-md);
    text-decoration: none;
    font-weight: 700;
    font-size: 0.95rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 48px;
    width: 100%;
    margin-top: 1rem;
    box-shadow: 0 4px 14px rgba(16, 185, 129, 0.35);
    transition: var(--transition);
}

.whatsapp-link-btn:hover {
    background: #059669;
    transform: translateY(-1px);
}

/* =========================================================================
   17. RESPONSIVE BREAKPOINTS (Mobile-First Transformation)
   ========================================================================= */

/* --- MOBILE (max-width: 767px) --- */
@media (max-width: 767px) {
    .sidebar {
        display: none !important;
    }

    .top-bar {
        height: var(--topbar-height-mobile);
        padding: 0 1rem;
    }

    .top-bar-left {
        gap: 8px;
    }

    .mobile-menu-btn {
        display: inline-flex;
    }

    .mobile-brand {
        display: flex;
    }

    .mfi-status-pill {
        padding: 0.25rem 0.6rem;
        font-size: 0.72rem;
    }

    #mfi-status-text {
        display: none; /* Hide long text on mobile to preserve header cleanliness */
    }

    .top-bar-right #topbar-activate-btn span {
        display: none; /* Icon-only on mobile topbar for compactness */
    }

    .top-bar-right #topbar-activate-btn {
        padding: 0.45rem 0.65rem;
        width: 38px;
        height: 38px;
    }

    .page-container {
        padding: 1rem 0.85rem;
    }

    .page-header {
        margin-bottom: 1.25rem;
    }

    .page-header > div:last-child {
        width: 100%;
    }

    .page-header > div:last-child .btn {
        width: 100%;
    }

    .kpi-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.75rem;
        margin-bottom: 1.25rem;
    }

    .kpi-card {
        padding: 0.95rem;
    }

    .kpi-icon-badge {
        width: 32px;
        height: 32px;
    }

    .kpi-value {
        font-size: 1.45rem;
    }

    /* Transform Tables -> Cards */
    .data-table-wrapper {
        display: none !important;
    }

    .mobile-card-list {
        display: flex !important;
    }

    /* Filters on Mobile */
    .filter-bar {
        padding: 0.75rem;
    }

    .filter-drawer-content {
        flex-direction: column;
    }

    .filter-group {
        width: 100%;
    }

    /* Modals become Bottom Sheets */
    .modal-overlay {
        align-items: flex-end;
        padding: 0;
    }

    .modal-content {
        max-width: 100% !important;
        border-radius: 20px 20px 0 0;
        max-height: 88vh;
        margin: 0;
        padding-bottom: max(1.5rem, env(safe-area-inset-bottom));
        animation: slideUp 0.28s cubic-bezier(0.16, 1, 0.3, 1);
    }

    .modal-sheet-handle {
        display: block;
        width: 44px;
        height: 5px;
        background: rgba(255, 255, 255, 0.25);
        border-radius: 9999px;
        margin: 0.6rem auto 0.4rem;
    }

    .modal-footer {
        flex-direction: column;
        gap: 8px;
    }

    .modal-footer .btn {
        width: 100%;
        min-height: 48px;
    }

    /* Pagination on Mobile */
    .pagination-bar {
        flex-direction: column;
        align-items: center;
        text-align: center;
        gap: 0.75rem;
    }

    .pagination-controls {
        width: 100%;
        justify-content: center;
    }
}

/* Extra small mobile (<= 360px) */
@media (max-width: 360px) {
    .kpi-grid {
        grid-template-columns: 1fr;
    }

    .card-meta-grid {
        grid-template-columns: 1fr;
    }
}

/* --- TABLET (768px - 1023px) --- */
@media (min-width: 768px) and (max-width: 1023px) {
    .sidebar {
        display: none !important;
    }

    .mobile-menu-btn {
        display: inline-flex;
    }

    .mobile-brand {
        display: flex;
    }

    .top-bar {
        height: var(--topbar-height-desktop);
    }

    .kpi-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    /* Show Table with horizontal scroll support */
    .data-table-wrapper {
        display: block !important;
    }

    .mobile-card-list {
        display: none !important;
    }

    .filter-drawer-content {
        display: flex !important;
    }

    .filter-toggle-btn {
        display: none;
    }
}

/* --- DESKTOP (1024px+) --- */
@media (min-width: 1024px) {
    .sidebar {
        display: flex !important;
    }

    .mobile-menu-btn, .mobile-brand {
        display: none !important;
    }

    .top-bar {
        height: var(--topbar-height-desktop);
        padding: 0 2rem;
    }

    .kpi-grid {
        grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
    }

    .data-table-wrapper {
        display: block !important;
    }

    .mobile-card-list {
        display: none !important;
    }

    .filter-bar {
        flex-direction: row;
        align-items: center;
        flex-wrap: wrap;
    }

    .filter-search-row {
        width: auto;
        flex: 1;
        min-width: 260px;
    }

    .filter-toggle-btn {
        display: none;
    }

    .filter-drawer-content {
        display: flex !important;
        padding-top: 0;
        border-top: none;
        flex: 2;
    }
}

/* --- WIDE DESKTOP (1440px+) & ULTRAWIDE (1920px+) --- */
@media (min-width: 1440px) {
    .page-container {
        max-width: 1560px;
    }
}

@media (min-width: 1920px) {
    .page-container {
        max-width: 1680px;
    }
}

/* --- LANDSCAPE MOBILE ADJUSTMENTS --- */
@media (max-height: 520px) and (orientation: landscape) {
    .modal-content {
        max-height: 94vh;
    }

    .kpi-grid {
        grid-template-columns: repeat(4, 1fr);
    }

    .login-screen {
        padding: 1rem;
    }

    .login-card {
        padding: 1.5rem;
    }

    .brand-icon {
        width: 44px;
        height: 44px;
        margin-bottom: 0.75rem;
    }
}
