:root {
    --primary: #6366f1;
    --primary-hover: #4f46e5;
    --secondary: #10b981;
    --secondary-hover: #059669;
    --danger: #ef4444;
    --warning: #f59e0b;
    --info: #3b82f6;
    --dark: #0f172a;
    --dark-lighter: #1e293b;
    --light: #f8fafc;
    --text-main: #334155;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --sidebar-width: 260px;
    --transition: all 0.3s ease;

    /* Responsive spacing scale */
    --space-xs: 0.25rem;
    --space-sm: 0.5rem;
    --space-md: 1rem;
    --space-lg: 1.5rem;
    --space-xl: 2rem;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Outfit', sans-serif;
    background-color: #f1f5f9;
    color: var(--text-main);
    line-height: 1.5;
}

a {
    text-decoration: none;
    color: inherit;
}

ul {
    list-style: none;
}

/* Layout */
.wrapper {
    display: flex;
    min-height: 100vh;
}

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    background-color: var(--dark);
    color: white;
    height: 100vh;
    position: fixed;
    left: 0;
    top: 0;
    transition: var(--transition);
    z-index: 1000;
}

.sidebar-header {
    padding: 2rem;
    text-align: center;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.sidebar-logo-img {
    max-width: 180px;
    height: auto;
    max-height: 45px;
    object-fit: contain;
    filter: drop-shadow(0 0 8px rgba(255, 255, 255, 0.1));
}

.sidebar-menu {
    padding: 1rem 0;
}

.menu-item {
    padding: 0.9rem 1.5rem;
    display: flex;
    align-items: center;
    gap: 1.25rem;
    color: #94a3b8;
    transition: var(--transition);
    cursor: pointer;
    border-radius: 8px;
    margin: 0.2rem 0.75rem;
}

.menu-item:hover,
.menu-item.active {
    color: white;
    background-color: rgba(99, 102, 241, 0.1);
    border-left: 4px solid var(--primary);
}

.menu-item i {
    font-size: 1.2rem;
    width: 20px;
}

/* Main Content Base */
.main-content {
    flex: 1;
    padding: clamp(1rem, 3vw, 2rem);
    /* Fluid padding based on viewport width */
    transition: var(--transition);
    width: 100%;
}

/* Desktop Only Layout */
@media (min-width: 1025px) {
    .sidebar {
        width: var(--sidebar-width);
        left: 0;
    }

    .main-content {
        margin-left: var(--sidebar-width);
        width: calc(100% - var(--sidebar-width));
    }

    .mobile-toggle,
    .mobile-close,
    .sidebar-overlay {
        display: none !important;
    }
}

/* Header */
.top-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
    background: white;
    padding: 1.25rem 4%;
    /* Percentage-based horizontal padding */
    border-radius: 12px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
    width: 100%;
}

.user-profile {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.avatar {
    width: 40px;
    height: 40px;
    background: var(--primary);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 600;
}

/* Cards */
.card {
    background: white;
    border-radius: 15px;
    padding: 1.5rem;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
    margin-bottom: 1.5rem;
    transition: var(--transition);
}

.card:hover {
    transform: translateY(-5px);
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
}

.card-title {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

/* Responsive card title with filters */
@media (max-width: 768px) {
    .card-title-responsive {
        flex-direction: column;
        align-items: flex-start;
        gap: 1rem;
    }

    .card-title-responsive .filters {
        width: 100%;
        flex-direction: column;
    }

    .card-title-responsive .filters select,
    .card-title-responsive .filters input,
    .card-title-responsive .filters button {
        width: 100%;
        max-width: none !important;
    }
}

/* Stats */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 280px), 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
    width: 100%;
}

/* Responsive Layout System */
.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    z-index: 999;
}

.mobile-toggle {
    display: none;
    background: none;
    border: none;
    font-size: 1.5rem;
    color: var(--text-main);
    cursor: pointer;
}

.mobile-close {
    display: none;
    position: absolute;
    right: 1.5rem;
    top: 1.5rem;
    font-size: 1.5rem;
    color: white;
    cursor: pointer;
}

/* Tablet and Mobile Layout (Hidden Sidebar) */
@media (max-width: 1024px) {
    .sidebar {
        left: -280px !important;
        width: min(85%, 280px) !important;
        /* Percentage-based width with cap */
        z-index: 2000;
    }

    .sidebar.active {
        left: 0 !important;
    }

    .main-content {
        margin-left: 0 !important;
        width: 100% !important;
        padding: 1rem 4% !important;
    }

    .mobile-toggle {
        display: block;
    }

    .mobile-close {
        display: block;
    }

    .sidebar-overlay.active {
        display: block;
    }

    .top-header {
        padding: 1rem 4% !important;
        margin-bottom: 1.5rem;
        border-radius: 10px;
    }

    .stats-grid {
        grid-template-columns: repeat(auto-fit, minmax(min(100%, 260px), 1fr));
        gap: 1.5rem;
    }
}

/* Specific Mobile Optimization */
@media (max-width: 600px) {
    .top-header {
        flex-direction: row !important;
        flex-wrap: wrap;
        justify-content: space-between;
        align-items: center !important;
        padding: 0.75rem 3% !important;
        gap: 0.5rem;
    }

    .header-left {
        flex: 1;
        min-width: 0;
    }

    .header-left h2 {
        font-size: 1rem;
        margin: 0;
        line-height: 1.2;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .mobile-toggle {
        font-size: 1.25rem;
        padding: 0.25rem;
    }

    .header-right {
        flex-shrink: 0;
    }

    .user-profile {
        gap: 0.5rem !important;
    }

    .user-info {
        display: none !important;
    }

    .avatar {
        width: 32px;
        height: 32px;
        font-size: 0.85rem;
    }

    .btn-sm {
        padding: 0.35rem 0.6rem;
        font-size: 0.75rem;
    }

    .stats-grid {
        grid-template-columns: 1fr;
        gap: 0.75rem;
        margin-bottom: 1rem;
    }

    .stat-card {
        padding: 1rem;
        gap: 0.75rem;
    }

    .stat-icon {
        width: 40px;
        height: 40px;
        font-size: 1.25rem;
    }

    .stat-info h3 {
        font-size: 0.8rem;
    }

    .stat-info p {
        font-size: 1.25rem;
    }

    .card {
        padding: 1rem;
        border-radius: 12px;
        margin-bottom: 1rem;
    }

    .card-title {
        font-size: 1rem;
        margin-bottom: 1rem;
        flex-wrap: wrap;
        gap: 0.5rem;
    }

    /* Mobile Tables */
    .table-container {
        border-radius: 8px;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    table {
        font-size: 0.85rem;
        min-width: 100%;
    }

    th, td {
        padding: 0.75rem 0.5rem;
        white-space: nowrap;
    }

    th {
        font-size: 0.65rem;
        padding: 0.75rem 0.5rem;
    }

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

    .form-group label {
        font-size: 0.85rem;
        margin-bottom: 0.35rem;
    }

    .form-control {
        padding: 0.6rem 0.75rem;
        font-size: 16px; /* Prevent zoom on iOS */
        border-radius: 8px;
    }

    /* Mobile Modal */
    .modal-content {
        padding: 1.25rem;
        width: 95%;
        margin: 3% auto;
        border-radius: 12px;
        max-height: 90vh;
        overflow-y: auto;
    }

    .modal-content h2,
    .modal-content h3 {
        font-size: 1.1rem;
    }

    /* Mobile Grid */
    .grid-2 {
        grid-template-columns: 1fr !important;
        gap: 0.75rem;
    }

    /* Mobile Buttons */
    .btn {
        padding: 0.5rem 1rem;
        font-size: 0.9rem;
    }

    /* Status badges mobile */
    .status-badge {
        padding: 0.2rem 0.5rem;
        font-size: 0.75rem;
    }

    /* Filters mobile */
    .filters {
        flex-direction: column !important;
        width: 100%;
        gap: 0.5rem !important;
    }

    .filters select,
    .filters input {
        width: 100% !important;
        max-width: none !important;
    }

    /* Login page mobile */
    .login-card {
        padding: 1.5rem;
        margin: 1rem;
        width: calc(100% - 2rem);
        max-width: none;
    }

    .login-logo {
        width: 150px;
    }

    /* Sidebar mobile */
    .sidebar {
        width: 280px !important;
    }

    .sidebar-header {
        padding: 1.5rem;
    }

    .sidebar-logo-img {
        max-width: 160px;
    }

    .menu-item {
        padding: 0.8rem 1.25rem;
        font-size: 0.95rem;
    }

    /* Attendance page specific */
    .stats-grid > .card[style*="grid-column: span 2"] {
        grid-column: span 1 !important;
    }

    /* Chart container mobile */
    canvas {
        max-height: 200px !important;
    }
}

/* Extra Small Devices */
@media (max-width: 375px) {
    .main-content {
        padding: 0.75rem !important;
    }

    .top-header {
        padding: 0.6rem !important;
    }

    .header-left h2 {
        font-size: 0.9rem;
    }

    .card {
        padding: 0.875rem;
    }

    .stat-card {
        padding: 0.875rem;
    }

    .stat-icon {
        width: 36px;
        height: 36px;
        font-size: 1.1rem;
    }

    .stat-info p {
        font-size: 1.1rem;
    }

    th, td {
        padding: 0.6rem 0.4rem;
        font-size: 0.8rem;
    }
}

/* Mobile Landscape */
@media (max-width: 768px) and (orientation: landscape) {
    .modal-content {
        max-height: 85vh;
        overflow-y: auto;
    }

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

    .stat-card {
        padding: 0.875rem;
    }
}

/* Tablet Optimization */
@media (min-width: 601px) and (max-width: 1024px) {
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 1rem;
    }

    .grid-2 {
        grid-template-columns: 1fr;
    }

    .card {
        padding: 1.25rem;
    }

    .top-header {
        padding: 1rem 4% !important;
    }

    /* Dashboard two-column layout becomes single column on tablet */
    .grid-2[style*="2fr 1fr"] {
        grid-template-columns: 1fr !important;
    }

    /* Tables still scrollable */
    .table-container {
        overflow-x: auto;
    }
}

/* Large Tablets and Small Laptops */
@media (min-width: 769px) and (max-width: 1024px) {
    .main-content {
        padding: 1.25rem;
    }

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

    .sidebar {
        width: 240px;
    }

    .main-content {
        margin-left: 240px;
        width: calc(100% - 240px);
    }

    .grid-2 {
        grid-template-columns: 1fr;
    }
}

/* Large Screens */
@media (min-width: 1400px) {
    .stats-grid {
        grid-template-columns: repeat(4, 1fr);
    }

    .main-content {
        padding: 2rem;
    }

    .card {
        padding: 2rem;
    }
}

/* Extra Large Screens */
@media (min-width: 1800px) {
    .main-content {
        max-width: 1600px;
        margin-left: var(--sidebar-width);
    }
}

/* Print Styles */
@media print {
    .sidebar,
    .mobile-toggle,
    .top-header,
    .btn {
        display: none !important;
    }

    .main-content {
        margin-left: 0 !important;
        padding: 0 !important;
    }

    .card {
        box-shadow: none;
        border: 1px solid #ddd;
        break-inside: avoid;
    }
}

/* Base Transitions */
.sidebar,
.main-content {
    transition: margin-left 0.3s ease, width 0.3s ease;
}

.stat-card {
    background: white;
    padding: 1.5rem;
    border-radius: 15px;
    display: flex;
    align-items: center;
    gap: 1rem;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
    transition: var(--transition);
}

.stat-card:hover {
    transform: scale(1.02);
}

.stat-icon {
    width: 50px;
    height: 50px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
}

.stat-info h3 {
    font-size: 0.9rem;
    color: var(--text-muted);
}

.stat-info p {
    font-size: 1.5rem;
    font-weight: 700;
}

/* Tables (Excel Style) */
.table-container {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    scrollbar-color: #cbd5e1 #f1f5f9;
}

.table-container::-webkit-scrollbar {
    height: 6px;
}

.table-container::-webkit-scrollbar-track {
    background: #f1f5f9;
}

.table-container::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 3px;
}

table {
    width: 100%;
    border-collapse: collapse;
    min-width: 600px;
}

th {
    background-color: #f8fafc;
    color: var(--text-muted);
    font-weight: 600;
    text-transform: uppercase;
    font-size: 0.7rem;
    padding: 1.25rem 1rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

td {
    padding: 1.25rem 1rem;
    border-bottom: 1px solid var(--border);
    font-size: 0.9rem;
    vertical-align: middle;
}

tr:hover {
    background-color: #f1f5f9;
}

.status-badge {
    padding: 0.25rem 0.75rem;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 600;
}

.status-active,
.status-completed {
    background: #dcfce7;
    color: #166534;
}

.status-inactive {
    background: #fee2e2;
    color: #991b1b;
}

.status-pending {
    background: #fef3c7;
    color: #92400e;
}

.status-in-progress {
    background: #dbeafe;
    color: #1e40af;
}

.status-late {
    background: #fee2e2;
    color: #991b1b;
}

/* Custom Scrollbar */
::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: #f1f5f9;
}

::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 10px;
}

::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

/* Animations */
@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.card,
.stat-card {
    animation: fadeInUp 0.5s ease-out forwards;
}

/* Glassmorphism utility */
.glass {
    background: rgba(255, 255, 255, 0.7) !important;
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.3);
}

/* Status Badge Overrides */
.status-badge {
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

/* Table Enhancements */
.table-container {
    border-radius: 12px;
    overflow: hidden;
    border: 1px solid var(--border);
}

th {
    background-color: #f8fafc;
}

/* Login Logo */
.login-logo {
    width: 200px;
    height: auto;
    margin-bottom: 2rem;
    display: block;
    margin-left: auto;
    margin-right: auto;
}

/* Professional Modal System */
.modal {
    display: none;
    position: fixed;
    z-index: 10000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(15, 23, 42, 0.6);
    backdrop-filter: blur(4px);
    animation: fadeIn 0.3s ease;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.modal-content {
    background-color: white;
    margin: 5% auto;
    padding: 2.5rem;
    border-radius: 20px;
    width: 90%;
    max-width: 600px;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
    position: relative;
    animation: slideIn 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    max-height: calc(100vh - 10%);
    overflow-y: auto;
}

/* Modal responsive improvements */
@media (max-width: 768px) {
    .modal-content {
        margin: 10% auto;
        padding: 1.5rem;
        width: 95%;
        border-radius: 15px;
        max-height: calc(100vh - 20%);
    }
}

@media (max-width: 480px) {
    .modal-content {
        margin: 5% auto;
        padding: 1.25rem;
        width: 96%;
        border-radius: 12px;
        max-height: 90vh;
    }
}

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

    to {
        transform: translateY(0);
        opacity: 1;
    }
}

/* Form Styling */
.form-group {
    margin-bottom: 1.25rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    color: var(--text-main);
    font-size: 0.9rem;
}

.form-control {
    width: 100%;
    padding: 0.75rem 1rem;
    border: 1px solid var(--border);
    border-radius: 10px;
    font-family: inherit;
    font-size: 0.95rem;
    transition: all 0.3s;
    background-color: #fff;
    color: var(--text-main);
}

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

textarea.form-control {
    resize: vertical;
}

.grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
}

/* Dashboard-specific grid - 2:1 ratio on desktop */
.dashboard-grid {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 1.5rem;
    margin-bottom: 1.5rem;
}

/* Reports grid - 2 columns */
.reports-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
    margin-top: 2rem;
}

.reports-grid .card-full-width {
    grid-column: span 2;
}

@media (max-width: 1024px) {
    .dashboard-grid {
        grid-template-columns: 1fr;
        gap: 1rem;
    }

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

    .reports-grid .card-full-width {
        grid-column: span 1;
    }
}

@media (max-width: 600px) {
    .grid-2 {
        grid-template-columns: 1fr;
        gap: 1rem;
    }

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

    .reports-grid {
        grid-template-columns: 1fr;
        gap: 0.75rem;
        margin-top: 1rem;
    }

    .reports-grid .card-full-width {
        grid-column: span 1;
    }
}

/* Form grid helpers */
.form-group-full {
    grid-column: span 2;
}

.form-group-btn {
    display: flex;
    align-items: flex-end;
}

@media (max-width: 600px) {
    .form-group-full {
        grid-column: span 1;
    }
}

/* Attendance page grid - 1:2 ratio */
.attendance-grid {
    display: grid;
    grid-template-columns: 1fr 2fr;
    gap: 1.5rem;
    margin-bottom: 1.5rem;
}

.attendance-grid .card-wide {
    grid-column: span 1;
}

@media (max-width: 1024px) {
    .attendance-grid {
        grid-template-columns: 1fr;
        gap: 1rem;
    }

    .attendance-grid .card-wide {
        grid-column: span 1;
    }
}

@media (max-width: 600px) {
    .attendance-grid {
        grid-template-columns: 1fr;
        gap: 0.75rem;
    }
}

/* Export page grid */
.export-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 1.5rem;
    margin-bottom: 1.5rem;
}

@media (max-width: 1024px) {
    .export-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 1rem;
    }
}

@media (max-width: 600px) {
    .export-grid {
        grid-template-columns: 1fr;
        gap: 0.75rem;
    }
}

.btn-outline {
    background: #f1f5f9;
    color: var(--text-main);
}

.btn-outline:hover {
    background: #e2e8f0;
}

.mt-4 {
    margin-top: 1.5rem;
}

.w-full {
    width: 100% !important;
}

/* Buttons */
.btn {
    padding: 0.6rem 1.2rem;
    border-radius: 8px;
    font-weight: 500;
    cursor: pointer;
    border: none;
    transition: var(--transition);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.btn-primary {
    background: var(--primary);
    color: white;
}

.btn-primary:hover {
    background: var(--primary-hover);
}

.btn-sm {
    padding: 0.4rem 0.8rem;
    font-size: 0.8rem;
}

.text-danger {
    color: var(--danger);
}

.text-warning {
    color: var(--warning);
}

.text-success {
    color: var(--secondary);
}

.font-bold {
    font-weight: 700;
}

.text-xs {
    font-size: 0.75rem;
}

.text-center {
    text-align: center;
}

.w-full {
    width: 100%;
}