@import url('https://fonts.googleapis.com/css2?family=Manrope:wght@400;500;600;700;800&family=JetBrains+Mono:wght@400;500;600&display=swap');

:root {
    --bg: #12141a;
    --bg-elevated: #191c24;
    --card: #191c24;
    --card-hover: #21252f;
    --card-dim: #15171d;
    --border: #2a2f3b;
    --text: #eef0f4;
    --text-dim: #9099ab;
    --text-faint: #5c6478;

    --ok: #5eead4;
    --ok-bg: #2a5a52;
    --warn: #f4c15c;
    --warn-bg: #4a3b1e;
    --critical: #f4736b;
    --critical-bg: #4a2321;

    --accent: #5eead4;
    --accent-bg: #2a5a52;

    --radius-lg: 18px;
    --radius-md: 14px;
    --radius-sm: 10px;

    --font-body: 'Manrope', system-ui, sans-serif;
    --font-mono: 'JetBrains Mono', 'Consolas', monospace;
}

* { box-sizing: border-box; }

html, body {
    height: 100%;
    margin: 0;
}

body {
    background: var(--bg);
    color: var(--text);
    font-family: var(--font-body);
    font-size: 14px;
    overflow: hidden;
}

.app {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

/* ---------- Topbar ---------- */

.topbar {
    display: flex;
    align-items: center;
    gap: 20px;
    padding: 12px 20px;
    background: var(--bg-elevated);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.brand {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 800;
    font-size: 16px;
}

.brand-icon {
    color: var(--accent);
}

.mode-toggle {
    display: flex;
    background: var(--card-dim);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 3px;
    gap: 2px;
}

.mode-btn {
    border: none;
    background: transparent;
    color: var(--text-dim);
    font-family: var(--font-body);
    font-weight: 600;
    font-size: 13px;
    padding: 7px 16px;
    border-radius: 999px;
    cursor: pointer;
    transition: background .15s, color .15s;
}

.mode-btn:hover { color: var(--text); }

.mode-btn.active {
    background: var(--accent);
    color: #0b1210;
}

.topbar-actions {
    margin-left: auto;
}

/* ---------- Buttons ---------- */

.btn {
    font-family: var(--font-body);
    font-weight: 600;
    font-size: 13px;
    border-radius: 999px;
    border: 1px solid transparent;
    padding: 9px 18px;
    cursor: pointer;
    transition: background .15s, border-color .15s, opacity .15s;
    white-space: nowrap;
}

.btn:disabled {
    opacity: .4;
    cursor: not-allowed;
}

.btn-primary {
    background: var(--accent);
    color: #0b1210;
}
.btn-primary:hover:not(:disabled) { filter: brightness(1.08); }

.btn-secondary {
    background: var(--bg-elevated);
    border-color: var(--border);
    color: var(--text);
}
.btn-secondary:hover:not(:disabled) { background: var(--card-hover); }

.btn-icon {
    padding: 9px 12px;
}

.btn-tool {
    background: var(--card-dim);
    border-color: var(--border);
    color: var(--text);
    width: 100%;
    text-align: left;
    display: flex;
    align-items: center;
    gap: 8px;
    border-radius: var(--radius-sm);
    padding: 10px 14px;
}
.btn-tool:hover:not(:disabled) { background: var(--card-hover); }
.btn-tool.active {
    background: var(--accent-bg);
    border-color: var(--accent);
    color: var(--accent);
}

.btn-danger-text {
    color: var(--critical);
}

.tool-icon {
    display: inline-block;
    width: 18px;
    text-align: center;
}

/* ---------- Layout ---------- */

.layout {
    flex: 1;
    display: flex;
    gap: 16px;
    padding: 16px;
    min-height: 0;
}

.card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
}

.sidebar {
    width: 300px;
    flex-shrink: 0;
    padding: 18px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 22px;
}

.tool-section h3 {
    margin: 0 0 10px;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--text-faint);
    font-weight: 700;
}

.tool-buttons {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.hint {
    color: var(--text-faint);
    font-size: 12px;
    margin: 8px 0 0;
    line-height: 1.5;
}

.canvas-area {
    flex: 1;
    min-width: 0;
    position: relative;
    overflow: hidden;
}

/* ---------- Color swatches ---------- */

.color-row {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.swatch {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    border: 2px solid transparent;
    cursor: pointer;
    padding: 0;
}

.swatch.active {
    border-color: var(--text);
    box-shadow: 0 0 0 2px var(--bg);
}

#customColor {
    width: 26px;
    height: 26px;
    padding: 0;
    border: none;
    border-radius: 50%;
    overflow: hidden;
    background: none;
    cursor: pointer;
}
#customColor::-webkit-color-swatch-wrapper { padding: 0; }
#customColor::-webkit-color-swatch { border: 2px solid var(--border); border-radius: 50%; }

/* ---------- Address search ---------- */

.search-row {
    display: flex;
    gap: 6px;
}

.search-row input {
    flex: 1;
    min-width: 0;
    background: var(--card-dim);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-family: var(--font-body);
    font-size: 13px;
    padding: 9px 12px;
}
.search-row input:focus {
    outline: none;
    border-color: var(--accent);
}

.address-results {
    margin-top: 6px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.address-result-item {
    background: var(--card-dim);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 8px 10px;
    font-size: 12px;
    color: var(--text-dim);
    cursor: pointer;
}
.address-result-item:hover {
    background: var(--card-hover);
    color: var(--text);
}

/* ---------- Upload drop ---------- */

.upload-drop {
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px dashed var(--border);
    border-radius: var(--radius-md);
    padding: 20px 12px;
    color: var(--text-dim);
    font-size: 13px;
    cursor: pointer;
    text-align: center;
    background: var(--card-dim);
}
.upload-drop:hover {
    background: var(--card-hover);
    border-color: var(--accent);
    color: var(--text);
}
.upload-drop input { display: none; }

/* ---------- Elements list ---------- */

.elements-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
    max-height: 260px;
    overflow-y: auto;
}

.empty-hint {
    color: var(--text-faint);
    font-size: 12px;
}

.element-item {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--card-dim);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 7px 10px;
    font-size: 12px;
}

.element-color-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    flex-shrink: 0;
}

.element-label {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--text-dim);
}

.element-delete {
    background: none;
    border: none;
    color: var(--text-faint);
    cursor: pointer;
    font-size: 13px;
    padding: 2px 4px;
    line-height: 1;
}
.element-delete:hover { color: var(--critical); }

/* ---------- Map / Image containers ---------- */

.map-container, .image-container {
    width: 100%;
    height: 100%;
    position: relative;
}

.map-container {
    border-radius: var(--radius-lg);
    overflow: hidden;
}

.image-container {
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: auto;
    background: var(--card-dim);
}

.image-empty {
    text-align: center;
    color: var(--text-faint);
}
.image-empty-icon {
    font-size: 40px;
    display: block;
    margin-bottom: 10px;
}

.image-stage {
    position: relative;
    display: inline-block;
    margin: auto;
}

.image-stage img {
    display: block;
    max-width: 100%;
    height: auto;
}

.image-stage canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    cursor: crosshair;
}

/* ---------- Leaflet marker overrides ---------- */

.note-marker {
    display: flex;
    align-items: center;
    gap: 6px;
    transform: translate(-6px, -6px);
}
.note-dot {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    border: 2px solid var(--bg);
    box-shadow: 0 1px 3px rgba(0,0,0,.5);
}
.note-label {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    color: var(--text);
    font-size: 11px;
    font-weight: 600;
    padding: 3px 8px;
    border-radius: 999px;
    white-space: nowrap;
    box-shadow: 0 1px 4px rgba(0,0,0,.4);
    max-width: 180px;
    overflow: hidden;
    text-overflow: ellipsis;
}

.endpoint-marker {
    width: 26px;
    height: 26px;
    border-radius: 50% 50% 50% 0;
    transform: rotate(-45deg) translate(-8px, -8px);
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 1px 4px rgba(0,0,0,.5);
    border: 2px solid var(--bg);
}
.endpoint-marker span {
    transform: rotate(45deg);
    font-size: 13px;
    font-weight: 800;
    color: #0b1210;
}
.endpoint-start { background: var(--ok); }
.endpoint-end { background: var(--critical); }

.leaflet-container {
    background: var(--card-dim);
    font-family: var(--font-body);
}

/* ---------- Note editor overlay ---------- */

.note-editor-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.5);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}
.note-editor-overlay.visible {
    display: flex;
}

.note-editor {
    width: 320px;
    padding: 20px;
}
.note-editor h3 {
    margin: 0 0 12px;
    font-size: 14px;
}
.note-editor textarea {
    width: 100%;
    background: var(--card-dim);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-family: var(--font-body);
    font-size: 13px;
    padding: 10px;
    resize: vertical;
}
.note-editor textarea:focus {
    outline: none;
    border-color: var(--accent);
}
.note-editor-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 14px;
}

/* ---------- Toast ---------- */

.toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 10px 18px;
    border-radius: 999px;
    font-size: 13px;
    opacity: 0;
    pointer-events: none;
    transition: opacity .2s, transform .2s;
    z-index: 2000;
}
.toast.visible {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* ---------- Responsive ---------- */

@media (max-width: 860px) {
    .layout {
        flex-direction: column;
    }
    .sidebar {
        width: 100%;
        max-height: 45vh;
    }
    .topbar {
        flex-wrap: wrap;
        gap: 10px;
    }
    .topbar-actions {
        margin-left: 0;
        width: 100%;
    }
    .topbar-actions .btn {
        width: 100%;
    }
}
