/* ============================================================
   PIELH QA Dashboard — styles.css
   ============================================================ */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 13px;
    background: #f1f5f9;
    color: #1e293b;
}

#app {
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
}

/* ── Header ────────────────────────────────────────────────── */

.header {
    flex: 0 0 auto;
    background: #1e3a5f;
    color: #fff;
    display: flex;
    align-items: center;
    gap: 24px;
    padding: 10px 20px;
    box-shadow: 0 2px 8px rgba(0,0,0,.25);
    flex-wrap: wrap;
}

.header-brand h1 {
    font-size: 20px;
    font-weight: 700;
    letter-spacing: .5px;
    line-height: 1.1;
}

.header-sub {
    font-size: 11px;
    opacity: .7;
    display: block;
}

.summary-cards {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    margin-left: auto;
}

.card {
    background: rgba(255,255,255,.12);
    border: 1px solid rgba(255,255,255,.2);
    border-radius: 8px;
    padding: 6px 14px;
    min-width: 72px;
    text-align: center;
}

.card-alert {
    background: rgba(234, 88, 12, .25);
    border-color: rgba(234, 88, 12, .5);
}

.card-value {
    font-size: 22px;
    font-weight: 700;
    line-height: 1.1;
}

.card-label {
    font-size: 10px;
    opacity: .8;
    text-transform: uppercase;
    letter-spacing: .4px;
    margin-top: 2px;
}

.card-sub-label {
    font-size: 9px;
    opacity: .65;
    margin-top: 1px;
    min-height: 11px;
}

.btn-explorer {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 7px 16px;
    background: linear-gradient(135deg, #38bdf8 0%, #2563eb 100%);
    border: none;
    color: #fff;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: .4px;
    text-decoration: none;
    text-transform: uppercase;
    white-space: nowrap;
    box-shadow: 0 2px 10px rgba(37,99,235,.45);
    transition: transform .15s, box-shadow .15s;
}
.btn-explorer::before {
    content: '⬡';
    font-size: 14px;
    opacity: .9;
}
.btn-explorer:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 16px rgba(37,99,235,.6);
}

.btn-sync {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 7px 16px;
    background: linear-gradient(135deg, #34d399 0%, #059669 100%);
    border: none;
    color: #fff;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: .4px;
    text-transform: uppercase;
    white-space: nowrap;
    cursor: pointer;
    box-shadow: 0 2px 10px rgba(5,150,105,.45);
    transition: transform .15s, box-shadow .15s;
}
.btn-sync:hover:not(:disabled) {
    transform: translateY(-1px);
    box-shadow: 0 4px 16px rgba(5,150,105,.6);
}
.btn-sync:disabled { opacity: .5; cursor: default; transform: none; }

.sync-status {
    font-size: 11px;
    color: rgba(255,255,255,.7);
    white-space: nowrap;
    max-width: 260px;
    overflow: hidden;
    text-overflow: ellipsis;
}

.btn-sync-record {
    font-size: 12px;
    padding: 5px 12px;
    border-color: #d97706;
    color: #d97706;
}

/* ── Alerts ────────────────────────────────────────────────── */

.alert {
    padding: 8px 20px;
    font-size: 13px;
    flex: 0 0 auto;
}

.alert-error {
    background: #fee2e2;
    color: #991b1b;
    border-bottom: 1px solid #fca5a5;
}

.alert-info {
    background: #dbeafe;
    color: #1e40af;
    border-bottom: 1px solid #93c5fd;
}

/* ── Main layout ───────────────────────────────────────────── */

.main-layout {
    flex: 1;
    display: flex;
    min-height: 0;
    overflow: hidden;
}

/* ── Sidebar ───────────────────────────────────────────────── */

.sidebar {
    flex: 0 0 210px;
    background: #fff;
    border-right: 1px solid #e2e8f0;
    overflow-y: auto;
    padding: 14px 12px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.sidebar-title {
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .6px;
    color: #64748b;
    margin-bottom: 8px;
}

.filter-group {
    display: flex;
    flex-direction: column;
    gap: 3px;
    margin-bottom: 8px;
}

.filter-group label {
    font-size: 11px;
    font-weight: 600;
    color: #475569;
    text-transform: uppercase;
    letter-spacing: .4px;
}

.filter-group input,
.filter-group select {
    width: 100%;
    padding: 5px 8px;
    border: 1px solid #cbd5e1;
    border-radius: 5px;
    font-size: 12px;
    background: #f8fafc;
    color: #1e293b;
    outline: none;
    transition: border-color .15s;
}

.filter-group input:focus,
.filter-group select:focus {
    border-color: #2563eb;
    background: #fff;
}

.btn-reset {
    width: 100%;
    padding: 6px;
    background: #f1f5f9;
    border: 1px solid #cbd5e1;
    border-radius: 5px;
    font-size: 12px;
    color: #475569;
    cursor: pointer;
    margin-top: 2px;
    transition: background .15s;
}

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

.btn-resolve {
    width: 100%;
    padding: 6px;
    background: #f5f3ff;
    border: 1px solid #c4b5fd;
    border-radius: 5px;
    font-size: 12px;
    color: #6d28d9;
    cursor: pointer;
    margin-top: 6px;
    transition: background .15s;
}
.btn-resolve:hover:not(:disabled) { background: #ede9fe; }
.btn-resolve:disabled { opacity: .5; cursor: default; }
.btn-resolve.btn-resolve-secondary { opacity: .7; font-size: .8rem; }
.btn-resolve.btn-resolve-secondary:hover:not(:disabled) { opacity: 1; background: #ede9fe; }

/* ── Modal ─────────────────────────────────────────────────── */

.modal-overlay {
    position: fixed; inset: 0;
    background: rgba(15,23,42,.55);
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-box {
    background: #fff;
    border-radius: 12px;
    width: 500px;
    max-width: 92vw;
    display: flex;
    flex-direction: column;
    box-shadow: 0 8px 40px rgba(0,0,0,.3);
    overflow: hidden;
}

.modal-header {
    padding: 14px 20px;
    font-weight: 700;
    font-size: 14px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid #e2e8f0;
    background: #f8fafc;
}

.modal-close {
    background: none; border: none; cursor: pointer;
    font-size: 17px; color: #94a3b8; line-height: 1;
}
.modal-close:hover:not(:disabled) { color: #1e293b; }
.modal-close:disabled { opacity: .35; cursor: default; }

.modal-progress-wrap {
    height: 3px;
    background: #e2e8f0;
}
.modal-progress-bar {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, #a78bfa, #6d28d9);
    transition: width .4s ease;
}

.modal-log {
    overflow-y: auto;
    padding: 10px 16px;
    font-size: 11.5px;
    font-family: 'Consolas', 'Courier New', monospace;
    line-height: 1.9;
    min-height: 160px;
    max-height: 340px;
    color: #475569;
}
.modal-log-ok  { color: #059669; }
.modal-log-err { color: #dc2626; }
.modal-log-dim { color: #94a3b8; }

.modal-footer {
    padding: 10px 16px;
    font-size: 11px;
    color: #64748b;
    border-top: 1px solid #e2e8f0;
    background: #f8fafc;
    min-height: 36px;
}

/* ── Resolve summary block ─────────────────────────────────── */

.rsb { font-size: 11px; color: #334155; }
.rsb-title { font-weight: 600; font-size: 12px; margin-bottom: 8px; color: #1e293b; }
.rsb-grid { display: flex; gap: 24px; margin-bottom: 8px; }
.rsb-col { flex: 1; }
.rsb-section { font-weight: 600; color: #6d28d9; text-transform: uppercase; letter-spacing: .04em; font-size: 10px; margin-bottom: 4px; }
.rsb-row { margin-bottom: 2px; }
.rsb-ok   { color: #059669; }
.rsb-warn { color: #d97706; }
.rsb-dim  { color: #94a3b8; }
.rsb-sensors { margin-bottom: 6px; border-top: 1px solid #e2e8f0; padding-top: 6px; }
.rsb-unknown { color: #64748b; }
.rsb-tags { font-style: italic; word-break: break-all; }

/* ── Legend ────────────────────────────────────────────────── */

.legend-details {
    margin-top: 12px;
    border-top: 1px solid #e2e8f0;
}
.legend-toggle {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .4px;
    color: #94a3b8;
    padding: 6px 0 4px;
    cursor: pointer;
    list-style: none;
    display: flex;
    align-items: center;
    gap: 4px;
    user-select: none;
}
.legend-toggle::-webkit-details-marker { display: none; }
.legend-toggle::before {
    content: '▶';
    font-size: 8px;
    transition: transform 0.15s;
    color: #94a3b8;
}
.legend-details[open] .legend-toggle::before { transform: rotate(90deg); }
.legend-details[open] .legend-toggle { color: #64748b; }

.legend {
    margin-top: 4px;
    padding-top: 6px;
}

.legend-title {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .4px;
    color: #64748b;
    margin-bottom: 6px;
}

.legend-row {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 11.5px;
    margin-bottom: 4px;
    color: #475569;
}

/* Generic dot (circle) */
.ldot {
    width: 11px;
    height: 11px;
    border-radius: 50%;
    display: inline-block;
    flex-shrink: 0;
    border: 1.5px solid;
}

/* Square for buildings */
.legend-square {
    width: 12px;
    height: 12px;
    display: inline-block;
    flex-shrink: 0;
    border-radius: 2px;
    border: 1.5px solid #1d4ed8;
    background: rgba(37,99,235,.55);
}

/* Dashed line for districts */
.legend-line {
    width: 22px;
    height: 0;
    display: inline-block;
    flex-shrink: 0;
    border-top: 2.5px dashed;
}
.legend-line-district  { border-color: #1e40af; }
.legend-line-neighborhood { border-color: #15803d; }

/* Legend color variants */
.ldot-neighborhood { background: rgba(34,197,94,.25); border-color: #15803d; }
.ldot-street       { background: rgba(139,92,246,.7); border-color: #6d28d9; }
.ldot-sensor       { background: rgba(249,115,22,.8); border-color: #ea580c; }
.ldot-other        { background: rgba(22,163,74,.35); border-color: #15803d; }

/* System legend */
.legend-sys-id {
    font-size: 10px;
    font-weight: 700;
    color: #334155;
    min-width: 34px;
    font-family: monospace;
}

.legend-sys-name {
    font-size: 10px;
    color: #64748b;
}

.legend-note {
    font-size: 10px;
    color: #94a3b8;
    font-style: normal;
}

/* ── Map ───────────────────────────────────────────────────── */

.map-wrap {
    flex: 1;
    position: relative;
    min-width: 0;
}

#map {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    z-index: 0;
}

/* ── Right panel ───────────────────────────────────────────── */

.right-panel {
    flex: 0 0 560px;
    background: #fff;
    border-left: 1px solid #e2e8f0;
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
    min-width: 440px;
    max-width: 70vw;
}

#panel-resizer {
    flex: 0 0 8px;
    width: 8px;
    cursor: col-resize;
    background: #cbd5e1;
    z-index: 50;
}

#panel-resizer:hover {
    background: #2563eb;
}

/* ── Tabs ──────────────────────────────────────────────────── */

.tabs {
    flex: 0 0 auto;
    display: flex;
    border-bottom: 2px solid #e2e8f0;
    background: #f8fafc;
}

.tab-btn {
    flex: 1;
    padding: 9px 6px;
    background: none;
    border: none;
    font-size: 12px;
    font-weight: 600;
    color: #64748b;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    transition: color .15s, border-color .15s;
    text-transform: uppercase;
    letter-spacing: .4px;
}

.tab-btn:hover    { color: #1e3a5f; }
.tab-btn.active   { color: #2563eb; border-bottom-color: #2563eb; background: #fff; }

.tab-pane {
    display: none;
    flex: 1;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
}

.tab-pane.active { display: flex; }

.tab-info {
    flex: 0 0 auto;
    padding: 6px 10px;
    font-size: 11px;
    color: #64748b;
    background: #f8fafc;
    border-bottom: 1px solid #e2e8f0;
}

.scroll-wrap {
    flex: 1;
    overflow-y: auto;
    overflow-x: auto;
}

/* ── Data table ────────────────────────────────────────────── */

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 11.5px;
}

.data-table th {
    position: sticky;
    top: 0;
    background: #f1f5f9;
    padding: 6px 8px;
    text-align: left;
    font-size: 10.5px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .3px;
    color: #64748b;
    border-bottom: 1px solid #e2e8f0;
    white-space: nowrap;
    z-index: 1;
}

.data-table td {
    padding: 5px 8px;
    border-bottom: 1px solid #f1f5f9;
    vertical-align: top;
    color: #334155;
    max-width: 140px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.data-table tr:hover td { background: #f8fafc; }

/* ── Map button in table ───────────────────────────────────── */

.btn-map {
    background: #2563eb;
    color: #fff;
    border: none;
    border-radius: 4px;
    padding: 2px 8px;
    font-size: 10.5px;
    cursor: pointer;
    white-space: nowrap;
    transition: background .15s;
}

.btn-map:hover { background: #1d4ed8; }

/* ── Building divIcon markers ──────────────────────────────── */

.building-marker {
    width: 18px;
    height: 18px;
    border-radius: 3px;
    border: 1.5px solid #1e3a5f;
    opacity: 0.82;
    transition: transform .1s, opacity .1s;
    cursor: pointer;
}

.building-marker:hover {
    opacity: 1;
    transform: scale(1.2);
}

.building-marker.bm-ok      { background: #4ade80; }  /* green  — con datos */
.building-marker.bm-nodata  { background: #94a3b8; }  /* gray   — sin datos */
.building-marker.bm-unknown { background: #93c5fd; }  /* blue   — desconocido */
.building-marker.bm-fuera   { background: #ef4444; }  /* red    — fuera proyecto */

/* IoT Demo Controls (sidebar) */
.iot-demo-controls {
    margin: 8px 0 4px;
    display: flex;
    flex-direction: column;
    gap: 5px;
}
.btn-demo-iot {
    padding: 5px 10px;
    font-size: 12px;
    font-weight: 600;
    border: 1.5px solid #86efac;
    background: #f0fdf4;
    color: #15803d;
    border-radius: 5px;
    cursor: pointer;
    text-align: left;
    transition: background 0.15s, color 0.15s;
}
.btn-demo-iot:hover { background: #dcfce7; }
.btn-demo-iot.btn-demo-iot-active { background: #16a34a; color: #fff; border-color: #15803d; }
.iot-chk-label {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 11.5px;
    color: #374151;
    cursor: pointer;
}
.iot-chk-label input[type="checkbox"] { accent-color: #16a34a; }
.iot-demo-summary {
    margin: 4px 0 10px;
    padding: 7px 10px;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 5px;
    font-size: 11px;
    min-height: 18px;
}
.iot-summary-row { display: flex; align-items: baseline; gap: 3px; line-height: 1.65; }
.iot-summary-val { font-weight: 700; color: #15803d; min-width: 28px; text-align: right; font-size: 12px; }
.iot-summary-lbl { color: #64748b; }

/* IoT health badges */
.iot-badge {
    display: inline-block;
    font-size: 10px;
    font-weight: 700;
    padding: 1px 5px;
    border-radius: 3px;
    letter-spacing: 0.02em;
    white-space: nowrap;
    line-height: 1.5;
}
.iot-badge.iot-active        { background: #dcfce7; color: #15803d; border: 1px solid #86efac; }
.iot-badge.iot-nodata        { background: #f1f5f9; color: #64748b; border: 1px solid #cbd5e1; }
.iot-badge.iot-no_data       { background: #f1f5f9; color: #64748b; border: 1px solid #cbd5e1; }
.iot-badge.iot-no_sensors    { background: #f8fafc; color: #94a3b8; border: 1px solid #e2e8f0; }
/* Granular IoT status states */
.iot-badge.iot-active_24h    { background: #dcfce7; color: #15803d; border: 1px solid #86efac; }
.iot-badge.iot-active_7d     { background: #d1fae5; color: #047857; border: 1px solid #6ee7b7; }
.iot-badge.iot-stale_30d     { background: #fef9c3; color: #854d0e; border: 1px solid #fde047; }
.iot-badge.iot-stale_90d     { background: #ffedd5; color: #9a3412; border: 1px solid #fdba74; }
.iot-badge.iot-inactive_90d  { background: #fee2e2; color: #991b1b; border: 1px solid #fca5a5; }
.iot-badge.iot-data_no_timestamp { background: #eff6ff; color: #1d4ed8; border: 1px solid #93c5fd; }
.iot-badge.iot-unknown       { background: #f8fafc; color: #94a3b8; border: 1px solid #e2e8f0; }

tr.row-fuera td { background: #fef2f2; color: #dc2626; }

/* Wrapper para el icono + etiqueta del edificio */
.bm-wrap { overflow: visible !important; background: transparent !important; border: none !important; }

.building-label {
    position: absolute;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 9px;
    font-weight: 700;
    color: #1e293b;
    white-space: nowrap;
    background: rgba(255,255,255,0.82);
    padding: 0 2px;
    border-radius: 2px;
    pointer-events: none;
    line-height: 1.3;
    letter-spacing: 0.02em;
}

/* ── Street tooltip ─────────────────────────────────────────── */

.street-tooltip {
    background: rgba(109,40,217,.85);
    color: #fff;
    border: none;
    border-radius: 4px;
    font-size: 10px;
    padding: 2px 6px;
    white-space: nowrap;
    box-shadow: 0 1px 4px rgba(0,0,0,.25);
}

.street-tooltip::before { display: none; }

/* ── Neighborhood label (divIcon) ───────────────────────────── */

.neighborhood-label {
    font-size: 11px;
    font-weight: 700;
    color: #15803d;
    background: rgba(255,255,255,.82);
    border: 1px solid #86efac;
    border-radius: 4px;
    padding: 1px 5px;
    white-space: nowrap;
    box-shadow: 0 1px 3px rgba(0,0,0,.15);
    pointer-events: auto;
    cursor: pointer;
}

/* ── District label (divIcon) ───────────────────────────────── */

.district-label {
    font-size: 10px;
    font-weight: 800;
    color: #1e40af;
    background: rgba(219,234,254,.75);
    border: 1px dashed #93c5fd;
    border-radius: 4px;
    padding: 2px 6px;
    white-space: nowrap;
    letter-spacing: .3px;
    text-transform: uppercase;
    box-shadow: 0 1px 3px rgba(0,0,0,.1);
    pointer-events: auto;
    cursor: pointer;
}

/* ── Sensor system dot in table ─────────────────────────────── */

.sys-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-right: 4px;
    vertical-align: middle;
    flex-shrink: 0;
}

/* ── Popup system dot ───────────────────────────────────────── */

.popup-sys-dot {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    margin-right: 6px;
    vertical-align: middle;
    flex-shrink: 0;
}

/* ── Badges ────────────────────────────────────────────────── */

.badge {
    display: inline-block;
    padding: 1px 6px;
    border-radius: 10px;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: .3px;
    text-transform: uppercase;
    white-space: nowrap;
}

.badge-building { background: #dbeafe; color: #1d4ed8; }
.badge-sensor   { background: #ffedd5; color: #c2410c; }
.badge-other    { background: #dcfce7; color: #15803d; }
.badge-error    { background: #fee2e2; color: #991b1b; }
.badge-warn     { background: #fef9c3; color: #854d0e; }
.badge-info     { background: #dbeafe; color: #1e40af; }
.badge-legacy   { background: #e2e8f0; color: #64748b; border: 1px solid #cbd5e1; font-size: 9px; padding: 1px 4px; }

tr.row-legacy td { opacity: 0.45; }

/* ── QA panel ──────────────────────────────────────────────── */


/* ── GeoJSON boundary tooltip ──────────────────────────────── */

.boundary-label {
    background: rgba(255,255,255,.88);
    border: none;
    border-radius: 4px;
    font-size: 11.5px;
    font-weight: 700;
    color: #1e293b;
    padding: 2px 7px;
    box-shadow: 0 1px 4px rgba(0,0,0,.15);
    white-space: nowrap;
    pointer-events: none;
}

.boundary-label::before { display: none; }

/* ── Popup styles ──────────────────────────────────────────── */

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

.popup-title {
    font-weight: 700;
    font-size: 13px;
    color: #1e3a5f;
    margin-bottom: 8px;
    padding-bottom: 6px;
    border-bottom: 1px solid #e2e8f0;
}

.popup-table {
    border-collapse: collapse;
    width: 100%;
}

.popup-table th {
    text-align: left;
    font-size: 10.5px;
    font-weight: 600;
    color: #64748b;
    padding: 2px 8px 2px 0;
    text-transform: uppercase;
    letter-spacing: .3px;
    white-space: nowrap;
}

.popup-table td {
    font-size: 11.5px;
    color: #1e293b;
    padding: 2px 0;
    word-break: break-all;
}

/* ============================================================
   EDIT / DETAIL PANEL
   ============================================================ */

.detail-panel {
    position: fixed;
    top: 0;
    right: -420px;
    width: 380px;
    height: 100vh;
    background: #fff;
    border-left: 1px solid #cbd5e1;
    box-shadow: -4px 0 20px rgba(0,0,0,.18);
    display: flex;
    flex-direction: column;
    z-index: 9000;
    transition: right .25s ease;
}

.detail-panel.open {
    right: 0;
}

.dp-header {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: #1e3a5f;
    color: #fff;
    font-weight: 700;
    font-size: 13px;
}

.dp-close {
    background: none;
    border: none;
    color: #fff;
    font-size: 18px;
    cursor: pointer;
    line-height: 1;
    padding: 2px 6px;
    border-radius: 4px;
    opacity: .8;
}

.dp-close:hover { opacity: 1; background: rgba(255,255,255,.15); }

.dp-body {
    flex: 1;
    overflow-y: auto;
    padding: 12px 16px;
}

.dp-footer {
    flex: 0 0 auto;
    border-top: 1px solid #e2e8f0;
    padding: 10px 16px;
}

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

/* ── Form rows ───────────────────────────────────────────────── */

#dp-form {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

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

.dp-row-tall {
    align-items: flex-start;
}

.dp-label {
    flex: 0 0 110px;
    font-size: 11px;
    font-weight: 600;
    color: #475569;
    text-transform: uppercase;
    letter-spacing: .3px;
}

.dp-input {
    flex: 1;
    padding: 5px 8px;
    border: 1px solid #cbd5e1;
    border-radius: 5px;
    font-size: 12px;
    background: #f8fafc;
    color: #1e293b;
    outline: none;
    min-width: 0;
}

.dp-input:focus {
    border-color: #2563eb;
    background: #fff;
}

.dp-textarea {
    flex: 1;
    padding: 5px 8px;
    border: 1px solid #cbd5e1;
    border-radius: 5px;
    font-size: 12px;
    background: #f8fafc;
    color: #1e293b;
    outline: none;
    resize: vertical;
    min-width: 0;
    font-family: inherit;
}

.dp-textarea:focus {
    border-color: #2563eb;
    background: #fff;
}

.dp-readonly {
    flex: 1;
    font-size: 12px;
    color: #64748b;
    font-family: monospace;
}

.dp-bulk-note {
    font-size: 11px;
    color: #64748b;
    font-style: italic;
    padding: 4px 0 4px;
    border-bottom: 1px solid #e2e8f0;
    margin-bottom: 4px;
}

/* ── Buttons ─────────────────────────────────────────────────── */

.btn-pri {
    padding: 6px 14px;
    background: #1e3a5f;
    color: #fff;
    border: none;
    border-radius: 5px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
}

.btn-pri:hover { background: #1e40af; }

.btn-sec {
    padding: 6px 14px;
    background: #f1f5f9;
    color: #475569;
    border: 1px solid #cbd5e1;
    border-radius: 5px;
    font-size: 12px;
    cursor: pointer;
    white-space: nowrap;
}

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

/* Bulk edit button in toolbar */
.btn-bulk {
    padding: 3px 10px;
    background: #0ea5e9;
    color: #fff;
    border: none;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
}

.btn-bulk:hover { background: #0284c7; }

/* ── Copy-from-building preview ──────────────────────────────── */

.dp-copy-preview {
    background: #f0fdf4;
    border: 1px solid #86efac;
    border-radius: 6px;
    padding: 10px 12px;
    margin-bottom: 10px;
    font-size: 12px;
}

.dp-preview-title {
    font-weight: 700;
    color: #15803d;
    margin-bottom: 8px;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: .4px;
}

.dp-preview-row {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 4px;
    flex-wrap: wrap;
}

.dp-preview-label {
    font-weight: 600;
    color: #374151;
    flex: 0 0 80px;
    font-size: 11px;
}

.dp-preview-old {
    color: #94a3b8;
    text-decoration: line-through;
    font-size: 11px;
}

.dp-preview-arrow { color: #475569; }

.dp-preview-new {
    color: #15803d;
    font-weight: 600;
    font-size: 11px;
}

.dp-preview-btns {
    display: flex;
    gap: 6px;
    margin-top: 8px;
}

/* ── Multi-row selection ─────────────────────────────────────── */

tr.row-multi-selected td {
    background: #dbeafe !important;
}

/* ── Toast ───────────────────────────────────────────────────── */

.toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    padding: 10px 20px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    z-index: 9999;
    box-shadow: 0 4px 16px rgba(0,0,0,.2);
    pointer-events: none;
    white-space: nowrap;
}

.toast-ok  { background: #15803d; color: #fff; }
.toast-err { background: #991b1b; color: #fff; }

.popup-mono {
    font-family: 'Courier New', monospace;
    font-size: 10px;
    color: #475569;
}

/* ── Scrollbar styling ─────────────────────────────────────── */

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #94a3b8; }

/* ── Panel resizer handle ───────────────────────────────────── */

#panel-resizer {
    flex: 0 0 5px;
    background: #e2e8f0;
    cursor: col-resize;
    transition: background .15s;
    z-index: 10;
}
#panel-resizer:hover,
#panel-resizer:active { background: #94a3b8; }

/* ── Tab toolbar (info + visible toggle) ────────────────────── */

.tab-toolbar {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 5px 10px;
    background: #f8fafc;
    border-bottom: 1px solid #e2e8f0;
    gap: 8px;
}

.tab-info-text {
    font-size: 11px;
    color: #64748b;
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.lbl-only-visible {
    font-size: 11px;
    color: #475569;
    display: flex;
    align-items: center;
    gap: 4px;
    cursor: pointer;
    white-space: nowrap;
    flex-shrink: 0;
}
.lbl-only-visible input { cursor: pointer; margin: 0; }

/* ── Sortable column headers ────────────────────────────────── */

.data-table th[data-sort] {
    cursor: pointer;
    user-select: none;
}
.data-table th[data-sort]:hover { background: #e2e8f0; }
.data-table th.sort-active      { background: #dbeafe; color: #1d4ed8; }

.sort-icon {
    font-size: 9px;
    margin-left: 2px;
    color: #2563eb;
    vertical-align: middle;
}

/* ── Row selection ──────────────────────────────────────────── */

.data-table tbody tr         { cursor: pointer; }
.data-table tbody tr.row-selected td {
    background: #eff6ff !important;
    border-bottom-color: #bfdbfe;
}

/* ── Selection bar ──────────────────────────────────────────── */

.selection-bar {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 5px 12px;
    background: #eff6ff;
    border-bottom: 1px solid #bfdbfe;
    min-height: 38px;
    font-size: 12px;
}

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

.selection-id {
    font-weight: 700;
    color: #1e40af;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.selection-name {
    color: #475569;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.selection-count {
    font-weight: 700;
    color: #1e40af;
}

.selection-actions {
    display: flex;
    gap: 4px;
    flex-shrink: 0;
}

.sel-btn {
    padding: 3px 8px;
    font-size: 11px;
    border: 1px solid #93c5fd;
    background: #fff;
    color: #1e40af;
    border-radius: 4px;
    cursor: pointer;
    white-space: nowrap;
    line-height: 1.4;
}

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

.sel-btn-clear {
    border-color: #e2e8f0;
    color: #64748b;
}

.sel-btn-clear:hover {
    background: #f1f5f9;
    color: #1e293b;
}

/* ── Column resizer handle ──────────────────────────────────── */

.col-resizer {
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    width: 5px;
    cursor: col-resize;
    z-index: 2;
}
.col-resizer:hover { background: #93c5fd; }

/* ── Selected building / sensor card ────────────────────────── */

.selection-card {
    flex: 0 0 auto;
    margin: 5px 8px 0;
    padding: 9px 12px;
    border: 1px solid #d7dee8;
    border-radius: 10px;
    background: #ffffff;
    box-shadow: 0 2px 6px rgba(15, 23, 42, 0.06);
}

.selection-card.hidden {
    display: none;
}

.selection-card-main {
    display: grid;
    grid-template-columns: 44px 1fr auto;
    gap: 9px;
    align-items: center;
}

.selection-card-icon {
    width: 44px;
    height: 44px;
    border-radius: 9px;
    overflow: hidden;
    background: #eef2f7;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.selection-card-icon img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.card-icon-emoji { font-size: 22px; }

.sys-icon-circle {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 9px;
    font-weight: 700;
    color: #fff;
    letter-spacing: -.02em;
}

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

.selection-card-kicker {
    font-size: 9px;
    color: #94a3b8;
    text-transform: uppercase;
    letter-spacing: .05em;
    line-height: 1.2;
}

.selection-card-title {
    font-size: 13px;
    font-weight: 700;
    color: #0f172a;
    line-height: 1.3;
}

.selection-card-meta {
    font-size: 11px;
    color: #64748b;
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0;
    line-height: 1.4;
}

.meta-sep {
    color: #cbd5e1;
    margin: 0 4px;
    flex-shrink: 0;
}

.selection-card-systems {
    display: flex;
    align-items: center;
    gap: 3px;
    overflow: hidden;
    line-height: 1;
}

.sys-badge {
    display: inline-flex;
    align-items: center;
    padding: 1px 4px;
    border-radius: 3px;
    font-size: 9px;
    font-weight: 700;
    color: #fff;
    white-space: nowrap;
    flex-shrink: 0;
}

.sys-count {
    font-size: 10px;
    color: #94a3b8;
    white-space: nowrap;
}

.sc-fields {
    display: flex;
    flex-wrap: wrap;
    gap: 2px 8px;
    margin-top: 4px;
}
.sc-field {
    font-size: 10px;
    color: #475569;
    white-space: nowrap;
}
.sc-label {
    font-weight: 600;
    color: #94a3b8;
}
.sc-shortname {
    font-size: 0.8em;
    color: #64748b;
    font-weight: 400;
}

.selection-card-actions {
    display: flex;
    flex-direction: column;
    gap: 3px;
    align-items: center;
    flex-shrink: 0;
}

.card-btn {
    width: 26px;
    height: 22px;
    padding: 0;
    font-size: 13px;
    border: 1px solid #e2e8f0;
    background: #f8fafc;
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

.card-btn:hover { background: #dbeafe; border-color: #93c5fd; }

.card-btn-clear { color: #94a3b8; }
.card-btn-clear:hover { background: #f1f5f9; border-color: #e2e8f0; color: #1e293b; }

/* ── Responsive ────────────────────────────────────────────── */

@media (max-width: 900px) {
    .main-layout { flex-wrap: wrap; overflow-y: auto; height: auto; }
    .sidebar     { flex: 0 0 100%; border-right: none; border-bottom: 1px solid #e2e8f0; }
    .map-wrap    { flex: 0 0 100%; height: 400px; position: relative; }
    #map         { position: absolute; inset: 0; }
    .right-panel { flex: 0 0 100%; height: 400px; border-left: none; border-top: 1px solid #e2e8f0; }
    #app         { overflow-y: auto; height: auto; }
}

/* ============================================================
   CENTRO DE SINCRONIZACIÓN IoT
   ============================================================ */

.sync-toolbar {
    flex-wrap: wrap;
    gap: 6px;
}

.sync-filters {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
    padding: 5px 10px;
    background: #f8fafc;
    border-bottom: 1px solid #e2e8f0;
    font-size: 12px;
    color: #475569;
}
.sync-filters label { display: flex; align-items: center; gap: 4px; cursor: pointer; }

/* Badges de estado */
.sync-badge {
    display: inline-block;
    padding: 2px 7px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 600;
    background: #f1f5f9;
    color: #64748b;
    border: 1px solid #cbd5e1;
}
.sync-badge-active  { background: #dcfce7; color: #15803d; border-color: #86efac; }
.sync-badge-partial { background: #fef9c3; color: #854d0e; border-color: #fde047; }
.sync-badge-nodata  { background: #f1f5f9; color: #64748b; border-color: #cbd5e1; }
.sync-badge-error   { background: #fee2e2; color: #991b1b; border-color: #fca5a5; }

/* Checkbox column */
.sync-chk-col { width: 28px; text-align: center; }

/* Fila TODOS */
.sync-row-all td { background: #f0f9ff; font-weight: 600; }
.sync-row-all:hover td { background: #e0f2fe; }

/* Botón de acción por sistema */
.btn-sync-system {
    padding: 3px 10px;
    font-size: 11px;
    background: #eff6ff;
    color: #1d4ed8;
    border: 1px solid #bfdbfe;
    border-radius: 4px;
    cursor: pointer;
    white-space: nowrap;
}
.btn-sync-system:hover { background: #dbeafe; }

/* Área de progreso */
.sync-progress-area {
    flex: 0 0 auto;
    padding: 8px 10px;
    background: #f8fafc;
    border-bottom: 1px solid #e2e8f0;
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.sync-prog-row {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
}
.sync-prog-label { width: 100px; flex-shrink: 0; color: #475569; font-weight: 600; }
.sync-prog-bar-wrap {
    flex: 1;
    height: 10px;
    background: #e2e8f0;
    border-radius: 5px;
    overflow: hidden;
}
.sync-prog-bar {
    height: 100%;
    width: 0%;
    background: #3b82f6;
    border-radius: 5px;
    transition: width .3s ease;
}
.sync-prog-status { width: 100px; flex-shrink: 0; color: #64748b; font-size: 11px; }

/* Sección global al pie */
.sync-global-action {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    background: #fafafa;
    border-top: 1px solid #e2e8f0;
    font-size: 12px;
}
.sync-global-note { color: #94a3b8; }

/* OK/ERR inline en última sync */
.sync-ok  { color: #15803d; font-weight: 600; }
.sync-err { color: #b91c1c; font-weight: 600; }

.sync-last-sync { font-size: 11px; color: #64748b; }
.sync-loading   { text-align: center; color: #94a3b8; padding: 20px; }

/* Botón "Subir" por sistema */
.btn-push-system {
    padding: 3px 10px;
    font-size: 11px;
    background: #fff7ed;
    color: #c2410c;
    border: 1px solid #fed7aa;
    border-radius: 4px;
    cursor: pointer;
    white-space: nowrap;
}
.btn-push-system:hover { background: #ffedd5; }

/* Tablas de sincronización: ancho mínimo para que el scroll horizontal
   se active antes de que las columnas empiecen a recortarse. */
#sync-table  { min-width: 860px; }
#bsync-table { min-width: 760px; }

/* Columna "Acciones" fija a la derecha: queda visible mientras el resto
   de columnas hace scroll horizontal bajo ella. */
#sync-table  th:last-child,
#bsync-table th:last-child {
    position: sticky;
    right: 0;
    z-index: 3;
    background: #f1f5f9;
    border-left: 1px solid #e2e8f0;
}
#sync-table  td:last-child,
#bsync-table td:last-child {
    position: sticky;
    right: 0;
    z-index: 1;
    background: #ffffff;
    border-left: 1px solid #f1f5f9;
}
#sync-table  tr:hover td:last-child,
#bsync-table tr:hover td:last-child { background: #f8fafc; }
#sync-table  tr.sync-row-all td:last-child,
#bsync-table tr.sync-row-all td:last-child { background: #f8fafc; }

/* Celda de acciones con 2 botones: anula el max-width/ellipsis de
   .data-table td y permite que los botones no se corten. */
#sync-table td.sync-actions-cell,
#bsync-table td.sync-actions-cell {
    max-width: none;
    overflow: visible;
    text-overflow: unset;
    white-space: normal;
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    min-width: 160px;
}

/* Tooltip de campos pendientes de subir */
#pending-tooltip {
    position: fixed;
    z-index: 9999;
    display: none;
    background: #1e293b;
    color: #f1f5f9;
    border-radius: 6px;
    padding: 8px 12px;
    font-size: 11px;
    line-height: 1.6;
    max-width: 300px;
    pointer-events: none;
    box-shadow: 0 4px 16px rgba(0,0,0,.35);
}
#pending-tooltip .pt-title {
    font-weight: 700;
    color: #fbbf24;
    margin-bottom: 2px;
}
#pending-tooltip .pt-title + .pt-title { margin-top: 6px; }
#pending-tooltip .pt-row { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#pending-tooltip .pt-id  { color: #94a3b8; margin-right: 4px; }
#pending-tooltip .pt-fields { color: #e2e8f0; }
#pending-tooltip .pt-more { color: #64748b; font-style: italic; }

/* Cabeceras ordenables en tablas de sincronización */
.th-sort {
    cursor: pointer;
    user-select: none;
    white-space: nowrap;
}
.th-sort:hover { background: #e2e8f0; }
.th-sort::after { content: ' ⇕'; opacity: 0.3; font-size: 0.75em; }
.th-sort.asc::after  { content: ' ▲'; opacity: 1; }
.th-sort.desc::after { content: ' ▼'; opacity: 1; }

/* Subpestañas dentro de "Sincronización" (Sistemas / Edificios) */
.sync-subtabs {
    flex: 0 0 auto;
    display: flex;
    gap: 4px;
    padding: 6px 10px 0;
    background: #f8fafc;
    border-bottom: 1px solid #e2e8f0;
}
.sync-subtab-btn {
    padding: 6px 14px;
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    font-size: 11.5px;
    font-weight: 600;
    color: #64748b;
    cursor: pointer;
    transition: color .15s, border-color .15s;
}
.sync-subtab-btn:hover  { color: #1e3a5f; }
.sync-subtab-btn.active { color: #2563eb; border-bottom-color: #2563eb; }

.sync-subtab-pane { display: none; flex: 1; flex-direction: column; min-height: 0; overflow: hidden; }
.sync-subtab-pane.active { display: flex; }

/* Badge "Pend. subir" */
.sync-pending-badge {
    display: inline-block;
    min-width: 18px;
    padding: 2px 6px;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 700;
    background: #ffedd5;
    color: #c2410c;
    border: 1px solid #fed7aa;
}

/* ── Modal de previsualización (Sincronizar / Subir) ─────────── */

.sync-preview-box {
    width: 720px;
    max-width: 94vw;
    max-height: 86vh;
}

.sync-preview-body {
    overflow-y: auto;
    padding: 10px 16px;
    max-height: 60vh;
}

.sync-preview-loading, .sync-preview-error {
    padding: 24px;
    text-align: center;
    color: #64748b;
}
.sync-preview-error { color: #b91c1c; }

.sync-preview-system-block + .sync-preview-system-block {
    margin-top: 14px;
    padding-top: 14px;
    border-top: 1px dashed #e2e8f0;
}
.sync-preview-system {
    font-size: 13px;
    color: #1e293b;
    margin-bottom: 6px;
}

.sp-block { margin-bottom: 8px; }
.sp-block-title {
    font-size: 11.5px;
    font-weight: 700;
    color: #475569;
    margin-bottom: 3px;
}
.sp-block-items {
    font-size: 12px;
    color: #334155;
    padding-left: 4px;
}
.sp-item { padding: 3px 0; line-height: 1.5; }
.sp-dim  { color: #94a3b8; }

.sp-item-id {
    font-weight: 600;
    color: #1e293b;
}
.sp-field-row {
    padding: 1px 0 1px 12px;
    font-size: 11.5px;
}
.sp-field-key {
    color: #475569;
    font-family: 'Consolas', 'Courier New', monospace;
}
.sp-field-old { color: #b91c1c; text-decoration: line-through; }
.sp-field-new { color: #15803d; font-weight: 600; }

.sp-block-crear        .sp-block-title { color: #15803d; }
.sp-block-completar    .sp-block-title { color: #1d4ed8; }
.sp-block-conflicto    .sp-block-title { color: #c2410c; }
.sp-block-missing      .sp-block-title { color: #b91c1c; }
.sp-block-sin-cambios  .sp-block-title { color: #64748b; }
.sp-block-sobrescribir .sp-block-title { color: #c2410c; }

.sp-conflict {
    background: #fff7ed;
    border: 1px solid #fed7aa;
    border-radius: 6px;
    padding: 6px 8px;
    margin-bottom: 4px;
}
.sp-radio-group {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 4px;
}
.sp-radio {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 11.5px;
    cursor: pointer;
}

.sync-preview-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}
.sync-preview-actions { display: flex; gap: 8px; flex-shrink: 0; }
