:root {
    --primary: #1a237e;
    --secondary: #ff6f00;
    --accent: #c62828;
    --bg-dark: #0f1117;
    --bg-card: #1a1d2e;
    --bg-card-hover: #232740;
    --text-primary: #e8eaf6;
    --text-secondary: #9fa8da;
    --border-subtle: rgba(255, 255, 255, 0.08);
    --gradient-primary: linear-gradient(135deg, #1a237e 0%, #283593 100%);
    --gradient-accent: linear-gradient(135deg, #ff6f00 0%, #ff8f00 100%);
    --shadow-card: 0 4px 24px rgba(0, 0, 0, 0.3);
    --skeleton: rgba(255, 255, 255, 0.05);
}

* {
    box-sizing: border-box;
}

html,
body {
    overflow-x: hidden;
    width: 100%;
    position: relative;
}

body {
    font-family: 'Inter', sans-serif;
    background: var(--bg-dark);
    color: var(--text-primary);
    min-height: 100vh;
    margin: 0;
}

/* ── Sidebar ── */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: 260px;
    height: 100vh;
    background: linear-gradient(180deg, #111327 0%, #0f1117 100%);
    border-right: 1px solid var(--border-subtle);
    padding: 1.5rem 0;
    z-index: 100;
    overflow-y: auto;
    transition: transform 0.3s ease;
}

.sidebar .brand {
    padding: 0 1.5rem 1.5rem;
    font-size: 1.25rem;
    font-weight: 700;
    color: #fff;
    border-bottom: 1px solid var(--border-subtle);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.sidebar .brand i {
    color: var(--secondary);
    font-size: 1.4rem;
}

.sidebar .nav-section {
    padding: 1rem 0.75rem;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-secondary);
    padding-bottom: 0.25rem;
}

.sidebar a {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.65rem 1.5rem;
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.9rem;
    transition: all 0.2s;
    border-radius: 0;
}

.sidebar a:hover,
.sidebar a.active {
    color: #fff;
    background: rgba(255, 255, 255, 0.06);
}

.sidebar a.active {
    border-left: 3px solid var(--secondary);
    padding-left: calc(1.5rem - 3px);
}

.sidebar a i {
    font-size: 1.1rem;
    width: 20px;
    text-align: center;
}

/* ── Glassmorphism & High-end Sidebar ── */
@media (min-width: 769px) {
    .sidebar {
        background: linear-gradient(180deg, rgba(17, 19, 39, 0.95) 0%, rgba(15, 17, 23, 0.98) 100%);
        backdrop-filter: blur(12px);
        -webkit-backdrop-filter: blur(12px);
    }
}

.sidebar-user {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--border-subtle);
    background: rgba(0, 0, 0, 0.2);
}

.sidebar-user .name {
    font-size: 0.85rem;
    font-weight: 600;
}

.sidebar-user .role {
    font-size: 0.7rem;
    color: var(--text-secondary);
    text-transform: uppercase;
}

/* ── Main content ── */
.main {
    margin-left: 260px;
    padding: 2rem;
    min-height: 100vh;
    overflow-x: hidden;
}

/* ── Cards ── */
.card-dark {
    background: var(--bg-card) !important;
    color: var(--text-primary) !important;
    border: 1px solid var(--border-subtle);
    border-radius: 12px;
    padding: 1.5rem;
    box-shadow: var(--shadow-card);
    transition: transform 0.2s, box-shadow 0.2s;
}

.card-dark:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
}

.stat-card {
    text-align: center;
    padding: 1.25rem;
}

.stat-card .stat-value {
    font-size: 2rem;
    font-weight: 700;
    background: var(--gradient-accent);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.stat-card .stat-label {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-top: 0.25rem;
}

/* ── Buttons ── */
.btn-primary-glow {
    background: var(--gradient-primary);
    color: #fff;
    border: none;
    padding: 0.6rem 1.5rem;
    border-radius: 8px;
    font-weight: 600;
    transition: all 0.2s;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}

.btn-primary-glow:hover {
    box-shadow: 0 4px 20px rgba(26, 35, 126, 0.5);
    transform: translateY(-1px);
    color: #fff;
}

.btn-accent {
    background: var(--gradient-accent);
    color: #fff;
    border: none;
    padding: 0.6rem 1.5rem;
    border-radius: 8px;
    font-weight: 600;
    transition: all 0.2s;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}

.btn-accent:hover {
    box-shadow: 0 4px 20px rgba(255, 111, 0, 0.4);
    transform: translateY(-1px);
    color: #fff;
}

/* ── Forms ── */
.form-control,
.form-select {
    background: rgba(255, 255, 255, 0.08); /* Slightly more opaque */
    border: 1px solid var(--border-subtle);
    color: var(--text-primary);
    border-radius: 8px;
}

.form-select option {
    background-color: #1a1d2e; /* Solid background matching var(--bg-card) */
    color: #e8eaf6;            /* Light text matching var(--text-primary) */
}

.form-control:focus,
.form-select:focus {
    background: rgba(255, 255, 255, 0.12);
    border-color: var(--secondary);
    color: var(--text-primary);
    box-shadow: 0 0 0 0.2rem rgba(255, 111, 0, 0.15);
}

.form-label {
    color: var(--text-secondary);
    font-size: 0.85rem;
    font-weight: 500;
}

/* ── Tables ── */
.table-dark-custom {
    color: var(--text-primary) !important;
    --bs-table-bg: transparent !important;
    --bs-table-color: var(--text-primary) !important;
    --bs-table-striped-bg: rgba(255, 255, 255, 0.02) !important;
    background-color: transparent !important;
}

.table-dark-custom th {
    color: var(--text-secondary) !important;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    border-bottom: 1px solid var(--border-subtle);
    padding: 0.75rem;
}

.table-dark-custom td {
    border-bottom: 1px solid var(--border-subtle);
    padding: 0.75rem;
    vertical-align: middle;
    color: var(--text-primary) !important;
}

.table-dark-custom tr:hover td {
    background: rgba(255, 255, 255, 0.03);
}

.bg-dark-audit {
    background: #232740 !important; /* Explicitly darker hex just in case */
    border: 1px solid var(--border-subtle);
}

.text-white-80 {
    color: rgba(255, 255, 255, 0.8) !important;
}

/* ── Badges ── */
.badge-success {
    background: rgba(76, 175, 80, 0.15);
    color: #81c784;
}

.badge-warning {
    background: rgba(255, 152, 0, 0.15);
    color: #ffb74d;
}

.badge-danger {
    background: rgba(244, 67, 54, 0.15);
    color: #ef5350;
}

.badge-info {
    background: rgba(33, 150, 243, 0.15);
    color: #64b5f6;
}

/* ── Page header ── */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.page-header h1 {
    font-size: 1.5rem;
    font-weight: 700;
    margin: 0;
}

/* ── Alerts ── */
.alert {
    border-radius: 8px;
    border: none;
}

/* ── Premium Aesthetics & Animations ── */
.skeleton {
    background: linear-gradient(90deg, var(--skeleton) 25%, rgba(255, 255, 255, 0.08) 50%, var(--skeleton) 75%);
    background-size: 200% 100%;
    animation: skeleton-loading 1.5s infinite;
    border-radius: 4px;
    display: inline-block;
    min-height: 1em;
}

@keyframes skeleton-loading {
    0% {
        background-position: 200% 0;
    }

    100% {
        background-position: -200% 0;
    }
}

/* Tap feedback */
@media (max-width: 768px) {

    .card-dark,
    .btn-primary-glow,
    .btn-accent,
    .sidebar a {
        -webkit-tap-highlight-color: transparent;
    }

    .card-dark:active {
        transform: scale(0.98);
        transition: transform 0.1s ease;
    }
}

/* Smooth page transitions for HTMX */
.htmx-settling {
    opacity: 0;
}

.htmx-request {
    filter: grayscale(100%) opacity(0.8);
    transition: all 0.3s ease;
}

/* ── Bottom Navigation Submenu ── */
.mobile-submenu {
    position: fixed;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: rgba(26, 29, 46, 0.98);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--border-subtle);
    border-radius: 16px;
    padding: 0.5rem;
    z-index: 1001;
    display: none;
    flex-direction: column;
    min-width: 200px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.6);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    opacity: 0;
}

.mobile-submenu.show {
    display: flex;
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

.mobile-submenu a {
    padding: 0.75rem 1rem;
    color: var(--text-primary);
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: 0.9rem;
    border-radius: 10px;
}

.mobile-submenu a:active {
    background: rgba(255, 255, 255, 0.08);
}

.mobile-submenu-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 1000;
    display: none;
    backdrop-filter: blur(4px);
}

.mobile-submenu-overlay.show {
    display: block;
}

/* ── Mobile ── */
.sidebar-toggle {
    display: none;
    position: fixed;
    top: 1rem;
    left: 1rem;
    z-index: 200;
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    color: #fff;
    padding: 0.5rem 0.75rem;
    border-radius: 8px;
    cursor: pointer;
}

@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
        background: rgba(15, 17, 23, 0.98);
        backdrop-filter: blur(15px);
        -webkit-backdrop-filter: blur(15px);
        width: 280px;
        box-shadow: 10px 0 30px rgba(0, 0, 0, 0.5);
    }

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

    .main {
        margin-left: 0;
        padding: 1rem;
        padding-bottom: 5rem;
        /* Space for bottom nav */
    }

    .sidebar-toggle {
        display: block;
    }

    .page-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 1rem;
    }

    .page-header .btn-primary-glow,
    .page-header .btn-accent {
        width: 100%;
        justify-content: center;
    }
}

/* ── Bottom Navigation ── */
.mobile-bottom-nav {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 65px;
    background: rgba(26, 29, 46, 0.98);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-top: 1px solid var(--border-subtle);
    z-index: 2000;
    justify-content: space-around;
    align-items: center;
    padding-bottom: env(safe-area-inset-bottom);
}

.mobile-bottom-nav a {
    color: var(--text-secondary);
    text-decoration: none;
    display: flex;
    flex-direction: column;
    align-items: center;
    font-size: 0.7rem;
    gap: 2px;
    transition: color 0.2s;
}

.mobile-bottom-nav a.active {
    color: var(--secondary);
}

.mobile-bottom-nav a i {
    font-size: 1.4rem;
}

@media (max-width: 768px) {
    .mobile-bottom-nav {
        display: flex !important;
        bottom: 0 !important;
    }
}

/* ── Floating Action Button (FAB) ── */
.fab {
    position: fixed;
    bottom: 85px;
    right: 20px;
    width: 56px;
    height: 56px;
    background: var(--gradient-accent);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    box-shadow: 0 4px 15px rgba(255, 111, 0, 0.4);
    z-index: 999;
    transition: transform 0.2s;
    text-decoration: none;
}

.fab:active {
    transform: scale(0.9);
}

@media (min-width: 769px) {
    .fab {
        display: none;
    }
}

/* ── Mobile Header ── */
.mobile-header {
    display: none;
    position: sticky;
    top: 0;
    left: 0;
    right: 0;
    height: 60px;
    background: var(--bg-dark);
    border-bottom: 1px solid var(--border-subtle);
    z-index: 99;
    align-items: center;
    padding: 0 1rem;
    justify-content: space-between;
}

@media (max-width: 768px) {
    .mobile-header {
        display: flex;
    }

    .sidebar-toggle {
        position: static;
    }
}

/* ── Toast Notifications ── */
.toast-container {
    position: fixed;
    bottom: 100px;
    right: 20px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.custom-toast {
    background: rgba(30, 34, 55, 0.95);
    backdrop-filter: blur(10px);
    color: #fff;
    padding: 12px 24px;
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    display: flex;
    align-items: center;
    gap: 12px;
    animation: toast-in 0.3s ease forwards;
    min-width: 280px;
}

.custom-toast.success i {
    color: #4caf50;
}

.custom-toast.error i {
    color: #f44336;
}

.custom-toast.info i {
    color: #2196f3;
}

@keyframes toast-in {
    from {
        transform: translateX(100%);
        opacity: 0;
    }

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

@keyframes toast-out {
    from {
        transform: translateX(0);
        opacity: 1;
    }

    to {
        transform: translateX(100%);
        opacity: 0;
    }
}
