:root {
    --primary: #0d6efd;
    --primary-dark: #0a58ca;
    --success: #198754;
    --warning: #ffc107;
    --danger: #dc3545;
    --bg: #f5f7fa;
    --card-bg: #ffffff;
    --text: #1e293b;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --radius: 12px;
    --nav-height: 64px;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
    padding-bottom: calc(var(--nav-height) + 72px);
}

/* Loading Screen */
.loading-screen {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100vh;
    color: var(--text-muted);
}

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

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

/* Page Container */
.page { padding: 16px; max-width: 480px; margin: 0 auto; animation: fadeIn 0.2s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

/* Header */
.page-header {
    padding: 20px 0 12px;
    margin-bottom: 16px;
}
.page-header h1 {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text);
}
.page-header p { color: var(--text-muted); font-size: 0.9rem; }

/* Cards */
.card {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 12px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
    border: 1px solid var(--border);
}
.card-title { font-size: 0.8rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 8px; font-weight: 600; }
.card-value { font-size: 1.5rem; font-weight: 700; }

/* Stats Row */
.stats-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 16px; }
.stat-card { text-align: center; }
.stat-card .card-value { color: var(--primary); }
.stat-card.warning .card-value { color: var(--warning); }
.stat-card.danger .card-value { color: var(--danger); }
.stat-card.success .card-value { color: var(--success); }

/* Fatura Item */
.fatura-item {
    display: flex;
    align-items: center;
    padding: 14px 16px;
    background: var(--card-bg);
    border-radius: var(--radius);
    margin-bottom: 8px;
    border: 1px solid var(--border);
    cursor: pointer;
    transition: transform 0.15s;
    text-decoration: none;
    color: inherit;
}
.fatura-item:active { transform: scale(0.98); }
.fatura-item .icon {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    margin-right: 12px;
    flex-shrink: 0;
}
.fatura-item .icon.pendente { background: #fff3cd; color: #856404; }
.fatura-item .icon.pago { background: #d1e7dd; color: #0f5132; }
.fatura-item .icon.vencido { background: #f8d7da; color: #842029; }
.fatura-item .info { flex: 1; }
.fatura-item .info .titulo { font-weight: 600; font-size: 0.95rem; }
.fatura-item .info .subtitulo { font-size: 0.8rem; color: var(--text-muted); }
.fatura-item .valor { text-align: right; }
.fatura-item .valor .preco { font-weight: 700; font-size: 1rem; }
.fatura-item .valor .vencimento { font-size: 0.75rem; color: var(--text-muted); }
.fatura-item .chevron { color: var(--text-muted); margin-left: 8px; }

/* Badge */
.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
}
.badge-pendente { background: #fff3cd; color: #856404; }
.badge-pago { background: #d1e7dd; color: #0f5132; }
.badge-vencido { background: #f8d7da; color: #842029; }
.badge-cancelado { background: #e2e3e5; color: #41464b; }
.badge-contato { background: #cff4fc; color: #055160; }
.badge-instalado { background: #d1e7dd; color: #0f5132; }

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 20px;
    border-radius: var(--radius);
    font-weight: 600;
    font-size: 0.95rem;
    border: none;
    cursor: pointer;
    transition: all 0.15s;
    text-decoration: none;
    width: 100%;
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-outline { background: transparent; border: 2px solid var(--primary); color: var(--primary); }
.btn-success { background: var(--success); color: white; }
.btn-danger { background: var(--danger); color: white; }
.btn-sm { padding: 8px 14px; font-size: 0.85rem; }
.btn-block { width: 100%; }

/* Form */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-weight: 600; font-size: 0.85rem; margin-bottom: 6px; color: var(--text); }
.form-input {
    width: 100%;
    padding: 12px 16px;
    border: 2px solid var(--border);
    border-radius: var(--radius);
    font-size: 1rem;
    transition: border-color 0.15s;
    background: var(--card-bg);
    color: var(--text);
}
.form-input:focus { outline: none; border-color: var(--primary); }
select.form-input {
    appearance: auto;
    -webkit-appearance: auto;
    cursor: pointer;
}

/* Login Page */
.login-page {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 24px;
    margin-bottom: calc((var(--nav-height) + 72px) * -1);
    background: linear-gradient(135deg, var(--primary) 0%, #1a1a2e 100%);
}
.login-card {
    background: white;
    border-radius: 20px;
    padding: 32px 24px;
    width: 100%;
    max-width: 380px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}
.login-logo { text-align: center; margin-bottom: 24px; }
.login-logo i { font-size: 3rem; color: var(--primary); }
.login-logo h2 { font-size: 1.3rem; margin-top: 8px; }
.login-error { background: #f8d7da; color: #842029; padding: 10px 14px; border-radius: 8px; font-size: 0.85rem; margin-bottom: 16px; }

/* Fatura Detalhe */
.fatura-detalhe-header {
    text-align: center;
    padding: 24px 16px;
    background: var(--card-bg);
    border-radius: var(--radius);
    margin-bottom: 16px;
    border: 1px solid var(--border);
}
.fatura-detalhe-header .valor { font-size: 2rem; font-weight: 700; color: var(--text); }
.fatura-detalhe-header .status { margin-top: 8px; }

.pix-box {
    background: #f0f9ff;
    border: 2px dashed var(--primary);
    border-radius: var(--radius);
    padding: 16px;
    text-align: center;
    margin-bottom: 12px;
}
.pix-box .code {
    background: white;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 10px;
    font-family: monospace;
    font-size: 0.75rem;
    word-break: break-all;
    margin: 12px 0;
    max-height: 80px;
    overflow-y: auto;
}

/* Indicações */
.share-box {
    background: linear-gradient(135deg, var(--primary) 0%, #6610f2 100%);
    border-radius: var(--radius);
    padding: 20px;
    color: white;
    text-align: center;
    margin-bottom: 16px;
}
.share-box h3 { font-size: 1.1rem; margin-bottom: 8px; }
.share-box .code {
    background: rgba(255,255,255,0.2);
    padding: 8px 16px;
    border-radius: 8px;
    font-family: monospace;
    font-size: 1.2rem;
    font-weight: 700;
    letter-spacing: 2px;
    display: inline-block;
    margin: 8px 0;
}
.share-box .btn { background: white; color: var(--primary); margin-top: 8px; width: auto; }

.indicacao-item {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    background: var(--card-bg);
    border-radius: var(--radius);
    margin-bottom: 8px;
    border: 1px solid var(--border);
}
.indicacao-item .avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--bg);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    color: var(--primary);
    margin-right: 12px;
    flex-shrink: 0;
}
.indicacao-item .info { flex: 1; }
.indicacao-item .info .nome { font-weight: 600; font-size: 0.95rem; }
.indicacao-item .info .tel { font-size: 0.8rem; color: var(--text-muted); }

/* Perfil */
.perfil-header {
    text-align: center;
    padding: 24px;
    background: var(--card-bg);
    border-radius: var(--radius);
    margin-bottom: 16px;
    border: 1px solid var(--border);
}
.perfil-header .avatar-lg {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: var(--primary);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    font-weight: 700;
    margin: 0 auto 12px;
}
.perfil-item {
    display: flex;
    align-items: center;
    padding: 14px 16px;
    background: var(--card-bg);
    border-radius: var(--radius);
    margin-bottom: 8px;
    border: 1px solid var(--border);
}
.perfil-item i { font-size: 1.2rem; color: var(--primary); margin-right: 12px; width: 24px; text-align: center; }
.perfil-item .label { font-size: 0.8rem; color: var(--text-muted); }
.perfil-item .value { font-weight: 600; }

/* Contrato card */
.contrato-card {
    background: linear-gradient(135deg, var(--primary) 0%, #0a58ca 100%);
    border-radius: var(--radius);
    padding: 20px;
    color: white;
    margin-bottom: 16px;
}
.contrato-card .plano { font-size: 1.1rem; font-weight: 700; }
.contrato-card .velocidade { font-size: 0.85rem; opacity: 0.9; }
.contrato-card .status-badge { background: rgba(255,255,255,0.2); padding: 4px 10px; border-radius: 20px; font-size: 0.75rem; }

/* Status Badges (global) */
.status-badge { display:inline-block; padding:3px 10px; border-radius:20px; font-size:0.7rem; font-weight:600; text-transform:capitalize; background:var(--bg); color:var(--text-muted); }
.status-badge.st-ativo { background:#dcfce7; color:#166534; }
.status-badge.st-reduzido { background:#fef3c7; color:#92400e; }
.status-badge.st-bloqueado { background:#fee2e2; color:#991b1b; }
.status-badge.st-cancelado { background:#f1f5f9; color:#64748b; }
.status-badge.st-teste { background:#e0e7ff; color:#3730a3; }

/* Bottom Navigation */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: var(--nav-height);
    background: var(--card-bg);
    display: flex;
    align-items: center;
    justify-content: space-around;
    border-top: 1px solid var(--border);
    z-index: 1000;
    padding-bottom: env(safe-area-inset-bottom);
}
.bottom-nav .nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-decoration: none;
    color: var(--text-muted);
    font-size: 0.7rem;
    padding: 6px 12px;
    transition: color 0.15s;
}
.bottom-nav .nav-item i { font-size: 1.3rem; margin-bottom: 2px; }
.bottom-nav .nav-item.active { color: var(--primary); }

/* Toast Notification */
.toast {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--text);
    color: white;
    padding: 12px 20px;
    border-radius: var(--radius);
    font-size: 0.9rem;
    z-index: 9999;
    animation: slideDown 0.3s ease;
    max-width: 90%;
}
.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }
@keyframes slideDown { from { transform: translateX(-50%) translateY(-20px); opacity: 0; } to { transform: translateX(-50%) translateY(0); opacity: 1; } }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.4; } }

/* Back button */
.back-btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    color: var(--primary);
    font-weight: 600;
    font-size: 0.9rem;
    text-decoration: none;
    margin-bottom: 12px;
    cursor: pointer;
    background: none;
    border: none;
    padding: 0;
}

/* Section Title */
.section-title {
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin: 20px 0 10px;
}

/* Timeline */
.timeline { position: relative; padding-left: 24px; }
.timeline-item { position: relative; padding-bottom: 20px; padding-left: 16px; }
.timeline-item:last-child { padding-bottom: 0; }
.timeline-item::before { content: ''; position: absolute; left: -24px; top: 14px; bottom: 0; width: 2px; background: var(--border); }
.timeline-item:last-child::before { display: none; }
.timeline-dot { position: absolute; left: -30px; top: 4px; width: 14px; height: 14px; border-radius: 50%; border: 3px solid white; box-shadow: 0 0 0 1px rgba(0,0,0,0.1); z-index: 1; }
.timeline-active .timeline-dot { width: 16px; height: 16px; left: -31px; top: 3px; }
.timeline-content { min-height: 20px; }

/* Modal overlay */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: flex-end;
    justify-content: center;
    z-index: 2000;
    animation: fadeIn 0.2s;
}
.modal-content {
    background: white;
    border-radius: 20px 20px 0 0;
    padding: 24px;
    width: 100%;
    max-width: 480px;
    max-height: 80vh;
    overflow-y: auto;
    animation: slideUp 0.3s ease;
}
@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }
.modal-content h3 { margin-bottom: 16px; }

/* WhatsApp FAB */
.whatsapp-fab {
    position: fixed;
    bottom: calc(var(--nav-height) + 16px);
    right: 16px;
    width: 52px;
    height: 52px;
    border-radius: 50%;
    background: #25d366;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    box-shadow: 0 4px 12px rgba(37,211,102,0.4);
    text-decoration: none;
    z-index: 999;
    transition: transform 0.2s, box-shadow 0.2s;
}
.whatsapp-fab:active { transform: scale(0.92); }

/* Speedtest options */
.speedtest-option {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 16px;
    margin-bottom: 10px;
    text-decoration: none;
    color: inherit;
    cursor: pointer;
    transition: transform 0.15s;
}
.speedtest-option:active { transform: scale(0.98); }
.speedtest-icon {
    width: 46px;
    height: 46px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

/* Chat Bubbles */
.chat-container {
    background: var(--bg);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    margin-bottom: 12px;
}
.chat-messages {
    max-height: 400px;
    overflow-y: auto;
    padding: 12px;
    scroll-behavior: smooth;
}
.chat-date-sep {
    text-align: center;
    margin: 12px 0;
}
.chat-date-sep span {
    background: var(--border);
    color: var(--text-muted);
    font-size: 0.7rem;
    padding: 3px 10px;
    border-radius: 10px;
}
.chat-bubble {
    max-width: 80%;
    padding: 8px 12px;
    border-radius: 12px;
    margin-bottom: 6px;
    animation: fadeIn 0.2s ease;
    clear: both;
}
.chat-right {
    background: var(--primary);
    color: white;
    margin-left: auto;
    border-bottom-right-radius: 4px;
}
.chat-left {
    background: var(--card-bg);
    border: 1px solid var(--border);
    color: var(--text);
    margin-right: auto;
    border-bottom-left-radius: 4px;
}
.chat-sender {
    font-size: 0.7rem;
    font-weight: 700;
    color: var(--primary);
    margin-bottom: 2px;
}
.chat-right .chat-sender { color: rgba(255,255,255,0.8); }
.chat-text { font-size: 0.85rem; line-height: 1.4; word-break: break-word; }
.chat-time { font-size: 0.65rem; opacity: 0.7; text-align: right; margin-top: 2px; }
.chat-sending { opacity: 0.7; }
.chat-input-bar {
    position: fixed;
    bottom: var(--nav-height);
    left: 0;
    right: 0;
    display: flex;
    gap: 8px;
    padding: 8px 12px;
    background: var(--card-bg);
    border-top: 1px solid var(--border);
    z-index: 100;
    max-width: 480px;
    margin: 0 auto;
}
.chat-input {
    flex: 1;
    padding: 10px 14px;
    border: 2px solid var(--border);
    border-radius: 20px;
    font-size: 0.9rem;
    background: var(--bg);
    color: var(--text);
    outline: none;
}
.chat-input:focus { border-color: var(--primary); }
.chat-send-btn {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: var(--primary);
    color: white;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    cursor: pointer;
    flex-shrink: 0;
}
.chat-send-btn:disabled { opacity: 0.5; }

/* Comprovante */
.comprovante-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 0;
    font-size: 0.85rem;
}
.comprovante-row span { color: var(--text-muted); }
.comprovante-row strong { text-align: right; max-width: 60%; }

/* Empty state */
.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-muted);
}
.empty-state i { font-size: 3rem; margin-bottom: 12px; display: block; }

/* Dark Mode */
html.dark {
    --bg: #0f172a;
    --card-bg: #1e293b;
    --text: #f1f5f9;
    --text-muted: #94a3b8;
    --border: #334155;
    --primary-dark: #3b82f6;
}
html.dark body { background: var(--bg); color: var(--text); }
html.dark .login-card { background: var(--card-bg); color: var(--text); }
html.dark .login-page { background: linear-gradient(135deg, #1e293b 0%, #0f172a 100%); }
html.dark .modal-content { background: var(--card-bg); color: var(--text); }
html.dark .pix-box { background: #1a2744; border-color: var(--primary); }
html.dark .pix-box .code { background: #0f172a; border-color: var(--border); color: var(--text); }
html.dark .toast { background: #334155; }
html.dark .chat-date-sep span { background: #334155; }
html.dark .login-error { background: #451a1a; color: #fca5a5; }
html.dark .badge-pendente { background: #422006; color: #fbbf24; }
html.dark .badge-pago { background: #052e16; color: #4ade80; }
html.dark .badge-vencido { background: #450a0a; color: #f87171; }
html.dark .badge-cancelado { background: #1e293b; color: #94a3b8; }
html.dark .fatura-item .icon.pendente { background: #422006; color: #fbbf24; }
html.dark .fatura-item .icon.pago { background: #052e16; color: #4ade80; }
html.dark .fatura-item .icon.vencido { background: #450a0a; color: #f87171; }
html.dark .contrato-card { background: linear-gradient(135deg, #1e3a5f 0%, #0f172a 100%); }
html.dark input, html.dark select, html.dark textarea { background: #0f172a; color: var(--text); border-color: var(--border); }
html.dark .btn-outline { border-color: var(--primary); color: var(--primary); }
