:root {
    --bg-base: #0a0e17;
    --bg-surface: rgba(17, 24, 39, 0.7);
    --bg-surface-hover: rgba(31, 41, 55, 0.8);
    --text-primary: #f3f4f6;
    --text-secondary: #9ca3af;
    --border-color: rgba(255, 255, 255, 0.1);
    
    --accent-primary: #3b82f6;
    --accent-primary-hover: #2563eb;
    --accent-success: #10b981;
    --accent-danger: #ef4444;
    --accent-danger-hover: #dc2626;
    
    --radius-sm: 6px;
    --radius-md: 12px;
    --radius-lg: 16px;
    
    --shadow-glass: 0 4px 30px rgba(0, 0, 0, 0.5);
}

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

body {
    font-family: 'Inter', system-ui, sans-serif;
    background-color: var(--bg-base);
    color: var(--text-primary);
    line-height: 1.5;
    min-height: 100vh;
    overflow-x: hidden;
    /* Adiciona um gradiente radial de fundo sutil para não ficar chapado */
    background-image: radial-gradient(circle at top right, rgba(59, 130, 246, 0.1), transparent 40%),
                      radial-gradient(circle at bottom left, rgba(16, 185, 129, 0.05), transparent 40%);
}

#app-container {
    width: 100%;
    height: 100vh;
    display: flex;
    flex-direction: column;
}

/* -------------------------------------------------------------------------- */
/* Utilities & Glassmorphism */
/* -------------------------------------------------------------------------- */

.hidden {
    display: none !important;
}

.glass-panel {
    background: var(--bg-surface);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-glass);
}

.w-full { width: 100%; }
.mt-4 { margin-top: 1rem; }
.mt-auto { margin-top: auto; }

/* -------------------------------------------------------------------------- */
/* Typography */
/* -------------------------------------------------------------------------- */

h1, h2, h3, h4 {
    font-weight: 600;
    line-height: 1.2;
}

/* -------------------------------------------------------------------------- */
/* Forms & Buttons */
/* -------------------------------------------------------------------------- */

.input-group {
    margin-bottom: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.input-group label {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

input[type="text"],
input[type="password"] {
    width: 100%;
    padding: 0.75rem 1rem;
    border-radius: var(--radius-sm);
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    font-family: inherit;
    transition: border-color 0.2s, box-shadow 0.2s;
}

input[type="text"]:focus,
input[type="password"]:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.25);
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.75rem 1.5rem;
    border-radius: var(--radius-sm);
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    border: none;
    font-family: inherit;
    font-size: 0.875rem;
}

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

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

.btn-secondary {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}
.btn-secondary:hover:not(:disabled) {
    background: rgba(255, 255, 255, 0.15);
}

.btn-danger {
    background: rgba(239, 68, 68, 0.1);
    color: var(--accent-danger);
    border: 1px solid rgba(239, 68, 68, 0.2);
}
.btn-danger:hover:not(:disabled) {
    background: var(--accent-danger);
    color: white;
}

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
}
.btn-ghost:hover:not(:disabled) {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-primary);
}

.icon-btn {
    padding: 0.5rem;
}

.input-with-button {
    display: flex;
    gap: 0.5rem;
}

/* -------------------------------------------------------------------------- */
/* Views Layout */
/* -------------------------------------------------------------------------- */

.view {
    flex: 1;
    display: flex;
    flex-direction: column;
}

/* --- Login View --- */
#login-view {
    align-items: center;
    justify-content: center;
}

.login-card {
    width: 100%;
    max-width: 400px;
    padding: 2rem;
    border-radius: var(--radius-md);
}

.login-header {
    text-align: center;
    margin-bottom: 2rem;
}
.login-header p {
    color: var(--text-secondary);
    font-size: 0.875rem;
    margin-top: 0.5rem;
}

hr {
    border: none;
    border-top: 1px solid var(--border-color);
    margin: 1.5rem 0;
}

.qrcode-wrapper {
    background: white;
    padding: 1rem;
    border-radius: var(--radius-sm);
    display: inline-block;
    margin: 1rem 0;
}

.secret-text {
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin-bottom: 1rem;
}

/* --- Devices View --- */
.app-header {
    height: 64px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 2rem;
    border-bottom: 1px solid var(--border-color);
    border-top: none;
    border-left: none;
    border-right: none;
    border-radius: 0;
}

.header-title {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.badge {
    background: rgba(255, 255, 255, 0.1);
    padding: 0.25rem 0.75rem;
    border-radius: 999px;
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.status-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.25rem 0.75rem;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 500;
}
.status-badge::before {
    content: '';
    width: 6px;
    height: 6px;
    border-radius: 50%;
}
.status-badge.online {
    background: rgba(16, 185, 129, 0.1);
    color: var(--accent-success);
}
.status-badge.online::before { background: var(--accent-success); }

.status-badge.connecting {
    background: rgba(245, 158, 11, 0.1);
    color: #fbbf24;
}
.status-badge.connecting::before { background: #fbbf24; }

.status-badge.offline, .status-badge.in-use {
    background: rgba(239, 68, 68, 0.1);
    color: var(--accent-danger);
}
.status-badge.offline::before, .status-badge.in-use::before { background: var(--accent-danger); }


.devices-main {
    padding: 2rem;
    max-width: 1200px;
    margin: 0 auto;
    width: 100%;
}

.devices-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
}

.devices-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 1.5rem;
}

.device-card {
    padding: 1.5rem;
    border-radius: var(--radius-md);
    display: flex;
    flex-direction: column;
    gap: 1rem;
    transition: transform 0.2s, box-shadow 0.2s;
}
.device-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.6);
}

.device-card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
}
.device-card-header h4 {
    font-size: 1.125rem;
    margin-bottom: 0.25rem;
}
.device-card-header p {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.empty-state {
    text-align: center;
    padding: 4rem;
    color: var(--text-secondary);
    background: rgba(255, 255, 255, 0.02);
    border-radius: var(--radius-md);
    border: 1px dashed var(--border-color);
}

/* --- Viewport View --- */
.viewport-layout {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

.viewport-sidebar {
    width: 320px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    padding: 1.5rem;
    border-radius: 0;
    border-left: none;
    border-top: none;
    border-bottom: none;
    z-index: 10;
}

.sidebar-header {
    margin-bottom: 2rem;
}
.sidebar-header h3 {
    margin-bottom: 0.5rem;
    word-break: break-all;
}

.action-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 0.5rem;
    margin-top: 1rem;
}

.stat-row {
    display: flex;
    justify-content: space-between;
    font-size: 0.75rem;
    color: var(--text-secondary);
    padding: 0.5rem 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}
.stat-row:last-child {
    border-bottom: none;
}

.viewport-main {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #000; /* Fundo totalmente escuro para contraste com a tela */
    padding: 2rem;
    position: relative;
}

.viewport-container {
    position: relative;
    /* Tamanho será dinâmico via JS para manter aspect ratio */
    max-width: 100%;
    max-height: 100%;
    box-shadow: 0 0 40px rgba(0,0,0,0.8);
}

#vp-canvas-screen {
    display: block;
    width: 100%;
    height: 100%;
    /* Interpolação suave ao fazer scale do canvas */
    image-rendering: -webkit-optimize-contrast;
}

#vp-canvas-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none; /* Deixa os cliques passarem pro container */
}

/* -------------------------------------------------------------------------- */
/* Toasts */
/* -------------------------------------------------------------------------- */

.toast-container {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    z-index: 9999;
    pointer-events: none;
}

.toast {
    background: var(--bg-surface);
    backdrop-filter: blur(8px);
    border: 1px solid var(--border-color);
    padding: 1rem 1.5rem;
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
    pointer-events: auto;
    animation: toast-in 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.toast.error { border-left: 4px solid var(--accent-danger); }
.toast.success { border-left: 4px solid var(--accent-success); }
.toast.info { border-left: 4px solid var(--accent-primary); }

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

.toast.hiding {
    animation: toast-out 0.3s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

@keyframes toast-out {
    to { transform: translateX(100%); opacity: 0; }
}
