/* =========================================================
   TrackServe - Referrals Module Stylesheet (Compact Vertical Layout)
   ========================================================= */

/* Page Header & Breadcrumb - Compact Rhythm */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 14px;
    margin-bottom: 12px;
    flex-wrap: wrap;
}

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

.breadcrumb {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 10.5px;
    font-weight: 700;
    color: #64748b;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: 2px;
}

.breadcrumb .separator {
    color: #cbd5e1;
    font-size: 8px;
}

.breadcrumb .current {
    color: var(--primary);
}

.title-with-badge {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.title-with-badge h1 {
    margin: 0;
    font-size: 18px;
    font-weight: 800;
    color: #17233c;
    letter-spacing: -0.02em;
    line-height: 1.2;
}

.live-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 10px;
    font-weight: 800;
    padding: 2px 7px;
    border-radius: 12px;
    background: #eef4ff;
    color: #0b4db8;
    border: 1px solid #c8dbf9;
}

.live-badge span {
    font-size: 8px;
}

.subtitle {
    margin: 2px 0 0 0;
    font-size: 11.5px;
    color: #64748b;
    line-height: 1.35;
    max-width: 950px;
}

.referrals-header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.referrals-header-actions .btn {
    padding: 5px 12px;
    font-size: 12px;
    height: 32px;
}

/* Toast Notifications */
.toast-notification {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 12px;
    margin-bottom: 10px;
    border-radius: 7px;
    font-size: 12px;
    font-weight: 600;
}

.toast-success {
    background: #e7f9ef;
    color: #0d6d3d;
    border: 1px solid #c2eed5;
}

.toast-error {
    background: #fee2e2;
    color: #b91c1c;
    border: 1px solid #fecaca;
}

.toast-close {
    background: transparent;
    border: 0;
    font-size: 13px;
    cursor: pointer;
    color: inherit;
    opacity: 0.7;
    padding: 0 4px;
}

.toast-close:hover {
    opacity: 1;
}

/* KPI Summary Stats Cards - Highly Compact */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 10px;
    margin-bottom: 12px;
}

.stat-card {
    background: #ffffff;
    border: 1px solid var(--border);
    border-radius: 9px;
    padding: 8px 12px;
    display: flex;
    align-items: center;
    gap: 10px;
    box-shadow: 0 1px 4px rgba(20, 45, 90, 0.04);
    min-height: auto;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.stat-card:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(20, 45, 90, 0.08);
}

.stat-card .stat-icon {
    width: 34px;
    height: 34px;
    border-radius: 7px;
    display: grid;
    place-items: center;
    font-size: 16px;
    flex-shrink: 0;
    background: #f1f5f9;
    margin-bottom: 0;
}

.stat-card .stat-info {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.stat-card .stat-label {
    font-size: 9.5px;
    font-weight: 700;
    color: #64748b;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    line-height: 1.1;
}

.stat-card .stat-value {
    font-size: 19px;
    font-weight: 900;
    color: #17233c;
    line-height: 1.1;
    margin: 1px 0 0 0;
}

.stat-card .stat-sub {
    font-size: 9.5px;
    color: #94a3b8;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-top: 1px;
    line-height: 1.1;
}

/* Stat Card Accents */
.stat-card.referral-total {
    border-top: 3px solid var(--primary);
}
.stat-card.referral-total .stat-icon {
    background: #eef4ff;
    color: var(--primary);
}

.stat-card.referral-health {
    border-top: 3px solid #10b981;
}
.stat-card.referral-health .stat-icon {
    background: #ecfdf5;
    color: #059669;
}

.stat-card.referral-edu {
    border-top: 3px solid #0284c7;
}
.stat-card.referral-edu .stat-icon {
    background: #f0f9ff;
    color: #0284c7;
}

.stat-card.referral-livelihood {
    border-top: 3px solid #f59e0b;
}
.stat-card.referral-livelihood .stat-icon {
    background: #fffbeb;
    color: #d97706;
}

.stat-card.referral-social {
    border-top: 3px solid #8b5cf6;
}
.stat-card.referral-social .stat-icon {
    background: #f5f3ff;
    color: #7c3aed;
}

/* Filter Toolbar - Compact Horizontal Layout */
.filter-card {
    padding: 7px 12px;
    margin-bottom: 12px;
    border-radius: 9px;
}

.filter-row-horizontal {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 8px;
    flex-wrap: nowrap;
}

.filter-row-horizontal .search-box {
    flex: 1.3;
    min-width: 220px;
    position: relative;
    display: flex;
    align-items: center;
}

.filter-row-horizontal .search-icon {
    position: absolute;
    left: 10px;
    color: #94a3b8;
    pointer-events: none;
    font-size: 12px;
}

.filter-row-horizontal .search-input {
    padding: 5px 26px 5px 30px;
    height: 32px;
    font-size: 11.5px;
    border-radius: 6px;
}

.filter-row-horizontal .clear-search {
    position: absolute;
    right: 7px;
    background: transparent;
    border: none;
    color: #94a3b8;
    font-size: 12px;
    cursor: pointer;
}

.filter-controls-horizontal {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 8px;
    flex: 2.7;
}

.filter-controls-horizontal .select-input {
    flex: 1;
    min-width: 120px;
    font-size: 11.5px;
    padding: 4px 8px;
    height: 32px;
    border-radius: 6px;
}

.filter-controls-horizontal .btn {
    height: 32px;
    padding: 4px 10px;
    font-size: 11.5px;
    border-radius: 6px;
}

/* Mobile & Tablet Responsive Adjustments */
@media (max-width: 1200px) {
    .stats-grid {
        grid-template-columns: repeat(3, 1fr);
    }
    .filter-row-horizontal {
        flex-wrap: wrap;
    }
    .filter-controls-horizontal {
        flex-wrap: wrap;
        width: 100%;
    }
}

@media (max-width: 900px) {
    .stats-grid {
        grid-template-columns: 1fr;
    }
    .filter-row-horizontal {
        flex-direction: column !important;
        align-items: stretch !important;
        width: 100% !important;
        gap: 8px !important;
    }
    .filter-row-horizontal .search-box {
        width: 100% !important;
        min-width: 100% !important;
        max-width: 100% !important;
        flex: none !important;
    }
    .filter-controls-horizontal {
        flex-direction: column !important;
        align-items: stretch !important;
        width: 100% !important;
        gap: 8px !important;
    }
    .filter-controls-horizontal .select-input,
    .filter-controls-horizontal .btn {
        width: 100% !important;
        min-width: 100% !important;
        max-width: 100% !important;
    }
}

/* =========================================================
   Agency Referral Cards & Pipeline List - Compressed Layout
   ========================================================= */
.table-card {
    border-radius: 10px;
}

.table-card .card-heading {
    padding: 8px 12px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid #edf0f4;
}

.table-card .card-heading h2 {
    margin: 0;
    font-size: 13px;
    font-weight: 800;
}

.table-card .card-heading .muted {
    display: block;
    font-size: 10.5px;
    color: var(--muted);
    margin-top: 1px;
}

/* Card Heading Collapse/Expand All Control */
.card-heading .heading-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.btn-collapse-all {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 4px 9px;
    font-size: 11px;
    font-weight: 700;
    color: #475569;
    background: #ffffff;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.15s ease;
    line-height: 1;
}

.btn-collapse-all:hover {
    background: #f8fafc;
    color: #0f172a;
    border-color: #94a3b8;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
    transform: translateY(-1px);
}

.btn-collapse-all:active {
    transform: translateY(0);
}

.btn-collapse-all .collapse-all-icon {
    flex-shrink: 0;
    color: #1e3a8a;
    transition: transform 0.2s ease;
}

.agency-referral-cards-list {
    display: flex;
    flex-direction: column;
    gap: 7px;
    padding: 9px 10px;
}

.agency-card {
    background: #ffffff;
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: 0 1px 4px rgba(20, 45, 90, 0.03);
    overflow: hidden;
    transition: box-shadow 0.15s ease, border-color 0.15s ease;
}

.agency-card:hover {
    border-color: #cbdbee;
    box-shadow: 0 4px 14px rgba(20, 45, 90, 0.06);
}

.agency-card.is-expanded {
    border-color: #b5cde8;
}

.agency-card-header {
    padding: 7px 12px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    background: #ffffff;
    cursor: pointer;
    user-select: none;
    transition: background 0.12s ease;
}

.agency-card-header:hover {
    background: #f9fbfd;
}

.agency-header-left {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 1;
    min-width: 0;
}

.agency-avatar {
    width: 32px;
    height: 32px;
    border-radius: 7px;
    background: linear-gradient(135deg, #0b4db8, #1d72d5);
    color: #ffffff;
    display: grid;
    place-items: center;
    font-size: 11px;
    font-weight: 900;
    flex-shrink: 0;
    box-shadow: 0 2px 6px rgba(11, 77, 184, 0.18);
    text-transform: uppercase;
    overflow: hidden;
    position: relative;
}

.agency-avatar-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.agency-info {
    display: flex;
    flex-direction: column;
    gap: 1px;
    min-width: 0;
}

.agency-title-row {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}

.agency-acronym-badge {
    background: #eef4ff;
    color: #0b4db8;
    padding: 2px 6px;
    border-radius: 5px;
    font-size: 11px;
    font-weight: 800;
    border: 1px solid #c8dbf9;
}

.agency-name-text {
    font-size: 13px;
    font-weight: 800;
    color: #17233c;
}

.agency-meta-tags {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
    font-size: 10.5px;
}

.services-count-badge {
    background: #f1f5f9;
    color: #334155;
    padding: 1px 6px;
    border-radius: 4px;
    font-weight: 700;
    font-size: 10.5px;
}

.agency-header-right {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}

.btn-agency-slip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 9px;
    background: #0b4db8;
    color: #ffffff;
    border: 1px solid #0b4db8;
    border-radius: 5px;
    font-size: 11px;
    font-weight: 800;
    cursor: pointer;
    transition: all 0.15s ease;
    white-space: nowrap;
}

.btn-agency-slip:hover {
    background: #073a8b;
    transform: translateY(-1px);
    box-shadow: 0 3px 8px rgba(11, 77, 184, 0.22);
}

.btn-agency-slip.icon-only {
    width: 27px;
    height: 27px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    border-radius: 6px;
}

.btn-toggle-expand {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 9px;
    background: #f8fafc;
    color: #475569;
    border: 1px solid #cbd5e1;
    border-radius: 5px;
    font-size: 11px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.15s ease;
    white-space: nowrap;
}

.btn-toggle-expand:hover {
    background: #e2e8f0;
    color: #1e293b;
}

.agency-card-body {
    padding: 0 10px 8px 10px;
    border-top: 1px solid #f0f3f8;
    background: #fbfcfe;
    animation: fadeIn 0.15s ease-out;
}

.agency-table-heading {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 5px 2px 3px 2px;
    font-size: 10px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: #5d6d88;
}

/* Compact Data Table inside Agency Card */
.agency-card .data-table {
    min-width: 700px;
}

.agency-card .data-table th {
    padding: 6px 8px;
    font-size: 10px;
    background: #f1f5f9;
    color: #475569;
    border-bottom: 1px solid #e2e8f0;
}

.agency-card .data-table td {
    padding: 6px 8px;
    font-size: 12px;
    border-bottom: 1px solid #edf2f7;
    vertical-align: middle;
}

.agency-card .sub-text {
    margin-top: 2px;
    display: flex;
    align-items: center;
    gap: 4px;
    flex-wrap: wrap;
    font-size: 10.5px;
}

.agency-card .sub-text code {
    font-size: 10px;
    color: #0b4db8;
    background: #eef4ff;
    padding: 1px 4px;
    border-radius: 3px;
}

.agency-card .swdi-badge {
    font-size: 9px;
    font-weight: 700;
    color: #556277;
    background: #e2e8f0;
    padding: 1px 4px;
    border-radius: 3px;
}

.agency-card .badge {
    padding: 2px 6px;
    font-size: 10px;
    font-weight: 700;
}

.agency-card .action-btn {
    width: 24px;
    height: 24px;
    font-size: 11px;
    border-radius: 4px;
}

/* Pipeline Duration Tags */
.pipeline-age {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    font-size: 10px;
    font-weight: 700;
    padding: 1px 5px;
    border-radius: 3px;
    white-space: nowrap;
}

.pipeline-age.recent {
    background: #e6f9ed;
    color: #107e3e;
    border: 1px solid #bcf0cf;
}

.pipeline-age.pending {
    background: #fff8e6;
    color: #b45309;
    border: 1px solid #fde68a;
}

.pipeline-age.overdue {
    background: #fee2e2;
    color: #dc2626;
    border: 1px solid #fca5a5;
}

.btn-mark-served-sm {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    padding: 3px 7px;
    background: #ecfdf5;
    color: #047857;
    border: 1px solid #a7f3d0;
    border-radius: 4px;
    font-size: 10.5px;
    font-weight: 800;
    cursor: pointer;
    transition: all 0.15s ease;
    white-space: nowrap;
}

.btn-mark-served-sm:hover {
    background: #10b981;
    color: #ffffff;
    border-color: #059669;
}

.btn-single-slip-sm {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    padding: 3px 7px;
    background: #f8fafc;
    color: #334155;
    border: 1px solid #cbd5e1;
    border-radius: 4px;
    font-size: 10.5px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.15s ease;
    white-space: nowrap;
}

.btn-single-slip-sm:hover {
    background: #0284c7;
    color: #ffffff;
    border-color: #0284c7;
}

/* Side Panel Drawer Styles */
.side-panel-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(10, 24, 48, 0.45);
    backdrop-filter: blur(3px);
    z-index: 2000;
    display: flex;
    justify-content: flex-end;
}

.side-panel-drawer {
    width: min(560px, 100vw);
    height: 100vh;
    background: #ffffff;
    box-shadow: -8px 0 30px rgba(0, 0, 0, 0.18);
    display: flex;
    flex-direction: column;
    z-index: 2001;
    animation: slideLeft 0.2s ease-out;
}

@keyframes slideLeft {
    from { transform: translateX(100%); }
    to { transform: translateX(0); }
}

.side-panel-header {
    padding: 12px 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border);
    background: #f8fafc;
}

.side-panel-header .header-left {
    display: flex;
    align-items: center;
    gap: 10px;
}

.side-panel-header h2 {
    margin: 2px 0 0;
    font-size: 15px;
    font-weight: 800;
    color: #17233c;
}

.btn-return {
    border: 1px solid #cbd5e1;
    background: #ffffff;
    color: #475569;
    font-size: 11px;
    font-weight: 700;
    padding: 4px 8px;
    border-radius: 5px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.btn-return:hover {
    background: #f1f5f9;
}

.side-panel-body {
    padding: 14px 16px;
    overflow-y: auto;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.form-section-card {
    background: #ffffff;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 12px 14px;
}

.section-title {
    font-size: 11.5px;
    font-weight: 800;
    color: #1e293b;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    padding-bottom: 6px;
    border-bottom: 1px solid #f1f5f9;
}

.selected-household-card {
    display: flex;
    align-items: center;
    gap: 10px;
}

.hh-info-left {
    display: flex;
    align-items: center;
    gap: 10px;
}

.hh-avatar {
    width: 34px;
    height: 34px;
    border-radius: 7px;
    background: var(--primary);
    color: #ffffff;
    display: grid;
    place-items: center;
    font-weight: 900;
    font-size: 13px;
    flex-shrink: 0;
}

.hh-details h4 {
    margin: 0 0 2px;
    font-size: 13px;
    font-weight: 800;
    color: #17233c;
}

.hh-tags {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
    font-size: 10.5px;
}

.hh-tags code {
    font-size: 10px;
    background: #eef4ff;
    color: var(--primary);
    padding: 1px 4px;
    border-radius: 3px;
}

.audit-meta-card {
    background: #f8fafc;
    border: 1px solid var(--border);
    border-radius: 7px;
    padding: 8px 12px;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    font-size: 11px;
}

.audit-meta-item {
    display: flex;
    flex-direction: column;
}

.audit-label {
    font-size: 9.5px;
    color: #94a3b8;
    text-transform: uppercase;
    font-weight: 700;
}

.audit-value {
    color: #334155;
    font-weight: 700;
    font-size: 11px;
}

.side-panel-footer {
    padding: 10px 16px;
    border-top: 1px solid var(--border);
    background: #ffffff;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.footer-actions-right {
    display: flex;
    gap: 8px;
}

.modal-card.small {
    width: min(500px, 94vw);
    background: #ffffff;
    border-radius: 10px;
    box-shadow: 0 20px 40px rgba(0,0,0,0.2);
    overflow: hidden;
}

/* =========================================================
   Status Transition Modal: "Referred" to "Served" Verification
   ========================================================= */
.status-transition-modal-card {
    width: min(510px, 94vw);
    background: #ffffff;
    border-radius: 10px;
    box-shadow: 0 16px 40px rgba(15, 23, 42, 0.22);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    animation: fadeIn 0.16s ease-out;
}

.status-transition-header {
    padding: 10px 16px;
    background: #ffffff;
    border-bottom: 1px solid #e2e8f0;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.status-transition-body {
    padding: 12px 16px;
    max-height: 82vh;
    overflow-y: auto;
    background: #f8fafc;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.served-beneficiary-summary {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 10px;
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 7px;
}

.served-beneficiary-summary .summary-avatar {
    width: 28px;
    height: 28px;
    border-radius: 6px;
    background: #0b4db8;
    color: #ffffff;
    font-size: 12px;
    font-weight: 800;
    display: grid;
    place-items: center;
    flex-shrink: 0;
}

.served-beneficiary-summary .summary-info strong {
    font-size: 12px;
    color: #0f172a;
    display: block;
    line-height: 1.2;
}

.served-beneficiary-summary .summary-sub {
    font-size: 10.5px;
    color: #64748b;
    margin-top: 1px;
    display: flex;
    align-items: center;
    gap: 5px;
    flex-wrap: wrap;
}

.requested-service-readonly-box {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    padding: 7px 10px;
    background: #eff6ff;
    border: 1px solid #bfdbfe;
    border-radius: 6px;
}

.requested-service-readonly-box .icon {
    font-size: 13px;
    margin-top: 1px;
}

.requested-service-readonly-box .service-text strong {
    display: block;
    font-size: 12px;
    color: #1e3a8a;
    line-height: 1.25;
}

.requested-service-readonly-box .service-text .muted-note {
    font-size: 10px;
    color: #3b82f6;
    margin-top: 1px;
    display: block;
}

.form-label-bold {
    font-size: 11px;
    font-weight: 700;
    color: #334155;
    margin-bottom: 3px;
    display: block;
}

.match-choice-group {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.match-choice-card {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    padding: 8px 10px;
    border: 1.5px solid #cbd5e1;
    background: #ffffff;
    border-radius: 7px;
    cursor: pointer;
    transition: all 0.12s ease;
    user-select: none;
}

.match-choice-card:hover {
    border-color: #94a3b8;
    background: #f8fafc;
}

.match-choice-card.selected {
    border-color: #059669;
    background: #f0fdf4;
    box-shadow: 0 0 0 2px rgba(5, 150, 105, 0.15);
}

.match-choice-card input[type="radio"] {
    margin-top: 2px;
    cursor: pointer;
}

.match-choice-title {
    font-size: 11.5px;
    font-weight: 700;
    color: #0f172a;
    line-height: 1.2;
}

.match-choice-card.selected .match-choice-title {
    color: #065f46;
}

.match-choice-desc {
    font-size: 9.5px;
    color: #64748b;
    margin-top: 2px;
    line-height: 1.25;
}

.status-transition-footer {
    padding: 10px 16px;
    background: #ffffff;
    border-top: 1px solid #e2e8f0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
}

.status-transition-footer .btn-sm {
    height: 28px;
    padding: 3px 12px;
    font-size: 11px;
}

/* =========================================================
   Official Printable DSWD Referral Slips (Agency & Single)
   ========================================================= */
.referral-slip-modal-card {
    background: #ffffff;
    border-radius: 12px;
    width: 950px;
    max-width: 96vw;
    max-height: 92vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 20px 45px rgba(0, 0, 0, 0.28);
}

.slip-modal-header {
    padding: 12px 20px;
    background: #17233c;
    color: #ffffff;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.slip-modal-header h3 {
    margin: 0;
    font-size: 14px;
    font-weight: 800;
    display: flex;
    align-items: center;
    gap: 8px;
}

.slip-modal-body {
    padding: 20px;
    overflow-y: auto;
    background: #f8fafc;
}

.referral-slip-sheet {
    background: #ffffff;
    border: 1px solid #cbd5e1;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.06);
    padding: 32px 38px;
    max-width: 860px;
    margin: 0 auto;
    font-family: 'Segoe UI', Arial, sans-serif;
    color: #0f172a;
    line-height: 1.4;
}

.slip-header-block {
    text-align: center;
    border-bottom: 2px solid #0f172a;
    padding-bottom: 14px;
    margin-bottom: 16px;
}

.slip-header-block .republic {
    font-size: 10.5px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: #475569;
}

.slip-header-block .agency-name {
    font-size: 13.5px;
    font-weight: 900;
    color: #0f172a;
    margin-top: 2px;
}

.slip-header-block .office-name {
    font-size: 11.5px;
    font-weight: 700;
    color: #334155;
}

.slip-header-block .program-title {
    font-size: 10.5px;
    font-weight: 600;
    color: #64748b;
}

.slip-form-title {
    text-align: center;
    margin: 14px 0;
}

.slip-form-title h2 {
    font-size: 16px;
    font-weight: 900;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: #0f172a;
    margin: 0;
}

.slip-form-title .slip-tracking-no {
    font-size: 10.5px;
    font-family: monospace;
    color: #64748b;
    font-weight: 700;
    margin-top: 3px;
}

.slip-meta-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 14px;
    font-size: 11.5px;
}

.slip-meta-table td {
    padding: 5px 9px;
    border: 1px solid #94a3b8;
}

.slip-meta-table td.label-cell {
    background: #f1f5f9;
    font-weight: 800;
    width: 22%;
    color: #1e293b;
}

.slip-manifest-table {
    width: 100%;
    border-collapse: collapse;
    margin: 8px 0 14px 0;
    font-size: 10.5px;
}

.slip-manifest-table th {
    background: #f1f5f9;
    color: #0f172a;
    font-weight: 800;
    padding: 6px 8px;
    border: 1px solid #94a3b8;
    text-align: left;
    text-transform: uppercase;
    font-size: 9.5px;
}

.slip-manifest-table td {
    padding: 6px 8px;
    border: 1px solid #94a3b8;
    vertical-align: top;
}

.slip-section-heading {
    background: #e2e8f0;
    padding: 5px 9px;
    font-weight: 900;
    font-size: 10.5px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    border: 1px solid #94a3b8;
    border-bottom: none;
    color: #0f172a;
    margin-top: 12px;
}

.slip-narrative-box {
    border: 1px solid #94a3b8;
    padding: 10px 12px;
    font-size: 11.5px;
    min-height: 60px;
    background: #ffffff;
}

.slip-signatures-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
    margin-top: 22px;
    padding-top: 8px;
}

.slip-sig-block {
    text-align: center;
    font-size: 10.5px;
}

.slip-sig-line {
    border-bottom: 1px solid #0f172a;
    margin-bottom: 5px;
    height: 30px;
}

.slip-sig-name {
    font-weight: 800;
    font-size: 11.5px;
}

.slip-ack-section {
    border: 2px dashed #94a3b8;
    border-radius: 6px;
    padding: 12px;
    margin-top: 18px;
    background: #f8fafc;
}

.slip-modal-footer {
    padding: 10px 20px;
    background: #ffffff;
    border-top: 1px solid #e2eaf4;
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

/* Print Stylesheet */
@media print {
    body * {
        visibility: hidden;
    }
    .referral-slip-sheet, .referral-slip-sheet * {
        visibility: visible;
    }
    .referral-slip-sheet {
        position: absolute;
        left: 0;
        top: 0;
        width: 100%;
        margin: 0;
        padding: 20px;
        border: none;
        box-shadow: none;
    }
    .slip-modal-header, .slip-modal-footer, .side-panel-backdrop, .app-shell {
        display: none !important;
    }
}

/* =========================================================
   Full-Page Referral Update Form inside Content Area
   ========================================================= */
.referral-update-fullpage {
    animation: fadeIn 0.15s ease-out;
    width: 100%;
}

.btn-return-link {
    background: none;
    border: none;
    padding: 0;
    color: var(--primary);
    font-size: 12px;
    font-weight: 700;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    transition: color 0.15s ease;
}

.btn-return-link:hover {
    color: #1d4ed8;
    text-decoration: underline;
}

.update-fullpage-content {
    display: flex;
    flex-direction: column;
    gap: 16px;
    max-width: 1100px;
}

.update-fullpage-content .form-section-card {
    background: #ffffff;
    border: 1px solid var(--border);
    border-radius: 9px;
    padding: 18px 20px;
    box-shadow: 0 1px 3px rgba(15, 23, 42, 0.04);
}

.update-fullpage-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #ffffff;
    border: 1px solid var(--border);
    border-radius: 9px;
    padding: 14px 20px;
    box-shadow: 0 1px 3px rgba(15, 23, 42, 0.04);
    margin-top: 4px;
}

.table-edit-btn {
    padding: 4px 10px !important;
    font-size: 11.5px !important;
    height: 28px !important;
    white-space: nowrap;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    border-radius: 6px;
    font-weight: 600;
    transition: all 0.12s ease;
}

/* Small Save Icon Button beside Agency Referral Slip */
.btn-save-sm {
    width: 27px;
    height: 27px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    font-size: 13px;
    position: relative;
    cursor: pointer;
    transition: all 0.15s ease;
    line-height: 1;
}

.btn-save-sm .save-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    background: #dc2626;
    color: #ffffff;
    font-size: 8.5px;
    font-weight: 800;
    min-width: 13px;
    height: 13px;
    border-radius: 99px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 3px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
    line-height: 1;
}

.btn-save-sm.disabled {
    background: #f1f5f9;
    color: #94a3b8;
    border: 1px solid #cbd5e1;
    cursor: not-allowed;
    opacity: 0.7;
}

.btn-save-sm.active {
    background: #059669;
    color: #ffffff;
    border: 1px solid #047857;
    font-weight: 800;
    cursor: pointer;
    box-shadow: 0 2px 6px rgba(5, 150, 105, 0.28);
}

.btn-save-sm.active:hover {
    background: #047857;
    transform: translateY(-1px);
    box-shadow: 0 3px 8px rgba(5, 150, 105, 0.35);
}

/* Status Action Select Dropdown in Table */
.status-select-wrap {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    position: relative;
}

.status-action-select {
    padding: 2px 6px;
    font-size: 10px;
    font-weight: 700;
    border-radius: 4px;
    cursor: pointer;
    outline: none;
    transition: all 0.15s ease;
    height: 22px;
    line-height: 1;
}

.status-action-select.is-referred {
    background: #eff6ff;
    color: #1d4ed8;
    border: 1px solid #bfdbfe;
}

.status-action-select.is-referred:hover {
    background: #dbeafe;
    border-color: #93c5fd;
}

.status-action-select.is-served {
    background: #ecfdf5;
    color: #047857;
    border: 1px solid #a7f3d0;
}

.status-action-select.is-served:hover {
    background: #d1fae5;
    border-color: #6ee7b7;
}

.status-action-select.is-planned {
    background: #fffbeb;
    color: #b45309;
    border: 1px solid #fde68a;
}

.status-action-select.is-planned:hover {
    background: #fef3c7;
    border-color: #fcd34d;
}

.status-action-select.is-pending {
    border-color: #059669 !important;
    box-shadow: 0 0 0 2px rgba(16, 185, 129, 0.25);
}

/* Compact Table Layout & Agency Separator */
.table-card .data-table {
    width: 100%;
    border-collapse: collapse;
}

.table-card .data-table th {
    padding: 6px 8px;
    font-size: 10px;
    font-weight: 800;
    letter-spacing: 0.04em;
    background: #f8fafc;
    color: #475569;
    vertical-align: middle;
}

.table-card .data-table td {
    padding: 5px 8px;
    font-size: 11.5px;
    line-height: 1.25;
    vertical-align: middle;
}

.table-card .agency-table-group-header td {
    padding: 6px 10px !important;
    border-top: 10px solid #e2e8f0 !important;
    border-bottom: 1px solid #cbd5e1 !important;
    background: #f1f5f9 !important;
}

.table-card .data-table tbody tr:first-child.agency-table-group-header td {
    border-top: none !important;
}

.table-card .sub-text {
    margin-top: 1px;
    font-size: 9.5px;
    display: flex;
    align-items: center;
    gap: 4px;
}

.table-card .sub-text code {
    font-size: 9px;
    padding: 1px 3px;
}

.pending-dot {
    color: #059669;
    font-size: 13px;
    font-weight: 900;
    animation: statusPulse 1.4s ease-in-out infinite;
}

@keyframes statusPulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.4; transform: scale(1.2); }
}

/* Agency Table Group Expand/Collapse Icon Button */
.btn-collapse-icon {
    width: 27px;
    height: 27px;
    border-radius: 6px;
    border: 1px solid #cbd5e1;
    background: #ffffff;
    color: #475569;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 10px;
    font-weight: 800;
    transition: all 0.15s ease;
    padding: 0;
    line-height: 1;
}

.btn-collapse-icon:hover {
    background: #f1f5f9;
    color: #0f172a;
    border-color: #94a3b8;
    transform: translateY(-1px);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

.btn-collapse-icon:active {
    transform: translateY(0);
}

/* =========================================================
   TWO-PANEL VIEW: SIDEBAR & MAIN CONTENT
   ========================================================= */
.referrals-two-panel-layout {
    display: grid;
    grid-template-columns: 260px 1fr;
    gap: 14px;
    align-items: start;
    width: 100%;
    height: calc(100vh - 165px);
    max-height: calc(100vh - 165px);
    overflow: hidden;
}

.interventions-two-panel-layout {
    height: calc(100vh - 280px);
    max-height: calc(100vh - 280px);
    min-height: 460px;
}

@media (max-width: 900px) {
    .referrals-two-panel-layout,
    .interventions-two-panel-layout {
        display: flex !important;
        flex-direction: column !important;
        height: auto !important;
        max-height: none !important;
        min-height: auto !important;
        gap: 14px !important;
        overflow: visible !important;
    }

    /* Unbox .referrals-main-content so its child elements (.filter-card and .table-card) become direct flex items */
    .referrals-main-content {
        display: contents !important;
    }

    /* 1. On top: Filters and Search Fields vertically stacked with full width */
    .referrals-main-content .filter-card,
    .referrals-two-panel-layout .filter-card {
        order: 1 !important;
        width: 100% !important;
        margin-bottom: 0 !important;
    }

    /* 2. Below filters: Left Panel (Sidebar) */
    .referrals-sidebar {
        order: 2 !important;
        width: 100% !important;
        max-width: 100% !important;
        height: auto !important;
        max-height: 280px !important;
        overflow-y: auto !important;
    }

    /* 3. At the bottom: Right Panel Card (Table Card / Content) */
    .referrals-main-content .table-card,
    .referrals-two-panel-layout .table-card,
    .referrals-main-content > :not(.filter-card) {
        order: 3 !important;
        width: 100% !important;
        min-height: auto !important;
        height: auto !important;
        max-height: none !important;
        overflow: visible !important;
    }

    .referrals-main-content .table-wrap {
        max-height: 520px;
        overflow: auto !important;
    }
}

/* Left Panel (Sidebar) */
.referrals-sidebar {
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 9px;
    padding: 10px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.03);
    height: 100%;
    max-height: 100%;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.sidebar-heading-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 2px 4px 8px 4px;
    border-bottom: 1px solid #f1f5f9;
    margin-bottom: 8px;
    flex-shrink: 0;
}

.sidebar-heading-title {
    font-size: 11px;
    font-weight: 800;
    color: #475569;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.sidebar-total-badge {
    background: #e2e8f0;
    color: #1e293b;
    font-size: 10px;
    font-weight: 800;
    padding: 2px 7px;
    border-radius: 9999px;
}

.sidebar-agency-search {
    position: relative;
    margin-bottom: 8px;
    flex-shrink: 0;
}

.sidebar-agency-search .search-icon {
    position: absolute;
    left: 8px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 11px;
    color: #94a3b8;
    pointer-events: none;
}

.sidebar-search-input {
    width: 100%;
    padding: 4px 22px 4px 26px !important;
    font-size: 11px !important;
    height: 28px !important;
    border-radius: 6px !important;
}

.sidebar-agency-search .clear-search {
    position: absolute;
    right: 6px;
    top: 50%;
    transform: translateY(-50%);
    background: transparent;
    border: none;
    color: #94a3b8;
    font-size: 11px;
    cursor: pointer;
    padding: 2px 4px;
}

.agency-filter-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
    overflow-y: auto;
    overflow-x: hidden;
    padding-right: 2px;
    flex: 1;
}

.agency-filter-item {
    width: 100%;
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 7px;
    padding: 6px 8px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    text-align: left;
    cursor: pointer;
    transition: all 0.12s ease;
    gap: 8px;
}

.agency-filter-item:hover {
    background: #f8fafc;
    border-color: #cbd5e1;
    transform: translateY(-1px);
}

.agency-filter-item.active {
    background: #eff6ff;
    border-color: #3b82f6;
    box-shadow: 0 0 0 1px #3b82f6, 0 1px 3px rgba(59, 130, 246, 0.15);
}

.agency-filter-left {
    display: flex;
    align-items: center;
    gap: 7px;
    min-width: 0;
    flex: 1;
}

.agency-filter-avatar {
    width: 26px;
    height: 26px;
    border-radius: 5px;
    background: #ffffff;
    border: 1px solid #cbd5e1;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 9.5px;
    font-weight: 800;
    color: #1e3a8a;
    flex-shrink: 0;
    overflow: hidden;
}

.agency-filter-avatar img {
    width: 20px;
    height: 20px;
    object-fit: contain;
}

.agency-filter-avatar.all {
    background: #f1f5f9;
    border-color: #cbd5e1;
    font-size: 13px;
}

.agency-filter-info {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.agency-filter-name {
    font-size: 11px;
    font-weight: 800;
    color: #0f172a;
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.agency-filter-sub {
    font-size: 9px;
    color: #64748b;
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.agency-filter-count {
    font-size: 9.5px;
    font-weight: 800;
    padding: 1px 6px;
    border-radius: 9999px;
    line-height: 1.2;
    flex-shrink: 0;
}

.agency-filter-count.badge-dark {
    background: #0f2b48;
    color: #ffffff;
}

.agency-filter-count.badge-blue {
    background: #2563eb;
    color: #ffffff;
}

.agency-filter-count.badge-active {
    background: #dbeafe;
    color: #1d4ed8;
}

.agency-filter-count.badge-zero {
    background: #f1f5f9;
    color: #94a3b8;
}

.agency-filter-count.badge-muted {
    background: #f1f5f9;
    color: #64748b;
}


/* Right Panel (Main Content) */
.referrals-main-content {
    display: flex;
    flex-direction: column;
    gap: 10px;
    min-width: 0;
    height: 100%;
    max-height: 100%;
    overflow: hidden;
}

.referrals-main-content .filter-card {
    flex-shrink: 0;
    padding: 8px 12px;
}

.referrals-main-content .table-card {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
    border-radius: 9px;
}

/* Right Panel Internal Scrollable Table */
.referrals-main-content .table-wrap {
    flex: 1;
    overflow-y: auto;
    overflow-x: auto;
    position: relative;
    border-radius: 0 0 8px 8px;
    scrollbar-width: thin;
    scrollbar-color: #cbd5e1 #f8fafc;
}

.referrals-main-content .table-wrap::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

.referrals-main-content .table-wrap::-webkit-scrollbar-track {
    background: #f8fafc;
    border-radius: 4px;
}

.referrals-main-content .table-wrap::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 4px;
}

.referrals-main-content .table-wrap::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

.referrals-main-content .table-wrap thead th {
    position: sticky;
    top: 0;
    z-index: 5;
    background: #ffffff;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}

/* Scroll Navigation Buttons */
.scroll-nav-group {
    display: inline-flex;
    align-items: center;
    background: #f8fafc;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    overflow: hidden;
    height: 27px;
}

.btn-scroll-nav {
    background: transparent;
    border: none;
    color: #475569;
    font-size: 10px;
    width: 24px;
    height: 100%;
    cursor: pointer;
    line-height: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: background 0.12s, color 0.12s;
    padding: 0;
}

.btn-scroll-nav:hover {
    background: #e2e8f0;
    color: #0f172a;
}

.btn-scroll-nav:active {
    background: #cbd5e1;
}

.btn-scroll-nav + .btn-scroll-nav {
    border-left: 1px solid #cbd5e1;
}

/* =========================================================
   Multi-Select Dropdown Filters (Municipality & Barangay)
   ========================================================= */
.multiselect-dropdown-wrapper {
    position: relative;
    flex: 1.2;
    min-width: 150px;
}

.multiselect-trigger-btn {
    width: 100%;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 11.5px;
    padding: 4px 8px;
    border-radius: 6px;
    cursor: pointer;
    text-align: left;
    background: #ffffff;
    border: 1px solid #cbd5e1;
    color: #334155;
    transition: all 0.15s ease;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}

.multiselect-trigger-btn:hover {
    border-color: #94a3b8;
    background: #f8fafc;
}

.multiselect-trigger-btn.active {
    border-color: #3b82f6;
    background: #eff6ff;
    color: #1e40af;
    font-weight: 600;
}

.multiselect-dropdown-panel {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    z-index: 1050;
    background: #ffffff;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.12), 0 8px 10px -6px rgba(0, 0, 0, 0.08);
    padding: 8px;
    font-size: 11.5px;
    animation: fadeInDropdown 0.15s ease-out;
}

.multiselect-item-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 5px 8px;
    border-radius: 5px;
    cursor: pointer;
    user-select: none;
    transition: background 0.1s ease;
}

.multiselect-item-row:hover {
    background: #f1f5f9;
}

.multiselect-item-row.selected {
    background: #eff6ff;
}

@keyframes fadeInDropdown {
    from {
        opacity: 0;
        transform: translateY(-4px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}
