:root {
    --sidebar-width: 240px;
    --brand: #6366f1;
    --brand-dark: #4f46e5;
    --brand-soft-bg: #eef2ff;
    --brand-soft-text: #4338ca;

    --bs-primary: #6366f1;
    --bs-primary-rgb: 99, 102, 241;
    --bs-danger: #f87171;
    --bs-danger-rgb: 248, 113, 113;
    --bs-warning: #fbbf24;
    --bs-warning-rgb: 251, 191, 36;
    --bs-success: #34d399;
    --bs-success-rgb: 52, 211, 153;
    --bs-info: #38bdf8;
    --bs-info-rgb: 56, 189, 248;
    --bs-secondary: #94a3b8;
    --bs-secondary-rgb: 148, 163, 184;
    --bs-link-color: var(--brand);
    --bs-link-color-rgb: 99, 102, 241;
    --bs-link-hover-color: var(--brand-dark);
}

body {
    background: #f6f7fb;
    font-family: -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
}

.login-body {
    min-height: 100vh;
    background: linear-gradient(135deg, #818cf8, #6366f1 55%, #4f46e5);
}

.login-card {
    width: 100%;
    max-width: 380px;
    border-radius: 16px;
}

.login-logo {
    height: 64px;
    width: auto;
}

.app-wrapper {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    max-width: var(--sidebar-width);
    background: #ffffff;
    color: #475569;
    border-right: 1px solid #e5e7eb;
    flex-shrink: 0;
    min-height: 100vh;
    position: sticky;
    top: 0;
    align-self: flex-start;
    overflow: hidden;
    transition: width .2s ease;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: .6rem;
    padding: 1.1rem 1.2rem;
    font-weight: 600;
    color: #1e1b4b;
    border-bottom: 1px solid #e5e7eb;
}

.brand-text {
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-collapse-btn {
    width: 26px;
    height: 26px;
    flex-shrink: 0;
    border-radius: 50%;
    background: #f8fafc;
    border: 1px solid #e5e7eb;
    align-items: center;
    justify-content: center;
    color: #64748b;
    font-size: .7rem;
    padding: 0;
}

.sidebar-collapse-btn:hover {
    color: var(--brand);
    border-color: var(--brand);
}

.sidebar-collapse-btn i {
    transition: transform .2s ease;
}

.sidebar-close-btn {
    display: inline-flex;
    width: 30px;
    height: 30px;
    flex-shrink: 0;
    border-radius: 50%;
    background: transparent;
    border: none;
    align-items: center;
    justify-content: center;
    color: #64748b;
    font-size: 1rem;
    padding: 0;
    margin-left: auto;
}

.sidebar-close-btn:hover {
    background: rgba(15,23,42,.06);
    color: #1e1b4b;
}

[data-bs-theme="dark"] .sidebar-close-btn:hover {
    background: rgba(255,255,255,.08);
    color: #fff;
}

.sidebar-backdrop {
    display: none;
}

[data-sidebar="collapsed"] .sidebar {
    width: 76px;
    min-width: 76px;
    max-width: 76px;
}

[data-sidebar="collapsed"] .sidebar-brand {
    justify-content: center;
    padding: 1.1rem .5rem;
}

[data-sidebar="collapsed"] .brand-text {
    display: none;
}

[data-sidebar="collapsed"] .sidebar-nav .nav-link {
    justify-content: center;
    padding: .65rem;
}

[data-sidebar="collapsed"] .sidebar-nav .nav-link .nav-label {
    display: none;
}

[data-sidebar="collapsed"] .sidebar-collapse-btn i {
    transform: rotate(180deg);
}

.sidebar-brand .brand-logo {
    height: 34px;
    width: auto;
    flex-shrink: 0;
}

.brand-logo-dark { display: none; }
[data-bs-theme="dark"] .brand-logo-light { display: none; }
[data-bs-theme="dark"] .brand-logo-dark { display: block; }

.sidebar-nav {
    padding: .75rem;
}

.sidebar-nav .nav-link {
    color: #475569;
    padding: .6rem .9rem;
    border-radius: 8px;
    margin-bottom: .2rem;
    display: flex;
    align-items: center;
    gap: .6rem;
    font-size: .92rem;
}

.sidebar-nav .nav-link i {
    font-size: 1.05rem;
}

.sidebar-nav .nav-link:hover {
    background: #f1f5f9;
    color: #1e1b4b;
}

.sidebar-nav .nav-link.active {
    background: var(--brand);
    color: #fff;
}

.app-content {
    flex-grow: 1;
    min-width: 0;
}

.topbar {
    background: #fff;
    height: 60px;
    border-bottom: 1px solid #e5e7eb;
    position: sticky;
    top: 0;
    z-index: 10;
    gap: .5rem;
}

.topbar h5 {
    min-width: 0;
    flex-shrink: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

@media (max-width: 575.98px) {
    .topbar h5 {
        font-size: 1rem;
    }
    .topbar .dropdown-toggle span.badge {
        display: none;
    }
    /* Bootstrap badges force white-space:nowrap, fine for short status pills
       but a long "peak value" badge (Environment Monitor highlights) then
       overflows the viewport instead of wrapping to a second line. */
    .badge {
        white-space: normal;
        text-align: left;
    }
}

@media (max-width: 767.98px) {
    /* Icon-only action buttons (view/edit/delete/undo) in tables default to
       ~32px, under the ~40px minimum comfortable touch target - bump them up
       on touch-sized screens without changing anything on desktop. */
    .table .btn-sm {
        min-width: 40px;
        min-height: 40px;
        padding: .5rem;
    }
}

.stat-card {
    border: 1px solid rgba(15,23,42,.04);
    border-radius: 16px;
    box-shadow: 0 1px 3px rgba(15,23,42,.06), 0 1px 2px rgba(15,23,42,.04);
}

.stat-card .stat-icon {
    font-size: 2rem;
    opacity: .35;
}

.stat-card.bg-blue  { background: #eef2ff; color: #4338ca; }
.stat-card.bg-red   { background: #fef2f2; color: #b91c1c; }
.stat-card.bg-amber { background: #fffbeb; color: #b45309; }
.stat-card.bg-green { background: #ecfdf5; color: #047857; }

.card {
    border: none;
    border-radius: 12px;
    box-shadow: 0 2px 10px rgba(0,0,0,.05);
}

.table thead th {
    font-size: .78rem;
    text-transform: uppercase;
    color: #6b7280;
    border-bottom-width: 1px;
}

#themeToggle {
    width: 34px;
    height: 34px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Pastel badge pills: light tint background + darker saturated text */
.badge.bg-primary   { background-color: #eef2ff !important; color: #4338ca !important; font-weight: 600; }
.badge.bg-danger    { background-color: #fef2f2 !important; color: #b91c1c !important; font-weight: 600; }
.badge.bg-warning   { background-color: #fffbeb !important; color: #b45309 !important; font-weight: 600; }
.badge.bg-success   { background-color: #ecfdf5 !important; color: #047857 !important; font-weight: 600; }
.badge.bg-info      { background-color: #f0f9ff !important; color: #0369a1 !important; font-weight: 600; }
.badge.bg-secondary { background-color: #f1f5f9 !important; color: #475569 !important; font-weight: 600; }

/* Softened solid buttons to match the new brand hue */
.btn-primary {
    --bs-btn-bg: #6366f1;
    --bs-btn-border-color: #6366f1;
    --bs-btn-hover-bg: #4f46e5;
    --bs-btn-hover-border-color: #4f46e5;
    --bs-btn-active-bg: #4338ca;
    --bs-btn-active-border-color: #4338ca;
}
.btn-outline-primary {
    --bs-btn-color: #6366f1;
    --bs-btn-border-color: #6366f1;
    --bs-btn-hover-bg: #6366f1;
    --bs-btn-hover-border-color: #6366f1;
    --bs-btn-active-bg: #6366f1;
    --bs-btn-active-border-color: #6366f1;
}
.btn-danger {
    --bs-btn-bg: #f87171;
    --bs-btn-border-color: #f87171;
    --bs-btn-hover-bg: #ef4444;
    --bs-btn-hover-border-color: #ef4444;
    --bs-btn-active-bg: #dc2626;
    --bs-btn-active-border-color: #dc2626;
}
.btn-outline-danger {
    --bs-btn-color: #ef4444;
    --bs-btn-border-color: #f87171;
    --bs-btn-hover-bg: #f87171;
    --bs-btn-hover-border-color: #f87171;
    --bs-btn-active-bg: #ef4444;
    --bs-btn-active-border-color: #ef4444;
}
.btn-outline-warning {
    --bs-btn-color: #b45309;
    --bs-btn-border-color: #fbbf24;
    --bs-btn-hover-bg: #fbbf24;
    --bs-btn-hover-border-color: #fbbf24;
    --bs-btn-hover-color: #78350f;
}
.btn-outline-secondary {
    --bs-btn-color: #64748b;
    --bs-btn-border-color: #cbd5e1;
    --bs-btn-hover-bg: #94a3b8;
    --bs-btn-hover-border-color: #94a3b8;
}

/* Softer alert boxes */
.alert-primary { background-color: #eef2ff; border-color: #e0e7ff; color: #4338ca; }
.alert-danger  { background-color: #fef2f2; border-color: #fee2e2; color: #b91c1c; }
.alert-warning { background-color: #fffbeb; border-color: #fef3c7; color: #b45309; }
.alert-success { background-color: #ecfdf5; border-color: #d1fae5; color: #047857; }
.alert-info    { background-color: #f0f9ff; border-color: #e0f2fe; color: #0369a1; }

[data-bs-theme="dark"] body {
    background: #0f1420;
}

[data-bs-theme="dark"] .sidebar {
    background: #10192e;
    color: #cbd5e1;
    border-right-color: #232b3f;
}

[data-bs-theme="dark"] .sidebar-brand {
    color: #fff;
    border-bottom-color: rgba(255,255,255,.08);
}

[data-bs-theme="dark"] .sidebar-nav .nav-link {
    color: #cbd5e1;
}

[data-bs-theme="dark"] .sidebar-nav .nav-link:hover {
    background: rgba(255,255,255,.06);
    color: #fff;
}

[data-bs-theme="dark"] .sidebar-collapse-btn {
    background: #10192e;
    border-color: #232b3f;
    color: #94a3b8;
}

[data-bs-theme="dark"] .topbar {
    background: #151b2c;
    border-bottom-color: #232b3f;
}

[data-bs-theme="dark"] .table thead th {
    color: #94a3b8;
}

[data-bs-theme="dark"] .card {
    box-shadow: 0 2px 10px rgba(0,0,0,.35);
}

[data-bs-theme="dark"] .badge.bg-light {
    background-color: #232b3f !important;
    color: #cbd5e1 !important;
}

[data-bs-theme="dark"] .stat-card {
    border-color: rgba(255,255,255,.06);
    box-shadow: 0 2px 10px rgba(0,0,0,.3);
}
[data-bs-theme="dark"] .stat-card.bg-blue  { background: rgba(99,102,241,.14); color: #a5b4fc; }
[data-bs-theme="dark"] .stat-card.bg-red   { background: rgba(248,113,113,.14); color: #fca5a5; }
[data-bs-theme="dark"] .stat-card.bg-amber { background: rgba(251,191,36,.14); color: #fcd34d; }
[data-bs-theme="dark"] .stat-card.bg-green { background: rgba(52,211,153,.14); color: #6ee7b7; }

[data-bs-theme="dark"] .badge.bg-primary   { background-color: rgba(129,140,248,.18) !important; color: #a5b4fc !important; }
[data-bs-theme="dark"] .badge.bg-danger    { background-color: rgba(248,113,113,.18) !important; color: #fca5a5 !important; }
[data-bs-theme="dark"] .badge.bg-warning   { background-color: rgba(251,191,36,.18) !important; color: #fcd34d !important; }
[data-bs-theme="dark"] .badge.bg-success   { background-color: rgba(52,211,153,.18) !important; color: #6ee7b7 !important; }
[data-bs-theme="dark"] .badge.bg-info      { background-color: rgba(56,189,248,.18) !important; color: #7dd3fc !important; }
[data-bs-theme="dark"] .badge.bg-secondary { background-color: rgba(148,163,184,.18) !important; color: #cbd5e1 !important; }

[data-bs-theme="dark"] .alert-primary { background-color: rgba(129,140,248,.12); border-color: rgba(129,140,248,.25); color: #a5b4fc; }
[data-bs-theme="dark"] .alert-danger  { background-color: rgba(248,113,113,.12); border-color: rgba(248,113,113,.25); color: #fca5a5; }
[data-bs-theme="dark"] .alert-warning { background-color: rgba(251,191,36,.12); border-color: rgba(251,191,36,.25); color: #fcd34d; }
[data-bs-theme="dark"] .alert-success { background-color: rgba(52,211,153,.12); border-color: rgba(52,211,153,.25); color: #6ee7b7; }
[data-bs-theme="dark"] .alert-info    { background-color: rgba(56,189,248,.12); border-color: rgba(56,189,248,.25); color: #7dd3fc; }

@media (max-width: 991.98px) {
    .sidebar {
        position: fixed;
        left: -260px;
        z-index: 1050;
        transition: left .2s ease;
        height: 100vh;
    }
    .sidebar.show {
        left: 0;
    }
    .sidebar-backdrop {
        position: fixed;
        inset: 0;
        background: rgba(15,23,42,.5);
        z-index: 1040;
        opacity: 0;
        pointer-events: none;
        transition: opacity .2s ease;
    }
    .sidebar-backdrop.show {
        display: block;
        opacity: 1;
        pointer-events: auto;
    }
    [data-sidebar="collapsed"] .sidebar {
        width: var(--sidebar-width);
        min-width: var(--sidebar-width);
        max-width: var(--sidebar-width);
    }
    [data-sidebar="collapsed"] .sidebar-brand {
        justify-content: flex-start;
        padding: 1.1rem 1.2rem;
    }
    [data-sidebar="collapsed"] .brand-text {
        display: inline;
    }
    [data-sidebar="collapsed"] .sidebar-nav .nav-link {
        justify-content: flex-start;
        padding: .6rem .9rem;
    }
    [data-sidebar="collapsed"] .sidebar-nav .nav-link .nav-label {
        display: inline;
    }
}
