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

:root {
    --bg: #121212;
    --card: #1B1B1B;
    --card-hover: #222222;
    --border: #2A2A2A;
    --text: #FFFFFF;
    --text-secondary: #888888;
    --green: #00C853;
    --green-bg: rgba(0, 200, 83, 0.1);
    --red: #FF1744;
    --red-bg: rgba(255, 23, 68, 0.1);
    --yellow: #FFD600;
    --yellow-bg: rgba(255, 214, 0, 0.1);
    --radius: 12px;
    --radius-sm: 8px;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 24px;
}

/* ===== HEADER ===== */

.header {
    margin-bottom: 32px;
}

.header-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
}

.header-title {
    font-size: 28px;
    font-weight: 700;
    letter-spacing: -0.5px;
}

.market-status {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 14px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 20px;
    font-size: 13px;
    font-weight: 500;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--text-secondary);
}

.market-status.open .status-dot {
    background: var(--green);
    box-shadow: 0 0 8px rgba(0, 200, 83, 0.5);
}

.market-status.closed .status-dot {
    background: var(--red);
}

.header-controls {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 16px;
}

.refresh-area {
    display: flex;
    align-items: center;
}

.sync-btn {
    background: var(--card);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 8px 16px;
    font-size: 14px;
    font-family: inherit;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.sync-btn:hover {
    background: var(--card-hover);
    border-color: #444;
}

.sync-btn:active {
    transform: scale(0.97);
}

.sync-btn.loading {
    opacity: 0.6;
    pointer-events: none;
}

.update-info {
    display: flex;
    align-items: center;
    gap: 16px;
    font-size: 13px;
    color: var(--text-secondary);
}

/* ===== CARDS GERAIS ===== */

.card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}

.card-header {
    display: flex;
    align-items: baseline;
    gap: 12px;
    padding: 24px 28px 0;
}

.card-title {
    font-size: 20px;
    font-weight: 700;
}

.card-subtitle {
    font-size: 13px;
    color: var(--text-secondary);
}

.card-body {
    padding: 20px 28px 28px;
}

/* ===== SEÇÃO IFIX ===== */

.section {
    margin-bottom: 32px;
}

.ifix-main {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 20px;
    margin-bottom: 24px;
}

.ifix-price {
    display: flex;
    align-items: baseline;
    gap: 16px;
}

.price-value {
    font-size: 42px;
    font-weight: 700;
    letter-spacing: -1px;
}

.price-change {
    font-size: 18px;
    font-weight: 600;
}

.price-change.up {
    color: var(--green);
}

.price-change.down {
    color: var(--red);
}

.ifix-details {
    display: flex;
    gap: 32px;
}

.detail {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.detail-label {
    font-size: 12px;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.detail-value {
    font-size: 15px;
    font-weight: 500;
}

.ifix-range-selector {
    display: flex;
    gap: 4px;
    margin-bottom: 12px;
}

.range-btn {
    background: transparent;
    color: var(--text-secondary);
    border: none;
    border-radius: 6px;
    padding: 4px 10px;
    font-size: 12px;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.15s;
}

.range-btn:hover {
    color: var(--text);
    background: rgba(255, 255, 255, 0.05);
}

.range-btn.active {
    color: var(--green);
    background: var(--green-bg);
}

.chart-container {
    position: relative;
    width: 100%;
}

.chart-ifix {
    height: 180px;
}

/* ===== SEÇÃO CARTEIRA ===== */

.portfolio-range-selector {
    display: flex;
    gap: 4px;
    margin-bottom: 12px;
}

.portfolio-stats {
    display: flex;
    gap: 40px;
    margin-bottom: 24px;
    flex-wrap: wrap;
}

.stat {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.stat-label {
    font-size: 12px;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.stat-value {
    font-size: 16px;
    font-weight: 600;
}

.stat-up {
    color: var(--green);
}

.stat-down {
    color: var(--red);
}

.chart-portfolio {
    height: 220px;
}

/* ===== GRID DE FIIs ===== */

.fii-grid {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 16px;
}

.fii-card {
    position: relative;
    background: var(--card);
    border-radius: var(--radius);
    padding: 20px 28px 28px;
    border: 1px solid var(--border);
    min-width: 0;
    overflow: hidden;
    transition: border-color 0.2s, transform 0.15s;
    cursor: grab;
}

.fii-card:active {
    cursor: grabbing;
}

.fii-card:hover {
    border-color: #444;
}

.fii-card.card-positive {
    border-color: var(--green);
}

.fii-card.card-negative {
    border-color: var(--red);
}

.fii-ticker {
    display: block;
    font-size: 18px;
    font-weight: 700;
    letter-spacing: 0.5px;
    margin-bottom: 8px;
}

.fii-price {
    font-size: 30px;
    font-weight: 300;
    margin-bottom: 6px;
    display: block;
}

.fii-change {
    display: flex;
    gap: 6px;
    align-items: center;
    font-size: 15px;
    font-weight: 700;
}

.fii-change .variation-value {
    font-size: 11px;
    font-weight: 500;
}

.fii-change.up {
    color: var(--green);
}

.fii-change.down {
    color: var(--red);
}

.fii-sparkline {
    margin-top: 10px;
    height: 70px;
}

.fii-details {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid rgba(255,255,255,.06);
}

.fii-detail-label {
    display: block;
    color: var(--text-secondary);
    font-size: 10px;
    margin-bottom: 1px;
}

.fii-detail-value {
    font-size: 12px;
    font-weight: 500;
}

/* ===== FILTRO DE TICKERS ===== */

.fii-card.hidden {
    display: none;
}

#ticker-search {
    background: var(--card);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 6px 10px;
    font-size: 13px;
    font-family: inherit;
    outline: none;
    transition: border-color 0.2s;
    width: 180px;
}

#ticker-search:focus {
    border-color: var(--green);
}

#ticker-search::placeholder {
    color: var(--text-secondary);
}

/* ===== TOOLBAR ===== */

.toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}

.toolbar-left {
    display: flex;
    align-items: center;
    gap: 8px;
}

.toolbar-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

.toolbar-group {
    display: flex;
    align-items: center;
    gap: 2px;
}

.toolbar-divider {
    width: 1px;
    height: 20px;
    background: var(--border);
    flex-shrink: 0;
}

.toolbar-left input {
    background: var(--card);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 6px 10px;
    font-size: 13px;
    font-family: inherit;
    outline: none;
    transition: border-color 0.2s;
}

.toolbar-left input:focus {
    border-color: var(--green);
}

.toolbar-left input::placeholder {
    color: var(--text-secondary);
}

.toolbar-left input#ticker-input {
    width: 110px;
}

#ticker-add-btn {
    background: var(--green);
    color: #000;
    border: none;
    border-radius: var(--radius-sm);
    width: 30px;
    height: 30px;
    font-size: 16px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: opacity 0.15s;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    flex-shrink: 0;
}

#ticker-add-btn:hover {
    opacity: 0.85;
}

#ticker-add-btn:active {
    transform: scale(0.93);
}

.sparkline-range-selector {
    display: flex;
    gap: 2px;
}

/* ===== SORT BAR ===== */

.sort-bar {
    display: flex;
    gap: 2px;
}

.sort-btn {
    background: transparent;
    color: var(--text-secondary);
    border: none;
    border-radius: 6px;
    padding: 4px 10px;
    font-size: 12px;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.15s;
}

.sort-btn:hover {
    color: var(--text);
    background: rgba(255, 255, 255, 0.05);
}

.sort-btn.active {
    color: var(--green);
    background: var(--green-bg);
}

/* ===== BOTÃO REMOVER CARD ===== */

.fii-card-remove {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.06);
    color: var(--text-secondary);
    border: none;
    border-radius: 6px;
    font-size: 16px;
    line-height: 1;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.15s, background 0.15s, color 0.15s;
    padding: 0;
    z-index: 2;
}

.fii-card:hover .fii-card-remove {
    opacity: 1;
}

.fii-card-remove:hover {
    background: var(--red-bg);
    color: var(--red);
}

/* ===== SORTABLEJS ===== */

.fii-card-ghost {
    opacity: 0.35;
    border-style: dashed;
    border-color: var(--green);
}

.fii-card-dragging {
    border-color: var(--green) !important;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}

.fii-grid.sortable-chosen {
    border-color: var(--green);
}

/* ===== ERROR BANNER ===== */

.error-banner {
    padding: 6px 12px;
    background: var(--red-bg);
    border: 1px solid rgba(255, 23, 68, 0.3);
    border-radius: var(--radius-sm);
    color: var(--red);
    font-size: 13px;
    white-space: nowrap;
    flex-shrink: 0;
}

/* ===== SKELETON LOADING ===== */

@keyframes shimmer {
    0% { background-position: -400px 0; }
    100% { background-position: 400px 0; }
}

.fii-card.skeleton {
    pointer-events: none;
    border-color: var(--border);
}

.fii-card.skeleton .skeleton-line,
.fii-card.skeleton .skeleton-chart {
    background: linear-gradient(90deg, var(--border) 25%, #333 50%, var(--border) 75%);
    background-size: 800px 100%;
    animation: shimmer 1.5s infinite linear;
    border-radius: 4px;
}

.skeleton-ticker {
    width: 70px;
    height: 18px;
    margin-bottom: 10px;
}

.skeleton-price {
    width: 120px;
    height: 30px;
    margin-bottom: 8px;
}

.skeleton-change {
    width: 80px;
    height: 16px;
    margin-bottom: 12px;
}

.skeleton-chart {
    width: 100%;
    height: 70px;
    margin-bottom: 12px;
}

.skeleton-details {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    padding-top: 10px;
    border-top: 1px solid rgba(255,255,255,.06);
}

.skeleton-detail {
    width: 100%;
    height: 30px;
}

/* ===== MODAL ===== */

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    animation: fadeIn 0.15s ease;
}

.modal-box {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 28px;
    min-width: 320px;
    max-width: 90vw;
    box-shadow: 0 16px 48px rgba(0, 0, 0, 0.5);
    animation: slideUp 0.2s ease;
}

.modal-message {
    font-size: 15px;
    margin-bottom: 24px;
    line-height: 1.5;
}

.modal-actions {
    display: flex;
    gap: 12px;
    justify-content: flex-end;
}

.modal-btn {
    padding: 8px 20px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-family: inherit;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.15s;
}

.modal-btn-cancel {
    background: rgba(255, 255, 255, 0.06);
    color: var(--text-secondary);
}

.modal-btn-cancel:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text);
}

.modal-btn-confirm {
    background: var(--red);
    color: #fff;
}

.modal-btn-confirm:hover {
    opacity: 0.9;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

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

/* ===== BOTTOM SHEET (mobile) ===== */

.sheet-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    animation: fadeIn 0.15s ease;
}

.sheet-box {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--card);
    border-top: 1px solid var(--border);
    border-radius: 16px 16px 0 0;
    padding: 20px 24px 28px;
    z-index: 1001;
    animation: sheetUp 0.25s ease;
    max-height: 70vh;
    overflow-y: auto;
}

.sheet-handle {
    width: 36px;
    height: 4px;
    background: rgba(255, 255, 255, 0.15);
    border-radius: 2px;
    margin: -8px auto 16px;
}

.sheet-title {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 16px;
}

.sheet-group {
    margin-bottom: 20px;
}

.sheet-group-label {
    font-size: 12px;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 8px;
    display: block;
}

.sheet-options {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.sheet-option {
    background: rgba(255, 255, 255, 0.04);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 8px 14px;
    font-size: 13px;
    font-family: inherit;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
    min-height: 36px;
}

.sheet-option:active {
    background: rgba(255, 255, 255, 0.08);
}

.sheet-option.active {
    color: var(--green);
    background: var(--green-bg);
    border-color: var(--green);
}

.sheet-btn-close {
    display: block;
    width: 100%;
    padding: 12px;
    margin-top: 8px;
    background: rgba(255, 255, 255, 0.06);
    color: var(--text-secondary);
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-family: inherit;
    font-weight: 600;
    cursor: pointer;
    min-height: 44px;
}

.sheet-btn-close:active {
    background: rgba(255, 255, 255, 0.1);
}

@keyframes sheetUp {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
}

/* ===== DESKTOP-ONLY ===== */

.desktop-only {
    display: flex;
}

.mobile-only {
    display: none;
}

/* ===== RESPONSIVIDADE ===== */

@media (max-width: 1400px) {
    .fii-grid {
        grid-template-columns: repeat(4, minmax(0, 1fr));
    }
}

@media (max-width: 1200px) {
    .fii-grid {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }
}

@media (max-width: 900px) {
    .fii-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 768px) {
    .container {
        padding: 12px;
    }

    .header {
        margin-bottom: 16px;
    }

    .header-top {
        flex-direction: row;
        align-items: center;
        margin-bottom: 0;
    }

    .header-title {
        font-size: 18px;
    }

    .market-status {
        padding: 4px 10px;
        font-size: 11px;
    }

    .status-dot {
        width: 6px;
        height: 6px;
    }

    .header-controls {
        gap: 8px;
        margin-bottom: 12px;
    }

    .sync-btn {
        padding: 8px 14px;
        font-size: 13px;
    }

    .update-info {
        font-size: 11px;
    }

    .section {
        margin-bottom: 16px;
    }

    .ifix-main {
        flex-direction: column;
        gap: 12px;
        margin-bottom: 16px;
    }

    .ifix-price {
        flex-direction: row;
        align-items: baseline;
        gap: 10px;
    }

    .price-value {
        font-size: 26px;
        letter-spacing: -0.5px;
    }

    .price-change {
        font-size: 15px;
    }

    .ifix-details {
        gap: 16px;
    }

    .detail-value {
        font-size: 13px;
    }

    .ifix-range-selector {
        flex-wrap: wrap;
    }

    .range-btn {
        padding: 6px 10px;
        min-width: 36px;
        text-align: center;
    }

    .portfolio-stats {
        gap: 16px;
        margin-bottom: 16px;
    }

    .stat-value {
        font-size: 14px;
    }

    .fii-grid {
        grid-template-columns: 1fr;
        gap: 10px;
    }

    .card-header {
        padding: 16px 16px 0;
        cursor: pointer;
        user-select: none;
        -webkit-user-select: none;
    }

    .card-header::after {
        content: '▼';
        font-size: 10px;
        color: var(--text-secondary);
        margin-left: auto;
        transition: transform 0.2s;
        opacity: 0.5;
    }

    .card.collapsed .card-header::after {
        transform: rotate(-90deg);
    }

    .card-header .card-subtitle {
        display: none;
    }

    .card-body {
        padding: 12px 16px 16px;
    }

    .card.collapsed .card-body {
        display: none;
    }

    .card.collapsed .chart-container {
        display: none;
    }

    .toolbar {
        flex-direction: row;
        align-items: center;
        gap: 8px;
        margin-bottom: 10px;
    }

    .toolbar-left {
        flex: 1;
        flex-wrap: nowrap;
        gap: 6px;
    }

    .toolbar-right {
        display: none;
    }

    .toolbar-divider {
        display: none;
    }

    .toolbar-left input {
        font-size: 14px;
        padding: 8px 10px;
        min-height: 40px;
    }

    .toolbar-left input#ticker-input {
        width: auto;
        flex: 1;
        min-width: 80px;
    }

    #ticker-search {
        width: 100px;
        flex: none;
    }

    #ticker-add-btn {
        width: 40px;
        height: 40px;
        font-size: 20px;
        flex-shrink: 0;
    }

    .fii-card {
        padding: 14px 16px 16px;
    }

    .fii-card:active {
        cursor: default;
    }

    .fii-ticker {
        font-size: 16px;
        margin-bottom: 4px;
    }

    .fii-price {
        font-size: 22px;
        margin-bottom: 2px;
    }

    .fii-change {
        font-size: 14px;
        gap: 4px;
    }

    .fii-change .variation-value {
        font-size: 11px;
    }

    .fii-sparkline {
        margin-top: 8px;
        height: 48px;
    }

    .fii-details {
        margin-top: 8px;
        padding-top: 8px;
    }

    .fii-detail-label {
        font-size: 9px;
    }

    .fii-detail-value {
        font-size: 11px;
    }

    .fii-card-remove {
        opacity: 1;
        background: rgba(255, 255, 255, 0.08);
        width: 36px;
        height: 36px;
        font-size: 18px;
        top: 4px;
        right: 4px;
    }

    .fii-card-remove:hover {
        background: var(--red-bg);
        color: var(--red);
    }

    .chart-ifix {
        height: 140px;
    }

    .chart-portfolio {
        height: 160px;
    }

    .mobile-overflow-btn {
        display: flex;
        align-items: center;
        justify-content: center;
        width: 40px;
        height: 40px;
        background: var(--card);
        color: var(--text-secondary);
        border: 1px solid var(--border);
        border-radius: var(--radius-sm);
        font-size: 20px;
        cursor: pointer;
        flex-shrink: 0;
        transition: all 0.15s;
    }

    .mobile-overflow-btn:active {
        background: var(--card-hover);
    }

    .desktop-only {
        display: none !important;
    }

    .mobile-only {
        display: flex;
    }
}

@media (max-width: 480px) {
    .container {
        padding: 8px;
    }

    .header-title {
        font-size: 16px;
    }

    .market-status {
        font-size: 10px;
        padding: 3px 8px;
    }

    .price-value {
        font-size: 22px;
    }

    .price-change {
        font-size: 13px;
    }

    .ifix-details {
        gap: 12px;
    }

    .detail-value {
        font-size: 12px;
    }

    .fii-grid {
        gap: 8px;
    }

    .fii-card {
        padding: 12px 14px 14px;
    }

    .fii-ticker {
        font-size: 15px;
    }

    .fii-price {
        font-size: 20px;
    }

    .fii-change {
        font-size: 13px;
    }

    .fii-sparkline {
        height: 40px;
    }

    .fii-details {
        margin-top: 6px;
        padding-top: 6px;
    }

    .fii-detail-value {
        font-size: 10px;
    }

    .fii-detail-label {
        font-size: 8px;
    }

    .toolbar-left input {
        font-size: 13px;
        padding: 6px 8px;
        min-height: 36px;
    }

    #ticker-search {
        width: 80px;
    }

    #ticker-add-btn {
        width: 36px;
        height: 36px;
        font-size: 18px;
    }

    .chart-ifix {
        height: 120px;
    }

    .chart-portfolio {
        height: 140px;
    }
}
