@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap');

:root {
    --bg: #f8fafc;
    --surface: rgba(255, 255, 255, 0.92);
    --surface-solid: #ffffff;
    --border: #e2e8f0;
    --text: #0f172a;
    --muted: #64748b;
    --primary: #0f62fe;
    --primary-hover: #0043ce;
    --positive: #24a148;
    --negative: #fa4d56;
    --warning: #e0a100;
    --shadow: 0 18px 40px rgba(15, 23, 42, 0.08);
    --radius: 18px;
}

* {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    padding: 0;
}

body {
    min-height: 100vh;
    padding: 24px;
    display: flex;
    justify-content: flex-start;
    align-items: center;
    flex-direction: column;
    background:
        radial-gradient(circle at top, rgba(15, 98, 254, 0.10), transparent 30%),
        linear-gradient(180deg, #f8fafc 0%, #eef2ff 100%);
    color: var(--text);
    font-family: 'Inter', sans-serif;
    line-height: 1.55;
    overflow-x: hidden;
}

h1 {
    margin: 0 0 4px;
    font-size: clamp(2rem, 4vw, 3rem);
    line-height: 1.1;
    letter-spacing: -0.03em;
    text-align: center;
    color: var(--text);
}

h2 {
    margin: 0 0 16px;
    font-size: 1.1rem;
    letter-spacing: -0.02em;
}

.container {
    width: 100%;
    max-width: 1200px;
    display: flex;
    flex-direction: column;
    gap: 18px;
}

.token-section,
.account-selector,
.overview-section,
.account-info,
.charts-container,
.composition-section,
.history-section {
    background: var(--surface);
    backdrop-filter: blur(12px);
    border: 1px solid rgba(226, 232, 240, 0.9);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 22px;
}

.token-section {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.token-input-container {
    display: flex;
    gap: 12px;
    align-items: center;
    flex-wrap: wrap;
}

.token-input-wrapper {
    position: relative;
    flex: 1;
    min-width: 260px;
}

.token-input-container input#api-token,
.account-selector select {
    width: 100%;
    min-height: 48px;
    padding: 0.8rem 1rem;
    border: 1px solid var(--border);
    border-radius: 14px;
    background: var(--surface-solid);
    color: var(--text);
    font-size: 16px;
    transition: border-color 0.2s ease, box-shadow 0.2s ease, transform 0.2s ease;
}

.token-input-container input#api-token {
    padding-right: 3rem;
}

.token-input-container input#api-token:focus,
.account-selector select:focus {
    outline: none;
    border-color: rgba(15, 98, 254, 0.55);
    box-shadow: 0 0 0 4px rgba(15, 98, 254, 0.12);
}

.token-input-container input#api-token.valid {
    border-color: rgba(36, 161, 72, 0.7);
}

.token-input-container input#api-token.invalid {
    border-color: rgba(250, 77, 86, 0.7);
}

.toggle-password {
    position: absolute;
    right: 0.8rem;
    top: 50%;
    transform: translateY(-50%);
    border: none;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
    padding: 6px;
    border-radius: 999px;
}

.toggle-password:hover {
    color: var(--text);
    background: rgba(100, 116, 139, 0.10);
}

button {
    font: inherit;
}

#fetch-accounts,
.toggle-section,
.chart-controls button {
    border: none;
    border-radius: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.18s ease, background 0.18s ease, color 0.18s ease, box-shadow 0.18s ease;
}

#fetch-accounts,
.toggle-section {
    min-height: 48px;
    padding: 0.85rem 1.2rem;
    background: var(--primary);
    color: #fff;
    box-shadow: 0 10px 24px rgba(15, 98, 254, 0.18);
}

#fetch-accounts:hover,
.toggle-section:hover,
.toggle-section.active {
    background: var(--primary-hover);
}

#fetch-accounts:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    box-shadow: none;
}

#loading-indicator,
#error-message,
#warning-message {
    margin-top: 4px;
    border-radius: 14px;
    padding: 0.9rem 1rem;
    text-align: center;
}

#loading-indicator {
    background: rgba(15, 98, 254, 0.08);
    border: 1px solid rgba(15, 98, 254, 0.16);
    color: var(--primary);
}

#error-message {
    background: rgba(250, 77, 86, 0.08);
    border: 1px solid rgba(250, 77, 86, 0.16);
    color: var(--negative);
}

#warning-message {
    background: rgba(224, 161, 0, 0.08);
    border: 1px solid rgba(224, 161, 0, 0.18);
    color: #8a6100;
}

.account-selector,
.overview-section,
.account-info,
.composition-section,
.history-section {
    margin-top: 2px;
}

.overview-section.fade-hidden::before {
    content: 'Selecciona una cuenta para ver el resumen.';
    display: block;
    text-align: center;
    color: var(--muted);
    font-style: italic;
}

.overview-grid,
.account-info-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 14px;
}

.overview-item,
.account-info-item {
    background: linear-gradient(180deg, rgba(241, 245, 249, 0.9), rgba(248, 250, 252, 0.9));
    border: 1px solid rgba(226, 232, 240, 0.9);
    border-radius: 16px;
    padding: 18px;
    text-align: center;
}

.overview-item p,
.account-info-item p {
    margin: 0 0 6px;
    font-size: 1.2rem;
    font-weight: 800;
    letter-spacing: -0.02em;
}

.overview-item span,
.account-info-item span {
    color: var(--muted);
    font-size: 0.92rem;
}

.positive-value { color: var(--positive); }
.negative-value { color: var(--negative); }

.charts-container {
    display: flex;
    flex-direction: column;
    gap: 18px;
}

.chart-section {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.chart-controls {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.chart-controls button {
    padding: 0.7rem 1rem;
    background: #e2e8f0;
    color: var(--text);
}

.chart-controls button:hover,
.chart-controls button.active {
    background: rgba(15, 98, 254, 0.12);
    color: var(--primary);
}

.chart-section canvas {
    width: 100%;
    max-height: 320px;
}

.composition-section,
.history-section {
    overflow-x: auto;
}

.composition-table,
.history-table {
    width: 100%;
    min-width: 620px;
    border-collapse: collapse;
    margin-top: 10px;
}

.composition-table th,
.composition-table td,
.history-table th,
.history-table td {
    border-bottom: 1px solid rgba(226, 232, 240, 0.95);
    padding: 0.8rem 0.9rem;
    text-align: left;
    white-space: nowrap;
}

.composition-table th,
.history-table th {
    color: var(--muted);
    font-size: 0.84rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    background: rgba(241, 245, 249, 0.8);
}

.weight-bar {
    width: 110px;
    height: 10px;
    background: rgba(226, 232, 240, 1);
    border-radius: 999px;
    overflow: hidden;
    display: inline-block;
    vertical-align: middle;
    margin-right: 8px;
}

.weight-bar-fill {
    height: 100%;
    background: var(--primary);
}

.fade-hidden {
    opacity: 0;
    pointer-events: none;
    max-height: 0;
    overflow: hidden;
    transition: opacity 0.22s ease, max-height 0.22s ease;
}

.fade-visible {
    opacity: 1;
    pointer-events: auto;
    max-height: 3000px;
    transition: opacity 0.22s ease, max-height 0.22s ease;
}

.height-hidden {
    max-height: 0;
    opacity: 0;
    overflow: hidden;
    pointer-events: none;
    transition: max-height 0.4s ease, opacity 0.22s ease;
}

.height-visible {
    max-height: 3000px;
    opacity: 1;
    pointer-events: auto;
    transition: max-height 0.4s ease, opacity 0.22s ease;
}

@media (min-width: 900px) {
    .charts-container {
        flex-direction: row;
        align-items: stretch;
    }

    .chart-section {
        flex: 1;
        min-width: 0;
    }
}

@media (max-width: 768px) {
    body {
        padding: 16px;
    }

    .token-section,
    .account-selector,
    .overview-section,
    .account-info,
    .charts-container,
    .composition-section,
    .history-section {
        padding: 18px;
        border-radius: 16px;
    }

    .token-input-container {
        flex-direction: column;
        align-items: stretch;
    }

    .token-input-wrapper {
        min-width: 0;
    }

    #fetch-accounts {
        width: 100%;
    }

    .composition-table,
    .history-table {
        min-width: 560px;
    }
}

@media (max-width: 420px) {
    body {
        padding: 12px;
    }

    h1 {
        font-size: 1.8rem;
    }

    .composition-table,
    .history-table {
        min-width: 500px;
    }
}
