:root {
    --primary: #2563ea;
    --primary-hover: #1d4ed8;
    --secondary: #64748b;
    --bg-body: #f1f5f9;
    --bg-white: #ffffff;
    --text-main: #1e293b;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --sidebar-width: 260px;
    --header-height: 64px;
    --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);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    color: var(--text-main);
    background-color: var(--bg-body);
    line-height: 1.5;
}

a {
    text-decoration: none;
    color: inherit;
}

.icon {
    width: 1.25rem;
    height: 1.25rem;
    stroke-width: 1.5;
    stroke: currentColor;
    fill: none;
}

/* Layout */
.layout {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-white);
    border-right: 1px solid var(--border);
    position: fixed;
    height: 100vh;
    display: flex;
    flex-direction: column;
}

.main-content {
    margin-left: var(--sidebar-width);
    flex: 1;
    display: flex;
    flex-direction: column;
}

.header {
    height: var(--header-height);
    background: var(--bg-white);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    padding: 0 2rem;
    position: sticky;
    top: 0;
    z-index: 10;
}

.page-content {
    padding: 2rem;
    max-width: 1200px;
    margin: 0 auto;
    width: 100%;
}

/* Sidebar Components */
.brand {
    height: var(--header-height);
    display: flex;
    align-items: center;
    padding: 0 1.5rem;
    font-weight: 700;
    font-size: 1.25rem;
    color: var(--primary);
    border-bottom: 1px solid var(--border);
}

.nav-links {
    padding: 1.5rem 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.nav-item {
    padding: 0.75rem 1rem;
    border-radius: 0.5rem;
    color: var(--text-muted);
    font-weight: 500;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.nav-item:hover,
.nav-item.active {
    background-color: #eff6ff;
    color: var(--primary);
}

/* Dashboard Cards */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.card {
    background: var(--bg-white);
    border-radius: 1rem;
    padding: 1.5rem;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border);
}

.stat-label {
    color: var(--text-muted);
    font-size: 0.875rem;
    font-weight: 500;
    margin-bottom: 0.5rem;
}

.stat-value {
    font-size: 1.875rem;
    font-weight: 700;
    color: var(--text-main);
}

/* Tables */
.table-container {
    background: var(--bg-white);
    border-radius: 1rem;
    border: 1px solid var(--border);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
}

table {
    width: 100%;
    border-collapse: collapse;
}

th,
td {
    padding: 1rem 1.5rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

th {
    background: #f8fafc;
    font-weight: 600;
    color: var(--text-muted);
    font-size: 0.875rem;
}

tr:last-child td {
    border-bottom: none;
}

.badge {
    padding: 0.25rem 0.75rem;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 600;
}

.badge-in {
    background: #dcfce7;
    color: #166534;
}

.badge-out {
    background: #fee2e2;
    color: #991b1b;
}

/* Forms */
.form-group {
    margin-bottom: 1.5rem;
}

.form-label {
    display: block;
    font-weight: 500;
    margin-bottom: 0.5rem;
    color: var(--text-main);
}

.form-control {
    width: 100%;
    padding: 0.75rem 1rem;
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    font-size: 1rem;
    transition: border-color 0.2s;
}

.form-control:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 234, 0.1);
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.75rem 1.5rem;
    border-radius: 0.5rem;
    font-weight: 600;
    cursor: pointer;
    border: none;
    transition: all 0.2s;
}

.btn-primary {
    background: var(--primary);
    color: white;
}

.btn-primary:hover {
    background: var(--primary-hover);
}

/* Loading State */
.btn.loading {
    position: relative;
    color: transparent !important;
    pointer-events: none;
    cursor: not-allowed;
}

.btn.loading::after {
    content: "";
    position: absolute;
    width: 1.25em;
    height: 1.25em;
    top: 50%;
    left: 50%;
    margin-top: -0.625em;
    /* half of height */
    margin-left: -0.625em;
    /* half of width */
    border: 2px solid #ffffff;
    border-radius: 50%;
    border-top-color: transparent;
    animation: btn-spin 0.8s linear infinite;
}

@keyframes btn-spin {
    to {
        transform: rotate(360deg);
    }
}

@keyframes btn-spin {
    to {
        transform: rotate(360deg);
    }
}

/* Toast Notification */
.toast {
    position: fixed;
    top: 1rem;
    right: 1rem;
    background: var(--bg-white);
    padding: 1rem 1.5rem;
    border-radius: 0.5rem;
    box-shadow: var(--shadow-md);
    border-left: 4px solid var(--primary);
    display: flex;
    align-items: center;
    gap: 0.75rem;
    z-index: 100;
    animation: slideIn 0.3s ease-out forwards;
    max-width: 90%;
    width: auto;
}

.toast.hide {
    animation: fadeOut 0.3s ease-in forwards;
}

@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }

    to {
        transform: translateX(0);
        opacity: 1;
    }
}

@keyframes fadeOut {
    to {
        opacity: 0;
        visibility: hidden;
    }
}

/* Modal */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 50;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s;
}

.modal-overlay.open {
    opacity: 1;
    pointer-events: auto;
}

.modal {
    background: var(--bg-white);
    padding: 2rem;
    border-radius: 1rem;
    width: 100%;
    max-width: 500px;
    box-shadow: var(--shadow-md);
}

/* Autocomplete Dropdown */
.autocomplete-wrapper {
    position: relative;
}

.autocomplete-results {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--bg-white);
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    max-height: 200px;
    overflow-y: auto;
    z-index: 50;
    box-shadow: var(--shadow-md);
    display: none;
    margin-top: 0.25rem;
}

.autocomplete-results.show {
    display: block;
}

.autocomplete-item {
    padding: 0.75rem 1rem;
    cursor: pointer;
    border-bottom: 1px solid var(--border);
    transition: background-color 0.1s;
}

.autocomplete-item:last-child {
    border-bottom: none;
}

.autocomplete-item:hover {
    background-color: #f1f5f9;
    color: var(--primary);
}

.no-results {
    padding: 1rem;
    color: var(--text-muted);
    font-style: italic;
    text-align: center;
}

/* Bottom Navigation */
.bottom-nav {
    display: none;
}

/* Responsive Layout Helpers */
.grid-responsive {
    display: grid;
    grid-template-columns: 1fr 3fr;
    gap: 1.5rem;
}

.search-form {
    display: flex;
    gap: 1rem;
    align-items: flex-end;
}

.search-form .form-group {
    flex: 1;
}

.search-form .btn {
    min-width: 120px;
}

/* Mobile Responsive */
@media (max-width: 768px) {
    .sidebar {
        display: none;
    }

    .main-content {
        margin-left: 0;
        margin-bottom: 80px;
        /* Space for bottom nav */
    }

    .header {
        padding: 0 1rem;
    }

    .page-content {
        padding: 1rem;
    }

    /* Bottom Nav Styles */
    .bottom-nav {
        display: flex;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        background: var(--bg-white);
        border-top: 1px solid var(--border);
        height: 64px;
        z-index: 40;
        justify-content: space-around;
        padding-bottom: env(safe-area-inset-bottom);
    }

    .bottom-nav .nav-item {
        flex-direction: column;
        gap: 0.25rem;
        font-size: 0.75rem;
        padding: 0.5rem;
        border-radius: 0;
        color: var(--text-muted);
        flex: 1;
        justify-content: center;
    }

    .bottom-nav .nav-item.active {
        color: var(--primary);
        background: transparent;
    }

    .bottom-nav .icon {
        width: 1.5rem;
        height: 1.5rem;
    }

    /* Mobile Menu Modal */
    #mobileMenuModal .modal {
        width: 100%;
        max-width: none;
        bottom: 0;
        border-radius: 1.5rem 1.5rem 0 0;
    }

    /* Stack Grids */
    .stats-grid {
        grid-template-columns: 1fr;
    }

    .layout .page-content>div[style*="grid-template-columns"] {
        grid-template-columns: 1fr !important;
    }

    /* Scrollable Tables */
    .table-container {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    table {
        min-width: 600px;
        /* Force scroll */
    }

    /* Adjust Forms for Mobile to prevent zoom */
    .form-control,
    select.form-control,
    input.form-control {
        font-size: 16px;
    }

    .modal {
        padding: 1.5rem;
        width: 90%;
    }

    /* Responsive Grid */
    .grid-responsive {
        grid-template-columns: 1fr;
    }

    .search-form {
        flex-direction: column;
        align-items: stretch;
    }

    /* Mobile Table Card View */
    .mobile-card-table {
        display: block;
        min-width: 0;
        width: 100%;
    }

    .mobile-card-table thead {
        display: none;
    }

    .mobile-card-table tbody {
        display: block;
    }

    .mobile-card-table tr {
        display: block;
        margin-bottom: 1rem;
        border: 1px solid var(--border);
        border-radius: 0.5rem;
        background: var(--bg-white);
        box-shadow: var(--shadow-sm);
    }

    .mobile-card-table td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        text-align: right;
        padding: 0.75rem 1rem;
        border-bottom: 1px solid var(--border);
        min-height: 3rem;
        word-break: break-word;
    }

    .mobile-card-table td:last-child {
        border-bottom: none;
    }

    .mobile-card-table td::before {
        content: attr(data-label);
        font-weight: 600;
        color: var(--text-muted);
        text-align: left;
        margin-right: 1rem;
        font-size: 0.875rem;
    }
}