/* ═══════════════════════════════════════════════════════
   LOCUS PLOTTER — Styles v3
   Multi-screen flow + Locus AR brand
   ═══════════════════════════════════════════════════════ */

:root {
    color-scheme: dark;
    --sidebar-w: 300px;

    --bg-dark:    #070a10;
    --bg-card:    rgba(10, 14, 26, 0.7);
    --bg-input:   rgba(16, 22, 40, 0.8);
    --bg-hover:   rgba(30, 40, 70, 0.7);
    --bg-glass:   rgba(8, 10, 18, 0.88);

    --accent:       #60a5fa;
    --accent-dim:   #3b82f6;
    --accent-glow:  rgba(96, 165, 250, 0.25);
    --danger:       #ef4444;
    --success:      #22c55e;

    --text:       #e9eefc;
    --text-dim:   rgba(233, 238, 252, 0.50);
    --text-label: rgba(233, 238, 252, 0.65);

    --border:     rgba(255, 255, 255, 0.14);
    --border-dim: rgba(255, 255, 255, 0.06);

    --radius: 12px;
    --radius-sm: 8px;
    --tr: .18s ease;
}

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

html, body {
    height: 100%;
    font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    font-size: 14px;
    color: var(--text);
    background: var(--bg-dark);
    overflow: hidden;
}

/* ─── SCREENS ─── */

#app { height: 100%; position: relative; }

.screen {
    position: absolute; inset: 0;
    display: none;
    flex-direction: column;
    background: var(--bg-dark);
    z-index: 1;
}
.screen.active { display: flex; z-index: 5; }

/* ─── TOP BAR ─── */

.top-bar {
    height: 52px;
    display: flex; align-items: center; gap: 12px;
    padding: 0 18px;
    border-bottom: 1px solid var(--border-dim);
    flex-shrink: 0;
}
.top-bar.compact { height: 46px; }
.top-bar h2 { font-size: 15px; font-weight: 700; letter-spacing: .2px; flex: 1; }
.top-bar-actions { display: flex; gap: 8px; }

.nav-back {
    width: 32px; height: 32px;
    display: flex; align-items: center; justify-content: center;
    border: 1px solid var(--border); border-radius: var(--radius-sm);
    background: transparent; color: var(--text-dim);
    font-size: 18px; cursor: pointer; transition: all var(--tr);
}
.nav-back:hover { color: var(--text); background: rgba(255,255,255,.05); }

/* ─── WELCOME SCREEN ─── */

.welcome {
    flex: 1;
    display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    padding: 40px 20px;
}

.welcome-title {
    font-size: 36px; font-weight: 800;
    letter-spacing: .5px;
    margin-bottom: 6px;
}
.welcome-sub {
    font-size: 14px; color: var(--text-dim);
    letter-spacing: .5px; text-transform: uppercase;
}

.welcome-choices {
    display: flex; gap: 20px;
    margin-top: 48px;
    flex-wrap: wrap;
    justify-content: center;
}

.choice-card {
    width: 260px; padding: 32px 24px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 16px;
    cursor: pointer; text-align: center;
    transition: all .24s ease;
    color: var(--text);
    display: flex; flex-direction: column; align-items: center; gap: 12px;
}
.choice-card:hover {
    border-color: rgba(96,165,250,.4);
    background: rgba(16,42,92,.35);
    transform: translateY(-4px);
    box-shadow: 0 12px 40px rgba(0,0,0,.4);
}

.choice-icon { color: var(--accent); margin-bottom: 4px; }
.choice-label { font-size: 16px; font-weight: 700; }
.choice-desc { font-size: 12px; color: var(--text-dim); line-height: 1.5; }

/* ─── QUICK QR SCREEN ─── */

.quick-body {
    flex: 1; display: flex;
    align-items: flex-start; justify-content: center;
    gap: 40px; padding: 32px;
    overflow-y: auto;
}
.quick-form { width: 320px; }
.quick-result {
    width: 320px;
    display: flex; flex-direction: column;
    align-items: center; gap: 16px;
}
.quick-result canvas {
    width: 260px; height: 260px;
    background: #fff; border-radius: var(--radius);
}
.q-payload {
    font-size: 11px; color: var(--text-dim);
    background: rgba(255,255,255,.04);
    border: 1px solid var(--border-dim);
    border-radius: var(--radius-sm);
    padding: 10px; width: 100%;
    font-family: ui-monospace, monospace;
    white-space: pre-wrap; word-break: break-all;
}

.toggle-label {
    display: flex; align-items: center; gap: 8px;
    font-size: 13px; cursor: pointer;
}
.toggle-label input[type="checkbox"] { accent-color: var(--accent); width: 16px; height: 16px; }

.field-note { display: block; font-size: 11px; color: var(--text-dim); margin-top: 3px; }
.field-warn { color: var(--danger); font-weight: 600; }
.field-ok { color: #4ade80; font-weight: 600; }
#ws-qr-status { margin-top: 8px; }

/* ─── VENUE SETUP ─── */

#screen-venue-setup.active {
    display: flex;
    flex-direction: column;
}

.setup-body {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    max-width: none;
    margin: 0;
    padding: 0;
    align-items: stretch;
    overflow: hidden;
}

.setup-top {
    flex-shrink: 0;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-dim);
}

.setup-panel { width: 100%; }

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

.setup-map-wrap {
    flex: 1;
    min-height: 280px;
    position: relative;
    background: #0a0e14;
}

#screen-venue-setup.upload-mode .setup-map-wrap,
#screen-venue-setup.upload-mode #sat-mini-map {
    display: none !important;
}

#screen-venue-setup.upload-mode.has-upload-image .calib-line-fields {
    margin-top: 6px;
    padding-bottom: 4px;
}

#screen-venue-setup.upload-mode.has-upload-image .setup-top {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    padding: 4px 10px 0;
    border-bottom: none;
}

#screen-venue-setup.upload-mode.has-upload-image #upload-setup {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

#screen-venue-setup.upload-mode.has-upload-image .upload-zone {
    display: none;
}

#screen-venue-setup.upload-mode.has-upload-image .upload-calibrate {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    margin-top: 0;
}

#screen-venue-setup.upload-mode.has-upload-image .calib-hint {
    margin: 2px 0 4px;
    flex-shrink: 0;
    line-height: 1.35;
}

#screen-venue-setup.upload-mode.has-upload-image .calib-stage {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    min-height: 0;
    height: auto;
    max-height: none;
    overflow: hidden;
}

#screen-venue-setup.upload-mode.has-upload-image .calib-toolbar {
    margin-bottom: 2px;
}

#screen-venue-setup.upload-mode.has-upload-image .calib-status {
    margin: 4px 0 2px;
}

#screen-venue-setup.upload-mode.has-upload-image .calib-line-fields {
    margin-top: 2px;
    flex-shrink: 0;
    position: relative;
    z-index: 2;
}

#screen-venue-setup.upload-mode.has-upload-image .calib-summary {
    margin: 4px 0 2px;
    padding: 8px 10px;
    flex-shrink: 0;
}

#screen-venue-setup.upload-mode.has-upload-image .setup-footer {
    padding: 4px 12px 10px;
}

#screen-venue-setup.upload-mode.has-upload-image .setup-footer .form-group {
    margin-bottom: 6px;
}

.calib-toolbar {
    flex-shrink: 0;
    margin-bottom: 4px;
}

.calib-field-row {
    align-items: flex-end;
    gap: 10px;
    flex-wrap: nowrap;
}
.calib-field-row .form-group {
    flex: 0 0 auto;
    min-width: 0;
    margin-bottom: 0;
}
.calib-field-row input[type="number"] {
    width: 6.5em;
    min-width: 6.5em;
    text-align: right;
}
.calib-field-row .btn {
    flex: 0 0 auto;
    width: auto;
    min-width: 0;
    margin-bottom: 0;
    padding-left: 14px;
    padding-right: 14px;
    white-space: nowrap;
}

.venue-map {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
}

.setup-footer {
    flex-shrink: 0;
    padding: 12px 16px 16px;
    border-top: 1px solid var(--border-dim);
    background: rgba(7, 10, 16, 0.95);
}

.setup-actions {
    display: flex;
    gap: 10px;
    align-items: center;
    margin-top: 4px;
}

.setup-actions .btn {
    margin-top: 0;
    width: auto;
    flex: 0 0 auto;
}

#calib-reset { display: none; }

#screen-venue-setup.upload-mode.has-upload-image .setup-actions {
    justify-content: space-between;
}

#screen-venue-setup.upload-mode.has-upload-image #calib-reset {
    display: inline-flex;
}

#screen-venue-setup:not(.has-upload-image) .setup-actions {
    justify-content: stretch;
}

#screen-venue-setup:not(.has-upload-image) #btn-venue-confirm {
    width: 100%;
}

.upload-zone {
    width: 100%; padding: 40px; text-align: center;
    border: 2px dashed var(--border);
    border-radius: var(--radius); cursor: pointer;
    transition: all var(--tr); color: var(--text-dim);
}
.upload-zone:hover { border-color: var(--accent); color: var(--text); }
.upload-zone.dragover { border-color: var(--accent); background: var(--accent-glow); }

.upload-preview { max-width: 100%; max-height: 200px; border-radius: var(--radius); margin-top: 10px; }

.upload-calibrate { margin-top: 10px; }

.calib-stage {
    position: relative;
    width: 100%;
    height: min(52vh, 520px);
    min-height: 180px;
    background: #0a0e14;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    cursor: crosshair;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
}

.calib-img {
    display: none;
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto;
    min-width: 0;
    min-height: 0;
    object-fit: contain;
    object-position: center center;
    user-select: none;
    -webkit-user-drag: none;
    flex-shrink: 1;
}

.calib-img.calib-img-ready {
    display: block;
}

.calib-overlay {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.calib-overlay circle { fill: #fbbf24; stroke: #fff; stroke-width: 2; }
.calib-overlay line { stroke: #22d3ee; stroke-width: 2.5; stroke-dasharray: 6 4; }

.calib-status {
    margin: 8px 0 4px;
    font-size: 13px;
    color: var(--accent);
    font-weight: 500;
    flex-shrink: 0;
}

.calib-line-fields { margin-top: 4px; flex-shrink: 0; }

.calib-summary {
    margin: 12px 0 10px;
    padding: 12px 14px;
    border-radius: var(--radius-sm);
    background: var(--accent-glow);
    border: 1px solid rgba(96, 165, 250, 0.35);
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
}

.calib-overlay .line1 { stroke: #fbbf24; }
.calib-overlay .line2 { stroke: #a78bfa; }
.calib-overlay .dot1 { fill: #fbbf24; }
.calib-overlay .dot2 { fill: #a78bfa; }

/* ─── FORMS (shared) ─── */

.form-group { margin-bottom: 10px; width: 100%; }
.form-group label {
    display: block; font-size: 10px; font-weight: 600;
    color: var(--text-label); margin-bottom: 4px;
    text-transform: uppercase; letter-spacing: .5px;
}

.form-row { display: flex; gap: 10px; }
.form-row .form-group { flex: 1; }

input[type="text"], input[type="number"] {
    width: 100%; padding: 8px 10px;
    background: var(--bg-input); border: 1px solid var(--border);
    border-radius: var(--radius-sm); color: var(--text); font-size: 13px;
    outline: none; transition: border-color var(--tr), box-shadow var(--tr);
}
input:focus { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-glow); }
input::placeholder { color: var(--text-dim); }

/* ─── BUTTONS ─── */

.btn {
    display: inline-flex; align-items: center; justify-content: center;
    padding: 9px 16px; border: 1px solid var(--border);
    border-radius: var(--radius); font-size: 13px; font-weight: 600;
    cursor: pointer; transition: all var(--tr); width: 100%;
    background: var(--bg-card); color: var(--text);
}
.btn:hover:not(:disabled) { transform: translateY(-1px); background: rgba(20,28,52,.7); }
.btn:active:not(:disabled) { transform: translateY(0); }
.btn:disabled { opacity: .35; cursor: not-allowed; }

.btn-primary { border-color: rgba(96,165,250,.35); background: rgba(16,42,92,.75); }
.btn-primary:hover:not(:disabled) { background: rgba(24,56,120,.85); }

.btn-secondary { background: rgba(255,255,255,.06); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--text-dim); }
.btn-ghost:hover:not(:disabled) { color: var(--text); background: rgba(255,255,255,.04); border-color: transparent; }

.btn-danger { background: rgba(239,68,68,.2); border-color: rgba(239,68,68,.35); color: #fca5a5; }

.btn-sm { padding: 5px 10px; font-size: 11px; }
.btn-row { display: flex; gap: 8px; }
.btn-row .btn { width: auto; flex: 1; }

/* ─── SEARCH ─── */

.search-wrap { position: relative; }
.search-results {
    position: absolute; top: 100%; left: 0; right: 0;
    background: var(--bg-glass); border: 1px solid var(--border);
    border-radius: 0 0 var(--radius) var(--radius);
    z-index: 20; max-height: 200px; overflow-y: auto; backdrop-filter: blur(12px);
}
.search-result-item {
    padding: 8px 10px; font-size: 12px; cursor: pointer;
    border-bottom: 1px solid var(--border-dim); transition: background var(--tr);
}
.search-result-item:hover { background: var(--bg-hover); }
.search-result-item:last-child { border-bottom: none; }
.search-result-name { color: var(--text); }
.search-result-context { color: var(--text-dim); font-size: 11px; margin-top: 2px; }

/* ─── WORKSPACE LAYOUT ─── */

#ws-body { display: flex; flex: 1; overflow: hidden; }

#sidebar {
    width: var(--sidebar-w); background: rgba(7,10,16,.95);
    border-right: 1px solid var(--border); overflow-y: auto; flex-shrink: 0;
    display: flex; flex-direction: column;
    backdrop-filter: blur(8px);
}
#sidebar::-webkit-scrollbar { width: 4px; }
#sidebar::-webkit-scrollbar-thumb { background: rgba(255,255,255,.1); border-radius: 3px; }

.sidebar-section { padding: 12px 14px; border-bottom: 1px solid var(--border-dim); }
.sidebar-heading { font-size: 10px; text-transform: uppercase; letter-spacing: .5px; color: var(--text-label); margin-bottom: 8px; }
.sidebar-note { font-size: 11px; color: var(--text-dim); line-height: 1.45; margin: 0 0 8px; }
.sidebar-bottom { margin-top: auto; }

.ws-help-main { font-size: 13px; font-weight: 600; color: var(--text); margin: 0 0 4px; line-height: 1.35; }
.ws-help-sub { font-size: 11px; color: var(--text-dim); margin: 0 0 6px; line-height: 1.4; }
.ws-tool-guide { font-size: 11px; color: var(--accent); margin: 0; line-height: 1.4; }
.ws-fill-total { color: var(--accent); font-weight: 600; margin-top: 6px; }

.info-box {
    background: rgba(255,255,255,.03); border: 1px solid var(--border-dim);
    border-radius: var(--radius-sm); padding: 8px 10px;
}
.info-row { display: flex; justify-content: space-between; font-size: 11px; padding: 2px 0; }
.info-row span:first-child { color: var(--text-dim); }
.info-row span:last-child { color: var(--text); font-weight: 600; }

.panel {
    background: rgba(255,255,255,.03); border: 1px solid var(--border);
    border-radius: var(--radius-sm); padding: 10px; margin: 10px 14px;
}
.panel h4 { font-size: 10px; text-transform: uppercase; letter-spacing: .5px; color: var(--text-label); margin-bottom: 8px; }

/* Grid list */
#ws-grid-list { max-height: 180px; overflow-y: auto; }
.grid-item {
    display: flex; align-items: center; gap: 6px;
    padding: 4px 6px; border-radius: 4px; cursor: pointer;
    font-size: 11px; border: 1px solid transparent; transition: background var(--tr);
}
.grid-item:hover { background: rgba(255,255,255,.04); }
.grid-item.selected { background: rgba(96,165,250,.1); border-color: rgba(96,165,250,.3); }
.grid-item-dot { width: 7px; height: 7px; border-radius: 2px; background: var(--accent); flex-shrink: 0; }
.grid-item-id { font-weight: 600; }
.grid-item-dims { color: var(--text-dim); margin-left: auto; font-size: 10px; }

/* QR output */
#ws-qr-grid {
    display: grid; grid-template-columns: repeat(auto-fill, minmax(110px,1fr));
    gap: 8px; max-height: 300px; overflow-y: auto;
}
.qr-card {
    background: rgba(255,255,255,.03); border: 1px solid var(--border-dim);
    border-radius: var(--radius-sm); padding: 6px; text-align: center;
}
.qr-card canvas { width: 100%; height: auto; border-radius: 4px; background: #fff; }
.qr-card-label { font-size: 9px; font-weight: 700; color: var(--accent); margin-top: 3px; }

#ws-sheet-grid {
    display: grid; grid-template-columns: repeat(auto-fill, minmax(150px,1fr));
    gap: 10px; max-height: 440px; overflow-y: auto;
}
#ws-sheet-grid img { width: 100%; height: auto; border-radius: 4px; background: #fff; }

/* ─── MAP ─── */

#map-area { flex: 1; position: relative; overflow: hidden; }
#map { width: 100%; height: 100%; }

.img-canvas {
    position: absolute; inset: 0;
    width: 100%; height: 100%;
    object-fit: contain;
    background: #111;
}

/* ─── TOOLBAR ─── */

.toolbar {
    position: absolute; top: 10px; left: 50%;
    transform: translateX(-50%);
    display: flex; align-items: center; flex-wrap: wrap; justify-content: center;
    gap: 4px; max-width: calc(100% - 24px);
    padding: 4px 6px; border-radius: 12px;
    background: rgba(8,10,18,.88);
    border: 1px solid var(--border);
    backdrop-filter: blur(14px);
    z-index: 20;
    pointer-events: auto;
    user-select: none;
}
.toolbar.toolbar-custom {
    transform: none;
}
.toolbar.is-dragging {
    opacity: 0.95;
    box-shadow: 0 8px 28px rgba(0, 0, 0, 0.45);
}
.toolbar-grip {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 16px;
    height: 30px;
    padding: 0;
    margin-right: 2px;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: var(--text-dim);
    cursor: grab;
    flex-shrink: 0;
    touch-action: none;
}
.toolbar-grip:hover {
    background: rgba(255, 255, 255, 0.06);
    color: var(--text);
}
.toolbar.is-dragging .toolbar-grip { cursor: grabbing; }
.toolbar-grip svg { opacity: 0.5; pointer-events: none; }
.tool-group { display: flex; align-items: center; gap: 2px; }
.toolbar.auto-mode .tool-group-place,
.toolbar.auto-mode .tool-sep-place { display: none; }
.toolbar.manual-mode .tool-group-auto { display: none; }
.tool-btn {
    display: flex; align-items: center; justify-content: center;
    border: none; border-radius: 8px;
    background: transparent; color: var(--text-dim);
    cursor: pointer; transition: all var(--tr);
}
.tool-btn-labeled {
    gap: 6px; padding: 6px 10px;
    font-size: 11px; font-weight: 600; white-space: nowrap;
}
.tool-btn:not(.tool-btn-labeled) { width: 34px; height: 34px; }
.tool-btn:hover { background: rgba(255,255,255,.08); color: var(--text); }
.tool-btn.active { background: rgba(96,165,250,.2); color: var(--accent); }
.tool-btn-primary { box-shadow: inset 0 0 0 1px rgba(96,165,250,.45); }
.tool-btn-pressed { transform: scale(0.96); }
.tool-btn:disabled { opacity: .3; cursor: not-allowed; }
.tool-btn-accent { color: #fbbf24; box-shadow: inset 0 0 0 1px rgba(251,191,36,.55); }
.tool-btn-accent:hover:not(:disabled) { background: rgba(251,191,36,.15); color: #fcd34d; }
.tool-btn-accent.active { background: rgba(251,191,36,.22); color: #fbbf24; }

.ws-ghost-banner {
    margin-top: 10px;
    padding: 10px 12px;
    border-radius: 8px;
    background: rgba(251,191,36,.12);
    border: 1px solid rgba(251,191,36,.35);
    color: #fde68a;
    font-size: 13px;
    line-height: 1.45;
}
.tool-sep { width: 1px; height: 24px; background: var(--border); margin: 0 2px; flex-shrink: 0; }

.ws-error {
    position: absolute; top: 56px; left: 50%; transform: translateX(-50%);
    z-index: 19; max-width: 90%;
    padding: 8px 12px; border-radius: 8px;
    background: rgba(127,29,29,.85); border: 1px solid rgba(248,113,113,.4);
    color: #fecaca; font-size: 11px; text-align: center;
    pointer-events: none;
}

/* ─── HANDLES ─── */

#handles-layer { position: absolute; inset: 0; pointer-events: none; z-index: 12; }
.handle { position: absolute; pointer-events: auto; transform: translate(-50%,-50%); }
.handle-corner { width: 10px; height: 10px; background: #fff; border: 2px solid var(--accent); border-radius: 2px; cursor: nwse-resize; }
.handle-group { width: 12px; height: 12px; border-color: #fbbf24; box-shadow: 0 0 0 2px rgba(251,191,36,.35); }
.handle-rotate { width: 14px; height: 14px; background: var(--accent); border: 2px solid #fff; border-radius: 50%; cursor: grab; }
.handle-rotate:active { cursor: grabbing; }
.handle-line { position: absolute; pointer-events: none; border-left: 1px dashed rgba(255,255,255,.3); }

.dim-tip {
    position: absolute; padding: 3px 7px; border-radius: 6px;
    background: rgba(8,10,18,.85); border: 1px solid var(--border);
    font-size: 11px; font-weight: 600; color: var(--text);
    white-space: nowrap; pointer-events: none; z-index: 25;
}

/* ─── TOAST ─── */

.map-toast {
    position: absolute; bottom: 20px; left: 50%;
    transform: translateX(-50%); z-index: 15;
    pointer-events: none; white-space: nowrap;
    transition: opacity .3s, transform .3s;
}
.map-toast-inner {
    padding: 8px 16px; border-radius: 10px;
    border: 1px solid var(--border);
    background: rgba(10,14,26,.7); backdrop-filter: blur(10px);
    font-size: 12px; font-weight: 500; color: rgba(233,238,252,.88);
}
.map-toast.hidden { opacity: 0; transform: translateX(-50%) translateY(10px); }

/* ─── UTILITIES ─── */

.hidden { display: none !important; }

.mapboxgl-ctrl-group { background: var(--bg-glass) !important; border: 1px solid var(--border) !important; border-radius: var(--radius-sm) !important; }
.mapboxgl-ctrl-group button { border-color: var(--border-dim) !important; }
.mapboxgl-ctrl-group button span { filter: invert(1) brightness(.8); }

@media (max-width: 768px) {
    :root { --sidebar-w: 240px; }
    .welcome-choices { flex-direction: column; align-items: center; }
    .choice-card { width: 100%; max-width: 300px; }
    .quick-body { flex-direction: column; align-items: center; }
}
@media (max-width: 600px) {
    #ws-body { flex-direction: column; }
    #sidebar { width: 100%; max-height: 38vh; border-right: none; border-bottom: 1px solid var(--border); }
}
