:root {
    --bg-dark: #0f172a;
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --glass-bg: rgba(30, 41, 59, 0.7);
    --glass-border: rgba(255, 255, 255, 0.1);
    --accent: #3b82f6;
    --accent-hover: #2563eb;
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Inter', sans-serif;
}

body {
    background-color: var(--bg-dark);
    color: var(--text-primary);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow-x: hidden;
    position: relative;
    padding: 2rem 1rem;
    width: 100%;
}
#app-container.wide {
    max-width: 1000px;
}

.background-blobs {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    z-index: -1;
}

.blob {
    position: absolute;
    filter: blur(80px);
    opacity: 0.5;
    animation: float 20s infinite ease-in-out;
}

.blob-1 { top: -10%; left: -10%; width: 500px; height: 500px; background: #4f46e5; animation-delay: 0s; }
.blob-2 { bottom: -10%; right: -10%; width: 600px; height: 600px; background: #10b981; animation-delay: -5s; }
.blob-3 { top: 40%; left: 60%; width: 400px; height: 400px; background: #ec4899; animation-delay: -10s; }

@keyframes float {
    0%, 100% { transform: translateY(0) scale(1); }
    50% { transform: translateY(-50px) scale(1.1); }
}

.container {
    width: 100%;
    max-width: 500px;
    padding: 2rem;
    border-radius: 24px;
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    transition: max-width 0.5s ease-in-out;
}

.container.wide {
    max-width: 900px;
}

/* --- LAYOUT DESKTOP (Grid Inteligente) --- */
@media (min-width: 1024px) {
    body {
        padding: 3rem 2rem;
    }

    .container {
        max-width: 1200px;
        padding: 3rem;
        border-radius: 32px;
    }

    .desktop-grid {
        display: grid;
        grid-template-columns: 350px 1fr;
        gap: 3rem;
        align-items: start;
    }

    .desktop-left-column {
        position: sticky;
        top: 2rem;
    }

    .form-section {
        /* No desktop, mantemos o comportamento de abas, mas o container maior */
    }

    /* Ajuste para que a Carteira sempre use o espaço total disponível */
    .container.wide .desktop-grid {
        grid-template-columns: 1fr;
    }

    .charts-dynamic-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

header {
    width: 100%;
    margin-bottom: 2rem;
}

.user-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    margin-bottom: 1rem;
}

.user-spacer {
    flex: 1;
}

.user-header h1 {
    flex: 2;
    text-align: center;
    font-size: 2rem;
    font-weight: 700;
    background: linear-gradient(to right, #60a5fa, #a78bfa);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.user-controls {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 1rem;
}

#user-display {
    font-size: 0.85rem;
    color: var(--warning);
    font-weight: 600;
    white-space: nowrap;
}

.btn-logout {
    padding: 0.4rem 0.8rem;
    font-size: 0.75rem;
    border: 1px solid var(--glass-border);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.3s;
}

.btn-logout:hover {
    background: var(--danger);
    color: white;
    border-color: transparent;
}

header p { text-align: center; font-size: 0.95rem; color: var(--text-secondary); }

.tabs { display: flex; background: rgba(15, 23, 42, 0.6); border-radius: 12px; padding: 0.25rem; }
.tab-btn { flex: 1; padding: 0.75rem; border: none; background: transparent; color: var(--text-secondary); font-weight: 600; cursor: pointer; border-radius: 10px; transition: all 0.3s; }
.tab-btn.active { background: var(--glass-border); color: var(--text-primary); box-shadow: 0 4px 6px rgba(0,0,0,0.1); }

.form-section { display: none; flex-direction: column; gap: 1rem; animation: fadeIn 0.3s ease; }
.form-section.active { display: flex; }

@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

.input-group { display: flex; flex-direction: column; gap: 0.5rem; }
label { font-size: 0.85rem; color: var(--text-secondary); font-weight: 600; }
input { width: 100%; padding: 0.8rem 1rem; border-radius: 10px; border: 1px solid rgba(255, 255, 255, 0.05); background: rgba(15, 23, 42, 0.5); color: var(--text-primary); font-size: 1rem; transition: all 0.3s; outline: none; }
input:focus { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2); }
input::placeholder { color: rgba(148, 163, 184, 0.5); }

.btn-primary { padding: 1rem; border: none; border-radius: 10px; background: var(--accent); color: white; font-weight: 600; font-size: 1rem; cursor: pointer; transition: all 0.3s; margin-top: 0.5rem; }
.btn-primary:hover { background: var(--accent-hover); transform: translateY(-2px); box-shadow: 0 10px 15px -3px rgba(59, 130, 246, 0.3); }

.btn-secondary { padding: 0.5rem; border: 1px solid var(--glass-border); border-radius: 8px; background: transparent; color: var(--text-secondary); font-size: 0.8rem; cursor: pointer; transition: all 0.3s; margin-top: 1rem; width: 100%; }
.btn-secondary:hover { background: rgba(255, 255, 255, 0.05); color: var(--text-primary); }

.result-card { padding: 1.5rem; border-radius: 12px; background: rgba(15, 23, 42, 0.8); border: 1px solid var(--glass-border); text-align: center; animation: scaleIn 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275); }
.result-card.hidden { display: none; }
@keyframes scaleIn { from { opacity: 0; transform: scale(0.9); } to { opacity: 1; transform: scale(1); } }

.result-icon { font-size: 3rem; margin-bottom: 0.5rem; }
.result-title { font-size: 1.5rem; font-weight: 700; margin-bottom: 0.5rem; }
.result-good { color: var(--success); }
.result-warn { color: var(--warning); }
.result-bad { color: var(--danger); }
.result-reason { font-size: 0.9rem; color: var(--text-secondary); line-height: 1.5; }

.history-section.hidden { display: none; }
.history-section h3 { font-size: 1rem; color: var(--text-secondary); margin-bottom: 1rem; text-align: center; }
#history-list { list-style: none; display: flex; flex-direction: column; gap: 0.5rem; }
.history-item { display: flex; justify-content: space-between; align-items: center; padding: 0.75rem 1rem; background: rgba(255, 255, 255, 0.03); border-radius: 8px; border: 1px solid rgba(255, 255, 255, 0.05); font-size: 0.9rem; }
.badge { padding: 0.2rem 0.5rem; border-radius: 4px; font-size: 0.75rem; font-weight: 600; }
.badge-good { background: rgba(16, 185, 129, 0.2); color: var(--success); }
.badge-warn { background: rgba(245, 158, 11, 0.2); color: var(--warning); }
.badge-bad { background: rgba(239, 68, 68, 0.2); color: var(--danger); }

/* Portfolio Specific */
.portfolio-summary {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1rem;
    margin-bottom: 2rem;
}

.summary-card {
    background: rgba(255,255,255,0.05);
    padding: 1rem;
    border-radius: 12px;
    border: 1px solid var(--glass-border);
    text-align: center;
}

.summary-card span {
    font-size: 0.75rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05rem;
}

.summary-card h3 {
    font-size: 1.1rem;
    margin-top: 0.25rem;
}

.summary-card.highlight h3 {
    color: var(--warning);
}

.table-container {
    overflow-x: auto;
    border-radius: 12px;
    background: rgba(15, 23, 42, 0.3);
    border: 1px solid var(--glass-border);
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}

th {
    text-align: left;
    padding: 1rem;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--glass-border);
    font-weight: 600;
}

td {
    padding: 1rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.02);
}

tr:last-child td {
    border-bottom: none;
}

.val-up { color: var(--success); font-weight: 600; }
.val-down { color: var(--danger); font-weight: 600; }

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    backdrop-filter: blur(4px);
}

.modal.hidden {
    display: none;
}

.modal-content {
    background: rgba(30, 41, 59, 0.95);
    backdrop-filter: blur(20px);
    padding: 2.5rem;
    border-radius: 20px;
    width: 90%;
    max-width: 500px;
    border: 1px solid var(--glass-border);
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    position: relative;
}

.btn-delete {
    background: transparent;
    border: none;
    cursor: pointer;
    font-size: 1.1rem;
    transition: transform 0.2s;
    padding: 2px 5px;
}

.btn-delete:hover {
    transform: scale(1.3);
}

/* Collapsible Portfolio */
.collapsible-portfolio {
    margin-top: 0.5rem;
    border-top: 1px solid var(--glass-border);
    padding-top: 0.5rem;
}

.collapsible-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.5rem;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 12px;
    cursor: pointer;
    transition: background 0.3s, transform 0.2s;
    user-select: none;
    border: 1px solid var(--glass-border);
}

.collapsible-header:hover {
    background: rgba(255, 255, 255, 0.1);
    transform: translateY(-2px);
}

.collapsible-header span {
    font-weight: 700;
    font-size: 0.9rem;
    letter-spacing: 1px;
    color: var(--text-primary);
}

.arrow-icon {
    font-style: normal;
    transition: transform 0.3s;
}

.collapsible-header.active .arrow-icon {
    transform: rotate(180deg);
}

.collapsible-content {
    max-height: 2000px; /* Suficiente para tabelas grandes */
    opacity: 1;
    overflow: hidden;
    transition: max-height 0.4s ease-out, opacity 0.3s;
}

.collapsible-content.hidden-content {
    max-height: 0;
    opacity: 0;
    padding: 0;
}

.no-transition {
    transition: none !important;
}

/* Category Sections */
.category-section {
    margin: 1rem 0;
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.02);
}

.category-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.8rem 1.2rem;
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-secondary);
    transition: background 0.2s;
}

.category-header:hover {
    background: rgba(255, 255, 255, 0.05);
}

.category-title {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.category-profit {
    font-size: 0.8rem;
    padding: 0.2rem 0.6rem;
    border-radius: 20px;
    background: rgba(0, 0, 0, 0.2);
}

.category-content {
    max-height: 1500px;
    opacity: 1;
    overflow-x: auto;
    transition: max-height 0.3s ease-in-out, opacity 0.2s;
    padding: 0 1rem 1rem 1rem;
}

.category-content.hidden {
    max-height: 0;
    opacity: 0;
    padding: 0;
    pointer-events: none;
}

/* --- RESPONSIVIDADE (MOBILE) --- */
@media (max-width: 768px) {
    body {
        padding: 1rem 0.5rem;
    }

    .container, .container.wide {
        max-width: 100%;
        padding: 1.2rem;
        border-radius: 16px;
        gap: 1rem;
    }

    header h1 {
        font-size: 1.6rem;
    }

    /* Cabeçalho de Usuário no Mobile */
    .user-header {
        flex-direction: column;
        gap: 0.5rem;
        margin-bottom: 1.5rem;
    }

    .user-spacer {
        display: none;
    }

    .user-header h1 {
        order: 1;
        width: 100%;
    }

    .user-controls {
        order: 2;
        width: 100%;
        justify-content: center;
        gap: 0.8rem;
    }

    #user-display {
        font-size: 0.75rem;
    }

    /* Abas em Wrap para não esmagar */
    .tabs {
        flex-wrap: wrap;
        gap: 5px;
        background: transparent;
    }

    .tab-btn {
        flex: unset;
        width: calc(50% - 5px);
        font-size: 0.8rem;
        padding: 0.6rem;
        background: rgba(15, 23, 42, 0.8);
    }

    /* Cards de Resumo Empilhados */
    .portfolio-summary {
        grid-template-columns: 1fr;
        gap: 0.8rem;
    }

    .summary-card {
        padding: 0.8rem;
    }

    .summary-card h3 {
        font-size: 1rem;
    }

    /* Tabelas e Conteúdo de Categorias */
    .category-content {
        padding: 0 0.5rem 0.5rem 0.5rem;
    }

    table {
        font-size: 0.75rem;
    }

    th, td {
        padding: 0.7rem 0.5rem;
    }

    /* Modais e Formulários */
    .modal-content {
        padding: 1.5rem;
        width: 95%;
    }

    h3 {
        font-size: 1.1rem;
    }

    .collapsible-header span {
        font-size: 0.75rem;
    }
}

/* Dividend List */
#dividends-container {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
    margin-bottom: 1.5rem;
}

.dividend-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.8rem 1.2rem;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: 10px;
}

.dividend-info {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
}

.dividend-info strong {
    font-size: 0.9rem;
    color: var(--accent);
}

.dividend-info span {
    font-size: 0.7rem;
    color: var(--text-secondary);
}

.dividend-amount {
    font-weight: 700;
    color: var(--success);
    font-size: 0.9rem;
}

.chart-container {
    background: rgba(0,0,0,0.2);
    padding: 1.5rem;
    border-radius: 12px;
    border: 1px solid var(--glass-border);
    display: flex;
    flex-direction: column;
    align-items: center;
    min-height: 320px;
}

.chart-container canvas {
    width: 100% !important;
    height: 300px !important;
}

.charts-dynamic-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1.5rem;
    padding: 1.5rem 0;
}

@media (max-width: 900px) {
    .charts-dynamic-grid {
        grid-template-columns: 1fr;
    }
}
