:root {
    /* Minimum top bar height (navbar can grow; logo row matches via grid). */
    --rpm-header-height: 56px;
}

:root[data-theme="light"] {
    --rpm-bg: #f5f7fb;
    --rpm-card: #ffffff;
    --rpm-text: #0f172a;
    --rpm-muted: #64748b;
    --rpm-card-border: rgba(15, 23, 42, 0.08);
}

:root[data-theme="dark"] {
    --rpm-bg: #0b1220;
    --rpm-card: #111827;
    --rpm-text: #e5e7eb;
    --rpm-muted: #94a3b8;
    --rpm-card-border: rgba(148, 163, 184, 0.2);
}

html, body {
    font-family: 'Inter', system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
    margin: 0;
}

.theme-body {
    background: var(--rpm-bg);
    color: var(--rpm-text);
}

.rpm-content .card {
    background: var(--rpm-card);
    color: var(--rpm-text);
    border-color: var(--rpm-card-border);
}

/* Muted / secondary text: Bootstrap default is too dark on dark cards */
.rpm-content .text-muted {
    color: var(--rpm-muted) !important;
}

:root[data-theme="dark"] .rpm-content .rpm-kpi .text-muted,
:root[data-theme="dark"] .rpm-content .card-header {
    color: #cbd5e1 !important;
}

:root[data-theme="dark"] .rpm-content .list-group-item {
    background-color: var(--rpm-card);
    color: var(--rpm-text);
    border-color: var(--rpm-card-border);
}

:root[data-theme="dark"] .rpm-content .display-6:not(.text-success) {
    color: #f1f5f9;
}

.rpm-sidebar-desktop {
    min-width: 260px;
    max-width: 280px;
}

/* Full-width logo band: offsets parent aside/offcanvas-body horizontal px-3 (1rem). */
.rpm-sidebar-brand-bleed {
    margin-left: -1rem;
    margin-right: -1rem;
    width: calc(100% + 2rem);
    box-sizing: border-box;
}

/* App shell: mobile = column; lg+ = grid so logo + navbar share one row height. */
.rpm-layout {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

@media (min-width: 992px) {
    .rpm-layout {
        display: grid;
        grid-template-columns: minmax(260px, 280px) 1fr;
        grid-template-rows: auto 1fr;
        min-height: 100vh;
    }

    .rpm-layout__brand {
        grid-column: 1;
        grid-row: 1;
        background-color: #fff;
        min-width: 0;
        min-height: 0;
        display: flex;
        flex-direction: column;
    }

    .rpm-layout__brand .rpm-sidebar-brand-bleed {
        flex: 1 1 auto;
        display: flex;
        align-items: center;
        justify-content: center;
        min-height: 0;
        margin-bottom: 0 !important;
        margin-left: 0;
        margin-right: 0;
        width: 100%;
        box-sizing: border-box;
        background-color: #fff;
    }

    .rpm-layout__brand .rpm-sidebar-logo-wrap {
        display: flex;
        align-items: center;
        justify-content: center;
        height: 100%;
        width: 100%;
        min-height: 0;
        padding: 6px 10px;
        box-sizing: border-box;
    }

    .rpm-layout__brand .rpm-sidebar-logo {
        max-width: 100%;
        max-height: 100%;
        width: auto;
        height: auto;
        object-fit: contain;
    }

    nav.rpm-layout__nav {
        grid-column: 2;
        grid-row: 1;
        min-width: 0;
    }

    .rpm-layout__aside {
        grid-column: 1;
        grid-row: 2;
        min-height: 0;
    }

    .rpm-layout__main {
        grid-column: 2;
        grid-row: 2;
        min-width: 0;
        min-height: 0;
    }
}

/* Top navbar: compact padding; row height follows content on desktop grid. */
nav.rpm-top-navbar.navbar {
    min-height: var(--rpm-header-height);
    padding-top: 0;
    padding-bottom: 0;
    box-sizing: border-box;
}

nav.rpm-top-navbar.navbar > .container-fluid {
    align-items: center;
    flex-wrap: nowrap;
}

nav.rpm-top-navbar .navbar-brand {
    padding-top: 0;
    padding-bottom: 0;
    margin-top: 0;
    margin-bottom: 0;
    line-height: 1.2;
    white-space: nowrap;
}

/* Top bar brand: letter-by-letter reveal with accent on "Planning". */
.rpm-erp-brand {
    position: relative;
    font-weight: 600;
    letter-spacing: 0.01em;
}

.rpm-erp-brand--intro {
    overflow: visible;
}

.rpm-erp-brand__text {
    display: inline-block;
    position: relative;
    z-index: 1;
}

.rpm-erp-brand--intro .rpm-erp-brand__ch {
    display: inline-block;
    opacity: 0;
    transform: translateY(0.45em) scale(0.94);
    filter: blur(2px);
    animation: rpmErpBrandChar 0.38s cubic-bezier(0.22, 1, 0.36, 1) forwards;
}

.rpm-erp-brand--intro .rpm-erp-brand__ch.is-accent {
    color: #fde68a;
    text-shadow: 0 0 14px rgba(253, 230, 138, 0.55);
}

.rpm-erp-brand__underline {
    position: absolute;
    left: 0;
    bottom: -2px;
    height: 2px;
    width: 0;
    border-radius: 2px;
    background: linear-gradient(90deg, rgba(255, 255, 255, 0.15), #fde68a, rgba(255, 255, 255, 0.85));
    box-shadow: 0 0 10px rgba(253, 230, 138, 0.45);
    animation: rpmErpBrandUnderline 0.55s cubic-bezier(0.22, 1, 0.36, 1) forwards;
    pointer-events: none;
}

@keyframes rpmErpBrandChar {
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
        filter: blur(0);
    }
}

@keyframes rpmErpBrandUnderline {
    to {
        width: 100%;
    }
}

@media (prefers-reduced-motion: reduce) {
    .rpm-erp-brand--intro .rpm-erp-brand__ch {
        animation: none;
        opacity: 1;
        transform: none;
        filter: none;
    }

    .rpm-erp-brand__underline {
        animation: none;
        width: 100%;
    }
}

nav.rpm-top-navbar .btn.dropdown-toggle {
    max-width: 14rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.rpm-sidebar-logo-wrap {
    line-height: 0;
    display: block;
    width: 100%;
}

/* Match sidebar column width; height follows image (offcanvas / mobile). */
.rpm-sidebar-logo {
    width: 100%;
    height: auto;
    display: block;
    object-fit: contain;
}

.rpm-kpi .display-6 {
    font-size: 2rem;
}

.login-body {
    min-height: 100vh;
    background: linear-gradient(120deg, #0f172a, #1d4ed8 45%, #0ea5e9);
    color: #fff;
}

.login-backdrop {
    position: fixed;
    inset: 0;
}

.glass-card {
    background: rgba(255, 255, 255, 0.12);
    border: 1px solid rgba(255, 255, 255, 0.25);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    color: #0f172a;
}

.glass-card a.login-forgot-link {
    color: #000 !important;
}

.glass-card a.login-forgot-link:hover {
    color: #212529 !important;
    text-decoration: underline !important;
}

.rpm-loader {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.35);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
}

@media print {
    .rpm-sidebar-desktop, .rpm-layout__brand, .offcanvas, nav, footer, .d-print-none {
        display: none !important;
    }
}

/* ============================================================
   Collapsible Sidebar Navigation
   Top-level groups render as toggle buttons; sub-menus are
   hidden until the parent is clicked. The active link's
   ancestor chain is auto-expanded on page load.
   ============================================================ */
.rpm-sidenav {
    gap: 2px;
}

.rpm-sidenav .rpm-sidenav__toggle,
.rpm-sidenav .rpm-sidenav__link,
.rpm-sidenav .rpm-sidenav__static {
    display: flex;
    align-items: center;
    gap: .65rem;
    width: 100%;
    text-align: left;
    border: 0;
    background: transparent;
    color: rgba(255, 255, 255, 0.78);
    padding: .5rem .75rem;
    border-radius: .5rem;
    text-decoration: none;
    font-size: .92rem;
    line-height: 1.2;
    transition: background-color .15s ease-in-out, color .15s ease-in-out;
}

.rpm-sidenav .rpm-sidenav__icon {
    width: 1.1rem;
    text-align: center;
    flex: 0 0 1.1rem;
    color: rgba(255, 255, 255, 0.55);
    transition: color .15s ease-in-out;
}

.rpm-sidenav .rpm-sidenav__label {
    flex: 1 1 auto;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.rpm-sidenav .rpm-sidenav__chev {
    margin-left: auto;
    font-size: .7rem;
    transition: transform .2s ease-in-out;
    color: rgba(255, 255, 255, 0.45);
}

.rpm-sidenav .rpm-sidenav__toggle[aria-expanded="true"] .rpm-sidenav__chev {
    transform: rotate(90deg);
    color: rgba(255, 255, 255, 0.85);
}

.rpm-sidenav .rpm-sidenav__toggle:hover,
.rpm-sidenav .rpm-sidenav__link:hover {
    background: rgba(255, 255, 255, 0.08);
    color: #fff;
}

.rpm-sidenav .rpm-sidenav__toggle:hover .rpm-sidenav__icon,
.rpm-sidenav .rpm-sidenav__link:hover .rpm-sidenav__icon {
    color: rgba(255, 255, 255, 0.95);
}

.rpm-sidenav .rpm-sidenav__toggle[aria-expanded="true"] {
    background: rgba(255, 255, 255, 0.06);
    color: #fff;
    font-weight: 600;
}

.rpm-sidenav .rpm-sidenav__link.active {
    background: rgba(13, 110, 253, 0.85);
    color: #fff;
    font-weight: 600;
    box-shadow: 0 2px 6px rgba(13, 110, 253, 0.35);
}

.rpm-sidenav .rpm-sidenav__link.active .rpm-sidenav__icon {
    color: #fff;
}

.rpm-sidenav .rpm-sidenav__static {
    text-transform: uppercase;
    font-size: .72rem;
    letter-spacing: .04em;
    color: rgba(255, 255, 255, 0.45);
    margin-top: .5rem;
    pointer-events: none;
}

.rpm-sidenav .rpm-sidenav__panel {
    padding: 2px 0 4px 0;
    margin-left: .55rem;
    border-left: 1px dashed rgba(255, 255, 255, 0.12);
}

.rpm-sidenav .rpm-sidenav__depth-0 {
    font-weight: 500;
}

.rpm-sidenav .rpm-sidenav__panel .rpm-sidenav__toggle,
.rpm-sidenav .rpm-sidenav__panel .rpm-sidenav__link,
.rpm-sidenav .rpm-sidenav__panel .rpm-sidenav__static {
    padding-left: .85rem;
    font-size: .88rem;
}

.rpm-sidenav .rpm-sidenav__panel .rpm-sidenav__panel .rpm-sidenav__toggle,
.rpm-sidenav .rpm-sidenav__panel .rpm-sidenav__panel .rpm-sidenav__link,
.rpm-sidenav .rpm-sidenav__panel .rpm-sidenav__panel .rpm-sidenav__static {
    padding-left: 1.15rem;
    font-size: .85rem;
}

/* Floating ERP chat assistant (demo) */
.rpm-chat {
    position: fixed;
    right: 1.25rem;
    bottom: 1.25rem;
    z-index: 1080;
    font-family: 'Inter', system-ui, sans-serif;
}

.rpm-chat__fab {
    position: relative;
    z-index: 2;
    width: 3.25rem;
    height: 3.25rem;
    border: 0;
    border-radius: 50%;
    background: linear-gradient(135deg, #2563eb, #1d4ed8);
    color: #fff;
    box-shadow: 0 8px 24px rgba(37, 99, 235, 0.45);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.rpm-chat__fab:hover {
    transform: scale(1.06);
    box-shadow: 0 10px 28px rgba(37, 99, 235, 0.55);
    color: #fff;
}

.rpm-chat__fab.is-open {
    background: linear-gradient(135deg, #475569, #334155);
}

.rpm-chat__panel {
    position: absolute;
    right: 0;
    bottom: calc(3.25rem + 0.75rem);
    width: min(360px, calc(100vw - 2rem));
    height: 420px;
    display: none;
    background: var(--rpm-card);
    color: var(--rpm-text);
    border: 1px solid var(--rpm-card-border);
    border-radius: 1rem;
    box-shadow: 0 16px 48px rgba(15, 23, 42, 0.18);
    flex-direction: column;
    overflow: hidden;
    z-index: 1;
}

.rpm-chat__panel.is-open {
    display: flex !important;
    animation: rpmChatSlideUp 0.22s ease-out;
    z-index: 3;
}

@keyframes rpmChatSlideUp {
    from {
        opacity: 0;
        transform: translateY(12px) scale(0.98);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.rpm-chat__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.85rem 1rem;
    background: linear-gradient(135deg, #1e3a5f, #2563eb);
    color: #fff;
}

.rpm-chat__head-info {
    display: flex;
    align-items: center;
    gap: 0.65rem;
}

.rpm-chat__avatar {
    width: 2.25rem;
    height: 2.25rem;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.15);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
}

.rpm-chat__title {
    font-weight: 600;
    font-size: 0.95rem;
    line-height: 1.2;
}

.rpm-chat__status {
    font-size: 0.72rem;
    opacity: 0.9;
    display: flex;
    align-items: center;
    gap: 0.35rem;
}

.rpm-chat__dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #4ade80;
    box-shadow: 0 0 6px #4ade80;
}

.rpm-chat__close {
    text-decoration: none;
    opacity: 0.85;
    padding: 0.15rem 0.35rem;
}

.rpm-chat__close:hover {
    opacity: 1;
    color: #fff;
}

.rpm-chat__messages {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.65rem;
    background: var(--rpm-bg);
}

.rpm-chat__msg {
    display: flex;
    max-width: 88%;
}

.rpm-chat__msg--user {
    align-self: flex-end;
}

.rpm-chat__msg--bot {
    align-self: flex-start;
}

.rpm-chat__bubble {
    padding: 0.55rem 0.8rem;
    border-radius: 0.85rem;
    font-size: 0.84rem;
    line-height: 1.45;
    word-break: break-word;
}

.rpm-chat__msg--user .rpm-chat__bubble {
    background: linear-gradient(135deg, #2563eb, #1d4ed8);
    color: #fff;
    border-bottom-right-radius: 0.2rem;
}

.rpm-chat__msg--bot .rpm-chat__bubble {
    background: var(--rpm-card);
    color: var(--rpm-text);
    border: 1px solid var(--rpm-card-border);
    border-bottom-left-radius: 0.2rem;
}

.rpm-chat__foot {
    padding: 0.65rem 0.75rem;
    border-top: 1px solid var(--rpm-card-border);
    background: var(--rpm-card);
}

.rpm-chat__form {
    display: flex;
    gap: 0.45rem;
    align-items: center;
}

.rpm-chat__form .form-control {
    border-radius: 2rem;
    font-size: 0.84rem;
}

.rpm-chat__form .btn {
    border-radius: 50%;
    width: 2.1rem;
    height: 2.1rem;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

@media (max-width: 575.98px) {
    .rpm-chat {
        right: 0.75rem;
        bottom: 0.75rem;
    }

    .rpm-chat__panel {
        width: calc(100vw - 1.5rem);
        height: min(420px, 70vh);
    }
}
