/* ==========================================================================
   CarCam — Cross-Network Live Monitor Stylesheet
   Modern, Dark-Themed & Mobile-First for iPhone Safari
   ========================================================================== */

:root {
    --bg-main: #0a0a1a;
    --bg-surface: #12122b;
    --bg-card: #181838;
    --bg-card-hover: #1f1f47;
    --bg-glass: rgba(18, 18, 43, 0.85);

    --accent: #e94560;
    --accent-hover: #ff5773;
    --accent-glow: rgba(233, 69, 96, 0.35);

    --green: #4ecca3;
    --green-glow: rgba(78, 204, 163, 0.35);

    --amber: #ffc857;
    --amber-glow: rgba(255, 200, 87, 0.35);

    --text-primary: #f0f0f8;
    --text-secondary: #9090b4;
    --text-muted: #5e5e82;

    --border: rgba(255, 255, 255, 0.08);
    --border-accent: rgba(233, 69, 96, 0.3);

    --radius-sm: 8px;
    --radius-md: 14px;
    --radius-lg: 20px;
    --radius-pill: 999px;

    --font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    --transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

html, body {
    font-family: var(--font-family);
    background-color: var(--bg-main);
    color: var(--text-primary);
    min-height: 100vh;
    min-height: 100dvh;
    min-height: -webkit-fill-available;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
}

/* App Container */
.app-container {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    min-height: 100dvh;
    max-width: 600px;
    margin: 0 auto;
    padding-top: env(safe-area-inset-top);
    padding-bottom: max(16px, env(safe-area-inset-bottom));
}

/* Header */
.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 18px;
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 50;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
}

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

.logo-icon-sm {
    width: 32px;
    height: 32px;
    flex-shrink: 0;
}

.logo-icon-sm svg {
    width: 100%;
    height: 100%;
}

.brand-text {
    display: flex;
    flex-direction: column;
}

.brand-name {
    font-size: 17px;
    font-weight: 700;
    letter-spacing: -0.3px;
    background: linear-gradient(135deg, #e94560, #ff8a80);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.brand-sub {
    font-size: 11px;
    color: var(--text-secondary);
    font-weight: 500;
    max-width: 140px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

/* Status Badge Pill */
.status-badge {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    border-radius: var(--radius-pill);
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.5px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border);
    transition: var(--transition);
}

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

.status-badge.disconnected .badge-dot { background: #888899; }
.status-badge.connecting .badge-dot { background: var(--amber); animation: pulse 1.2s infinite; }
.status-badge.standby .badge-dot { background: #5a78ff; animation: pulse 2s infinite; }
.status-badge.waking .badge-dot { background: var(--amber); animation: pulse 0.8s infinite; }
.status-badge.streaming .badge-dot { background: var(--green); box-shadow: 0 0 8px var(--green-glow); }

@keyframes pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.4; transform: scale(0.85); }
}

.btn-icon-header {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-secondary);
    width: 34px;
    height: 34px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: var(--transition);
}

.btn-icon-header:hover {
    color: var(--text-primary);
    border-color: var(--accent);
}

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

/* Main Content */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 16px;
    gap: 16px;
}

/* Video Section */
.video-section {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.video-container {
    position: relative;
    width: 100%;
    aspect-ratio: 16 / 9;
    background: #000;
    border-radius: var(--radius-md);
    overflow: hidden;
    border: 1px solid var(--border);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}

.video-container video {
    width: 100%;
    height: 100%;
    object-fit: contain;
    background: #000;
}

/* Video Overlay */
.video-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: 10px;
    pointer-events: none;
    z-index: 10;
}

.overlay-top, .overlay-bottom {
    display: flex;
    align-items: center;
    gap: 8px;
}

.overlay-bottom {
    justify-content: flex-end;
}

.live-pill {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    background: rgba(233, 69, 96, 0.85);
    color: #fff;
    padding: 3px 8px;
    border-radius: var(--radius-pill);
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.5px;
    backdrop-filter: blur(4px);
}

.live-pill .pill-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #fff;
    animation: pulse 1s infinite;
}

.fps-pill, .night-pill {
    background: rgba(0, 0, 0, 0.65);
    color: var(--text-primary);
    padding: 3px 8px;
    border-radius: var(--radius-pill);
    font-size: 11px;
    font-weight: 600;
    backdrop-filter: blur(4px);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.night-pill {
    color: var(--amber);
}

.btn-overlay {
    pointer-events: auto;
    background: rgba(18, 18, 43, 0.75);
    color: var(--text-primary);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: var(--radius-sm);
    padding: 6px 10px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    backdrop-filter: blur(6px);
    transition: var(--transition);
}

.btn-overlay:hover {
    background: var(--bg-card);
    border-color: var(--accent);
}

/* Placeholders inside Video Container */
.video-placeholder {
    position: absolute;
    inset: 0;
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    background: radial-gradient(circle at center, #161634 0%, #080816 100%);
    padding: 24px;
    z-index: 5;
}

.video-placeholder.active {
    display: flex;
}

.placeholder-icon {
    width: 56px;
    height: 56px;
    color: var(--text-muted);
    margin-bottom: 12px;
}

.placeholder-icon svg {
    width: 100%;
    height: 100%;
}

.video-placeholder h3 {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 6px;
}

.video-placeholder p {
    font-size: 12px;
    color: var(--text-secondary);
    max-width: 280px;
    line-height: 1.4;
    margin-bottom: 14px;
}

/* Spinners */
.spinner-large {
    width: 44px;
    height: 44px;
    border: 3px solid rgba(233, 69, 96, 0.2);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin-bottom: 14px;
}

.spinner-inline {
    width: 18px;
    height: 18px;
    border: 2px solid rgba(233, 69, 96, 0.2);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    flex-shrink: 0;
}

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

/* Video Toolbar Buttons */
.video-toolbar {
    display: flex;
    gap: 8px;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 600;
    border: none;
    cursor: pointer;
    transition: var(--transition);
    user-select: none;
}

.btn-primary {
    background: linear-gradient(135deg, var(--accent), #ff6b6b);
    color: #fff;
    box-shadow: 0 4px 14px var(--accent-glow);
}

.btn-primary:active {
    transform: scale(0.98);
}

.btn-secondary {
    background: var(--bg-card);
    color: var(--text-primary);
    border: 1px solid var(--border);
}

.btn-secondary:hover:not(:disabled) {
    background: var(--bg-card-hover);
    border-color: rgba(255, 255, 255, 0.2);
}

.btn-danger {
    background: rgba(233, 69, 96, 0.15);
    color: var(--accent);
    border: 1px solid var(--border-accent);
}

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

.btn-action {
    flex: 1;
}

.btn-sm {
    padding: 8px 14px;
    font-size: 12px;
}

.btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    box-shadow: none;
}

.btn-icon {
    font-size: 15px;
}

/* Dashboard Section */
.dashboard-section {
    margin-top: 4px;
}

.dashboard-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.telemetry-card {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    transition: var(--transition);
}

.telemetry-card:hover {
    background: var(--bg-card);
    border-color: rgba(255, 255, 255, 0.12);
}

.card-header {
    display: flex;
    align-items: center;
    gap: 6px;
}

.card-icon {
    font-size: 16px;
}

.card-title {
    font-size: 12px;
    font-weight: 500;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.card-body {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.value-row {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
}

.card-value {
    font-size: 20px;
    font-weight: 700;
    color: var(--text-primary);
}

.card-value-sm {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 140px;
}

.card-sub {
    font-size: 11px;
    font-weight: 500;
    color: var(--text-muted);
}

.meter-bar {
    width: 100%;
    height: 6px;
    background: rgba(255, 255, 255, 0.07);
    border-radius: var(--radius-pill);
    overflow: hidden;
}

.meter-fill {
    height: 100%;
    background: var(--green);
    border-radius: var(--radius-pill);
    transition: width 0.4s ease;
}

.info-tag-row {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
}

.info-tag {
    font-size: 10px;
    font-weight: 600;
    padding: 2px 6px;
    border-radius: var(--radius-sm);
    background: rgba(255, 255, 255, 0.06);
    color: var(--text-secondary);
}

.tag-success {
    background: rgba(78, 204, 163, 0.15);
    color: var(--green);
}

.tag-accent {
    background: rgba(233, 69, 96, 0.15);
    color: var(--accent);
}

/* Modal Backdrop & Card */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    display: none;
    align-items: center;
    justify-content: center;
    padding: 16px;
    z-index: 100;
}

.modal-backdrop.active {
    display: flex;
}

.modal-card {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 480px;
    max-height: 90vh;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    box-shadow: 0 16px 36px rgba(0, 0, 0, 0.6);
}

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

.modal-header h2 {
    font-size: 18px;
    font-weight: 700;
}

.btn-close {
    background: transparent;
    border: none;
    font-size: 24px;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0 4px;
}

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

.modal-desc {
    font-size: 13px;
    color: var(--text-secondary);
    line-height: 1.45;
}

/* Tabs */
.tab-bar {
    display: flex;
    background: var(--bg-card);
    padding: 4px;
    border-radius: var(--radius-sm);
    gap: 4px;
}

.tab-btn {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
}

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

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

/* Scanner Wrapper */
.scanner-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    margin-top: 10px;
}

.scanner-box {
    position: relative;
    width: 240px;
    height: 240px;
    background: #000;
    border-radius: var(--radius-md);
    overflow: hidden;
    border: 1px solid var(--border);
}

.scanner-box video {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.scanner-reticle {
    position: absolute;
    inset: 20px;
    pointer-events: none;
}

.corner {
    position: absolute;
    width: 24px;
    height: 24px;
    border: 3px solid var(--accent);
}

.corner.tl { top: 0; left: 0; border-right: none; border-bottom: none; }
.corner.tr { top: 0; right: 0; border-left: none; border-bottom: none; }
.corner.bl { bottom: 0; left: 0; border-right: none; border-top: none; }
.corner.br { bottom: 0; right: 0; border-left: none; border-top: none; }

.scanner-laser {
    position: absolute;
    left: 0;
    right: 0;
    height: 2px;
    background: linear-gradient(90deg, transparent, var(--accent), transparent);
    box-shadow: 0 0 10px var(--accent);
    animation: laserScan 2s ease-in-out infinite alternate;
}

@keyframes laserScan {
    0% { top: 10%; }
    100% { top: 90%; }
}

.scanner-message {
    font-size: 12px;
    color: var(--text-secondary);
    text-align: center;
}

/* Form Groups */
.form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 12px;
}

.form-group label {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    color: var(--text-secondary);
    letter-spacing: 0.5px;
}

.form-group input, .form-group textarea {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    padding: 10px 12px;
    font-size: 13px;
    font-family: inherit;
    outline: none;
    transition: var(--transition);
}

.form-group input:focus, .form-group textarea:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-glow);
}

.pairing-status-box {
    display: flex;
    align-items: center;
    gap: 10px;
    background: rgba(233, 69, 96, 0.1);
    border: 1px solid var(--border-accent);
    border-radius: var(--radius-sm);
    padding: 12px;
    font-size: 13px;
    color: var(--text-primary);
}

.paired-device-box {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 12px;
    margin-top: 10px;
}

.paired-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
}

.paired-sub {
    font-size: 11px;
    color: var(--text-muted);
}

/* Toast Alerts */
.toast-container {
    position: fixed;
    bottom: max(20px, env(safe-area-inset-bottom));
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    flex-direction: column;
    gap: 8px;
    z-index: 200;
    pointer-events: none;
    width: 90%;
    max-width: 400px;
}

.toast {
    background: var(--bg-surface);
    color: var(--text-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 10px 14px;
    font-size: 13px;
    font-weight: 500;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.6);
    pointer-events: auto;
    animation: slideUp 0.3s ease forwards;
}

.toast.toast-error {
    border-color: var(--accent);
    background: #1c0e18;
}

.toast.toast-success {
    border-color: var(--green);
    background: #0d1e18;
}

@keyframes slideUp {
    from { opacity: 0; transform: translateY(12px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Auth / Passcode Lock Screen */
.auth-lock-overlay {
    position: fixed;
    inset: 0;
    background: var(--bg-base);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    z-index: 500;
}

.auth-card {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 32px 24px;
    width: 100%;
    max-width: 360px;
    text-align: center;
    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.7);
}

.auth-icon {
    width: 64px;
    height: 64px;
    margin: 0 auto 16px;
    background: rgba(78, 204, 163, 0.12);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--green);
}

.auth-icon svg {
    width: 34px;
    height: 34px;
}

.btn-faceid {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 14px 24px;
    font-size: 16px;
    font-weight: 600;
    width: 100%;
    border-radius: var(--radius-md);
    background: linear-gradient(135deg, #0f3460, #16213e);
    border: 1px solid var(--border);
    color: #fff;
    cursor: pointer;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
    transition: all 0.2s ease;
}

.btn-faceid:hover, .btn-faceid:active {
    background: linear-gradient(135deg, #4ecca3, #2e7d32);
    border-color: transparent;
    transform: translateY(-1px);
    box-shadow: 0 6px 20px rgba(78, 204, 163, 0.4);
}

.faceid-btn-svg {
    width: 24px;
    height: 24px;
}

.auth-title {
    font-size: 20px;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 6px;
}

.auth-subtitle {
    font-size: 13px;
    color: var(--text-muted);
    margin-bottom: 20px;
}

.auth-error-msg {
    color: var(--accent);
    font-size: 12px;
    font-weight: 500;
    margin-bottom: 12px;
}

.settings-passcode-section {
    margin-top: 20px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
}

.settings-subtitle {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 4px;
}

.settings-hint {
    font-size: 12px;
    color: var(--text-muted);
    margin-bottom: 12px;
}

.passcode-btn-row {
    display: flex;
    gap: 8px;
}
