:root {
    --moh-red: #E30613;
    --moh-blue: #0072BC;
    --moh-gold: #C9A24B;
    --moh-dark: #1a1a1a;
    --chart-purple: #6f42c1;
    --chart-indigo: #6610f2;
    --app-header-height: 100px;
}

html {
    font-size: 125%;
}

body {
    font-family: 'Tajawal', sans-serif;
    font-weight: 500;
    background: #f8f9fb;
    color: var(--moh-dark);
}

body.page-dashboard {
    background: #f0f2f5;
}

.app-container {
    max-width: 100%;
    width: 100%;
    padding-right: 1.5rem;
    padding-left: 1.5rem;
}

@media (min-width: 1400px) {
    .app-container {
        padding-right: 2rem;
        padding-left: 2rem;
    }
}

.app-header {
    position: sticky;
    top: 0;
    z-index: 1060;
    background: #fff;
    border-bottom: 3px solid var(--moh-red) !important;
}

.app-logo {
    width: 72px;
    height: 72px;
    object-fit: contain;
}

.text-primary {
    color: var(--moh-blue) !important;
}

.btn-primary,
.btn-danger {
    background-color: var(--moh-red);
    border-color: var(--moh-red);
}

.btn-primary:hover,
.btn-danger:hover {
    background-color: #c00510;
    border-color: #c00510;
}

.btn-outline-primary {
    color: var(--moh-blue);
    border-color: var(--moh-blue);
}

.btn-outline-primary:hover,
.btn-outline-primary.active {
    background-color: var(--moh-blue);
    border-color: var(--moh-blue);
    color: #fff;
}

.card {
    border: none;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.06);
}

.card-header {
    background: linear-gradient(90deg, var(--moh-blue), #005a94);
    color: #fff;
    font-weight: 700;
}

.table thead th {
    background: #eef4fb;
    color: var(--moh-blue);
    white-space: nowrap;
    font-size: 0.85rem;
    padding: 0.6rem 0.5rem;
}

.table tbody td {
    font-size: 0.875rem;
    padding: 0.55rem 0.5rem;
    vertical-align: middle;
}

.table-compact {
    table-layout: auto;
}

.table-compact td,
.table-compact th {
    white-space: normal;
    word-break: break-word;
}

.table-compact .col-id {
    min-width: 3.25rem;
    width: 3.25rem;
    white-space: nowrap;
    padding-right: 0.75rem;
    padding-left: 0.75rem;
    text-align: center;
}

.observations-list-table {
    table-layout: fixed;
    width: 100%;
}

.observations-list-table thead th {
    white-space: normal;
    word-break: break-word;
    line-height: 1.3;
    vertical-align: middle;
}

.observations-list-table .value-badge {
    display: inline-block;
    max-width: 100%;
    word-break: break-word;
}

.observations-list-table .value-badge--stacked {
    display: inline-block;
    max-width: 100%;
    white-space: normal;
    text-align: start;
    line-height: 1.35;
}

.observations-list-table .col-period { width: 7%; }
.observations-list-table .col-authority { width: 13%; }
.observations-list-table .col-facility { width: 10%; }

.observations-list-table .col-facility .value-badge--stacked {
    font-size: 0.72rem;
    padding: 0.3em 0.45em;
}

.observations-list-table .col-affiliation { width: 12%; }
.observations-list-table .col-negativity { width: 14%; }
.observations-list-table .col-sub { width: 14%; }
.observations-list-table .col-department { width: 12%; }

.observations-list-table .table-actions {
    width: 6.5rem;
    min-width: 6.5rem;
}

.observations-table-scroll {
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

@media (min-width: 992px) and (max-width: 1399px) {
    html {
        font-size: 112.5%;
    }

    .app-main,
    .dashboard-content {
        padding: 1rem 1.25rem;
    }

    .observations-list-table thead th {
        font-size: 0.68rem;
        padding: 0.4rem 0.3rem;
    }

    .observations-list-table tbody td {
        font-size: 0.72rem;
        padding: 0.35rem 0.3rem;
        vertical-align: top;
    }

    .observations-list-table .value-badge {
        font-size: 0.65rem;
        padding: 0.25em 0.35em;
    }

    .observations-list-table .value-badge--stacked {
        font-size: 0.62rem;
        line-height: 1.3;
    }

    .observations-list-table .col-period { width: 7%; }
    .observations-list-table .col-authority { width: 12%; }
    .observations-list-table .col-facility { width: 11%; }
    .observations-list-table .col-affiliation { width: 11%; }
    .observations-list-table .col-negativity { width: 13%; }
    .observations-list-table .col-sub { width: 13%; }
    .observations-list-table .col-department { width: 11%; }

    .observations-list-table .table-actions {
        width: 5.5rem;
        min-width: 5.5rem;
    }

    .observations-list-table .btn-icon {
        width: 1.65rem;
        height: 1.65rem;
    }

    .observations-list-table .btn-icon .bi {
        font-size: 0.8rem;
    }

    .table-compact .col-id {
        min-width: 2.25rem;
        width: 2.25rem;
        padding: 0.3rem;
    }
}

.table-actions {
    white-space: nowrap;
    min-width: 7.5rem;
}

.table-actions .btn-icon {
    margin-inline-start: 0.15rem;
}

.table-actions .btn-icon:first-child,
.table-actions form:first-child .btn-icon {
    margin-inline-start: 0;
}

.table-actions form {
    display: inline;
}

.btn-icon {
    width: 2rem;
    height: 2rem;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

.btn-icon .bi {
    font-size: 0.95rem;
    line-height: 1;
}

.value-badge {
    font-size: 0.78rem;
    font-weight: 500;
    padding: 0.35em 0.65em;
    white-space: normal;
    text-align: center;
    line-height: 1.35;
}

.badge-id {
    background: #e7f1ff;
    color: #084298;
}

.badge-his {
    background: #f1f3f5;
    color: #495057;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    letter-spacing: 0.02em;
}

.badge-date {
    background: #e8f4fd;
    color: #055160;
}

.badge-tone-blue { background: #dbeafe; color: #1e40af; }
.badge-tone-indigo { background: #e0e7ff; color: #3730a3; }
.badge-tone-teal { background: #ccfbf1; color: #115e59; }
.badge-tone-purple { background: #ede9fe; color: #5b21b6; }
.badge-tone-cyan { background: #cffafe; color: #155e75; }
.badge-tone-orange { background: #ffedd5; color: #9a3412; }
.badge-tone-pink { background: #fce7f3; color: #9d174d; }
.badge-tone-slate { background: #e2e8f0; color: #334155; }

.badge-risk-critical { background: #f8d7da; color: #842029; }
.badge-risk-high { background: #ffe5d0; color: #984c0c; }
.badge-risk-medium { background: #fff3cd; color: #664d03; }
.badge-risk-low { background: #d1e7dd; color: #0f5132; }

.badge-rate-critical { background: #f8d7da; color: #842029; }
.badge-rate-low { background: #fff3cd; color: #664d03; }
.badge-rate-medium { background: #cfe2ff; color: #084298; }
.badge-rate-high { background: #d1e7dd; color: #0f5132; }
.badge-rate-complete { background: #198754; color: #fff; }

.badge-status-done { background: #d1e7dd; color: #0f5132; }
.badge-status-progress { background: #cfe2ff; color: #084298; }
.badge-status-delayed { background: #f8d7da; color: #842029; }
.badge-status-pending { background: #e2e3e5; color: #41464b; }

.detail-item span .value-badge {
    margin-top: 0.15rem;
}

.detail-actions {
    display: flex;
    gap: 0.35rem;
    flex-wrap: wrap;
}

.detail-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 1rem;
}

.detail-item {
    background: #f8f9fb;
    border-radius: 0.5rem;
    padding: 0.875rem 1rem;
    border: 1px solid #e9ecef;
}

.detail-item label {
    display: block;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--moh-blue);
    margin-bottom: 0.25rem;
}

.detail-item span {
    font-size: 0.95rem;
    color: var(--moh-dark);
}

.detail-item.full-width {
    grid-column: 1 / -1;
}

.select2-container--bootstrap-5 .select2-selection {
    min-height: 38px;
}

.select2-container--bootstrap-5.select2-container--focus .select2-selection,
.select2-container--bootstrap-5.select2-container--open .select2-selection {
    border-color: var(--moh-blue);
    box-shadow: 0 0 0 0.2rem rgba(0, 114, 188, 0.15);
}

.badge-effective {
    background: #d1e7dd;
    color: #0f5132;
}

.badge-ineffective {
    background: #f8d7da;
    color: #842029;
}

.filter-grid .form-label {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--moh-blue);
}

.page-link {
    color: var(--moh-blue);
}

.page-item.active .page-link {
    background-color: var(--moh-blue);
    border-color: var(--moh-blue);
}

.pagination {
    margin-bottom: 0;
}

.pagination .page-link {
    font-size: 0.9rem;
    padding: 0.375rem 0.75rem;
}

.pagination svg {
    width: 1rem;
    height: 1rem;
}

.login-page {
    background: #f8f9fb;
}

.login-card {
    border: none;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.08);
}

.audit-entry {
    border: 1px solid #e9ecef;
    border-radius: 0.5rem;
    padding: 1rem 1.25rem;
    background: #fff;
}

.audit-event-badge {
    background: var(--moh-blue);
    color: #fff;
    font-size: 0.8rem;
}

.audit-diff-table thead th {
    background: #eef4fb;
    color: var(--moh-blue);
    font-size: 0.85rem;
}

.audit-before {
    color: #842029;
    background: #fff5f5;
}

.audit-after {
    color: #0f5132;
    background: #f0fdf4;
}

.dashboard-body {
    background: #f0f2f5;
}

.app-shell,
.dashboard-shell {
    display: flex;
    gap: 0;
    min-height: calc(100vh - var(--app-header-height));
}

.app-sidebar,
.dashboard-sidebar {
    width: 260px;
    flex-shrink: 0;
    background: #fff;
    border-left: 1px solid #e9ecef;
    padding: 0;
    position: sticky;
    top: var(--app-header-height);
    align-self: flex-start;
    max-height: calc(100vh - var(--app-header-height));
    overflow-y: auto;
}

.app-sidebar-brand {
    padding: 1rem 1.25rem 0.5rem;
}

.app-sidebar-brand-title {
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: #6c757d;
}

.app-sidebar-nav {
    display: flex;
    flex-direction: column;
    padding: 0.25rem 0 0.75rem;
}

.app-sidebar-link {
    display: block;
    padding: 0.65rem 1.25rem;
    color: var(--moh-dark);
    text-decoration: none;
    font-size: 0.95rem;
    border-right: 3px solid transparent;
    transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.app-sidebar-link:hover {
    background: #eef4fb;
    color: var(--moh-blue);
}

.app-sidebar-link.active {
    background: #eef4fb;
    color: var(--moh-blue);
    border-right-color: var(--moh-blue);
    font-weight: 600;
}

.app-sidebar-divider {
    height: 1px;
    background: #e9ecef;
    margin: 0.5rem 1rem;
}

.app-sidebar-nav-sub .app-sidebar-link-sub {
    font-size: 0.85rem;
    padding: 0.45rem 1.25rem 0.45rem 1.5rem;
    color: #495057;
}

.app-main,
.dashboard-content {
    flex: 1;
    padding: 1.5rem 2rem;
    min-width: 0;
}

.dashboard-section {
    background: #fff;
    border-radius: 0.5rem;
    padding: 1.25rem 1.5rem;
    margin-bottom: 1.5rem;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
}

.dashboard-section-title {
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--moh-blue);
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 2px solid #eef4fb;
}

.stat-card {
    background: #fff;
    border: 1px solid #e9ecef;
    border-radius: 0.5rem;
    padding: 1.25rem;
    text-align: center;
    border-top: 3px solid var(--moh-blue);
}

.stat-card-accent {
    border-top-color: var(--chart-purple);
}

.stat-card-label {
    font-size: 0.85rem;
    color: #6c757d;
    margin-bottom: 0.5rem;
}

.stat-card-value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--moh-blue);
}

.stat-card-accent .stat-card-value {
    color: var(--chart-purple);
}

.stat-card-sm {
    padding: 0.65rem 0.75rem;
}

.stat-card-sm .stat-card-label {
    font-size: 0.75rem;
    margin-bottom: 0.25rem;
}

.stat-card-sm .stat-card-value {
    font-size: 1.35rem;
}

.chart-wrap-overview {
    height: 220px;
}

.chart-wrap {
    position: relative;
    height: 280px;
    direction: rtl;
}

.chart-wrap canvas {
    direction: rtl;
}

.chart-wrap-lg {
    height: 480px;
}

.chart-wrap.is-scrollable:not(.is-scrollable-x) {
    height: auto;
    overflow-y: auto;
    overflow-x: hidden;
}

.chart-wrap.is-scrollable.is-scrollable-x {
    overflow-x: auto;
    overflow-y: hidden;
}

.chart-wrap-overview.is-scrollable {
    max-height: 220px;
}

.chart-wrap.is-scrollable:not(.chart-wrap-lg):not(.chart-wrap-overview) {
    max-height: 280px;
}

.chart-wrap-lg.is-scrollable {
    max-height: 480px;
}

.chart-scroll-inner {
    position: relative;
    width: 100%;
}

.chart-scroll-inner canvas {
    display: block;
}

.dashboard-table-panel {
    margin-top: 0.25rem;
}

.dashboard-table-toggle {
    font-size: 0.85rem;
}

.dashboard-table-pagination {
    width: 100%;
    max-width: 100%;
    overflow: hidden;
}

.dashboard-table-pagination .pagination {
    flex-wrap: wrap;
    gap: 0.2rem;
}

.dashboard-table-pagination .page-link {
    cursor: pointer;
    min-width: 2.25rem;
    text-align: center;
    padding: 0.3rem 0.55rem;
}

.dashboard-table-pagination .page-item.disabled .page-link {
    pointer-events: none;
}

.dashboard-filter-btn {
    position: relative;
    width: 44px;
    height: 44px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    border-radius: 0.5rem;
}

.dashboard-filter-badge {
    position: absolute;
    top: 6px;
    left: 6px;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--moh-red);
    border: 2px solid #fff;
}

.dashboard-filter-drawer {
    width: min(360px, 100vw);
}

.dashboard-filter-drawer .form-label {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--moh-blue);
}

@media (max-width: 991px) {
    .app-shell,
    .dashboard-shell {
        flex-direction: column;
    }

    .app-sidebar,
    .dashboard-sidebar {
        width: 100%;
        position: fixed;
        top: 0;
        right: 0;
        bottom: 0;
        z-index: 1050;
        max-height: 100vh;
        transform: translateX(100%);
        transition: transform 0.25s ease;
        box-shadow: -4px 0 20px rgba(0, 0, 0, 0.15);
    }

    .app-shell.sidebar-open .app-sidebar {
        transform: translateX(0);
    }

    .app-main,
    .dashboard-content {
        padding: 1rem;
    }
}
