:root {
    --bg-primary: #0a0a0a;
    --bg-secondary: #141414;
    --bg-tertiary: #1f1f1f;
    --bg-card: #181818;
    --accent: #e11d48;
    --accent-hover: #be123c;
    --accent-glow: rgba(225, 29, 72, 0.25);
    --text-primary: #fafafa;
    --text-secondary: #a1a1aa;
    --text-muted: #71717a;
    --success: #22c55e;
    --error: #ef4444;
    --border: rgba(255, 255, 255, 0.08);
    --border-hover: rgba(255, 255, 255, 0.15);
    --radius: 16px;
    --radius-sm: 10px;
}

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: linear-gradient(180deg, #0a0a0a 0%, #0f0f0f 50%, #0a0a0a 100%);
    background-attachment: fixed;
    color: var(--text-primary);
    min-height: 100vh;
    line-height: 1.6;
}

.container {
    max-width: 1100px;
    margin: 0 auto;
    padding: 2.5rem 2rem;
}

/* Header */
header {
    text-align: center;
    margin-bottom: 3rem;
    padding-bottom: 2rem;
    border-bottom: 1px solid var(--border);
    background: linear-gradient(180deg, rgba(225, 29, 72, 0.03) 0%, transparent 100%);
    margin: -2.5rem -2rem 3rem;
    padding: 2.5rem 2rem 2rem;
}

header h1 {
    font-size: 3rem;
    font-weight: 900;
    letter-spacing: -0.02em;
    color: var(--text-primary);
    margin-bottom: 0.75rem;
}

header h1 .accent {
    color: var(--accent);
}

.subtitle {
    color: var(--text-muted);
    font-size: 1.1rem;
    font-weight: 400;
}

/* API Keys Section */
.api-keys {
    margin-bottom: 1.5rem;
}

details {
    background: linear-gradient(145deg, var(--bg-secondary) 0%, rgba(18, 18, 18, 0.98) 100%);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    transition: border-color 0.2s, box-shadow 0.2s;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.2);
}

details:hover {
    border-color: var(--border-hover);
}

details[open] {
    border-color: var(--accent);
    box-shadow: 0 4px 20px rgba(225, 29, 72, 0.1);
}

summary {
    padding: 1.25rem 1.75rem;
    cursor: pointer;
    font-weight: 600;
    font-size: 0.95rem;
    color: var(--text-secondary);
    transition: color 0.2s;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

summary:hover {
    color: var(--text-primary);
}

summary::marker {
    color: var(--accent);
}

.api-form {
    padding: 0.5rem 1.75rem 1.75rem;
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

/* Input Groups */
.input-group {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
}

label {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

input[type="text"],
input[type="password"],
input[type="number"] {
    background: linear-gradient(145deg, var(--bg-tertiary) 0%, rgba(28, 28, 28, 0.95) 100%);
    border: 1px solid rgba(225, 29, 72, 0.2);
    border-radius: var(--radius-sm);
    padding: 1rem 1.25rem;
    color: var(--text-primary);
    font-size: 1rem;
    font-family: inherit;
    transition: all 0.2s ease;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
}

input[type="number"] {
    padding: 0.75rem 1rem;
}

input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 4px var(--accent-glow);
    background: var(--bg-card);
}

input::placeholder {
    color: var(--text-muted);
}

/* Buttons */
.btn {
    padding: 1rem 2rem;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 0.95rem;
    font-weight: 700;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.2s ease;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.btn:active {
    transform: scale(0.97);
}

.btn-primary {
    background: var(--accent);
    color: white;
    box-shadow: 0 4px 20px var(--accent-glow);
}

.btn-primary:hover {
    background: var(--accent-hover);
    box-shadow: 0 6px 30px var(--accent-glow);
    transform: translateY(-2px);
}

.btn-secondary {
    background: linear-gradient(145deg, var(--bg-tertiary) 0%, rgba(28, 28, 28, 0.95) 100%);
    color: var(--text-primary);
    border: 1px solid rgba(225, 29, 72, 0.3);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
    position: relative;
    overflow: hidden;
}

.btn-secondary::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 1px;
    background: linear-gradient(90deg, transparent, rgba(225, 29, 72, 0.5), transparent);
}

.btn-secondary:hover {
    background: linear-gradient(145deg, var(--bg-card) 0%, rgba(35, 35, 35, 0.95) 100%);
    border-color: var(--accent);
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(225, 29, 72, 0.2), 0 0 15px rgba(225, 29, 72, 0.1);
}

/* Search Section */
.search-section {
    background: linear-gradient(145deg, var(--bg-secondary) 0%, rgba(20, 20, 20, 0.95) 100%);
    padding: 2rem;
    border-radius: var(--radius);
    border: 1px solid rgba(225, 29, 72, 0.25);
    margin-bottom: 2rem;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.3), inset 0 1px 0 rgba(255, 255, 255, 0.03);
    position: relative;
    overflow: hidden;
}

.search-section::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 2px;
    background: linear-gradient(90deg, transparent, var(--accent), transparent);
    opacity: 0.6;
}

.search-row {
    display: flex;
    gap: 1rem;
    align-items: flex-end;
    flex-wrap: wrap;
}

.search-row input {
    flex: 1;
    min-width: 200px;
}

/* Satellite Zoom Level Selector */
.zoom-select-wrapper {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
}

.zoom-label {
    font-size: 0.65rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: 0.4rem;
}

.zoom-select {
    background: linear-gradient(145deg, var(--bg-tertiary) 0%, rgba(28, 28, 28, 0.95) 100%);
    border: 1px solid rgba(225, 29, 72, 0.3);
    border-radius: var(--radius-sm);
    padding: 1rem 1.25rem;
    color: var(--text-primary);
    font-size: 0.95rem;
    font-weight: 700;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
    text-transform: uppercase;
    letter-spacing: 0.03em;
    -webkit-appearance: none;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23fafafa' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.75rem center;
    padding-right: 2.5rem;
}

.zoom-select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 4px var(--accent-glow);
}

.zoom-select:hover {
    border-color: var(--accent);
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(225, 29, 72, 0.2);
}

.zoom-select option {
    background: var(--bg-secondary);
    color: var(--text-primary);
    padding: 0.75rem;
    font-weight: 600;
}

/* Tools Section */
.input-group[style*="border-top"] {
    margin-top: 1.5rem !important;
    padding-top: 1.5rem !important;
    border-top: 1px solid var(--border) !important;
}

/* Results Section */
.results-section {
    display: grid;
    grid-template-columns: 1fr;
    gap: 2rem;
    align-items: start;
}

.image-container {
    position: relative;
    background: var(--bg-secondary);
    border-radius: var(--radius);
    overflow: hidden;
    border: 2px solid var(--border);
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.6), 0 0 60px rgba(225, 29, 72, 0.08);
    /* Desktop: show full square map (mobile has its own overrides below) */
    aspect-ratio: 1 / 1;
    height: auto;
}

/* Map Wrapper for Transform */
#map-wrapper {
    width: 100%;
    /* height: 100%; REMOVED for aspect ratio safety */
    position: absolute;
    top: 0;
    left: 0;
    transform-origin: 0 0;
    /* Enforce Top-Left Origin */
    touch-action: none;
    /* Prevent browser panning/scrolling */
}

/* Map Controls */
.map-controls {
    position: absolute;
    top: 1rem;
    right: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    z-index: 100;
}

/* Pan is always enabled; hide the (now-unused) toggle button. */
#btn-pan-mode {
    display: none;
}

.control-btn {
    width: 48px;
    height: 48px;
    border: 1px solid rgba(255, 255, 255, 0.12);
    background: rgba(20, 20, 20, 0.9);
    color: var(--text-primary);
    border-radius: 10px;
    cursor: pointer;
    font-size: 1.2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    transition: all 0.2s ease;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

#btn-snap-mode {
    font-size: 0.7rem;
    letter-spacing: 0.03em;
}

#btn-square-property {
    font-size: 0.7rem;
    letter-spacing: 0.03em;
}

#btn-square-shed {
    font-size: 0.6rem;
    letter-spacing: 0.04em;
}

#btn-shadow-label {
    font-size: 0.65rem;
    letter-spacing: 0.03em;
}

.control-btn:hover {
    background: var(--accent);
    border-color: var(--accent);
    transform: translateY(-1px);
}

.control-btn.active {
    background: var(--accent);
    border-color: var(--accent);
    box-shadow: 0 0 15px var(--accent-glow);
}

#satellite-img {
    width: 100%;
    height: auto;
    display: block;
}

#overlay-canvas {
    position: absolute;
    top: 0;
    left: 0;
    /* Match the image exactly, not the container */
    width: 100%;
    height: auto;
    /* Aspect ratio matches the image (square) */
    aspect-ratio: 1 / 1;
    pointer-events: auto;
    cursor: grab;
}

/* Touch devices: keep map square-sized and disable transform smoothing (prevents jumpy pan). */
@media (hover: none) and (pointer: coarse) {
    .image-container {
        width: 100%;
        max-width: 100vh;
        max-width: 100svh;
        aspect-ratio: 1 / 1;
        height: auto;
        margin-left: auto;
        margin-right: auto;
        margin-inline: auto;
    }

    #map-wrapper {
        transition: none !important;
    }

    #overlay-canvas {
        touch-action: none;
    }
}

/* Pan Mode Cursors */
.cursor-pan-grab {
    cursor: grab !important;
}

.cursor-pan-grabbing {
    cursor: grabbing !important;
}

.loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(10, 10, 10, 0.95);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1.25rem;
    backdrop-filter: blur(8px);
}

.spinner {
    width: 52px;
    height: 52px;
    border: 3px solid var(--bg-tertiary);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* Measurements Panel */
.measurements-panel {
    background: linear-gradient(145deg, var(--bg-secondary) 0%, rgba(20, 20, 20, 0.95) 100%);
    padding: 2rem;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    position: static;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.3), inset 0 1px 0 rgba(255, 255, 255, 0.03);
}

.measurements-panel h2 {
    font-size: 1.1rem;
    font-weight: 700;
    margin-bottom: 1.5rem;
    color: var(--text-primary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.measurement-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
}

.measurement-item {
    background: linear-gradient(145deg, var(--bg-tertiary) 0%, rgba(25, 25, 25, 0.95) 100%);
    padding: 1.25rem 1rem;
    border-radius: var(--radius-sm);
    text-align: center;
    border: 1px solid rgba(225, 29, 72, 0.25);
    transition: all 0.25s ease;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2), inset 0 1px 0 rgba(255, 255, 255, 0.03);
    position: relative;
    overflow: hidden;
}

.measurement-item::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 2px;
    background: linear-gradient(90deg, transparent, var(--accent), transparent);
    opacity: 0.5;
}

.measurement-item:hover {
    border-color: var(--accent);
    transform: translateY(-3px);
    box-shadow: 0 8px 20px rgba(225, 29, 72, 0.2), 0 0 15px rgba(225, 29, 72, 0.1);
}

.measurement-item:hover::before {
    opacity: 1;
}

.measurement-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 600;
}

.measurement-value {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-size: 1.1rem;
    font-weight: 800;
    color: var(--accent);
    text-shadow: 0 0 20px rgba(225, 29, 72, 0.3);
}

.measurement-input {
    width: 110px;
    box-sizing: border-box;
    height: 48px;
    line-height: 1.1;
    text-align: center;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.18);
    border-radius: 6px;
    color: var(--text-primary);
    font-size: 1.25rem;
    font-weight: 800;
    padding: 6px 10px;
    -webkit-appearance: none;
    appearance: none;
    -moz-appearance: textfield;
}

.measurement-input::-webkit-outer-spin-button,
.measurement-input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.measurement-input:focus {
    outline: 2px solid rgba(99, 102, 241, 0.45);
    outline-offset: 2px;
}

.measurement-subvalue {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-top: 0.35rem;
    font-weight: 500;
}

.measurement-unit {
    font-size: 0.85rem;
    color: var(--text-muted);
    font-weight: 500;
}

.area-display {
    margin-top: 1.25rem;
    padding-top: 1.25rem;
    border-top: 1px solid var(--border);
    text-align: center;
}

.area-value {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--success);
    background: rgba(34, 197, 94, 0.1);
    padding: 0.75rem 1rem;
    border-radius: var(--radius-sm);
    display: inline-block;
}

.clearances-panel {
    margin-top: 1.25rem;
    padding-top: 1.25rem;
    border-top: 1px solid var(--border);
}

.clearances-panel h3 {
    font-size: 0.9rem;
    font-weight: 700;
    margin-bottom: 1rem;
    color: var(--text-primary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.clearance-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
}

.clearance-item {
    background: linear-gradient(145deg, var(--bg-tertiary) 0%, rgba(25, 25, 25, 0.95) 100%);
    padding: 1rem 0.75rem;
    border-radius: var(--radius-sm);
    text-align: center;
    border: 1px solid rgba(225, 29, 72, 0.2);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
    transition: all 0.2s ease;
}

.clearance-item:hover {
    border-color: rgba(225, 29, 72, 0.4);
    transform: translateY(-2px);
}

.clearance-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-bottom: 0.35rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 600;
}

.clearance-value {
    font-size: 1.35rem;
    font-weight: 800;
    color: #38bdf8;
}

.clearance-value.is-danger {
    color: var(--error);
}

.clearance-input-row {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.clearance-input {
    width: 110px;
    box-sizing: border-box;
    height: 48px;
    line-height: 1.1;
    text-align: center;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.18);
    border-radius: 6px;
    color: var(--text-primary);
    font-size: 1.05rem;
    font-weight: 800;
    padding: 6px 10px;
    -webkit-appearance: none;
    appearance: none;
    -moz-appearance: textfield;
}

.clearance-input::-webkit-outer-spin-button,
.clearance-input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.clearance-input:focus {
    outline: 2px solid rgba(56, 189, 248, 0.45);
    outline-offset: 2px;
}

.clearance-input:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.clearance-subvalue {
    margin-top: 0.35rem;
    font-size: 0.85rem;
    color: var(--text-muted);
    font-weight: 500;
}

.clearance-item.is-danger .clearance-input {
    border-color: rgba(239, 68, 68, 0.6);
    color: var(--error);
}

.clearance-include {
    margin-top: 0.5rem;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: 0.85rem;
    color: var(--text-muted);
    user-select: none;
}

.clearance-include input {
    width: 18px;
    height: 18px;
}

.clearance-prompt-actions {
    margin-top: 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.clearance-prompt-status {
    font-size: 0.85rem;
    color: var(--text-muted);
    min-height: 1.1em;
}

.clearance-warning {
    margin-top: 0.75rem;
    font-size: 0.85rem;
    color: #fca5a5;
    background: rgba(239, 68, 68, 0.1);
    padding: 0.5rem 0.75rem;
    border-radius: var(--radius-sm);
    border: 1px solid rgba(239, 68, 68, 0.35);
}

/* Fixed Bottom Action Bar */
.bottom-action-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 0;
    background: linear-gradient(180deg, rgba(15, 15, 26, 0.0) 0%, rgba(15, 15, 26, 0.98) 20%);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    z-index: 1000;
}

.action-bar-buttons {
    display: flex;
    gap: 10px;
    padding: 12px 16px 16px;
    justify-content: center;
    max-width: 500px;
    margin: 0 auto;
}

.action-bar-btn {
    flex: 1;
    padding: 14px 20px;
    border: none;
    border-radius: 12px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: inherit;
    white-space: nowrap;
}

.action-bar-secondary {
    background: rgba(45, 45, 70, 0.95);
    color: var(--text-primary);
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.action-bar-secondary:hover {
    background: rgba(65, 65, 100, 0.95);
    border-color: rgba(255, 255, 255, 0.2);
    transform: translateY(-2px);
}

.action-bar-secondary.active {
    background: rgba(99, 102, 241, 0.3);
    border-color: var(--accent);
}

.action-bar-primary {
    background: linear-gradient(135deg, var(--accent), #be123c);
    color: white;
    box-shadow: 0 4px 20px var(--accent-glow);
}

.action-bar-primary:hover {
    box-shadow: 0 6px 25px var(--accent-glow);
    transform: translateY(-2px);
}

/* Options Popup */
.options-popup {
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%) translateY(10px);
    width: calc(100% - 32px);
    max-width: 400px;
    background: rgba(25, 25, 45, 0.98);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 16px;
    padding: 16px;
    margin-bottom: 8px;
    box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.5);
    opacity: 0;
    visibility: hidden;
    transition: all 0.25s ease;
}

.options-popup.visible {
    opacity: 1;
    visibility: visible;
    transform: translateX(-50%) translateY(0);
}

.options-popup-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 14px;
    padding-bottom: 10px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.options-popup-header span {
    font-weight: 600;
    font-size: 0.95rem;
    color: var(--text-primary);
}

.options-popup-close {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 1.1rem;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 6px;
    transition: all 0.15s;
}

.options-popup-close:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-primary);
}

.options-popup-grid {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.options-popup-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.options-popup-row span {
    font-size: 0.85rem;
    color: var(--text-secondary);
    white-space: nowrap;
}

.options-popup-row select,
.options-popup-row input[type="text"],
.options-popup-row input[type="number"] {
    flex: 1;
    padding: 8px 12px;
    background: rgba(15, 15, 30, 0.8);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 0.85rem;
    font-family: inherit;
}

.options-popup-row select:focus,
.options-popup-row input[type="text"]:focus,
.options-popup-row input[type="number"]:focus {
    outline: none;
    border-color: var(--accent);
}

.options-popup-toggles {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.options-toggle {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    background: rgba(15, 15, 30, 0.6);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 20px;
    cursor: pointer;
    transition: all 0.15s;
}

.options-toggle:hover {
    background: rgba(30, 30, 50, 0.8);
}

.options-toggle:has(input:checked) {
    background: rgba(99, 102, 241, 0.2);
    border-color: rgba(99, 102, 241, 0.4);
}

.options-toggle input {
    width: 14px;
    height: 14px;
    accent-color: var(--accent);
}

.options-toggle span {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.options-toggle:has(input:checked) span {
    color: var(--text-primary);
}

/* Add padding to main content so it doesn't get hidden behind bottom bar */
.results-section {
    padding-bottom: 100px;
}

/* Error Section */
.error-box {
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid var(--error);
    border-radius: var(--radius);
    padding: 1.25rem 1.75rem;
    color: var(--error);
    font-weight: 500;
}

/* Checkboxes */
input[type="checkbox"] {
    accent-color: var(--accent);
    cursor: pointer;
}

/* Google Places Autocomplete - Dark Theme */
.pac-container {
    background-color: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
    margin-top: 4px;
    font-family: 'Inter', sans-serif;
}

.pac-item {
    padding: 12px 16px;
    color: var(--text-primary);
    border-top: 1px solid var(--border);
    cursor: pointer;
    transition: background 0.15s;
}

.pac-item:first-child {
    border-top: none;
}

.pac-item:hover {
    background-color: var(--bg-tertiary);
}

.pac-item-selected {
    background-color: var(--bg-tertiary);
}

.pac-item-query {
    color: var(--text-primary);
    font-weight: 600;
}

.pac-matched {
    color: var(--accent);
    font-weight: 700;
}

.pac-icon {
    filter: invert(1) opacity(0.5);
}

/* Responsive */
@media (max-width: 900px) {
    .results-section {
        grid-template-columns: 1fr;
    }

    .measurements-panel {
        position: static;
    }
}

@media (max-width: 600px) {
    .container {
        padding: 1rem;
    }

    header {
        margin-bottom: 1.5rem;
        padding-bottom: 1.5rem;
    }

    header h1 {
        font-size: 1.75rem;
    }

    .subtitle {
        font-size: 0.9rem;
    }

    .search-section {
        padding: 1.25rem;
    }

    .search-row {
        flex-direction: column;
        gap: 0.75rem;
    }

    .search-row input {
        min-width: 100%;
        width: 100% !important;
    }

    .btn {
        width: 100%;
        padding: 0.875rem 1rem;
    }

    /* Shed and setback tool rows */
    .input-group .search-row {
        flex-wrap: wrap;
    }

    .input-group .search-row>div {
        width: 100%;
        justify-content: flex-start;
    }

    .input-group .search-row input[type="number"] {
        width: 60px !important;
        min-width: 60px !important;
        flex: 0 0 auto;
    }

    .input-group label {
        font-size: 0.8rem;
    }

    /* Setback row - keep items inline */
    .setback-row {
        flex-direction: row !important;
        flex-wrap: wrap !important;
    }

    .setback-row input[type="number"] {
        width: 55px !important;
        min-width: 55px !important;
    }

    .show-toggle {
        margin-left: 0 !important;
    }

    /* Results section */
    .results-section {
        gap: 1.25rem;
    }

    .measurement-grid {
        grid-template-columns: 1fr 1fr;
        gap: 0.5rem;
    }

    .measurement-item {
        padding: 1rem 0.75rem;
    }

    .measurement-value {
        font-size: 1.35rem;
    }

    .measurements-panel {
        padding: 1.25rem;
    }

    .measurements-panel h2 {
        font-size: 1rem;
        margin-bottom: 1rem;
    }

    .export-btn {
        padding: 1rem;
        font-size: 0.9rem;
    }

    /* API keys section */
    summary {
        padding: 1rem 1.25rem;
        font-size: 0.9rem;
    }

    .api-form {
        padding: 0.5rem 1.25rem 1.25rem;
    }
}

@media (max-width: 400px) {
    .container {
        padding: 0.75rem;
    }

    header h1 {
        font-size: 1.5rem;
    }

    .search-section {
        padding: 1rem;
    }

    .measurement-grid {
        grid-template-columns: 1fr;
    }

    .clearance-grid {
        grid-template-columns: 1fr;
    }
}

/* Export Options Panel */
.workflow-help {
    background: linear-gradient(145deg, var(--bg-tertiary) 0%, rgba(25, 25, 25, 0.95) 100%);
    border: 1px solid rgba(225, 29, 72, 0.2);
    border-radius: var(--radius-sm);
    margin-bottom: 1.25rem;
    overflow: hidden;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.2);
    position: relative;
}

.workflow-help::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 2px;
    background: linear-gradient(90deg, transparent, var(--accent), transparent);
    opacity: 0.5;
}

.workflow-help summary {
    padding: 1rem 1.25rem;
    cursor: pointer;
    font-weight: 700;
    font-size: 0.9rem;
    color: var(--text-primary);
    user-select: none;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    letter-spacing: 0.02em;
    transition: background 0.2s;
}

.workflow-help summary:hover {
    background: rgba(225, 29, 72, 0.05);
}

.workflow-help[open] summary {
    border-bottom: 1px solid rgba(225, 29, 72, 0.15);
    background: rgba(225, 29, 72, 0.03);
}

.workflow-steps {
    padding: 1rem 1.25rem 1.25rem;
    margin-left: 0;
    padding-left: 2.5rem;
    color: var(--text-secondary);
    font-size: 0.9rem;
    counter-reset: workflow-step;
    list-style: none;
}

.workflow-steps li {
    margin: 0.75rem 0;
    line-height: 1.5;
    position: relative;
    padding-left: 0.5rem;
    counter-increment: workflow-step;
}

.workflow-steps li::before {
    content: counter(workflow-step);
    position: absolute;
    left: -1.75rem;
    top: 0;
    width: 1.4rem;
    height: 1.4rem;
    background: linear-gradient(135deg, var(--accent), #be123c);
    color: white;
    font-size: 0.75rem;
    font-weight: 700;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 6px rgba(225, 29, 72, 0.3);
}

.workflow-steps strong {
    color: var(--text-primary);
    font-weight: 600;
}

.workflow-steps em {
    color: var(--text-muted);
    font-style: normal;
    font-size: 0.85em;
}

.workflow-steps code {
    background: rgba(225, 29, 72, 0.1);
    border: 1px solid rgba(225, 29, 72, 0.25);
    padding: 0.15rem 0.5rem;
    border-radius: 4px;
    font-size: 0.8em;
    font-weight: 600;
    color: var(--accent);
}

.refresh-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.5rem;
    height: 1.5rem;
    background: rgba(225, 29, 72, 0.15);
    border: 1px solid rgba(225, 29, 72, 0.3);
    border-radius: 50%;
    font-size: 0.95rem;
    color: var(--accent);
    margin-right: 0.35rem;
    vertical-align: middle;
}

.export-options {
    background: linear-gradient(145deg, var(--bg-tertiary) 0%, rgba(28, 28, 28, 0.95) 100%);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    margin-top: 1rem;
    margin-bottom: 1rem;
    overflow: hidden;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.2);
    transition: border-color 0.2s, box-shadow 0.2s;
}

.export-options summary {
    padding: 0.75rem 1rem;
    cursor: pointer;
    font-weight: 500;
    color: var(--text-primary);
    user-select: none;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.export-options summary:hover {
    background: rgba(255, 255, 255, 0.03);
}

.export-options[open] summary {
    border-bottom: 1px solid var(--border);
    background: rgba(225, 29, 72, 0.03);
}

.options-grid {
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.option-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.option-row span {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    white-space: nowrap;
}

.option-row select {
    background: var(--bg-secondary);
    color: var(--text-primary);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 0.4rem 0.6rem;
    font-size: 0.85rem;
    min-width: 130px;
}

.option-row select:focus {
    outline: none;
    border-color: var(--accent);
}

.option-row input[type="text"] {
    background: var(--bg-secondary);
    color: var(--text-primary);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 0.4rem 0.6rem;
    font-size: 0.85rem;
}

.option-row input[type="text"]:focus {
    outline: none;
    border-color: var(--accent);
}

.toggle-row input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: var(--accent);
    cursor: pointer;
}

/* Custom Notes - Full Width Row */
.option-row.notes-row {
    flex-direction: column;
    align-items: stretch;
    gap: 0.5rem;
}

.option-row.notes-row input[type="text"] {
    width: 100%;
}

/* Mobile adjustments for export options */
@media (max-width: 400px) {
    .option-row {
        flex-wrap: wrap;
    }

    .option-row select,
    .option-row input[type="text"] {
        width: 100%;
        min-width: unset;
    }
}

/* Area Display - Use Accent Color (not green) */
.area-display {
    text-align: center;
    padding: 1rem 0;
    margin-bottom: 0.5rem;
}

.area-display .area-value {
    color: var(--accent);
    font-size: 1.1rem;
    font-weight: 600;
}

/* Map Tool Popups */
.map-tool-popup {
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 8px;
    background: rgba(20, 20, 20, 0.95);
    border: 1px solid rgba(225, 29, 72, 0.3);
    border-radius: 12px;
    padding: 1rem;
    min-width: 180px;
    z-index: 200;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5), 0 0 20px rgba(225, 29, 72, 0.1);
    display: none;
}

.map-tool-popup.visible {
    display: block;
}

.map-tool-popup-title {
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.75rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.map-tool-popup-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 0.75rem;
}

.map-tool-popup-row input[type="number"] {
    width: 60px;
    padding: 0.5rem;
    text-align: center;
    font-size: 0.9rem;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 6px;
    color: var(--text-primary);
}

.map-tool-popup-row input[type="number"]:focus {
    outline: none;
    border-color: var(--accent);
}

.map-tool-popup-row span {
    color: var(--text-muted);
    font-size: 0.85rem;
}

.map-tool-popup .btn {
    width: 100%;
    padding: 0.6rem 1rem;
    font-size: 0.8rem;
    margin-top: 0.25rem;
}

.map-tool-popup .btn+.btn {
    margin-top: 0.5rem;
}

.map-tool-popup .btn-remove {
    background: #7f1d1d;
    border-color: #991b1b;
}

.map-tool-popup .btn-remove:hover {
    background: #991b1b;
}

/* Tool button with popup container */
.control-btn-wrapper {
    position: relative;
}

#btn-shed-tool,
#btn-house-tool {
    font-size: 0.65rem;
    letter-spacing: 0.03em;
}

#btn-setback-tool {
    font-size: 0.55rem;
    letter-spacing: 0.02em;
    line-height: 1.1;
    text-align: center;
}

#btn-measure-tool {
    font-size: 1.3rem;
}

#btn-whiteout-tool {
    font-size: 0.5rem;
    letter-spacing: 0.02em;
    line-height: 1.1;
    text-align: center;
}

/* Measure popup grid */
.measure-popup-grid {
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-height: 200px;
    overflow-y: auto;
}

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

.measure-popup-row label {
    min-width: 50px;
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.measure-popup-row input {
    width: 70px;
    padding: 6px 8px;
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 6px;
    background: rgba(30, 30, 30, 0.8);
    color: var(--text-primary);
    font-size: 0.9rem;
    text-align: right;
}

.measure-popup-row span {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

/* Structure List Styles */
.structure-list-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 8px;
    margin-bottom: 4px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 4px;
    border: 1px solid transparent;
    cursor: pointer;
    transition: all 0.15s ease;
}

.structure-list-item:hover {
    background: rgba(255, 255, 255, 0.1);
}

.structure-list-item.selected {
    background: rgba(234, 179, 8, 0.2);
    border-color: rgba(234, 179, 8, 0.5);
}

.structure-name {
    font-size: 0.75rem;
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.structure-delete-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 0.75rem;
    padding: 2px 6px;
    border-radius: 3px;
    opacity: 0.6;
    transition: all 0.15s ease;
}

.structure-delete-btn:hover {
    background: rgba(239, 68, 68, 0.2);
    color: #ef4444;
    opacity: 1;
}

/* Quick Load Popup */
.quick-load-popup {
    position: fixed;
    width: 280px;
    background: linear-gradient(145deg, rgba(30, 30, 50, 0.98) 0%, rgba(20, 20, 35, 0.98) 100%);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 16px;
    padding: 16px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.6), 0 0 0 1px rgba(255, 255, 255, 0.05) inset;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-8px);
    transition: opacity 0.2s ease, visibility 0.2s ease, transform 0.2s ease;
    z-index: 9999;
    backdrop-filter: blur(10px);
}

.quick-load-popup.visible {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.quick-load-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 14px;
    padding-bottom: 12px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.quick-load-header span {
    font-weight: 600;
    font-size: 0.95rem;
    color: var(--text-primary);
}

.quick-load-list {
    max-height: 180px;
    overflow-y: auto;
    margin-bottom: 12px;
}

.quick-load-list::-webkit-scrollbar {
    width: 4px;
}

.quick-load-list::-webkit-scrollbar-track {
    background: transparent;
}

.quick-load-list::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.15);
    border-radius: 4px;
}

.quick-load-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 12px;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid transparent;
    border-radius: 8px;
    margin-bottom: 6px;
    cursor: pointer;
    transition: all 0.15s ease;
}

.quick-load-item:last-child {
    margin-bottom: 0;
}

.quick-load-item:hover {
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(255, 255, 255, 0.1);
}

.quick-load-item:active {
    transform: scale(0.98);
}

.quick-load-item-name {
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
}

.quick-load-item-date {
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-left: 12px;
    flex-shrink: 0;
}

.quick-load-divider {
    display: flex;
    align-items: center;
    gap: 12px;
    color: var(--text-muted);
    font-size: 0.75rem;
    margin: 14px 0;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.quick-load-divider::before,
.quick-load-divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: rgba(255, 255, 255, 0.08);
}

.quick-load-import-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    padding: 10px 16px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px dashed rgba(255, 255, 255, 0.15);
    border-radius: 8px;
    color: var(--text-secondary);
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.15s ease;
}

.quick-load-import-btn:hover {
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(255, 255, 255, 0.25);
    color: var(--text-primary);
    cursor: pointer;
}

.quick-load-empty {
    color: var(--text-muted);
    font-size: 0.8rem;
    padding: 16px 8px;
    text-align: center;
}

.search-row {
    position: relative;
}