:root {
    --forest: #12312b;
    --leaf: #2f7d5f;
    --lime: #d9f99d;
    --paper: #f7f7f2;
    --ink: #18211f;
    --muted: #64706c;
    --line: rgba(18, 49, 43, .14);
}

html, body {
    width: 100%;
    height: 100%;
    margin: 0;
    font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    color: var(--ink);
    background: var(--paper);
}

.login-view {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 1rem;
    background: linear-gradient(135deg, #12312b 0%, #2f7d5f 58%, #eef6e6 100%);
}

.login-panel {
    width: min(420px, 100%);
    padding: 2rem;
    border-radius: 8px;
    background: rgba(255, 255, 255, .94);
}

.login-panel h1 {
    margin: .7rem 0 1.4rem;
    font-size: 2rem;
    font-weight: 800;
}

.brand-mark {
    display: inline-grid;
    place-items: center;
    width: 54px;
    height: 54px;
    border-radius: 8px;
    background: var(--forest);
    color: #fff;
    font-weight: 800;
}

.app-shell, #map {
    position: fixed;
    inset: 0;
}

.topbar {
    position: absolute;
    z-index: 600;
    top: .75rem;
    left: .75rem;
    right: .75rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .75rem;
    padding: .5rem;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: rgba(255, 255, 255, .92);
    backdrop-filter: blur(10px);
}

.route-title {
    display: flex;
    align-items: center;
    gap: .5rem;
    min-width: 0;
}

.brand-dot {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--leaf);
    box-shadow: inset 0 0 0 4px var(--lime);
}

.top-actions {
    display: flex;
    align-items: center;
    gap: .35rem;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.btn svg {
    width: 16px;
    height: 16px;
    margin-right: .25rem;
    vertical-align: -2px;
}

.btn-sm svg {
    margin-right: 0;
}

#newSignalBtn svg,
.panel-actions .btn svg,
.photo-head .btn svg {
    margin-right: .25rem;
}

#locateBtn.location-active {
    box-shadow: 0 0 0 .2rem rgba(13, 110, 253, .22);
}

.signal-panel {
    position: absolute;
    z-index: 650;
    top: 5rem;
    right: .75rem;
    bottom: .75rem;
    width: min(430px, calc(100vw - 1.5rem));
    display: flex;
    flex-direction: column;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: rgba(255, 255, 255, .96);
    transform: translateX(calc(100% + 1rem));
    transition: transform .2s ease;
    overflow: hidden;
}

.signal-panel.open {
    transform: translateX(0);
}

.panel-tab {
    position: absolute;
    z-index: 640;
    top: 50%;
    right: 0;
    display: grid;
    place-items: center;
    width: 42px;
    height: 52px;
    border: 1px solid var(--line);
    border-right: 0;
    border-radius: 8px 0 0 8px;
    background: rgba(255, 255, 255, .96);
    color: var(--forest);
    box-shadow: 0 4px 14px rgba(0, 0, 0, .16);
}

.panel-tab svg {
    width: 19px;
    height: 19px;
}

.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1rem;
    padding: 1rem;
    border-bottom: 1px solid var(--line);
}

.panel-header h2 {
    margin: 0;
    font-size: 1.35rem;
    font-weight: 800;
}

.eyebrow {
    display: block;
    margin-bottom: .2rem;
    color: var(--muted);
    font-size: .78rem;
    text-transform: uppercase;
    letter-spacing: .08em;
}

.panel-body {
    overflow: auto;
    padding: 1rem;
}

.status-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: .55rem;
    margin-bottom: 1rem;
}

.status-option {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 46px;
    gap: .35rem;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    font-weight: 700;
    cursor: pointer;
}

.status-option svg {
    width: 18px;
    height: 18px;
}

.btn-check:checked + .status-option {
    color: #fff;
    border-color: transparent;
}

.btn-check:checked + .maintained { background: #198754; }
.btn-check:checked + .removed { background: #dc3545; }
.btn-check:checked + .new { background: #0d6efd; }
.btn-check:checked + .none { background: #495057; }

.readonly-status {
    display: flex;
    align-items: center;
    gap: .45rem;
    margin: .75rem 0;
    padding: .65rem .75rem;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #f8faf9;
    color: var(--muted);
    font-size: .86rem;
    font-weight: 700;
}

.readonly-status strong {
    margin-left: auto;
    color: var(--ink);
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: .75rem;
}

.form-grid label {
    color: var(--muted);
    font-size: .82rem;
    font-weight: 700;
}

.form-grid .wide {
    grid-column: 1 / -1;
}

.legacy-photos,
.new-photos {
    margin-top: 1.1rem;
}

.legacy-photos h3,
.new-photos h3 {
    margin: 0 0 .65rem;
    font-size: 1rem;
    font-weight: 800;
}

.photo-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: .75rem;
}

.photo-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: .5rem;
}

.photo-card {
    position: relative;
    display: grid;
    place-items: center;
    overflow: hidden;
    aspect-ratio: 1;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #eef1ed;
}

.photo-card img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    cursor: zoom-in;
}

.photo-card button {
    position: absolute;
    top: .25rem;
    right: .25rem;
}

.photo-card.missing {
    padding: .5rem;
    color: var(--muted);
    font-size: .82rem;
    font-weight: 700;
    text-align: center;
}

.photo-caption {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    padding: .2rem .35rem;
    overflow: hidden;
    color: #fff;
    background: rgba(18, 33, 31, .72);
    font-size: .68rem;
    font-weight: 700;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.photo-empty {
    grid-column: 1 / -1;
    padding: .75rem;
    border: 1px dashed var(--line);
    border-radius: 8px;
    color: var(--muted);
    font-size: .86rem;
    font-weight: 700;
    text-align: center;
}

.panel-actions {
    position: sticky;
    bottom: -1rem;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: .6rem;
    margin: 1rem -1rem -1rem;
    padding: .85rem 1rem;
    background: rgba(255, 255, 255, .96);
    border-top: 1px solid var(--line);
}

.signal-marker {
    display: grid;
    place-items: center;
    width: 30px;
    height: 30px;
    border: 2px solid #fff;
    border-radius: 50%;
    color: #fff;
    font-size: 12px;
    font-weight: 800;
    box-shadow: 0 2px 8px rgba(0, 0, 0, .3);
}

.signal-marker.tip-placa {
    border-radius: 50%;
}

.signal-symbol {
    display: block;
    line-height: 1;
}

.signal-marker.tip-poste {
    border-radius: 5px;
    transform: rotate(45deg);
}

.signal-marker.tip-poste .signal-symbol {
    transform: rotate(-45deg);
}

.signal-marker.tip-otro {
    border-radius: 9px 9px 9px 2px;
}

.signal-marker.mantenida { background: #198754; }
.signal-marker.eliminada { background: #dc3545; }
.signal-marker.nueva { background: #0d6efd; }
.signal-marker.sin_actuar { background: #495057; }

.map-legend {
    display: grid;
    gap: .3rem;
    padding: .65rem .75rem;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: rgba(255, 255, 255, .94);
    color: var(--ink);
    font-size: .78rem;
    line-height: 1.2;
    box-shadow: 0 4px 14px rgba(0, 0, 0, .14);
}

.map-legend strong {
    margin-bottom: .15rem;
    font-size: .8rem;
}

.map-legend span {
    display: flex;
    align-items: center;
    gap: .4rem;
    white-space: nowrap;
}

.legend-color,
.legend-shape {
    display: inline-block;
    width: 13px;
    height: 13px;
    border: 2px solid #fff;
    box-shadow: 0 0 0 1px rgba(0, 0, 0, .2);
}

.legend-shape.placa {
    border-radius: 50%;
    background: #495057;
}

.legend-shape.poste {
    border-radius: 3px;
    background: #495057;
    transform: rotate(45deg);
}

.legend-color.mantenida { background: #198754; }
.legend-color.eliminada { background: #dc3545; }
.legend-color.nueva { background: #0d6efd; }
.legend-color.sin_actuar { background: #495057; }

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

.signal-popup .leaflet-popup-content {
    width: min(360px, 78vw) !important;
    margin: .75rem;
}

.field-popup {
    display: grid;
    gap: .75rem;
    color: var(--ink);
}

.field-popup h3 {
    margin: 0;
    font-size: 1.05rem;
    font-weight: 800;
}

.field-popup .popup-subtitle {
    color: var(--muted);
    font-size: .78rem;
    font-weight: 700;
}

.disposition-list {
    display: grid;
    gap: .45rem;
    max-height: 190px;
    overflow: auto;
}

.sign-card {
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: .55rem;
    background: #f8faf7;
}

.sign-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .5rem;
    margin-bottom: .35rem;
    font-size: .78rem;
    font-weight: 800;
    color: var(--muted);
}

.sign-badges,
.route-lines {
    display: flex;
    flex-wrap: wrap;
    gap: .28rem;
}

.dir-badge,
.route-badge,
.special-badge {
    display: inline-flex;
    align-items: center;
    min-height: 26px;
    border-radius: 8px;
    padding: .18rem .42rem;
    font-size: .76rem;
    font-weight: 800;
}

.dir-badge {
    background: #e8f3ee;
    color: #17523e;
}

.route-badge {
    background: #eaf1ff;
    color: #17438a;
}

.special-badge.warn {
    background: #fff3cd;
    color: #7a4d00;
}

.special-badge.stop {
    background: #fde2e1;
    color: #9b1c1c;
}

.popup-status-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: .35rem;
}

.popup-status-grid input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.popup-status-grid label {
    display: grid;
    place-items: center;
    gap: .16rem;
    min-height: 52px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    font-size: .68rem;
    font-weight: 800;
    text-align: center;
    cursor: pointer;
}

.popup-status-grid svg {
    width: 19px;
    height: 19px;
}

.popup-status-grid input:checked + label {
    color: #fff;
    border-color: transparent;
}

.popup-status-grid input:checked + .popup-maintained { background: #198754; }
.popup-status-grid input:checked + .popup-removed { background: #dc3545; }
.popup-status-grid input:checked + .popup-new { background: #0d6efd; }
.popup-status-grid input:checked + .popup-none { background: #495057; }

.popup-photo-head,
.popup-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .5rem;
}

.popup-photo-grid {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: .35rem;
}

.popup-photo {
    position: relative;
    display: grid;
    place-items: center;
    aspect-ratio: 1;
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #eef1ed;
    color: var(--muted);
    font-size: .7rem;
    font-weight: 800;
}

.popup-photo img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.popup-photo button {
    position: absolute;
    top: .15rem;
    right: .15rem;
    display: grid;
    place-items: center;
    width: 22px;
    height: 22px;
    border: 0;
    border-radius: 50%;
    color: #fff;
    background: rgba(220, 53, 69, .95);
    font-weight: 900;
}

.popup-actions {
    justify-content: flex-end;
    flex-wrap: wrap;
}

.user-form {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: .6rem;
    align-items: center;
}

@media (max-width: 760px) {
    .topbar {
        align-items: flex-start;
        flex-direction: column;
    }

    .top-actions {
        width: 100%;
        justify-content: flex-start;
    }

    .signal-panel {
        top: auto;
        left: .5rem;
        right: .5rem;
        bottom: .5rem;
        width: auto;
        max-height: 72vh;
    }

    .form-grid,
    .status-grid {
        grid-template-columns: 1fr;
    }

    .photo-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .user-form {
        grid-template-columns: 1fr;
    }
}
