:root {
    --sidebar-width: 272px;
    --body-bg: #f3f6fb;
    --surface: #ffffff;
    --surface-soft: #f8fafc;
    --sidebar-bg: #18202b;
    --sidebar-active: #2f80ed;
    --accent-teal: #0f9f8f;
    --accent-amber: #f59e0b;
    --text-main: #162033;
    --text-muted: #64748b;
    --panel-border: #e2e8f0;
    --shadow-soft: 0 12px 28px rgba(15, 23, 42, 0.07);
    --shadow-panel: 0 8px 20px rgba(15, 23, 42, 0.05);
    --radius: 8px;
}

* {
    box-sizing: border-box;
}

html {
    min-width: 320px;
}

body {
    margin: 0;
    min-height: 100vh;
    background: var(--body-bg);
    color: var(--text-main);
    font-family: Arial, Helvetica, sans-serif;
    line-height: 1.45;
    overflow-x: hidden;
}

a {
    color: var(--sidebar-active);
}

.alert code {
    color: inherit;
}

.app-shell {
    min-height: 100vh;
    display: grid;
    grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
}

.sidebar {
    min-height: 100vh;
    background: var(--sidebar-bg);
    color: #fff;
    padding: 22px 16px;
    position: sticky;
    top: 0;
    overflow-y: auto;
    z-index: 20;
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    padding-bottom: 20px;
    margin-bottom: 14px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.12);
    min-width: 0;
}

.brand-mark {
    width: 48px;
    height: 48px;
    display: grid;
    place-items: center;
    flex: 0 0 auto;
    border-radius: 12px;
    overflow: hidden;
    background: transparent;
    box-shadow: 0 10px 22px rgba(0, 0, 0, 0.22);
}

.brand-mark img {
    display: block;
    width: 100%;
    height: 100%;
}

.brand strong,
.brand span {
    display: block;
}

.brand strong {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.brand span {
    color: rgba(255, 255, 255, 0.68);
    font-size: 0.82rem;
}

.sidebar .nav {
    min-width: 0;
}

.sidebar .nav-link {
    color: rgba(255, 255, 255, 0.78);
    border-radius: var(--radius);
    padding: 10px 12px;
    font-weight: 700;
    letter-spacing: 0;
    min-height: 42px;
    display: flex;
    align-items: center;
}

.sidebar .nav-link:hover,
.sidebar .nav-link.active {
    color: #fff;
    background: rgba(47, 128, 237, 0.22);
}

.sidebar .nav-link.active {
    box-shadow: inset 3px 0 0 var(--accent-teal);
}

.main-content {
    min-width: 0;
    width: 100%;
    padding: 28px;
}

.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 18px;
    margin-bottom: 24px;
}

.topbar > div:first-child {
    min-width: 0;
}

.topbar h1 {
    margin: 0;
    color: var(--text-main);
    font-size: 1.75rem;
    font-weight: 800;
    letter-spacing: 0;
    line-height: 1.18;
}

.eyebrow {
    color: var(--text-muted);
    text-transform: uppercase;
    font-size: 0.75rem;
    font-weight: 800;
    letter-spacing: 0.08em;
}

.user-menu {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 12px;
    text-align: right;
    min-width: 0;
}

.user-menu strong,
.user-menu span {
    display: block;
}

.user-menu strong {
    max-width: 180px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.user-menu span {
    color: var(--text-muted);
    font-size: 0.82rem;
}

.login-page {
    min-height: 100vh;
    background:
        linear-gradient(180deg, rgba(47, 128, 237, 0.08), rgba(15, 159, 143, 0.06)),
        var(--body-bg);
}

.login-shell {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
}

.login-panel {
    width: min(100%, 420px);
    background: var(--surface);
    border: 1px solid var(--panel-border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-soft);
    padding: 28px;
}

.login-brand {
    color: var(--text-main);
    border-bottom-color: var(--panel-border);
    margin-bottom: 24px;
}

.login-brand span {
    color: var(--text-muted);
}

.login-panel h1 {
    font-size: 1.55rem;
    font-weight: 800;
    margin-bottom: 18px;
    letter-spacing: 0;
}

.metric-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.dashboard-grid {
    display: grid;
    grid-template-columns: minmax(0, 1.25fr) minmax(300px, 0.75fr);
    gap: 16px;
}

.metric-card,
.content-panel {
    background: var(--surface);
    border: 1px solid var(--panel-border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-panel);
}

.metric-card {
    padding: 18px;
    min-width: 0;
}

.metric-card span {
    display: block;
    color: var(--text-muted);
    font-size: 0.88rem;
    font-weight: 700;
    margin-bottom: 8px;
}

.metric-card strong {
    display: block;
    color: var(--text-main);
    font-size: 1.65rem;
    line-height: 1.18;
}

.dashboard-choice-grid {
    margin-bottom: 18px;
}

.dashboard-tabs {
    gap: 8px;
    margin-bottom: 18px;
    overflow-x: auto;
    padding-bottom: 2px;
    flex-wrap: nowrap;
}

.dashboard-tabs .nav-link {
    border: 1px solid var(--panel-border);
    color: var(--text-main);
    background: var(--surface);
    border-radius: var(--radius);
    font-weight: 800;
    white-space: nowrap;
}

.dashboard-tabs .nav-link.active {
    border-color: var(--sidebar-active);
    background: var(--sidebar-active);
    color: #fff;
}

.dashboard-tab-content {
    min-height: 320px;
}

.dashboard-group-table {
    margin-bottom: 0;
}

.dashboard-filter {
    max-width: 420px;
    margin-bottom: 18px;
}

.dashboard-filter-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 8px;
}

.dashboard-filter-header .form-label {
    margin-bottom: 0;
}

.dashboard-selected-results {
    min-height: 220px;
}

.dashboard-empty-state,
.scanner-empty-state,
.scanner-mini-empty {
    display: grid;
    place-items: center;
    min-height: 180px;
    border: 1px dashed var(--panel-border);
    border-radius: var(--radius);
    color: var(--text-muted);
    text-align: center;
    background: var(--surface-soft);
    padding: 18px;
}

.dashboard-result-heading {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    margin-bottom: 12px;
}

.dashboard-result-heading h3 {
    font-size: 1rem;
    font-weight: 800;
    margin: 0 0 2px;
    letter-spacing: 0;
}

.dashboard-result-heading p {
    color: var(--text-muted);
    margin: 0;
}

.dashboard-report-menu {
    flex: 0 0 auto;
}

.encoder-privacy-mode {
    user-select: none;
}

.encoder-privacy-mode input,
.encoder-privacy-mode textarea,
.encoder-privacy-mode select {
    user-select: text;
}

.encoder-watermark-grid {
    position: fixed;
    inset: 0;
    z-index: 2147483647;
    pointer-events: none;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    grid-auto-rows: 150px;
    align-items: center;
    justify-items: center;
    overflow: hidden;
}

.encoder-watermark-grid span {
    color: rgba(31, 41, 55, 0.13);
    font-size: 24px;
    font-weight: 800;
    letter-spacing: 0;
    text-align: center;
    transform: rotate(-24deg);
    white-space: pre-wrap;
}

@media print {
    .encoder-privacy-mode * {
        visibility: hidden !important;
    }

    .encoder-privacy-mode::after {
        content: "Printing is disabled for Encoder accounts.";
        position: fixed;
        top: 48px;
        left: 48px;
        right: 48px;
        visibility: visible !important;
        color: #111827;
        font-size: 18px;
        font-weight: 700;
    }
}

.duplicate-list {
    display: grid;
    gap: 10px;
    margin-top: 12px;
    max-height: 360px;
    overflow-y: auto;
    text-align: left;
}

.duplicate-record {
    border: 1px solid var(--panel-border);
    border-radius: var(--radius);
    padding: 12px;
    background: var(--surface-soft);
}

.duplicate-record strong,
.duplicate-record span {
    display: block;
}

.duplicate-record strong {
    margin-bottom: 6px;
}

.duplicate-record span {
    color: var(--text-muted);
    font-size: 0.88rem;
}

.modal-subtitle {
    color: var(--text-muted);
    font-size: 0.88rem;
}

.recipient-summary {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 14px;
}

.recipient-filter {
    font-weight: 800;
}

.content-panel {
    padding: 20px;
    min-width: 0;
}

.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    margin-bottom: 18px;
}

.panel-header > div {
    min-width: 0;
}

.panel-header h2 {
    margin: 0 0 4px;
    color: var(--text-main);
    font-size: 1.15rem;
    font-weight: 800;
    letter-spacing: 0;
}

.panel-header p {
    margin: 0;
    color: var(--text-muted);
}

.table-responsive {
    width: 100%;
}

.table {
    color: var(--text-main);
}

.table > :not(caption) > * > * {
    padding: 0.82rem 0.72rem;
    vertical-align: middle;
}

.table thead th {
    color: #0f172a;
    font-size: 0.82rem;
    font-weight: 800;
    white-space: nowrap;
    background: #f8fafc;
}

.table tbody td {
    color: var(--text-main);
}

.dataTables_wrapper {
    width: 100%;
}

.dataTables_wrapper .row {
    row-gap: 12px;
    align-items: center;
}

.dataTables_wrapper .dataTables_length select {
    min-width: 76px;
}

.dataTables_wrapper .dataTables_filter input {
    max-width: 100%;
}

.dataTables_wrapper .dataTables_paginate .pagination {
    flex-wrap: wrap;
    gap: 4px;
}

.dataTables_wrapper .dataTables_paginate .page-link {
    border-radius: 6px;
}

table.dataTable.dtr-inline.collapsed > tbody > tr > td.dtr-control:before,
table.dataTable.dtr-inline.collapsed > tbody > tr > th.dtr-control:before {
    border: 0;
    background: var(--sidebar-active);
    box-shadow: none;
}

.dtr-details {
    width: 100%;
}

.table-name {
    font-weight: 800;
}

.table-subtext {
    color: var(--text-muted);
    display: block;
    font-size: 0.82rem;
    margin-top: 2px;
}

.table-name-button {
    color: var(--sidebar-active);
    font-weight: 800;
    text-align: left;
    text-decoration: none;
}

.table-name-button:hover {
    text-decoration: underline;
}

.status-badges {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}

.residence-status-option {
    min-height: 86px;
    border: 1px solid var(--panel-border);
    border-radius: var(--radius);
    background: var(--surface-soft);
    padding: 12px;
}

.residence-status-option .form-check-input {
    margin-right: 8px;
}

.residence-status-option .form-check-label {
    font-weight: 800;
}

.residence-status-option span {
    display: block;
    color: var(--text-muted);
    font-size: 0.86rem;
    margin-top: 5px;
}

.history-list {
    display: grid;
    gap: 14px;
}

.history-item {
    border: 1px solid var(--panel-border);
    border-radius: var(--radius);
    padding: 14px;
    background: var(--surface);
}

.history-item-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 16px;
}

.history-item-header > div {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
}

.history-item-header > span {
    color: var(--text-muted);
    font-size: 0.88rem;
    white-space: nowrap;
}

.history-section-title {
    font-size: 0.92rem;
    font-weight: 800;
    margin: 14px 0 8px;
}

.history-change-table td,
.history-change-table th {
    min-width: 160px;
}

.residence-qr-card {
    display: grid;
    gap: 14px;
    justify-items: center;
    text-align: center;
}

.residence-qr-card h6 {
    color: var(--text-main);
    font-size: 1.05rem;
    font-weight: 800;
    margin: 0 0 4px;
}

.residence-qr-card p {
    color: var(--text-muted);
    margin: 0;
}

.residence-qr-box {
    background: var(--surface);
    border: 1px solid var(--panel-border);
    border-radius: var(--radius);
    padding: 14px;
}

.residence-qr-box img,
.residence-qr-box canvas {
    display: block;
    max-width: 100%;
    height: auto;
}

#residenceQrLink {
    font-size: 0.78rem;
    overflow-wrap: anywhere;
}

.scanner-layout {
    display: grid;
    grid-template-columns: minmax(320px, 420px) minmax(0, 1fr);
    gap: 16px;
    align-items: start;
}

.scanner-reader-shell {
    display: grid;
    gap: 12px;
}

#aidQrReader {
    min-height: 320px;
    border: 1px dashed #cbd5e1;
    border-radius: var(--radius);
    background: var(--surface-soft);
    overflow: hidden;
}

#aidQrReader video {
    max-width: 100%;
}

.scanner-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.scanner-note {
    color: var(--text-muted);
    font-size: 0.9rem;
    margin: 0;
}

.scanner-resident-card {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    border-left: 4px solid var(--sidebar-active);
    border-radius: var(--radius);
    background: var(--surface-soft);
    padding: 14px;
    margin-bottom: 18px;
}

.scanner-resident-card h2 {
    margin: 4px 0;
    font-size: 1.3rem;
    font-weight: 800;
}

.scanner-resident-card p {
    margin: 0;
    color: var(--text-muted);
}

.scanner-section {
    margin-top: 18px;
}

.scanner-section h3 {
    font-size: 1rem;
    font-weight: 800;
    margin-bottom: 10px;
}

.scanner-aid-list {
    display: grid;
    gap: 10px;
}

.scanner-aid-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    border: 1px solid var(--panel-border);
    border-radius: var(--radius);
    padding: 12px;
    background: var(--surface);
}

.scanner-aid-item div {
    display: grid;
    gap: 4px;
}

.scanner-aid-item span {
    color: var(--text-muted);
    font-size: 0.86rem;
}

.scanner-aid-item-muted {
    background: var(--surface-soft);
}

.btn {
    border-radius: var(--radius);
    font-weight: 800;
    letter-spacing: 0;
}

.btn-primary {
    background: var(--sidebar-active);
    border-color: var(--sidebar-active);
}

.btn-primary:hover,
.btn-primary:focus {
    background: #246fd4;
    border-color: #246fd4;
}

.form-label {
    color: #334155;
    font-weight: 700;
}

.form-control,
.form-select,
.modal-content {
    border-radius: var(--radius);
}

.form-control,
.form-select {
    border-color: #cbd5e1;
    min-height: 42px;
}

.form-control:focus,
.form-select:focus {
    border-color: var(--sidebar-active);
    box-shadow: 0 0 0 0.18rem rgba(47, 128, 237, 0.16);
}

.smart-select-native {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    opacity: 0 !important;
    pointer-events: none !important;
}

.smart-select {
    position: relative;
}

.smart-select-input {
    padding-right: 44px;
}

.smart-select-toggle {
    position: absolute;
    top: 1px;
    right: 1px;
    width: 42px;
    height: 40px;
    border: 0;
    border-left: 1px solid #e2e8f0;
    border-radius: 0 var(--radius) var(--radius) 0;
    background: transparent;
}

.smart-select-toggle::after {
    content: "";
    display: inline-block;
    width: 9px;
    height: 9px;
    border-right: 2px solid #475569;
    border-bottom: 2px solid #475569;
    transform: translateY(-3px) rotate(45deg);
}

.smart-select-menu {
    display: none;
    position: absolute;
    z-index: 1080;
    top: calc(100% + 5px);
    right: 0;
    left: 0;
    max-height: 230px;
    overflow-y: auto;
    border: 1px solid #cbd5e1;
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: var(--shadow-soft);
    padding: 5px;
}

.smart-select.open .smart-select-menu {
    display: block;
}

.smart-select-option {
    display: block;
    width: 100%;
    border: 0;
    border-radius: 7px;
    background: transparent;
    color: var(--text-main);
    padding: 9px 10px;
    text-align: left;
}

.smart-select-option:hover,
.smart-select-option:focus,
.smart-select-option.active {
    background: rgba(47, 128, 237, 0.12);
    color: #0f3f86;
    outline: none;
}

.smart-select-empty {
    color: var(--text-muted);
    font-size: 0.9rem;
    padding: 9px 10px;
}

.modal-content {
    border: 1px solid var(--panel-border);
    box-shadow: var(--shadow-soft);
}

.modal-header,
.modal-footer {
    border-color: var(--panel-border);
}

.badge {
    font-weight: 800;
}

@media (max-width: 1199.98px) {
    :root {
        --sidebar-width: 236px;
    }

    .main-content {
        padding: 24px;
    }
}

@media (max-width: 991.98px) {
    .app-shell {
        grid-template-columns: 1fr;
    }

    .sidebar {
        position: sticky;
        top: 0;
        min-height: auto;
        padding: 12px 14px;
        overflow: hidden;
        box-shadow: 0 10px 22px rgba(15, 23, 42, 0.15);
    }

    .brand {
        padding-bottom: 10px;
        margin-bottom: 10px;
    }

    .brand-mark {
        width: 38px;
        height: 38px;
        font-size: 1.05rem;
    }

    .sidebar .nav.flex-column {
        flex-direction: row !important;
        overflow-x: auto;
        overflow-y: hidden;
        gap: 8px !important;
        padding-bottom: 3px;
        scrollbar-width: thin;
    }

    .sidebar .nav-link {
        flex: 0 0 auto;
        min-height: 38px;
        padding: 8px 12px;
        white-space: nowrap;
        box-shadow: none;
    }

    .sidebar .nav-link.active {
        box-shadow: inset 0 -3px 0 var(--accent-teal);
    }

    .main-content {
        padding: 20px;
    }

    .topbar {
        align-items: flex-start;
    }

    .metric-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .dashboard-grid,
    .scanner-layout {
        grid-template-columns: 1fr;
    }

    .dashboard-result-heading {
        align-items: flex-start;
    }
}

@media (max-width: 767.98px) {
    .topbar {
        flex-direction: column;
        margin-bottom: 18px;
    }

    .topbar h1 {
        font-size: 1.45rem;
    }

    .user-menu {
        justify-content: space-between;
        text-align: left;
        width: 100%;
        background: var(--surface);
        border: 1px solid var(--panel-border);
        border-radius: var(--radius);
        padding: 10px;
        box-shadow: var(--shadow-panel);
    }

    .panel-header,
    .dashboard-result-heading,
    .scanner-resident-card,
    .history-item-header {
        align-items: stretch;
        flex-direction: column;
    }

    .panel-header .btn,
    .dashboard-filter-header .btn,
    .dashboard-result-heading .btn,
    .scanner-actions .btn,
    .modal-footer .btn {
        width: 100%;
    }

    .dashboard-filter {
        max-width: none;
    }

    .dashboard-filter-header {
        align-items: stretch;
        flex-direction: column;
    }

    .content-panel {
        padding: 16px;
    }

    .dataTables_wrapper .row > div {
        width: 100%;
    }

    .dataTables_wrapper .dataTables_length,
    .dataTables_wrapper .dataTables_filter,
    .dataTables_wrapper .dataTables_info,
    .dataTables_wrapper .dataTables_paginate {
        text-align: left;
    }

    .dataTables_wrapper .dataTables_paginate .pagination {
        justify-content: flex-start !important;
        margin-top: 8px;
    }

    .dataTables_wrapper .dataTables_paginate .page-link {
        min-width: 34px;
        padding: 0.38rem 0.52rem;
        text-align: center;
    }

    .dataTables_wrapper .dataTables_filter label,
    .dataTables_wrapper .dataTables_filter input {
        width: 100%;
    }

    .table > :not(caption) > * > * {
        padding: 0.72rem 0.62rem;
    }

    .scanner-aid-item {
        align-items: stretch;
        flex-direction: column;
    }

    #aidQrReader {
        min-height: 280px;
    }
}

@media (max-width: 575.98px) {
    .main-content {
        padding: 14px;
    }

    .brand strong {
        max-width: 220px;
    }

    .metric-grid {
        grid-template-columns: 1fr;
        gap: 12px;
        margin-bottom: 16px;
    }

    .metric-card {
        padding: 16px;
    }

    .content-panel {
        padding: 14px;
    }

    .login-shell {
        align-items: stretch;
        padding: 14px;
    }

    .login-panel {
        align-self: center;
        padding: 22px;
    }

    .login-panel h1 {
        font-size: 1.35rem;
    }

    .modal-dialog {
        margin: 8px;
    }

    .modal-body,
    .modal-header,
    .modal-footer {
        padding: 14px;
    }

    .modal-footer {
        flex-direction: column-reverse;
    }

    .modal-footer > * {
        width: 100%;
        margin: 0;
    }

    .recipient-summary .btn {
        flex: 1 1 100%;
    }

    .dashboard-tabs .nav-link {
        padding: 8px 10px;
    }

    .scanner-resident-card h2 {
        font-size: 1.15rem;
    }
}
