:root {
    --primary: #4f46e5;
    --primary-hover: #4338ca;
    --primary-light: #eef2ff;
    --primary-gradient: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%);
    --secondary-gradient: linear-gradient(135deg, #0ea5e9 0%, #3b82f6 100%);
    --success-gradient: linear-gradient(135deg, #10b981 0%, #059669 100%);
    --warning-gradient: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
    --danger-gradient: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
    --dark-gradient: linear-gradient(135deg, #1e293b 0%, #0f172a 100%);
    
    --bg-main: #f8fafc;
    --card-bg: #ffffff;
    --text-main: #1e293b;
    --text-muted: #64748b;
    --border-color: #e2e8f0;
    --border-radius-sm: 8px;
    --border-radius-md: 14px;
    --border-radius-lg: 20px;
    --box-shadow-sm: 0 1px 3px 0 rgba(0, 0, 0, 0.05), 0 1px 2px -1px rgba(0, 0, 0, 0.05);
    --box-shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.07), 0 2px 4px -2px rgba(0, 0, 0, 0.05);
    --box-shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.08), 0 4px 6px -4px rgba(0, 0, 0, 0.04);
}

/* =========================================================
   GLOBAL FONT AND RTL ENFORCEMENT
   ========================================================= */
html, body,
input, button, select, textarea, optgroup,
.btn, .form-control, .form-select, .form-label,
.table, .card, .dropdown-menu, .dropdown-item,
.modal, .modal-title, .modal-body, .modal-footer,
.toast, .toast-body, .badge, .alert, .nav-link,
h1, h2, h3, h4, h5, h6, p, label, small {
    font-family: 'Vazirmatn', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif !important;
}

/* Preserve FontAwesome Icon Fonts */
.fa, .fas, .far, .fal, .fad, .fab, .fa-solid, .fa-regular, .fa-brands, .fa-light, .fa-thin, .fa-duotone,
.fa::before, .fas::before, .far::before, .fal::before, .fad::before, .fab::before,
.fa-solid::before, .fa-regular::before, .fa-brands::before,
[class^="fa-"]::before, [class*=" fa-"]::before {
    font-family: "Font Awesome 6 Free", "Font Awesome 6 Brands", "FontAwesome" !important;
}
.fa-brands, .fa-brands::before, .fab, .fab::before {
    font-family: "Font Awesome 6 Brands" !important;
}

html, body {
    direction: rtl !important;
    text-align: right !important;
    background-color: var(--bg-main);
    color: var(--text-main);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    padding-bottom: 75px; /* Space for mobile bottom bar */
}

@media (min-width: 768px) {
    body {
        padding-bottom: 30px;
    }
}

/* RTL Form Controls Alignment */
.form-control, .form-select {
    text-align: right;
    direction: rtl;
    border-radius: var(--border-radius-sm);
    border-color: var(--border-color);
    padding: 0.6rem 0.85rem;
    font-size: 0.95rem;
}
.form-control::placeholder, textarea::placeholder {
    text-align: right;
    direction: rtl;
}
.form-control:focus, .form-select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.15);
}

.form-label {
    text-align: right;
    display: block;
    margin-bottom: 0.4rem;
}

/* Specific LTR Overrides for Identifiers, Codes, Time, Dates */
[dir="ltr"], .ltr, 
input[type="time"], input[type="date"], 
code, pre, .font-monospace {
    direction: ltr !important;
    text-align: left !important;
    unicode-bidi: embed;
}

input[type="password"] {
    direction: ltr !important;
    text-align: left !important;
}

input[dir="ltr"]::placeholder, .ltr::placeholder, input[type="password"]::placeholder, input[type="number"]::placeholder {
    direction: rtl !important;
    text-align: right !important;
}

/* Custom Scrollbar */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}
::-webkit-scrollbar-track {
    background: #f1f5f9;
}
::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

/* Top Navbar */
.main-navbar {
    background: #ffffff;
    border-bottom: 1px solid var(--border-color);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.02);
    position: sticky;
    top: 0;
    z-index: 1020;
    backdrop-filter: blur(10px);
}

.brand-badge {
    background: var(--primary-gradient);
    color: #fff;
    width: 38px;
    height: 38px;
    border-radius: 10px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1.15rem;
    box-shadow: 0 4px 10px rgba(79, 70, 229, 0.3);
}

.nav-link-custom {
    color: #475569 !important;
    font-weight: 500;
    padding: 0.55rem 1rem !important;
    border-radius: 10px;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.nav-link-custom:hover {
    color: var(--primary) !important;
    background-color: var(--primary-light);
}

.nav-link-custom.active {
    color: var(--primary) !important;
    background-color: var(--primary-light);
    font-weight: 600;
}

/* User Dropdown Pill */
.user-pill {
    background-color: #f1f5f9;
    border: 1px solid var(--border-color);
    padding: 0.35rem 0.85rem;
    border-radius: 9999px;
    font-size: 0.9rem;
    color: var(--text-main);
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.user-pill:hover {
    background-color: #e2e8f0;
}

.user-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--primary-gradient);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    font-weight: 600;
}

/* Cards & Surfaces */
.app-card {
    background: var(--card-bg);
    border-radius: var(--border-radius-md);
    border: 1px solid var(--border-color);
    box-shadow: var(--box-shadow-sm);
    transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
    overflow: hidden;
}

.app-card-hover:hover {
    transform: translateY(-3px);
    box-shadow: var(--box-shadow-lg);
    border-color: #cbd5e1;
}

/* Hero & Stat Cards */
.stat-card {
    border-radius: var(--border-radius-md);
    padding: 1.25rem;
    position: relative;
    overflow: hidden;
    color: #fff;
    border: none;
    box-shadow: var(--box-shadow-md);
    transition: transform 0.2s ease;
}

.stat-card:hover {
    transform: translateY(-3px);
}

.stat-card.stat-purple { background: var(--primary-gradient); }
.stat-card.stat-blue { background: var(--secondary-gradient); }
.stat-card.stat-emerald { background: var(--success-gradient); }
.stat-card.stat-amber { background: var(--warning-gradient); }

.stat-card-icon {
    position: absolute;
    left: -10px;
    bottom: -15px;
    font-size: 4.5rem;
    opacity: 0.15;
    pointer-events: none;
}

.stat-title {
    font-size: 0.85rem;
    opacity: 0.9;
    margin-bottom: 0.4rem;
}

.stat-value {
    font-size: 1.9rem;
    font-weight: 800;
    line-height: 1;
}

.stat-subtitle {
    font-size: 0.78rem;
    opacity: 0.85;
    margin-top: 0.4rem;
}

/* Buttons */
.btn-primary {
    background: var(--primary);
    border-color: var(--primary);
    border-radius: var(--border-radius-sm);
    font-weight: 500;
    padding: 0.55rem 1.15rem;
    box-shadow: 0 2px 4px rgba(79, 70, 229, 0.2);
    transition: all 0.2s ease;
}

.btn-primary:hover, .btn-primary:focus {
    background: var(--primary-hover);
    border-color: var(--primary-hover);
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(79, 70, 229, 0.3);
}

.btn-soft-primary {
    background-color: var(--primary-light);
    color: var(--primary);
    border: none;
    border-radius: var(--border-radius-sm);
    font-weight: 500;
}
.btn-soft-primary:hover {
    background-color: #e0e7ff;
    color: var(--primary-hover);
}

.btn-soft-success {
    background-color: #ecfdf5;
    color: #059669;
    border: none;
    border-radius: var(--border-radius-sm);
}
.btn-soft-success:hover {
    background-color: #d1fae5;
    color: #047857;
}

.btn-soft-danger {
    background-color: #fef2f2;
    color: #dc2626;
    border: none;
    border-radius: var(--border-radius-sm);
}
.btn-soft-danger:hover {
    background-color: #fee2e2;
    color: #b91c1c;
}

/* Modern RTL Tables */
.app-table {
    margin-bottom: 0;
    width: 100%;
}
.app-table thead th {
    background-color: #f8fafc;
    color: #475569;
    font-weight: 600;
    font-size: 0.85rem;
    text-align: right;
    border-bottom: 1px solid var(--border-color);
    padding: 0.9rem 1rem;
}
.app-table tbody td {
    padding: 0.95rem 1rem;
    vertical-align: middle;
    text-align: right;
    border-bottom: 1px solid #f1f5f9;
    font-size: 0.92rem;
}
.app-table tbody tr:hover {
    background-color: #f8fafc;
}

/* Badges & Status */
.status-badge {
    padding: 0.35rem 0.75rem;
    border-radius: 9999px;
    font-size: 0.8rem;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
}
.status-badge.status-ontime {
    background-color: #dcfce7;
    color: #15803d;
}
.status-badge.status-late {
    background-color: #fee2e2;
    color: #b91c1c;
}
.status-badge.status-absent {
    background-color: #f1f5f9;
    color: #64748b;
}

/* Mobile Bottom Navigation Bar */
.mobile-bottom-nav {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: #ffffff;
    border-top: 1px solid var(--border-color);
    box-shadow: 0 -4px 15px rgba(0, 0, 0, 0.05);
    z-index: 1030;
    padding: 0.4rem 0.5rem;
}

@media (max-width: 767.98px) {
    .mobile-bottom-nav {
        display: flex;
        justify-content: space-around;
        align-items: center;
    }
    
    .desktop-only-table {
        display: none !important;
    }
    
    .mobile-card-list {
        display: block !important;
    }
}

@media (min-width: 768px) {
    .mobile-card-list {
        display: none !important;
    }
}

.mobile-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-decoration: none;
    color: #64748b;
    font-size: 0.72rem;
    font-weight: 500;
    padding: 0.3rem 0.6rem;
    border-radius: 12px;
    transition: all 0.2s ease;
    flex: 1;
    text-align: center;
}

.mobile-nav-item i {
    font-size: 1.15rem;
    margin-bottom: 2px;
    transition: transform 0.2s ease;
}

.mobile-nav-item.active {
    color: var(--primary);
    font-weight: 700;
}

.mobile-nav-item.active i {
    transform: scale(1.15);
}

/* Mobile student/attendance card item */
.mobile-record-card {
    background: #fff;
    border-radius: var(--border-radius-sm);
    border: 1px solid var(--border-color);
    padding: 0.9rem;
    margin-bottom: 0.75rem;
    box-shadow: var(--box-shadow-sm);
    text-align: right;
    transition: transform 0.15s ease;
}
.mobile-record-card:active {
    transform: scale(0.99);
}

/* Copy Code Pill */
.copy-pill {
    background-color: #f1f5f9;
    border: 1px dashed #cbd5e1;
    padding: 0.2rem 0.5rem;
    border-radius: 6px;
    font-family: monospace;
    font-size: 0.85rem;
    color: #334155;
    cursor: pointer;
    transition: all 0.15s ease;
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
}
.copy-pill:hover {
    background-color: #e2e8f0;
    border-color: var(--primary);
    color: var(--primary);
}

/* Animations - Opacity only to prevent creating containing blocks that trap fixed modals */
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.animate-fade-in {
    animation: fadeIn 0.2s ease-out forwards;
}

/* Quick Filter Pills */
.filter-pill {
    background: #f1f5f9;
    color: #475569;
    border: 1px solid transparent;
    padding: 0.4rem 0.85rem;
    border-radius: 9999px;
    font-size: 0.82rem;
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
}
.filter-pill:hover, .filter-pill.active {
    background: var(--primary-light);
    color: var(--primary);
    border-color: #c7d2fe;
    font-weight: 600;
}

/* Empty State Box */
.empty-state {
    text-align: center;
    padding: 3rem 1.5rem;
    color: var(--text-muted);
}
.empty-state-icon {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background-color: #f1f5f9;
    color: #94a3b8;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1.75rem;
    margin-bottom: 1rem;
}

/* Modals & Backdrop Stacking & RTL */
.modal-backdrop {
    z-index: 1050 !important;
}

.modal {
    z-index: 1055 !important;
    direction: rtl !important;
    text-align: right !important;
}

.modal-content {
    border-radius: var(--border-radius-md);
    overflow: hidden;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border-color);
}

.modal-header .btn-close {
    margin: 0 !important;
}

.modal-body {
    padding: 1.25rem;
    text-align: right;
    direction: rtl;
}

.modal-footer {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 0.5rem;
    padding: 0.85rem 1.25rem;
    border-top: 1px solid var(--border-color);
}

/* Persian Datepicker Custom Theme Integration */
jdp-container {
    font-family: var(--font-family) !important;
    border-radius: 12px !important;
    border: 1px solid #e2e8f0 !important;
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.1) !important;
    z-index: 1060 !important;
}

jdp-container * {
    font-family: inherit !important;
}

jdp-container .jdp-day.selected {
    background-color: var(--primary) !important;
}

jdp-container .jdp-btn-today,
jdp-container .jdp-btn-empty,
jdp-container .jdp-btn-close {
    background-color: var(--primary) !important;
}

jdp-container .jdp-btn-today:hover,
jdp-container .jdp-btn-empty:hover,
jdp-container .jdp-btn-close:hover {
    background-color: var(--primary-dark) !important;
}

input[data-jdp] {
    cursor: pointer !important;
    background-color: #fff !important;
}

input[data-jdp]:focus {
    border-color: var(--primary) !important;
    box-shadow: 0 0 0 0.25rem rgba(79, 70, 229, 0.15) !important;
}
