:root {
    --sidebar-width: 236px;
    --sidebar-collapsed-width: 68px;
    --navbar-height: 54px;
    --erp-primary: #2563eb;
    --erp-primary-dark: #1d4ed8;
    --erp-primary-soft: rgba(37, 99, 235, 0.1);
    --erp-bg: #f4f6f9;
    --erp-surface: #ffffff;
    --erp-surface-alt: #f8fafc;
    --erp-border: #e2e8f0;
    --erp-text: #0f172a;
    --erp-muted: #64748b;
    --erp-shadow: 0 1px 3px rgba(15, 23, 42, 0.05), 0 1px 2px rgba(15, 23, 42, 0.03);
}

[data-bs-theme="dark"] {
    --erp-bg: #090e1a;
    --erp-surface: #111827;
    --erp-surface-alt: #1e293b;
    --erp-border: #1f2937;
    --erp-text: #f1f5f9;
    --erp-muted: #94a3b8;
    --erp-primary-soft: rgba(59, 130, 246, 0.18);
    --erp-shadow: 0 1px 3px rgba(0, 0, 0, 0.35);
}

html, body {
    overflow-x: hidden;
    background-color: var(--erp-bg);
    color: var(--erp-text);
    font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    font-size: 14px;
    -webkit-font-smoothing: antialiased;
}

.tabular-nums {
    font-variant-numeric: tabular-nums;
}

.auth-body {
    background: radial-gradient(circle at top right, #1e40af 0%, #0f172a 60%, #020617 100%);
}

.auth-logo {
    width: 56px;
    height: 56px;
}

/* App Shell */
.app-wrapper {
    display: flex;
    min-height: 100vh;
}

.app-sidebar {
    width: var(--sidebar-width);
    background: #0f172a;
    color: #cbd5e1;
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 1040;
    display: flex;
    flex-direction: column;
    transition: width 0.2s ease, transform 0.25s ease;
    border-right: 1px solid rgba(255, 255, 255, 0.07);
}

.app-sidebar .sidebar-brand {
    height: var(--navbar-height);
    display: flex;
    align-items: center;
    padding: 0 0.9rem;
    gap: 0.65rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.07);
    font-weight: 700;
    font-size: 0.92rem;
    color: #fff;
    white-space: nowrap;
    overflow: hidden;
}

.app-sidebar .brand-badge {
    width: 30px;
    height: 30px;
    border-radius: 8px;
    background: linear-gradient(135deg, #3b82f6, #1d4ed8);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    color: #fff;
}

.app-sidebar .sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: 0.55rem 0.5rem 1.5rem;
    scrollbar-width: thin;
}

.sidebar-section-title {
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: #64748b;
    padding: 0.65rem 0.7rem 0.2rem;
    font-weight: 700;
    white-space: nowrap;
}

.app-sidebar .nav-link {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    color: #94a3b8;
    padding: 0.46rem 0.7rem;
    border-radius: 7px;
    font-size: 0.84rem;
    font-weight: 500;
    margin-bottom: 1px;
    white-space: nowrap;
    transition: background-color 0.15s ease, color 0.15s ease;
}

.app-sidebar .nav-link i {
    font-size: 1rem;
    min-width: 20px;
    text-align: center;
}

.app-sidebar .nav-link:hover {
    background: rgba(255, 255, 255, 0.07);
    color: #f8fafc;
}

.app-sidebar .nav-link.active {
    background: linear-gradient(90deg, #2563eb 0%, #1d4ed8 100%);
    color: #ffffff;
    font-weight: 600;
    box-shadow: 0 2px 6px rgba(37, 99, 235, 0.35);
}

.app-main {
    flex: 1;
    margin-left: var(--sidebar-width);
    min-width: 0;
    display: flex;
    flex-direction: column;
    transition: margin-left 0.2s ease;
}

/* Desktop Collapsed Sidebar */
@media (min-width: 992px) {
    body.sidebar-collapsed .app-sidebar {
        width: var(--sidebar-collapsed-width);
    }
    body.sidebar-collapsed .app-sidebar .brand-text,
    body.sidebar-collapsed .app-sidebar .nav-text,
    body.sidebar-collapsed .app-sidebar .sidebar-section-title {
        display: none;
    }
    body.sidebar-collapsed .app-sidebar .sidebar-brand {
        justify-content: center;
        padding: 0;
    }
    body.sidebar-collapsed .app-sidebar .nav-link {
        justify-content: center;
        padding: 0.55rem;
    }
    body.sidebar-collapsed .app-main {
        margin-left: var(--sidebar-collapsed-width);
    }
}

/* Mobile & Tablet Sidebar Drawer */
@media (max-width: 991.98px) {
    .app-sidebar {
        transform: translateX(-100%);
        width: 256px;
    }
    body.sidebar-mobile-open .app-sidebar {
        transform: translateX(0);
    }
    .app-main {
        margin-left: 0;
        padding-bottom: 64px; /* space for mobile bottom nav */
    }
    .sidebar-backdrop {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(15, 23, 42, 0.55);
        backdrop-filter: blur(2px);
        z-index: 1035;
    }
    body.sidebar-mobile-open .sidebar-backdrop {
        display: block;
    }
}

/* Top Navbar */
.app-navbar {
    height: var(--navbar-height);
    background: var(--erp-surface);
    border-bottom: 1px solid var(--erp-border);
    position: sticky;
    top: 0;
    z-index: 1020;
    padding: 0 1rem;
}

.app-content {
    flex: 1;
    padding: 1rem 1.25rem;
}

@media (max-width: 575.98px) {
    .app-content {
        padding: 0.75rem;
    }
    .app-navbar {
        padding: 0 0.65rem;
    }
}

/* Cards & Tables */
.card {
    background-color: var(--erp-surface);
    border: 1px solid var(--erp-border);
    border-radius: 10px;
    box-shadow: var(--erp-shadow);
}

.card-header {
    border-bottom: 1px solid var(--erp-border);
    padding: 0.65rem 0.95rem;
    font-size: 0.86rem;
}

/* Enterprise KPI Cards */
.kpi-card {
    border: 1px solid var(--erp-border);
    border-radius: 10px;
    background: var(--erp-surface);
    padding: 0.85rem 1rem;
    box-shadow: var(--erp-shadow);
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

.kpi-top {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 0.5rem;
}

.kpi-label {
    font-size: 0.74rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--erp-muted);
}

.kpi-value {
    font-size: 1.35rem;
    font-weight: 700;
    line-height: 1.2;
    margin-top: 0.2rem;
    font-variant-numeric: tabular-nums;
}

.kpi-icon {
    width: 34px;
    height: 34px;
    border-radius: 8px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    flex-shrink: 0;
}

.kpi-sub {
    margin-top: 0.55rem;
    padding-top: 0.45rem;
    border-top: 1px dashed var(--erp-border);
    font-size: 0.76rem;
    color: var(--erp-muted);
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    gap: 0.35rem;
}

/* Compact Attendance Strip */
.att-strip {
    display: grid;
    grid-template-columns: repeat(6, minmax(0, 1fr));
    gap: 0.5rem;
}

@media (max-width: 991.98px) {
    .att-strip {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }
}

@media (max-width: 575.98px) {
    .att-strip {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

.att-pill-card {
    background: var(--erp-surface);
    border: 1px solid var(--erp-border);
    border-left-width: 3px;
    border-radius: 8px;
    padding: 0.5rem 0.7rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: var(--erp-shadow);
}

.att-pill-card .lbl {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--erp-muted);
}

.att-pill-card .val {
    font-size: 1.05rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

/* Quick Action Bar */
.quick-action-btn {
    background: var(--erp-surface);
    border: 1px solid var(--erp-border);
    color: var(--erp-text);
    font-size: 0.8rem;
    font-weight: 600;
    padding: 0.36rem 0.7rem;
    border-radius: 7px;
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    text-decoration: none;
    transition: all 0.12s ease;
}

.quick-action-btn:hover {
    background: var(--erp-surface-alt);
    border-color: var(--erp-primary);
    color: var(--erp-primary);
}

.quick-action-btn.primary {
    background: var(--erp-primary);
    border-color: var(--erp-primary);
    color: #fff;
}

.quick-action-btn.primary:hover {
    background: var(--erp-primary-dark);
    color: #fff;
}

/* Compact Flash Alert */
.erp-flash {
    padding: 0.5rem 0.85rem;
    font-size: 0.85rem;
    border-radius: 8px;
    margin-bottom: 0.75rem;
}

/* Tables */
.table {
    font-size: 0.85rem;
}

.table > thead th {
    font-size: 0.74rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--erp-muted);
    font-weight: 700;
    background: var(--erp-surface-alt);
    padding-top: 0.55rem;
    padding-bottom: 0.55rem;
}

.table-sticky thead th {
    position: sticky;
    top: 0;
    z-index: 2;
    background: var(--erp-surface-alt);
    border-bottom-width: 1px;
}

/* Mobile Bottom Nav */
.mobile-bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 58px;
    background: var(--erp-surface);
    border-top: 1px solid var(--erp-border);
    display: flex;
    justify-content: space-around;
    align-items: center;
    z-index: 1030;
    box-shadow: 0 -2px 10px rgba(15, 23, 42, 0.06);
}

.mobile-bottom-nav a {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    color: var(--erp-muted);
    font-size: 0.68rem;
    font-weight: 600;
    gap: 2px;
    padding: 4px 0;
}

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

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

/* Attendance Touch Buttons */
.att-btn-group {
    display: flex;
    flex-wrap: wrap;
    gap: 0.3rem;
}

.att-btn {
    border: 1px solid var(--erp-border);
    background: var(--erp-surface);
    color: var(--erp-text);
    padding: 0.38rem 0.6rem;
    border-radius: 7px;
    font-size: 0.78rem;
    font-weight: 600;
    cursor: pointer;
    min-height: 34px;
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    transition: all 0.12s ease;
}

@media (max-width: 767.98px) {
    .att-btn {
        min-height: 42px;
        flex: 1 1 calc(33% - 0.3rem);
        justify-content: center;
    }
}

.att-btn[data-status="Present"].active { background: #16a34a; border-color: #16a34a; color: #fff; }
.att-btn[data-status="Absent"].active { background: #dc2626; border-color: #dc2626; color: #fff; }
.att-btn[data-status="Half Day"].active { background: #ea580c; border-color: #ea580c; color: #fff; }
.att-btn[data-status="Paid Leave"].active { background: #2563eb; border-color: #2563eb; color: #fff; }
.att-btn[data-status="Unpaid Leave"].active { background: #0284c7; border-color: #0284c7; color: #fff; }
.att-btn[data-status="Weekly Off"].active { background: #475569; border-color: #475569; color: #fff; }
.att-btn[data-status="Holiday"].active { background: #7c3aed; border-color: #7c3aed; color: #fff; }
.att-btn[data-status="Not Marked"].active { background: #64748b; border-color: #64748b; color: #fff; }

/* Calendar Attendance Cells */
.cal-grid {
    display: grid;
    grid-template-columns: repeat(7, minmax(0, 1fr));
    gap: 5px;
}

.cal-day-header {
    font-size: 0.72rem;
    font-weight: 700;
    text-align: center;
    color: var(--erp-muted);
    padding: 3px 0;
}

.cal-cell {
    border: 1px solid var(--erp-border);
    border-radius: 8px;
    padding: 0.4rem;
    min-height: 68px;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    transition: transform 0.1s ease, box-shadow 0.1s ease;
}

@media (max-width: 575.98px) {
    .cal-cell {
        min-height: 54px;
        padding: 0.28rem;
        font-size: 0.78rem;
    }
}

.cal-cell:hover:not(.cal-empty):not(.cal-future) {
    transform: translateY(-1px);
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.08);
}

.cal-cell.cal-empty { border: none; background: transparent; cursor: default; }
.cal-cell.cal-future { opacity: 0.45; cursor: not-allowed; }
.cal-cell.cal-locked { box-shadow: inset 0 0 0 2px #f59e0b; }

.cal-status-Present { background: rgba(22, 163, 74, 0.13); border-color: #16a34a; }
.cal-status-Absent { background: rgba(220, 38, 38, 0.13); border-color: #dc2626; }
.cal-status-HalfDay { background: rgba(234, 88, 12, 0.14); border-color: #ea580c; }
.cal-status-Leave { background: rgba(37, 99, 235, 0.13); border-color: #2563eb; }
.cal-status-Holiday { background: rgba(124, 58, 237, 0.13); border-color: #7c3aed; }
.cal-status-WeeklyOff { background: rgba(100, 116, 139, 0.15); border-color: #64748b; }
.cal-status-NotMarked { background: rgba(148, 163, 184, 0.10); border-color: #94a3b8; }

.cal-dot {
    display: inline-block;
    width: 9px;
    height: 9px;
    border-radius: 50%;
}

/* Searchable select helper */
.searchable-select-wrapper {
    position: relative;
}
.searchable-select-filter {
    margin-bottom: 4px;
    font-size: 0.82rem;
}

/* Offline Banner */
#offlineBanner {
    display: none;
    position: sticky;
    top: var(--navbar-height);
    z-index: 1015;
}

body.is-offline #offlineBanner {
    display: flex;
}

/* PWA First-Open Install Notification Banner */
.pwa-install-banner {
    position: fixed;
    bottom: 16px;
    left: 50%;
    transform: translateX(-50%);
    width: calc(100% - 24px);
    max-width: 480px;
    background: var(--erp-surface);
    color: var(--erp-text);
    border: 1px solid var(--erp-border);
    border-radius: 12px;
    padding: 0.7rem 0.85rem;
    box-shadow: 0 12px 32px rgba(15, 23, 42, 0.18);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    z-index: 1050;
}

@media (max-width: 991.98px) {
    .pwa-install-banner {
        bottom: 68px; /* Sit cleanly above mobile bottom navigation */
    }
}

/* Print utilities */
@media print {
    .app-sidebar, .app-navbar, .no-print, #offlineBanner, .mobile-bottom-nav {
        display: none !important;
    }
    .app-main {
        margin-left: 0 !important;
        padding-bottom: 0 !important;
    }
    .app-content {
        padding: 0 !important;
    }
    body {
        background: #fff !important;
        color: #000 !important;
    }
    .card, .kpi-card {
        border: 1px solid #cbd5e1 !important;
        box-shadow: none !important;
    }
}
