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

html, body { height: 100%; font-family: system-ui, -apple-system, sans-serif; }

/* Layout */
body { display: flex; }

#map {
    flex: 1;
    height: 100vh;
    z-index: 0;
}

#panel {
    width: 320px;
    min-width: 320px;
    height: 100vh;
    display: flex;
    flex-direction: column;
    background: #fff;
    box-shadow: 2px 0 12px rgba(0,0,0,.12);
    z-index: 1000;
}

#panel-scroll {
    flex: 1;
    min-height: 0;      /* lets flex child shrink so overflow-y actually fires */
    overflow-y: auto;
    padding: 16px;
}

/* Typography */
h1 {
    font-size: 1.5rem;
    font-weight: 700;
    color: #1a1a1a;
    letter-spacing: -0.02em;
}

.subtitle {
    font-size: .8rem;
    color: #888;
    margin-top: 2px;
    margin-bottom: 12px;
}

/* Fields */
.field {
    margin-bottom: 10px;
}

.field label {
    display: block;
    font-size: .78rem;
    font-weight: 600;
    color: #444;
    margin-bottom: 5px;
    text-transform: uppercase;
    letter-spacing: .04em;
}

.field input[type="range"] {
    width: 100%;
    accent-color: #3b82f6;
    cursor: pointer;
}

.field input[type="text"],
.field input[type="number"],
.field select {
    width: 100%;
    padding: 7px 10px;
    border: 1.5px solid #ddd;
    border-radius: 6px;
    font-size: .88rem;
    color: #1a1a1a;
    background: #fafafa;
    transition: border-color .15s;
}

.field input[type="text"]:focus,
.field input[type="number"]:focus,
.field select:focus {
    outline: none;
    border-color: #3b82f6;
    background: #fff;
}

/* File inputs */
.file-input {
    display: block;
    width: 100%;
    padding: 5px 0;
    font-size: .82rem;
    color: #555;
    cursor: pointer;
}
.file-input::-webkit-file-upload-button {
    padding: 5px 10px;
    background: #f3f4f6;
    color: #374151;
    border: 1.5px solid #d1d5db;
    border-radius: 5px;
    font-size: .8rem;
    font-weight: 500;
    cursor: pointer;
    margin-right: 8px;
    transition: background .12s;
}
.file-input::-webkit-file-upload-button:hover { background: #e5e7eb; }
.file-input::file-selector-button {
    padding: 5px 10px;
    background: #f3f4f6;
    color: #374151;
    border: 1.5px solid #d1d5db;
    border-radius: 5px;
    font-size: .8rem;
    font-weight: 500;
    cursor: pointer;
    margin-right: 8px;
    transition: background .12s;
}
.file-input::file-selector-button:hover { background: #e5e7eb; }

.search-row {
    display: flex;
    gap: 6px;
}
.search-row input { flex: 1; }
.search-row button {
    padding: 7px 12px;
    background: #3b82f6;
    color: #fff;
    border: none;
    border-radius: 6px;
    font-size: .85rem;
    font-weight: 600;
    cursor: pointer;
    transition: background .15s;
}
.search-row button:hover { background: #2563eb; }

.checkbox-label {
    display: flex !important;
    align-items: center;
    gap: 8px;
    font-size: .88rem;
    font-weight: 400 !important;
    text-transform: none !important;
    letter-spacing: 0 !important;
    color: #333 !important;
    cursor: pointer;
}
.checkbox-label input { width: 15px; height: 15px; accent-color: #3b82f6; cursor: pointer; }

.hint {
    font-size: .78rem;
    color: #888;
    margin-bottom: 10px;
}

/* Coords display */
#coords-display span {
    font-size: .88rem;
    color: #2563eb;
    font-weight: 500;
}

.clear-link {
    font-size: .75rem;
    color: #888;
    text-decoration: underline;
    cursor: pointer;
    margin-left: 8px;
}
.clear-link:hover { color: #ef4444; }

/* Segmented control */
.seg-control {
    display: flex;
    border: 1.5px solid #ddd;
    border-radius: 6px;
    overflow: hidden;
}
.seg-btn {
    flex: 1;
    padding: 7px 0;
    background: #fafafa;
    color: #555;
    border: none;
    border-right: 1.5px solid #ddd;
    font-size: .82rem;
    font-weight: 500;
    cursor: pointer;
    transition: background .12s, color .12s;
}
.seg-btn:last-child { border-right: none; }
.seg-btn:hover { background: #f3f4f6; }
.seg-btn.active { background: #3b82f6; color: #fff; }

/* 3-up mode toggle: slightly smaller text so it fits */
.seg-control-3 .seg-btn {
    font-size: .76rem;
    padding: 7px 2px;
}

/* Small hint below a field */
.field-hint {
    display: block;
    font-size: .72rem;
    color: #aaa;
    margin-top: 3px;
}

/* Scale size warning */
.scale-size-warn {
    color: #dc2626 !important;
    font-weight: 600;
}

/* Collapsible groups — shared styles */
details.group,
details.advanced {
    margin-bottom: 8px;
    border: 1.5px solid #e5e7eb;
    border-radius: 8px;
}

details.group summary,
details.advanced summary {
    padding: 7px 10px;
    font-size: .78rem;
    font-weight: 600;
    color: #555;
    text-transform: uppercase;
    letter-spacing: .04em;
    cursor: pointer;
    background: #f9fafb;
    user-select: none;
    border-radius: 6px;
    list-style: none;
}

details.group[open] summary,
details.advanced[open] summary {
    border-radius: 6px 6px 0 0;
    border-bottom: 1.5px solid #e5e7eb;
    margin-bottom: 0;
}

details.group summary:hover,
details.advanced summary:hover { background: #f3f4f6; }

details.group summary::-webkit-details-marker,
details.advanced summary::-webkit-details-marker { display: none; }

details.group summary::before,
details.advanced summary::before {
    content: '▸';
    display: inline-block;
    margin-right: 6px;
    transition: transform .15s;
}

details.group[open] summary::before,
details.advanced[open] summary::before { transform: rotate(90deg); }

details.group > .field,
details.advanced > .field {
    padding: 0 10px;
    margin-top: 8px;
}

details.group > .field:last-child,
details.advanced > .field:last-child { margin-bottom: 8px; }

/* Inner mode blocks inside group */
details.group > #pin-options,
details.group > #area-options,
details.group > #route-options {
    padding: 8px 10px 4px;
}

/* Small secondary button used inside groups */
button.secondary-sm {
    padding: 6px 10px;
    background: #f3f4f6;
    color: #374151;
    border: 1.5px solid #d1d5db;
    border-radius: 6px;
    font-size: .8rem;
    font-weight: 500;
    cursor: pointer;
    transition: background .12s;
}
button.secondary-sm:hover { background: #e5e7eb; }
button.secondary-sm.active { background: #fef3c7; border-color: #f59e0b; color: #92400e; }

/* Route point icons */
.route-point-icon {
    background: transparent;
    border: none;
}

/* Divider */
.divider {
    height: 1px;
    background: #e5e7eb;
    margin: 4px 0 10px;
}

/* Buttons */
button.primary, a.btn.primary {
    display: block;
    width: 100%;
    padding: 10px;
    background: #3b82f6;
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: .92rem;
    font-weight: 600;
    cursor: pointer;
    text-align: center;
    text-decoration: none;
    transition: background .15s, opacity .15s;
    margin-bottom: 10px;
}
button.primary:hover, a.btn.primary:hover { background: #2563eb; }
button.primary:disabled { opacity: .45; cursor: not-allowed; }

/* Status area */
#status-area {
    border: 1.5px solid #e5e7eb;
    border-radius: 8px;
    padding: 12px 14px;
    background: #f9fafb;
}

#status-area.hidden { display: none; }

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

#status-icon { font-size: 1.1rem; }

#status-msg {
    font-size: .88rem;
    font-weight: 600;
    color: #1a1a1a;
}

#elapsed {
    font-size: .78rem;
    color: #888;
    margin-bottom: 10px;
}

/* Spinner */
.spinner {
    display: inline-block;
    width: 14px;
    height: 14px;
    border: 2px solid #d1d5db;
    border-top-color: #3b82f6;
    border-radius: 50%;
    animation: spin .7s linear infinite;
    flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }

.hidden { display: none !important; }

/* Attribution bar */
#attr {
    font-size: .68rem;
    color: #aaa;
    margin-top: 12px;
    padding-top: 10px;
    border-top: 1px solid #f0f0f0;
    line-height: 1.5;
}
#attr a { color: #93c5fd; }

/* Download + preview side-by-side */
.action-row { display: flex; gap: 8px; }
.action-row .btn,
.action-row button { flex: 1; margin-bottom: 0; }

button.secondary {
    display: block;
    width: 100%;
    padding: 10px;
    background: #f3f4f6;
    color: #374151;
    border: 1.5px solid #d1d5db;
    border-radius: 8px;
    font-size: .92rem;
    font-weight: 600;
    cursor: pointer;
    transition: background .15s;
}
button.secondary:hover { background: #e5e7eb; }

/* 3D preview modal */
#preview-modal {
    position: fixed;
    inset: 0;
    background: #111827;
    z-index: 9000;
    display: flex;
    flex-direction: column;
}
#preview-modal.hidden { display: none !important; }

#preview-canvas { flex: 1; display: block; width: 100%; }

#preview-close {
    position: absolute;
    top: 12px;
    right: 16px;
    color: #fff;
    cursor: pointer;
    font-size: .88rem;
    font-weight: 600;
    z-index: 9001;
    background: rgba(0,0,0,.5);
    padding: 5px 12px;
    border-radius: 6px;
    border: none;
}
#preview-close:hover { background: rgba(0,0,0,.75); }

#preview-loading {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: rgba(255,255,255,.6);
    font-size: 1rem;
    pointer-events: none;
}
#preview-loading.hidden { display: none; }

#preview-hint {
    position: absolute;
    bottom: 14px;
    left: 50%;
    transform: translateX(-50%);
    color: rgba(255,255,255,.35);
    font-size: .75rem;
    pointer-events: none;
    white-space: nowrap;
}

@media (max-width: 640px) {
    body { flex-direction: column-reverse; }
    #map { height: 45vh; }
    #panel { width: 100%; height: 55vh; min-width: unset; box-shadow: none; border-top: 1px solid #e5e7eb; }
    #panel-scroll { padding: 12px; }
}
