:root {
    --bg: #0B1220;
    --bg-panel: #101A2C;
    --bg-card: #16233A;
    --bg-elev: #1B2B47;
    --bg-input: #0E1726;
    --border: rgba(148, 163, 184, 0.16);
    --border-strong: rgba(148, 163, 184, 0.28);
    --text: #E6EDF7;
    --text-muted: #93A4C0;
    --muted-dim: #5D6B85;
    --accent: #3B82F6;
    --accent-strong: #2563EB;
    --green: #2ECC71;
    --amber: #F5A623;
    --red: #EF4444;
    --radius: 12px;
    --radius-sm: 8px;
    --radius-lg: 18px;
    --shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
    --shadow-lg: 0 18px 48px rgba(0, 0, 0, 0.55);
    --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    --topbar-h: 58px;
    --sb-w: 288px;
    --accent-grad: linear-gradient(135deg, #3B82F6, #2563EB);
    --focus-ring: 0 0 0 3px rgba(59, 130, 246, 0.35);
}

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

html, body {
    height: 100%;
}

body {
    font-family: var(--font);
    background:
        radial-gradient(1100px 560px at 12% -8%, rgba(59, 130, 246, 0.10), transparent 55%),
        radial-gradient(900px 460px at 112% 4%, rgba(46, 204, 113, 0.06), transparent 55%),
        var(--bg);
    color: var(--text);
    font-size: 14px;
    -webkit-font-smoothing: antialiased;
    overflow: hidden;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
[role="separator"]:focus-visible {
    outline: none;
    box-shadow: var(--focus-ring);
}

.hidden {
    display: none !important;
}

.muted {
    color: var(--text-muted);
    font-weight: 400;
}

/* ---------- Screens ---------- */
.screen {
    display: none;
    height: 100%;
}

.screen.is-active {
    display: block;
}

/* ---------- Auth ---------- */
.auth-shell {
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background:
        radial-gradient(1000px 500px at 20% -10%, rgba(59, 130, 246, 0.14), transparent 60%),
        radial-gradient(800px 420px at 110% 110%, rgba(46, 204, 113, 0.10), transparent 60%),
        var(--bg);
}

.auth-card {
    width: 100%;
    max-width: 400px;
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 32px;
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    gap: 18px;
}

.auth-brand {
    text-align: center;
}

.auth-logo {
    width: 52px;
    height: 52px;
    color: var(--accent);
    margin-bottom: 10px;
}

.auth-brand h1 {
    font-size: 22px;
    font-weight: 800;
    letter-spacing: -0.3px;
}

.auth-brand p {
    color: var(--text-muted);
    margin-top: 4px;
    font-size: 13px;
}

.auth-form {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.text-btn {
    background: none;
    border: none;
    color: var(--accent);
    font: inherit;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    align-self: center;
}

.text-btn:hover {
    color: var(--accent-strong);
    text-decoration: underline;
}

.text-btn svg {
    width: 16px;
    height: 16px;
}

/* ---------- Fields ---------- */
.field {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.field label {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
}

.field input,
.field select {
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    padding: 10px 12px;
    font: inherit;
    outline: none;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.field input:focus,
.field select:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2);
}

.field-hint {
    color: var(--muted-dim);
    font-size: 11px;
}

.form-error {
    color: var(--red);
    font-size: 13px;
}

.auth-config {
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    font: inherit;
    font-weight: 600;
    cursor: pointer;
    padding: 10px 16px;
    transition: background 0.15s ease, border-color 0.15s ease, opacity 0.15s ease;
}

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

.btn svg {
    width: 16px;
    height: 16px;
}

.btn-block {
    width: 100%;
}

.btn-sm {
    padding: 7px 12px;
    font-size: 13px;
}

.btn-primary {
    background: var(--accent);
    color: #fff;
}

.btn-primary:hover:not(:disabled) {
    background: var(--accent-strong);
}

.btn-secondary {
    background: var(--bg-elev);
    color: var(--text);
    border-color: var(--border);
}

.btn-secondary:hover:not(:disabled) {
    border-color: var(--border-strong);
}

.btn-ghost {
    background: transparent;
    color: var(--text-muted);
    border-color: var(--border);
}

.btn-ghost:hover:not(:disabled) {
    color: var(--text);
    border-color: var(--border-strong);
}

.icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--bg-panel);
    color: var(--text-muted);
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease;
}

.icon-btn:hover {
    background: var(--bg-elev);
    color: var(--text);
}

.icon-btn svg {
    width: 20px;
    height: 20px;
}

.icon-btn-sm {
    width: 32px;
    height: 32px;
}

.icon-btn-sm svg {
    width: 17px;
    height: 17px;
}

/* ---------- Topbar ---------- */
.topbar {
    height: var(--topbar-h);
    background: rgba(16, 26, 44, 0.92);
    border-bottom: 1px solid var(--border);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    z-index: 50;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    gap: 16px;
}

.topbar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
}

.brand-mark {
    width: 26px;
    height: 26px;
    color: var(--accent);
}

.brand-name {
    font-size: 16px;
    font-weight: 800;
    letter-spacing: -0.2px;
}

/* ---------- View mode switch ---------- */
.view-switch {
    display: flex;
    gap: 4px;
    padding: 4px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 999px;
}

.view-btn {
    border: none;
    background: transparent;
    color: var(--text-muted);
    font: inherit;
    font-size: 12px;
    font-weight: 700;
    padding: 6px 14px;
    border-radius: 999px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
    transition: background 0.15s ease, color 0.15s ease;
}

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

.view-btn.is-active {
    background: var(--accent);
    color: #fff;
}

/* ---------- Status pill ---------- */
.status-pill {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: var(--bg-input);
    font-size: 13px;
    font-weight: 600;
    color: var(--text-muted);
    white-space: nowrap;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--muted-dim);
}

.status-pill[data-state="on"] {
    color: var(--green);
    border-color: rgba(46, 204, 113, 0.35);
}

.status-pill[data-state="on"] .status-dot {
    background: var(--green);
    box-shadow: 0 0 8px rgba(46, 204, 113, 0.7);
}

.status-pill[data-state="connecting"] {
    color: var(--amber);
    border-color: rgba(245, 166, 35, 0.35);
}

.status-pill[data-state="connecting"] .status-dot {
    background: var(--amber);
    animation: pulse 1.2s ease infinite;
}

.status-pill[data-state="off"] .status-dot {
    background: var(--red);
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.35; }
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

.user-chip {
    color: var(--text-muted);
    font-size: 13px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 220px;
}

/* ---------- Layout ---------- */
.layout {
    display: flex;
    height: calc(100% - var(--topbar-h));
}

.sidebar {
    width: 280px;
    flex-shrink: 0;
    background: var(--bg-panel);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: margin-left 0.2s ease;
    z-index: 30;
}

.sidebar.collapsed {
    margin-left: -280px;
}

.sidebar-section {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    padding: 16px;
}

.sidebar-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    color: var(--text-muted);
}

.count-badge {
    background: var(--bg-elev);
    color: var(--text-muted);
    border-radius: 999px;
    min-width: 22px;
    height: 20px;
    padding: 0 6px;
    font-size: 11px;
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.drone-list {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.drone-card {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    background: var(--bg-card);
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease;
}

.drone-card:hover {
    background: var(--bg-elev);
}

.drone-card.is-selected {
    border-color: var(--accent);
    background: rgba(59, 130, 246, 0.10);
}

.drone-avatar {
    position: relative;
    width: 38px;
    height: 38px;
    border-radius: 10px;
    background: var(--bg-elev);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--dc, var(--accent));
    flex-shrink: 0;
}

.drone-avatar svg {
    width: 22px;
    height: 22px;
}

.drone-card-main {
    flex: 1;
    min-width: 0;
}

.drone-card-name {
    font-weight: 700;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.drone-card-sub {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-footer {
    padding: 12px 16px;
    border-top: 1px solid var(--border);
}

.empty-hint {
    color: var(--muted-dim);
    font-size: 13px;
    padding: 12px 0;
}

/* ---------- LIVE tag ---------- */
.live-tag {
    display: inline-block;
    background: var(--red);
    color: #fff;
    font-size: 9px;
    font-weight: 800;
    padding: 2px 6px;
    border-radius: 999px;
    letter-spacing: 0.6px;
    line-height: 1.4;
    white-space: nowrap;
}

.drone-avatar .live-tag {
    position: absolute;
    top: -6px;
    right: -6px;
}

/* ---------- Stage: map / split / stream ---------- */
.stage {
    flex: 1;
    min-width: 0;
    display: grid;
    grid-template-columns: 1fr;
    grid-template-rows: 1fr;
    overflow: hidden;
}

.stage.mode-split {
    --split-a: min(60%, 900px);
    grid-template-columns:
        minmax(240px, var(--split-a, 60%))
        var(--split-handle-w, 8px)
        minmax(0, 1fr);
}

.stage.mode-stream {
    grid-template-columns: 1fr;
}

.split-handle {
    display: none;
    position: relative;
    z-index: 5;
    cursor: col-resize;
    touch-action: none;
    background: transparent;
}

.split-handle::after {
    content: "";
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 4px;
    height: 48px;
    border-radius: 999px;
    background: var(--border-strong);
    transition: height 0.15s ease, background 0.15s ease;
}

.split-handle:hover::after,
.split-handle.is-dragging::after {
    height: 76px;
    background: var(--accent);
}

.stage.mode-split .split-handle {
    display: block;
    grid-column: 2;
    grid-row: 1;
}

.stage.mode-split .map-pane {
    grid-column: 1;
    grid-row: 1;
}

.stage.mode-split .stream-pane {
    grid-column: 3;
    grid-row: 1;
    border-left: 1px solid var(--border);
}

.map-pane {
    position: relative;
    grid-column: 1;
    grid-row: 1;
    min-width: 0;
    min-height: 0;
    overflow: hidden;
}

.stream-pane {
    grid-column: 2;
    grid-row: 1;
    min-width: 0;
    min-height: 0;
    background: var(--bg-panel);
    border-left: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.stage.mode-stream .stream-pane {
    grid-column: 1;
    border-left: none;
}

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

.leaflet-container {
    width: 100%;
    height: 100%;
    background: #0d1524;
}

.map-icon {
    background: transparent;
    border: none;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.5));
}

.map-fallback {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
    color: var(--text-muted);
    text-align: center;
    padding: 32px;
}

.map-fallback svg {
    width: 44px;
    height: 44px;
    opacity: 0.5;
}

.map-fallback h3 {
    margin: 0;
    color: var(--text);
}

.map-fallback p {
    margin: 0;
    max-width: 320px;
    font-size: 13px;
}

.map-stats {
    position: absolute;
    top: 14px;
    left: 16px;
    z-index: 10;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 14px;
    border-radius: 999px;
    background: rgba(11, 18, 32, 0.85);
    border: 1px solid var(--border);
    backdrop-filter: blur(6px);
    color: var(--text-muted);
    font-size: 13px;
    font-weight: 600;
    white-space: nowrap;
}

.stat-sep {
    opacity: 0.4;
}

.map-actions {
    position: absolute;
    bottom: 16px;
    right: 16px;
    z-index: 10;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.map-actions .icon-btn {
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.4);
}

.target-picker {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    z-index: 20;
    width: 280px;
    background: var(--bg-panel);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 16px;
}

.target-picker-meta {
    display: flex;
    align-items: baseline;
    gap: 6px;
}

.target-picker-title {
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    font-weight: 700;
}

.target-picker-drone {
    font-weight: 700;
}

.target-picker-coords {
    font-size: 12px;
    color: var(--text-muted);
    margin: 8px 0 0;
    font-variant-numeric: tabular-nums;
}

.target-picker-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 14px;
}

/* ---------- Stream panel ---------- */
.stream-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 14px;
    border-bottom: 1px solid var(--border);
}

.stream-id {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.stream-id-text {
    min-width: 0;
}

.stream-name {
    font-size: 16px;
    font-weight: 800;
    letter-spacing: -0.2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.stream-model {
    color: var(--text-muted);
    font-size: 12px;
    margin-top: 1px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.stream-head-right {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    background: var(--border-strong);
    color: var(--text-muted);
    white-space: nowrap;
}

.badge--live { background: var(--green); color: #06110B; }
.badge--watching,
.badge--connecting { background: var(--accent); color: #fff; }
.badge--waiting,
.badge--fallback { background: var(--amber); color: #1a1a1a; }
.badge--offline { background: var(--red); color: #fff; }
.badge--standby { background: var(--border-strong); color: var(--text-muted); }

.online-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--red);
    flex-shrink: 0;
}

.online-dot.is-online {
    background: var(--green);
    box-shadow: 0 0 8px rgba(46, 204, 113, 0.7);
}

/* ---------- Stream chips ---------- */
.stream-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 8px 14px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.chip {
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 3px 10px;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

/* ---------- Stream tabs ---------- */
.stream-tabs {
    display: flex;
    gap: 4px;
    padding: 6px 10px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.stream-tab {
    flex: 1;
    padding: 8px 6px;
    border-radius: var(--radius-sm);
    border: none;
    background: transparent;
    color: var(--text-muted);
    font: inherit;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

.stream-tab:hover {
    color: var(--text);
    background: var(--bg-elev);
}

.stream-tab.is-active {
    color: #fff;
    background: linear-gradient(135deg, rgba(59, 130, 246, 0.42), rgba(37, 99, 235, 0.30));
    box-shadow: inset 0 0 0 1px rgba(59, 130, 246, 0.35);
}

/* ---------- Stream tabpanes ---------- */
.stream-body {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.stream-tabpane {
    display: none;
    flex: 1;
    min-height: 0;
}

.stream-tabpane.is-active {
    display: flex;
    flex-direction: column;
}

/* ---------- Video pane ---------- */
#sp-video > .live-stage {
    flex: 1;
    min-height: 0;
}

.live-stage {
    position: relative;
    background: #000;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
}

.live-canvas {
    position: absolute;
    inset: 0;
    display: block;
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.live-fallback {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    width: 100%;
    height: 100%;
    justify-content: center;
    padding: 16px;
}

.live-fallback-img {
    display: block;
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

.live-fallback-note {
    color: var(--text-muted);
    font-size: 12px;
}

.live-status {
    position: absolute;
    left: 12px;
    bottom: 10px;
    margin: 0;
    padding: 4px 10px;
    border-radius: 999px;
    background: rgba(11, 18, 32, 0.85);
    color: var(--text);
    font-size: 12px;
    font-weight: 600;
}

.no-signal {
    position: absolute;
    inset: 40% auto auto 50%;
    transform: translate(-50%, -50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    text-align: center;
    pointer-events: none;
    user-select: none;
    animation: no-signal-fade 1.1s ease-in-out infinite;
}

.no-signal-icon {
    width: 46px;
    height: 46px;
    color: var(--red);
    filter: drop-shadow(0 0 10px rgba(239, 68, 68, 0.55));
}

.no-signal-title {
    margin: 0;
    font-size: 22px;
    font-weight: 800;
    letter-spacing: 3px;
    color: var(--red);
    text-shadow: 0 0 14px rgba(239, 68, 68, 0.5);
}

.no-signal-sub {
    margin: 0;
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.6px;
    color: var(--text-muted);
    text-transform: uppercase;
}

@keyframes no-signal-fade {
    0%, 100% { opacity: 0.55; }
    50% { opacity: 1; }
}

/* ---------- OSD overlay ---------- */
.osd {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    pointer-events: none;
    z-index: 10;
    color: #fff;
    font-size: 13px;
    font-weight: 600;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.85);
}

.osd-tr, .osd-cr, .osd-bl, .osd-br {
    position: absolute;
    display: flex;
    gap: 6px;
}

.osd-tr { top: 10px; right: 12px; }
.osd-cr { top: 50%; right: 12px; transform: translateY(-50%); }
.osd-bl { bottom: 36px; left: 12px; flex-wrap: wrap; }
.osd-br { bottom: 10px; left: 12px; flex-wrap: wrap; }

.osd-chip {
    background: rgba(0, 0, 0, 0.55);
    border-radius: 4px;
    padding: 2px 7px;
    white-space: nowrap;
    line-height: 1.6;
    font-variant-numeric: tabular-nums;
}

/* ---------- Compass HUD ---------- */
.osd-compass {
    position: relative;
    width: 46px;
    height: 46px;
    flex: 0 0 auto;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.5);
    border: 1px solid rgba(255, 255, 255, 0.35);
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
}
.osd-compass-rose {
    position: absolute;
    inset: 0;
    border-radius: 50%;
    transition: transform 220ms linear;
    will-change: transform;
}
.osd-compass-rose span {
    position: absolute;
    font-size: 9px;
    font-weight: 800;
    color: #fff;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.85);
}
.osd-compass-rose span:nth-child(1) { top: 4px; left: 50%; transform: translateX(-50%); color: #f87171; }
.osd-compass-rose span:nth-child(2) { top: 50%; right: 3px; transform: translateY(-50%); }
.osd-compass-rose span:nth-child(3) { bottom: 4px; left: 50%; transform: translateX(-50%); }
.osd-compass-rose span:nth-child(4) { top: 50%; left: 3px; transform: translateY(-50%); }
.osd-compass-lubber {
    position: absolute;
    top: -2px;
    left: 50%;
    transform: translateX(-50%);
    width: 2px;
    height: 10px;
    background: #f87171;
    border-radius: 1px;
}
#osd-hdg {
    position: relative;
    z-index: 2;
    background: rgba(0, 0, 0, 0.7);
}

.osd-laser { background: rgba(220, 38, 38, 0.7); }
.osd-conf { background: rgba(234, 179, 8, 0.65); }

/* ---------- Gimbal pro-joystick dock ---------- */
.gimbal-dock {
    position: absolute;
    bottom: 14px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 400;
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 10px 12px;
    border-radius: 14px;
    background: linear-gradient(180deg, rgba(15, 23, 42, 0.88), rgba(2, 6, 23, 0.88));
    border: 1px solid rgba(255, 255, 255, 0.10);
    box-shadow: 0 8px 28px rgba(0, 0, 0, 0.45);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    pointer-events: auto;
    user-select: none;
    -webkit-user-select: none;
    touch-action: none;
}

.gimbal-topline {
    display: flex;
    align-items: center;
    gap: 8px;
}

.gimbal-read {
    color: #e2e8f0;
    font-size: 12px;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    padding: 3px 8px;
    border-radius: 6px;
    background: rgba(0, 0, 0, 0.45);
}

.gimbal-read b {
    color: #ffffff;
}

.gimbal-pad {
    display: grid;
    grid-template-rows: auto auto auto;
    gap: 4px;
    justify-items: center;
}

.gimbal-cell {
    display: flex;
    gap: 4px;
}

.gpad {
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid rgba(255, 255, 255, 0.16);
    background: rgba(30, 41, 59, 0.9);
    color: #e2e8f0;
    border-radius: 10px;
    cursor: pointer;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.35);
    transition: background 0.12s ease, transform 0.08s ease, box-shadow 0.12s ease;
}

.gpad-dir {
    width: 52px;
    height: 44px;
}

.gpad-mini {
    width: 34px;
    height: 30px;
    font-size: 16px;
    font-weight: 700;
}

.gpad-stop {
    width: 52px;
    height: 44px;
}

.gpad-level {
    height: 28px;
    padding: 0 10px;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: #7dd3fc;
    border-color: rgba(56, 189, 248, 0.35);
}

.gpad svg {
    width: 20px;
    height: 20px;
}

.gpad:hover {
    background: rgba(51, 65, 85, 0.95);
}

.gpad:active,
.gpad.is-held {
    background: rgba(16, 185, 129, 0.35);
    border-color: rgba(16, 185, 129, 0.7);
    box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.18), 0 2px 6px rgba(0, 0, 0, 0.35);
    transform: scale(0.96);
}

.gimbal-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.gimbal-cams {
    display: flex;
    gap: 4px;
    padding: 3px;
    border-radius: 9px;
    background: rgba(0, 0, 0, 0.4);
}

.gimbal-cam {
    border: 0;
    background: transparent;
    color: #94a3b8;
    font-size: 11px;
    font-weight: 600;
    padding: 5px 10px;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.12s ease, color 0.12s ease;
}

.gimbal-cam:hover {
    color: #e2e8f0;
}

.gimbal-cam.is-active {
    background: #3b82f6;
    color: #fff;
}

.gimbal-zoom {
    display: flex;
    align-items: center;
    gap: 6px;
}

.gimbal-zoomval {
    min-width: 40px;
    text-align: center;
    color: #e2e8f0;
    font-size: 12px;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

.gimbal-hint {
    margin: 0;
    color: #64748b;
    font-size: 10px;
    letter-spacing: 0.02em;
}

.gimbal-reopen {
    position: absolute;
    bottom: 14px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 400;
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 12px;
    border-radius: 999px;
    border: 1px solid rgba(255, 255, 255, 0.14);
    background: rgba(15, 23, 42, 0.85);
    color: #e2e8f0;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.4);
}

.gimbal-reopen svg {
    width: 16px;
    height: 16px;
    color: #7dd3fc;
}

/* ---------- Data metric grid ---------- */
.metric-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    padding: 16px;
}

.metric {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 12px;
}

.metric-label {
    display: block;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    margin-bottom: 6px;
}

.metric-value {
    font-size: 13px;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    word-break: break-word;
}

.hint {
    margin: 0 16px 16px;
    color: var(--muted-dim);
    font-size: 12px;
    line-height: 1.5;
}

/* ---------- Targets grid ---------- */
#sp-targets {
    overflow-y: auto;
}

.target-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    padding: 16px;
    align-content: start;
}

.target-grid .empty-hint {
    grid-column: 1 / -1;
    text-align: center;
    padding: 32px 0;
}

.target-card {
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--bg-card);
    overflow: hidden;
    cursor: pointer;
    transition: border-color 0.15s ease;
}

.target-card:hover {
    border-color: var(--border-strong);
}

.target-thumb-wrap {
    position: relative;
    aspect-ratio: 4 / 3;
    background: var(--bg-input);
}

.target-thumb {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.target-thumb-wrap .no-image {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--muted-dim);
    font-size: 12px;
}

.target-card-meta {
    padding: 8px 10px;
}

.target-card-dist {
    font-size: 13px;
    font-weight: 700;
}

.target-card-dist.is-accepted {
    color: #10B981;
}

.target-card-time {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 1px;
}

/* ---------- Messages ---------- */
#sp-messages {
    overflow: hidden;
}

.message-list {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 16px;
}

.message {
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--bg-card);
    padding: 10px 12px;
}

.message.is-from-drone {
    border-left: 3px solid var(--accent);
}

.message.is-to-drone {
    border-left: 3px solid var(--green);
}

.message-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 11px;
    color: var(--text-muted);
    margin-bottom: 3px;
}

.message-sender {
    font-weight: 700;
    color: var(--text);
}

.message-body {
    font-size: 13px;
    line-height: 1.45;
    word-break: break-word;
}

.message-compose {
    display: flex;
    gap: 8px;
    border-top: 1px solid var(--border);
    padding: 12px 16px;
    flex-shrink: 0;
}

.message-compose input {
    flex: 1;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    padding: 9px 12px;
    font: inherit;
    outline: none;
}

.message-compose input:focus {
    border-color: var(--accent);
}

/* ---------- Modal ---------- */
.modal {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(4, 8, 16, 0.65);
    backdrop-filter: blur(2px);
}

.modal-card {
    position: relative;
    width: 100%;
    max-width: 420px;
    background: var(--bg-panel);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 22px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.modal-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.modal-head h3 {
    font-size: 16px;
    font-weight: 800;
}

#add-drone-form {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

/* ---------- Lightbox ---------- */
.lightbox {
    position: fixed;
    inset: 0;
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
}

.lightbox-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(4, 8, 16, 0.86);
}

.lightbox-card {
    position: relative;
    max-width: min(92vw, 1100px);
    max-height: 90vh;
    border-radius: var(--radius);
    overflow: hidden;
    background: var(--bg-panel);
    border: 1px solid var(--border-strong);
    box-shadow: var(--shadow);
}

.lightbox-close {
    position: absolute;
    top: 12px;
    right: 12px;
    z-index: 5;
    background: rgba(11, 18, 32, 0.85);
}

.lightbox-img {
    display: block;
    max-width: 100%;
    max-height: 78vh;
    object-fit: contain;
    margin: 0 auto;
}

.lightbox-caption {
    padding: 14px 18px;
    border-top: 1px solid var(--border);
}

.lightbox-title {
    font-weight: 700;
}

.lightbox-sub {
    color: var(--text-muted);
    font-size: 12px;
    margin-top: 3px;
}

/* ---------- Toasts ---------- */
.toasts {
    position: fixed;
    top: 68px;
    right: 18px;
    z-index: 300;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toast {
    min-width: 200px;
    max-width: 320px;
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    background: var(--bg-elev);
    border: 1px solid var(--border-strong);
    box-shadow: var(--shadow);
    font-size: 13px;
    font-weight: 500;
    animation: toast-in 0.18s ease;
}

.toast--success { border-left: 3px solid var(--green); }
.toast--error { border-left: 3px solid var(--red); }
.toast--info { border-left: 3px solid var(--accent); }

@keyframes toast-in {
    from { transform: translateX(20px); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

/* ---------- Topbar: menu button + icon view switcher ---------- */
.topbar-menu {
    display: none;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    margin-left: -6px;
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease;
}

.topbar-menu:hover {
    background: var(--bg-elev);
    color: var(--text);
}

.topbar-menu svg {
    width: 21px;
    height: 21px;
}

.view-btn svg {
    width: 14px;
    height: 14px;
    opacity: 0.85;
}

.view-btn.is-active svg {
    opacity: 1;
}

.view-btn.is-active {
    background: var(--accent-grad);
    box-shadow: 0 4px 14px rgba(37, 99, 235, 0.35);
}

/* ---------- Stream fullscreen viewer (YouTube-style) ---------- */
#stream-fullscreen .fs-exit {
    display: none;
}

#stream-fullscreen[data-fs="on"] .fs-exit {
    display: block;
}

#stream-fullscreen[data-fs="on"] .fs-enter {
    display: none;
}

.stream-pane:fullscreen {
    width: 100vw;
    height: 100vh;
    border: none;
    border-radius: 0;
    box-shadow: none;
    background: #05080f;
}

.stream-pane:fullscreen .stream-head {
    cursor: default;
}

.stream-pane:fullscreen .stream-chips {
    flex-shrink: 0;
}

/* Fallback fullscreen (no native API): fixed overlay wins over pip. */
html body.fs-fallback .stream-pane {
    position: fixed;
    inset: 0;
    width: auto;
    height: 100vh;
    z-index: 400;
    border: none;
    border-radius: 0;
    box-shadow: none;
}

/* ---------- Floating mini overlay (PiP) ---------- */
body.pip-active .stream-pane {
    position: fixed;
    right: var(--pip-right, 18px);
    bottom: var(--pip-bottom, 18px);
    left: auto;
    top: auto;
    z-index: 70;
    width: var(--pip-w, 400px);
    height: var(--pip-h, 300px);
    max-width: 92vw;
    max-height: 82vh;
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-strong);
    border-left: 1px solid var(--border-strong);
    box-shadow: var(--shadow-lg);
    overflow: hidden;
}

body.pip-active.is-dragged-pip .stream-pane {
    right: auto;
    bottom: auto;
    left: var(--pip-x, 24px);
    top: var(--pip-y, 24px);
}

body.pip-active .stream-pane .stream-head {
    cursor: grab;
    -webkit-user-select: none;
    user-select: none;
}

body.pip-active .stream-pane .stream-head.is-dragging {
    cursor: grabbing;
}

.pip-resize {
    position: absolute;
    right: 0;
    bottom: 0;
    z-index: 6;
    width: 24px;
    height: 24px;
    display: none;
    cursor: nwse-resize;
    touch-action: none;
}

.pip-resize::before {
    content: "";
    position: absolute;
    right: 5px;
    bottom: 5px;
    width: 10px;
    height: 10px;
    border-right: 2px solid var(--text-muted);
    border-bottom: 2px solid var(--text-muted);
    border-radius: 2px;
}

body.pip-active .pip-resize {
    display: block;
}

body.pip-active .pip-resize.is-dragging::before {
    border-color: var(--accent);
}

/* ---------- Fleet drawer backdrop ---------- */
.sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 34;
    background: rgba(4, 8, 16, 0.5);
    backdrop-filter: blur(1px);
}

/* ---------- Mobile bottom navigation ---------- */
.mobile-nav {
    display: none;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 60;
    height: calc(58px + env(safe-area-inset-bottom));
    padding-bottom: env(safe-area-inset-bottom);
    background: var(--bg-panel);
    border-top: 1px solid var(--border);
    box-shadow: 0 -6px 20px rgba(0, 0, 0, 0.35);
}

.mnav-btn {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    font: inherit;
    font-size: 10px;
    font-weight: 600;
    cursor: pointer;
    transition: color 0.15s ease, background 0.15s ease;
}

.mnav-btn svg {
    width: 20px;
    height: 20px;
}

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

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

/* ---------- Scrollbars ---------- */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-thumb {
    background: var(--border-strong);
    border-radius: 999px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

/* ---------- Responsive: desktop / tablet / mobile ---------- */

@media (max-width: 1180px) {
    .stage.mode-split {
        --split-a: min(60%, 720px);
        grid-template-columns:
            minmax(200px, var(--split-a, 55%))
            var(--split-handle-w, 8px)
            minmax(0, 1fr);
    }
}

/* Tablet + mobile: fleet sidebar becomes an overlay drawer. */
@media (max-width: 899px) {
    .topbar-menu {
        display: inline-flex;
    }

    .sidebar {
        position: fixed;
        top: var(--topbar-h);
        left: 0;
        bottom: 0;
        width: min(300px, 86vw);
        margin-left: 0;
        transform: translateX(-104%);
        transition: transform 0.22s ease, box-shadow 0.22s ease;
        z-index: 40;
    }

    .sidebar.is-open {
        transform: translateX(0);
        box-shadow: var(--shadow-lg);
    }

    .sidebar.collapsed {
        margin-left: 0;
    }

    .sidebar-backdrop.show {
        display: block;
    }
}

/* Mobile: left/right safety insets, bottom nav, stacked split,
   pip becomes a bottom sheet, gimbal dock clears the bottom nav. */
@media (max-width: 640px) {
    body {
        padding-left: env(safe-area-inset-left);
        padding-right: env(safe-area-inset-right);
    }

    .topbar {
        padding: env(safe-area-inset-top) 12px 0;
        gap: 8px;
        height: calc(var(--topbar-h) + env(safe-area-inset-top));
    }

    .layout {
        height: calc(100% - var(--topbar-h) - env(safe-area-inset-top) - env(safe-area-inset-bottom) - 58px);
    }

    .sidebar {
        top: calc(var(--topbar-h) + env(safe-area-inset-top));
        bottom: calc(58px + env(safe-area-inset-bottom));
    }

    .view-switch {
        display: none;
    }

    .mobile-nav {
        display: flex;
    }

    #dashboard-screen.screen.is-active {
        padding-bottom: calc(58px + env(safe-area-inset-bottom));
    }

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

    .status-text {
        display: none;
    }

    .status-pill {
        padding: 6px 9px;
    }

    .topbar-right {
        gap: 6px;
        padding-left: 4px;
    }

    .user-chip {
        max-width: 90px;
    }

    /* Stacked split: map on top, grip in the middle, stream below. */
    .stage.mode-split {
        --split-a: min(42%, 420px);
        grid-template-columns: 1fr;
        grid-template-rows:
            minmax(120px, var(--split-a, 38%))
            var(--split-handle-w, 8px)
            minmax(0, 1fr);
    }

    .stage.mode-split .map-pane {
        grid-column: 1;
        grid-row: 1;
    }

    .stage.mode-split .split-handle {
        grid-column: 1;
        grid-row: 2;
        cursor: row-resize;
    }

    .stage.mode-split .split-handle::after {
        width: 48px;
        height: 4px;
    }

    .stage.mode-split .stream-pane {
        grid-column: 1;
        grid-row: 3;
        border-left: none;
        border-top: 1px solid var(--border);
    }

    /* Pip becomes a bottom sheet over the map. */
    body.pip-active .stream-pane {
        position: fixed;
        left: 0;
        right: 0;
        bottom: calc(58px + env(safe-area-inset-bottom));
        top: auto;
        width: auto;
        height: 46vh;
        max-width: none;
        max-height: 54vh;
        border-radius: 16px 16px 0 0;
    }

    body.pip-active.is-dragged-pip .stream-pane {
        left: 0;
        right: 0;
        top: auto;
    }

    body.pip-active .pip-resize {
        display: none;
    }

    body.pip-active .stream-pane .stream-head {
        cursor: default;
    }

    .gimbal-dock {
        bottom: calc(70px + env(safe-area-inset-bottom));
    }

    .gimbal-reopen {
        bottom: calc(70px + env(safe-area-inset-bottom));
    }

    .metric-grid,
    .target-grid {
        grid-template-columns: 1fr;
    }

    .target-picker {
        width: min(280px, calc(100vw - 32px));
    }

    .stream-chips {
        flex-wrap: nowrap;
        overflow-x: auto;
        scrollbar-width: none;
    }

    .stream-chips::-webkit-scrollbar {
        display: none;
    }

    .osd-chip {
        font-size: 11px;
        padding: 2px 5px;
    }

    .live-status {
        display: none;
    }

    .map-actions {
        bottom: 14px;
    }

    .auth-card {
        padding: 24px 20px;
    }

    .toasts {
        right: 12px;
        left: 12px;
    }

    .toast {
        max-width: none;
    }
}

/* Tiny phones: declutter topbar, tabs, gimbal pad, OSD. */
@media (max-width: 480px) {
    .brand-name {
        display: none;
    }

    .mnav-btn span {
        display: none;
    }

    .mnav-btn {
        gap: 0;
    }

    .stream-head {
        padding: 10px;
    }

    .stream-head-right .icon-btn {
        width: 30px;
        height: 30px;
    }

    .stream-tabs {
        padding: 4px 6px;
    }

    .stream-tab {
        font-size: 12px;
        padding: 7px 4px;
    }

    .chip {
        font-size: 10px;
        padding: 3px 8px;
    }

    .gimbal-dock {
        padding: 8px 10px;
    }

    .gpad-dir,
    .gpad-stop {
        width: 46px;
        height: 40px;
    }

    .gpad-mini {
        width: 30px;
        height: 28px;
    }

    .osd-tr {
        top: 6px;
        right: 8px;
    }

    .osd-cr {
        right: 8px;
    }

    .osd-bl {
        bottom: 26px;
        left: 8px;
    }

    .osd-br {
        bottom: 8px;
        left: 8px;
    }

    .sidebar {
        width: min(280px, 90vw);
    }

    .map-actions {
        right: 10px;
        bottom: 12px;
    }

    .metric {
        padding: 10px;
    }

    .message-list {
        padding: 12px;
    }

    .target-grid {
        padding: 12px;
    }
}