/* ==========================================================================
   Billease Admin — Dashboard layout + multi-level (3 tier) sidebar
   Built on top of local Bootstrap 5. Loaded only by dashboard.html.
   ========================================================================== */

:root {
    --sb-width: 270px;
    --sb-mini-width: 74px;
    --sb-bg: #0b1120;
    --sb-text: #8a97ad;
    --sb-text-hover: #e6ebf3;
    --sb-active: #ffffff;
    --sb-active-bg: rgba(59, 130, 246, 0.16);
    --sb-accent: #3b82f6;
    --sb-border: #1b2740;
    --sb-guide: #263450;
    --topbar-h: 66px;
    --brand-grad: linear-gradient(135deg, #2563eb, #0ea5e9);
}

* { box-sizing: border-box; }

body.admin-body {
    margin: 0;
    font-family: "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background-color: #0b1120;
}

/* Give every inline icon a consistent stroke look */
.admin-sidebar svg,
.admin-topbar svg {
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

/* -------------------------------------------------- Layout ---- */
.admin-wrapper { min-height: 100vh; }

.admin-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: var(--sb-width);
    height: 100vh;
    background: var(--sb-bg);
    border-right: 1px solid var(--sb-border);
    display: flex;
    flex-direction: column;
    z-index: 1040;
    transition: transform 0.25s ease, width 0.25s ease;
}

.admin-main {
    margin-left: var(--sb-width);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    background-color: var(--bs-body-bg);
    color: var(--bs-body-color);
    transition: margin-left 0.25s ease;
}

/* Desktop collapse (toggled by hamburger) -> icon-only mini sidebar */
.admin-wrapper.sidebar-collapsed .admin-sidebar { width: var(--sb-mini-width); }
.admin-wrapper.sidebar-collapsed .admin-main { margin-left: var(--sb-mini-width); }

/* Hide text-y bits, keep icons centered */
.admin-wrapper.sidebar-collapsed .admin-sidebar .menu-text,
.admin-wrapper.sidebar-collapsed .admin-sidebar .menu-arrow,
.admin-wrapper.sidebar-collapsed .admin-sidebar .menu-heading,
.admin-wrapper.sidebar-collapsed .admin-sidebar .sidebar-brand > span:not(.logo),
.admin-wrapper.sidebar-collapsed .admin-sidebar .sidebar-footer > div,
.admin-wrapper.sidebar-collapsed .admin-sidebar .sidebar-footer .actions,
.admin-wrapper.sidebar-collapsed .admin-sidebar .kbd-hint {
    display: none !important;
}

.admin-wrapper.sidebar-collapsed .admin-sidebar .menu-link {
    justify-content: center;
    gap: 0;
    padding: 0.6rem;
}

.admin-wrapper.sidebar-collapsed .admin-sidebar .sidebar-brand {
    justify-content: center;
    padding: 0 0.5rem;
}

/* Collapse nested submenus while in mini mode (no room for fly-outs) */
.admin-wrapper.sidebar-collapsed .admin-sidebar .submenu { display: none !important; }

.admin-wrapper.sidebar-collapsed .admin-sidebar .sidebar-footer {
    justify-content: center;
}

/* -------------------------------------------------- Brand ----- */
.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    height: var(--topbar-h);
    padding: 0 1.25rem;
    border-bottom: 1px solid var(--sb-border);
    color: #fff;
    text-decoration: none;
    flex-shrink: 0;
}

.sidebar-brand .logo {
    display: grid;
    place-items: center;
    width: 38px;
    height: 38px;
    border-radius: 10px;
    background: var(--brand-grad);
    color: #fff;
    font-weight: 800;
    font-size: 1.15rem;
    flex-shrink: 0;
}

.sidebar-brand .brand-name {
    font-weight: 800;
    font-size: 1.2rem;
    line-height: 1.05;
    color: #fff;
}

.sidebar-brand .brand-name span { color: #5ea0ff; }

.sidebar-brand .brand-sub {
    font-size: 0.66rem;
    letter-spacing: 0.16em;
    text-transform: uppercase;
    color: var(--sb-text);
}

/* -------------------------------------------------- Scroll ---- */
.sidebar-scroll {
    flex: 1;
    overflow-y: auto;
    padding: 0.5rem 0.75rem 1.5rem;
}

.sidebar-scroll::-webkit-scrollbar { width: 6px; }
.sidebar-scroll::-webkit-scrollbar-thumb { background: #1e2b45; border-radius: 3px; }

.menu-heading {
    list-style: none;
    font-size: 0.68rem;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: #566178;
    padding: 1rem 0.75rem 0.35rem;
    font-weight: 700;
}

/* -------------------------------------------------- Menu ------ */
.sidebar-menu,
.submenu {
    list-style: none;
    margin: 0;
    padding: 0;
}

.menu-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.6rem 0.75rem;
    margin: 0.12rem 0;
    color: var(--sb-text);
    text-decoration: none;
    border-radius: 8px;
    font-size: 0.92rem;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}

.menu-link:hover {
    color: var(--sb-text-hover);
    background: rgba(255, 255, 255, 0.04);
}

.menu-link .menu-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    flex-shrink: 0;
}

.menu-link .menu-icon svg { width: 19px; height: 19px; }
.menu-link .menu-icon i { font-size: 16px; line-height: 1; }
.menu-link .menu-text { flex: 1; white-space: nowrap; }

.menu-link .menu-arrow {
    display: inline-flex;
    color: #62708c;
    transition: transform 0.2s ease;
}

.menu-link .menu-arrow svg { width: 15px; height: 15px; }
.menu-link .menu-arrow i { font-size: 12px; line-height: 1; }
.menu-link[aria-expanded="true"] .menu-arrow { transform: rotate(90deg); }
.menu-link[aria-expanded="true"] { color: var(--sb-text-hover); }

/* Level 1 active */
.menu-link.active {
    color: var(--sb-active);
    background: var(--sb-active-bg);
    box-shadow: inset 3px 0 0 var(--sb-accent);
}

.menu-link.active .menu-icon { color: var(--sb-accent); }

/* Submenus (levels 2 & 3) with connecting guide line */
.submenu {
    margin: 0.1rem 0 0.25rem 1.6rem;
    padding-left: 0.55rem;
    border-left: 1px solid var(--sb-guide);
}

.submenu .menu-link {
    padding: 0.5rem 0.6rem 0.5rem 0.85rem;
    font-size: 0.875rem;
    position: relative;
}

.submenu .menu-link::before {
    content: "";
    position: absolute;
    left: -0.55rem;
    top: 50%;
    transform: translateY(-50%);
    width: 0.6rem;
    height: 1px;
    background: var(--sb-guide);
}

/* Level 3 — nudge in a little further */
.submenu .submenu { margin-left: 0.9rem; }

/* Active leaf inside a submenu */
.submenu .menu-link.active {
    background: transparent;
    box-shadow: none;
    color: #fff;
    font-weight: 600;
}

.submenu .menu-link.active::before {
    background: var(--sb-accent);
    width: 0.85rem;
    height: 2px;
}

/* -------------------------------------------------- Sidebar footer ---- */
.sidebar-footer {
    flex-shrink: 0;
    border-top: 1px solid var(--sb-border);
    padding: 0.8rem 1rem;
    display: flex;
    align-items: center;
    gap: 0.7rem;
    background: rgba(255, 255, 255, 0.02);
}

.sidebar-footer .avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--brand-grad);
    display: grid;
    place-items: center;
    color: #fff;
    font-weight: 700;
    flex-shrink: 0;
}

.sidebar-footer .u-name { color: #fff; font-weight: 600; font-size: 0.9rem; line-height: 1.15; }
.sidebar-footer .u-role { color: var(--sb-text); font-size: 0.66rem; letter-spacing: 0.08em; text-transform: uppercase; }
.sidebar-footer .actions { margin-left: auto; display: flex; gap: 0.15rem; }

.sidebar-footer .actions a {
    color: var(--sb-text);
    display: inline-flex;
    padding: 0.35rem;
    border-radius: 6px;
}

.sidebar-footer .actions a:hover { color: #fff; background: rgba(255, 255, 255, 0.06); }
.sidebar-footer .actions svg { width: 18px; height: 18px; }

/* -------------------------------------------------- Backdrop -- */
.sidebar-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(2, 6, 23, 0.6);
    z-index: 1035;
    display: none;
}

/* -------------------------------------------------- Topbar ---- */
.admin-topbar {
    position: sticky;
    top: 0;
    z-index: 1030;
    height: var(--topbar-h);
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0 1.25rem;
    background: var(--bs-body-bg);
    border-bottom: 1px solid var(--bs-border-color);
}

.topbar-toggle {
    background: none;
    border: none;
    color: var(--bs-body-color);
    display: inline-flex;
    padding: 0.4rem;
    border-radius: 8px;
    cursor: pointer;
}

.topbar-toggle:hover { background: var(--bs-tertiary-bg); }
.topbar-toggle svg { width: 22px; height: 22px; }
.topbar-toggle i { font-size: 18px; line-height: 1; }

.topbar-search { position: relative; flex: 1; max-width: 440px; }

.topbar-search svg {
    position: absolute;
    left: 0.85rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--bs-secondary-color);
    width: 18px;
    height: 18px;
}

.topbar-search i {
    position: absolute;
    left: 0.95rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--bs-secondary-color);
    font-size: 15px;
    line-height: 1;
    pointer-events: none;
}

.topbar-search .form-control { padding-left: 2.5rem; border-radius: 10px; }
.topbar-search .kbd-hint { position: absolute; right: 0.55rem; top: 50%; transform: translateY(-50%); }

.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 0.3rem; }

.topbar-btn {
    position: relative;
    background: none;
    border: none;
    color: var(--bs-body-color);
    width: 40px;
    height: 40px;
    border-radius: 10px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.topbar-btn:hover { background: var(--bs-tertiary-bg); }
.topbar-btn svg { width: 20px; height: 20px; }
.topbar-btn i { font-size: 17px; line-height: 1; }

.topbar-btn .dot {
    position: absolute;
    top: 6px;
    right: 6px;
    min-width: 16px;
    height: 16px;
    padding: 0 3px;
    border-radius: 999px;
    background: #ef4444;
    color: #fff;
    font-size: 0.62rem;
    display: grid;
    place-items: center;
    font-weight: 700;
}

.topbar-avatar {
    width: 38px;
    height: 38px;
    border: 0;
    padding: 0;
    cursor: pointer;
    border-radius: 50%;
    background: var(--brand-grad);
    color: #fff;
    display: grid;
    place-items: center;
    font-weight: 700;
    line-height: 1;
    margin-left: 0.25rem;
}

/* Icons inside the user dropdown */
.dropdown-menu svg {
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
    flex-shrink: 0;
}

/* Notifications dropdown */
.notif-menu { width: 344px; max-width: 92vw; overflow: hidden; }
.notif-header { border-bottom: 1px solid var(--bs-border-color); }
.notif-list { max-height: 344px; overflow-y: auto; }

.notif-item {
    display: flex;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    text-decoration: none;
    color: var(--bs-body-color);
    border-bottom: 1px solid var(--bs-border-color);
    position: relative;
    transition: background 0.15s;
}

.notif-item:last-child { border-bottom: 0; }
.notif-item:hover { background: var(--bs-tertiary-bg); }
.notif-item.unread { background: rgba(59, 130, 246, 0.08); }

.notif-ico {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    display: grid;
    place-items: center;
    font-size: 1.15rem;
    flex-shrink: 0;
}

.notif-body { display: flex; flex-direction: column; min-width: 0; padding-right: 0.75rem; }
.notif-title { font-weight: 600; font-size: 0.875rem; }
.notif-text { font-size: 0.8rem; color: var(--bs-secondary-color); }
.notif-time { font-size: 0.72rem; color: var(--bs-secondary-color); margin-top: 0.15rem; }

.notif-item.unread::after {
    content: "";
    position: absolute;
    top: 1.05rem;
    right: 0.85rem;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--sb-accent);
}

.notif-footer { border-top: 1px solid var(--bs-border-color); padding: 0.6rem 1rem; }

/* Toasts drop in from the top-right, right under the user avatar */
#toastContainer .toast {
    transform-origin: top right;
}

#toastContainer .toast.show {
    animation: toastDrop 0.28s ease;
}

@keyframes toastDrop {
    from { opacity: 0; transform: translateY(-16px); }
    to { opacity: 1; transform: translateY(0); }
}

.toast-status-wrap {
    display: inline-flex;
    align-items: center;
    padding-top: 0.65rem;
}

.toast-status-ico {
    font-size: 1.05rem;
    line-height: 1;
}

/* ---- Form validation feedback: Font Awesome icons (not Bootstrap SVG) ---- */
/* Suppress Bootstrap's default background-image tick/cross so only our FA icon shows. */
.form-control.is-valid,
.form-control.is-invalid,
.was-validated .form-control:valid,
.was-validated .form-control:invalid,
.form-select.is-valid,
.form-select.is-invalid,
.was-validated .form-select:valid,
.was-validated .form-select:invalid {
    background-image: none;
    padding-right: 2.25rem;
}

.form-control.is-valid,
.form-select.is-valid { border-color: var(--bs-success, #198754); }

.form-control.is-invalid,
.form-select.is-invalid { border-color: var(--bs-danger, #dc3545); }

/* Wrapper we inject around a lone field so the icon can be absolutely placed. */
.app-vwrap { position: relative; display: block; }

/* input-group hosts the icon too. */
.app-vhost { position: relative; }

.app-vicon {
    position: absolute;
    top: 50%;
    right: .75rem;
    transform: translateY(-50%);
    z-index: 5;
    font-size: 1.05rem;
    line-height: 1;
    pointer-events: none;
}

/* Selects have a caret at the right edge; nudge the icon left of it. */
.app-vicon-select { right: 2.1rem; }

/* Page loader */
.page-loader {
    position: fixed;
    inset: 0;
    z-index: 2000;
    display: grid;
    place-items: center;
    background: rgba(11, 17, 32, 0.45);
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
    transition: opacity 0.4s ease, visibility 0.4s ease;
}

.page-loader.loaded {
    opacity: 0;
    visibility: hidden;
}

.page-loader-inner {
    position: relative;
    display: grid;
    place-items: center;
}

.page-loader .loader-logo {
    width: 56px;
    height: 56px;
    border-radius: 14px;
    background: var(--brand-grad);
    color: #fff;
    font-weight: 800;
    font-size: 1.6rem;
    display: grid;
    place-items: center;
}

.page-loader .loader-spinner {
    position: absolute;
    top: -15px;
    left: -15px;
    width: 86px;
    height: 86px;
    border: 3px solid rgba(59, 130, 246, 0.2);
    border-top-color: var(--sb-accent);
    border-radius: 50%;
    animation: pageLoaderSpin 0.8s linear infinite;
}

@keyframes pageLoaderSpin {
    to { transform: rotate(360deg); }
}

/* -------------------------------------------------- Content --- */
.admin-content { padding: 1.5rem 1.5rem 2.5rem; flex: 1; }

.stat-ico {
    width: 50px;
    height: 50px;
    border-radius: 12px;
    display: grid;
    place-items: center;
    font-size: 1.4rem;
    flex-shrink: 0;
}

.avatar-initials {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: var(--brand-grad);
    color: #fff;
    display: grid;
    place-items: center;
    font-weight: 700;
    font-size: 0.8rem;
    flex-shrink: 0;
}

/* Mini bar chart */
.bar-chart { display: flex; align-items: stretch; gap: 0.75rem; height: 220px; }

.bar-col {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-end;
    gap: 0.5rem;
}

.bar-col .bar {
    width: 100%;
    max-width: 42px;
    background: var(--brand-grad);
    border-radius: 7px 7px 0 0;
    min-height: 6px;
    opacity: 0.85;
    transition: opacity 0.2s;
}

.bar-col:hover .bar { opacity: 1; }
.bar-col .lbl { font-size: 0.72rem; color: var(--bs-secondary-color); }

/* -------------------------------------------------- Theme palettes ---- */
/* Dark (default) — deep navy admin look */
.admin-main[data-bs-theme="dark"] {
    --bs-body-bg: #0d1526;
    --bs-body-color: #c3cede;
    --bs-emphasis-color: #ffffff;
    --bs-secondary-color: rgba(195, 206, 222, 0.65);
    --bs-secondary-bg: #0b1220;
    --bs-tertiary-bg: #131d33;
    --bs-border-color: #1e2a44;
    --bs-card-bg: #131d33;
    --bs-card-border-color: #1e2a44;
    --bs-heading-color: #ffffff;
}

/* Light — soft slate */
.admin-main[data-bs-theme="light"] {
    --bs-body-bg: #f1f5f9;
    --bs-card-bg: #ffffff;
    --bs-border-color: #e2e8f0;
    --bs-tertiary-bg: #e9eef5;
}

/* -------------------------------------------------- Responsive ---- */
@media (max-width: 991.98px) {
    .admin-sidebar { transform: translateX(-100%); }
    .admin-main { margin-left: 0; }
    .admin-wrapper.sidebar-open .admin-sidebar { transform: none; }
    .admin-wrapper.sidebar-open .sidebar-backdrop { display: block; }
}

@media (max-width: 575.98px) {
    .topbar-search { display: none; }
    .admin-content { padding: 1.25rem 1rem 2rem; }
}

/* -------------------------------------------------- Card headers ---- */
/* Uniform dark-navy (sidebar colour) header across every card in the admin
   content, overriding per-view utilities like .bg-primary. */
.admin-content .card > .card-header,
.admin-content .card > .card-header.bg-primary,
.admin-content .card > .card-header.bg-secondary,
.admin-content .card > .card-header.bg-dark {
    background-color: #1B2A5E !important;
    color: #ffffff !important;
    border-bottom: 1px solid var(--sb-border);
}

/* Keep text and icons legible on the dark header. */
.admin-content .card > .card-header,
.admin-content .card > .card-header a,
.admin-content .card > .card-header i,
.admin-content .card > .card-header .card-title,
.admin-content .card > .card-header h1,
.admin-content .card > .card-header h2,
.admin-content .card > .card-header h3,
.admin-content .card > .card-header h4,
.admin-content .card > .card-header h5,
.admin-content .card > .card-header h6 {
    color: #ffffff !important;
}
