:root {
    --color-primary: #2e7d32;
    --color-primary-dark: #1b5e20;
    --color-bg: #f8fafc;
    --color-surface: #ffffff;
    --color-text: #1e293b;
    --color-text-muted: #64748b;
    --color-border: #e2e8f0;
    --color-danger: #ef4444;
    --color-success: #10b981;
    --color-warning: #f59e0b;
    
    /* Spacing & Layout Tokens */
    --el-space-2: 0.5rem;
    --el-space-3: 0.75rem;
    --el-space-4: 1rem;
    --el-neutral-200: #e2e8f0;
    --el-neutral-500: #64748b;
    --el-neutral-700: #334155;
    
    /* Dashboard Strip Gradients */
    --grad-orange: linear-gradient(135deg, #EA580C, #F97316);
    --grad-orange-dark: linear-gradient(135deg, #C2410C, #EA580C);
    
    --sidebar-width: 260px;

    /* Typography Hierarchy - The "Maalem" Standard */
    --fs-xs: 0.75rem;     /* 12px - Metadata */
    --fs-sm: 0.875rem;    /* 14px - Table content, Labels */
    --fs-base: 1rem;      /* 16px - Base text, Inputs */
    --fs-lg: 1.125rem;    /* 18px - Section titles */
    --fs-xl: 1.5rem;      /* 24px - Page headers */
    --fs-xxl: 2rem;       /* 32px - Dashboard big numbers */

    /* Shadows & Materiality */
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
    
    /* Glassmorphism Tokens */
    --glass-bg: rgba(255, 255, 255, 0.7);
    --glass-border: rgba(255, 255, 255, 0.2);
}

* {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    padding: 0;
    direction: rtl;
    text-align: right;
    font-family: 'IBM Plex Sans Arabic', sans-serif;
    background-color: var(--color-bg);
    color: var(--color-text);
    font-size: var(--fs-base);
    line-height: 1.6;
    height: 100%;
}

h1 { font-size: var(--fs-xl); font-weight: 700; margin-bottom: 1.5rem; }
h2 { font-size: var(--fs-lg); font-weight: 700; margin-bottom: 1rem; }
h3 { font-size: var(--fs-base); font-weight: 600; margin-bottom: 0.75rem; }
h4, h5, h6 { font-size: var(--fs-sm); font-weight: 600; }

/* Base Layout Structure */
.app-container {
    display: flex;
    min-height: 100vh;
}

/* Sidebar Styling */
.sidebar {
    width: var(--sidebar-width);
    background-color: var(--color-surface);
    border-left: 1px solid var(--color-border);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    bottom: 0;
    right: 0;
    z-index: 100;
}

.sidebar .brand {
    padding: 1.5rem 1rem;
    display: flex;
    justify-content: center;
    align-items: center;
    border-bottom: 1px solid var(--color-border);
}

.brand-logo {
    max-width: 100%;
    max-height: 80px;
    object-fit: contain;
}

.brand-name {
    font-size: var(--fs-lg);
    font-weight: 800;
    color: var(--color-primary);
    margin: 0;
}

.brand-name-mobile {
    font-size: var(--fs-base);
    font-weight: 700;
    color: var(--color-primary);
}

.sidebar .nav-links {
    flex: 1;
    padding: 1rem 0;
    overflow-y: auto;
}

.sidebar .nav-link {
    display: flex;
    align-items: center;
    padding: 0.875rem 1.5rem;
    color: var(--color-text);
    text-decoration: none;
    transition: all 0.2s;
    font-size: var(--fs-sm);
    font-weight: 500;
}

.sidebar .nav-link:hover {
    background-color: #f0f0f0;
}

.sidebar .nav-link.active {
    background-color: var(--color-primary);
    color: white;
}

.sidebar .nav-link .material-icons-round {
    margin-left: 0.8rem;
}

.sidebar .logout {
    padding: 1rem 1.5rem;
    color: var(--color-danger);
    border-top: 1px solid var(--color-border);
}

/* Main Content Area */
.main-content {
    flex: 1;
    margin-right: var(--sidebar-width);
    padding: 2rem;
    min-height: 100vh;
    transition: margin-right 0.3s;
}

.page-container {
    max-width: 1300px;
    margin: 0 auto;
}

/* El Maalem Dashboard Strip */
.dashboard-strip {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: var(--el-space-4);
    margin-bottom: 2rem;
}

.dash-card {
    border-radius: 12px;
    padding: 1.5rem;
    color: white;
    display: flex;
    align-items: center;
    gap: 1.25rem;
    box-shadow: 0 4px 15px rgba(0,0,0,0.08);
}

.dash-card.green {
    background: linear-gradient(135deg, var(--color-primary), #4caf50);
}

.dash-card.orange {
    background: var(--grad-orange);
}

.dash-card.orange-dark {
    background: var(--grad-orange-dark);
}

.dash-icon {
    width: 48px;
    height: 48px;
    background: rgba(255,255,255,0.2);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.dash-icon i, .dash-icon .material-icons-round {
    font-size: 1.4rem;
}

.dash-info {
    display: flex;
    flex-direction: column;
}

.dash-label {
    font-size: var(--fs-xs);
    opacity: 0.9;
    margin-bottom: 0.25rem;
    font-weight: 500;
}

.dash-value {
    font-size: var(--fs-xxl);
    font-weight: 800;
}

/* Quick Actions Bar */
.actions-bar {
    display: flex;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

/* Modernized Card */
.card {
    background: white;
    padding: 1.5rem;
    border-radius: 12px;
    box-shadow: var(--shadow-md);
    border: 1px solid var(--color-border);
    transition: transform 0.2s, box-shadow 0.2s;
}

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

.card-title {
    font-size: var(--fs-lg);
    font-weight: 700;
    margin-bottom: 1.5rem;
    color: var(--color-primary-dark);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* Glassmorphism Card Variation */
.glass-card {
    background: var(--glass-bg);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid var(--glass-border);
    box-shadow: var(--shadow-lg);
}

.chart-container {
    padding: 1rem;
}

.bg-primary { background: #e8f5e9; color: var(--color-primary); }
.bg-success { background: #e8f5e9; color: var(--color-success); }
.bg-warning { background: #fffde7; color: #fbc02d; }

/* Table Styling */
.table-container {
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
    overflow-x: auto; /* Enable horizontal scroll on mobile */
    -webkit-overflow-scrolling: touch;
}

.data-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
}

.data-table th, .data-table td {
    padding: 1rem;
    text-align: right;
}

.data-table th {
    background: #f8fafc;
    color: var(--color-text-muted);
    font-weight: 600;
    font-size: var(--fs-xs);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    border-bottom: 2px solid var(--color-border);
}

.data-table td {
    padding: 1rem;
    border-bottom: 1px solid var(--color-border);
    vertical-align: middle;
    font-size: var(--fs-sm);
}

.data-table tr:hover {
    background: rgba(46, 125, 50, 0.02);
}

/* Badges - Refined Maalem Style */
.badge {
    padding: 0.25rem 0.75rem;
    border-radius: 6px;
    font-size: var(--fs-xs);
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.badge-success { background: #dcfce7; color: #166534; border: 1px solid #bbf7d0; }
.badge-warning { background: #fef3c7; color: #92400e; border: 1px solid #fde68a; }
.badge-danger { background: #fee2e2; color: #991b1b; border: 1px solid #fecaca; }
.badge-info { background: #e0f2fe; color: #075985; border: 1px solid #bae6fd; }
.badge-primary { background: #e8f5e9; color: var(--color-primary); border: 1px solid #c8e6c9; }

/* Table Actions & Icons */
.actions-cell {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    justify-content: center;
}

.icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 4px;
    border: 1px solid var(--color-border);
    background: white;
    color: var(--color-text-muted);
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
    padding: 0;
}

.icon-btn:hover {
    background: #f5f5f5;
    color: var(--color-primary);
    border-color: var(--color-primary);
}

.icon-btn.text-danger:hover {
    color: var(--color-danger);
    border-color: var(--color-danger);
    background: #fff5f5;
}

.icon-btn .material-icons-round {
    font-size: 1.25rem;
}

.inline-form {
    display: inline;
    margin: 0;
    padding: 0;
}

/* Auth Layout */
.auth-container {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    width: 100%;
    background: var(--color-primary-dark);
}

.auth-brand {
    display: flex;
    justify-content: center;
    margin-bottom: 2rem;
}

.auth-brand .brand-logo {
    max-height: 120px;
}

.auth-card {
    background: white;
    padding: 3rem;
    border-radius: 20px;
    width: 100%;
    max-width: 420px;
    box-shadow: var(--shadow-lg);
    border: 1px solid rgba(255,255,255,0.1);
}

.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
    padding-bottom: 1rem;
    border-bottom: 2px solid var(--color-primary);
}

.page-title {
    font-size: var(--fs-xl);
    font-weight: 700;
    color: var(--color-primary-dark);
    margin: 0;
}

/* Forms */
.form-group {
    margin-bottom: 1.5rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 600;
    font-size: var(--fs-sm);
    color: var(--el-neutral-700);
}

.form-control {
    width: 100%;
    padding: 0.75rem 1rem;
    border: 1.5px solid var(--color-border);
    border-radius: 8px;
    font-family: inherit;
    font-size: var(--fs-base);
    height: 48px;
    transition: all 0.2s;
    background-color: #ffffff;
}

.form-control:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(46, 125, 50, 0.1);
}

.h-form-control {
    height: 45px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.form-row {
    display: flex;
    gap: 1rem;
}

.flex-1 { flex: 1; }
.flex-2 { flex: 2; }
.align-items-end { align-items: flex-end; }
.bg-primary-light { background: #e8f5e9; color: var(--color-primary) !important; }
.border-bottom { border-bottom: 1px solid var(--color-border); }
.border-radius { border-radius: 12px; }
.font-bold { font-weight: bold; }

/* Utilities */
.gap-1 { gap: 0.5rem; }
.gap-2 { gap: 1rem; }
.gap-3 { gap: 1.5rem; }
.w-100 { width: 100%; }
.justify-between { justify-content: space-between; }
.flex-column { flex-direction: column; }
.align-items-start { align-items: flex-start; }
.mb-0 { margin-bottom: 0 !important; }
.mb-4 { margin-bottom: 1.5rem !important; }
.mb-5 { margin-bottom: 3rem !important; }
.mr-2 { margin-right: 0.5rem !important; }
.mt-4 { margin-top: 1.5rem !important; }
.d-flex { display: flex !important; }
.hide-on-print { display: flex; }

@media print {
    .hide-on-print { display: none !important; }
    .main-content { margin-right: 0 !important; padding: 0 !important; }
    .sidebar, .bottom-bar, .mobile-header { display: none !important; }
    body { background: white; }
    .card { box-shadow: none; border: 1px solid #eee; }
}

/* Buttons - Premium Maalem Style */
.btn {
    padding: 0.75rem 1.5rem;
    border-radius: 8px;
    border: none;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    transition: all 0.2s;
    font-size: var(--fs-sm);
    box-shadow: var(--shadow-sm);
}

.btn:active {
    transform: translateY(1px);
}

.btn-primary { 
    background: var(--color-primary); 
    color: white; 
}
.btn-primary:hover { 
    background: var(--color-primary-dark); 
    box-shadow: var(--shadow-md); 
}

.btn-secondary { 
    background: #ffffff; 
    color: var(--color-text); 
    border: 1px solid var(--color-border);
}
.btn-secondary:hover { 
    background: #f8fafc; 
}

.btn-danger { 
    background: var(--color-danger); 
    color: white; 
}
.btn-danger:hover { 
    background: #dc2626; 
}

.btn-sm {
    padding: 0.4rem 0.8rem;
    font-size: var(--fs-xs);
    border-radius: 6px;
}

/* Modals - Standardized Professionally */
.modal {
    display: none;
    position: fixed;
    z-index: 2000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(15, 23, 42, 0.4);
    backdrop-filter: blur(4px);
    align-items: center;
    justify-content: center;
}

.modal-content {
    background-color: var(--color-surface);
    padding: 2.5rem;
    border-radius: 20px;
    width: 90%;
    max-width: 500px;
    box-shadow: var(--shadow-lg);
    text-align: center;
    border: 1px solid var(--color-border);
    animation: modalSlideUp 0.3s ease-out;
}

.modal-content h2, .modal-content h3 {
    color: var(--color-primary-dark);
    margin-top: 0;
}

.modal-content p {
    color: var(--color-text-muted);
    margin-bottom: 2rem;
    font-size: var(--fs-base);
}

.modal-actions {
    display: flex;
    justify-content: center;
    gap: 1rem;
}

@media (max-width: 768px) {
    .modal-content {
        width: 95%;
        max-width: 480px;
        padding: 2rem 1.5rem;
    }
}

/* Utilities */
.text-center { text-align: center !important; }
.text-danger { color: var(--color-danger) !important; }
.text-muted { color: var(--color-text-muted) !important; }
.font-bold { font-weight: bold; }

/* Flash Messages */
.flash-messages {
    position: fixed;
    top: 1rem;
    left: 50%;
    transform: translateX(-50%);
    z-index: 2000;
}

.flash-message {
    background: white;
    padding: 1.25rem 2rem;
    border-radius: 12px;
    box-shadow: var(--shadow-lg);
    margin-bottom: 0.75rem;
    border-right: 6px solid var(--color-primary);
    display: flex;
    align-items: center;
    font-weight: 500;
    min-width: 350px;
    animation: slideIn 0.3s ease-out;
}

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

.flash-error { border-right-color: var(--color-danger); }
.flash-warning { border-right-color: var(--color-warning); }
.flash-success { border-right-color: var(--color-success); }

/* --- Mobile Responsiveness --- */

/* Responsive Typography Foundations */
@media (max-width: 768px) {
    :root {
        --fs-xl: 1.25rem;    /* Scale down headers */
        --fs-xxl: 1.5rem;   /* Scale down big numbers */
    }
    
    .flash-messages {
        width: 90%;
        max-width: 400px;
    }
    
    .flash-message {
        min-width: auto;
        padding: 1rem;
        font-size: var(--fs-sm);
    }
}

/* Mobile Header (Hidden on Desktop) */
.mobile-header {
    display: none;
}

/* Mobile Responsiveness */
@media (max-width: 768px) {
    .app-container {
        flex-direction: column;
    }

    .sidebar {
        transform: translateX(100%); /* Hidden off-screen right */
        transition: transform 0.3s ease;
        display: flex; /* Override display: none if present */
        box-shadow: -5px 0 15px rgba(0,0,0,0.1);
    }

    .sidebar.active {
        transform: translateX(0);
    }

    .sidebar-overlay {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0,0,0,0.3);
        z-index: 99;
    }

    .sidebar-overlay.active {
        display: block;
    }
    
    .page-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 1rem;
    }

    .mobile-header {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 0.5rem 1rem;
        background: white;
        border-bottom: 1px solid var(--color-border);
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        z-index: 1001;
        height: 60px;
    }

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

    .brand-mobile .brand-logo {
        max-height: 40px;
    }
    
    .main-content {
        margin-right: 0;
        padding: 1rem;
        padding-top: 80px; /* Space for fixed mobile header */
        padding-bottom: 85px; /* Leave space for bottom bar */
    }

    .dashboard-strip {
        grid-template-columns: 1fr;
        gap: 1rem;
    }

    .form-row {
        flex-direction: column;
        gap: 0.5rem;
    }

    .actions-bar {
        flex-direction: column;
        align-items: stretch;
    }

    .actions-bar .btn {
        width: 100%;
        margin-bottom: 0.5rem;
    }

    .filter-bar {
        flex-direction: column;
        gap: 0.75rem;
    }

    .card {
        padding: 1rem;
    }

    .data-table th, .data-table td {
        padding: 0.75rem 0.5rem;
        font-size: 0.9rem;
    }

    .auth-card {
        padding: 2rem 1.5rem;
        margin: 1.5rem;
        max-width: 460px;
    }

    .align-items-end {
        align-items: stretch !important;
    }

    .page-title {
        font-size: 1.5rem;
    }

    /* Sales New Page Specific Responsiveness */
    .add-item-row {
        gap: 0.75rem;
    }
    
    .w-100-mobile {
        width: 100% !important;
    }

    .invoice-totals-display {
        display: flex;
        flex-direction: column;
        gap: 0.5rem;
    }

    .invoice-totals-display h3 {
        font-size: var(--fs-lg);
    }

    .table-container {
        margin-left: -1rem;
        margin-right: -1rem;
        border-radius: 0;
    }
    
    .data-table th, .data-table td {
        white-space: nowrap;
    }

    .bottom-bar {
        display: flex;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        background: white;
        border-top: 1px solid var(--color-border);
        justify-content: space-around;
        padding: 0.75rem 0;
        z-index: 1000;
        box-shadow: 0 -2px 10px rgba(0,0,0,0.05);
    }

    .bottom-bar .nav-link {
        flex: 1;
        text-align: center;
        padding: 0.25rem;
    }

    /* --- Responsive Tables (Card View) --- */
    .data-table, .data-table thead, .data-table tbody, .data-table th, .data-table td, .data-table tr {
        display: block;
    }

    .data-table thead tr {
        position: absolute;
        top: -9999px;
        right: -9999px;
    }

    .data-table tr {
        margin-bottom: 1rem;
        border: 1px solid var(--color-border);
        border-radius: 8px;
        background: white;
        padding: 0.5rem;
    }

    .data-table td {
        border: none;
        border-bottom: 1px solid #eee;
        position: relative;
        padding-right: 50% !important;
        text-align: left !important; /* Content on the left */
        white-space: normal;
        min-height: 2.5rem;
        display: flex;
        align-items: center;
        justify-content: flex-end;
    }

    .data-table td:last-child {
        border-bottom: 0;
    }

    .data-table td:before {
        position: absolute;
        top: 50%;
        right: 1rem;
        width: 45%;
        padding-left: 10px;
        white-space: nowrap;
        transform: translateY(-50%);
        content: attr(data-label);
        font-weight: 700;
        color: var(--color-text-muted);
        text-align: right; /* Label on the right (RTL) */
        font-size: var(--fs-xs);
    }

    .actions-cell {
        justify-content: flex-end;
    }
}

.bottom-bar {
    display: none;
}

.bottom-bar .nav-link {
    display: flex;
    flex-direction: column;
    align-items: center;
    color: var(--color-text);
    text-decoration: none;
    font-size: 0.7rem;
}

.bottom-bar .nav-link.active {
    color: var(--color-primary);
}

/* Search bar */
.filter-bar {
    display: flex;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.search-box {
    flex: 2;
}

.category-filter {
    flex: 1;
}

/* FAB */
.fab-container {
    position: fixed;
    bottom: 2rem;
    left: 2rem;
}

.fab {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: var(--color-primary);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 10px rgba(0,0,0,0.3);
    text-decoration: none;
}
