/* The application shell spans MainLayout and NavMenu, so these rules must remain global. */
html,
body,
#app,
#layout-wrapper {
    min-height: 100%;
}

#layout-wrapper {
    min-height: 100vh;
}

/* Light mode needs an explicit palette; dark mode supplies its own overrides. */
html:not([data-theme="dark"]) {
    --light-bg: #f3f6fa;
    --light-surface: #fff;
    --light-surface-muted: #f8fafc;
    --light-border: #dbe3ed;
    --light-text: #1f2937;
    --light-text-secondary: #526071;
    --light-text-muted: #6b7280;
    color-scheme: light;
}

html:not([data-theme="dark"]) body {
    color: var(--light-text);
    background: var(--light-bg);
}

html:not([data-theme="dark"]) .vertical-menu,
html:not([data-theme="dark"]) .top-navbar,
html:not([data-theme="dark"]) .footer {
    color: var(--light-text);
    background-color: var(--light-surface);
    border-color: var(--light-border);
}

html:not([data-theme="dark"]) .vertical-menu {
    box-shadow: 4px 0 18px rgb(31 41 55 / 7%);
}

html:not([data-theme="dark"]) .top-navbar {
    box-shadow: 0 3px 14px rgb(31 41 55 / 7%);
}

html:not([data-theme="dark"]) .main-content,
html:not([data-theme="dark"]) .page-content {
    color: var(--light-text);
    background-color: var(--light-bg);
}

html:not([data-theme="dark"]) .sidebar-menu-title,
html:not([data-theme="dark"]) .text-muted {
    color: var(--light-text-muted) !important;
}

html:not([data-theme="dark"]) .sidebar-menu-link {
    color: var(--light-text-secondary);
}

html:not([data-theme="dark"]) .sidebar-menu-link:hover {
    color: #174ea6;
    background-color: #edf4ff;
}

html:not([data-theme="dark"]) .sidebar-menu-link.active {
    color: #0b57d0;
    background-color: #e8f0fe;
    border-left-color: #0b57d0;
}

html:not([data-theme="dark"]) .page-title,
html:not([data-theme="dark"]) h1,
html:not([data-theme="dark"]) h2,
html:not([data-theme="dark"]) h3,
html:not([data-theme="dark"]) h4,
html:not([data-theme="dark"]) h5,
html:not([data-theme="dark"]) h6 {
    color: var(--light-text);
}

html:not([data-theme="dark"]) .card,
html:not([data-theme="dark"]) .modern-card,
html:not([data-theme="dark"]) .existing-data-card {
    color: var(--light-text);
    background-color: var(--light-surface);
    border-color: var(--light-border) !important;
    box-shadow: 0 5px 18px rgb(31 41 55 / 7%);
}

html:not([data-theme="dark"]) .card-header,
html:not([data-theme="dark"]) .card-footer {
    color: var(--light-text);
    background-color: var(--light-surface-muted);
    border-color: var(--light-border);
}

html:not([data-theme="dark"]) .table {
    --bs-table-color: var(--light-text);
    --bs-table-bg: var(--light-surface);
    --bs-table-border-color: var(--light-border);
    --bs-table-striped-bg: #f7f9fc;
    --bs-table-hover-bg: #eef4fb;
}

html:not([data-theme="dark"]) .form-control,
html:not([data-theme="dark"]) .form-select,
html:not([data-theme="dark"]) .input-group-text {
    color: var(--light-text);
    background-color: var(--light-surface);
    border-color: #c8d2df;
}

html:not([data-theme="dark"]) .form-control:focus,
html:not([data-theme="dark"]) .form-select:focus {
    border-color: #6ea8fe;
    box-shadow: 0 0 0 .2rem rgb(13 110 253 / 14%);
}

html:not([data-theme="dark"]) .dropdown-menu,
html:not([data-theme="dark"]) .modal-content,
html:not([data-theme="dark"]) .list-group-item {
    color: var(--light-text);
    background-color: var(--light-surface);
    border-color: var(--light-border);
}

html:not([data-theme="dark"]) .dropdown-item {
    color: var(--light-text-secondary);
}

html:not([data-theme="dark"]) .dropdown-item:hover,
html:not([data-theme="dark"]) .dropdown-item:focus {
    color: var(--light-text);
    background-color: #edf4ff;
}

.vertical-menu {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 1000;
    width: var(--sidebar-width);
    height: 100vh;
    overflow-x: hidden;
    overflow-y: auto;
    background: #fff;
    border-right: 1px solid var(--border-color);
    box-shadow: 0 0 15px rgb(0 0 0 / 5%);
    transition: width var(--transition-speed) ease, left var(--transition-speed) ease;
}

.vertical-menu.collapsed {
    width: var(--sidebar-collapsed-width);
}

.navbar-brand-box {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: var(--header-height);
    padding: 0 1rem;
    border-bottom: 1px solid var(--border-color);
}

.logo,
.logo-lg,
.logo-sm {
    display: flex;
    align-items: center;
    min-width: 0;
    height: 100%;
    text-decoration: none;
}

.vertical-menu.collapsed .logo-lg,
.vertical-menu:not(.collapsed) .logo-sm {
    display: none;
}

.sidebar-menu-container {
    padding: 1rem 0;
    overflow-x: hidden;
}

.sidebar-menu-title {
    padding: .5rem 1.5rem;
    color: #6c757d;
    font-size: .75rem;
    font-weight: 600;
    letter-spacing: .05em;
    text-transform: uppercase;
    white-space: nowrap;
}

.sidebar-menu-list {
    padding: 0;
    margin: 0 0 1.5rem;
    list-style: none;
}

.sidebar-menu-item {
    margin: 2px 0;
}

.sidebar-menu-link {
    display: flex;
    align-items: center;
    min-height: 44px;
    padding: .7rem 1.5rem;
    color: #5a5a5a;
    text-decoration: none;
    white-space: nowrap;
    border-left: 3px solid transparent;
    transition: color .2s ease, background-color .2s ease, border-color .2s ease;
}

.sidebar-menu-link:hover {
    color: var(--primary-color);
    background: #f7f9fc;
}

.sidebar-menu-link.active {
    color: var(--primary-color);
    background: var(--primary-light);
    border-left-color: var(--primary-color);
}

.sidebar-menu-link i {
    flex: 0 0 1.75rem;
    min-width: 1.75rem;
    font-size: 1.25rem;
}

.menu-text {
    overflow: hidden;
    text-overflow: ellipsis;
}

.vertical-menu.collapsed .sidebar-menu-link {
    justify-content: center;
    padding-right: 0;
    padding-left: 0;
}

.vertical-menu.collapsed .sidebar-menu-link i {
    flex-basis: auto;
    min-width: 0;
}

.main-content {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    margin-left: var(--sidebar-width);
    background: #f7f9fc;
    transition: margin-left var(--transition-speed) ease;
}

.main-content.collapsed {
    margin-left: var(--sidebar-collapsed-width);
}

.top-navbar {
    position: sticky;
    top: 0;
    z-index: 999;
    height: var(--header-height);
    background: #fff;
    border-bottom: 1px solid var(--border-color);
    box-shadow: 0 0 15px rgb(0 0 0 / 5%);
}

.top-navbar > .container-fluid,
.top-navbar > .container-fluid > .d-flex {
    height: 100%;
}

.page-title {
    max-width: min(45vw, 520px);
    margin-left: .5rem;
    overflow: hidden;
    color: #333;
    font-size: 1.1rem;
    font-weight: 600;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.menu-toggle-btn,
.nav-icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: #6c757d;
    text-decoration: none;
}

.menu-toggle-btn:hover,
.nav-icon-btn:hover {
    color: var(--primary-color);
    background: #f2f4f7;
}

.nav-icon-btn {
    width: 36px;
    height: 36px;
    padding: 0;
    border-radius: 8px;
}

.menu-toggle-btn i,
.nav-icon-btn i {
    font-size: 1.35rem;
}

.notification-dot {
    position: absolute;
    top: 6px;
    right: 6px;
    width: 8px;
    height: 8px;
    background: #dc3545;
    border: 2px solid #fff;
    border-radius: 50%;
}

.user-profile img {
    width: 32px;
    height: 32px;
    object-fit: cover;
}

.page-content {
    flex: 1 0 auto;
    min-width: 0;
}

.footer {
    flex: 0 0 auto;
    padding: 1rem 1.5rem;
    background: #fff;
    border-top: 1px solid var(--border-color);
}

#blazor-error-ui {
    position: fixed;
    right: 1rem;
    bottom: 1rem;
    display: none;
    max-width: min(480px, calc(100vw - 2rem));
    padding: .85rem 3rem .85rem 1rem;
    color: #842029;
    font-weight: 600;
    text-align: left;
    background: #fff5f5;
    border: 1px solid #f1b8be;
    border-radius: 14px;
    box-shadow: 0 16px 40px rgb(31 41 55 / 18%);
    z-index: 1200;
}

#blazor-error-ui .reload {
    margin-left: .75rem;
    color: #0b57d0;
    text-decoration: underline;
    cursor: pointer;
}

#blazor-error-ui .dismiss {
    position: absolute;
    top: .55rem;
    right: .9rem;
    color: #842029;
    font-size: 1.25rem;
    line-height: 1;
    cursor: pointer;
}

.sidebar-overlay {
    position: fixed;
    inset: 0;
    z-index: 999;
    visibility: hidden;
    background: rgb(0 0 0 / 50%);
    opacity: 0;
    transition: opacity var(--transition-speed) ease, visibility var(--transition-speed) ease;
}

.sidebar-overlay.active {
    visibility: visible;
    opacity: 1;
}

@media (max-width: 991.98px) {
    .vertical-menu,
    .vertical-menu.collapsed {
        left: calc(-1 * var(--sidebar-width));
        width: var(--sidebar-width);
        box-shadow: none;
    }

    .vertical-menu:not(.collapsed) {
        left: 0;
        box-shadow: 0 0 15px rgb(0 0 0 / 12%);
    }

    .vertical-menu:not(.collapsed) .logo-lg,
    .vertical-menu:not(.collapsed) .menu-text,
    .vertical-menu:not(.collapsed) .sidebar-menu-title {
        display: flex !important;
    }

    .vertical-menu:not(.collapsed) .sidebar-menu-title {
        display: block !important;
    }

    .main-content,
    .main-content.collapsed {
        margin-left: 0;
    }

    .sidebar-overlay {
        display: none;
    }

    .sidebar-overlay.active {
        display: block;
    }
}

@media (max-width: 575.98px) {
    .top-navbar .container-fluid {
        padding-right: .5rem;
        padding-left: .5rem;
    }

    .page-title {
        max-width: 34vw;
        font-size: 1rem;
    }

    .footer {
        padding: .75rem 1rem;
    }
}
