/* ===== RESET & BASE ===== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    background: #0b1121;
    color: #e8edf5;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
    padding: 24px;
    min-height: 100vh;
}

/* ===== HEADER ===== */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 16px;
    margin-bottom: 24px;
    padding-bottom: 16px;
    border-bottom: 1px solid #1e2a45;
}

.header h1 {
    color: #38bdf8;
    font-size: 26px;
    font-weight: 700;
    letter-spacing: -0.5px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.header h1 span {
    font-size: 28px;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 14px;
    flex-wrap: wrap;
}

.header-actions .user-badge {
    background: #1e2a45;
    padding: 6px 16px;
    border-radius: 20px;
    font-size: 13px;
    color: #94a3b8;
    display: flex;
    align-items: center;
    gap: 8px;
}

.header-actions .user-badge .emoji {
    font-size: 16px;
}

.btn {
    padding: 7px 18px;
    border: none;
    border-radius: 20px;
    font-weight: 600;
    font-size: 13px;
    cursor: pointer;
    transition: opacity 0.2s, transform 0.1s;
}
.btn:hover {
    opacity: 0.85;
    transform: scale(0.97);
}
.btn-logout {
    background: #ef4444;
    color: #fff;
}
.btn-refresh {
    background: #38bdf8;
    color: #0b1121;
}
.btn-refresh:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}
.btn-reset {
    background: #dc2626;
    color: #fff;
}
.btn-reset:hover {
    opacity: 0.85;
    transform: scale(0.97);
}
.btn-reset:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}
.btn-detail {
    background: transparent;
    color: #38bdf8;
    border: 1px solid #38bdf8;
}
.btn-detail:hover {
    background: #38bdf8;
    color: #0b1121;
}

/* ---- Link cambio vista desktop<->mobile (in entrambi i template) ---- */
.view-switch-link {
    color: #38bdf8;
    font-size: 12px;
    text-decoration: none;
    padding: 7px 12px;
    border: 1px solid #1e2a45;
    border-radius: 20px;
    transition: all 0.15s;
    white-space: nowrap;
}
.view-switch-link:hover {
    border-color: #38bdf8;
    background: #182240;
}

#update-time {
    color: #64748b;
    font-size: 13px;
    min-width: 140px;
    text-align: right;
}

/* ===== RIEPILOGO TOTALI ===== */
.summary-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 18px;
    margin-bottom: 28px;
}
.summary-card {
    background: #141d33;
    border-radius: 16px;
    padding: 18px 20px;
    border: 1px solid #1e2a45;
    border-left: 4px solid #38bdf8;
    transition: border-color 0.2s, transform 0.1s, background 0.2s;
    cursor: pointer;
}
.summary-card:hover { border-color: #38bdf8; background: #182240; }
.summary-card:active { transform: scale(0.98); }
.summary-card.active {
    background: #182240;
    box-shadow: 0 0 0 2px #38bdf8 inset;
}
.summary-card .label {
    color: #94a3b8;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    font-weight: 500;
    margin-bottom: 6px;
}
.summary-card .value {
    font-size: 24px;
    font-weight: 700;
    color: #facc15;
    line-height: 1.2;
}
.summary-card.total { border-left-color: #facc15; }
.summary-card.total .value { color: #facc15; }
.summary-card.chain-solana { border-left-color: #9945FF; }
.summary-card.chain-solana .value { color: #c4a6ff; }
.summary-card.chain-ethereum { border-left-color: #627EEA; }
.summary-card.chain-ethereum .value { color: #a3b3f7; }
.summary-card.chain-ton { border-left-color: #38bdf8; }
.summary-card.chain-ton .value { color: #7dd3fc; }

/* ===== SEZIONI GENERICHE ===== */
.section {
    background: #141d33;
    border-radius: 16px;
    padding: 20px 22px;
    border: 1px solid #1e2a45;
    margin-bottom: 22px;
}
.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 18px;
}
.section-header h3 {
    color: #e8edf5;
    font-size: 16px;
    font-weight: 600;
}

/* ===== FILTRI / TABS (prezzi e transazioni) ===== */
.price-filter, .tx-tabs {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}
.filter-btn, .tab-btn {
    background: #0b1121;
    color: #94a3b8;
    border: 1px solid #1e2a45;
    padding: 6px 14px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
}
.filter-btn:hover, .tab-btn:hover {
    border-color: #38bdf8;
    color: #e8edf5;
}
.filter-btn.active, .tab-btn.active {
    background: #38bdf8;
    color: #0b1121;
    border-color: #38bdf8;
}

/* ===== SEZIONE PREZZI ===== */
.price-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 14px;
}
.price-card {
    position: relative;
    background: #0b1121;
    border: 1px solid #1e2a45;
    border-radius: 12px;
    padding: 10px 16px 14px;
    transition: border-color 0.2s;
}
.price-card:hover { border-color: #38bdf8; }

/* Sfondo tenue in base al segno della variazione 24h — toni smorzati,
   non troppo vividi, per non affaticare la lettura su tante card insieme. */
.price-card-positive {
    background: rgba(74, 222, 128, 0.055);
    border-color: rgba(74, 222, 128, 0.18);
}
.price-card-positive:hover { border-color: rgba(74, 222, 128, 0.4); }
.price-card-negative {
    background: rgba(248, 113, 113, 0.055);
    border-color: rgba(248, 113, 113, 0.18);
}
.price-card-negative:hover { border-color: rgba(248, 113, 113, 0.4); }
.price-card-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 4px;
    min-height: 20px;
}
.price-card .star-btn {
    background: transparent;
    border: none;
    font-size: 15px;
    cursor: pointer;
    color: #334155;
    opacity: 0.6;
    transition: all 0.15s;
    padding: 0;
}
.price-card .star-btn:hover { opacity: 1; color: #facc15; }
.price-card .star-btn.active { color: #facc15; opacity: 1; }
.price-change {
    font-size: 11px;
    font-weight: 700;
    padding: 2px 7px;
    border-radius: 10px;
}
.price-change-up {
    color: #4ade80;
    background: rgba(74, 222, 128, 0.12);
}
.price-change-down {
    color: #f87171;
    background: rgba(248, 113, 113, 0.12);
}
.price-token {
    font-weight: 700;
    font-size: 15px;
    color: #e8edf5;
    margin-bottom: 4px;
}
.price-value {
    font-size: 18px;
    font-weight: 700;
    color: #4ade80;
    margin-bottom: 4px;
}
.price-chain {
    font-size: 11px;
    color: #64748b;
}

/* ===== SEZIONE SALDI ===== */
.balances-chains {
    display: flex;
    flex-direction: column;
    gap: 16px;
}
.chain-block {
    border: 1px solid #1e2a45;
    border-radius: 12px;
    overflow: hidden;
    border-left: 4px solid #38bdf8;
}
.chain-block.chain-solana { border-left-color: #9945FF; }
.chain-block.chain-ethereum { border-left-color: #627EEA; }
.chain-block.chain-ton { border-left-color: #38bdf8; }

.chain-block-header {
    background: #0b1121;
    padding: 10px 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: 700;
    font-size: 14px;
    color: #e8edf5;
}
.chain-block-header .chain-subtotal {
    color: #facc15;
    font-size: 15px;
}
.chain-block-body {
    display: flex;
    flex-direction: column;
}
.balance-row {
    display: grid;
    grid-template-columns: 1fr 1.2fr 1fr 1fr;
    align-items: center;
    gap: 10px;
    padding: 10px 16px;
    border-top: 1px solid #1e2a45;
    font-size: 13px;
}
.balance-token {
    font-weight: 700;
    color: #e8edf5;
}
.balance-amount {
    color: #cbd5e1;
    font-family: 'SF Mono', 'Consolas', monospace;
}
.balance-price {
    color: #64748b;
    font-size: 12px;
}
.balance-value {
    color: #4ade80;
    font-weight: 700;
    text-align: right;
}

/* ===== TABELLA TRANSAZIONI ===== */
.tx-table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

/* Tendina compatta mobile: nascosta di default (desktop mostra la tabella),
   resa visibile in sua vece da style_mobile.css. */
.tx-dropdown-wrap { display: none; }

.tx-table {
    width: 100%;
    font-size: 13px;
    border-collapse: collapse;
}
.tx-table th {
    text-align: left;
    color: #64748b;
    font-weight: 400;
    padding: 8px;
    border-bottom: 1px solid #1e2a45;
}
.tx-table td {
    padding: 8px;
    border-bottom: 1px solid #0b1121;
}
.tx-table .status-success { color: #4ade80; }
.tx-table .status-failed { color: #f87171; }

.empty-state {
    color: #64748b;
    font-size: 14px;
    text-align: center;
    padding: 20px 0;
    grid-column: 1 / -1;
}

#balances-section-subtitle {
    color: #64748b;
    font-size: 13px;
    font-weight: 400;
}

.tx-detail-link {
    margin-top: 14px;
    text-align: right;
}

/* ===== RIGA SWAP (30%) + STORICO (70%), solo desktop ===== */
.section-row-swap-history {
    display: flex;
    gap: 22px;
    align-items: flex-start;
}
.section-row-swap-history .section-jupiter {
    flex: 0 0 30%;
    max-width: 30%;
    margin-bottom: 22px; /* stessa spaziatura delle altre .section, che qui è sul figlio flex e non sul contenitore */
}
.section-row-swap-history .section-history {
    flex: 0 0 70%;
    max-width: 70%;
    margin-bottom: 22px;
}

/* ===== SEZIONE JUPITER SWAP (integrata fissa in pagina) ===== */
.section-jupiter {
    display: flex;
    flex-direction: column;
}
.section-jupiter #jupiter-plugin-container {
    width: 100%;
    min-height: 560px;
}

/* Hint deep-link mobile: nascosto di default (desktop), riattivato dal media
   query in style_mobile.css. Vedi nota nel template _dashboard_content.html
   sul perché si usano <a> reali invece di JS. */
.jupiter-mobile-hint {
    display: none;
    gap: 8px;
    padding: 0 0 16px 0;
    flex-wrap: wrap;
    justify-content: center;
    text-align: center;
}
.jupiter-mobile-hint span {
    width: 100%;
    font-size: 12px;
    color: #64748b;
}
.btn-wallet-deeplink {
    display: inline-block;
    background: #1e2a45;
    color: #e2e8f0;
    font-size: 13px;
    padding: 8px 16px;
    border-radius: 20px;
    font-weight: 600;
    border: 1px solid #2c3b5c;
    text-decoration: none;
}
.btn-wallet-deeplink:active {
    opacity: 0.8;
}

/* ===== MODAL DETTAGLIO SOLANA ===== */

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.65);
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}
.modal-box {
    background: #141d33;
    border: 1px solid #1e2a45;
    border-radius: 16px;
    width: 100%;
    max-width: 1200px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 18px 22px;
    border-bottom: 1px solid #1e2a45;
}
.modal-header h3 {
    color: #38bdf8;
    font-size: 16px;
}
.modal-close {
    background: transparent;
    border: none;
    color: #94a3b8;
    font-size: 18px;
    cursor: pointer;
    padding: 4px 10px;
    border-radius: 8px;
    transition: all 0.15s;
}
.modal-close:hover {
    background: #1e2a45;
    color: #e8edf5;
}
.modal-filters {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 14px 22px;
    border-bottom: 1px solid #1e2a45;
    align-items: center;
}
.modal-filters input,
.modal-filters select {
    background: #0b1121;
    border: 1px solid #1e2a45;
    color: #e8edf5;
    border-radius: 8px;
    padding: 7px 10px;
    font-size: 12px;
}
.modal-filters input:focus,
.modal-filters select:focus {
    outline: none;
    border-color: #38bdf8;
}
.modal-filters .date-label {
    display: flex;
    align-items: center;
    gap: 6px;
    color: #94a3b8;
    font-size: 12px;
}
.modal-filters .page-size-label {
    display: flex;
    align-items: center;
    gap: 6px;
    color: #94a3b8;
    font-size: 12px;
    margin-left: auto;
}
.modal-filters-hint {
    padding: 0 22px 10px;
    color: #64748b;
    font-size: 11px;
}
.modal-table-wrap {
    overflow: auto;
    padding: 0 22px;
    flex: 1;
}
.detail-table {
    white-space: nowrap;
}
.detail-table th, .detail-table td {
    font-size: 12px;
    padding: 7px 10px;
}
.filterable-th {
    cursor: pointer;
    user-select: none;
    transition: color 0.15s;
}
.filterable-th:hover {
    color: #38bdf8;
}
.column-filter-input {
    width: 100%;
    box-sizing: border-box;
    background: #0b1121;
    border: 1px solid #38bdf8;
    color: #e8edf5;
    border-radius: 6px;
    padding: 4px 6px;
    font-size: 11px;
    font-weight: 400;
}
.column-filter-input:focus {
    outline: none;
}
#column-filter-row th {
    padding: 4px 10px 8px;
}
.mono-small {
    font-family: 'SF Mono', 'Consolas', monospace;
    font-size: 11px;
    color: #64748b;
}

.txid-chip {
    background: #0b1121;
    border: 1px solid #1e2a45;
    color: #38bdf8;
    border-radius: 6px;
    padding: 4px 8px;
    font-size: 11px;
    font-family: 'SF Mono', 'Consolas', monospace;
    cursor: pointer;
    transition: all 0.15s;
}
.txid-chip:hover {
    border-color: #38bdf8;
    background: #141d33;
}

.txid-popup {
    position: absolute;
    z-index: 300;
    background: #141d33;
    border: 1px solid #38bdf8;
    border-radius: 10px;
    padding: 8px;
    display: flex;
    gap: 6px;
    align-items: center;
    box-shadow: 0 8px 24px rgba(0,0,0,0.5);
}
.txid-popup input {
    background: #0b1121;
    border: 1px solid #1e2a45;
    color: #e8edf5;
    border-radius: 6px;
    padding: 6px 8px;
    font-size: 11px;
    font-family: 'SF Mono', 'Consolas', monospace;
    width: 320px;
}
.txid-popup input:focus {
    outline: none;
    border-color: #38bdf8;
}
.txid-popup-mobile {
    position: fixed !important;
    top: 50% !important;
    left: 50% !important;
    transform: translate(-50%, -50%);
    width: 90vw;
    max-width: 400px;
    flex-direction: column;
    align-items: stretch;
}
.txid-popup-mobile input {
    width: 100%;
    box-sizing: border-box;
}
.modal-pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 16px;
    padding: 14px 22px;
    border-top: 1px solid #1e2a45;
    color: #94a3b8;
    font-size: 13px;
}

/* ===== LOGIN ===== */
.login-container {
    max-width: 420px;
    margin: 80px auto;
    background: #141d33;
    padding: 40px;
    border-radius: 16px;
    border: 1px solid #1e2a45;
}
.login-container h2 {
    color: #38bdf8;
    text-align: center;
    margin-bottom: 20px;
    font-size: 24px;
}
.login-container input {
    width: 100%;
    padding: 12px;
    margin: 10px 0;
    border-radius: 8px;
    border: 1px solid #1e2a45;
    background: #0b1121;
    color: #e8edf5;
    font-size: 16px;
}
.login-container input:focus {
    outline: none;
    border-color: #38bdf8;
}
.login-container button {
    width: 100%;
    padding: 12px;
    background: #38bdf8;
    color: #0b1121;
    border: none;
    border-radius: 8px;
    font-weight: 700;
    font-size: 16px;
    cursor: pointer;
    margin-top: 12px;
    transition: opacity 0.2s;
}
.login-container button:hover {
    opacity: 0.85;
}
.login-container .error {
    color: #f87171;
    text-align: center;
    margin-top: 12px;
}

/* ===== RESPONSIVE ===== */

/* ---- Tablet e schermi medi (≤ 900px) ---- */
@media (max-width: 900px) {
    .modal-box {
        max-width: 95vw;
    }
    .summary-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    .section-row-swap-history {
        display: block; /* sotto i 900px, 30/70 diventa troppo stretto: torna a impilare */
    }
    .section-row-swap-history .section-jupiter,
    .section-row-swap-history .section-history {
        flex: none;
        max-width: 100%;
    }
}

/* ---- Mobile (≤ 768px) ---- */
@media (max-width: 768px) {
    body { padding: 12px; }

    /* Header: impila e restringe */
    .header {
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
    }
    .header h1 { font-size: 19px; }
    .header-actions {
        justify-content: space-between;
        gap: 8px;
    }
    .header-actions .user-badge { order: -1; }
    #update-time {
        text-align: left;
        min-width: 0;
        flex-basis: 100%;
        order: 10;
    }
    .btn { padding: 8px 14px; font-size: 13px; } /* target touch più grande */

    /* Riepilogo totali */
    .summary-grid { grid-template-columns: 1fr 1fr; gap: 12px; }
    .summary-card { padding: 14px 16px; }
    .summary-card .value { font-size: 19px; }
    .summary-card .label { font-size: 11px; }

    /* Sezioni generiche */
    .section { padding: 16px; }
    .section-header { flex-direction: column; align-items: flex-start; gap: 10px; }
    .price-filter, .tx-tabs { width: 100%; }
    .filter-btn, .tab-btn { flex: 1; text-align: center; padding: 8px 10px; }

    /* Prezzi & preferiti */
    .price-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
    .price-card { padding: 12px 14px; }

    /* Saldi */
    .balance-row {
        grid-template-columns: 1fr 1fr;
        row-gap: 4px;
    }
    .balance-price { display: none; }
    .chain-block-header { font-size: 13px; }

    /* Storico compatto */
    .tx-table { font-size: 12px; min-width: 500px; } /* forza scroll orizzontale invece di schiacciare le colonne */
    .tx-table th:nth-child(5), .tx-table td:nth-child(5) { display: none; } /* Fee nascosta */

    /* Login */
    .login-container { padding: 24px; margin: 40px auto; width: calc(100% - 32px); }

    /* ---- Modal storico dettagliato: full-screen su mobile ---- */
    .modal-overlay { padding: 0; align-items: stretch; }
    .modal-box {
        max-width: 100vw;
        width: 100vw;
        max-height: 100vh;
        height: 100vh;
        border-radius: 0;
    }
    .modal-header { padding: 14px 16px; }
    .modal-header h3 { font-size: 14px; }
    .modal-filters {
        padding: 12px 16px;
        gap: 6px;
    }
    .modal-filters .page-size-label { margin-left: 0; }
    .modal-filters-hint { padding: 0 16px 8px; font-size: 10px; }
    .modal-table-wrap { padding: 0 16px; -webkit-overflow-scrolling: touch; }
    .detail-table { min-width: 1100px; } /* la tabella resta larga, scrolla in orizzontale */
    .modal-pagination { padding: 12px 16px; flex-wrap: wrap; gap: 10px; }

    /* Popup copia TX ID: sempre centrato su mobile (gestito anche da JS/isMobile()) */
    .txid-popup { max-width: 90vw; }
}

/* ---- Telefoni piccoli (≤ 480px) ---- */
@media (max-width: 480px) {
    .summary-grid { grid-template-columns: 1fr; }
    .price-grid { grid-template-columns: repeat(2, 1fr); }
    .header-actions { flex-wrap: wrap; }
    .header-actions .btn { flex: 1 1 auto; }
    .balance-row { grid-template-columns: 1fr; row-gap: 2px; }
    .balance-value { text-align: left; }
    .login-container { padding: 20px; }
}