:root {
    --color-bg: #eef2f6;
    --color-panel: #ffffff;
    --color-line: #d7dde6;
    --color-text: #111827;
    --color-muted: #64748b;
    --color-primary: #2563eb;
    --color-primary-dark: #1d4ed8;
    --color-sidebar: #0f172a;
    --color-accent: #0891b2;
    --shadow-panel: 0 16px 40px rgba(15, 23, 42, 0.08);
    --shadow-soft: 0 8px 22px rgba(15, 23, 42, 0.06);
}

* {
    box-sizing: border-box;
}

body {
    min-height: 100vh;
    margin: 0;
    background: linear-gradient(180deg, #f8fafc 0%, var(--color-bg) 280px);
    color: var(--color-text);
    font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.auth-page {
    display: grid;
    place-items: center;
    padding: 24px;
    background: linear-gradient(135deg, #f8fafc 0%, #eef2f6 100%);
}

.auth-shell {
    width: min(100%, 420px);
}

.login-card {
    background: var(--color-panel);
    border: 1px solid var(--color-line);
    border-radius: 12px;
    box-shadow: var(--shadow-panel);
    padding: 30px;
}

.login-heading,
.brand {
    display: flex;
    align-items: center;
    gap: 12px;
}

.login-heading {
    margin-bottom: 24px;
}

.login-heading h1 {
    margin: 0;
    font-size: 1.35rem;
}

.login-heading p,
.brand small,
.topbar span,
.module-placeholder p,
.login-help {
    color: var(--color-muted);
}

.login-heading p {
    margin: 2px 0 0;
}

.brand-mark {
    display: inline-grid;
    place-items: center;
    width: 42px;
    height: 42px;
    border-radius: 8px;
    background: var(--color-primary);
    color: #fff;
    font-weight: 700;
}

.brand-logo {
    width: 148px;
    max-width: 100%;
    height: auto;
}

.login-logo {
    width: 158px;
    max-width: 100%;
    height: auto;
}

.brand-logo-photo,
.login-logo-photo {
    background: #151515;
    border-radius: 10px;
    object-fit: contain;
}

.brand-logo-photo {
    width: 118px;
    height: 118px;
    box-shadow: 0 12px 26px rgba(0, 0, 0, 0.24);
}

.login-logo-photo {
    width: 132px;
    height: 132px;
    box-shadow: 0 14px 30px rgba(15, 23, 42, 0.16);
}

.login-help {
    margin-top: 18px;
    font-size: 0.88rem;
    text-align: center;
}

.btn-primary {
    --bs-btn-bg: var(--color-primary);
    --bs-btn-border-color: var(--color-primary);
    --bs-btn-hover-bg: var(--color-primary-dark);
    --bs-btn-hover-border-color: var(--color-primary-dark);
}

.app-shell {
    display: grid;
    grid-template-columns: 272px minmax(0, 1fr);
    min-height: 100vh;
}

.sidebar {
    background: var(--color-sidebar);
    color: #fff;
    padding: 22px 18px;
    box-shadow: 8px 0 30px rgba(15, 23, 42, 0.12);
}

.brand {
    align-items: flex-start;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 28px;
}

.brand strong,
.brand small {
    display: block;
}

.sidebar-nav {
    gap: 4px;
}

.sidebar-nav .nav-link {
    border: 1px solid transparent;
    border-radius: 8px;
    color: rgba(255, 255, 255, 0.78);
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 650;
    padding: 10px 12px;
    transition: background 0.16s ease, border-color 0.16s ease, color 0.16s ease, transform 0.16s ease;
}

.sidebar-nav .nav-link i {
    color: #9cff73;
    font-size: 1rem;
    width: 20px;
}

.sidebar-nav .nav-link.active,
.sidebar-nav .nav-link:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.12);
    color: #fff;
    transform: translateX(2px);
}

.sidebar-nav .nav-link.active {
    box-shadow: inset 3px 0 0 #39B54A;
}

.sidebar-nav .nav-link.disabled {
    color: rgba(255, 255, 255, 0.38);
}

.main-area {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    min-height: 76px;
    padding: 16px 26px;
    background: rgba(255, 255, 255, 0.94);
    border-bottom: 1px solid var(--color-line);
    backdrop-filter: blur(10px);
}

.topbar h1 {
    margin: 0;
    font-size: 1.35rem;
    font-weight: 800;
}

.content {
    flex: 1;
    padding: 26px;
}

.app-footer {
    border-top: 1px solid var(--color-line);
    color: var(--color-muted);
    font-size: 0.84rem;
    padding: 14px 26px 18px;
}

.app-footer a,
.login-help a {
    color: var(--color-primary);
    font-weight: 700;
    text-decoration: none;
}

.app-footer a:hover,
.login-help a:hover {
    text-decoration: underline;
}

.module-placeholder {
    display: flex;
    align-items: center;
    min-height: 220px;
    padding: 28px;
    border: 1px solid var(--color-line);
    border-radius: 8px;
    background: #fff;
    box-shadow: var(--shadow-soft);
}

.module-placeholder h2 {
    margin: 4px 0 8px;
    font-size: 1.35rem;
}

.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 14px;
    margin-bottom: 18px;
}

.metric-card,
.dashboard-panel {
    border: 1px solid var(--color-line);
    border-radius: 10px;
    background: #fff;
    box-shadow: var(--shadow-soft);
}

.metric-card {
    padding: 18px;
    overflow: hidden;
    position: relative;
}

.metric-card::before {
    content: "";
    display: block;
    width: 42px;
    height: 3px;
    border-radius: 999px;
    background: var(--color-primary);
    margin-bottom: 14px;
}

.metric-card span,
.panel-heading span,
.bar-column small,
.bar-column span,
.rank-item span,
.activity-item small,
.empty-inline {
    color: var(--color-muted);
}

.metric-card span {
    display: block;
    font-size: 0.76rem;
    font-weight: 700;
    text-transform: uppercase;
}

.metric-card strong {
    display: block;
    margin-top: 6px;
    font-size: 1.65rem;
}

.metric-card small {
    color: var(--color-muted);
    display: block;
    margin-top: 4px;
}

.dashboard-panels {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
}

.dashboard-panel {
    padding: 18px;
}

.dashboard-panel-wide {
    grid-column: 1 / -1;
}

.panel-heading {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 14px;
    margin-bottom: 16px;
}

.panel-heading h2 {
    margin: 0;
    font-size: 1.05rem;
}

.panel-heading span {
    font-size: 0.84rem;
}

.bar-chart {
    display: grid;
    grid-template-columns: repeat(6, minmax(0, 1fr));
    gap: 12px;
    min-height: 210px;
}

.bar-column {
    display: grid;
    grid-template-rows: 150px auto auto auto;
    gap: 5px;
    min-width: 0;
    text-align: center;
}

.bar-track {
    display: flex;
    align-items: flex-end;
    height: 150px;
    border-radius: 8px;
    background: #eef2f7;
    overflow: hidden;
}

.bar-fill {
    width: 100%;
    height: var(--bar-size, 0);
    min-height: 6px;
    background: var(--color-primary);
}

.bar-column strong,
.bar-column small,
.bar-column span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.bar-column strong {
    font-size: 0.82rem;
}

.bar-column small,
.bar-column span {
    font-size: 0.78rem;
}

.horizontal-bars,
.rank-list,
.activity-list {
    display: grid;
    gap: 12px;
}

.hbar-row,
.rank-item {
    display: grid;
    gap: 7px;
}

.hbar-row > div:first-child,
.rank-item > div:first-child {
    display: flex;
    justify-content: space-between;
    gap: 10px;
}

.hbar-row strong,
.rank-item strong {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.hbar-track {
    height: 9px;
    border-radius: 999px;
    background: #edf1f5;
    overflow: hidden;
}

.hbar-fill {
    height: 100%;
    min-width: 4px;
    border-radius: inherit;
    background: var(--color-primary);
}

.hbar-fill.muted {
    background: #60758f;
}

.hbar-fill.accent {
    background: #2f7d6d;
}

.activity-item {
    display: grid;
    grid-template-columns: 96px minmax(0, 1fr);
    gap: 12px;
    border-top: 1px solid var(--color-line);
    padding-top: 12px;
}

.activity-item:first-child {
    border-top: 0;
    padding-top: 0;
}

.activity-item > span {
    align-self: start;
    border-radius: 999px;
    background: #eef3f8;
    color: #2f3b4c;
    font-size: 0.76rem;
    font-weight: 700;
    padding: 5px 9px;
    text-align: center;
}

.activity-item strong,
.activity-item small {
    display: block;
}

.activity-item strong {
    overflow-wrap: anywhere;
}

.empty-inline {
    margin: 0;
}

.page-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 18px;
}

.search-form {
    display: flex;
    gap: 8px;
    width: min(100%, 560px);
}

.filter-form {
    display: grid;
    grid-template-columns: minmax(180px, 1.4fr) repeat(4, minmax(150px, 1fr)) auto;
    gap: 8px;
    width: min(100%, 1120px);
}

.summary-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 14px;
    margin-bottom: 18px;
}

.summary-card {
    border: 1px solid var(--color-line);
    border-radius: 10px;
    background: #fff;
    padding: 18px;
    box-shadow: var(--shadow-soft);
}

.summary-card span {
    display: block;
    color: var(--color-muted);
    font-size: 0.82rem;
    font-weight: 700;
    text-transform: uppercase;
}

.summary-card strong {
    display: block;
    margin-top: 6px;
    font-size: 1.6rem;
}

.preview-panel {
    margin-top: 18px;
    border: 1px solid var(--color-line);
    border-radius: 10px;
    background: #fff;
    padding: 22px;
    box-shadow: var(--shadow-soft);
}

.preview-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 18px;
}

.preview-header h2 {
    margin: 4px 0 0;
    font-size: 1.2rem;
}

.preview-actions {
    display: flex;
    gap: 8px;
}

.section-title {
    margin: 22px 0 12px;
    font-size: 1rem;
}

.status-pill {
    display: inline-flex;
    align-items: center;
    min-height: 28px;
    border-radius: 999px;
    background: #eef6ff;
    color: #1d4ed8;
    font-size: 0.82rem;
    font-weight: 700;
    padding: 4px 10px;
}

.form-control,
.form-select {
    border-color: var(--color-line);
    border-radius: 8px;
    min-height: 40px;
}

.form-control:focus,
.form-select:focus {
    border-color: rgba(37, 99, 235, 0.55);
    box-shadow: 0 0 0 0.2rem rgba(37, 99, 235, 0.12);
}

.btn {
    border-radius: 8px;
    font-weight: 700;
}

.detail-panel {
    border: 1px solid var(--color-line);
    border-radius: 10px;
    background: #fff;
    padding: 22px;
    box-shadow: var(--shadow-soft);
}

.detail-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 20px;
}

.detail-header h2 {
    margin: 4px 0 0;
    font-size: 1.3rem;
}

.detail-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 14px;
    margin: 0 0 22px;
}

.detail-grid div {
    border: 1px solid var(--color-line);
    border-radius: 8px;
    padding: 12px;
}

.detail-grid dt {
    color: var(--color-muted);
    font-size: 0.76rem;
    font-weight: 700;
    text-transform: uppercase;
}

.detail-grid dd {
    margin: 4px 0 0;
}

.detail-block {
    border-top: 1px solid var(--color-line);
    padding-top: 18px;
}

.detail-block + .detail-block {
    margin-top: 18px;
}

.detail-block h3 {
    font-size: 1rem;
    margin-bottom: 10px;
}

.detail-block pre {
    margin: 0;
    white-space: pre-wrap;
}

.box-selector {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    max-height: 320px;
    overflow: auto;
    border: 1px solid var(--color-line);
    border-radius: 8px;
    padding: 10px;
}

.box-option {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    border: 1px solid var(--color-line);
    border-radius: 8px;
    padding: 10px;
}

.box-option span,
.box-option strong {
    display: block;
}

.box-option span {
    color: var(--color-muted);
    font-size: 0.86rem;
}

.box-option strong {
    color: var(--color-text);
}

.report-links {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 14px;
}

.report-card {
    display: block;
    border: 1px solid var(--color-line);
    border-radius: 10px;
    background: #fff;
    color: var(--color-text);
    padding: 20px;
    text-decoration: none;
    box-shadow: var(--shadow-soft);
}

.report-card:hover {
    border-color: var(--color-primary);
}

.report-card span {
    display: block;
    color: var(--color-primary);
    font-weight: 700;
    margin-bottom: 8px;
}

.report-card strong {
    font-size: 1rem;
    font-weight: 600;
}

.report-filter {
    grid-template-columns: repeat(4, minmax(140px, 1fr)) repeat(3, auto);
}

.table-panel,
.form-panel {
    border: 1px solid var(--color-line);
    border-radius: 10px;
    background: #fff;
    box-shadow: var(--shadow-soft);
}

.table-panel {
    overflow: hidden;
}

.table-panel .table {
    margin: 0;
}

.table-panel th {
    color: var(--color-muted);
    font-size: 0.78rem;
    font-weight: 700;
    text-transform: uppercase;
    background: #f8fafc;
}

.table > :not(caption) > * > * {
    padding: 0.85rem 0.9rem;
}

.table tbody tr:hover {
    background: #f8fafc;
}

.table-panel td strong,
.table-panel td small {
    display: block;
}

.table-panel td small {
    color: var(--color-muted);
    margin-top: 2px;
}

.inline-form {
    display: inline-block;
    margin-left: 4px;
}

.empty-state {
    color: var(--color-muted);
    padding: 32px !important;
    text-align: center;
}

.form-panel {
    padding: 22px;
}

.form-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 22px;
}

.eyebrow {
    color: var(--color-primary);
    font-size: 0.78rem;
    font-weight: 700;
    letter-spacing: 0;
    text-transform: uppercase;
}

@media (max-width: 860px) {
    .app-shell {
        grid-template-columns: 1fr;
    }

    .sidebar {
        position: static;
        padding-bottom: 14px;
    }

    .brand {
        margin-bottom: 16px;
    }

    .brand-logo {
        width: 132px;
    }

    .topbar {
        align-items: flex-start;
        flex-direction: column;
        padding: 16px 18px;
    }

    .content {
        padding: 18px;
    }

    .app-footer {
        padding: 14px 18px 18px;
    }

    .page-actions,
    .search-form,
    .filter-form {
        align-items: stretch;
        flex-direction: column;
    }

    .filter-form,
    .summary-grid,
    .dashboard-grid,
    .dashboard-panels,
    .bar-chart {
        grid-template-columns: 1fr;
    }

    .dashboard-panel-wide {
        grid-column: auto;
    }

    .bar-column {
        grid-template-columns: 90px minmax(0, 1fr) 54px;
        grid-template-rows: auto;
        align-items: center;
        text-align: left;
    }

    .bar-track {
        height: 12px;
    }

    .bar-fill {
        height: 100%;
        width: var(--bar-size, 0);
    }

    .activity-item {
        grid-template-columns: 1fr;
    }

    .preview-header,
    .preview-actions,
    .detail-header {
        align-items: stretch;
        flex-direction: column;
    }

    .detail-grid {
        grid-template-columns: 1fr;
    }

    .box-selector {
        grid-template-columns: 1fr;
    }

    .report-links {
        grid-template-columns: 1fr;
    }
}

/* Responsiveness hardening for tablets and phones */
html,
body {
    max-width: 100%;
    overflow-x: hidden;
}

.main-area,
.content,
.table-responsive,
.form-panel,
.preview-panel,
.detail-panel,
.table-panel {
    min-width: 0;
}

.table-responsive {
    -webkit-overflow-scrolling: touch;
}

.table-panel .table {
    min-width: 760px;
}

.table-panel td,
.table-panel th {
    vertical-align: middle;
}

.table-panel td:not(.text-end),
.table-panel th:not(.text-end) {
    max-width: 260px;
}

.table-panel td {
    overflow-wrap: anywhere;
}

.form-actions,
.preview-actions,
.detail-header {
    flex-wrap: wrap;
}

.form-actions .btn,
.preview-actions .btn,
.detail-header .btn {
    white-space: nowrap;
}

@media (max-width: 1200px) {
    .app-shell {
        grid-template-columns: 232px minmax(0, 1fr);
    }

    .sidebar {
        padding: 18px 14px;
    }

    .brand-logo-photo {
        height: 76px;
        width: 76px;
    }

    .content {
        padding: 22px;
    }

    .summary-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .report-links {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .box-selector {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 992px) {
    .app-shell {
        grid-template-columns: 1fr;
    }

    .sidebar {
        border-right: 0;
        box-shadow: 0 8px 26px rgba(15, 23, 42, 0.12);
        padding: 16px;
    }

    .brand {
        align-items: center;
        flex-direction: row;
        margin-bottom: 14px;
    }

    .brand-logo-photo {
        height: 62px;
        width: 62px;
    }

    .sidebar-nav {
        display: grid !important;
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }

    .sidebar-nav .nav-link {
        justify-content: flex-start;
        min-width: 0;
    }

    .sidebar-nav .nav-link i {
        flex: 0 0 20px;
    }

    .sidebar-nav .nav-link {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .topbar {
        min-height: 72px;
        padding: 14px 18px;
    }

    .content {
        padding: 18px;
    }

    .app-footer {
        padding: 14px 18px 18px;
    }

    .page-actions {
        grid-template-columns: 1fr;
    }

    .page-actions > .btn {
        justify-self: start;
    }

    .detail-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 720px) {
    .sidebar-nav {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .topbar {
        align-items: stretch;
        flex-direction: column;
        gap: 12px;
    }

    .topbar form,
    .topbar .btn {
        width: 100%;
    }

    .content {
        padding: 14px;
    }

    .summary-grid,
    .report-links,
    .detail-grid {
        grid-template-columns: 1fr;
    }

    .page-actions,
    .form-panel,
    .preview-panel,
    .detail-panel {
        padding: 16px;
    }

    .search-form,
    .filter-form {
        align-items: stretch;
        flex-direction: column;
    }

    .filter-form > .form-control,
    .filter-form > .form-select,
    .filter-form > button,
    .filter-form > .btn,
    .search-form > .form-control,
    .search-form > button,
    .search-form > .btn,
    .page-actions > .btn {
        flex: 1 1 auto;
        min-width: 0;
        width: 100%;
    }

    .form-actions,
    .preview-actions,
    .detail-header {
        align-items: stretch;
        flex-direction: column;
    }

    .form-actions .btn,
    .preview-actions .btn,
    .detail-header .btn {
        width: 100%;
    }

    .summary-card strong {
        font-size: 1.55rem;
    }
}

/* Definitive sidebar scroll behavior */
@media (min-width: 1201px) {
    .app-shell {
        display: block;
    }

    .app-shell::before {
        background: #0d1412;
        bottom: 0;
        content: "";
        left: 0;
        position: fixed;
        top: 0;
        width: 272px;
        z-index: 50;
    }

    .sidebar {
        bottom: 0;
        height: 100vh;
        height: 100dvh;
        left: 0;
        min-height: 100vh;
        overflow-y: auto;
        position: fixed;
        top: 0;
        width: 272px;
        z-index: 61;
    }

    .main-area {
        margin-left: 272px;
        min-height: 100vh;
    }
}

@media (min-width: 993px) and (max-width: 1200px) {
    .app-shell {
        display: block;
    }

    .app-shell::before {
        background: #0d1412;
        bottom: 0;
        content: "";
        left: 0;
        position: fixed;
        top: 0;
        width: 232px;
        z-index: 50;
    }

    .sidebar {
        bottom: 0;
        height: 100vh;
        height: 100dvh;
        left: 0;
        min-height: 100vh;
        overflow-y: auto;
        position: fixed;
        top: 0;
        width: 232px;
        z-index: 61;
    }

    .main-area {
        margin-left: 232px;
        min-height: 100vh;
    }
}

@media (max-width: 992px) {
    .app-shell {
        display: grid;
    }

    .app-shell::before {
        display: none;
    }

    .main-area {
        margin-left: 0;
    }
}

@media (max-width: 480px) {
    .sidebar {
        padding: 12px;
    }

    .brand {
        padding: 12px;
    }

    .brand-logo-photo {
        height: 54px;
        width: 54px;
    }

    .brand strong {
        font-size: 1rem;
    }

    .sidebar-nav {
        grid-template-columns: 1fr;
    }

    .sidebar-nav .nav-link {
        min-height: 42px;
    }

    .topbar h1 {
        font-size: 1.25rem;
    }

    .content {
        padding: 12px;
    }

    .page-actions,
    .form-panel,
    .preview-panel,
    .detail-panel,
    .summary-card,
    .report-card {
        border-radius: 9px;
    }

    .table > :not(caption) > * > * {
        padding: 0.68rem 0.72rem;
    }

    .table-panel .table {
        min-width: 680px;
    }
}

/* Final menu behavior: must remain after all responsive blocks. */
@media (min-width: 993px) {
    .sidebar {
        align-self: start;
        height: 100vh;
        overflow-y: auto;
        position: sticky;
        top: 0;
    }
}

@media (max-width: 992px) {
    .sidebar {
        background:
            linear-gradient(135deg, rgba(57, 181, 74, 0.1), transparent 260px),
            #111a17;
        border-bottom: 1px solid rgba(255, 255, 255, 0.08);
        box-shadow: 0 10px 28px rgba(15, 23, 42, 0.14);
        padding: 12px 12px 10px;
        position: sticky;
        top: 0;
        z-index: 50;
    }

    .brand {
        background: transparent;
        border: 0;
        margin: 0 0 10px;
        padding: 0;
    }

    .brand-logo-photo {
        height: 48px;
        width: 48px;
    }

    .brand strong {
        font-size: 1rem;
        line-height: 1.1;
    }

    .brand small {
        font-size: 0.78rem;
    }

    .sidebar-nav {
        display: flex !important;
        flex-direction: row;
        gap: 8px;
        grid-template-columns: none;
        margin: 0 -12px;
        overflow-x: auto;
        padding: 0 12px 4px;
        scrollbar-width: thin;
        -webkit-overflow-scrolling: touch;
    }

    .sidebar-nav .nav-link {
        border-radius: 999px;
        flex: 0 0 auto;
        font-size: 0.86rem;
        min-height: 38px;
        overflow: visible;
        padding: 8px 12px;
        text-overflow: clip;
        white-space: nowrap;
        width: auto;
    }

    .sidebar-nav .nav-link.active,
    .sidebar-nav .nav-link:hover {
        box-shadow: inset 0 -2px 0 var(--color-primary);
        transform: none;
    }

    .sidebar-nav .nav-link i {
        flex: 0 0 auto;
        font-size: 0.95rem;
        width: auto;
    }
}

@media (max-width: 520px) {
    .sidebar {
        padding: 10px 10px 8px;
    }

    .brand {
        gap: 9px;
    }

    .brand-logo-photo {
        height: 42px;
        width: 42px;
    }

    .sidebar-nav {
        margin: 0 -10px;
        padding: 0 10px 4px;
    }

    .sidebar-nav .nav-link {
        font-size: 0.82rem;
        min-height: 36px;
        padding: 8px 10px;
    }
}

/* Layout compactness fixes after visual review */
.content {
    align-items: stretch;
    display: flex;
    flex-direction: column;
    gap: 18px;
    justify-content: flex-start;
}

.page-actions {
    align-items: center;
    min-height: 0;
}

.search-form > .form-control,
.search-form > .form-select {
    flex: 1 1 220px;
    min-width: 160px;
}

.search-form > button,
.search-form > .btn {
    flex: 0 0 auto;
}

.form-panel,
.preview-panel,
.table-panel,
.detail-panel,
.summary-card,
.report-card,
.page-actions {
    align-self: stretch;
}

.form-panel > .row {
    align-items: flex-end;
}

@media (min-width: 993px) {
    .page-actions {
        grid-template-columns: minmax(0, 1fr) auto;
    }

    .search-form,
    .filter-form {
        flex-direction: row;
    }

    .page-actions > .btn {
        justify-self: end;
    }
}

@media (max-width: 720px) {
    .content {
        gap: 14px;
    }

    .page-actions {
        align-items: stretch;
    }

    .search-form > .form-control,
    .search-form > .form-select,
    .search-form > button,
    .search-form > .btn {
        flex: 1 1 auto;
        min-width: 0;
        width: 100%;
    }
}

/* Sidebar behavior refinement */
@media (min-width: 993px) {
    .sidebar {
        align-self: start;
        height: 100vh;
        overflow-y: auto;
        position: sticky;
        top: 0;
    }
}

@media (max-width: 992px) {
    .sidebar {
        background:
            linear-gradient(135deg, rgba(57, 181, 74, 0.1), transparent 260px),
            #111a17;
        border-bottom: 1px solid rgba(255, 255, 255, 0.08);
        box-shadow: 0 10px 28px rgba(15, 23, 42, 0.14);
        padding: 12px 12px 10px;
        position: sticky;
        top: 0;
        z-index: 50;
    }

    .brand {
        background: transparent;
        border: 0;
        margin: 0 0 10px;
        padding: 0;
    }

    .brand-logo-photo {
        height: 48px;
        width: 48px;
    }

    .brand strong {
        font-size: 1rem;
        line-height: 1.1;
    }

    .brand small {
        font-size: 0.78rem;
    }

    .sidebar-nav {
        display: flex !important;
        flex-direction: row;
        gap: 8px;
        margin: 0 -12px;
        overflow-x: auto;
        padding: 0 12px 4px;
        scrollbar-width: thin;
        -webkit-overflow-scrolling: touch;
    }

    .sidebar-nav .nav-link {
        border-radius: 999px;
        flex: 0 0 auto;
        font-size: 0.86rem;
        min-height: 38px;
        padding: 8px 12px;
        white-space: nowrap;
        width: auto;
    }

    .sidebar-nav .nav-link.active,
    .sidebar-nav .nav-link:hover {
        box-shadow: inset 0 -2px 0 var(--color-primary);
        transform: none;
    }

    .sidebar-nav .nav-link i {
        flex: 0 0 auto;
        font-size: 0.95rem;
        width: auto;
    }
}

@media (max-width: 520px) {
    .sidebar {
        padding: 10px 10px 8px;
    }

    .brand {
        gap: 9px;
    }

    .brand-logo-photo {
        height: 42px;
        width: 42px;
    }

    .sidebar-nav {
        margin: 0 -10px;
        padding: 0 10px 4px;
    }

    .sidebar-nav .nav-link {
        font-size: 0.82rem;
        min-height: 36px;
        padding: 8px 10px;
    }
}

/* BoxManager visual refresh for internal modules */
:root {
    --color-bg: #f5f7fa;
    --color-panel: #ffffff;
    --color-line: #dfe6ee;
    --color-text: #172033;
    --color-muted: #687385;
    --color-primary: #39B54A;
    --color-primary-dark: #1F7A35;
    --color-sidebar: #111a17;
    --color-accent: #2f7d6d;
    --shadow-panel: 0 10px 24px rgba(23, 32, 51, 0.06);
    --shadow-soft: 0 8px 18px rgba(23, 32, 51, 0.05);
}

body {
    background:
        radial-gradient(circle at 88% 4%, rgba(57, 181, 74, 0.12), transparent 28%),
        linear-gradient(180deg, #f8fafc 0%, #eef4f0 360px, #f5f7fa 100%);
    color: var(--color-text);
}

.app-shell {
    background: transparent;
}

.sidebar {
    background:
        linear-gradient(180deg, rgba(57, 181, 74, 0.08), transparent 220px),
        linear-gradient(180deg, #111a17 0%, #0d1412 100%);
    border-right: 1px solid rgba(255, 255, 255, 0.06);
    padding: 22px 18px;
}

.brand {
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 14px;
    padding: 14px;
}

.brand strong {
    color: #fff;
    font-size: 1.15rem;
    font-weight: 900;
}

.brand small {
    color: rgba(255, 255, 255, 0.62);
    font-weight: 700;
}

.brand-logo-photo {
    border-radius: 14px;
    height: 92px;
    width: 92px;
}

.sidebar-nav {
    gap: 6px;
}

.sidebar-nav .nav-link {
    border-radius: 10px;
    min-height: 44px;
    padding: 11px 12px;
}

.sidebar-nav .nav-link i {
    color: #9cff73;
}

.sidebar-nav .nav-link.active,
.sidebar-nav .nav-link:hover {
    background: rgba(255, 255, 255, 0.11);
    border-color: rgba(156, 255, 115, 0.18);
    box-shadow: inset 3px 0 0 var(--color-primary);
}

.topbar {
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(14px);
    border-bottom: 1px solid rgba(223, 230, 238, 0.92);
    min-height: 82px;
}

.topbar h1 {
    color: var(--color-text);
    font-size: 1.5rem;
    font-weight: 900;
}

.topbar span {
    color: var(--color-muted);
    font-weight: 700;
}

.content {
    display: grid;
    gap: 18px;
}

.app-footer {
    background: rgba(255, 255, 255, 0.62);
    border-top-color: rgba(223, 230, 238, 0.84);
    font-weight: 700;
}

.page-actions {
    align-items: stretch;
    background: #fff;
    border: 1px solid var(--color-line);
    border-radius: 10px;
    box-shadow: var(--shadow-panel);
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    margin-bottom: 0;
    padding: 14px;
}

.search-form,
.filter-form {
    align-items: center;
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    gap: 8px;
    min-width: 0;
    width: 100%;
}

.search-form .form-control {
    flex: 1 1 240px;
}

.filter-form > .form-control,
.filter-form > .form-select {
    flex: 1 1 145px;
    min-width: 130px;
}

.filter-form > input[type="search"] {
    flex-basis: 220px;
}

.filter-form > button,
.filter-form > .btn,
.search-form > button,
.search-form > .btn {
    flex: 0 0 auto;
    min-width: 96px;
    white-space: nowrap;
}

.page-actions > .btn {
    align-self: center;
    min-width: max-content;
    white-space: nowrap;
}

.summary-grid {
    margin-bottom: 0;
}

.summary-card {
    border-color: var(--color-line);
    border-radius: 10px;
    box-shadow: var(--shadow-panel);
    overflow: hidden;
    position: relative;
}

.summary-card::before {
    background: var(--color-primary);
    border-radius: 999px;
    content: "";
    display: block;
    height: 3px;
    margin-bottom: 14px;
    width: 44px;
}

.summary-card span {
    color: var(--color-muted);
    font-size: 0.76rem;
    font-weight: 850;
}

.summary-card strong {
    color: var(--color-text);
    font-size: 1.8rem;
    font-weight: 900;
}

.table-panel,
.form-panel,
.preview-panel,
.detail-panel,
.dashboard-panel,
.module-placeholder {
    border-color: var(--color-line);
    border-radius: 10px;
    box-shadow: var(--shadow-panel);
}

.table-panel {
    background: #fff;
}

.table-panel .table {
    --bs-table-color: var(--color-text);
}

.table-panel th {
    background: #f6f9f7;
    border-bottom-color: var(--color-line);
    color: #526174;
    font-size: 0.76rem;
    letter-spacing: 0;
}

.table-panel td {
    border-bottom-color: #edf1f5;
}

.table tbody tr {
    transition: background 0.16s ease, box-shadow 0.16s ease;
}

.table tbody tr:hover {
    background: #f8fcf9;
}

.table-panel td strong {
    color: var(--color-text);
    font-weight: 850;
}

.form-panel,
.preview-panel,
.detail-panel {
    padding: 24px;
}

.form-label {
    color: #253244;
    font-size: 0.88rem;
    font-weight: 800;
}

.form-control,
.form-select {
    background-color: #fbfcfd;
    border-color: var(--color-line);
    border-radius: 10px;
    font-size: 0.92rem;
    min-height: 40px;
    transition: border-color 0.16s ease, box-shadow 0.16s ease, background 0.16s ease;
}

.form-control:focus,
.form-select:focus {
    background-color: #fff;
    border-color: rgba(57, 181, 74, 0.62);
    box-shadow: 0 0 0 0.22rem rgba(57, 181, 74, 0.13);
}

.btn {
    border-radius: 10px;
    min-height: 40px;
    font-weight: 800;
    transition: background 0.16s ease, border-color 0.16s ease, color 0.16s ease, transform 0.16s ease, box-shadow 0.16s ease;
}

.btn:not(.btn-sm):hover {
    transform: translateY(-1px);
}

.btn-sm {
    border-radius: 8px;
    min-height: 32px;
    padding: 0.28rem 0.55rem;
    white-space: nowrap;
}

.inline-form {
    vertical-align: middle;
}

.table-panel .text-end {
    white-space: nowrap;
}

.btn-primary {
    --bs-btn-bg: var(--color-primary);
    --bs-btn-border-color: var(--color-primary);
    --bs-btn-hover-bg: var(--color-primary-dark);
    --bs-btn-hover-border-color: var(--color-primary-dark);
    --bs-btn-active-bg: var(--color-primary-dark);
    --bs-btn-active-border-color: var(--color-primary-dark);
    box-shadow: 0 10px 20px rgba(57, 181, 74, 0.2);
}

.btn-outline-primary {
    --bs-btn-color: var(--color-primary-dark);
    --bs-btn-border-color: rgba(57, 181, 74, 0.42);
    --bs-btn-hover-bg: var(--color-primary);
    --bs-btn-hover-border-color: var(--color-primary);
    --bs-btn-hover-color: #fff;
}

.btn-outline-secondary {
    --bs-btn-color: #405064;
    --bs-btn-border-color: #cfd8e3;
    --bs-btn-hover-bg: #edf7ef;
    --bs-btn-hover-border-color: rgba(57, 181, 74, 0.36);
    --bs-btn-hover-color: var(--color-primary-dark);
}

.alert {
    border: 0;
    border-radius: 10px;
    box-shadow: var(--shadow-soft);
    font-weight: 750;
}

.alert-success {
    background: #ecfdf3;
    color: #247d3a;
}

.alert-danger {
    background: #fff1f2;
    color: #b4232c;
}

.alert-warning {
    background: #fffbeb;
    color: #92400e;
}

.status-pill {
    background: #edf7ef;
    color: var(--color-primary-dark);
    font-weight: 850;
}

.empty-state,
.empty-inline {
    color: var(--color-muted);
    font-weight: 700;
}

.report-links {
    gap: 16px;
}

.report-card {
    border-color: var(--color-line);
    border-radius: 10px;
    box-shadow: var(--shadow-panel);
    min-height: 138px;
    overflow: hidden;
    position: relative;
    transition: border-color 0.16s ease, box-shadow 0.16s ease, transform 0.16s ease;
}

.report-card::after {
    background: rgba(57, 181, 74, 0.12);
    border-radius: 999px;
    content: "";
    height: 86px;
    position: absolute;
    right: -28px;
    top: -28px;
    width: 86px;
}

.report-card:hover {
    border-color: rgba(57, 181, 74, 0.56);
    box-shadow: 0 14px 32px rgba(23, 32, 51, 0.1);
    transform: translateY(-2px);
}

.report-card span {
    color: var(--color-primary-dark);
    font-weight: 900;
}

.report-card strong {
    color: #2f3b4c;
    line-height: 1.45;
}

.preview-header {
    border-bottom: 1px solid var(--color-line);
    padding-bottom: 16px;
}

.preview-header h2,
.detail-header h2,
.module-placeholder h2 {
    color: var(--color-text);
    font-weight: 900;
}

.detail-grid div {
    background: #fbfcfd;
    border-color: var(--color-line);
}

.box-option {
    background: #fbfcfd;
    transition: background 0.16s ease, border-color 0.16s ease;
}

.box-option:hover {
    background: #f7fbf8;
    border-color: rgba(57, 181, 74, 0.34);
}

@media (max-width: 1100px) {
    .page-actions {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 860px) {
    .brand {
        align-items: center;
        flex-direction: row;
    }

    .brand-logo-photo {
        height: 68px;
        width: 68px;
    }

    .content {
        gap: 14px;
    }

    .page-actions {
        gap: 12px;
    }

    .filter-form > .form-control,
    .filter-form > .form-select,
    .filter-form > button,
    .filter-form > .btn,
    .search-form > .form-control,
    .search-form > button,
    .search-form > .btn,
    .page-actions > .btn {
        flex: 1 1 100%;
        width: 100%;
    }

    .page-actions > .btn {
        justify-self: stretch;
        min-width: 0;
    }
}

/* Final responsive overrides: keep this block at the end of app.css. */
@media (max-width: 1200px) {
    .app-shell {
        grid-template-columns: 232px minmax(0, 1fr);
    }

    .content {
        padding: 22px;
    }

    .summary-grid,
    .report-links {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 992px) {
    html,
    body {
        overflow-x: hidden;
    }

    .app-shell {
        grid-template-columns: 1fr;
    }

    .sidebar {
        border-right: 0;
        padding: 16px;
    }

    .brand {
        align-items: center;
        flex-direction: row;
        margin-bottom: 14px;
    }

    .brand-logo-photo {
        height: 62px;
        width: 62px;
    }

    .sidebar-nav {
        display: grid !important;
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }

    .sidebar-nav .nav-link {
        min-width: 0;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .topbar {
        min-height: 72px;
        padding: 14px 18px;
    }

    .content {
        padding: 18px;
    }

    .page-actions {
        grid-template-columns: 1fr;
    }

    .page-actions > .btn {
        justify-self: start;
        min-width: max-content;
    }

    .detail-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 720px) {
    .sidebar-nav {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .topbar {
        align-items: stretch;
        flex-direction: column;
        gap: 12px;
    }

    .topbar form,
    .topbar .btn {
        width: 100%;
    }

    .content {
        padding: 14px;
    }

    .summary-grid,
    .report-links,
    .detail-grid {
        grid-template-columns: 1fr;
    }

    .page-actions,
    .form-panel,
    .preview-panel,
    .detail-panel {
        padding: 16px;
    }

    .search-form,
    .filter-form {
        align-items: stretch;
        flex-direction: column;
    }

    .filter-form > .form-control,
    .filter-form > .form-select,
    .filter-form > button,
    .filter-form > .btn,
    .search-form > .form-control,
    .search-form > button,
    .search-form > .btn,
    .page-actions > .btn {
        flex: 1 1 auto;
        min-width: 0;
        width: 100%;
    }

    .form-actions,
    .preview-actions,
    .detail-header {
        align-items: stretch;
        flex-direction: column;
    }

    .form-actions .btn,
    .preview-actions .btn,
    .detail-header .btn {
        width: 100%;
    }

    .box-selector {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 480px) {
    .sidebar {
        padding: 12px;
    }

    .brand {
        padding: 12px;
    }

    .brand-logo-photo {
        height: 54px;
        width: 54px;
    }

    .brand strong {
        font-size: 1rem;
    }

    .sidebar-nav {
        grid-template-columns: 1fr;
    }

    .topbar h1 {
        font-size: 1.25rem;
    }

    .content {
        padding: 12px;
    }

    .table > :not(caption) > * > * {
        padding: 0.68rem 0.72rem;
    }

    .table-panel .table {
        min-width: 680px;
    }
}

/* Final menu behavior: must remain after all responsive blocks. */
@media (min-width: 993px) {
    .sidebar {
        align-self: start;
        height: 100vh;
        overflow-y: auto;
        position: sticky;
        top: 0;
    }
}

@media (max-width: 992px) {
    .sidebar {
        background:
            linear-gradient(135deg, rgba(57, 181, 74, 0.1), transparent 260px),
            #111a17;
        border-bottom: 1px solid rgba(255, 255, 255, 0.08);
        box-shadow: 0 10px 28px rgba(15, 23, 42, 0.14);
        padding: 12px 12px 10px;
        position: sticky;
        top: 0;
        z-index: 50;
    }

    .brand {
        background: transparent;
        border: 0;
        margin: 0 0 10px;
        padding: 0;
    }

    .brand-logo-photo {
        height: 48px;
        width: 48px;
    }

    .brand strong {
        font-size: 1rem;
        line-height: 1.1;
    }

    .brand small {
        font-size: 0.78rem;
    }

    .sidebar-nav {
        display: flex !important;
        flex-direction: row;
        gap: 8px;
        grid-template-columns: none;
        margin: 0 -12px;
        overflow-x: auto;
        padding: 0 12px 4px;
        scrollbar-width: thin;
        -webkit-overflow-scrolling: touch;
    }

    .sidebar-nav .nav-link {
        border-radius: 999px;
        flex: 0 0 auto;
        font-size: 0.86rem;
        min-height: 38px;
        overflow: visible;
        padding: 8px 12px;
        text-overflow: clip;
        white-space: nowrap;
        width: auto;
    }

    .sidebar-nav .nav-link.active,
    .sidebar-nav .nav-link:hover {
        box-shadow: inset 0 -2px 0 var(--color-primary);
        transform: none;
    }

    .sidebar-nav .nav-link i {
        flex: 0 0 auto;
        font-size: 0.95rem;
        width: auto;
    }
}

@media (max-width: 520px) {
    .sidebar {
        padding: 10px 10px 8px;
    }

    .brand {
        gap: 9px;
    }

    .brand-logo-photo {
        height: 42px;
        width: 42px;
    }

    .sidebar-nav {
        margin: 0 -10px;
        padding: 0 10px 4px;
    }

    .sidebar-nav .nav-link {
        font-size: 0.82rem;
        min-height: 36px;
        padding: 8px 10px;
    }
}

/* Final compactness overrides: keep as the last block. */
.content {
    align-items: stretch;
    display: flex;
    flex-direction: column;
    gap: 18px;
    justify-content: flex-start;
}

.page-actions {
    align-items: center;
    min-height: 0;
}

.search-form > .form-control,
.search-form > .form-select {
    flex: 1 1 220px;
    min-width: 160px;
}

.search-form > button,
.search-form > .btn {
    flex: 0 0 auto;
}

.form-panel,
.preview-panel,
.table-panel,
.detail-panel,
.summary-card,
.report-card,
.page-actions {
    align-self: stretch;
}

.form-panel > .row {
    align-items: flex-end;
}

@media (min-width: 993px) {
    .page-actions {
        grid-template-columns: minmax(0, 1fr) auto;
    }

    .search-form,
    .filter-form {
        flex-direction: row;
    }

    .page-actions > .btn {
        justify-self: end;
    }
}

@media (max-width: 720px) {
    .content {
        gap: 14px;
    }

    .page-actions {
        align-items: stretch;
    }

    .search-form > .form-control,
    .search-form > .form-select,
    .search-form > button,
    .search-form > .btn {
        flex: 1 1 auto;
        min-width: 0;
        width: 100%;
    }
}

/* Definitive sidebar scroll behavior: keep as the last block. */
@media (min-width: 1201px) {
    .app-shell {
        display: block;
    }

    .app-shell::before {
        background: #0d1412;
        bottom: 0;
        content: "";
        left: 0;
        position: fixed;
        top: 0;
        width: 272px;
        z-index: 50;
    }

    .sidebar {
        bottom: 0;
        height: 100vh;
        height: 100dvh;
        left: 0;
        min-height: 100vh;
        overflow-y: auto;
        position: fixed;
        top: 0;
        width: 272px;
        z-index: 61;
    }

    .main-area {
        margin-left: 272px;
        min-height: 100vh;
    }
}

@media (min-width: 993px) and (max-width: 1200px) {
    .app-shell {
        display: block;
    }

    .app-shell::before {
        background: #0d1412;
        bottom: 0;
        content: "";
        left: 0;
        position: fixed;
        top: 0;
        width: 232px;
        z-index: 50;
    }

    .sidebar {
        bottom: 0;
        height: 100vh;
        height: 100dvh;
        left: 0;
        min-height: 100vh;
        overflow-y: auto;
        position: fixed;
        top: 0;
        width: 232px;
        z-index: 61;
    }

    .main-area {
        margin-left: 232px;
        min-height: 100vh;
    }
}

@media (max-width: 992px) {
    .app-shell {
        display: grid;
    }

    .app-shell::before {
        display: none;
    }

    .main-area {
        margin-left: 0;
    }
}
