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

body {
    font-family: 'Assistant', -apple-system, BlinkMacSystemFont, sans-serif;
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background-color: #f8f9fa;
}

body.embed-mode header {
    display: none !important;
}

header {
    background-color: #1e293b;
    color: #ffffff;
    padding: 10px 18px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    z-index: 1000;
}

header h1 {
    font-size: 1.2rem;
    font-weight: 700;
}

.poi-count-badge {
    background-color: #8B261D;
    color: white;
    padding: 3px 10px;
    border-radius: 14px;
    font-size: 0.85rem;
    font-weight: 600;
}

#appWorkspace {
    flex: 1;
    min-height: 0;
    width: 100%;
    display: flex;
    position: relative;
    overflow: hidden;
}

#map {
    flex: 1;
    min-width: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
}

/* v1.4 integrated map controls */
.map-ui-panel {
    width: 290px;
    max-width: calc(100vw - 24px);
    max-height: calc(100vh - 145px);
    overflow: hidden;
    background: rgba(255, 255, 255, 0.97);
    border: 1px solid rgba(203, 213, 225, 0.95);
    border-radius: 10px;
    box-shadow: 0 5px 18px rgba(15, 23, 42, 0.18);
    color: #1e293b;
    direction: ltr !important;
    text-align: left !important;
    user-select: none;
}

.map-ui-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 9px 11px;
    border-bottom: 1px solid #e2e8f0;
    background: #f8fafc;
}

.map-ui-panel-title {
    color: #0f172a;
    font-size: 13px;
    font-weight: 700;
}

.map-ui-panel-collapse {
    display: none;
    width: 26px;
    height: 24px;
    border: 1px solid #cbd5e1;
    border-radius: 5px;
    background: #ffffff;
    color: #334155;
    font-size: 16px;
    line-height: 18px;
    cursor: pointer;
}

.map-ui-panel-body {
    max-height: calc(100vh - 190px);
    overflow-y: auto;
    padding: 2px 11px 10px;
}

.map-control-section {
    padding: 9px 0;
    border-top: 1px solid #e2e8f0;
}

.map-control-section:first-child {
    border-top: 0;
}

.map-control-section-title {
    margin: 0 0 6px;
    color: #0f172a;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.01em;
}

.filter-actions {
    display: flex;
    justify-content: flex-end;
    gap: 4px;
    margin: -2px 0 5px;
}

.filter-action-button {
    border: 1px solid #cbd5e1;
    background: #f8fafc;
    color: #475569;
    border-radius: 4px;
    font-size: 10px;
    line-height: 1.2;
    padding: 2px 6px;
    cursor: pointer;
}

.filter-action-button:hover,
.filter-action-button:focus {
    background: #e2e8f0;
    outline: none;
}

.control-toggle-items {
    display: flex;
    flex-direction: column;
    gap: 1px;
}

.control-toggle-item {
    display: grid;
    grid-template-columns: 20px minmax(0, 1fr) auto;
    align-items: center;
    gap: 7px;
    min-height: 26px;
    padding: 2px 4px;
    border-radius: 5px;
    cursor: pointer;
    transition: opacity 0.16s, background-color 0.16s, filter 0.16s;
}

.control-toggle-item:hover,
.control-toggle-item:focus {
    background: #f1f5f9;
    outline: none;
}

.control-toggle-item.disabled {
    opacity: 0.35;
    text-decoration: line-through;
    filter: grayscale(80%);
}

.control-toggle-icon {
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.control-toggle-label {
    min-width: 0;
    overflow-wrap: anywhere;
    font-size: 12px;
    line-height: 1.25;
}

.control-toggle-count {
    color: #64748b;
    font-size: 10px;
    font-variant-numeric: tabular-nums;
}

.type-color-swatch {
    width: 13px;
    height: 13px;
    display: inline-block;
    border-radius: 4px;
    background: var(--type-color, #64748b);
    border: 1px solid rgba(15, 23, 42, 0.16);
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.25);
}

.geometry-icon {
    display: inline-block;
    color: #475569;
}

.geometry-icon-point {
    width: 11px;
    height: 11px;
    border-radius: 50%;
    background: currentColor;
}

.geometry-icon-line {
    width: 16px;
    height: 0;
    border-top: 3px solid currentColor;
    transform: rotate(-18deg);
}

.geometry-icon-polygon {
    width: 14px;
    height: 12px;
    border: 2px solid currentColor;
    background: rgba(71, 85, 105, 0.12);
    clip-path: polygon(10% 20%, 82% 4%, 98% 75%, 35% 100%, 0 68%);
}

.map-search-input {
    width: 100%;
    padding: 6px 8px;
    border: 1px solid #cbd5e1;
    border-radius: 5px;
    background: #ffffff;
    color: #1e293b;
    font-size: 12px;
    outline: none;
}

.map-search-input:focus {
    border-color: #0284c7;
    box-shadow: 0 0 0 2px rgba(2, 132, 199, 0.12);
}

.map-utility-buttons {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 5px;
}

.btn-control {
    background: #f8fafc;
    border: 1px solid #cbd5e1;
    border-radius: 5px;
    padding: 5px 7px;
    font-size: 10px;
    cursor: pointer;
    font-weight: 600;
    color: #334155;
    transition: background-color 0.16s, border-color 0.16s, color 0.16s;
}

.btn-control:hover,
.btn-control:focus {
    background: #e2e8f0;
    outline: none;
}

.btn-control.active {
    background: #0284c7;
    color: white;
    border-color: #0284c7;
}

.coords-display {
    margin-top: 7px;
    padding: 5px 7px;
    border: 1px solid #e2e8f0;
    border-radius: 5px;
    background: #f8fafc;
    color: #475569;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 10px;
    line-height: 1.3;
}

body.embed-mode .map-ui-panel {
    width: 265px;
    max-height: calc(100vh - 28px);
}

body.embed-mode .map-ui-panel-body {
    max-height: calc(100vh - 75px);
}

@media (max-width: 700px) {
    .map-ui-panel {
        width: min(280px, calc(100vw - 78px));
        max-height: 60vh;
    }

    .map-ui-panel-collapse {
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }

    .map-ui-panel.collapsed {
        width: auto;
        min-width: 126px;
    }

    .map-ui-panel.collapsed .map-ui-panel-body {
        display: none;
    }

    .map-ui-panel-body {
        max-height: calc(60vh - 44px);
    }

    .control-toggle-label {
        font-size: 11px;
    }
}

/* Map popup */
.leaflet-popup-content-wrapper {
    border-radius: 8px;
    padding: 4px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
}

.leaflet-popup-content {
    margin: 10px 12px;
    max-width: 280px !important;
    font-size: 13px;
    line-height: 1.45;
    color: #222;
    direction: ltr !important;
    text-align: left !important;
}

.popup-field {
    margin-bottom: 3px;
    word-wrap: break-word;
}

.popup-field strong {
    color: #0f172a;
}

.popup-img {
    width: 100%;
    max-width: 260px;
    height: auto;
    max-height: 220px;
    object-fit: cover;
    border-radius: 6px;
    display: block;
    margin-top: 8px;
    border: 1px solid #ddd;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.15);
}

.custom-svg-icon {
    background: transparent;
    border: none;
}


/* Stage 7: entity detail panel */
.entity-detail-panel {
    display: none;
    width: min(390px, 34vw);
    min-width: 330px;
    height: 100%;
    background: #ffffff;
    border-left: 1px solid #cbd5e1;
    box-shadow: -4px 0 16px rgba(15, 23, 42, 0.12);
    color: #1e293b;
    z-index: 900;
    flex-direction: column;
    direction: ltr !important;
    text-align: left !important;
}

.entity-detail-panel.open {
    display: flex;
}

.entity-detail-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    padding: 16px 16px 12px;
    border-bottom: 1px solid #e2e8f0;
    background: #f8fafc;
}

.entity-detail-heading {
    min-width: 0;
}

.entity-detail-eyebrow {
    color: #64748b;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    margin-bottom: 3px;
}

.entity-detail-header h2 {
    margin: 0;
    color: #0f172a;
    font-size: 18px;
    line-height: 1.25;
    overflow-wrap: anywhere;
}

.entity-detail-close {
    flex: 0 0 auto;
    width: 30px;
    height: 30px;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    background: #ffffff;
    color: #475569;
    font-size: 22px;
    line-height: 24px;
    cursor: pointer;
}

.entity-detail-close:hover,
.entity-detail-close:focus {
    background: #e2e8f0;
    color: #0f172a;
    outline: none;
}

.entity-detail-content {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 14px 16px 20px;
}

.entity-detail-badges {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 14px;
}

.entity-detail-badge {
    display: inline-flex;
    align-items: center;
    min-height: 24px;
    padding: 3px 8px;
    border-radius: 999px;
    background: #e0f2fe;
    color: #075985;
    border: 1px solid #bae6fd;
    font-size: 11px;
    font-weight: 700;
}

.entity-detail-badge-secondary {
    background: #f1f5f9;
    border-color: #cbd5e1;
    color: #475569;
}

.entity-detail-section {
    padding: 12px 0;
    border-top: 1px solid #e2e8f0;
}

.entity-detail-section:first-of-type {
    border-top: 0;
    padding-top: 0;
}

.entity-detail-section h3,
.entity-detail-technical summary {
    margin: 0 0 8px;
    color: #0f172a;
    font-size: 12px;
    font-weight: 700;
}

.entity-detail-section-count {
    display: inline-block;
    margin-left: 4px;
    color: #64748b;
    font-size: 10px;
    font-weight: 600;
}

.entity-detail-description {
    color: #334155;
    font-size: 13px;
    line-height: 1.55;
    overflow-wrap: anywhere;
}

.entity-detail-fields {
    display: grid;
    gap: 8px;
}

.entity-detail-field {
    display: grid;
    grid-template-columns: minmax(105px, 0.8fr) minmax(0, 1.6fr);
    gap: 10px;
    align-items: start;
}

.entity-detail-label {
    color: #64748b;
    font-size: 11px;
    font-weight: 600;
}

.entity-detail-value {
    color: #1e293b;
    font-size: 12px;
    line-height: 1.4;
    overflow-wrap: anywhere;
}

.entity-detail-field-monospace .entity-detail-value {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 10px;
}

.entity-detail-media-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
}

.entity-detail-media-item {
    display: block;
    color: #475569;
    text-decoration: none;
    font-size: 10px;
}

.entity-detail-media-item img {
    display: block;
    width: 100%;
    aspect-ratio: 4 / 3;
    object-fit: cover;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    background: #f1f5f9;
    margin-bottom: 3px;
}

.entity-detail-media-item:hover img,
.entity-detail-media-item:focus img {
    border-color: #0284c7;
}

.entity-detail-attachment-link {
    display: block;
    padding: 7px 8px;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    color: #0369a1;
    text-decoration: none;
    font-size: 11px;
}

.entity-detail-technical {
    margin-top: 4px;
    padding-top: 12px;
    border-top: 1px solid #e2e8f0;
}

.entity-detail-technical summary {
    cursor: pointer;
    margin-bottom: 0;
}

.entity-detail-technical[open] summary {
    margin-bottom: 8px;
}

.entity-detail-empty {
    color: #64748b;
    font-size: 12px;
}

body.embed-mode .entity-detail-panel {
    width: min(340px, 38vw);
    min-width: 290px;
}

/* Concise popup; the full record now lives in the Detail Panel. */
.popup-summary {
    min-width: 190px;
}

.popup-title {
    margin-bottom: 6px;
    color: #0f172a;
    font-size: 14px;
    font-weight: 700;
    line-height: 1.3;
}

.popup-detail-button {
    width: 100%;
    margin-top: 8px;
    padding: 6px 9px;
    border: 1px solid #0284c7;
    border-radius: 5px;
    background: #0284c7;
    color: #ffffff;
    font-size: 11px;
    font-weight: 700;
    cursor: pointer;
}

.popup-detail-button:hover,
.popup-detail-button:focus {
    background: #0369a1;
    border-color: #0369a1;
    outline: none;
}

@media (max-width: 700px) {
    .entity-detail-panel,
    body.embed-mode .entity-detail-panel {
        position: absolute;
        left: 8px;
        right: 8px;
        bottom: 8px;
        width: auto;
        min-width: 0;
        height: auto;
        max-height: 62%;
        border: 1px solid #cbd5e1;
        border-radius: 10px;
        box-shadow: 0 -4px 18px rgba(15, 23, 42, 0.18);
        z-index: 1200;
    }

    .entity-detail-header {
        padding: 12px 12px 9px;
    }

    .entity-detail-content {
        padding: 10px 12px 14px;
    }

    .entity-detail-field {
        grid-template-columns: 1fr;
        gap: 2px;
    }
}

/* v1.4 Stage 8 unified Type + Geometry filtering */
.map-ui-panel-summary {
    padding: 6px 11px;
    border-bottom: 1px solid #e2e8f0;
    background: #ffffff;
    color: #475569;
    font-size: 10px;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

.control-toggle-item.no-matches:not(.disabled) {
    opacity: 0.55;
}

.control-toggle-item.synthetic-value .control-toggle-label {
    font-style: italic;
}

.control-toggle-item.synthetic-value .type-color-swatch {
    border-style: dashed;
}

@media (max-width: 700px) {
    .map-ui-panel.collapsed .map-ui-panel-summary {
        display: block;
        max-width: 180px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }
}

/* v1.4 Stage 9 multi-geometry search suggestions */
.map-search-results {
    margin-top: 5px;
    max-height: 245px;
    overflow-y: auto;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    background: #ffffff;
    box-shadow: 0 4px 12px rgba(15, 23, 42, 0.12);
}

.map-search-results[hidden] {
    display: none;
}

.map-search-result {
    width: 100%;
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    gap: 8px;
    align-items: start;
    padding: 7px 8px;
    border: 0;
    border-bottom: 1px solid #e2e8f0;
    background: #ffffff;
    color: #1e293b;
    text-align: left;
    cursor: pointer;
}

.map-search-result:last-child {
    border-bottom: 0;
}

.map-search-result:hover,
.map-search-result:focus,
.map-search-result.active {
    background: #f0f9ff;
    outline: none;
}

.map-search-result-geometry {
    min-width: 48px;
    padding: 2px 5px;
    border-radius: 999px;
    background: #e2e8f0;
    color: #475569;
    font-size: 9px;
    font-weight: 700;
    text-align: center;
}

.map-search-result-geometry.geometry-point {
    background: #e0f2fe;
    color: #0369a1;
}

.map-search-result-geometry.geometry-line {
    background: #dcfce7;
    color: #166534;
}

.map-search-result-geometry.geometry-polygon {
    background: #fef3c7;
    color: #92400e;
}

.map-search-result-text {
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.map-search-result-name {
    color: #0f172a;
    font-size: 11px;
    font-weight: 700;
    line-height: 1.25;
    overflow-wrap: anywhere;
}

.map-search-result-meta {
    color: #64748b;
    font-size: 9px;
    line-height: 1.3;
    overflow-wrap: anywhere;
}

.map-search-empty {
    padding: 8px;
    color: #64748b;
    font-size: 10px;
}

/* Stage 9 attachment/detail refinements */
.entity-detail-badge-geometry {
    background: #e2e8f0;
    color: #334155;
}

.entity-detail-audio-item {
    grid-column: 1 / -1;
    padding: 8px;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    background: #f8fafc;
}

.entity-detail-attachment-name {
    margin-bottom: 6px;
    color: #334155;
    font-size: 10px;
    font-weight: 600;
    overflow-wrap: anywhere;
}

.entity-detail-audio-item audio {
    width: 100%;
    min-width: 0;
    margin-bottom: 5px;
}

.entity-detail-audio-item .entity-detail-attachment-link {
    padding: 4px 0 0;
    border: 0;
    background: transparent;
}

/* v1.4 Stage 10 media/attachment refinement */
.entity-detail-media-section + .entity-detail-media-section {
    margin-top: 12px;
}

.entity-detail-audio-list,
.entity-detail-other-list {
    display: grid;
    gap: 8px;
}

.entity-detail-other-item {
    display: grid;
    gap: 4px;
}

.entity-detail-media-kind {
    color: #64748b;
    font-size: 9px;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}
