/* ── FSA Dashboard – custom styles ────────────────────────────────────────
   All project-specific overrides live here; Sneat's core.css is untouched.
──────────────────────────────────────────────────────────────────────────── */

/* ── Page background ───────────────────────────────────────────────────── */
body {
    background: rgb(201, 201, 201);
}

/* ── Header banner ─────────────────────────────────────────────────────── */
.fsa-header {
    background: linear-gradient(135deg, #696cff 0%, #5e63d8 100%);
    color: #fff;
    border-radius: 12px;
    padding: 09px 12px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    box-shadow: 0 4px 12px rgba(105, 108, 255, 0.35);
    position: relative;
    overflow: hidden;
}
.fsa-header::before {
    content: '';
    position: absolute;
    inset: 0;
    background: url('../img/Logo-PDMA.png') center / 10% auto repeat-x;
    opacity: 0.08;
    border-radius: 12px;
    pointer-events: none;
}
.fsa-header > * {
    position: relative;
    z-index: 1;
}

.fsa-header-logo {
    height: 80px;
    width: auto;
    object-fit: contain;
    flex-shrink: 0;
}

.fsa-header-title {
    flex: 1;
    text-align: center;
}

.fsa-header-title h4 {
    color: #fff;
    font-weight: 700;
    margin: 0;
}

.fsa-header-title small {
    color: rgba(255,255,255,.75);
    font-size: .85rem;
    letter-spacing: .04em;
    text-transform: uppercase;
}

/* ── Stat cards ─────────────────────────────────────────────────────────── */
.stat-card {
    display: flex;
    align-items: center;
    gap: 1rem;
    background: #fff;
    border-radius: 12px;
    padding: 1.25rem;
    border: 1px solid rgba(67, 89, 113, .1);
    box-shadow: 0 2px 8px rgba(67, 89, 113, .08);
    height: 100%;
    transition: transform .2s, box-shadow .2s;
}
.stat-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 6px 18px rgba(67, 89, 113, .14);
}

.stat-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 56px;
    height: 56px;
    border-radius: 12px;
    flex-shrink: 0;
}
.stat-icon-target   { background: #e9f7ef; }
.stat-icon-surveyed { background: #eef8ed; }
.stat-icon-revisited{ background: #fff4e5; }
.stat-icon-pending  { background: #fdecea; }

.stat-icon-text { font-size: 1.75rem; line-height: 1; }

.stat-content { min-width: 0; }

.stat-label {
    margin: 0 0 .3rem;
    font-size: .8rem;
    font-weight: 600;
    color: #697a8d;
    text-transform: uppercase;
    letter-spacing: .04em;
}

.stat-value {
    margin: 0;
    font-size: 1.85rem;
    font-weight: 700;
    color: #1f2b3d;
    line-height: 1;
}

/* ── Cards ──────────────────────────────────────────────────────────────── */
.card {
    border: 1px solid rgba(67, 89, 113, .1);
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(67, 89, 113, .06);
}

.card-header {
    background: #fff;
    border-bottom: 1px solid rgba(67, 89, 113, .1);
    border-radius: 12px 12px 0 0 !important;
    padding: .9rem 1.25rem;
}

.card-header h5 {
    font-weight: 700;
    color: #1f2b3d;
}

/* ── Chart card header with centered legend ─────────────────────────────── */
.chart-header-grid {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    gap: .5rem;
}

.chart-header-grid .chart-legend {
    grid-column: 2;
    justify-self: center;
}

.chart-header-grid .chart-level-label {
    grid-column: 2;
    justify-self: center;
    font-weight: 700;
    font-size: .9rem;
    color: #4a5568;
}

.chart-header-grid .chart-header-actions {
    grid-column: 3;
    justify-self: end;
}

.chart-legend.chart-legend-bottom {
    justify-content: center;
    margin-top: .75rem;
}

.chart-legend-item {
    display: flex;
    align-items: center;
    gap: .35rem;
    font-size: .82rem;
    cursor: pointer;
    user-select: none;
    color: #4a5568;
}

.chart-legend-item.is-hidden {
    opacity: .4;
    text-decoration: line-through;
}

.chart-legend-swatch {
    display: inline-block;
    width: 12px;
    height: 12px;
    border-radius: 3px;
}

/* ── Division Compliance Summary table – kobo-source columns ────────────── */
#divisionComparisonTable th.kobo-source {
    background-color: #e6f4ea;
    font-weight: 700;
}

#divisionComparisonTable td.kobo-data {
    background-color: #e6f4ea;
}

/* ── Footer ─────────────────────────────────────────────────────────────── */
.fsa-footer {
    background: rgba(255, 172, 38, .55);
    color: #000;
    padding: 8px;
    text-align: center;
    box-shadow: 0 -3px 8px rgba(0,0,0,.08);
    margin-top: 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
}

.fsa-footer marquee {
    font-size: .875rem;
    font-weight: 500;
}

/* ── Map popup ──────────────────────────────────────────────────────────── */
.leaflet-popup-content {
    font-size: .875rem;
    line-height: 1.6;
    min-width: 180px;
}

/* ── Map legend ─────────────────────────────────────────────────────────── */
.map-legend {
    background-color: #ffffff;
    border: 2px solid #c8c8c8;
    border-radius: 6px;
    padding: 8px 12px 10px;
    font-size: 13px;
    line-height: 1.6;
    color: #333333;
    box-shadow: 0 3px 10px rgba(0,0,0,0.25);
    min-width: 175px;
}
.map-legend .legend-title {
    font-weight: 700;
    font-size: 13px;
    margin-bottom: 6px;
    border-bottom: 2px solid #e0e0e0;
    padding-bottom: 4px;
    color: #111111;
}
.map-legend .legend-item {
    display: flex;
    align-items: center;
    gap: 7px;
    margin-bottom: 4px;
}
.map-legend .legend-dot {
    display: inline-block;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    flex-shrink: 0;
    border: 1px solid rgba(0,0,0,0.25);
}

/* ── Building search autocomplete ──────────────────────────────────────── */
/* Keep the focus highlight on the search input itself, not the whole
   input-group (which also wraps the Search and Advanced Search buttons). */
.bsearch-group:focus-within,
.bsearch-group:focus {
    box-shadow: none !important;
}
.bsearch-group:focus-within::before,
.bsearch-group:focus::before {
    box-shadow: none !important;
}
/* Bootstrap also puts a primary-colored edge box-shadow on every .btn inside
   the input-group whenever any descendant has focus — strip that too so the
   Search / Advanced Building Search buttons don't pick up a focus ring. */
.bsearch-group:focus-within .btn,
.bsearch-group:focus .btn {
    box-shadow: none !important;
}
.bsearch-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: #ffffff;
    border: 1px solid #c8c8c8;
    border-top: none;
    border-radius: 0 0 6px 6px;
    box-shadow: 0 6px 16px rgba(0,0,0,0.15);
    max-height: 340px;
    overflow-y: auto;
    z-index: 1050;
}
.bsearch-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    cursor: pointer;
    border-bottom: 1px solid #f2f2f2;
}
.bsearch-item:last-child { border-bottom: none; }
.bsearch-item:hover,
.bsearch-item.bsearch-active { background: #f0f4ff; }
.bsearch-dot {
    width: 11px;
    height: 11px;
    border-radius: 50%;
    flex-shrink: 0;
    border: 1px solid rgba(0,0,0,0.18);
}
.bsearch-text { min-width: 0; }
.bsearch-name {
    font-weight: 600;
    font-size: .875rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.bsearch-meta {
    font-size: .75rem;
    color: #6c757d;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.bsearch-empty {
    padding: 10px 14px;
    font-size: .875rem;
    color: #6c757d;
}
.bsearch-more {
    padding: 6px 14px;
    font-size: .75rem;
    color: #999;
    background: #fafafa;
    border-top: 1px solid #eee;
    text-align: center;
}

/* ── Building detail modal ──────────────────────────────────────────────── */
.bdetail-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.55);
    z-index: 9000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
}
.bdetail-modal {
    background: #ffffff;
    border-radius: 8px;
    width: 100%;
    max-width: 680px;
    max-height: 88vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 16px 48px rgba(0,0,0,0.3);
}
.bdetail-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid #dee2e6;
    flex-shrink: 0;
}
.bdetail-header h6 { font-weight: 700; font-size: .95rem; }
.bdetail-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    line-height: 1;
    cursor: pointer;
    color: #888;
    padding: 0 2px;
}
.bdetail-close:hover { color: #111; }
.bdetail-body { overflow-y: auto; padding: 14px 16px; flex: 1; }
.bdetail-section { margin-bottom: 12px; }
.bdetail-row {
    display: flex;
    align-items: baseline;
    gap: 8px;
    padding: 5px 0;
    border-bottom: 1px solid #f2f2f2;
    font-size: .855rem;
}
.bdetail-row:last-child { border-bottom: none; }
.bdetail-lbl {
    width: 140px;
    flex-shrink: 0;
    color: #6c757d;
    font-weight: 500;
}
.bdetail-qtitle {
    font-weight: 700;
    font-size: .85rem;
    padding: 6px 0 6px;
    border-bottom: 2px solid #dee2e6;
    margin-bottom: 8px;
}
.bdetail-badge {
    display: inline-block;
    padding: 2px 9px;
    border-radius: 4px;
    font-size: .73rem;
    font-weight: 600;
    letter-spacing: .02em;
}
.bdetail-yes { background: #d4edda; color: #155724; }
.bdetail-no  { background: #f8d7da; color: #721c24; }
.bdetail-na  { background: #f0f0f0; color: #777; }

/* ── Building details page (buildingDetails.php) ─────────────────────────── */
/* Section group header */
.qgroup-header {
    background: linear-gradient(90deg,#696cff 0%,#5e63d8 100%);
    color: #fff;
    font-size: .8rem;
    font-weight: 700;
    letter-spacing: .06em;
    text-transform: uppercase;
    padding: 5px 10px;
}
.qgroup-header.orange { background: linear-gradient(90deg,#ff9f43 0%,#e8850e 100%); }
.qgroup-header.red    { background: linear-gradient(90deg,#ea5455 0%,#c73435 100%); }
.card-header:has(.qgroup-header) { overflow: hidden; border-bottom: none; }
.card-body:has(> .table-responsive:last-child) {
    overflow: hidden;
    border-bottom-left-radius: calc(0.375rem - 1px);
    border-bottom-right-radius: calc(0.375rem - 1px);
}

/* Remark row */
.q-remark-row td {
    background: #fffbf0;
    border-top: none !important;
    padding: 3px 10px 6px 42px !important;
    font-size: .75rem;
    color: #7a6000;
    font-style: italic;
}

/* Info grid */
.info-grid {
    display: flex;
    flex-direction: column;
}
.info-grid .ig-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    border-bottom: 1px solid #f2f2f2;
    transition: background-color .15s ease;
}
.info-grid .ig-row:last-child {
    border-bottom: none;
}
.info-grid .ig-row:nth-child(even) {
    background: #fafbfc;
}
.info-grid .ig-row:hover {
    background: #f1f2fe;
}
.info-grid .ig-field {
    padding: 10px 14px;
    border-right: 1px solid #f2f2f2;
}
.info-grid .ig-field:last-child {
    border-right: none;
}
.info-grid .ig-label {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: .72rem;
    color: #697a8d;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .03em;
    margin-bottom: 3px;
}
.info-grid .ig-label i {
    font-size: .9rem;
    color: #696cff;
    line-height: 1;
}
.info-grid .ig-value {
    display: block;
    font-size: .875rem;
    font-weight: 600;
    color: #1f2b3d;
}
@media (max-width: 575px) {
    .info-grid .ig-row { grid-template-columns: 1fr; }
    .info-grid .ig-field { border-right: none; border-bottom: 1px solid #f2f2f2; }
    .info-grid .ig-field:last-child { border-bottom: none; }
}

/* Photo gallery */
.photo-gallery {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    padding: 10px 0 0;
}
.photo-thumb {
    width: 120px;
    height: 120px;
    object-fit: cover;
    border-radius: 6px;
    border: 2px solid #dee2e6;
    cursor: pointer;
    transition: border-color .15s, transform .15s;
    display: block;
}
.photo-thumb:hover { border-color: #696cff; transform: scale(1.04); }

.doc-card {
    width: 120px;
    height: 120px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 6px;
    border-radius: 6px;
    border: 2px solid #dee2e6;
    background: #f8f9fa;
    cursor: pointer;
    text-decoration: none;
    transition: border-color .15s, transform .15s;
    padding: 6px;
}
.doc-card:hover { border-color: #696cff; transform: scale(1.04); }
.doc-card .doc-icon { font-size: 2.4rem; line-height: 1; }
.doc-card .doc-name {
    font-size: .65rem;
    color: #555;
    text-align: center;
    word-break: break-all;
    max-height: 40px;
    overflow: hidden;
}
.doc-card .doc-date { font-size: .65rem; color: #888; }

/* Lightbox */
#lightbox {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.88);
    z-index: 9900;
    align-items: center;
    justify-content: center;
    padding: 20px;
}
#lightbox.open { display: flex; }
#lightbox img {
    max-width: 90vw;
    max-height: 90vh;
    border-radius: 6px;
    box-shadow: 0 8px 32px rgba(0,0,0,.6);
}
#lightboxClose {
    position: fixed;
    top: 18px;
    right: 22px;
    color: #fff;
    font-size: 2.2rem;
    line-height: 1;
    cursor: pointer;
    background: none;
    border: none;
    z-index: 9901;
    padding: 0 4px;
}
#lightboxClose:hover { color: #ccc; }
#lightboxCaption {
    position: fixed;
    bottom: 16px;
    left: 0;
    right: 0;
    text-align: center;
    color: rgba(255,255,255,.75);
    font-size: .82rem;
}

/* Revisit card */
.revisit-badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: .78rem;
    font-weight: 600;
    background: #e8eaff;
    color: #363795;
}

/* ── KoboToolbox sync page (updatefsa.php) ───────────────────────────────── */
.sync-card { max-width: 860px; margin: 2.5rem auto; }

.log-box {
    background: #1e2a36;
    color: #c8d6e5;
    font-family: 'Courier New', monospace;
    font-size: .8rem;
    line-height: 1.6;
    border-radius: 8px;
    padding: 1rem 1.25rem;
    max-height: 400px;
    overflow-y: auto;
    white-space: pre-wrap;
    word-break: break-word;
}
.log-box .log-ok  { color: #28c76f; }
.log-box .log-err { color: #ea5455; }
.log-box .log-sep { color: #444e5a; }
.log-box .log-ts  { color: #7fa8cc; }

.spinner {
    display: inline-block;
    width: 1rem; height: 1rem;
    border: 2px solid rgba(255,255,255,.4);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin .7s linear infinite;
    vertical-align: middle;
    margin-right: .35rem;
}
@keyframes spin { to { transform: rotate(360deg); } }

#livePanel { display: none; }

/* Login modal overlay */
.login-overlay {
    position: fixed; inset: 0;
    background: rgba(34, 41, 57, 0.72);
    backdrop-filter: blur(4px);
    display: flex; align-items: center; justify-content: center;
    z-index: 9999;
}
.login-box {
    background: #fff;
    border-radius: 12px;
    padding: 2.2rem 2.4rem 2rem;
    width: 100%; max-width: 380px;
    box-shadow: 0 8px 32px rgba(0,0,0,.22);
}
.login-box h5 { font-weight: 700; margin-bottom: 1.4rem; text-align: center; }
.login-box .login-logo {
    display: flex; justify-content: center; gap: 1.5rem;
    margin-bottom: 1.2rem;
}
.login-box .login-logo img { height: 100px; object-fit: contain; }

/* ── Responsive tweaks ──────────────────────────────────────────────────── */
@media (max-width: 575.98px) {
    .fsa-header {
        flex-wrap: wrap;
        justify-content: center;
        padding: 14px 12px;
        gap: 10px;
    }
    .fsa-header-logo { height: 40px; }
    .fsa-header-title h4 { font-size: 1rem; }

    .stat-value  { font-size: 1.5rem; }
    .stat-icon   { width: 46px; height: 46px; }

    .card-header { flex-direction: column; align-items: flex-start !important; }

    .chart-header-grid {
        grid-template-columns: 1fr;
        justify-items: flex-start;
    }
    .chart-header-grid .chart-legend,
    .chart-header-grid .chart-level-label,
    .chart-header-grid .chart-header-actions {
        grid-column: 1;
        justify-self: flex-start;
    }
}

@media (min-width: 576px) and (max-width: 991.98px) {
    .fsa-header-title h4 { font-size: 1.15rem; }
}
