@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@300;400;500;600;700&display=swap');

:root {
    --primary: #4f46e5;
    --primary-light: #818cf8;
    --secondary: #10b981;
    --accent: #f59e0b;
    --danger: #ef4444;
    --bg-main: #f8fafc;
    --bg-card: #ffffff;
    --text-main: #1e293b;
    --text-muted: #64748b;
    --border-color: #e2e8f0;
    --radius-lg: 16px;
    --radius-md: 12px;
    --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-hover: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
}

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

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

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

/* Sidebar */
.sidebar {
    width: 280px;
    background: var(--bg-card);
    border-right: 1px solid var(--border-color);
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    height: 100vh;
    z-index: 50;
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    overflow-y: auto;
    overflow-x: hidden;
}

.sidebar::-webkit-scrollbar {
    width: 5px;
}

.sidebar::-webkit-scrollbar-thumb {
    background: #e2e8f0;
    border-radius: 10px;
}

.sidebar::-webkit-scrollbar-track {
    background: transparent;
}

.sidebar.minimized {
    width: 80px;
    padding: 1.5rem 0.5rem;
}

.sidebar .brand-name,
.sidebar .nav-link span,
.sidebar .nav-item p {
    opacity: 1;
    transition: opacity 0.3s ease, visibility 0.3s;
    visibility: visible;
}

.sidebar.minimized .brand-name,
.sidebar.minimized .nav-link span,
.sidebar.minimized .nav-item p {
    opacity: 0;
    visibility: hidden;
    width: 0;
    height: 0;
    overflow: hidden;
    position: absolute;
}

.sidebar.minimized .brand {
    flex-direction: column;
    gap: 15px;
    padding: 0;
    margin-bottom: 2rem;
    border-bottom: transparent;
}

.sidebar.minimized #sidebar-minimize {
    margin: 0;
}

.sidebar.minimized .nav-link {
    justify-content: center;
    padding: 0.8rem;
    gap: 0;
}

.sidebar.minimized .nav-link i {
    font-size: 1.25rem;
    margin: 0;
}

.brand {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 2.5rem;
    padding-bottom: 1.5rem;
    border-bottom: 1px solid #f1f5f9;
    transition: all 0.4s;
}

.brand-logo {
    width: 40px;
    height: 40px;
    background: linear-gradient(135deg, var(--primary), var(--primary-light));
    border-radius: var(--radius-md);
    display: flex;
    flex-sizing: border-box;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: bold;
    font-size: 1.2rem;
    flex-shrink: 0;
}

.brand-name {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--primary);
    letter-spacing: -0.5px;
    white-space: nowrap;
}

.nav-menu {
    list-style: none;
    flex: 1;
}

.nav-item {
    margin-bottom: 0.5rem;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0.8rem 1rem;
    text-decoration: none;
    color: var(--text-muted);
    border-radius: var(--radius-md);
    transition: all 0.2s ease;
    font-weight: 500;
    white-space: nowrap;
}

.nav-link i {
    width: 20px;
    text-align: center;
}

.nav-link:hover {
    background-color: #f1f5f9;
    color: var(--primary);
}

.nav-link.active {
    background: linear-gradient(to right, var(--primary), var(--primary-light));
    color: white;
    box-shadow: 0 4px 12px rgba(79, 70, 229, 0.3);
}

/* Main Content */
.main-content {
    flex: 1;
    margin-left: 280px;
    padding: 2rem 3rem;
    transition: margin-left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.main-content.sidebar-minimized {
    margin-left: 85px;
}

.top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2.5rem;
}

.page-title h1 {
    font-size: 1.875rem;
    font-weight: 700;
    color: var(--text-main);
}

.user-profile {
    display: flex;
    align-items: center;
    gap: 12px;
    background: var(--bg-card);
    padding: 0.5rem 1rem;
    border-radius: 50px;
    box-shadow: var(--shadow);
}

/* Dashboard Cards */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2.5rem;
}

.stat-card {
    padding: 1.5rem 2rem;
    border-radius: var(--radius-lg);
    box-shadow: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    color: white;
}

.stat-card::after {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    width: 150px;
    height: 150px;
    background: radial-gradient(circle, rgba(255, 255, 255, 0.15) 0%, rgba(255, 255, 255, 0) 70%);
    transform: translate(30%, -30%);
    border-radius: 50%;
    pointer-events: none;
}

.stat-card:hover {
    transform: translateY(-6px);
    box-shadow: 0 20px 25px -5px rgb(0 0 0 / 0.15), 0 8px 10px -6px rgb(0 0 0 / 0.1);
}

.stat-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 1.5rem;
}

.stat-icon {
    width: 54px;
    height: 54px;
    border-radius: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.75rem;
    background: rgba(255, 255, 255, 0.2);
    color: white;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    backdrop-filter: blur(4px);
}

.stat-info {
    margin-top: auto;
}

.stat-value {
    font-size: 2.75rem;
    font-weight: 800;
    letter-spacing: -1px;
    line-height: 1;
    margin-bottom: 0.5rem;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.stat-label {
    font-weight: 600;
    font-size: 0.95rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: rgba(255, 255, 255, 0.9);
}

/* Tables */
.card {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    overflow: hidden;
    margin-bottom: 2rem;
}

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

.table-container {
    width: 100%;
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
}

th {
    background-color: #f8fafc;
    padding: 1rem 1.5rem;
    text-align: left;
    font-weight: 600;
    color: var(--text-muted);
    font-size: 0.875rem;
    text-transform: uppercase;
}

td {
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
}

tr:last-child td {
    border-bottom: none;
}

/* Buttons */
.btn {
    padding: 0.6rem 1.25rem;
    border-radius: var(--radius-md);
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    border: none;
    font-family: inherit;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary), var(--primary-light));
    color: white;
}

.btn-primary:hover {
    box-shadow: 0 4px 12px rgba(79, 70, 229, 0.4);
    opacity: 0.9;
}

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

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

.form-control {
    width: 100%;
    padding: 0.75rem 1rem;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    font-family: inherit;
    transition: border-color 0.2s;
}

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

/* Alerts */
.alert {
    padding: 1rem 1.5rem;
    border-radius: var(--radius-md);
    margin-bottom: 1.5rem;
    font-weight: 500;
}

.alert-success {
    background-color: #ecfdf5;
    color: #065f46;
    border-left: 4px solid var(--secondary);
}

.alert-danger {
    background-color: #fef2f2;
    color: #991b1b;
    border-left: 4px solid var(--danger);
}

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

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

.animate-slide-in {
    animation: slideIn 0.3s ease forwards;
}

/* Login Page Styles */
.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: linear-gradient(135deg, #f0f9ff 0%, #e0f2fe 100%);
}

.login-card {
    background: white;
    padding: 3rem;
    border-radius: var(--radius-lg);
    box-shadow: 0 25px 50px -12px rgb(0 0 0 / 0.1);
    width: 100%;
    max-width: 450px;
    text-align: center;
}

.login-header h2 {
    font-size: 2rem;
    font-weight: 800;
    margin-bottom: 0.5rem;
    color: var(--primary);
}

.login-header p {
    color: var(--text-muted);
    margin-bottom: 2.5rem;
}

/* ==========================================================================
   Responsive Design (Media Queries)
   ========================================================================== */

/* Overlay for mobile sidebar */
.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100vh;
    background: rgba(15, 23, 42, 0.6);
    backdrop-filter: blur(2px);
    z-index: 40;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.sidebar-overlay.show {
    display: block;
    opacity: 1;
}

/* Menu Toggle Button (Hamburger) */
.menu-toggle {
    display: none;
    background: none;
    border: none;
    font-size: 1.5rem;
    color: var(--text-main);
    cursor: pointer;
    padding: 0.5rem;
    margin-right: 1rem;
    border-radius: 8px;
    transition: background 0.2s;
}

.menu-toggle:hover {
    background: #f1f5f9;
}

/* Tablet & Smaller Laptops */
@media (max-width: 992px) {
    .sidebar {
        transform: translateX(-100%);
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        box-shadow: 4px 0 25px rgba(0, 0, 0, 0.1);
    }

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

    .main-content {
        margin-left: 0;
        padding: 1rem;
    }

    .menu-toggle {
        display: block;
    }

    .top-bar {
        justify-content: flex-start;
    }

    .page-title {
        flex: 1;
    }

    /* Make inline grids stack automatically */
    .desktop-only {
        display: none !important;
    }

    div[style*="grid-template-columns: 1fr 1fr"] {
        grid-template-columns: 1fr !important;
        gap: 20px !important;
    }

    div[style*="grid-column: 2"] {
        grid-column: 1 !important;
    }
}

/* Mobile Phones */
@media (max-width: 768px) {
    .main-content {
        padding: 1rem;
    }

    .login-card {
        padding: 2rem 1.5rem;
        margin: 1rem;
    }

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

    .page-title h1 {
        font-size: 1.25rem;
    }

    .user-profile {
        padding: 0.25rem 0.25rem 0.25rem 0.75rem;
    }

    .user-profile>div:first-child {
        display: none;
        /* Hide name/role text on small screens */
    }

    /* Mobile Sidebar Toggle - Handled in CSS above */

    .top-bar {
        flex-wrap: wrap !important;
        gap: 0.75rem !important;
        margin-bottom: 1.5rem !important;
    }

    .page-title {
        order: 2 !important;
        width: 100% !important;
        flex: none !important;
    }

    .page-title h1 {
        font-size: 1.25rem !important;
    }

    .menu-toggle {
        order: 1 !important;
        display: block !important;
    }

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

    .card-header {
        flex-direction: column !important;
        align-items: stretch !important;
        gap: 1rem !important;
        padding: 1.25rem !important;
    }

    /* Target ANY flex container inside card-header to stack on mobile */
    .card-header div,
    .card-header form {
        display: flex !important;
        flex-direction: column !important;
        align-items: stretch !important;
        width: 100% !important;
        gap: 8px !important;
        margin: 0 !important;
    }

    .card-header .btn,
    .card-header .form-control {
        width: 100% !important;
        margin: 0 !important;
    }

    /* Better Table Handling */
    .table-container {
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch;
        border: 1px solid var(--border-color);
        border-radius: var(--radius-md);
        margin: 1rem 0;
        background: #fff;
        width: 100% !important;
        display: block !important;
    }

    .table-container table {
        min-width: 800px !important;
        /* Force a wide table to ensure scrolling */
        width: 100%;
        border-collapse: collapse;
    }

    /* Custom Scrollbar for better visibility */
    .table-container::-webkit-scrollbar {
        height: 6px;
    }

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

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

    /* Fixed header for tables if needed */
    th,
    td {
        white-space: nowrap;
        padding: 1rem 0.75rem !important;
    }

    /* Scanner specific overrides */
    #live-clock {
        font-size: 2.25rem !important;
    }

    .scanner-container {
        padding: 1.5rem 1rem !important;
    }

    .id-card-illustration {
        width: 140px !important;
        height: 90px !important;
    }

    /* Settings buttons stack */
    div[style*="display: flex; gap: 15px; flex-wrap: wrap"] {
        flex-direction: column;
        align-items: stretch !important;
        gap: 10px !important;
    }

    div[style*="display: flex; gap: 10px; flex-wrap: wrap"] {
        flex-direction: column;
        align-items: stretch !important;
        gap: 10px !important;
    }

    form.form-delete {
        margin-left: 0 !important;
        width: 100%;
    }

    form.form-delete .btn {
        width: 100%;
    }
}