/* ── Reset & Base ─────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --bg: #0f1118;
    --surface: #1a1d2e;
    --surface2: #232740;
    --border: #2e3348;
    --text: #e1e4ed;
    --text-muted: #8b90a5;
    --accent: #6c7aff;
    --accent-hover: #8892ff;
    --green: #34d399;
    --red: #f87171;
    --yellow: #fbbf24;
    --radius: 10px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
}

.container {
    max-width: 960px;
    margin: 0 auto;
    padding: 2rem 1.5rem;
}

/* ── Header ──────────────────────────────────────────────── */
header {
    text-align: center;
    margin-bottom: 2rem;
}
header h1 {
    font-size: 1.8rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}
.subtitle {
    color: var(--text-muted);
    margin-top: 0.3rem;
    font-size: 0.95rem;
}

/* ── Tab Bar ─────────────────────────────────────────────── */
.tab-bar {
    display: flex;
    gap: 0;
    margin-bottom: 1.5rem;
    border-bottom: 2px solid var(--border);
}
.tab-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 0.95rem;
    font-weight: 600;
    padding: 0.75rem 1.25rem;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    transition: all 0.15s;
    font-family: inherit;
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
}

/* ── Form ────────────────────────────────────────────────── */
#lookup-form {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
    margin-bottom: 1.5rem;
}
.form-top-row {
    display: flex;
    gap: 1rem;
    margin-bottom: 1rem;
}
.form-top-row .form-group { flex: 1; }
.form-group {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}
.form-group label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.wallets-group {
    margin-bottom: 1rem;
}
input, select {
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    padding: 0.6rem 0.75rem;
    font-size: 0.95rem;
    outline: none;
    transition: border-color 0.15s;
    font-family: inherit;
}
input:focus, select:focus {
    border-color: var(--accent);
}
select {
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg width='10' height='6' viewBox='0 0 10 6' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%238b90a5' stroke-width='1.5' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.75rem center;
    padding-right: 2rem;
}
input[type="date"]::-webkit-calendar-picker-indicator {
    filter: invert(0.7);
}

/* Wallet input rows */
#wallet-inputs {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}
.wallet-input-row {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}
.wallet-input-row input {
    flex: 1;
}
.wallet-input-row select.wallet-chain {
    width: 160px;
    flex-shrink: 0;
}
.btn-remove {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-muted);
    width: 32px;
    height: 32px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 1.1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s;
}
.btn-remove:hover {
    border-color: var(--red);
    color: var(--red);
    background: rgba(248, 113, 113, 0.1);
}
#add-wallet-btn {
    margin-top: 0.5rem;
}

/* Buttons */
.btn-primary, button[type="submit"] {
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 6px;
    padding: 0.6rem 1.5rem;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s;
    white-space: nowrap;
    width: 100%;
}
.btn-primary:hover, button[type="submit"]:hover { background: var(--accent-hover); }
.btn-primary:disabled, button[type="submit"]:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}
.btn-secondary {
    background: transparent;
    color: var(--accent);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 0.45rem 1rem;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
}
.btn-secondary:hover {
    border-color: var(--accent);
    background: rgba(108, 122, 255, 0.08);
}

/* ── Loading ─────────────────────────────────────────────── */
.loading {
    text-align: center;
    padding: 3rem 0;
    color: var(--text-muted);
}
.spinner {
    width: 36px; height: 36px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
    margin: 0 auto 1rem;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Error ───────────────────────────────────────────────── */
.error {
    background: rgba(248, 113, 113, 0.1);
    border: 1px solid var(--red);
    color: var(--red);
    border-radius: var(--radius);
    padding: 0.75rem 1rem;
    margin-bottom: 1.5rem;
    font-size: 0.9rem;
}

/* ── CU Panel ────────────────────────────────────────────── */
.cu-panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
    margin-bottom: 1.5rem;
}
.cu-header h3 {
    font-size: 0.9rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
}
.cu-meter {
    height: 8px;
    background: var(--surface2);
    border-radius: 4px;
    overflow: hidden;
    margin-bottom: 0.3rem;
}
.cu-meter-fill {
    height: 100%;
    background: var(--accent);
    border-radius: 4px;
    transition: width 0.4s ease;
    width: 0%;
}
.cu-meter-fill.warning { background: var(--yellow); }
.cu-meter-fill.danger { background: var(--red); }
.cu-meter-label {
    font-size: 0.75rem;
    color: var(--text-muted);
}
.cu-status {
    margin-top: 0.75rem;
    font-size: 0.85rem;
    color: var(--text-muted);
}
.cu-status .cu-done { color: var(--green); }
.cu-phase2-confirm {
    margin-top: 0.75rem;
    padding-top: 0.75rem;
    border-top: 1px solid var(--border);
}
.cu-phase2-confirm p {
    font-size: 0.9rem;
    margin-bottom: 0.75rem;
}
.cu-actions {
    display: flex;
    gap: 0.75rem;
}
.cu-actions .btn-primary {
    width: auto;
    padding: 0.5rem 1.25rem;
    font-size: 0.85rem;
}
.cu-actions .btn-secondary {
    padding: 0.5rem 1.25rem;
}
.cu-defi-toggle {
    margin-top: 0.75rem;
    padding-top: 0.75rem;
    border-top: 1px solid var(--border);
}
.toggle-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.85rem;
    cursor: pointer;
}
.toggle-label input[type="checkbox"] {
    width: 16px;
    height: 16px;
    accent-color: var(--accent);
}
.cu-defi-est {
    color: var(--text-muted);
    font-size: 0.8rem;
}

/* ── Summary Cards ───────────────────────────────────────── */
.summary-section {
    display: flex;
    gap: 1rem;
    margin-bottom: 2rem;
    flex-wrap: wrap;
}
.summary-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem 1.25rem;
    flex: 1;
    min-width: 140px;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}
.summary-card--hero {
    flex: 2;
    padding: 1.25rem 1.5rem;
    border-color: var(--accent);
    background: linear-gradient(135deg, var(--surface) 0%, rgba(108, 122, 255, 0.08) 100%);
}
.summary-card--hero .summary-value {
    font-size: 1.8rem;
}
.summary-label {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.summary-value {
    font-size: 1.4rem;
    font-weight: 700;
}

/* ── Section Headings ────────────────────────────────────── */
section { margin-bottom: 2rem; }
section h2 {
    font-size: 1.15rem;
    font-weight: 700;
    margin-bottom: 0.75rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.date-badge {
    font-size: 0.7rem;
    font-weight: 600;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 0.15rem 0.5rem;
    color: var(--text-muted);
}
.live-badge {
    font-size: 0.65rem;
    font-weight: 700;
    background: rgba(52, 211, 153, 0.15);
    color: var(--green);
    border-radius: 4px;
    padding: 0.15rem 0.5rem;
    letter-spacing: 0.06em;
}
.note {
    color: var(--text-muted);
    font-size: 0.85rem;
    margin-bottom: 1rem;
}

/* ── Table ───────────────────────────────────────────────── */
.table-wrapper {
    overflow-x: auto;
}
table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}
thead th {
    text-align: left;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    padding: 0.6rem 0.75rem;
    border-bottom: 1px solid var(--border);
}
thead th.right, tbody td.right { text-align: right; }
tbody tr {
    border-bottom: 1px solid var(--border);
    transition: background 0.1s;
}
tbody tr:hover { background: var(--surface); }
tbody td {
    padding: 0.65rem 0.75rem;
    vertical-align: middle;
}
.token-cell {
    display: flex;
    align-items: center;
    gap: 0.6rem;
}
.token-logo {
    width: 28px; height: 28px;
    border-radius: 50%;
    background: var(--surface2);
    object-fit: cover;
}
.token-logo-placeholder {
    width: 28px; height: 28px;
    border-radius: 50%;
    background: var(--surface2);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.65rem;
    font-weight: 700;
    color: var(--text-muted);
    flex-shrink: 0;
}
.token-name { font-weight: 600; }
.token-symbol { color: var(--text-muted); font-size: 0.82rem; }
.na { color: var(--text-muted); font-style: italic; }
.native-row { background: rgba(108, 122, 255, 0.05); }

/* Chain section header in token table */
.chain-header-row td {
    background: var(--surface);
    padding: 0.5rem 0.75rem;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--accent);
    border-bottom: 2px solid var(--accent);
}
.chain-header-row:hover { background: var(--surface) !important; }

/* Chain note for limited historical data */
.chain-note-row td {
    padding: 0.4rem 0.75rem;
    border-bottom: 1px solid var(--border);
}
.chain-note-row:hover { background: transparent !important; }
.chain-note {
    font-size: 0.78rem;
    color: var(--yellow);
    font-style: italic;
}

/* Expandable per-wallet rows */
.expandable { cursor: pointer; }
.expandable .token-cell::after {
    content: "▸";
    color: var(--text-muted);
    font-size: 0.7rem;
    margin-left: auto;
    transition: transform 0.15s;
}
.expandable.expanded .token-cell::after {
    transform: rotate(90deg);
}
.wallet-breakdown {
    background: var(--surface2);
    font-size: 0.82rem;
}
.wallet-breakdown td {
    padding: 0.4rem 0.75rem 0.4rem 3rem;
    color: var(--text-muted);
}
.wallet-breakdown .wallet-addr {
    font-family: monospace;
    font-size: 0.75rem;
}

/* Shimmer loading for price cells */
.shimmer {
    background: linear-gradient(90deg, var(--surface2) 25%, var(--border) 50%, var(--surface2) 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
    border-radius: 4px;
    height: 1em;
    width: 60px;
    display: inline-block;
}
@keyframes shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* ── DeFi Cards ──────────────────────────────────────────── */
.defi-wallet-group {
    margin-bottom: 1.5rem;
}
.defi-wallet-header {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-muted);
    font-family: monospace;
    margin-bottom: 0.75rem;
    padding-bottom: 0.25rem;
    border-bottom: 1px solid var(--border);
}
.defi-protocol {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem 1.25rem;
    margin-bottom: 0.75rem;
}
.defi-protocol-header {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    margin-bottom: 0.75rem;
}
.defi-protocol-logo {
    width: 24px; height: 24px;
    border-radius: 50%;
}
.defi-protocol-name {
    font-weight: 700;
    font-size: 1rem;
}
.defi-protocol-value {
    margin-left: auto;
    font-weight: 700;
    color: var(--green);
}
.defi-meta {
    display: flex;
    gap: 1.5rem;
    font-size: 0.82rem;
    color: var(--text-muted);
}
.defi-position-list {
    margin-top: 0.75rem;
    font-size: 0.85rem;
    overflow-x: auto;
}
.defi-position-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.82rem;
}
.defi-position-table th {
    text-align: left;
    padding: 0.5rem 0.6rem;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border);
    font-weight: 500;
    white-space: nowrap;
}
.defi-position-table td {
    padding: 0.45rem 0.6rem;
    border-bottom: 1px solid var(--border);
    color: var(--text);
    vertical-align: top;
}
.defi-position-table td.num {
    text-align: right;
    font-variant-numeric: tabular-nums;
}
.defi-position-table td.unclaimed-col {
    color: var(--yellow);
    font-size: 0.78rem;
}
.defi-position-table tbody tr:hover {
    background: var(--surface2);
}
.defi-position-table strong {
    color: var(--accent);
}
.defi-position-table .token-usd {
    color: var(--text-muted);
    font-size: 0.75rem;
}
.defi-position-item {
    padding: 0.5rem 0;
    border-top: 1px solid var(--border);
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem 1.5rem;
}
.defi-position-item span {
    color: var(--text-muted);
}
.defi-position-item strong {
    color: var(--text);
}

.empty-state {
    text-align: center;
    color: var(--text-muted);
    padding: 2rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

/* ── DeFi Protocol History ───────────────────────────────── */
.defi-history-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}
.defi-history-item {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.75rem 1rem;
}
.defi-history-name {
    font-weight: 700;
    font-size: 0.95rem;
    margin-bottom: 0.3rem;
}
.defi-history-meta {
    display: flex;
    gap: 1.5rem;
    font-size: 0.82rem;
    color: var(--text-muted);
    margin-bottom: 0.4rem;
}
.defi-history-categories {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
}
.defi-history-cat {
    font-size: 0.7rem;
    font-weight: 600;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 0.1rem 0.45rem;
    color: var(--text-muted);
    text-transform: capitalize;
}

/* ── TX Logs Tab ─────────────────────────────────────────── */
#tx-lookup-form {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
    margin-bottom: 1.5rem;
}
.tx-detail-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
}
.tx-detail-item {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
}
.tx-detail-label {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.tx-detail-value {
    font-size: 0.9rem;
    word-break: break-all;
}
.monospace { font-family: monospace; font-size: 0.82rem; }
.tx-status-success { color: var(--green); font-weight: 600; }
.tx-status-fail { color: var(--red); font-weight: 600; }
.tx-log-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem 1.25rem;
    margin-bottom: 0.75rem;
}
.tx-log-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 0.5rem;
}
.tx-log-index {
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--text-muted);
    background: var(--surface2);
    padding: 0.1rem 0.4rem;
    border-radius: 4px;
}
.tx-log-event-name {
    font-weight: 700;
    font-size: 0.95rem;
}
.tx-log-address {
    margin-left: auto;
    color: var(--text-muted);
    font-size: 0.8rem;
}
.tx-log-sig {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
    padding: 0.3rem 0.5rem;
    background: var(--surface2);
    border-radius: 4px;
    word-break: break-all;
}
.tx-log-params {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}
.tx-log-param {
    display: grid;
    grid-template-columns: 120px 80px 1fr;
    gap: 0.5rem;
    font-size: 0.82rem;
    align-items: baseline;
}
.tx-log-param-name { font-weight: 600; }
.tx-log-param-type { color: var(--text-muted); font-style: italic; }
.tx-log-param-value {
    font-family: monospace;
    font-size: 0.78rem;
    word-break: break-all;
    color: var(--text-muted);
}

/* ── TRX Tab ────────────────────────────────────────────────── */
#tab-trx {
    max-width: none;
}
#tab-trx .table-wrapper {
    overflow-x: auto;
    max-width: calc(100vw - 3rem);
}
.trx-info-panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
    margin-bottom: 1.5rem;
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.75rem;
}
.trx-info-panel p {
    font-size: 0.9rem;
    color: var(--text-muted);
    margin-bottom: 0;
    flex: 1;
}
.trx-hint {
    font-size: 0.82rem;
    color: var(--text-muted);
    margin-left: 0.75rem;
    font-style: italic;
}
.trx-actions {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    margin-top: 0.5rem;
}
#trx-table {
    font-size: 0.78rem;
    min-width: 1200px;
}
#trx-table thead th {
    font-size: 0.68rem;
    white-space: nowrap;
}
#trx-table tbody td {
    padding: 0.45rem 0.5rem;
}
#trx-table .trx-hash {
    font-family: monospace;
    font-size: 0.72rem;
    color: var(--accent);
    word-break: keep-all;
    cursor: pointer;
}
#trx-table .trx-hash:hover {
    text-decoration: underline;
}
#trx-table .trx-addr {
    font-family: monospace;
    font-size: 0.72rem;
    word-break: keep-all;
    cursor: pointer;
}
#trx-table .trx-addr:hover {
    color: var(--accent);
}
.trx-dir-in {
    color: var(--green);
    font-weight: 600;
}
.trx-dir-out {
    color: var(--red);
    font-weight: 600;
}
.trx-chain-badge {
    font-size: 0.65rem;
    font-weight: 600;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 3px;
    padding: 0.05rem 0.35rem;
    color: var(--text-muted);
    margin-left: 0.3rem;
}

.hidden { display: none !important; }

/* ── Responsive ──────────────────────────────────────────── */
@media (max-width: 640px) {
    .form-top-row {
        flex-direction: column;
    }
    .summary-section {
        flex-direction: column;
    }
    .cu-actions {
        flex-direction: column;
    }
    .wallet-input-row {
        flex-wrap: wrap;
    }
    .wallet-input-row select.wallet-chain {
        width: 100%;
    }
    .tx-detail-grid {
        grid-template-columns: 1fr;
    }
    .tx-log-param {
        grid-template-columns: 1fr;
        gap: 0.1rem;
    }
}
