:root {
    --shell-bg: #f4f6fb;
    --shell-text: #182236;
    --sidebar-bg: linear-gradient(180deg, #10192c 0%, #0d1222 100%);
    --card-bg: #ffffff;
    --card-border: #e7ebf4;
    --muted: #6b7384;
    --success-soft: #d8f8e5;
    --success-text: #1d7a47;
    --danger-soft: #fee2e6;
    --danger-text: #9f2642;
    --neutral-soft: #eef1f6;
    --neutral-text: #4f596d;
}

html,
body {
    width: 100%;
    min-height: 100%;
    margin: 0;
    background: radial-gradient(circle at 15% 20%, #fdf8da 0%, #f4f6fb 42%);
    color: var(--shell-text);
}

body:has(.mrj-v3) {
    background: #f6f8fb;
}

body:has(.mrj-v3) .app-content {
    padding: 0;
}

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

.app-sidebar {
    width: 214px;
    background: var(--sidebar-bg);
    color: #e7ecfa;
    padding: 0.58rem 0.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    position: sticky;
    top: 0;
    min-height: 100vh;
    max-height: 100vh;
    overflow: hidden;
}

.sidebar-brand {
    padding: 0.16rem 0.22rem 0.1rem;
}

.brand-block {
    display: flex;
    align-items: center;
    gap: 0.56rem;
}

.brand-name {
    font-size: 1.01rem;
    line-height: 1;
    font-weight: 650;
}

.brand-home-icon {
    display: none;
    width: 1.85rem;
    height: 1.85rem;
    border-radius: 0.62rem;
    border: 1px solid rgba(255, 255, 255, 0.16);
    background: rgba(255, 255, 255, 0.08);
    align-items: center;
    justify-content: center;
    font-size: 0.92rem;
}

.brand-link {
    color: inherit;
    text-decoration: none;
}

.brand-link:hover {
    color: inherit;
    text-decoration: none;
}

.brand-dot {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: #f2b705;
    box-shadow: 0 0 0 4px rgba(242, 183, 5, 0.24);
}

.brand-subtitle {
    margin: 0.38rem 0 0;
    font-size: 0.74rem;
    color: #a4acc5;
}

.sidebar-nav-wrap {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    overflow-x: hidden;
}

.sidebar-nav-shell {
    display: flex;
    flex-direction: column;
    min-height: 100%;
}

.sidebar-nav {
    gap: 0.14rem;
    width: 100%;
    margin: 0;
}

.sidebar-primary {
    margin-top: 0.12rem;
}

.sidebar-secondary {
    margin-top: auto;
    padding-top: 0.28rem;
    position: sticky;
    bottom: 0;
    z-index: 2;
    background: linear-gradient(180deg, rgba(13, 18, 34, 0) 0%, rgba(13, 18, 34, 0.96) 36%);
    padding-bottom: 0.18rem;
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 0.42rem;
    border-radius: 0.66rem;
    padding: 0.45rem 0.52rem;
    font-size: 0.91rem;
    font-weight: 500;
}

.sidebar-link .bi {
    width: 1rem;
    text-align: center;
    font-size: 0.95rem;
}

.sidebar-link.active {
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
}

.sidebar-link:hover {
    background: rgba(255, 255, 255, 0.08);
    color: #fff;
}

.sidebar-controls {
    margin-top: auto;
    padding-top: 0.24rem;
    position: sticky;
    bottom: 0;
    z-index: 3;
    background: linear-gradient(180deg, rgba(13, 18, 34, 0) 0%, rgba(13, 18, 34, 0.96) 38%);
}

.sidebar-toggle {
    border: 1px solid rgba(212, 220, 241, 0.25);
    background: rgba(255, 255, 255, 0.06);
    color: #e7ecfa;
    border-radius: 0.75rem;
    padding: 0.4rem 0.5rem;
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
}

.sidebar-toggle:hover {
    background: rgba(255, 255, 255, 0.14);
}

.sidebar-toggle-top {
    color: #2d3a58;
    border-color: #d7deec;
    background: #fff;
}

.sidebar-toggle-bottom {
    margin-top: 0.1rem;
    width: 100%;
    justify-content: center;
}

.app-shell.sidebar-collapsed .app-sidebar {
    width: 68px;
    padding: 0.56rem 0.34rem;
    align-items: center;
}

.app-shell.sidebar-collapsed .brand-subtitle,
.app-shell.sidebar-collapsed .brand-name,
.app-shell.sidebar-collapsed .nav-text {
    display: none;
}

.app-shell.sidebar-collapsed .brand-dot {
    display: none;
}

.app-shell.sidebar-collapsed .brand-home-icon {
    display: inline-flex;
}

.app-shell.sidebar-collapsed .brand-block {
    justify-content: center;
}

.app-shell.sidebar-collapsed .sidebar-link {
    justify-content: center;
    padding: 0.38rem;
    width: 2.45rem;
    height: 2.45rem;
    margin-inline: auto;
    border-radius: 0.78rem;
}

.app-shell.sidebar-collapsed .sidebar-link .bi {
    margin-right: 0 !important;
    font-size: 1.05rem;
}

.app-shell.sidebar-collapsed .sidebar-toggle-bottom {
    width: 100%;
}

.app-shell.sidebar-collapsed .sidebar-toggle {
    padding: 0.38rem;
    justify-content: center;
}

.app-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.app-header {
    min-height: 56px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: rgba(255, 255, 255, 0.7);
    border-bottom: 1px solid var(--card-border);
    padding: 0 1.3rem;
    backdrop-filter: blur(6px);
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.header-user {
    font-weight: 500;
}

.header-date {
    margin-left: 0.25rem;
}

.app-content {
    padding: 1.3rem;
}

.app-footer {
    margin-top: auto;
    padding: 0.8rem 1.3rem;
    border-top: 1px solid var(--card-border);
    font-size: 0.85rem;
    color: var(--muted);
    display: flex;
    justify-content: space-between;
}

.surface-card {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 16px;
    box-shadow: 0 10px 24px rgba(20, 32, 62, 0.05);
}

.kpi-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 0.9rem;
}

.public-page-actions,
.access-links {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.public-data-summary {
    display: grid;
    grid-template-columns: minmax(0, 2fr) minmax(12rem, 1fr);
    gap: 0.9rem;
}

.public-coverage-card,
.public-readings-card {
    padding: 1rem;
}

.public-coverage-card {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    align-items: end;
}

.public-data-eyebrow {
    margin: 0 0 0.25rem;
    color: var(--muted);
    font-size: 0.8rem;
    font-weight: 700;
    letter-spacing: 0.02em;
    text-transform: uppercase;
}

.public-coverage-card h2 {
    margin: 0;
    font-size: clamp(1.8rem, 4vw, 2.5rem);
}

.public-coverage-card h2 span {
    color: var(--muted);
    font-weight: 500;
}

.public-coverage-meter {
    min-width: min(16rem, 44%);
}

.public-coverage-meter strong {
    display: block;
    margin-bottom: 0.35rem;
    text-align: right;
}

.public-readings-card {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.public-readings-card > .bi {
    color: #0b5ed7;
    font-size: 1.5rem;
}

.public-readings-card strong {
    font-size: 1.75rem;
}

.public-filter-feedback {
    min-height: 1.5rem;
    margin: -0.25rem 0 0.9rem;
    color: var(--muted);
    font-size: 0.875rem;
}

.access-links {
    margin-top: 1rem;
    justify-content: space-between;
    font-size: 0.9rem;
}

.kpi-card {
    border-radius: 16px;
    background: linear-gradient(180deg, #ffffff 0%, #fbfdff 100%);
    border: 1px solid #e6ebf5;
    padding: 1rem 1.1rem;
}

.kpi-label {
    font-size: 0.82rem;
    color: var(--muted);
    margin-bottom: 0.25rem;
}

.kpi-value {
    font-size: 1.9rem;
    font-weight: 700;
    line-height: 1.1;
}

.kpi-subtitle {
    margin-top: 0.35rem;
    color: var(--muted);
    font-size: 0.8rem;
}

.status-pill {
    font-size: 0.78rem;
    font-weight: 600;
    padding: 0.35rem 0.6rem;
    border-radius: 999px;
}

.status-success {
    background: var(--success-soft);
    color: var(--success-text);
}

.status-danger {
    background: var(--danger-soft);
    color: var(--danger-text);
}

.status-neutral {
    background: var(--neutral-soft);
    color: var(--neutral-text);
}

.table-modern thead th {
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--muted);
    border-bottom-width: 1px;
}

.table-modern td {
    vertical-align: middle;
}

.utility-card {
    border: 1px solid var(--card-border);
    border-radius: 14px;
    padding: 0.8rem 0.95rem;
    background: #fff;
}

.form-panel {
    border: 1px solid var(--card-border);
    background: #fff;
    border-radius: 16px;
    padding: 1rem;
}

/* Primary input highlight - guides user to main data entry */
.reading-value-primary {
    background: linear-gradient(135deg, #f0f7ff 0%, #e8f4fd 100%);
    border: 2px solid #0d6efd;
    border-radius: 8px;
}
.reading-value-primary:focus {
    background: #fff;
    border-color: #0d6efd;
    box-shadow: 0 0 0 0.25rem rgba(13, 110, 253, 0.15);
}

.auth-wrap {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 1rem;
}

.auth-card {
    width: min(520px, 100%);
}

/* Mobile: sidebar overlay backdrop */
.sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(7, 12, 28, 0.5);
    z-index: 1040;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
}

.sidebar-backdrop.show {
    opacity: 1;
    pointer-events: auto;
}

.sidebar-hamburger {
    display: none;
    align-items: center;
    justify-content: center;
    width: 2.75rem;
    height: 2.75rem;
    padding: 0;
    border: 1px solid var(--card-border);
    border-radius: 0.5rem;
    background: #fff;
    color: var(--shell-text);
    font-size: 1.25rem;
}

.sidebar-hamburger:hover {
    background: var(--neutral-soft);
}

@media (max-width: 991.98px) {
    html,
    body {
        max-width: 100%;
        overflow-x: clip;
        overflow-clip-margin: 0;
    }

    .app-shell {
        flex-direction: column;
        width: 100%;
        max-width: 100vw;
        overflow-x: clip;
    }

    .table-responsive {
        max-width: 100%;
        overflow-x: auto;
        overscroll-behavior-inline: contain;
        contain: inline-size paint;
    }

    .sidebar-hamburger {
        display: flex;
    }

    .sidebar-backdrop {
        display: block;
    }

    .app-sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        z-index: 1050;
        width: 280px;
        max-width: 85vw;
        min-height: 100vh;
        transform: none;
        visibility: hidden;
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.2s ease, visibility 0s linear 0.2s;
        box-shadow: none;
    }

    .app-shell.mobile-menu-open .app-sidebar {
        visibility: visible;
        opacity: 1;
        pointer-events: auto;
        transition: opacity 0.2s ease;
        box-shadow: 8px 0 24px rgba(0, 0, 0, 0.25);
    }

    .app-shell.mobile-menu-open .sidebar-backdrop {
        pointer-events: auto;
    }

    .app-shell.sidebar-collapsed .app-sidebar {
        width: 280px;
        padding: 0.58rem 0.5rem;
        align-items: stretch;
    }

    .app-shell.sidebar-collapsed .brand-subtitle,
    .app-shell.sidebar-collapsed .brand-name,
    .app-shell.sidebar-collapsed .nav-text {
        display: block;
    }

    .app-shell.sidebar-collapsed .brand-dot {
        display: block;
    }

    .app-shell.sidebar-collapsed .brand-home-icon {
        display: none;
    }

    .app-shell.sidebar-collapsed .brand-block {
        justify-content: flex-start;
    }

    .app-shell.sidebar-collapsed .sidebar-link {
        justify-content: flex-start;
        padding: 0.45rem 0.52rem;
        width: auto;
        height: auto;
        margin-inline: 0;
    }

    .sidebar-nav {
        flex-direction: column;
        flex-wrap: nowrap;
        overflow-x: visible;
        overflow-y: auto;
    }

    .sidebar-nav .nav-item {
        flex: 0 0 auto;
    }

    .sidebar-controls {
        display: none;
    }

    .app-header {
        height: auto;
        min-height: 56px;
        padding: 0.8rem 0.9rem;
        gap: 0.65rem;
        flex-wrap: wrap;
    }

    .header-actions {
        flex: 1;
        justify-content: flex-end;
        flex-wrap: wrap;
    }

    .header-date {
        margin-left: 0;
    }

    .kpi-grid {
        grid-template-columns: 1fr 1fr;
    }
}

@media (max-width: 767.98px) {
    .public-data-summary {
        grid-template-columns: 1fr;
    }

    .public-coverage-card {
        align-items: stretch;
        flex-direction: column;
    }

    .public-coverage-meter {
        min-width: 0;
    }

    .kpi-grid {
        grid-template-columns: 1fr;
    }

    .app-content {
        padding: 0.85rem;
    }

    .sidebar-link {
        padding: 0.58rem 0.7rem;
        font-size: 0.9rem;
        white-space: nowrap;
    }

    .auth-wrap {
        align-items: flex-start;
        padding-top: 2rem;
    }
}
:where(a, button, input, select, textarea, summary, [tabindex]):focus-visible {
    outline: 3px solid #0b5ed7;
    outline-offset: 3px;
    box-shadow: 0 0 0 3px rgba(11, 94, 215, 0.22);
}

@media (max-width: 767.98px) {
    :where(.btn, .nav-link, button, summary, .form-select) {
        min-height: 44px;
    }

    .table-responsive:has(> .role-dashboard-mobile-cards) {
        overflow-x: visible;
        contain: none;
    }

    .role-dashboard-mobile-cards,
    .role-dashboard-mobile-cards tbody,
    .role-dashboard-mobile-cards tr,
    .role-dashboard-mobile-cards td {
        display: block;
        width: 100%;
    }

    .role-dashboard-mobile-cards thead {
        display: none;
    }

    .role-dashboard-mobile-cards tbody {
        display: grid;
        gap: 0.85rem;
    }

    .role-dashboard-mobile-cards tbody tr {
        border: 1px solid var(--card-border);
        border-radius: 12px;
        padding: 0.65rem 0.75rem;
        background: #fff;
    }

    .role-dashboard-mobile-cards td {
        display: grid;
        grid-template-columns: minmax(7rem, 42%) minmax(0, 1fr);
        gap: 0.65rem;
        align-items: start;
        padding: 0.45rem 0;
        border-bottom: 1px solid var(--card-border);
        overflow-wrap: anywhere;
    }

    .role-dashboard-mobile-cards td::before {
        content: attr(data-label);
        color: var(--muted);
        font-size: 0.75rem;
        font-weight: 700;
        letter-spacing: 0.04em;
        text-transform: uppercase;
    }

    .role-dashboard-mobile-cards td:last-child {
        border-bottom: 0;
    }

    .role-dashboard-mobile-cards td[colspan] {
        display: block;
    }

    .role-dashboard-mobile-cards td[colspan]::before {
        content: none;
    }

    .role-dashboard-mobile-cards td .d-flex {
        min-width: 0;
    }

    .report-review-mobile-cards .mobile-card-actions {
        grid-template-columns: 1fr;
    }

    .report-review-mobile-cards .review-queue-primary-action {
        display: flex;
        width: 100%;
        justify-content: center;
    }
}
