*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
button, [role="button"] { outline: none; }

:root {
    --bg: #0a0f0a;
    --bg-card: #0d150d;
    --border: #1a2e1a;
    --green: #3a8a3a;
    --green-light: #4a9a4a;
    --red: #e04040;
    --text: #e0e0e0;
    --text-dim: #888;
    --gold: #e8c84a;
}

body {
    font-family: var(--font-ui);
    background: var(--bg);
    color: var(--text);
    min-height: 100dvh;
    -webkit-font-smoothing: antialiased;
}

/* === Screens === */
.screen {
    display: none;
    min-height: 100dvh;
    padding: 2rem 1.5rem;
}

.screen--active { display: flex; }

.screen__inner {
    width: 100%;
    max-width: 400px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1rem;
}

.screen__title {
    font-family: var(--font-ui);
    font-weight: 700;
    font-size: 1.4rem;
}

.screen__text {
    font-size: 0.85rem;
    color: var(--text-dim);
    text-align: center;
}

/* === Splash === */
.splash-spinner {
    width: 24px;
    height: 24px;
    border: 2.5px solid var(--border);
    border-top-color: var(--green);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
    margin-top: 0.5rem;
}

/* === Branding === */
.app-brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 1rem;
}
.app-brand--small {
    gap: 0.5rem;
    margin-bottom: 0.5rem;
}
.app-logo { border-radius: 8px; }
.app-logo--small { border-radius: 6px; }
.app-brand__name {
    font-family: var(--font-brand);
    font-weight: 700;
    font-size: 2rem;
    letter-spacing: 0.12em;
    color: #e8e8e8;
}
.app-brand__name--small {
    font-size: 1.3rem;
}
.app-brand__accent {
    color: #FF5800;
}
.screen__logo { border-radius: 6px; opacity: 0.7; }

.app-subtitle {
    font-size: 0.9rem;
    color: var(--text-dim);
    margin-bottom: 1.5rem;
}

/* === Form === */
.form__label {
    display: block;
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-dim);
    margin-bottom: 0.3rem;
}

.form__input, .form__select {
    width: 100%;
    padding: 0.7rem 0.9rem;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    font-family: inherit;
    font-size: 0.9rem;
    outline: none;
    transition: border-color 0.2s;
}

.form__input:focus, .form__select:focus {
    border-color: var(--green);
}

.form__input--large {
    font-family: var(--font-ui);
    font-size: 1.8rem;
    font-weight: 700;
    text-align: center;
    letter-spacing: 0.2em;
    text-transform: uppercase;
    padding: 1rem;
}

.form__group {
    width: 100%;
    margin-bottom: 0.75rem;
}

/* === Buttons === */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: 8px;
    font-family: var(--font-ui);
    font-weight: 600;
    font-size: 0.95rem;
    letter-spacing: 0.03em;
    cursor: pointer;
    transition: all 0.2s;
}

.btn--primary { background: var(--green); color: #fff; }
.btn--primary:hover { background: var(--green-light); }
.btn--primary:disabled { background: #2a4a2a; color: #666; cursor: not-allowed; }

.btn--outline {
    background: transparent;
    color: var(--green);
    border: 1.5px solid var(--green);
}
.btn--outline:hover { background: rgba(58, 138, 58, 0.1); }
.btn--outline:disabled { border-color: #2a4a2a; color: #666; cursor: not-allowed; }

.btn--text {
    background: transparent;
    color: var(--text-dim);
    font-size: 0.8rem;
    padding: 0.5rem;
}
.btn--text:hover { color: var(--red); }

.btn--warning { background: var(--gold); color: #000; }
.btn--warning:hover { background: #f0d060; }

.btn--success { background: var(--green); color: #fff; }
.btn--success:hover { background: var(--green-light); }

.btn--danger { background: var(--red); color: #fff; }
.btn--danger:hover { background: #e85050; }

.btn--full { width: 100%; }

.btn svg { vertical-align: -2px; margin-right: 4px; }

/* === Stream Actions (Pause / Disconnect row) === */
.stream-actions {
    display: flex;
    gap: 0.5rem;
    width: 100%;
}
.stream-actions .btn { flex: 1; }

/* === Confirm Dialog === */
.app-confirm[hidden] { display: none; }
.app-confirm {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
}
.app-confirm__backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.6);
}
.app-confirm__box {
    position: relative;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 0.75rem;
    padding: 1.5rem;
    max-width: 300px;
    width: 90%;
    text-align: center;
}
.app-confirm__box p { color: var(--text); margin-bottom: 0.25rem; }
.app-confirm__sub { font-size: 0.8rem; color: var(--text-dim); margin-bottom: 1rem !important; }
.app-confirm__actions { display: flex; gap: 0.5rem; }
.app-confirm__actions .btn { flex: 1; }

/* === Join Form === */
.join-form {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

/* === Permissions prompt === */
.permissions-prompt {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
    width: 100%;
}

/* === Alerts === */
.alert {
    width: 100%;
    padding: 0.65rem 0.9rem;
    border-radius: 8px;
    font-size: 0.8rem;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    animation: alertSlideIn 0.2s ease-out;
}

.alert--error {
    background: rgba(224, 64, 64, 0.12);
    color: var(--red);
    border: 1px solid rgba(224, 64, 64, 0.25);
}

.alert--error::before {
    content: '';
    width: 16px;
    height: 16px;
    flex-shrink: 0;
    background: var(--red);
    -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2'%3E%3Ccircle cx='12' cy='12' r='10'/%3E%3Cline x1='15' y1='9' x2='9' y2='15'/%3E%3Cline x1='9' y1='9' x2='15' y2='15'/%3E%3C/svg%3E") center / contain no-repeat;
    mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2'%3E%3Ccircle cx='12' cy='12' r='10'/%3E%3Cline x1='15' y1='9' x2='9' y2='15'/%3E%3Cline x1='9' y1='9' x2='15' y2='15'/%3E%3C/svg%3E") center / contain no-repeat;
}

.alert--success {
    background: rgba(58, 138, 58, 0.12);
    color: var(--green-light);
    border: 1px solid rgba(58, 138, 58, 0.25);
}

.alert--success::before {
    content: '';
    width: 16px;
    height: 16px;
    flex-shrink: 0;
    background: var(--green-light);
    -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2'%3E%3Cpath d='M22 11.08V12a10 10 0 11-5.93-9.14'/%3E%3Cpath d='M22 4L12 14.01l-3-3'/%3E%3C/svg%3E") center / contain no-repeat;
    mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2'%3E%3Cpath d='M22 11.08V12a10 10 0 11-5.93-9.14'/%3E%3Cpath d='M22 4L12 14.01l-3-3'/%3E%3C/svg%3E") center / contain no-repeat;
}

@keyframes alertSlideIn {
    from { opacity: 0; transform: translateY(-4px); }
    to { opacity: 1; transform: translateY(0); }
}

/* === Preview === */
.preview[hidden] { display: none; }
.preview, .streaming-preview {
    position: relative;
    width: 100%;
    aspect-ratio: 4/3;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    overflow: hidden;
    margin: 0.5rem 0;
}

/* === Reconnect Overlay === */
.reconnect-overlay[hidden] { display: none; }
.reconnect-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
}

.reconnect-overlay__content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.8rem;
    color: var(--gold);
    font-size: 0.9rem;
    font-weight: 600;
}

.reconnect-overlay__spinner {
    width: 32px;
    height: 32px;
    border: 3px solid rgba(232, 200, 74, 0.3);
    border-top-color: var(--gold);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

.preview__video {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* === Media Select === */
.media-select {
    width: 100%;
}

/* === Global hidden fix === */
[hidden] { display: none !important; }

/* === Stream Badges (overlay on video) === */
.stream-badge {
    position: absolute;
    top: 8px;
    right: 8px;
    z-index: 5;
    display: flex;
    align-items: center;
    gap: 5px;
    font-family: var(--font-ui);
    font-weight: 700;
    font-size: 0.75rem;
    padding: 0.3rem 0.7rem;
    border-radius: 5px;
    letter-spacing: 0.05em;
    color: #fff;
}

.stream-badge--ready { background: rgba(58, 138, 58, 0.85); }
.stream-badge--live { background: rgba(224, 64, 64, 0.9); }

.stream-badge__dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #fff;
}

.stream-badge__dot--pulse {
    animation: pulse 2s ease-in-out infinite;
}

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

/* === Collapsible === */
.collapsible {
    width: 100%;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
}

.collapsible__toggle {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.55rem 0.8rem;
    background: none;
    border: none;
    color: var(--text-dim);
    font-family: inherit;
    font-size: 0.75rem;
    font-weight: 600;
    cursor: pointer;
    transition: color 0.2s;
}

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

.collapsible__arrow {
    transition: transform 0.2s;
    flex-shrink: 0;
}

.collapsible__toggle--open .collapsible__arrow {
    transform: rotate(180deg);
}

.collapsible__body {
    border-top: 1px solid var(--border);
    padding: 0.3rem 0;
}

/* === Device Info Panel === */
.device-info-panel__row {
    display: flex;
    justify-content: space-between;
    padding: 0.3rem 0.8rem;
    font-size: 0.75rem;
}

.device-info-panel__label { color: var(--text-dim); }
.device-info-panel__value { color: var(--text); font-weight: 500; text-align: right; max-width: 60%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* === Toggle switch === */
.switch {
    position: relative;
    display: inline-block;
    width: 36px;
    height: 20px;
    flex-shrink: 0;
}

.switch input { opacity: 0; width: 0; height: 0; }

.switch__track {
    position: absolute;
    inset: 0;
    background: #333;
    border-radius: 10px;
    cursor: pointer;
    transition: background 0.2s;
}

.switch__track::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 16px;
    height: 16px;
    background: #888;
    border-radius: 50%;
    transition: transform 0.2s, background 0.2s;
}

.switch input:checked + .switch__track {
    background: var(--green);
}

.switch input:checked + .switch__track::after {
    transform: translateX(16px);
    background: #fff;
}

.switch input:disabled + .switch__track {
    opacity: 0.4;
    cursor: not-allowed;
}

.switch--large {
    width: 72px;
    height: 36px;
}
.switch--large .switch__track { border-radius: 18px; }
.switch--large .switch__track::after {
    width: 28px;
    height: 28px;
    top: 4px;
    left: 4px;
}
.switch--large input:checked + .switch__track::after {
    transform: translateX(36px);
}

/* === Permission toggles === */
.perm-toggles {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    margin: 0.3rem 0;
}

.perm-toggle {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.7rem;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 0.8rem;
    color: var(--text-dim);
}

.perm-toggle__label {
    flex: 1;
    color: var(--text);
    font-weight: 500;
}

.perm-toggle--unavailable {
    opacity: 0.5;
}

/* === Button Icon === */
.btn__icon {
    margin-right: 0.4rem;
    flex-shrink: 0;
}

/* === Button Spinner === */
.btn__spinner, .btn-spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
    margin-right: 0.5rem;
    flex-shrink: 0;
}

/* === Stream Controls (overlay on video, right side column) === */
.preview-controls, .stream-controls-overlay {
    position: absolute;
    right: 8px;
    top: 38px;
    z-index: 5;
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.preview-controls { top: 8px; }

.stream-ctrl-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.2s, color 0.2s;
    background: rgba(0, 0, 0, 0.5);
}

.stream-ctrl-btn--on { color: var(--green-light); }
.stream-ctrl-btn--off { color: var(--red); }
.stream-ctrl-btn--disabled { color: #555; opacity: 0.5; cursor: not-allowed; }
.stream-ctrl-btn--sim { color: #e0a020; }

/* === Stream Status === */
/* === Camera switch on streaming screen === */
.stream-camera-switch {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.stream-camera-switch__label {
    font-size: 0.75rem;
    color: var(--text-dim);
    white-space: nowrap;
    display: flex;
    align-items: center;
    gap: 4px;
}
.stream-camera-switch .form__select--compact {
    flex: 1;
    padding: 0.35rem 0.5rem;
    font-size: 0.75rem;
}

.stream-status {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.status-item {
    display: flex;
    justify-content: space-between;
    padding: 0.5rem 0.7rem;
    background: var(--bg-card);
    border-radius: 6px;
    font-size: 0.8rem;
}

.status-item__label { color: var(--text-dim); }
.status-item__value { font-weight: 600; }

/* ── Mode Selection ── */
.mode-select {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    width: 100%;
    max-width: 320px;
}
.mode-select__btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.4rem;
    padding: 1.25rem 1rem;
    background: var(--bg-card);
    border: 2px solid var(--border);
    border-radius: 12px;
    color: var(--text-main);
    cursor: pointer;
    transition: border-color 0.2s, background 0.2s;
}
.mode-select__btn:hover {
    border-color: var(--green);
    background: rgba(74, 154, 74, 0.08);
}
.mode-select__label {
    font-size: 1rem;
    font-weight: 700;
}
.mode-select__desc {
    font-size: 0.75rem;
    color: var(--text-dim);
}

/* ── GPS Active ── */
.gps-active {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
    padding: 1.5rem 0;
}
.gps-active__identity {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text-main);
    text-align: center;
}
.gps-active__status {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.85rem;
    color: var(--text-dim);
}
.gps-active__dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    flex-shrink: 0;
}
.gps-active__dot--waiting {
    background: #888;
    animation: gpsPulse 2s ease-in-out infinite;
}
.gps-active__dot--confirmed {
    background: var(--green);
    animation: gpsPulse 1.5s ease-in-out infinite;
}
@keyframes gpsPulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}
.gps-active__coords {
    font-family: var(--font-mono, monospace);
    font-size: 0.8rem;
    color: var(--text-dim);
}
.gps-active__buttons {
    display: flex;
    gap: 0.5rem;
    margin-top: 1.5rem;
    width: 100%;
    max-width: 320px;
}
.gps-active__buttons .btn { flex: 1; }
.btn--danger-outline {
    border: 1px solid rgba(224, 64, 64, 0.4);
    background: none;
    color: #e04040;
}
.btn--danger-outline:hover {
    background: rgba(224, 64, 64, 0.1);
}

/* === Screen Lock === */
.screen-lock {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 0.75rem 1rem;
    margin-top: 0.5rem;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 10px;
    position: relative;
    z-index: 100;
}
.screen-lock__label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--text-dim);
    font-size: 0.85rem;
}
.screen--locked .screen-lock__label {
    color: var(--gold);
}
.screen-lock__overlay {
    position: fixed;
    inset: 0;
    z-index: 99;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-dim);
}
