:root {
    --primary-gradient: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%);
    --secondary-gradient: linear-gradient(135deg, #3b82f6 0%, #2dd4bf 100%);
    --info-gradient: linear-gradient(135deg, #0ea5e9 0%, #22d3ee 100%);
    --success-gradient: linear-gradient(135deg, #10b981 0%, #34d399 100%);
    --warning-gradient: linear-gradient(135deg, #f59e0b 0%, #fbbf24 100%);
    --danger-gradient: linear-gradient(135deg, #ef4444 0%, #f87171 100%);
    --dark-gradient: linear-gradient(135deg, #1f2937 0%, #374151 100%);
    --surface-color: #ffffff;
    --background-color: #f3f4f6;
    --text-primary: #1f2937;
    --text-secondary: #6b7280;
    --border-radius: 16px;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
}

[data-bs-theme="dark"] {
    --surface-color: #212529;
    /* bg-dark */
    --background-color: #000000;
    /* bg-black */
    --text-primary: #f8f9fa;
    /* text-light */
    --text-secondary: #adb5bd;
    /* text-body-secondary */
}

[data-bs-theme="dark"] .table thead th {
    background-color: #2c3034;
    color: #dee2e6;
    border-color: #373b3e;
}

[data-bs-theme="dark"] .table tbody td {
    color: #dee2e6;
    border-color: #373b3e;
}

[data-bs-theme="dark"] .form-floating>.form-control,
[data-bs-theme="dark"] .form-floating>.form-select {
    background-color: #2c3034;
    border-color: #495057;
    color: #fff;
}

[data-bs-theme="dark"] .btn-reset {
    background-color: #2c3034;
    border-color: #495057;
    color: #fff;
}

[data-bs-theme="dark"] .day-number {
    background-color: #495057;
    color: #fff;
}

body {
    font-family: 'Cairo', 'Inter', sans-serif;
    background-color: var(--background-color);
    color: var(--text-primary);
    min-height: 100vh;
}

/* RTL Support */
[dir="rtl"] {
    text-align: right;
}

[dir="rtl"] .dropdown-menu {
    text-align: right;
}

[dir="rtl"] .me-2 {
    margin-right: 0 !important;
    margin-left: 0.5rem !important;
}

[dir="rtl"] .ms-2 {
    margin-left: 0 !important;
    margin-right: 0.5rem !important;
}

[dir="rtl"] .float-end {
    float: left !important;
}

[dir="rtl"] .float-start {
    float: right !important;
}

/* Animated Background */
.bg-animated {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: -1;
    background:
        radial-gradient(circle at 15% 50%, rgba(79, 70, 229, 0.08), transparent 25%),
        radial-gradient(circle at 85% 30%, rgba(45, 212, 191, 0.08), transparent 25%);
}

.bg-gradient-info {
    background: var(--info-gradient) !important;
}

.bg-gradient-success {
    background: var(--success-gradient) !important;
}

.bg-gradient-warning {
    background: var(--warning-gradient) !important;
}

.bg-gradient-danger {
    background: var(--danger-gradient) !important;
}

.bg-gradient-dark {
    background: var(--dark-gradient) !important;
}

/* Header Section */
.page-header {
    background: var(--primary-gradient);
    padding: 1rem 0 4rem;
    color: white;
    border-radius: 0 0 40px 40px;
    margin-bottom: -3rem;
    position: relative;
    z-index: 10;
}

.header-content h1 {
    font-weight: 700;
    font-size: 2.5rem;
    margin-bottom: 0.5rem;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.header-content p {
    opacity: 0.9;
    font-size: 1.1rem;
}

/* Custom Cards */
.custom-card {
    background: var(--surface-color);
    border-radius: var(--border-radius);
    border: 1px solid rgba(255, 255, 255, 0.5);
    box-shadow: var(--shadow-md);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    backdrop-filter: blur(10px);
    overflow: hidden;
    height: 100%;
}

.custom-card:hover {
    transform: translateY(-5px);
    box-shadow: var(--shadow-lg);
}

/* Stats Cards */
.stats-icon-wrapper {
    width: 64px;
    height: 64px;
    border-radius: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.75rem;
    margin-bottom: 1rem;
}

.stats-primary .stats-icon-wrapper {
    background: rgba(79, 70, 229, 0.1);
    color: #4f46e5;
}

.stats-success .stats-icon-wrapper {
    background: rgba(16, 185, 129, 0.1);
    color: #10b981;
}

.stats-value {
    font-size: 2.25rem;
    font-weight: 800;
    background: var(--primary-gradient);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

/* Filter Section */
.filter-container {
    padding: 2rem;
}

.filter-title {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 1.5rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.form-floating>.form-control,
.form-floating>.form-select {
    border-radius: 12px;
    border: 1px solid #e5e7eb;
    background-color: #f9fafb;
}

.form-floating>.form-control:focus,
.form-floating>.form-select:focus {
    background-color: #fff;
    border-color: #818cf8;
    box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.1);
}

.btn-search {
    background: var(--primary-gradient);
    border: none;
    color: white;
    border-radius: 12px;
    font-weight: 600;
    padding: 1rem;
    transition: opacity 0.2s;
}

.btn-reset {
    background: white;
    border: 1px solid #e5e7eb;
    color: var(--text-secondary);
    border-radius: 12px;
    font-weight: 600;
    padding: 1rem;
}

.btn-search:hover {
    opacity: 0.9;
    color: white;
}

.btn-reset:hover {
    background: #f9fafb;
    color: var(--text-primary);
}

/* Table Styles */
.table-container {
    border-radius: var(--border-radius);
    overflow: hidden;
    margin-top: 2rem;
}

.table thead th {
    background-color: #f8fafc;
    color: var(--text-secondary);
    font-weight: 600;
    text-transform: uppercase;
    font-size: 0.8rem;
    letter-spacing: 0.05em;
    padding: 1rem;
    border-bottom: 2px solid #e2e8f0;
}

.table tbody td {
    padding: 1rem;
    vertical-align: middle;
    color: var(--text-primary);
    border-bottom: 1px solid #f1f5f9;
}

.table-hover tbody tr:hover {
    background-color: rgba(79, 70, 229, 0.02);
    transform: scale(1.001);
    transition: all 0.2s;
}

/* Status Badges */
.status-badge {
    padding: 0.5rem 1rem;
    border-radius: 9999px;
    font-size: 0.85rem;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}

.status-badge::before {
    content: '';
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background-color: currentColor;
}

.status-0 {
    background: #dcfce7;
    color: #166534;
}

/* Check-In */
.status-1 {
    background: #fee2e2;
    color: #991b1b;
}

/* Check-Out */
.status-2 {
    background: #ffedd5;
    color: #9a3412;
}

/* Break-Out */
.status-3 {
    background: #e0f2fe;
    color: #075985;
}

/* Break-In */
.status-15 {
    background: #f3f4f6;
    color: #4b5563;
}

/* Unknown */

/* Animation Keyframes */
@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.animate-fade-up {
    animation: fadeInUp 0.5s ease-out forwards;
}

.delay-100 {
    animation-delay: 0.1s;
}

.delay-200 {
    animation-delay: 0.2s;
}

.delay-300 {
    animation-delay: 0.3s;
}

/* Pagination */
.pagination .page-link {
    border-radius: 8px;
    margin: 0 4px;
    border: none;
    color: var(--text-secondary);
    font-weight: 600;
}

.pagination .page-item.active .page-link {
    background: var(--primary-gradient);
    color: white;
    box-shadow: 0 4px 6px rgba(99, 102, 241, 0.3);
}

/* Calendar Styles */
.day-cell {
    height: 100px;
    vertical-align: top;
    padding: 0.5rem;
    position: relative;
    transition: all 0.2s;
}

.day-cell:hover {
    transform: scale(1.02);
    z-index: 5;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.day-number {
    font-weight: 700;
    margin-bottom: 0.25rem;
    display: inline-block;
    width: 24px;
    height: 24px;
    text-align: center;
    line-height: 24px;
    border-radius: 50%;
    background: white;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

/* --- ZK Devices Legacy Styles (Merged) --- */

.device-card {
    background: white;
    border-radius: 15px;
    padding: 25px;
    margin-bottom: 20px;
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.08);
    transition: all 0.3s ease;
    border: 1px solid #e8eaf0;
}

.device-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 8px 20px rgba(102, 126, 234, 0.15);
    border-color: #667eea;
}

.device-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding-bottom: 15px;
    border-bottom: 2px solid #f0f2f5;
}

.device-name {
    font-size: 22px;
    font-weight: 700;
    color: #2d3748;
    display: flex;
    align-items: center;
    gap: 10px;
}

.device-name i {
    color: #667eea;
}

.device-status {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 14px;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 600;
}

.status-active {
    background: linear-gradient(135deg, #d4edda 0%, #c3e6cb 100%);
    color: #155724;
}

.status-inactive {
    background: linear-gradient(135deg, #f8d7da 0%, #f5c6cb 100%);
    color: #721c24;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    animation: pulse 2s infinite;
}

.status-active .status-dot {
    background: #28a745;
}

.status-inactive .status-dot {
    background: #dc3545;
}

@keyframes pulse {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.5;
    }
}

.device-info {
    color: #4a5568;
    font-size: 14px;
    margin-bottom: 20px;
    line-height: 1.8;
}

.device-info div {
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.device-info i {
    width: 20px;
    color: #667eea;
}

.device-actions {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
    gap: 10px;
}

.btn-action {
    padding: 10px 16px;
    border-radius: 8px;
    font-weight: 600;
    font-size: 13px;
    transition: all 0.2s ease;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

.btn-action:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.btn-action:active {
    transform: translateY(0);
}

.btn-action:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.stats-card {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border-radius: 15px;
    padding: 25px;
    text-align: center;
    margin-bottom: 20px;
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.3);
}

.stats-number {
    font-size: 42px;
    font-weight: 700;
    margin-bottom: 8px;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.stats-label {
    font-size: 14px;
    opacity: 0.95;
    font-weight: 500;
}

.loading-spinner {
    display: inline-block;
    width: 14px;
    height: 14px;
    border: 2px solid #f3f3f3;
    border-top: 2px solid currentColor;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

.batch-actions {
    background: white;
    border-radius: 15px;
    padding: 20px;
    margin-bottom: 25px;
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.08);
    border: 1px solid #e8eaf0;
}

/* Page Header Override/Merge */
.page-header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border-radius: 15px;
    padding: 30px;
    margin-bottom: 30px;
    box-shadow: 0 5px 20px rgba(102, 126, 234, 0.3);
}

.page-header h1 {
    margin: 0;
    font-size: 32px;
    font-weight: 700;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.page-header p {
    margin: 10px 0 0 0;
    opacity: 0.95;
    font-size: 16px;
}

.section-title {
    font-size: 24px;
    font-weight: 700;
    color: #2d3748;
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.section-title i {
    color: #667eea;
}

.no-devices {
    text-align: center;
    padding: 60px 20px;
    background: white;
    border-radius: 15px;
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.08);
}

.no-devices i {
    font-size: 64px;
    color: #cbd5e0;
    margin-bottom: 20px;
}

/* Welcome Banner (Index) */
.welcome-banner {
    background-color: #f8f9fa;
    /* Light mode default (Bootstrap bg-light) */
    color: var(--text-primary);
    transition: all 0.3s ease;
}

[data-bs-theme="dark"] .welcome-banner {
    background-color: var(--surface-color);
    /* Dark mode surface */
    color: var(--text-primary);
    border: 1px solid #373b3e;
}

/* =========================================
   Shared Layout Styles (From _layout.html)
   ========================================= */

/* Navbar Base */
.navbar {
    background: #2c3e50;
    padding: 0 1rem;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

.nav-list {
    list-style: none;
    display: flex;
    margin: 0;
    padding: 0;
}

.nav-item {
    position: relative;
}

.nav-link {
    display: block;
    color: #ecf0f1;
    text-decoration: none;
    padding: 1rem 1.5rem;
    font-weight: 500;
    transition: background 0.3s;
}

.nav-link:hover,
.nav-link:focus {
    background: #34495e;
}

.dropdown-item {
    position: relative;
}

.dropdown-link {
    display: block;
    padding: 0.4rem 1.5rem;
    color: #2c3e50;
    text-decoration: none;
    white-space: nowrap;
}

.dropdown-link:hover,
.dropdown-link:focus {
    background: #f1f5f9;
    color: #1a5fb4;
}

/* Second-level (nested) dropdown */
.dropdown-submenu {
    position: absolute;
    top: 0;
    left: 100%;
    background: white;
    list-style: none;
    min-width: 200px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    border-radius: 4px;
    opacity: 0;
    visibility: hidden;
    transform: translateX(-10px);
    transition: all 0.3s ease;
}

.dropdown-item:hover>.dropdown-submenu,
.dropdown-item:focus-within>.dropdown-submenu,
.dropdown-item.active>.dropdown-submenu {
    opacity: 1;
    visibility: visible;
    transform: translateX(0);
}

/* Arrow indicator for items with submenu */
.dropdown-link.has-submenu::after {
    content: "▸";
    float: right;
    font-size: 0.8em;
    margin-left: 0.5rem;
}

/* Desktop Nested Dropdowns */
@media (min-width: 769px) {
    .dropdown-menu .dropdown-item {
        position: relative;
    }

    .dropdown-menu .dropdown-submenu {
        display: none;
        position: absolute;
        left: 100%;
        top: -7px;
    }

    .dropdown-menu .dropdown-item:hover>.dropdown-submenu,
    .dropdown-menu .dropdown-submenu:hover {
        display: block;
    }

    /* Adjust submenu direction if it goes off-screen (simplified) */
    .dropdown-menu .dropdown-submenu-left {
        right: 100%;
        left: auto;
    }
}

@media (max-width: 768px) {
    .nav-list {
        flex-direction: column;
    }

    .dropdown-menu,
    .dropdown-submenu {
        position: static;
        box-shadow: none;
        opacity: 1;
        visibility: visible;
        transform: none;
        max-height: 0;
        overflow: hidden;
        transition: max-height 0.3s ease;
    }

    .nav-item.active>.dropdown-menu,
    .dropdown-item.active>.dropdown-submenu {
        max-height: 500px;
    }

    .dropdown-menu .dropdown-link {
        padding-left: 2.5rem;
    }

    .dropdown-submenu .dropdown-link {
        padding-left: 4rem;
    }
}

/* Dark Mode Overrides for Layout */
[data-bs-theme="dark"] .dropdown-menu {
    background-color: #343a40;
    color: #dee2e6;
    border-color: #495057;
}

[data-bs-theme="dark"] .dropdown-item {
    color: #dee2e6;
}

[data-bs-theme="dark"] .dropdown-item:hover {
    background-color: #495057;
    color: #fff;
}

[data-bs-theme="dark"] .list-group-item {
    background-color: #343a40;
    color: #dee2e6;
    border-color: #495057;
}

/* Utility Classes for Dark Mode */
.bg-surface {
    background-color: var(--surface-color) !important;
}

.bg-background {
    background-color: var(--background-color) !important;
}

.text-primary-theme {
    color: var(--text-primary) !important;
}

.text-secondary-theme {
    color: var(--text-secondary) !important;
}

/* Form Enhanced Card */
.form-enhanced-card {
    background-color: var(--surface-color);
    transition: all 0.3s ease;
}

.custom-card-body {
    background-color: var(--surface-color);
    color: var(--text-primary);
}

/* Ensure inputs in dark mode have correct background/text */
[data-bs-theme="dark"] .form-control,
[data-bs-theme="dark"] .form-select {
    background-color: #2c3034;
    border-color: #495057;
    color: #fff;
}

[data-bs-theme="dark"] .form-control:focus,
[data-bs-theme="dark"] .form-select:focus {
    background-color: #3b4248;
    border-color: #818cf8;
    color: #fff;
}

[data-bs-theme="dark"] .input-group-text {
    background-color: #343a40;
    border-color: #495057;
    color: #dee2e6;
}

background-color: #212529;
color: #fff;
border-color: #495057;
}

/* Fix Select2 in Dark Mode */
[data-bs-theme="dark"] .select2-container--default .select2-selection--single,
[data-bs-theme="dark"] .select2-dropdown {
    background-color: #212529 !important;
    color: #fff !important;
    border-color: #495057 !important;
}

/* Dark Mode for Nested Dropdowns */
[data-bs-theme="dark"] .dropdown-submenu {
    background-color: #343a40;
    color: #dee2e6;
    border-color: #495057;
}

[data-bs-theme="dark"] .dropdown-link {
    color: #dee2e6;
}

[data-bs-theme="dark"] .dropdown-link:hover,
[data-bs-theme="dark"] .dropdown-link:focus {
    background-color: #495057;
    color: #fff;
}

/* Select 2 Dark Theme Detailed */
html[data-bs-theme="dark"] .select2-container--default .select2-selection--single {
    background-color: #212529 !important;
    border-color: #495057;
}

html[data-bs-theme="dark"] .select2-container--default .select2-selection--single .select2-selection__rendered {
    color: #fff !important;
}

html[data-bs-theme="dark"] .select2-dropdown {
    background-color: #212529 !important;
    border-color: #495057;
}

html[data-bs-theme="dark"] .select2-container--default .select2-results__option[aria-selected=true] {
    background-color: #343a40 !important;
}

html[data-bs-theme="dark"] body {
    background-color: #212529;
    color: #f8f9fa;
}

html[data-bs-theme="dark"] .card {
    background-color: #2c3237;
    border-color: #495057;
}

html[data-bs-theme="dark"] .table {
    color: #f8f9fa;
    border-color: #495057;
}

/* Default (Light Mode) - Modern Gradient Navbar */
/* Default (Light Mode) - Modern Gradient Navbar (Main Header) */
.navbar.navbar-dark {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
}

/* Dark Mode - Old Dark (Bootstrap Default) */
html[data-bs-theme="dark"] .navbar.navbar-dark {
    background: #212529 !important;
    border-bottom: 1px solid #373b3e;
    box-shadow: none;
}

html[data-bs-theme="dark"] .navbar.navbar-dark .nav-link {
    color: rgba(255, 255, 255, 0.55);
}

html[data-bs-theme="dark"] .navbar.navbar-dark .nav-link:hover,
html[data-bs-theme="dark"] .navbar.navbar-dark .nav-link:focus,
html[data-bs-theme="dark"] .navbar.navbar-dark .nav-link.active {
    color: #fff;
    background: transparent;
}

/* Top Bar Nav (Header 2) Visibility Fixes */
.top-bar-nav .nav-link,
.top-bar-nav i,
.top-bar-nav .btn-link {
    color: #1a1a1a !important;
    font-weight: 500;
}

.top-bar-nav .nav-link:hover,
.top-bar-nav i:hover {
    color: #0d6efd !important;
}

html[data-bs-theme="dark"] .top-bar-nav {
    background: transparent !important;
}

html[data-bs-theme="dark"] .top-bar-nav .nav-link,
html[data-bs-theme="dark"] .top-bar-nav i,
html[data-bs-theme="dark"] .top-bar-nav .btn-link {
    color: #f8f9fa !important;
}

html[data-bs-theme="dark"] .top-bar-nav .nav-link:hover,
html[data-bs-theme="dark"] .top-bar-nav i:hover {
    color: #6ea8fe !important;
}

@media print {

    html,
    body {
        display: none;
    }
}