* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    color: #1A1A1A;
    background: #EEF2F7;
}

#map-wrap {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    right: 0;
}

#map, #mapB {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    right: 0;
}

/* mapB only participates in layout when comparison mode is active */
#mapB { display: none; }
body.comparing #mapB { display: block; }

.compare-toggle {
    display: flex !important;
    align-items: center;
    gap: 6px;
    margin-top: 10px;
    font-size: 12.5px;
    font-weight: 600;
    color: #13315C;
    text-transform: none !important;
    letter-spacing: 0 !important;
    cursor: pointer;
}

#compare-b {
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px dashed #d2d8e0;
}

.side-tag {
    font-weight: 400;
    color: #5B6B7B;
    font-size: 10px;
}

#panel {
    position: absolute;
    top: 16px;
    left: 16px;
    width: 320px;
    max-height: calc(100vh - 32px);
    overflow-y: auto;
    background: rgba(255, 255, 255, 0.96);
    border-radius: 12px;
    box-shadow: 0 6px 24px rgba(11, 37, 69, 0.18);
    padding: 16px 18px;
    z-index: 1;
}

#panel header h1 {
    margin: 0 0 2px 0;
    font-size: 16px;
    color: #0B2545;
    font-weight: 700;
}

#panel .subtitle {
    margin: 0 0 14px 0;
    font-size: 12px;
    color: #5B6B7B;
    font-style: italic;
}

#panel section { margin-bottom: 16px; }

#panel section.epochs label {
    display: block;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: #13315C;
    margin-bottom: 6px;
}

.epoch-buttons {
    display: flex;
    gap: 4px;
    margin-bottom: 8px;
}

.epoch-btn {
    flex: 1 1 auto;
    padding: 7px 4px;
    font-size: 12px;
    font-weight: 600;
    color: #13315C;
    background: #eef1f5;
    border: 1px solid #d2d8e0;
    border-radius: 6px;
    cursor: pointer;
    transition: background .12s, color .12s;
    white-space: nowrap;
}

.epoch-btn:hover { background: #e2e7ee; }

.epoch-btn.active {
    background: #C75146;
    border-color: #C75146;
    color: #fff;
}

.epoch-btn.active:hover { background: #b5453b; }

.hint {
    margin: 6px 0 0 0;
    font-size: 11px;
    color: #5B6B7B;
}

.counter-line {
    margin: 4px 0 0 0;
    font-size: 11.5px;
    color: #5B6B7B;
}

.counter-line strong {
    color: #0B2545;
    font-variant-numeric: tabular-nums;
}

#panel h2 {
    margin: 0 0 8px 0;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: #13315C;
}

.layers label {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 0;
    font-size: 13px;
    cursor: pointer;
}

.layers .swatch {
    display: inline-block;
    width: 14px;
    height: 14px;
    border-radius: 3px;
    border: 1px solid rgba(0, 0, 0, 0.15);
}

.swatch.batiment      { background: #C75146; }
.swatch.rempart       { background: #2b2b2b; }
.swatch.rue           { background: #8a6a3a; }
.swatch.parcelle      { background: #d8c89a; }
.swatch.lieu_memoire  { background: #0B2545; border-radius: 50%; }

.meta {
    margin: 0;
    font-size: 11px;
    color: #5B6B7B;
    line-height: 1.4;
}

.overlays h2 {
    margin-top: 4px;
}

.overlays .hint {
    margin: 0 0 6px 0;
    font-size: 11.5px;
    color: #5B6B7B;
}

.overlays .hint a {
    color: #13315C;
}

.overlays input[type="text"] {
    width: 100%;
    padding: 5px 7px;
    font-size: 11px;
    font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
    border: 1px solid #d2d8e0;
    border-radius: 5px;
    margin-bottom: 6px;
}

.overlays select {
    width: 100%;
    padding: 5px 7px;
    font-size: 12px;
    border: 1px solid #d2d8e0;
    border-radius: 5px;
    margin-bottom: 6px;
    background: white;
}

.overlays .preset-note {
    margin: 0 0 6px 0;
    padding: 6px 8px;
    font-size: 11px;
    color: #5B6B7B;
    background: #F4E9CD;
    border-radius: 4px;
    line-height: 1.4;
    min-height: 0;
}

.overlays .preset-note:empty {
    display: none;
}

.overlays .row {
    display: flex;
    gap: 6px;
    margin-bottom: 8px;
}

.overlays button {
    appearance: none;
    border: 0;
    background: #0B2545;
    color: white;
    padding: 5px 10px;
    border-radius: 5px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
}

.overlays button.secondary {
    background: transparent;
    color: #5B6B7B;
    border: 1px solid #d2d8e0;
}

.overlays .opacity-row {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 11px;
    color: #5B6B7B;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: 6px;
}

.overlays .opacity-row input[type="range"] {
    flex: 1;
    accent-color: #C75146;
}

.overlay-list {
    list-style: none;
    padding: 0;
    margin: 0;
    font-size: 11.5px;
}

.overlay-list li {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
    padding: 4px 0;
    border-top: 1px solid #eef1f5;
}

.overlay-list .url {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: #1A1A1A;
}

.overlay-list .remove {
    appearance: none;
    border: 0;
    background: transparent;
    color: #B23A48;
    font-size: 16px;
    font-weight: 700;
    cursor: pointer;
    line-height: 1;
    padding: 0 4px;
}

.meta code {
    background: #F4E9CD;
    padding: 1px 4px;
    border-radius: 3px;
    font-size: 10.5px;
}

#popup {
    position: absolute;
    bottom: 16px;
    right: 16px;
    width: 380px;
    max-height: 70vh;
    overflow-y: auto;
    padding: 14px 16px;
    background: rgba(255, 255, 255, 0.97);
    border-radius: 10px;
    box-shadow: 0 6px 24px rgba(11, 37, 69, 0.18);
    z-index: 1;
    font-size: 13px;
}

#popup img {
    display: block;
    width: 100%;
    height: auto;
    max-height: 180px;
    object-fit: cover;
    border-radius: 6px;
    margin-bottom: 10px;
}

#popup .desc {
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid #e3e7ec;
    font-size: 12.5px;
    line-height: 1.5;
    color: #1A1A1A;
    white-space: pre-wrap;
}

#popup .src {
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid #e3e7ec;
}

#popup .src h4 {
    margin: 0 0 4px 0;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: #13315C;
}

#popup .src p {
    margin: 0 0 4px 0;
    font-size: 12px;
    color: #5B6B7B;
    line-height: 1.4;
}

#popup h3 {
    margin: 0 0 6px 0;
    font-size: 14px;
    color: #0B2545;
}

#popup dl {
    margin: 0;
    display: grid;
    grid-template-columns: 90px 1fr;
    row-gap: 4px;
    column-gap: 8px;
}

#popup dt {
    font-size: 11px;
    color: #5B6B7B;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

#popup dd {
    margin: 0;
    font-size: 12.5px;
    word-wrap: break-word;
}

#popup .close {
    float: right;
    cursor: pointer;
    color: #5B6B7B;
    font-size: 18px;
    line-height: 1;
}
