/* ============================================
   QrLogin PWA - Styles
   ============================================ */

:root {
    --primary: #4361ee;
    --primary-dark: #3651d4;
    --success: #10b981;
    --danger: #ef4444;
    --warning: #f59e0b;
    --bg: #f8fafc;
    --card: #ffffff;
    --text: #1e293b;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --shadow: 0 4px 6px -1px rgba(0,0,0,0.1);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    overflow-x: hidden;
}

#app {
    max-width: 480px;
    margin: 0 auto;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Header */
.header {
    background: var(--primary);
    color: white;
    padding: 16px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 100;
}

.header h1 {
    font-size: 20px;
    font-weight: 600;
}

.header .status {
    font-size: 12px;
    background: rgba(255,255,255,0.2);
    padding: 4px 12px;
    border-radius: 12px;
}

/* Screens */
.screen {
    display: none;
    flex: 1;
    padding: 20px;
}

.screen.active {
    display: flex;
    flex-direction: column;
}

/* Scanner */
.scanner-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

#qr-reader {
    width: 100%;
    max-width: 350px;
    border-radius: 16px;
    overflow: hidden;
    box-shadow: var(--shadow);
}

#qr-reader video {
    border-radius: 16px;
}

.hint {
    margin-top: 20px;
    color: var(--text-muted);
    text-align: center;
}

/* Buttons */
.btn {
    padding: 14px 24px;
    border: none;
    border-radius: 12px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.btn:active {
    transform: scale(0.98);
}

.btn-primary {
    background: var(--primary);
    color: white;
}

.btn-primary:hover {
    background: var(--primary-dark);
}

.btn-secondary {
    background: var(--border);
    color: var(--text);
    margin-top: 20px;
}

.btn-success {
    background: var(--success);
    color: white;
    flex: 1;
}

.btn-danger {
    background: var(--danger);
    color: white;
    flex: 1;
}

/* Confirm Screen */
.confirm-card {
    background: var(--card);
    border-radius: 20px;
    padding: 30px 20px;
    box-shadow: var(--shadow);
    text-align: center;
}

.confirm-icon {
    font-size: 64px;
    margin-bottom: 16px;
}

.confirm-card h2 {
    margin-bottom: 20px;
    color: var(--text);
}

.device-info {
    background: var(--bg);
    border-radius: 12px;
    padding: 16px;
    margin: 20px 0;
    text-align: left;
}

.device-info p {
    margin: 8px 0;
    font-size: 14px;
    color: var(--text-muted);
}

.device-info strong {
    color: var(--text);
}

.warning {
    color: var(--warning);
    font-size: 14px;
    margin-bottom: 20px;
    font-weight: 500;
}

.confirm-buttons {
    display: flex;
    gap: 12px;
}

/* Result Screen */
.result-card {
    background: var(--card);
    border-radius: 20px;
    padding: 40px 20px;
    box-shadow: var(--shadow);
    text-align: center;
}

.result-card.success .result-icon {
    color: var(--success);
}

.result-card.error .result-icon {
    color: var(--danger);
}

.result-icon {
    font-size: 72px;
    margin-bottom: 20px;
}

.result-card h2 {
    margin-bottom: 12px;
}

.result-card p {
    color: var(--text-muted);
    margin-bottom: 30px;
}

/* Login Screen */
.login-card {
    background: var(--card);
    border-radius: 20px;
    padding: 30px 20px;
    box-shadow: var(--shadow);
    text-align: center;
}

.login-card h2 {
    margin-bottom: 12px;
}

.login-card > p {
    color: var(--text-muted);
    margin-bottom: 24px;
}

#login-form {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

#login-form input {
    padding: 14px 16px;
    border: 2px solid var(--border);
    border-radius: 12px;
    font-size: 16px;
    transition: border-color 0.2s;
}

#login-form input:focus {
    outline: none;
    border-color: var(--primary);
}

.error {
    color: var(--danger);
    font-size: 14px;
    margin-top: 12px;
}

/* Loading */
.loading {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.loading.hidden {
    display: none;
}

.spinner {
    width: 48px;
    height: 48px;
    border: 4px solid rgba(255,255,255,0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.loading p {
    color: white;
    margin-top: 16px;
}

/* Responsive */
@media (max-width: 380px) {
    .confirm-buttons {
        flex-direction: column;
    }
}

/* PWA Install Prompt */
.install-prompt {
    position: fixed;
    bottom: 20px;
    left: 20px;
    right: 20px;
    background: var(--card);
    padding: 16px;
    border-radius: 16px;
    box-shadow: var(--shadow);
    display: flex;
    align-items: center;
    gap: 12px;
}

.install-prompt.hidden {
    display: none;
}

/* ============================================
   Accounts Management
   ============================================ */

/* Botao de contas no header */
.btn-icon {
    background: transparent;
    border: none;
    color: white;
    padding: 8px;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.2s;
}

.btn-icon:hover {
    background: rgba(255,255,255,0.2);
}

/* Lista de contas */
.accounts-card,
.select-account-card {
    background: var(--card);
    border-radius: 20px;
    padding: 30px 20px;
    box-shadow: var(--shadow);
}

.accounts-card h2,
.select-account-card h2 {
    text-align: center;
    margin-bottom: 8px;
}

.select-account-card .subtitle {
    text-align: center;
    color: var(--text-muted);
    margin-bottom: 24px;
}

.accounts-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin: 20px 0;
}

.account-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    background: var(--bg);
    border-radius: 12px;
    transition: all 0.2s;
}

.account-item.selectable {
    cursor: pointer;
}

.account-item.selectable:hover {
    background: var(--border);
    transform: translateX(4px);
}

.account-avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--primary);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    font-weight: 600;
    flex-shrink: 0;
}

.account-info {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.account-name {
    font-weight: 600;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.account-label {
    font-size: 13px;
    color: var(--primary);
    font-weight: 500;
}

.account-url {
    font-size: 12px;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.btn-delete {
    background: transparent;
    border: none;
    color: var(--text-muted);
    padding: 8px;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-delete:hover {
    background: rgba(239, 68, 68, 0.1);
    color: var(--danger);
}

.no-accounts {
    text-align: center;
    color: var(--text-muted);
    padding: 30px;
}

/* Conta selecionada na tela de confirmacao */
.selected-account {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    background: rgba(67, 97, 238, 0.1);
    border: 2px solid var(--primary);
    border-radius: 12px;
    margin: 16px 0;
}

.selected-account .account-avatar {
    width: 40px;
    height: 40px;
    font-size: 14px;
}

.selected-account .account-details {
    display: flex;
    flex-direction: column;
    text-align: left;
}

.selected-account .account-name {
    font-size: 14px;
}

.selected-account .account-label {
    font-size: 12px;
}

/* Form de adicionar conta */
#add-account-form {
    display: flex;
    flex-direction: column;
    gap: 16px;
    text-align: left;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.form-group label {
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
}

.form-group input {
    padding: 12px 14px;
    border: 2px solid var(--border);
    border-radius: 10px;
    font-size: 15px;
    transition: border-color 0.2s;
}

.form-group input:focus {
    outline: none;
    border-color: var(--primary);
}

.form-group small {
    font-size: 12px;
    color: var(--text-muted);
}

#btn-cancel-add {
    margin-top: 12px;
}

/* ============================================
   Restricao de Rede
   ============================================ */

.form-section {
    margin: 16px 0;
    padding: 16px;
    background: var(--bg);
    border-radius: 10px;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    font-weight: 500;
}

.checkbox-label input[type="checkbox"] {
    width: 20px;
    height: 20px;
    accent-color: var(--primary);
}

.form-section small {
    display: block;
    margin-top: 6px;
    margin-left: 30px;
    color: var(--text-muted);
    font-size: 12px;
}

.network-config {
    margin-top: 12px;
    padding: 16px;
    background: rgba(67, 97, 238, 0.05);
    border: 1px solid var(--primary);
    border-radius: 10px;
}

.network-config.hidden {
    display: none;
}

.btn-small {
    padding: 10px 16px;
    font-size: 13px;
    background: var(--border);
    color: var(--text);
    border: none;
    border-radius: 8px;
    cursor: pointer;
    width: 100%;
    margin-top: 8px;
}

.btn-small:hover {
    background: #d1d5db;
}

/* Badge de restricao de rede */
.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
}

.badge-network {
    background: rgba(16, 185, 129, 0.15);
    color: var(--success);
}

.account-name-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Tela de selecao com indicador de rede */
.account-item.selectable .badge-network {
    background: rgba(16, 185, 129, 0.2);
}

/* Secao do Beacon */
.beacon-section {
    margin-top: 20px;
    padding-top: 16px;
    border-top: 1px dashed var(--border);
}

.beacon-section h4 {
    font-size: 14px;
    color: var(--text);
    margin-bottom: 4px;
}

.beacon-section > small {
    display: block;
    color: var(--text-muted);
    font-size: 12px;
    margin-bottom: 16px;
}

.beacon-section .form-group {
    margin-bottom: 12px;
}

.badge-beacon {
    background: rgba(67, 97, 238, 0.15);
    color: var(--primary);
}

/* ============================================
   Login Screen
   ============================================ */

.login-logo {
    width: 80px;
    height: 80px;
    margin: 0 auto 16px;
    background: var(--primary);
    border-radius: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
}

.login-help {
    margin-top: 24px;
    color: var(--text-muted);
}

#login-form {
    text-align: left;
}

#login-form .form-group {
    margin-bottom: 16px;
}

/* ============================================
   Utility Classes
   ============================================ */

.btn-block {
    width: 100%;
}

.divider {
    border: none;
    border-top: 1px solid var(--border);
    margin: 20px 0;
}

.hidden {
    display: none !important;
}
