/* ========================================
   Polygon Drawer - Apple-inspired Design
   ======================================== */

:root {
    --bg-glass: rgba(28, 28, 30, 0.72);
    --bg-glass-light: rgba(28, 28, 30, 0.55);
    --bg-solid: #1c1c1e;
    --bg-elevated: #2c2c2e;
    --bg-tertiary: #3a3a3c;
    --text-primary: #ffffff;
    --text-secondary: rgba(255, 255, 255, 0.6);
    --text-tertiary: rgba(255, 255, 255, 0.4);
    --accent: #0a84ff;
    --accent-hover: #409cff;
    --success: #30d158;
    --danger: #ff453a;
    --separator: rgba(255, 255, 255, 0.08);
    --radius-sm: 10px;
    --radius-md: 14px;
    --radius-lg: 20px;
    --radius-xl: 28px;
    --blur: 20px;
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --toolbar-height: 82px;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

html, body {
    height: 100%;
    overflow: hidden;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'SF Pro Text', system-ui, sans-serif;
    background: #000;
    color: var(--text-primary);
    line-height: 1.4;
    -webkit-font-smoothing: antialiased;
}

.hidden {
    display: none !important;
}

/* App Layout */
#app {
    height: 100%;
    position: relative;
}

/* Map */
#map {
    position: absolute;
    inset: 0;
    z-index: 1;
}

.mapboxgl-canvas {
    outline: none;
}

/* Top Bar */
.top-bar {
    position: absolute;
    top: calc(12px + var(--safe-top));
    left: 12px;
    right: 12px;
    z-index: 100;
    display: flex;
    gap: 8px;
    align-items: flex-start;
}

/* Search */
.search-container {
    flex: 1;
    min-width: 0;
}

/* Language Toggle */
.lang-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 50px;
    height: 50px;
    background: var(--bg-glass);
    backdrop-filter: blur(var(--blur));
    -webkit-backdrop-filter: blur(var(--blur));
    border-radius: var(--radius-lg);
    border: 1px solid var(--separator);
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.3);
    cursor: pointer;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.lang-toggle:hover {
    background: var(--bg-solid);
    border-color: var(--accent);
}

.lang-toggle:active {
    transform: scale(0.95);
}

.lang-flag {
    font-size: 18px;
    line-height: 1;
}

.lang-code {
    font-size: 12px;
    font-weight: 700;
    color: var(--text-secondary);
    letter-spacing: 0.02em;
}

.search-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0 16px;
    height: 50px;
    background: var(--bg-glass);
    backdrop-filter: blur(var(--blur));
    -webkit-backdrop-filter: blur(var(--blur));
    border-radius: var(--radius-lg);
    border: 1px solid var(--separator);
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.3);
    transition: all 0.2s ease;
}

.search-bar:focus-within {
    background: var(--bg-solid);
    border-color: var(--accent);
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.4), 0 0 0 1px var(--accent);
}

.search-icon {
    color: var(--text-secondary);
    flex-shrink: 0;
}

.search-bar input {
    flex: 1;
    background: none;
    border: none;
    outline: none;
    font-size: 17px;
    font-weight: 400;
    color: var(--text-primary);
    min-width: 0;
}

.search-bar input::placeholder {
    color: var(--text-tertiary);
}

.search-clear {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    background: none;
    border: none;
    cursor: pointer;
    opacity: 0.7;
    transition: opacity 0.15s;
}

.search-clear:hover {
    opacity: 1;
}

.search-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
}

.search-spinner {
    width: 16px;
    height: 16px;
    border: 2px solid var(--separator);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

.search-results {
    margin-top: 8px;
    background: var(--bg-solid);
    border-radius: var(--radius-md);
    border: 1px solid var(--separator);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    overflow: hidden;
    max-height: 280px;
    overflow-y: auto;
}

.search-result {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    cursor: pointer;
    transition: background 0.15s;
    border-bottom: 1px solid var(--separator);
}

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

.search-result:hover, .search-result:focus {
    background: var(--bg-elevated);
}

.search-result-icon {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-tertiary);
    border-radius: 8px;
    color: var(--text-secondary);
    flex-shrink: 0;
}

.search-result-text {
    flex: 1;
    min-width: 0;
}

.search-result-name {
    font-size: 16px;
    font-weight: 500;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.search-result-detail {
    font-size: 13px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Info Panel */
.info-panel {
    position: absolute;
    bottom: calc(var(--toolbar-height) + 12px + var(--safe-bottom));
    left: 50%;
    transform: translateX(-50%);
    z-index: 50;
    padding: 6px 12px;
    background: transparent;
    font-size: 13px;
    font-weight: 400;
    color: var(--text-secondary);
    white-space: nowrap;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.8);
}

.info-panel.has-area {
    padding: 10px 20px;
    background: var(--bg-glass);
    backdrop-filter: blur(var(--blur));
    -webkit-backdrop-filter: blur(var(--blur));
    border-radius: var(--radius-xl);
    border: 1px solid var(--separator);
    font-size: 15px;
    font-weight: 500;
    color: var(--text-primary);
    text-shadow: none;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
}

.info-panel .area-value {
    color: var(--accent);
    font-weight: 600;
}

/* Toolbar */
.toolbar {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 100;
    display: flex;
    justify-content: space-around;
    align-items: flex-start;
    height: var(--toolbar-height);
    padding: 8px 8px calc(8px + var(--safe-bottom));
    background: var(--bg-glass);
    backdrop-filter: blur(var(--blur));
    -webkit-backdrop-filter: blur(var(--blur));
    border-top: 1px solid var(--separator);
}

.toolbar-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    min-width: 70px;
    padding: 8px 12px;
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 10px;
    font-weight: 500;
    letter-spacing: 0.02em;
    cursor: pointer;
    border-radius: var(--radius-md);
    transition: all 0.2s ease;
}

.toolbar-btn svg {
    width: 26px;
    height: 26px;
}

.toolbar-btn:hover {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.05);
}

.toolbar-btn:active {
    transform: scale(0.95);
}

.toolbar-btn.active {
    color: var(--accent);
}

/* Modals */
.modal {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    padding: 12px;
    padding-bottom: calc(12px + var(--safe-bottom));
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    animation: fadeIn 0.25s ease;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.modal-content {
    position: relative;
    width: 100%;
    max-width: 420px;
    max-height: 85vh;
    background: var(--bg-solid);
    border-radius: var(--radius-xl);
    box-shadow: 0 25px 50px rgba(0, 0, 0, 0.5);
    overflow: hidden;
    animation: slideUp 0.35s cubic-bezier(0.32, 0.72, 0, 1);
}

.modal-compact {
    max-height: auto;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(40px) scale(0.96);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 20px 16px;
}

.modal-header h2 {
    font-size: 22px;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.modal-close {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    background: none;
    border: none;
    cursor: pointer;
    border-radius: 50%;
    transition: transform 0.15s;
}

.modal-close:hover {
    transform: scale(1.1);
}

.modal-close:active {
    transform: scale(0.9);
}

.modal-body {
    padding: 0 20px 24px;
}

/* Help Items */
.help-item {
    display: flex;
    align-items: flex-start;
    gap: 14px;
    padding: 14px 0;
    border-bottom: 1px solid var(--separator);
}

.help-item:last-child {
    border-bottom: none;
}

.help-icon {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-tertiary);
    border-radius: 10px;
    color: var(--accent);
    flex-shrink: 0;
}

.help-step {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--accent);
    border-radius: 50%;
    color: #fff;
    font-size: 16px;
    font-weight: 700;
    flex-shrink: 0;
}

.help-item h3 {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 2px;
}

.help-item p {
    font-size: 14px;
    color: var(--text-secondary);
    line-height: 1.4;
}

.help-item p strong {
    color: var(--text-primary);
    font-weight: 600;
}

.help-note {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    margin-top: 16px;
    padding: 12px 14px;
    background: var(--bg-tertiary);
    border-radius: var(--radius-sm);
}

.help-note svg {
    flex-shrink: 0;
    color: var(--text-tertiary);
    margin-top: 1px;
}

.help-note p {
    font-size: 13px;
    color: var(--text-secondary);
    line-height: 1.4;
    margin: 0;
}

.help-note p strong {
    color: var(--text-primary);
}

.permission-intro {
    font-size: 15px;
    color: var(--text-secondary);
    margin-bottom: 16px;
    line-height: 1.5;
}

/* Toast */
.toast {
    position: fixed;
    bottom: calc(var(--toolbar-height) + 70px + var(--safe-bottom));
    left: 50%;
    transform: translateX(-50%);
    z-index: 1100;
    padding: 14px 24px;
    background: var(--bg-solid);
    border-radius: var(--radius-xl);
    border: 1px solid var(--separator);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    font-size: 15px;
    font-weight: 500;
    color: var(--text-primary);
    animation: toastIn 0.3s cubic-bezier(0.32, 0.72, 0, 1);
}

.toast.success {
    background: var(--success);
    border-color: var(--success);
    color: #000;
}

.toast.error {
    background: var(--danger);
    border-color: var(--danger);
}

@keyframes toastIn {
    from {
        opacity: 0;
        transform: translateX(-50%) translateY(16px) scale(0.9);
    }
    to {
        opacity: 1;
        transform: translateX(-50%) translateY(0) scale(1);
    }
}

/* Location Marker */
.location-marker {
    width: 22px;
    height: 22px;
    background: var(--accent);
    border: 3px solid #fff;
    border-radius: 50%;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(10, 132, 255, 0.5); }
    50% { box-shadow: 0 0 0 12px rgba(10, 132, 255, 0); }
}

/* Mapbox Overrides */
.mapboxgl-ctrl-group {
    background: var(--bg-glass) !important;
    backdrop-filter: blur(var(--blur)) !important;
    -webkit-backdrop-filter: blur(var(--blur)) !important;
    border: 1px solid var(--separator) !important;
    border-radius: var(--radius-md) !important;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2) !important;
    overflow: hidden !important;
}

.mapboxgl-ctrl-group button {
    width: 44px !important;
    height: 44px !important;
    background: transparent !important;
}

.mapboxgl-ctrl-group button + button {
    border-top: 1px solid var(--separator) !important;
}

.mapboxgl-ctrl-group button:hover {
    background: rgba(255, 255, 255, 0.1) !important;
}

.mapboxgl-ctrl-zoom-in .mapboxgl-ctrl-icon,
.mapboxgl-ctrl-zoom-out .mapboxgl-ctrl-icon,
.mapboxgl-ctrl-compass .mapboxgl-ctrl-icon {
    filter: invert(1);
}

.mapboxgl-ctrl-attrib {
    background: var(--bg-glass) !important;
    backdrop-filter: blur(10px) !important;
    -webkit-backdrop-filter: blur(10px) !important;
    border-radius: 8px !important;
    padding: 4px 8px !important;
    font-size: 10px !important;
    color: var(--text-tertiary) !important;
}

.mapboxgl-ctrl-attrib a {
    color: var(--text-tertiary) !important;
}

.mapboxgl-ctrl-bottom-right {
    right: 12px !important;
    bottom: calc(var(--toolbar-height) + 16px + var(--safe-bottom)) !important;
}

.mapboxgl-ctrl-bottom-left {
    left: 12px !important;
    bottom: calc(var(--toolbar-height) + 16px + var(--safe-bottom)) !important;
}

/* Copy Success Modal */
.copy-success-content {
    text-align: center;
    padding: 40px 30px;
}

.copy-success-icon {
    margin-bottom: 20px;
    animation: checkmarkPop 0.4s cubic-bezier(0.32, 0.72, 0, 1);
}

@keyframes checkmarkPop {
    0% { transform: scale(0); opacity: 0; }
    50% { transform: scale(1.2); }
    100% { transform: scale(1); opacity: 1; }
}

.copy-success-content h2 {
    font-size: 24px;
    font-weight: 700;
    letter-spacing: -0.02em;
    margin-bottom: 12px;
    color: var(--success);
}

.copy-success-message {
    font-size: 15px;
    color: var(--text-secondary);
    line-height: 1.5;
    margin-bottom: 20px;
}

.copy-countdown {
    font-size: 14px;
    color: var(--text-tertiary);
    margin-bottom: 24px;
}

.copy-countdown span {
    font-weight: 700;
    color: var(--accent);
    font-size: 16px;
}

.back-to-form-btn {
    display: inline-block;
    padding: 14px 32px;
    background: var(--accent);
    color: #fff;
    font-size: 16px;
    font-weight: 600;
    border: none;
    border-radius: var(--radius-lg);
    cursor: pointer;
    transition: all 0.2s ease;
}

.back-to-form-btn:hover {
    background: var(--accent-hover);
    transform: translateY(-1px);
}

.back-to-form-btn:active {
    transform: scale(0.98);
}

/* Desktop */
@media (min-width: 768px) {
    .top-bar {
        left: 50%;
        right: auto;
        transform: translateX(-50%);
        max-width: 460px;
    }

    .toolbar {
        left: 50%;
        right: auto;
        transform: translateX(-50%);
        width: auto;
        min-width: 380px;
        border-radius: var(--radius-xl) var(--radius-xl) 0 0;
        padding: 10px 16px calc(10px + var(--safe-bottom));
    }

    .toolbar-btn {
        flex-direction: row;
        gap: 8px;
        min-width: auto;
        padding: 10px 16px;
        font-size: 13px;
    }

    .toolbar-btn svg {
        width: 22px;
        height: 22px;
    }

    .modal {
        align-items: center;
    }

    .fab-container {
        right: 20px;
    }
}

/* Reduce Motion */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
    }
}
