/* ============================================================
   RESET & VARIÁVEIS GLOBAIS
============================================================ */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --primary:        #6C63FF;
    --primary-light:  #8B85FF;
    --primary-dark:   #5A52D5;
    --success:        #22C55E;
    --danger:         #EF4444;
    --warning:        #F59E0B;
    --bg:             #F0F2F8;
    --surface:        #FFFFFF;
    --surface2:       #F8F9FC;
    --border:         #E2E8F0;
    --text:           #1E293B;
    --text-muted:     #64748B;
    --text-light:     #94A3B8;
    --shadow:         0 2px 16px rgba(108,99,255,0.08);
    --shadow-md:      0 4px 24px rgba(108,99,255,0.14);
    --radius:         16px;
    --radius-sm:      10px;
    --nav-height:     72px;
    --transition:     0.25s cubic-bezier(0.4,0,0.2,1);
}

html, body {
    height: 100%;
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: var(--bg);
    color: var(--text);
    overflow-x: hidden;
}

/* ============================================================
   LAYOUT
============================================================ */
#app {
    max-width: 480px;
    margin: 0 auto;
    min-height: 100vh;
    background: var(--bg);
    position: relative;
}

@media (min-width: 768px) {
    #app {
        max-width: 100%;
        display: flex;
        flex-direction: column;
    }
    #bottom-nav {
        position: fixed;
        top: 0; left: 0;
        width: 240px;
        height: 100vh;
        flex-direction: column;
        padding: 32px 16px;
        background: var(--surface);
        border-right: 1px solid var(--border);
        border-bottom: none;
        justify-content: flex-start;
        gap: 8px;
    }
    .nav-btn {
        flex-direction: row;
        gap: 12px;
        padding: 14px 18px;
        border-radius: var(--radius-sm);
        justify-content: flex-start;
    }
    .nav-btn .nav-label {
        font-size: 0.95rem;
        opacity: 1;
    }
    .nav-logo { display: flex !important; }
    .screen { padding: 32px 32px calc(40px) 32px; margin-left: 240px; max-width: 900px; }
}

/* ============================================================
   HEADER MOBILE
============================================================ */
.app-header {
    padding: 20px 20px 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.app-header h1 { font-size: 1.4rem; font-weight: 700; color: var(--primary); }
.app-header .subtitle { font-size: 0.8rem; color: var(--text-muted); }

@media (min-width: 768px) { .app-header { display: none; } }

/* ============================================================
   NAVEGAÇÃO
============================================================ */
#bottom-nav {
    position: fixed;
    bottom: 0; left: 0; right: 0;
    display: flex;
    background: var(--surface);
    border-top: 1px solid var(--border);
    padding: 8px 0 env(safe-area-inset-bottom);
    z-index: 1000;
    box-shadow: 0 -4px 20px rgba(0,0,0,0.06);
}

.nav-logo {
    display: none;
    padding: 16px 18px 24px;
    font-size: 1.2rem;
    font-weight: 800;
    color: var(--primary);
    letter-spacing: -0.5px;
}

.nav-btn {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 8px 4px;
    border: none;
    background: none;
    cursor: pointer;
    color: var(--text-muted);
    transition: color var(--transition);
    border-radius: var(--radius-sm);
}

.nav-btn svg { width: 22px; height: 22px; transition: transform var(--transition); }
.nav-btn .nav-label { font-size: 0.7rem; font-weight: 600; opacity: 0.8; }
.nav-btn.active { color: var(--primary); }
.nav-btn.active svg { transform: scale(1.15); }

.nav-indicator {
    width: 4px; height: 4px;
    border-radius: 50%;
    background: var(--primary);
    margin-top: 2px;
    opacity: 0;
    transition: opacity var(--transition);
}
.nav-btn.active .nav-indicator { opacity: 1; }

/* ============================================================
   TELAS
============================================================ */
.screen {
    display: none;
    padding: 16px 16px calc(var(--nav-height) + 16px);
    min-height: 100vh;
    animation: fadeIn 0.3s ease;
}
.screen.active { display: block; }

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}

.screen-title {
    font-size: 1.5rem;
    font-weight: 800;
    color: var(--text);
    margin-bottom: 4px;
}
.screen-subtitle {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 20px;
}

/* ============================================================
   CARDS
============================================================ */
.card {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow);
    margin-bottom: 16px;
}
.card-title {
    font-size: 0.8rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--text-muted);
    margin-bottom: 12px;
}

/* ============================================================
   DASHBOARD — PATRIMÔNIO
============================================================ */
.total-patrimonio {
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    border-radius: var(--radius);
    padding: 24px 20px;
    color: white;
    margin-bottom: 16px;
    position: relative;
    overflow: hidden;
}
.total-patrimonio::after {
    content: '';
    position: absolute;
    top: -40px; right: -40px;
    width: 160px; height: 160px;
    border-radius: 50%;
    background: rgba(255,255,255,0.06);
}
.total-patrimonio::before {
    content: '';
    position: absolute;
    bottom: -60px; right: 20px;
    width: 200px; height: 200px;
    border-radius: 50%;
    background: rgba(255,255,255,0.04);
}
.total-patrimonio .label  { font-size: 0.82rem; opacity: 0.85; font-weight: 500; margin-bottom: 6px; }
.total-patrimonio .valor  { font-size: 2.2rem; font-weight: 800; letter-spacing: -1px; position: relative; z-index: 1; }
.total-patrimonio .meta   { font-size: 0.78rem; opacity: 0.7; margin-top: 4px; }

/* ============================================================
   SUMMARY GRID (DASHBOARD)
============================================================ */
.summary-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    margin-bottom: 16px;
}
.summary-item {
    background: var(--surface);
    border-radius: var(--radius-sm);
    padding: 14px 12px;
    text-align: center;
    box-shadow: var(--shadow);
}
.summary-item .si-label { font-size: 0.72rem; color: var(--text-muted); font-weight: 600; margin-bottom: 6px; }
.summary-item .si-valor { font-size: 0.9rem; font-weight: 800; color: var(--text); }
.summary-item .si-dot   { width: 8px; height: 8px; border-radius: 50%; margin: 0 auto 6px; }

/* ============================================================
   GRÁFICOS
============================================================ */
.chart-container {
    position: relative;
    height: 220px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.chart-empty {
    text-align: center;
    color: var(--text-muted);
    font-size: 0.85rem;
    padding: 20px;
    line-height: 1.6;
}
.chart-empty svg {
    width: 48px; height: 48px;
    opacity: 0.3;
    display: block;
    margin: 0 auto 8px;
}

/* ============================================================
   SEARCH BAR E SORT
============================================================ */
.search-bar {
    display: flex;
    gap: 8px;
    margin-bottom: 14px;
}
.search-bar input {
    flex: 1;
    padding: 12px 16px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    background: var(--surface);
    color: var(--text);
    transition: border-color var(--transition);
    outline: none;
}
.search-bar input:focus { border-color: var(--primary); }

.sort-btn {
    padding: 12px 14px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text-muted);
    cursor: pointer;
    font-size: 0.8rem;
    font-weight: 600;
    white-space: nowrap;
    transition: all var(--transition);
}
.sort-btn:hover { border-color: var(--primary); color: var(--primary); }

/* ============================================================
   LISTA DE ATIVOS
============================================================ */
.asset-list { display: flex; flex-direction: column; gap: 10px; }

.asset-item {
    background: var(--surface);
    border-radius: var(--radius-sm);
    padding: 14px 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    box-shadow: var(--shadow);
    transition: transform var(--transition), box-shadow var(--transition);
    animation: slideIn 0.3s ease;
}
@keyframes slideIn {
    from { opacity: 0; transform: translateX(-10px); }
    to   { opacity: 1; transform: translateX(0); }
}
.asset-item:hover { transform: translateY(-1px); box-shadow: var(--shadow-md); }

.asset-icon {
    width: 40px; height: 40px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    flex-shrink: 0;
}
.asset-icon.fixa    { background: #EEF2FF; }
.asset-icon.variavel{ background: #F0FDF4; }
.asset-icon.cripto  { background: #FFF7ED; }

.asset-info { flex: 1; min-width: 0; }
.asset-name {
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.asset-type  { font-size: 0.72rem; color: var(--text-muted); font-weight: 500; margin-top: 2px; }

.asset-values { text-align: right; flex-shrink: 0; }
.asset-valor   { font-size: 0.95rem; font-weight: 800; color: var(--text); }
.asset-percent { font-size: 0.75rem; color: var(--text-muted); font-weight: 600; margin-top: 2px; }

.asset-actions { display: flex; gap: 6px; flex-shrink: 0; }

/* ============================================================
   BOTÕES DE ÍCONE (EDITAR / REMOVER)
============================================================ */
.btn-icon {
    width: 32px; height: 32px;
    border-radius: 8px;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition);
}
.btn-icon svg { width: 15px; height: 15px; }
.btn-icon.edit        { background: #EEF2FF; color: var(--primary); }
.btn-icon.edit:hover  { background: var(--primary); color: white; }
.btn-icon.del         { background: #FEF2F2; color: var(--danger); }
.btn-icon.del:hover   { background: var(--danger); color: white; }

/* ============================================================
   CRIPTOMOEDAS — CARDS DE PERFORMANCE
============================================================ */
.cripto-item {
    background: var(--surface);
    border-radius: var(--radius-sm);
    padding: 14px 16px;
    box-shadow: var(--shadow);
    margin-bottom: 10px;
    animation: slideIn 0.3s ease;
}
.cripto-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
}
.cripto-body {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}
.cripto-field label {
    font-size: 0.72rem;
    color: var(--text-muted);
    font-weight: 600;
    display: block;
    margin-bottom: 4px;
}
.cripto-field input {
    width: 100%;
    padding: 8px 10px;
    border: 1.5px solid var(--border);
    border-radius: 8px;
    font-size: 0.85rem;
    background: var(--surface2);
    color: var(--text);
    outline: none;
    transition: border-color var(--transition);
}
.cripto-field input:focus { border-color: var(--primary); background: white; }

.cripto-performance {
    margin-top: 10px;
    padding: 10px 12px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 0.82rem;
    font-weight: 700;
}
.cripto-performance.lucro    { background: #F0FDF4; color: var(--success); }
.cripto-performance.prejuizo { background: #FEF2F2; color: var(--danger); }
.cripto-performance.neutro   { background: var(--surface2); color: var(--text-muted); }

/* ============================================================
   BOTÕES PRIMÁRIO E SECUNDÁRIO
============================================================ */
.btn-primary {
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    padding: 14px 20px;
    font-size: 0.9rem;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: all var(--transition);
    box-shadow: 0 4px 12px rgba(108,99,255,0.3);
    width: 100%;
    justify-content: center;
    margin-bottom: 16px;
}
.btn-primary:hover  { transform: translateY(-1px); box-shadow: 0 6px 20px rgba(108,99,255,0.4); }
.btn-primary:active { transform: translateY(0); }

.btn-secondary {
    background: var(--surface);
    color: var(--primary);
    border: 1.5px solid var(--primary);
    border-radius: var(--radius-sm);
    padding: 12px 20px;
    font-size: 0.88rem;
    font-weight: 700;
    cursor: pointer;
    transition: all var(--transition);
    width: 100%;
}
.btn-secondary:hover { background: #EEF2FF; }

/* ============================================================
   MODAL
============================================================ */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15,23,42,0.5);
    backdrop-filter: blur(4px);
    z-index: 2000;
    align-items: flex-end;
    justify-content: center;
    padding: 16px;
}
.modal-overlay.open { display: flex; animation: overlayIn 0.2s ease; }

@keyframes overlayIn { from { opacity: 0; } to { opacity: 1; } }

.modal {
    background: var(--surface);
    border-radius: var(--radius) var(--radius) 0 0;
    padding: 24px 20px;
    width: 100%;
    max-width: 480px;
    animation: modalIn 0.3s cubic-bezier(0.4,0,0.2,1);
    max-height: 90vh;
    overflow-y: auto;
}
@media (min-width: 768px) {
    .modal-overlay { align-items: center; }
    .modal { border-radius: var(--radius); max-width: 440px; }
}
@keyframes modalIn {
    from { transform: translateY(40px); opacity: 0; }
    to   { transform: translateY(0); opacity: 1; }
}

.modal-title  { font-size: 1.1rem; font-weight: 800; margin-bottom: 20px; color: var(--text); }
.modal-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 20px; }

/* ============================================================
   FORMULÁRIOS
============================================================ */
.form-group { margin-bottom: 16px; }
.form-group label {
    display: block;
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--text-muted);
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.form-group input,
.form-group select {
    width: 100%;
    padding: 12px 14px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.92rem;
    background: var(--surface2);
    color: var(--text);
    outline: none;
    transition: border-color var(--transition), box-shadow var(--transition);
    -webkit-appearance: none;
    appearance: none;
}
.form-group input:focus,
.form-group select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(108,99,255,0.12);
}
.form-group .error { font-size: 0.75rem; color: var(--danger); margin-top: 4px; display: none; }
.form-group.has-error input,
.form-group.has-error select { border-color: var(--danger); }
.form-group.has-error .error { display: block; }

/* ============================================================
   SELETOR DE TIPO
============================================================ */
.type-selector { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.type-option {
    padding: 12px;
    border: 2px solid var(--border);
    border-radius: var(--radius-sm);
    text-align: center;
    cursor: pointer;
    font-size: 0.82rem;
    font-weight: 700;
    color: var(--text-muted);
    transition: all var(--transition);
}
.type-option:hover    { border-color: var(--primary-light); color: var(--primary); }
.type-option.selected { border-color: var(--primary); background: #EEF2FF; color: var(--primary); }
.type-option .type-emoji { font-size: 1.4rem; display: block; margin-bottom: 4px; }

/* ============================================================
   BADGES
============================================================ */
.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 100px;
    font-size: 0.68rem;
    font-weight: 700;
}
.badge.fixa    { background: #EEF2FF; color: #4338CA; }
.badge.variavel{ background: #F0FDF4; color: #15803D; }
.badge.cripto  { background: #FFF7ED; color: #C2410C; }

/* ============================================================
   TOAST
============================================================ */
.toast {
    position: fixed;
    bottom: calc(var(--nav-height) + 16px);
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: var(--text);
    color: white;
    padding: 12px 20px;
    border-radius: 100px;
    font-size: 0.85rem;
    font-weight: 600;
    z-index: 3000;
    opacity: 0;
    transition: all 0.3s ease;
    white-space: nowrap;
    pointer-events: none;
}
.toast.show    { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.success { background: var(--success); }
.toast.error   { background: var(--danger); }

@media (min-width: 768px) { .toast { bottom: 24px; } }

/* ============================================================
   ANÁLISES — CALCULADORA
============================================================ */
.charts-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 16px;
}
@media (min-width: 768px) { .charts-grid { grid-template-columns: 1fr 1fr; } }

.calculadora {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow);
    margin-bottom: 16px;
}
.calc-title    { font-size: 1rem; font-weight: 800; color: var(--text); margin-bottom: 4px; }
.calc-subtitle { font-size: 0.8rem; color: var(--text-muted); margin-bottom: 16px; }

.calc-sliders { display: flex; flex-direction: column; gap: 14px; margin-bottom: 16px; }
.slider-group label {
    display: flex;
    justify-content: space-between;
    font-size: 0.82rem;
    font-weight: 700;
    color: var(--text-muted);
    margin-bottom: 6px;
}
.slider-group label span { color: var(--primary); font-weight: 800; }

.slider-group input[type="range"] {
    width: 100%;
    -webkit-appearance: none;
    appearance: none;
    height: 6px;
    border-radius: 3px;
    background: var(--border);
    outline: none;
}
.slider-group input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 18px; height: 18px;
    border-radius: 50%;
    background: var(--primary);
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(108,99,255,0.4);
}

.calc-total-input { display: flex; gap: 10px; margin-bottom: 16px; }
.calc-total-input input {
    flex: 1;
    padding: 12px 14px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.92rem;
    background: var(--surface2);
    color: var(--text);
    outline: none;
    transition: border-color var(--transition);
}
.calc-total-input input:focus { border-color: var(--primary); }

.calc-btn {
    padding: 12px 18px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    font-weight: 700;
    cursor: pointer;
    transition: all var(--transition);
    white-space: nowrap;
}
.calc-btn:hover { background: var(--primary-dark); }

.calc-resultado { display: none; flex-direction: column; gap: 10px; }
.calc-resultado.show { display: flex; }

.calc-categoria { border-radius: var(--radius-sm); overflow: hidden; border: 1px solid var(--border); }
.calc-cat-header {
    padding: 10px 14px;
    font-size: 0.85rem;
    font-weight: 700;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.calc-cat-header.fixa    { background: #EEF2FF; color: #4338CA; }
.calc-cat-header.variavel{ background: #F0FDF4; color: #15803D; }
.calc-cat-header.cripto  { background: #FFF7ED; color: #C2410C; }

.calc-cat-body { padding: 10px 14px; background: var(--surface2); }
.calc-ativo-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.82rem;
    padding: 5px 0;
    border-bottom: 1px solid var(--border);
    gap: 8px;
}
.calc-ativo-row:last-child { border-bottom: none; }
.calc-ativo-row .ativo-nome  { color: var(--text-muted); flex: 1; }
.calc-ativo-row .ativo-val   { font-weight: 700; color: var(--text); }
.calc-ativo-row .ativo-aporte{ font-weight: 700; color: var(--primary); font-size: 0.78rem; }

.perc-warning {
    font-size: 0.78rem;
    color: var(--warning);
    text-align: center;
    padding: 8px;
    background: #FFFBEB;
    border-radius: 8px;
    margin-bottom: 12px;
    display: none;
}
.perc-warning.show { display: block; }

/* ============================================================
   EMPTY STATE
============================================================ */
.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-muted);
}
.empty-state svg    { width: 56px; height: 56px; opacity: 0.25; margin-bottom: 12px; }
.empty-state strong { display: block; font-size: 1rem; color: var(--text); margin-bottom: 4px; }
.empty-state p      { font-size: 0.9rem; line-height: 1.6; }