/* STM Map App — Styles v9 (v1.2.7 Sidebar Collapse + Bulk Edit Expand) */

* {
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    margin: 0;
    padding: 0;
    overflow: hidden;
    color: #1f2937;
}

#app {
    display: flex;
    height: 100vh;
    position: relative;
}

/* ---- Sidebar ---- */

#sidebar {
    width: 360px;
    background-color: #f8fafc;
    padding: 16px;
    box-shadow: 2px 0 6px rgba(0, 0, 0, 0.08);
    overflow-y: auto;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    position: relative;
}

#sidebar h1 {
    margin: 0 0 12px 0;
    font-size: 1.3em;
    color: #0f172a;
    white-space: nowrap;
    position: relative;
    padding-right: 44px;
    /* room for toggle button inside header */
}

#sidebar h2 {
    font-size: 1em;
    margin: 14px 0 8px 0;
    color: #475569;
    border-bottom: 1px solid #e2e8f0;
    padding-bottom: 4px;
}

/* ---- View Toggle ---- */

.view-toggle {
    display: flex;
    gap: 4px;
    margin-bottom: 12px;
}

.toggle-btn {
    flex: 1;
    padding: 8px;
    border: 1px solid #cbd5e1;
    background: #fff;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.85em;
    font-weight: 600;
    color: #475569;
    transition: all 0.15s;
}

.toggle-btn.active {
    background: #1e40af;
    color: #fff;
    border-color: #1e40af;
}

.toggle-btn:hover:not(.active) {
    background: #e2e8f0;
}

/* ---- Status Banner ---- */

.status-banner {
    padding: 6px 10px;
    border-radius: 6px;
    font-size: 0.8em;
    margin-bottom: 10px;
    text-align: center;
    font-weight: 500;
}

.status-ok {
    background: #f0fdf4;
    border: 1px solid #bbf7d0;
    color: #166534;
}

.status-loading {
    background: #f0f9ff;
    border: 1px solid #bae6fd;
    color: #0369a1;
}

.status-error {
    background: #fef2f2;
    border: 1px solid #fecaca;
    color: #991b1b;
    font-weight: 700;
}

/* ---- Filter ---- */

.filter-section {
    margin-bottom: 10px;
    position: relative;
}

.filter-count {
    display: block;
    font-size: 0.78em;
    color: #64748b;
    margin-top: 4px;
    text-align: right;
}

.filter-section label {
    display: block;
    margin-bottom: 3px;
    font-weight: 600;
    font-size: 0.82em;
    color: #475569;
}

.filter-section select {
    width: 100%;
    padding: 7px;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    font-size: 0.88em;
    background: #fff;
}

/* ---- Legend ---- */

.legend {
    display: flex;
    gap: 10px;
    margin-bottom: 12px;
    font-size: 0.78em;
    flex-wrap: wrap;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 4px;
}

.dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    display: inline-block;
}

.dot.green {
    background: #22c55e;
}

.dot.red {
    background: #ef4444;
}

.dot.orange {
    background: #f59e0b;
}

.dot.gray {
    background: #6b7280;
}

/* ---- Sale Status Tag ---- */

.sale-tag {
    display: inline-block;
    color: #fff;
    font-size: 0.72em;
    font-weight: 600;
    padding: 1px 6px;
    border-radius: 3px;
    white-space: nowrap;
}

/* ---- Property List ---- */

#propertyList {
    flex: 1;
    overflow-y: auto;
}

#properties {
    list-style: none;
    padding: 0 0 80px 0;
    margin: 0;
}

.property-item {
    background: #fff;
    border: 1px solid #e2e8f0;
    border-left: 4px solid #9ca3af;
    margin-bottom: 6px;
    padding: 8px 10px;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.15s, transform 0.1s;
}

.property-item:hover {
    background: #f1f5f9;
    transform: translateX(2px);
}

.state-border-viable {
    border-left-color: #22c55e;
}

.state-border-not_viable {
    border-left-color: #ef4444;
}

.state-border-pending {
    border-left-color: #f59e0b;
}

.prop-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 3px;
}

.prop-header strong {
    font-size: 0.85em;
    color: #0f172a;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 190px;
}

.prop-details {
    display: flex;
    gap: 8px;
    font-size: 0.78em;
    color: #64748b;
    flex-wrap: wrap;
    align-items: center;
    margin-bottom: 4px;
}

/* ---- Property Actions (in list) ---- */

.prop-actions {
    display: flex;
    gap: 4px;
    margin-top: 2px;
}

.action-btn {
    border: 1px solid #e2e8f0;
    background: #fff;
    border-radius: 6px;
    cursor: pointer;
    padding: 3px 8px;
    font-size: 1em;
    transition: all 0.15s;
    line-height: 1;
}

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

/* Star button (prominent) */
.star-btn {
    font-size: 1.2em;
    color: #9ca3af;
}

.star-btn.starred {
    color: #f59e0b;
    background: #fef3c7;
    border-color: #f59e0b;
    font-size: 1.2em;
}

/* Like button */
.like-btn.active {
    background: #dcfce7;
    border-color: #22c55e;
}

/* Pass button */
.pass-btn.active {
    background: #fee2e2;
    border-color: #ef4444;
}

/* ---- State Badges ---- */

.state-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 0.72em;
    font-weight: 700;
    text-transform: uppercase;
    white-space: nowrap;
}

.state-viable {
    background: #dcfce7;
    color: #166534;
}

.state-not_viable {
    background: #fee2e2;
    color: #991b1b;
}

.state-pending {
    background: #fef3c7;
    color: #92400e;
}

/* ---- Viability Badge (icon-only, replaces text state-badge in cards) ---- */
.viability-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1.3em;
    line-height: 1;
    min-width: 28px;
    min-height: 28px;
    border-radius: 6px;
    flex-shrink: 0;
}

.viability-viable {
    background: #dcfce7;
}

.viability-not_viable {
    background: #fee2e2;
}

.viability-pending {
    background: #fef3c7;
}

.viability-unknown {
    background: #f1f5f9;
}

/* ---- Factor Icons (compact property card) ---- */
.factor-icons {
    display: inline-flex;
    gap: 3px;
    align-items: center;
    margin-right: 4px;
}

.factor-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1em;
    font-weight: 900;
    min-width: 22px;
    min-height: 22px;
    border-radius: 4px;
    background: rgba(0, 0, 0, 0.04);
    cursor: default;
}

/* ---- Factor Pills (color-coded label+icon badges on property cards) ---- */
.prop-factors {
    display: flex;
    flex-wrap: wrap;
    gap: 3px;
    margin: 4px 0;
}

.factor-pill {
    display: inline-flex;
    align-items: center;
    gap: 2px;
    padding: 2px 7px;
    border-radius: 4px;
    font-size: 0.78em;
    font-weight: 600;
    white-space: nowrap;
    line-height: 1.3;
}

/* ---- Inline Edit (bulk table) ---- */
.inline-editable {
    cursor: pointer;
    border-bottom: 1px dashed rgba(0, 0, 0, 0.2);
    padding: 1px 2px;
}

.inline-editable:hover {
    background: #dbeafe;
    border-bottom-color: #3b82f6;
}

.inline-edit-input {
    font-size: inherit;
    padding: 2px 4px;
    border: 2px solid #3b82f6;
    border-radius: 4px;
    background: #fff;
    min-width: 60px;
    width: 100%;
}

.bulk-actions-cell {
    white-space: nowrap;
}

.bulk-actions-cell .small-btn {
    margin: 0 1px;
}

/* ---- Map ---- */

#map-container {
    flex-grow: 1;
    position: relative;
}

#mapid {
    height: 100%;
    width: 100%;
}

/* ---- Popup ---- */

.leaflet-popup-content-wrapper {
    border-radius: 8px;
}

.leaflet-popup-content {
    font-size: 13px;
    line-height: 1.5;
    min-width: 260px;
}

.leaflet-popup-content h3 {
    margin: 0 0 4px 0;
    font-size: 1em;
    color: #0f172a;
}

.leaflet-popup-content p {
    margin: 2px 0;
}

.factor-row {
    margin: 6px 0;
}

.popup-actions {
    margin-top: 8px;
    display: flex;
    gap: 4px;
}

.popup-actions button {
    flex: 1;
    padding: 5px 6px;
    border: 1px solid #cbd5e1;
    background: #fff;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.85em;
    transition: all 0.15s;
}

.popup-actions button:hover {
    background: #e2e8f0;
}

.popup-actions .active-like {
    background: #dcfce7;
    border-color: #22c55e;
    font-weight: 700;
}

.popup-actions .active-pass {
    background: #fee2e2;
    border-color: #ef4444;
    font-weight: 700;
}

.popup-actions .active-star {
    background: #fef3c7;
    border-color: #f59e0b;
    font-weight: 700;
}

.detail-link {
    display: block;
    width: 100%;
    margin-top: 8px;
    padding: 6px;
    background: #1e40af;
    color: #fff;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.85em;
    font-weight: 600;
    text-align: center;
}

.detail-link:hover {
    background: #1e3a8a;
}

/* ---- Detail Panel (slide-in) ---- */

.detail-panel {
    position: fixed;
    right: 0;
    top: 0;
    width: 380px;
    height: 100vh;
    height: 100dvh;
    max-height: -webkit-fill-available;
    background: #fff;
    box-shadow: -4px 0 12px rgba(0, 0, 0, 0.15);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    z-index: 9500;
    transition: transform 0.25s ease;
    transform: translateX(0);
    padding-bottom: 40px;
    box-sizing: border-box;
}

.detail-panel.hidden {
    transform: translateX(100%);
    pointer-events: none;
}

.detail-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    background: #1e40af;
    color: #fff;
    position: sticky;
    top: 0;
    z-index: 1;
}

.detail-header h2 {
    margin: 0;
    font-size: 1em;
    color: #fff;
    border: none;
    padding: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 280px;
}

.close-btn {
    background: none;
    border: none;
    color: #fff;
    font-size: 1.2em;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
}

.close-btn:hover {
    background: rgba(255, 255, 255, 0.2);
}

.detail-section {
    padding: 12px 16px;
    border-bottom: 1px solid #e2e8f0;
}

.detail-section h3 {
    margin: 0 0 8px 0;
    font-size: 0.9em;
    color: #475569;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.detail-status-row {
    display: flex;
    gap: 8px;
    align-items: center;
}

.detail-table {
    width: 100%;
    font-size: 0.85em;
    border-collapse: collapse;
}

.detail-table td {
    padding: 3px 0;
    vertical-align: top;
}

.detail-table td:first-child {
    font-weight: 600;
    color: #475569;
    width: 100px;
    white-space: nowrap;
}

.detail-table td:last-child {
    color: #1f2937;
    word-break: break-word;
}

.detail-actions {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.reaction-row {
    display: flex;
    gap: 8px;
}

.big-action-btn {
    padding: 10px 16px;
    border: 2px solid #e2e8f0;
    background: #fff;
    border-radius: 8px;
    cursor: pointer;
    font-size: 1em;
    font-weight: 600;
    transition: all 0.15s;
    flex: 1;
    text-align: center;
}

.big-action-btn:hover {
    background: #f1f5f9;
}

.big-action-btn.active-star {
    background: #fef3c7;
    border-color: #f59e0b;
    color: #92400e;
}

.big-action-btn.active-like {
    background: #dcfce7;
    border-color: #22c55e;
    color: #166534;
}

.big-action-btn.active-pass {
    background: #fee2e2;
    border-color: #ef4444;
    color: #991b1b;
}

.detail-meta {
    font-size: 0.78em;
    color: #94a3b8;
}

.detail-meta p {
    margin: 0;
}

/* ---- Admin Panel ---- */

.admin-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85em;
}

.admin-table td,
.admin-table th {
    padding: 4px 8px;
    text-align: left;
}

.admin-table tr:nth-child(even) {
    background: #f1f5f9;
}

.admin-table .viable {
    color: #166534;
    font-weight: 600;
}

.admin-table .not-viable {
    color: #991b1b;
    font-weight: 600;
}

.admin-table .pending-state {
    color: #92400e;
    font-weight: 600;
}

.attention th {
    background: #1e293b;
    color: #fff;
    font-size: 0.8em;
}

.hold-badge {
    display: inline-block;
    background: #fef3c7;
    color: #92400e;
    padding: 1px 6px;
    border-radius: 3px;
    font-size: 0.8em;
    font-weight: 600;
}

#btn-recalculate {
    width: 100%;
    margin-top: 12px;
    padding: 10px;
    background: #1e40af;
    color: #fff;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.9em;
    font-weight: 600;
    transition: background 0.15s;
}

#btn-recalculate:hover {
    background: #1e3a8a;
}

#btn-recalculate:disabled {
    background: #94a3b8;
    cursor: not-allowed;
}

/* Custom marker container */
.custom-marker {
    background: none !important;
    border: none !important;
}

/* ---- Filter Bar (All / Active / Liked / Starred) ---- */

.filter-bar {
    display: flex;
    gap: 4px;
    margin-bottom: 8px;
}

.filter-btn {
    flex: 1;
    padding: 6px 4px;
    border: 1px solid #cbd5e1;
    background: #fff;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.78em;
    font-weight: 600;
    color: #475569;
    transition: all 0.15s;
    text-align: center;
}

.filter-btn.active {
    background: #1e40af;
    color: #fff;
    border-color: #1e40af;
}

.filter-btn:hover:not(.active) {
    background: #e2e8f0;
}

/* ---- Gold dot for Starred ---- */
.dot.gold {
    background: #f59e0b;
}

/* ---- Reaction tag in list ---- */
.reaction-tag {
    font-size: 1em;
}

/* ---- Document links ---- */
.doc-link {
    display: inline-block;
    padding: 6px 12px;
    background: #eff6ff;
    border: 1px solid #93c5fd;
    border-radius: 6px;
    color: #1e40af;
    text-decoration: none;
    font-size: 0.85em;
    font-weight: 600;
    margin-right: 6px;
    margin-bottom: 4px;
    transition: background 0.15s;
}

.doc-link:hover {
    background: #dbeafe;
}

/* ---- Deal badges ---- */
.deal-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 0.78em;
    font-weight: 700;
    text-transform: uppercase;
}

.deal-prospecting {
    background: #eff6ff;
    color: #1e40af;
}

.deal-loi_sent {
    background: #fef3c7;
    color: #92400e;
}

.deal-under_contract {
    background: #dcfce7;
    color: #166534;
}

.deal-closed {
    background: #22c55e;
    color: #fff;
}

.deal-dead {
    background: #fee2e2;
    color: #991b1b;
}

.deal-none {
    background: #f1f5f9;
    color: #64748b;
}

/* ---- Broker button ---- */
.broker-btn {
    background: #eff6ff !important;
    border-color: #3b82f6 !important;
    color: #1e40af !important;
}

.broker-btn:hover {
    background: #dbeafe !important;
}

/* ---- Modal overlay ---- */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-content {
    background: #fff;
    border-radius: 12px;
    width: 420px;
    max-width: 95vw;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 18px;
    border-bottom: 1px solid #e2e8f0;
}

.modal-header h3 {
    margin: 0;
    font-size: 1em;
    color: #0f172a;
}

.modal-body {
    padding: 18px;
}

.modal-body label {
    display: block;
    font-size: 0.82em;
    font-weight: 600;
    color: #475569;
    margin-top: 10px;
    margin-bottom: 3px;
}

.modal-body input,
.modal-body textarea {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    font-size: 0.88em;
    font-family: inherit;
}

.modal-body textarea {
    resize: vertical;
}

.submit-btn {
    display: block;
    width: 100%;
    margin-top: 14px;
    padding: 10px;
    background: #1e40af;
    color: #fff;
    border: none;
    border-radius: 6px;
    font-size: 0.9em;
    font-weight: 600;
    cursor: pointer;
}

.submit-btn:hover {
    background: #1e3a8a;
}

/* ---- Bulk Edit Table ---- */
.bulk-table-wrap {
    max-height: 50vh;
    overflow-y: auto;
    overflow-x: auto;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    margin-bottom: 10px;
}

#bulk-edit-section {
    margin-top: 8px;
    border-top: 1px solid #e2e8f0;
    padding-top: 8px;
}

/* Bulk Edit full-screen expansion */
#bulk-edit-section.expanded {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 9000;
    background: #f8fafc;
    padding: 20px;
    overflow-y: auto;
}

#bulk-edit-section.expanded .bulk-table-wrap {
    max-height: calc(100vh - 120px);
    border-radius: 8px;
}

#bulk-edit-section.expanded .bulk-edit-table {
    font-size: 0.85em;
}

#bulk-edit-section.expanded .bulk-edit-table td {
    max-width: none;
    white-space: normal;
}

/* Expand button — prominent */
.expand-btn {
    padding: 6px 14px;
    border: 2px solid #3b82f6;
    background: #eff6ff;
    border-radius: 6px;
    cursor: pointer;
    font-size: 1em;
    font-weight: 700;
    color: #1e40af;
    transition: all 0.15s;
    white-space: nowrap;
    min-height: 38px;
}

.expand-btn:hover {
    background: #dbeafe;
}

#bulk-edit-section.expanded .expand-btn {
    font-size: 1.1em;
    padding: 8px 18px;
    background: #fee2e2;
    border-color: #ef4444;
    color: #991b1b;
}

.bulk-edit-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.75em;
}

.bulk-edit-table th {
    background: #1e293b;
    color: #fff;
    padding: 4px 6px;
    text-align: left;
    position: sticky;
    top: 0;
    font-weight: 600;
    cursor: pointer;
    user-select: none;
}

.bulk-edit-table th:hover {
    background: #334155;
}

.bulk-edit-table td {
    padding: 3px 6px;
    border-bottom: 1px solid #f1f5f9;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 120px;
}

.bulk-edit-table tr:nth-child(even) {
    background: #f8fafc;
}

.bulk-edit-table tr:hover {
    background: #e2e8f0;
}

.small-btn {
    padding: 2px 8px;
    border: 1px solid #cbd5e1;
    background: #fff;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.9em;
    transition: background 0.15s;
}

.small-btn:hover {
    background: #e2e8f0;
}

/* ---- Market Selector (v1.2) ---- */
/* Build version badge — fixed bottom-right */
.build-badge {
    position: fixed;
    bottom: 8px;
    right: 12px;
    font-size: 0.85em;
    color: #1e293b;
    background: rgba(255, 255, 255, 0.95);
    padding: 4px 12px;
    border-radius: 6px;
    border: 1px solid #cbd5e1;
    z-index: 9999;
    pointer-events: none;
    font-family: monospace;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.market-selector {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 10px;
    background: #f8fafc;
    border-bottom: 1px solid #e2e8f0;
}

.market-selector label {
    font-size: 0.82em;
    font-weight: 600;
    color: #475569;
    white-space: nowrap;
}

.market-selector select {
    flex: 1;
    padding: 4px 8px;
    border: 1px solid #cbd5e1;
    border-radius: 4px;
    font-size: 0.85em;
    background: #fff;
}

/* ---- GIS Source line (v1.2) ---- */
.gis-source {
    font-size: 0.72em;
    color: #94a3b8;
    margin-top: 8px;
    padding-top: 4px;
    border-top: 1px solid #e2e8f0;
    font-style: italic;
}

/* ---- Blue dot for For Sale legend (v1.2.4) ---- */
.dot.blue {
    background: #3b82f6;
}

/* ---- z-index hierarchy (v1.2.12) ----
   Leaflet controls : 1000
   Sidebar toggle    : 1100  (only when floating over map)
   Modals / overlays : 9999
   ---- */
.leaflet-control-zoom,
.leaflet-control-layers {
    z-index: 1000 !important;
}

.leaflet-top.leaflet-right,
.leaflet-top.leaflet-left,
.leaflet-bottom.leaflet-right,
.leaflet-bottom.leaflet-left {
    z-index: 1000 !important;
    pointer-events: auto;
}

/* ---- Leaflet layers control: text fallback, never blank (v1.2.11) ---- */
/* Force expanded view so we never depend on layers.png icon */
.leaflet-control-layers-toggle {
    background-image: none !important;
    width: auto !important;
    height: auto !important;
    padding: 6px 10px !important;
    font-size: 14px;
    line-height: 1.3;
    color: #333;
}

.leaflet-control-layers-toggle::after {
    content: '🗺 Layers';
}

.leaflet-control-layers {
    background: #fff;
    border-radius: 8px !important;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15) !important;
}

/* ---- Sidebar toggle (v1.2.12) ---- */
/* Default: lives inside sidebar h1, positioned absolute top-right of header */
#sidebar-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    position: absolute;
    top: -2px;
    right: 0;
    width: 32px;
    height: 32px;
    background: #fff;
    border: 2px solid #3b82f6;
    border-radius: 8px;
    font-size: 18px;
    cursor: pointer;
    z-index: 2;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.12);
    -webkit-tap-highlight-color: transparent;
    transition: none;
}

/* When sidebar is collapsed, JS moves button to #app and we float it over the map */
body.sidebar-collapsed #sidebar-toggle {
    position: fixed;
    top: 82px;
    left: 12px;
    width: 36px;
    height: 36px;
    font-size: 20px;
    z-index: 1100;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.18);
}

/* Desktop sidebar collapse */
#sidebar {
    transition: width 0.25s ease, padding 0.25s ease;
}

#sidebar.collapsed {
    width: 0 !important;
    padding: 0 !important;
    overflow: hidden !important;
    border-right: none;
}

#sidebar.collapsed~#map-container {
    flex: 1;
}

@media (max-width: 768px) {
    #sidebar {
        position: fixed;
        left: 0;
        top: 0;
        height: 100vh;
        width: 85vw;
        max-width: 360px;
        z-index: 1000;
        transform: translateX(-100%);
        transition: transform 0.25s ease;
    }

    #sidebar.open {
        transform: translateX(0);
    }

    /* Mobile: toggle inside header when sidebar open */
    #sidebar.open #sidebar-toggle {
        position: absolute;
        top: -2px;
        right: 0;
        width: 40px;
        height: 40px;
        font-size: 20px;
    }

    /* Mobile: toggle floating when sidebar closed (button is in #app) */
    body:not(.sidebar-open)>#sidebar-toggle {
        position: fixed;
        top: 82px;
        left: 10px;
        width: 44px;
        height: 44px;
        border-radius: 10px;
        font-size: 22px;
        z-index: 1100;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
    }

    #sidebar-overlay {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.3);
        z-index: 999;
    }

    #sidebar.open+#sidebar-overlay,
    #sidebar.open~#sidebar-overlay {
        display: block;
    }

    #map-container {
        width: 100vw;
        height: 100vh;
    }

    /* Legend stays visible on map */
    .legend {
        position: fixed;
        bottom: 48px;
        left: 10px;
        background: rgba(255, 255, 255, 0.92);
        padding: 6px 10px;
        border-radius: 8px;
        z-index: 800;
        box-shadow: 0 1px 4px rgba(0, 0, 0, 0.15);
        pointer-events: none;
    }

    .build-badge {
        bottom: 4px;
        right: 4px;
        font-size: 0.7em;
        padding: 2px 8px;
    }

    /* Move GPS button above build badge */
    #gps-locate-btn {
        bottom: 36px !important;
        right: 8px !important;
    }

    /* Make filter bar horizontal scroll on tiny screens */
    .filter-bar {
        overflow-x: auto;
        flex-wrap: nowrap;
    }

    /* ---- Detail Panel: Mobile Bottom Sheet ---- */
    .detail-panel {
        top: auto;
        bottom: 0;
        left: 0;
        right: 0;
        width: 100%;
        height: 65vh;
        max-height: 65vh;
        border-radius: 16px 16px 0 0;
        box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.2);
        transform: translateY(100%);
        transition: transform 0.25s ease;
    }

    .detail-panel:not(.hidden) {
        transform: translateY(0);
    }

    .detail-panel.hidden {
        transform: translateY(100%);
    }

    .detail-header {
        border-radius: 16px 16px 0 0;
    }
}

/* ---- Touch: prevent accidental text selection on map interactions ---- */
#mapid {
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
    touch-action: manipulation;
}

/* ---- Broker Send Bottom Sheet (v1.2.5) ---- */

/* ---- Admin Edit enhancements (v1.2.6) ---- */
.edit-section-label {
    font-size: 0.78em;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: #1e40af;
    margin-top: 14px;
    margin-bottom: 4px;
    padding-top: 10px;
    border-top: 1px solid #e2e8f0;
}

.edit-section-label:first-of-type {
    border-top: none;
    margin-top: 0;
    padding-top: 0;
}

.note-item {
    padding: 4px 0;
    border-bottom: 1px solid #f1f5f9;
    font-size: 0.88em;
    line-height: 1.4;
}

.note-date {
    color: #94a3b8;
    font-size: 0.82em;
    margin-right: 6px;
}

/* ---- Detail panel: files + broker cases (v1.2.6) ---- */
.files-list {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.cases-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.case-item {
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    padding: 8px 10px;
    font-size: 0.85em;
}

.case-item .deal-badge {
    margin-right: 6px;
}

.case-date {
    color: #94a3b8;
    font-size: 0.82em;
    margin-right: 6px;
}

.case-broker {
    color: #475569;
    font-weight: 600;
}

.case-msg {
    margin: 4px 0 0 0;
    color: #64748b;
    font-size: 0.9em;
    white-space: pre-wrap;
    word-break: break-word;
}

.broker-sheet-overlay {
    position: fixed;
    inset: 0;
    z-index: 10000;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    pointer-events: auto;
}

.broker-sheet-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    -webkit-tap-highlight-color: transparent;
}

.broker-sheet {
    position: relative;
    background: #fff;
    border-radius: 16px 16px 0 0;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.2);
    animation: broker-sheet-up 0.25s ease-out;
}

@keyframes broker-sheet-up {
    from {
        transform: translateY(100%);
    }

    to {
        transform: translateY(0);
    }
}

.broker-sheet-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 18px;
    border-bottom: 1px solid #e2e8f0;
    flex-shrink: 0;
}

.broker-sheet-header h3 {
    margin: 0;
    font-size: 1.05em;
    color: #0f172a;
}

.broker-sheet-header .close-btn {
    background: none;
    border: none;
    font-size: 1.3em;
    cursor: pointer;
    color: #64748b;
    padding: 4px 8px;
    border-radius: 4px;
    -webkit-tap-highlight-color: transparent;
}

.broker-sheet-body {
    overflow-y: auto;
    padding: 16px 18px;
    flex: 1;
    -webkit-overflow-scrolling: touch;
}

.broker-route-info {
    font-size: 0.85em;
    color: #475569;
    background: #f0f9ff;
    border: 1px solid #bae6fd;
    border-radius: 6px;
    padding: 8px 12px;
    margin-bottom: 12px;
}

.broker-parcel-summary {
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 10px 14px;
    margin-bottom: 12px;
}

.bps-row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    padding: 3px 0;
    font-size: 0.88em;
    border-bottom: 1px solid #f1f5f9;
}

.bps-row:last-child {
    border-bottom: none;
}

.bps-label {
    font-weight: 600;
    color: #475569;
    min-width: 72px;
}

.bps-value {
    color: #1f2937;
    text-align: right;
    word-break: break-word;
}

.broker-sheet-body label {
    display: block;
    font-size: 0.82em;
    font-weight: 600;
    color: #475569;
    margin-top: 8px;
    margin-bottom: 3px;
}

.broker-sheet-body textarea,
.broker-sheet-body input[type="file"] {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    font-size: 0.88em;
    font-family: inherit;
}

.broker-sheet-body textarea {
    resize: vertical;
    min-height: 60px;
}

.broker-sheet-footer {
    padding: 12px 18px;
    border-top: 1px solid #e2e8f0;
    background: #fff;
    flex-shrink: 0;
    position: sticky;
    bottom: 0;
}

.broker-send-btn {
    display: block;
    width: 100%;
    padding: 14px;
    background: #1e40af;
    color: #fff;
    border: none;
    border-radius: 10px;
    font-size: 1.05em;
    font-weight: 700;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    transition: background 0.15s;
}

.broker-send-btn:hover {
    background: #1e3a8a;
}

.broker-send-btn:disabled {
    background: #94a3b8;
    cursor: not-allowed;
}

/* Desktop: center the sheet as a card instead of full-width bottom */
@media (min-width: 769px) {
    .broker-sheet-overlay {
        justify-content: center;
        align-items: center;
    }

    .broker-sheet {
        border-radius: 12px;
        max-width: 480px;
        width: 90%;
        max-height: 80vh;
    }
}

/* ── Contact action buttons ─────────────────────────────── */
.contact-link {
    color: #2563eb;
    text-decoration: none;
    font-weight: 600;
}

.contact-link:hover {
    text-decoration: underline;
}

.contact-none {
    color: #94a3b8;
    font-style: italic;
}

.copy-micro-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: #f1f5f9;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.8em;
    padding: 2px 5px;
    margin-left: 4px;
    vertical-align: middle;
    min-width: 26px;
    min-height: 26px;
    transition: background 0.15s;
}

.copy-micro-btn:hover {
    background: #e2e8f0;
}

.copy-micro-btn:active {
    background: #cbd5e1;
}

/* Ensure phone/email cells don't wrap awkwardly */
.contact-table td:last-child {
    white-space: nowrap;
}

/* Bigger tap targets on mobile */
@media (max-width: 768px) {
    .copy-micro-btn {
        min-width: 36px;
        min-height: 36px;
        font-size: 1em;
        padding: 4px 8px;
    }

    .contact-link {
        font-size: 1.05em;
        padding: 2px 0;
    }

    .contact-table td:last-child {
        white-space: normal;
    }
}

/* Source IDs section */
.detail-source-ids table td:first-child {
    width: 110px;
}

/* ── Auto-Verify progress ─────────────────────── */
.verify-progress-box {
    border-radius: 6px;
    padding: 10px 12px;
    font-size: 0.85em;
    margin-top: 6px;
}

.verify-progress-box.verify-running {
    background: #eff6ff;
    border: 1px solid #93c5fd;
    color: #1e40af;
}

.verify-progress-box.verify-done {
    background: #f0fdf4;
    border: 1px solid #86efac;
    color: #166534;
}

.verify-progress-box.verify-fail {
    background: #fef2f2;
    border: 1px solid #fca5a5;
    color: #991b1b;
}

.verify-bar-track {
    margin-top: 6px;
    height: 10px;
    background: #dbeafe;
    border-radius: 5px;
    overflow: hidden;
}

.verify-bar-fill {
    height: 100%;
    background: #3b82f6;
    border-radius: 5px;
    transition: width 0.4s ease;
}

/* ── Verification filter bar ───────────────────── */
.vf-bar {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    margin-bottom: 8px;
    padding: 6px 0;
}

.vf-btn {
    font-size: 0.8em;
    padding: 4px 10px;
    border-radius: 6px;
    border: 2px solid;
    background: transparent;
    cursor: pointer;
    font-weight: 600;
    transition: background 0.15s, color 0.15s;
}

.vf-btn:hover {
    opacity: 0.85;
}

.vf-btn.vf-active {
    color: #fff !important;
}

/* ── Verification reason badges ────────────────── */
.v-badge {
    display: inline-block;
    font-size: 0.72em;
    font-weight: 600;
    padding: 1px 6px;
    border-radius: 4px;
    white-space: nowrap;
    cursor: default;
}

.v-badge-ok {
    background: #dcfce7;
    color: #166534;
}

.v-badge-unk {
    color: #9ca3af;
}

.v-badge-pin {
    background: #fef3c7;
    color: #92400e;
}

.v-badge-acre {
    background: #fef3c7;
    color: #92400e;
}

.v-badge-multi {
    background: #ede9fe;
    color: #6d28d9;
}

.v-badge-fail {
    background: #fee2e2;
    color: #991b1b;
}

.v-badge-warn {
    background: #fef3c7;
    color: #92400e;
}