:root {
    --primary-color: #4f46e5;
    /* Indigo 600 */
    --primary-hover: #4338ca;
    /* Indigo 700 */
    --secondary-color: #64748b;
    /* Slate 500 */
    --success-color: #10b981;
    /* Emerald 500 */
    --warning-color: #f59e0b;
    /* Amber 500 */
    --danger-color: #ef4444;
    /* Red 500 */
    --background-color: #f8fafc;
    /* Slate 50 */
    --card-bg: #ffffff;
    --text-main: #1e293b;
    /* Slate 800 */
    --text-muted: #64748b;
    /* Slate 500 */
    --border-color: #e2e8f0;
    /* Slate 200 */
    --sidebar-width: 260px;
    --collapsed-width: 70px;
    --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);
    --radius-md: 0.5rem;
    --radius-lg: 0.75rem;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    background-color: var(--background-color);
    color: var(--text-main);
    line-height: 1.5;
}

a {
    text-decoration: none;
    color: inherit;
}

/* Layout */
.app-container {
    min-height: 100vh;
}

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    background-color: var(--card-bg);
    border-right: 1px solid var(--border-color);
    position: fixed;
    height: 100vh;
    display: flex;
    flex-direction: column;
    z-index: 10;

    /* Off-Canvas Default for ALL screens */
    transform: translateX(-100%);
    transition: transform 0.3s ease-in-out;
}

/* Open State */
body.sidebar-open .sidebar {
    transform: translateX(0);
}

body.sidebar-open .sidebar-overlay {
    display: block;
}

/* Nav Text always visible inside sidebar */
.sidebar .nav-text {
    display: inline;
}

/* Main Content always full width (since sidebar is overlay) */
.main-content {
    margin-left: 0;
    width: 100%;
    transition: margin-left 0.3s ease;
}

/* Desktop: Push Content when Sidebar Open */
@media (min-width: 769px) {
    body.sidebar-open .main-content {
        margin-left: var(--sidebar-width);
    }

    /* Disable overlay on desktop so content is interactive */
    body.sidebar-open .sidebar-overlay {
        display: none;
    }
}

/* Menu Button always visible */
.menu-btn {
    display: block;
    background: none;
    border: none;
    font-size: 1.25rem;
    cursor: pointer;
    color: var(--text-main);
    margin-right: 1rem;
    padding: 0.5rem;
}

/* Close Button always visible inside sidebar */
.close-sidebar-btn {
    display: block;
    background: none;
    border: none;
    font-size: 1.25rem;
    color: var(--text-muted);
    cursor: pointer;
    margin-left: auto;
}

/* Overlay */
.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 9;
}

.sidebar-header {
    height: var(--header-height);
    display: flex;
    align-items: center;
    padding: 0 1.5rem;
    border-bottom: 1px solid var(--border-color);
    font-weight: 700;
    font-size: 1.25rem;
    color: var(--primary-color);
}

.sidebar-nav {
    padding: 1.5rem 1rem;
    flex: 1;
    overflow-y: auto;
}

/* Custom scrollbar for sidebar */
.sidebar-nav::-webkit-scrollbar {
    width: 6px;
}

.sidebar-nav::-webkit-scrollbar-track {
    background: transparent;
}

.sidebar-nav::-webkit-scrollbar-thumb {
    background: #e2e8f0;
    border-radius: 10px;
}

.sidebar-nav::-webkit-scrollbar-thumb:hover {
    background: #cbd5e1;
}

.nav-item {
    display: flex;
    align-items: center;
    padding: 0.75rem 1rem;
    color: var(--text-muted);
    border-radius: var(--radius-md);
    margin-bottom: 0.25rem;
    transition: all 0.2s;
    font-weight: 500;
}

.nav-item:hover,
.nav-item.active {
    background-color: #eef2ff;
    /* Indigo 50 */
    color: var(--primary-color);
}

.nav-icon {
    margin-right: 0.75rem;
    width: 20px;
    text-align: center;
}

/* Main Content (styles moved to top) */

.top-header {
    height: var(--header-height);
    background-color: var(--card-bg);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 2rem;
    position: sticky;
    top: 0;
    z-index: 5;
}

.page-content {
    padding: 2rem;
}

/* Cards */
.card {
    background-color: var(--card-bg);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-color);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.card-title {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--text-main);
}

/* Stats Grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.stat-card {
    background: var(--card-bg);
    padding: 1.5rem;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-color);
    display: flex;
    align-items: center;
}

.stat-icon {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    margin-right: 1rem;
}

.stat-icon.blue {
    background: #e0e7ff;
    color: var(--primary-color);
}

.stat-icon.green {
    background: #dcfce7;
    color: var(--success-color);
}

.stat-icon.orange {
    background: #fef3c7;
    color: var(--warning-color);
}

.stat-icon.red {
    background: #fee2e2;
    color: var(--danger-color);
}

.stat-info h3 {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 0.25rem;
}

.stat-info p {
    color: var(--text-muted);
    font-size: 0.875rem;
}

/* Tables */
.table-container {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
}

th {
    background-color: #f8fafc;
    padding: 0.75rem 1rem;
    font-weight: 600;
    color: var(--text-muted);
    font-size: 0.875rem;
    border-bottom: 1px solid var(--border-color);
}

td {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border-color);
    color: var(--text-main);
    font-size: 0.925rem;
}

tr:last-child td {
    border-bottom: none;
}

/* Badges */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 0.25rem 0.625rem;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 600;
}

.badge-success {
    background: #dcfce7;
    color: #166534;
}

.badge-warning {
    background: #fef3c7;
    color: #92400e;
}

.badge-danger {
    background: #fee2e2;
    color: #991b1b;
}

.badge-neutral {
    background: #f1f5f9;
    color: #475569;
}

/* Category Stats Card */
.category-card {
    padding: 1.25rem;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    height: 100%;
}

.category-header {
    display: flex;
    align-items: center;
    margin-bottom: 1rem;
    width: 100%;
}

.category-icon {
    width: 40px;
    height: 40px;
    font-size: 1.25rem;
    margin-right: 0.75rem;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #e0e7ff;
    color: var(--primary-color);
}

.category-title {
    font-size: 1.1rem;
    font-weight: 600;
    margin: 0;
    color: var(--text-main);
}

.category-grid {
    width: 100%;
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 0.5rem;
    text-align: center;
}

.count-pill {
    padding: 0.5rem;
    border-radius: 0.5rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.count-pill.total {
    background: #f8fafc;
}

.count-pill.assigned {
    background: #e0e7ff;
}

.count-pill.available {
    background: #dcfce7;
}

.count-value {
    font-size: 1.25rem;
    font-weight: 700;
    line-height: 1.2;
}

.count-label {
    font-size: 0.7rem;
    text-transform: uppercase;
    font-weight: 600;
    margin-top: 2px;
}

/* Utility Classes */
.text-left {
    text-align: left !important;
}

.text-center {
    text-align: center !important;
}

.text-right {
    text-align: right !important;
}

.w-full {
    width: 100%;
}

.mt-1 {
    margin-top: 0.25rem;
}

.mt-2 {
    margin-top: 0.5rem;
}

.mt-4 {
    margin-top: 1rem;
}

.mb-1 {
    margin-bottom: 0.25rem;
}

.mb-2 {
    margin-bottom: 0.5rem;
}

.mb-4 {
    margin-bottom: 1rem;
}

/* Text Colors */
.text-primary {
    color: var(--primary-color);
}

.text-success {
    color: #166534;
}

.text-muted-upper {
    color: var(--text-muted);
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.5rem 1rem;
    border-radius: var(--radius-md);
    font-weight: 500;
    font-size: 0.875rem;
    cursor: pointer;
    transition: all 0.2s;
    border: 1px solid transparent;
    gap: 0.5rem;
    line-height: normal;
    text-align: center;
    white-space: nowrap;
    user-select: none;
    height: 40px;
    /* Standardize height */
}

.btn:active {
    transform: translateY(1px);
}

.btn-primary {
    background-color: var(--primary-color);
    color: white;
}

.btn-primary:hover {
    background-color: var(--primary-hover);
    box-shadow: 0 4px 12px rgba(79, 70, 229, 0.2);
}

.btn-warning {
    background-color: var(--warning-color);
    color: #92400e;
}

.btn-warning:hover {
    background-color: #d97706;
}

.btn-danger {
    background-color: var(--danger-color);
    color: white;
}

.btn-danger:hover {
    background-color: #dc2626;
}

.btn-success {
    background-color: var(--success-color);
    color: white;
}

.btn-success:hover {
    background-color: #059669;
}

.btn-secondary {
    background-color: var(--secondary-color);
    color: white;
}

.btn-secondary:hover {
    background-color: #475569;
}

.btn-outline {
    background-color: transparent;
    border-color: var(--border-color);
    color: var(--text-main);
}

.btn-outline:hover {
    background-color: #f8fafc;
    border-color: #cbd5e1;
}

.btn-sm {
    padding: 0 0.75rem;
    font-size: 0.75rem;
    height: 32px;
    /* Uniform small height */
    border-radius: 6px;
}

/* Forms */
.form-group {
    margin-bottom: 1rem;
}

.form-label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    font-size: 0.875rem;
    color: var(--text-main);
}

.form-control {
    width: 100%;
    padding: 0.625rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    font-size: 0.925rem;
    transition: border-color 0.2s;
}

.form-control:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

/* Utilities */
.flex {
    display: flex;
}

.items-center {
    align-items: center;
}

.justify-between {
    justify-content: space-between;
}

.gap-2 {
    gap: 0.5rem;
}

.mb-4 {
    margin-bottom: 1rem;
}

.text-right {
    text-align: right;
}

.text-center {
    text-align: center;
}

/* ============================================================
   MOBILE RESPONSIVE  ≤ 768px
   ============================================================ */
@media (max-width: 768px) {

    /* --- Stats grid: single column --- */
    .stats-grid {
        grid-template-columns: 1fr;
        gap: 1rem;
        margin-bottom: 1rem;
    }

    /* --- Page content: tighter padding --- */
    .page-content {
        padding: 1rem 0.75rem;
    }

    /* --- Top header: compact, hide username text --- */
    .top-header {
        padding: 0 0.75rem;
    }

    .top-header .user-profile span {
        display: none;
        /* hide name + role text, keep avatar */
    }

    /* --- Notification dropdown: full width on mobile --- */
    .notif-dropdown {
        width: calc(100vw - 1.5rem);
        right: -0.5rem;
    }

    /* --- Card header: stack title + buttons vertically --- */
    .card-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.75rem;
    }

    .card-header>*:last-child {
        width: 100%;
    }

    /* --- Button rows: wrap and stretch full width --- */
    .btn-group,
    .action-buttons,
    [style*="display:flex"][style*="gap"],
    .flex.gap-2 {
        flex-wrap: wrap;
    }

    /* Full-width primary action buttons inside card headers */
    .card-header .btn {
        flex: 1 1 auto;
        justify-content: center;
        text-align: center;
    }

    /* Inline action buttons (edit/delete in table rows) stay small */
    td .btn,
    td .btn-sm {
        flex: none;
    }

    /* --- Tables: horizontal scroll --- */
    .table-container {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        border-radius: var(--radius-md);
    }

    table {
        min-width: 540px;
    }

    th,
    td {
        padding: 0.6rem 0.75rem;
        font-size: 0.85rem;
        white-space: nowrap;
    }

    /* --- Cards: less padding --- */
    .card {
        padding: 1rem;
    }

    /* --- Form grids → single column --- */
    .form-grid,
    .grid-2,
    .grid-3,
    [style*="grid-template-columns"] {
        grid-template-columns: 1fr !important;
    }

    /* --- Category grid stays 3-col (small but fine) --- */
    .category-grid {
        grid-template-columns: 1fr 1fr 1fr;
    }

    /* --- Modals: full width --- */
    .modal-content,
    [id$="Modal"]>div,
    .modal>.card {
        width: 95vw !important;
        max-width: 95vw !important;
        margin: 0.5rem auto !important;
        padding: 1rem !important;
    }

    /* --- Search/filter bar: stack vertically --- */
    .filter-bar,
    .search-bar,
    [style*="display:flex"][style*="align-items:center"][style*="gap"] {
        flex-wrap: wrap;
        gap: 0.5rem !important;
    }

    .filter-bar input,
    .filter-bar select,
    .search-bar input,
    .search-bar select {
        width: 100%;
    }

    /* --- Inline icon-only buttons: ensure tappable size --- */
    .btn-sm {
        padding: 0.35rem 0.6rem;
        min-width: 32px;
        min-height: 32px;
    }

    /* --- Session warning: full bottom bar --- */
    #session-warning {
        left: 0.5rem;
        right: 0.5rem;
        max-width: none;
    }

    /* --- Filter bar: selects go full width --- */
    #filterForm {
        flex-wrap: wrap;
        width: 100%;
    }

    #filterForm select {
        width: 100% !important;
        flex: 1 1 auto;
    }

    /* --- Inline 2-col grids inside form-groups → 1 col --- */
    .form-group div[style*="grid-template-columns: 1fr 1fr"],
    .form-group div[style*="grid-template-columns:1fr 1fr"] {
        grid-template-columns: 1fr !important;
    }

    /* --- Asset tag input + generate button: stack --- */
    .form-group div[style*="display: flex"][style*="gap: 10px"] {
        flex-wrap: wrap;
    }

    .form-group div[style*="display: flex"][style*="gap: 10px"] input,
    .form-group div[style*="display: flex"][style*="gap: 10px"] button {
        width: 100%;
    }

    /* --- CSV import: truncate file input label --- */
    input[type="file"] {
        max-width: 140px;
        font-size: 0.75rem;
    }

    /* --- Page title in header shrink --- */
    .card-title {
        font-size: 0.95rem;
    }
}