:root {
    --bg-main: #0c0e12;
    --bg-card: #15181e;
    --bg-card-hover: #1c212b;
    --border-color: #242b35;
    --accent-green: #00ff88;
    --accent-pink: #ff3333;
    --text-primary: #f0f3f6;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --radius-lg: 16px;
    --radius-md: 10px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
}

html, body {
    height: 100%;
    height: 100dvh;
    width: 100vw;
    overflow: hidden;
    touch-action: none;
}

body {
    background-color: var(--bg-main);
    color: var(--text-primary);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: space-between;
}

.hidden {
    display: none !important;
}

/* ==========================================================================
   Ícones SVG Padronizados & Acessibilidade de Clique
   ========================================================================== */
.icon-svg {
    width: 20px;
    height: 20px;
    min-width: 20px;
    min-height: 20px;
    display: inline-block;
    vertical-align: middle;
    object-fit: contain;
    pointer-events: none;
}

.btn-menu img,
.btn-menu svg,
.btn-sidebar img,
.btn-sidebar svg {
    pointer-events: none;
}

/* ==========================================================================
   Overlay de Carregamento
   ========================================================================== */
.loading-overlay {
    position: fixed;
    inset: 0;
    background: rgba(12, 14, 18, 0.95);
    backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    padding: 16px;
}

.loading-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    padding: clamp(16px, 4vw, 24px);
    border-radius: var(--radius-lg);
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    max-width: 440px;
    text-align: center;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.5);
}

.loading-guide-img {
    width: 100%;
    height: auto;
    max-height: 46vh;
    object-fit: contain;
    border-radius: var(--radius-md);
    margin-bottom: 18px;
}

.spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--border-color);
    border-top: 3px solid var(--accent-green);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin-bottom: 12px;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.loading-text {
    color: var(--text-secondary);
    font-size: 0.95rem;
}

/* ==========================================================================
   Navbar
   ========================================================================== */
.navbar {
    width: 100%;
    max-width: 1000px;
    padding: 16px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

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

.brand-logo {
    width: 32px;
    height: 32px;
}

.brand-name {
    font-weight: 700;
    font-size: 1.25rem;
    letter-spacing: -0.5px;
}

.nav-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

.privacy-badge {
    display: flex;
    align-items: center;
    gap: 8px;
    background: rgba(0, 255, 136, 0.08);
    border: 1px solid rgba(0, 255, 136, 0.2);
    color: var(--accent-green);
    padding: 6px 14px;
    border-radius: 99px;
    font-size: 0.8rem;
    font-weight: 500;
}

.pulse-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--accent-green);
    box-shadow: 0 0 8px var(--accent-green);
    animation: pulse 1.8s infinite;
}

@keyframes pulse {
    0% { transform: scale(0.95); opacity: 0.8; }
    50% { transform: scale(1.3); opacity: 1; }
    100% { transform: scale(0.95); opacity: 0.8; }
}

.btn-menu {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border-color);
    width: 38px;
    height: 38px;
    border-radius: var(--radius-md);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.btn-menu:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: var(--accent-green);
}

/* ==========================================================================
   Container & Câmera com Proporção Natural e Centralização
   ========================================================================== */
.main-container {
    width: 100%;
    max-width: 800px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 0 16px;
    flex: 1;
    margin: auto 0;
    min-height: 0;
}

.hero-text {
    text-align: center;
    margin-bottom: 12px;
}

.hero-text h1 {
    font-size: 1.35rem;
    font-weight: 600;
    margin-bottom: 4px;
}

.status-indicator {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-secondary);
    min-height: 22px;
}

.camera-wrapper {
    position: relative;
    width: 100%;
    max-width: 580px;
    border-radius: var(--radius-lg);
    padding: 3px;
    background: linear-gradient(180deg, var(--border-color) 0%, transparent 100%);
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.4);
    margin-bottom: 12px;
    display: flex;
    justify-content: center;
    align-items: center;
}

.video-container {
    position: relative;
    width: 100%;
    border-radius: calc(var(--radius-lg) - 2px);
    overflow: hidden;
    background: #000;
    line-height: 0;
}

.video-container .loading-guide-img {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    z-index: 10;
    margin-bottom: 0;
    border-radius: inherit;
    transition: opacity 0.3s ease;
}

#webcam {
    display: block;
    width: 100%;
    height: auto;
    max-height: 48vh;
    object-fit: contain;
    border-radius: inherit;
    transform: scaleX(-1);
    transition: transform 0.2s ease;
}

#output {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: contain;
    border-radius: inherit;
    transform: scaleX(-1);
    pointer-events: none;
    transition: transform 0.2s ease;
}

/* ==========================================================================
   Painel de Controles & Badges
   ========================================================================== */
.controls-panel {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
    flex-wrap: wrap;
    justify-content: center;
    width: 100%;
}

.btn {
    padding: 10px 18px;
    border-radius: var(--radius-md);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    border: none;
    transition: transform 0.15s ease, background-color 0.2s ease;
}

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

.btn-primary {
    background: #e2e8f0;
    color: #0f172a;
}

.btn-primary:hover {
    background: #ffffff;
}

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

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

.badge-calibrada {
    font-size: 0.82rem;
    color: var(--text-secondary);
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    padding: 8px 14px;
    border-radius: var(--radius-md);
    transition: all 0.3s ease;
}

.telemetry-bar {
    font-size: 0.82rem;
    color: var(--text-secondary);
    font-family: monospace;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    padding: 6px 14px;
    border-radius: var(--radius-md);
    text-align: center;
}

/* ==========================================================================
   Sidebar Lateral (Gaveta)
   ========================================================================== */
.sidebar-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.65);
    backdrop-filter: blur(4px);
    z-index: 9990;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: all 0.3s ease;
}

.sidebar-backdrop.active {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}

.sidebar {
    position: fixed !important;
    top: 0;
    right: -320px;
    width: 290px;
    height: 100vh;
    height: 100dvh;
    background: var(--bg-card);
    border-left: 1px solid var(--border-color);
    box-shadow: -10px 0 30px rgba(0, 0, 0, 0.7);
    z-index: 9995;
    transition: right 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    display: flex;
    flex-direction: column;
    padding: 24px 20px;
    box-sizing: border-box;
}

.sidebar.active {
    right: 0 !important;
}

.sidebar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 12px;
}

.sidebar-header h3 {
    font-size: 1.05rem;
    font-weight: 600;
}

.sidebar-close {
    background: transparent;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.sidebar-content {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.btn-sidebar {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 14px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    border-radius: var(--radius-md);
    cursor: pointer;
    font-size: 0.88rem;
    font-weight: 500;
    transition: all 0.2s ease;
    text-align: left;
}

.btn-sidebar:hover {
    background: rgba(255, 255, 255, 0.08);
    border-color: var(--accent-green);
}

.sidebar-item-container.hidden,
#btn-calibrar.hidden {
    display: none !important;
}

/* ==========================================================================
   Toasts & Alertas
   ========================================================================== */
.toast-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    z-index: 10000;
    pointer-events: none;
}

.toast {
    background: var(--bg-card);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    padding: 12px 16px;
    border-radius: var(--radius-md);
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.88rem;
    opacity: 0;
    transform: translateY(20px);
    transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    pointer-events: auto;
}

.toast.show {
    opacity: 1;
    transform: translateY(0);
}

.toast-postura {
    border-left: 4px solid #ffaa00;
}

.toast-piscada {
    border-left: 4px solid var(--accent-pink);
}

.toast-fechar {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 1.2rem;
    cursor: pointer;
    padding: 0 4px;
}

#toast-postura-grande,
.toast-postura-grande {
    position: fixed;
    top: 35%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0.9);
    background: rgba(239, 68, 68, 0.95);
    color: #ffffff;
    font-weight: 700;
    font-size: 1.1rem;
    padding: 18px 24px;
    border-radius: var(--radius-lg);
    box-shadow: 0 20px 50px rgba(239, 68, 68, 0.4);
    z-index: 10001;
    border: none;
    opacity: 0;
    pointer-events: none;
    transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.25s ease;
}

#toast-postura-grande.show,
.toast-postura-grande.show {
    transform: translate(-50%, -50%) scale(1);
    opacity: 1;
    pointer-events: auto;
}

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

.toast-svg-icon-grande {
    width: 24px;
    height: 24px;
}

.status-svg-icon {
    width: 16px;
    height: 16px;
    vertical-align: text-bottom;
}

/* ==========================================================================
   Tela de Descanso Visual (30 Segundos)
   ========================================================================== */
.tela-descanso {
    position: fixed;
    inset: 0;
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    background-color: rgba(12, 14, 18, 0.96);
    backdrop-filter: blur(16px);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 20000;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.tela-descanso.active {
    display: flex;
    opacity: 1;
}

.descanso-content {
    background-color: var(--bg-card);
    border: 1px solid var(--border-color);
    padding: clamp(24px, 5vw, 40px);
    border-radius: var(--radius-lg);
    text-align: center;
    max-width: 480px;
    width: 90%;
    box-shadow: 0 24px 64px rgba(0, 0, 0, 0.8);
    transform: scale(0.95);
    transition: transform 0.3s ease;
}

.tela-descanso.active .descanso-content {
    transform: scale(1);
}

.descanso-content h2 {
    color: var(--text-primary);
    margin-top: 0;
    font-size: 1.4rem;
}

.descanso-content p {
    color: var(--text-secondary);
    font-size: 0.95rem;
    line-height: 1.5;
    margin-top: 8px;
}

.contador-descanso {
    font-size: 3rem;
    font-weight: 700;
    color: var(--accent-pink);
    margin-top: 20px;
    font-family: ui-monospace, monospace;
}

/* ==========================================================================
   Modal do Gráfico & Histórico
   ========================================================================== */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(5px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9000;
}

.modal.hidden {
    display: none;
}

.modal-content {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 20px;
    width: 90%;
    max-width: 620px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.6);
}

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

.modal-close {
    background: transparent;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
}

.modal-tabs {
    display: flex;
    gap: 8px;
}

.tab-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-size: 0.9rem;
    font-weight: 600;
    padding: 6px 12px;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.tab-btn.active {
    background: rgba(255, 255, 255, 0.08);
    color: var(--accent-green);
}

.tab-pane {
    display: none;
}

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

.chart-container {
    position: relative;
    height: 260px;
    width: 100%;
}

.lista-avisos-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.8rem;
    color: #8b949e;
    margin-bottom: 10px;
}

.btn-link {
    background: transparent;
    border: none;
    color: #f72585;
    cursor: pointer;
    font-size: 0.78rem;
}

.btn-link:hover {
    text-decoration: underline;
}

.lista-avisos {
    list-style: none;
    max-height: 240px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 8px;
    touch-action: pan-y;
}

.aviso-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-left: 3px solid #f72585;
    padding: 10px 12px;
    border-radius: 6px;
    font-size: 0.82rem;
}

.aviso-item .aviso-hora {
    font-family: ui-monospace, monospace;
    color: #e6edf3;
    font-weight: 600;
}

.aviso-item .aviso-desc {
    color: #8b949e;
    font-size: 0.75rem;
}

/* ==========================================================================
   Footer
   ========================================================================== */
.app-footer {
    width: 100%;
    padding: 14px 16px;
    display: flex;
    justify-content: center;
    align-items: center;
}

.footer-copy {
    font-size: 0.8rem;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px;
}

.footer-copy a {
    color: var(--accent-green);
    text-decoration: none;
    font-weight: 500;
}

.footer-separator {
    color: var(--border-color);
}

.footer-version {
    font-family: ui-monospace, monospace;
    font-size: 0.75rem;
    background: rgba(0, 255, 136, 0.08);
    border: 1px solid rgba(0, 255, 136, 0.2);
    color: var(--accent-green);
    padding: 2px 6px;
    border-radius: 4px;
    font-weight: 600;
}

/* ==========================================================================
   Responsividade Mobile (Smartphones e Telas Pequenas)
   ========================================================================== */
@media (max-width: 600px) {
    body {
        padding-top: env(safe-area-inset-top, 0px);
    }

    .navbar {
        flex-direction: column;
        gap: 8px;
        padding: 10px 16px 4px;
        align-items: center;
    }

    .main-container {
        padding: 6px 16px;
    }

    .hero-text h1 {
        font-size: 1.12rem;
    }

    .camera-wrapper {
        width: fit-content;
        max-width: 88vw;
        margin-bottom: 10px;
    }

    #webcam {
        max-height: 44vh;
    }

    .controls-panel {
        max-width: 320px;
        flex-direction: column;
        gap: 8px;
        margin-bottom: 8px;
    }

    .controls-panel .btn,
    .badge-calibrada,
    .telemetry-bar {
        width: 100%;
        max-width: 320px;
        text-align: center;
        box-sizing: border-box;
    }

    .toast-container {
        right: 12px;
        left: 12px;
        bottom: 16px;
    }

    .toast {
        width: 100%;
        font-size: 0.8rem;
    }
}