/*!
 * Copyright (c) 2025 Blaž Čadež
 * All rights reserved.
 *
 * PROHIBITION OF USE: This source code is proprietary and confidential.
 * Unauthorized copying, modification, distribution, or use of this code,
 * in whole or in part, is strictly prohibited without prior written
 * permission from the copyright holder.
 */

/* ── Lab2Dirt GCP Tagger — palette and chrome shared with TrailBuilder ── */

:root {
    --color-light-brown: #e2d5c0;
    --color-dark-brown: #d3c7b5;
    --color-tan: #c0b6a7;
    --color-dark-gray: #7f5844;
    --color-light-gray-border: #6a645c;
    --color-text-light: #dedede;
    --color-text-cream: #c1afa4;
    --color-brown-dark: #443b31;
    --color-brown-dark-alt: #2b251f;
    --color-brown-medium: rgb(127, 89, 68);
    --color-button-hover: #d9c9b8;
    --color-button-active: #c7b5a0;
    --color-dark-shadow: rgba(0, 0, 0, 0.3);
    --color-shadow-medium: rgba(0, 0, 0, 0.2);
    --color-success-green: #28a745;
    --color-danger-red: #dc3545;
    --color-warning-orange: #FF6B35;
    --header-height: 50px;
    --radius: 8px;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    height: 100%;
    width: 100%;
    overflow: hidden;
    position: fixed;
}

body {
    font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
                 Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
    background-color: var(--color-brown-dark);
    color: var(--color-text-light);
    display: flex;
    flex-direction: column;
    line-height: 1.45;
}

/* ── Header bar ── */

#app-header {
    background-color: var(--color-brown-dark-alt);
    width: 100%;
    height: var(--header-height);
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0 10px;
    flex-shrink: 0;
    z-index: 1000;
}
#app-header .header-logo {
    height: 30px;
    width: auto;
    opacity: 0.95;
}
#app-header h1 {
    font-size: 1rem;
    font-weight: 600;
    margin: 0;
    color: var(--color-light-brown);
    letter-spacing: 0.02em;
    white-space: nowrap;
}
#app-header .header-sub {
    font-size: 0.75rem;
    color: var(--color-text-cream);
    opacity: 0.75;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
#app-header .header-spacer { flex: 1 1 auto; }
#app-header .header-status {
    font-size: 0.72rem;
    color: var(--color-text-cream);
    white-space: nowrap;
}

/* ── Buttons (TrailBuilder pill style) ── */

button, .btn {
    border-radius: 40px;
    color: var(--color-dark-gray);
    background-color: var(--color-light-brown);
    border: 1px solid var(--color-dark-gray);
    box-shadow: 0 1px 2px var(--color-dark-shadow);
    min-height: 30px;
    padding: 0.25rem 0.9rem;
    font-size: 0.85rem;
    font-family: inherit;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.3rem;
    white-space: nowrap;
    transition: background-color 0.15s, box-shadow 0.15s, transform 0.1s;
}
button:hover:not(:disabled), .btn:hover {
    background-color: var(--color-button-hover);
    box-shadow: 0 4px 8px var(--color-shadow-medium);
    transform: translateY(-1px);
}
button:active:not(:disabled), .btn:active {
    background-color: var(--color-button-active);
    transform: translateY(0);
}
button:disabled, .btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
    box-shadow: none;
}
.btn-sm { padding: 0.15rem 0.7rem; min-height: 26px; font-size: 0.8rem; }
.btn-secondary {
    background-color: var(--color-brown-dark-alt);
    color: var(--color-light-brown);
    border-color: var(--color-light-gray-border);
}
.btn-secondary:hover {
    background-color: var(--color-brown-medium);
    color: var(--color-light-brown);
}
.btn-primary {
    background-color: var(--color-brown-medium);
    color: #fff8f0;
    border-color: var(--color-light-brown);
    font-weight: 600;
}
.btn-primary:hover { background-color: #96684f; color: #fff8f0; }
.btn-danger { background-color: var(--color-light-brown); color: #8b2a33; border-color: #8b2a33; }
.btn-danger:hover { background-color: #f0c8c8; color: #8b2a33; }
.btn.active { outline: 2px solid var(--color-light-brown); }

/* ── Cards / panels ── */

.card {
    background: var(--color-brown-dark-alt);
    border: 1px solid var(--color-light-gray-border);
    border-radius: var(--radius);
    padding: 0.8rem 1rem;
}
.card h2 {
    font-size: 0.95rem;
    font-weight: 600;
    margin: 0 0 0.6rem 0;
    color: var(--color-light-brown);
}
.hint {
    display: block;
    color: var(--color-text-cream);
    font-size: 0.78rem;
    margin: 0;
}
code {
    background: rgba(0, 0, 0, 0.3);
    padding: 0 0.25rem;
    border-radius: 3px;
    font-size: 0.9em;
}
summary { cursor: pointer; user-select: none; }

/* ── Inputs ── */

input[type="text"],
input[type="number"],
select {
    padding: 0.3rem 0.5rem;
    background: var(--color-brown-dark);
    border: 1px solid var(--color-light-gray-border);
    border-radius: 6px;
    color: var(--color-text-light);
    font-size: 0.85rem;
    font-family: inherit;
    min-height: 30px;
}
input:focus, select:focus {
    outline: none;
    border-color: var(--color-light-brown);
}
label.btn { position: relative; overflow: hidden; }

/* ── Page layout ── */

main {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
    width: 100%;
    padding: 0.5rem 0.7rem 0.6rem;
    gap: 0.5rem;
    overflow: hidden;
}
main > details.card { flex: 0 0 auto; padding: 0.4rem 0.8rem; }
main > details.card summary { font-weight: 600; font-size: 0.85rem; color: var(--color-light-brown); }
main > details.card p.hint { margin-top: 0.4rem; }

.tagger-layout { flex: 1 1 auto; min-height: 0; display: flex; gap: 0.6rem; }
.tagger-layout > .card { display: flex; flex-direction: column; min-height: 0; overflow: hidden; }
.tagger-layout > .card:first-child { flex: 0 0 330px; }
.tagger-layout > .card:last-child { flex: 1 1 auto; min-width: 0; }
.tagger-layout > .card > h2,
.tagger-layout > .card > .tagger-toolbar { flex: 0 0 auto; }

.pts-header { display: flex; align-items: center; gap: 0.4rem; cursor: pointer; user-select: none; }
.pts-header .pts-toggle { font-size: 0.7em; opacity: 0.6; transition: transform 0.15s; }
.pts-header.collapsed .pts-toggle { transform: rotate(-90deg); }
.gcp-list.collapsed { display: none; }

.gcp-list { flex: 1 1 auto; min-height: 60px; overflow-y: auto; }
.gcp-row { display: flex; align-items: center; gap: 0.5rem; padding: 0.3rem 0.45rem;
           border-radius: 6px; cursor: pointer; font-size: 0.85rem; }
.gcp-row:hover { background: rgba(226, 213, 192, 0.12); }
.gcp-row.active { background: rgba(220, 60, 60, 0.2); outline: 1px solid rgba(220, 60, 60, 0.5); }
.gcp-row .coords { opacity: 0.7; font-size: 0.72rem; font-family: ui-monospace, monospace; }
.gcp-row .prow-del { margin-left: 0.2rem; opacity: 0; font-size: 0.85rem; color: var(--color-text-cream); }
.gcp-row:hover .prow-del { opacity: 0.8; }
.tag-count { margin-left: auto; font-weight: 700; padding: 0.05rem 0.5rem; border-radius: 10px;
             font-size: 0.78rem; color: #fff; }
.tag-count.bad { background: #c33; }
.tag-count.mid { background: #d90; }
.tag-count.good { background: #2a8; }

.manual-add input { width: 100%; margin-bottom: 0.3rem; }

/* ── Photo panel ── */

.tagger-toolbar { display: flex; gap: 0.4rem; align-items: center; flex-wrap: wrap; margin-bottom: 0.5rem; }
.crs-input { width: 260px; }

.thumb-strip { display: flex; gap: 0.4rem; overflow-x: auto; padding: 0.4rem 0; flex: 0 0 auto; }
.thumb { position: relative; flex: 0 0 auto; width: 92px; height: 62px; border-radius: 6px;
         overflow: hidden; cursor: pointer; border: 2px solid transparent; }
.thumb.active { border-color: #d33; }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb .badge { position: absolute; right: 2px; top: 2px; background: rgba(40, 160, 90, 0.95);
                color: #fff; border-radius: 8px; font-size: 0.7rem; padding: 0 0.35rem; }
.thumb .fname { position: absolute; left: 0; right: 0; bottom: 0; font-size: 0.6rem;
                background: rgba(0, 0, 0, 0.55); color: #eee; padding: 0 2px;
                white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.thumb.sees-pt:not(.active) { border-color: rgba(255, 153, 0, 0.85); }
.thumb.sees-pt::after { content: '◎'; position: absolute; left: 3px; top: -1px; color: #fb0;
                        font-size: 0.8rem; text-shadow: 0 0 3px #000; }

.tag-stage { flex: 1 1 auto; min-height: 0; display: flex; }
.split-divider { display: none; flex: 0 0 8px; margin: 0 3px; border-radius: 4px;
                 cursor: col-resize; background: rgba(226, 213, 192, 0.25); }
.split-divider:hover { background: rgba(226, 213, 192, 0.5); }
.tag-stage.split .split-divider { display: block; }
.tag-viewport { position: relative; flex: 1 1 0; min-width: 0; min-height: 200px; overflow: hidden;
                background: #111; border-radius: 8px; cursor: crosshair; user-select: none; }
.tag-canvas { position: absolute; transform-origin: 0 0; }
.tag-canvas img { display: block; pointer-events: none; -webkit-user-drag: none; }
.tag-marker { position: absolute; width: 22px; height: 22px; margin: -11px 0 0 -11px;
              pointer-events: auto; cursor: move; }
.tag-marker::before, .tag-marker::after { content: ''; position: absolute; background: #f33; }
.tag-marker::before { left: 10px; top: 0; width: 2px; height: 22px; }
.tag-marker::after { top: 10px; left: 0; height: 2px; width: 22px; }
.tag-marker .mlabel { position: absolute; left: 14px; top: -14px; background: rgba(220, 40, 40, 0.9);
                      color: #fff; font-size: 11px; padding: 0 4px; border-radius: 6px; white-space: nowrap; }
.tag-marker .mdel { position: absolute; left: 12px; bottom: -14px; width: 15px; height: 15px;
                    background: rgba(30, 30, 30, 0.85); color: #fff; border-radius: 50%; font-size: 11px;
                    line-height: 15px; text-align: center; opacity: 0; transition: opacity 0.1s; }
.tag-marker:hover .mdel { opacity: 1; }
.tag-marker:hover::before, .tag-marker:hover::after { background: #ff6; }
.tag-marker.dragging::before, .tag-marker.dragging::after { background: #6f6; }

.tag-marker.predicted { pointer-events: none; width: 26px; height: 26px; margin: -13px 0 0 -13px; }
.tag-marker.predicted::before, .tag-marker.predicted::after { background: #f90; }
.tag-marker.predicted::before { left: 12px; top: 3px; width: 2px; height: 20px; }
.tag-marker.predicted::after { top: 12px; left: 3px; height: 2px; width: 20px; }
.tag-marker.predicted .mlabel { background: rgba(230, 140, 0, 0.9); top: -12px; }
.tag-marker.predicted.other { opacity: 0.5; }
.tag-marker.predicted.other::before, .tag-marker.predicted.other::after { background: #cc850a; }
.tag-marker.predicted.low-confidence .mlabel::after { content: ' ?'; }
.tag-marker.predicted.snapped::before, .tag-marker.predicted.snapped::after { background: #4d4; }
.tag-marker.predicted.snapped .mlabel { background: rgba(40, 160, 60, 0.92); }
.tag-marker.predicted.clickable { pointer-events: auto; cursor: pointer; }
.pred-radius { position: absolute; box-sizing: border-box; border-radius: 50%;
               border: 1px dashed rgba(255, 153, 0, 0.55); pointer-events: none; }
.viewport-hint { position: absolute; left: 8px; bottom: 8px; z-index: 5; font-size: 0.75rem;
                 background: rgba(0, 0, 0, 0.6); color: #ddd; padding: 2px 8px; border-radius: 6px;
                 max-width: calc(100% - 16px); }

/* ── Map view (photo positions + GCPs) ── */

.tag-map { display: none; flex: 1 1 0; min-width: 0; min-height: 200px; border-radius: 8px;
           overflow: hidden; background: #222; }
.cam-wrap { position: relative; width: 14px; height: 14px; }
.cam-dot { position: absolute; inset: 1px; border-radius: 50%; background: #2b7cd3;
           border: 2px solid #fff; box-sizing: border-box; box-shadow: 0 0 4px rgba(0, 0, 0, 0.6); }
.cam-hdg { position: absolute; left: 6px; top: -7px; width: 2px; height: 14px;
           background: #2b7cd3; transform-origin: 1px 14px; box-shadow: 0 0 2px rgba(0, 0, 0, 0.5); }
.cam-wrap.tagged .cam-dot, .cam-wrap.tagged .cam-hdg { background: #2a8; }
.cam-wrap.sees .cam-dot, .cam-wrap.sees .cam-hdg { background: #f90; }
.cam-wrap.active .cam-dot, .cam-wrap.active .cam-hdg { background: #d33; }
.gcp-spot { position: absolute; left: -5px; top: -5px; width: 10px; height: 10px;
            border-radius: 50%; border: 2px solid #fff; box-sizing: border-box;
            box-shadow: 0 0 4px rgba(0, 0, 0, 0.6); }
.gcp-pin { position: absolute; left: 7px; top: -24px; padding: 0 6px; border-radius: 8px;
           color: #fff; font-size: 11px; font-weight: 700; white-space: nowrap;
           box-shadow: 0 1px 3px rgba(0, 0, 0, 0.5); }
.gcp-spot.bad, .gcp-pin.bad { background: #c33; }
.gcp-spot.mid, .gcp-pin.mid { background: #d90; }
.gcp-spot.good, .gcp-pin.good { background: #2a8; }
.gcp-spot.active, .gcp-pin.active { outline: 2px solid #fff; }
.leaflet-container { background: #222; }

/* ── Install / update prompts ── */

#install-btn { display: none; }
#update-toast {
    position: fixed; right: 12px; bottom: 12px; z-index: 4000; display: none;
    align-items: center; gap: 0.6rem; padding: 0.5rem 0.8rem;
    background: var(--color-brown-dark-alt); color: var(--color-light-brown);
    border: 1px solid var(--color-light-brown); border-radius: 10px;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.5); font-size: 0.82rem;
}

/* ── Narrow screens / phones ── */

@media (max-width: 900px) {
    html, body { position: static; height: auto; overflow: auto; }
    body { min-height: 100%; }
    main { overflow: visible; }
    #app-header .header-sub { display: none; }
    .tagger-layout { flex-direction: column; }
    .tagger-layout > .card:first-child { flex: 0 0 auto; }
    .tagger-layout > .card:last-child { flex: 0 0 auto; }
    .gcp-list { max-height: 240px; }
    .tag-viewport { height: 55vh; }
    .tag-stage { flex-direction: column; }
    .tag-stage.split .tag-viewport, .tag-stage.split .tag-map { height: 42vh; }
    .split-divider { cursor: row-resize; margin: 3px 0; }
    .crs-input { width: 100%; }
}
