:root {
    --navy: #071A57;
    --blue: #103FD5;
    --sky: #67BAE4;
    --font: 'Poppins', sans-serif;
    --r: 12px;
    --rs: 8px;
    color-scheme: dark;
}

[data-theme="dark"] {
    --bg: linear-gradient(135deg, #071A57 0%, #0d2fa0 55%, #103FD5 100%);
    --surface: rgba(255, 255, 255, .06);
    --surface-hover: rgba(255, 255, 255, .1);
    --border: rgba(103, 186, 228, .15);
    --border-hover: rgba(103, 186, 228, .3);
    --text: #ffffff;
    --text2: rgba(255, 255, 255, .7);
    --text3: rgba(255, 255, 255, .4);
    --inp-bg: rgba(255, 255, 255, .06);
    --inp-brd: rgba(103, 186, 228, .2);
    --inp-txt: #ffffff;
    --red: #e05252;
    --green: #1ec774;
    --amber: #d9a74a;
    --glow-opacity: 0.15;
    --shadow: rgba(0, 0, 0, .2);
    --th-bg: #091a4f;
    --th-bg-hover: #10266e;
}

[data-theme="light"] {
    color-scheme: light;
    --bg: #f4f4f4;
    --surface: #ffffff;
    --surface-hover: #fcfcfc;
    --border: rgba(7, 26, 87, .09);
    --border-hover: rgba(16, 63, 213, .25);
    --text: #071A57;
    --text2: #4a5472;
    --text3: #8792b0;
    --inp-bg: #f8fafc;
    --inp-brd: rgba(16, 63, 213, .15);
    --inp-txt: #071A57;
    --red: #d63c3c;
    --green: #0e9b58;
    --amber: #b07d1a;
    --glow-opacity: 0.04;
    --shadow: rgba(7, 26, 87, .06);
    --th-bg: #ffffff;
    --th-bg-hover: #f1f5f9;
}

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

html, body {
    min-height: 100%;
    overflow-y: auto;
    font-family: var(--font);
    font-size: 13px;
    background: var(--bg);
    color: var(--text);
    transition: background .4s ease, color .4s ease;
}

/* Background animated glows */
.background-effects {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: -1;
    overflow: hidden;
    pointer-events: none;
}

.glow {
    position: absolute;
    border-radius: 50%;
    filter: blur(120px);
    opacity: var(--glow-opacity);
    transition: opacity .4s ease;
}

.glow-1 {
    top: -10%;
    right: 10%;
    width: 40vw;
    height: 40vw;
    background: var(--sky);
}

.glow-2 {
    bottom: -10%;
    left: 10%;
    width: 45vw;
    height: 45vw;
    background: var(--blue);
}

/* ── TOPBAR ── */
.topbar {
    position: sticky;
    top: 0;
    display: flex;
    justify-content: center;
    width: 100%;
    background: rgba(0, 0, 0, .2);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-bottom: 1px solid var(--border);
    transition: background .4s, border-color .4s;
    z-index: 100;
    box-shadow: 0 4px 30px rgba(0, 0, 0, 0.05);
}

[data-theme="light"] .topbar {
    background: rgba(255, 255, 255, .75);
}

.topbar-content {
    width: 100%;
    max-width: 1200px;
    padding: 0 24px;
    height: 64px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}

.brand {
    display: flex;
    align-items: center;
    height: 38px;
    text-decoration: none;
}

.brand img {
    height: 100%;
    object-fit: contain;
    transition: transform .2s ease;
}

.brand img:hover {
    transform: scale(1.02);
}

.logo-dark { display: block; }
.logo-light { display: none; }

[data-theme="light"] .logo-dark { display: none; }
[data-theme="light"] .logo-light { display: block; }

.topbar-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--text2);
    letter-spacing: .1em;
    text-transform: uppercase;
    flex: 1;
    text-align: center;
}

.toggle-wrap {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--text2);
    font-weight: 500;
}

.toggle {
    width: 44px;
    height: 22px;
    background: rgba(255, 255, 255, .15);
    border: 1px solid rgba(255, 255, 255, .2);
    border-radius: 12px;
    cursor: pointer;
    position: relative;
    transition: background .3s;
    flex-shrink: 0;
    outline: none;
}

[data-theme="light"] .toggle {
    background: rgba(7, 26, 87, .12);
    border-color: rgba(7, 26, 87, .18);
}

.toggle::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 3px;
    width: 16px;
    height: 16px;
    background: #ffffff;
    border-radius: 50%;
    transition: transform .3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 2px 4px rgba(0, 0, 0, .2);
}

[data-theme="light"] .toggle::after {
    transform: translateX(20px);
    background: var(--navy);
}

/* ── CONTAINER LAYOUT ── */
.container {
    width: 100%;
    max-width: 1200px;
    padding: 32px 24px 64px;
    display: flex;
    flex-direction: column;
    gap: 24px;
    margin: 0 auto;
}

.hero-section {
    margin-bottom: 8px;
}

.hero-section h1 {
    font-size: 28px;
    font-weight: 700;
    letter-spacing: -0.5px;
    margin-bottom: 8px;
    background: linear-gradient(135deg, var(--text) 30%, var(--sky) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

[data-theme="light"] .hero-section h1 {
    background: linear-gradient(135deg, var(--navy) 40%, var(--blue) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.hero-section p {
    font-size: 14px;
    color: var(--text2);
    line-height: 1.6;
    max-width: 800px;
}

/* ── CARDS (GLASSMORPHISM) ── */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r);
    padding: 20px 24px;
    box-shadow: 0 4px 20px var(--shadow);
    transition: background .3s, border-color .3s, transform .2s, box-shadow .3s;
}

.card:hover {
    border-color: var(--border-hover);
    background: var(--surface-hover);
}

.sect-label {
    font-size: 11px;
    font-weight: 600;
    color: var(--sky);
    text-transform: uppercase;
    letter-spacing: .08em;
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    gap: 8px;
}

[data-theme="light"] .sect-label {
    color: var(--blue);
}

/* ── QUERY PANEL ── */
.query-panel {
    background: var(--surface);
}

.query-row {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    align-items: flex-end;
    margin-bottom: 16px;
}

.input-group {
    flex: 1;
    min-width: 200px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.input-group label {
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    color: var(--text2);
    letter-spacing: .05em;
}

.input-group input, .input-group select, .filter-col select, .filter-col input {
    width: 100%;
    padding: 10px 14px;
    background: var(--inp-bg);
    border: 1.5px solid var(--inp-brd);
    border-radius: var(--rs);
    font-family: var(--font);
    font-size: 13px;
    font-weight: 500;
    color: var(--inp-txt);
    outline: none;
    transition: border-color .2s, background .3s;
}

select option {
    background-color: #071A57;
    color: #ffffff;
}

[data-theme="light"] select option {
    background-color: #ffffff;
    color: #071A57;
}

.input-group input:focus, .input-group select:focus, .filter-col select:focus, .filter-col input:focus {
    border-color: var(--sky);
}

[data-theme="light"] .input-group input:focus, 
[data-theme="light"] .input-group select:focus,
[data-theme="light"] .filter-col select:focus,
[data-theme="light"] .filter-col input:focus {
    border-color: var(--blue);
}

.button-group {
    display: flex;
    align-items: flex-end;
}

/* ── BUTTONS ── */
.btn {
    padding: 11px 24px;
    font-family: var(--font);
    font-size: 13px;
    font-weight: 600;
    border-radius: var(--rs);
    border: none;
    cursor: pointer;
    transition: all .2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    text-decoration: none;
}

.btn-primary {
    background: linear-gradient(135deg, var(--sky) 0%, var(--blue) 100%);
    color: #ffffff;
    box-shadow: 0 4px 15px rgba(16, 63, 213, .3);
}

.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 20px rgba(16, 63, 213, .45);
    filter: brightness(1.05);
}

.btn-secondary {
    background: var(--inp-bg);
    border: 1.5px solid var(--inp-brd);
    color: var(--text);
}

.btn-secondary:hover {
    border-color: var(--sky);
    background: rgba(255, 255, 255, .05);
}

[data-theme="light"] .btn-secondary:hover {
    border-color: var(--blue);
    background: rgba(16, 63, 213, .05);
}

/* Info and alert boxes */
.info-box {
    background: rgba(103, 186, 228, .07);
    border: 1px solid rgba(103, 186, 228, .18);
    border-radius: var(--rs);
    padding: 12px 16px;
    font-size: 11.5px;
    line-height: 1.6;
    color: var(--text2);
    margin-top: 16px;
}

.info-box strong {
    color: var(--sky);
}

[data-theme="light"] .info-box {
    background: rgba(16, 63, 213, .04);
    border-color: rgba(16, 63, 213, .12);
}

[data-theme="light"] .info-box strong {
    color: var(--blue);
}

/* ── COOLDOWN TIMER ── */
.cooldown-container {
    margin-top: 16px;
    background: rgba(224, 82, 82, .06);
    border: 1px solid rgba(224, 82, 82, .18);
    border-radius: var(--rs);
    padding: 12px 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.cooldown-header {
    display: flex;
    justify-content: space-between;
    font-weight: 600;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: .02em;
    color: var(--red);
}

.cooldown-bar-wrap {
    width: 100%;
    height: 6px;
    background: rgba(255, 255, 255, .1);
    border-radius: 3px;
    overflow: hidden;
}

.cooldown-progress-bar {
    height: 100%;
    background: var(--red);
    border-radius: 3px;
    transition: width 1s linear;
}

/* ── METRICS SUMMARY CARDS ── */
.metrics {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 16px;
    margin-bottom: 16px; /* Added spacing between metrics and charts below */
}

@media (min-width: 768px) {
    .metrics {
        grid-template-columns: 1.55fr 1.15fr 1.15fr 0.65fr;
    }
}

.metric {
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.metric .m-lbl {
    font-size: 10px;
    font-weight: 600;
    color: var(--text2);
    text-transform: uppercase;
    letter-spacing: .06em;
    margin-bottom: 8px;
}

.metric .m-val {
    font-size: 32px;
    font-weight: 700;
    letter-spacing: -0.5px;
    line-height: 1.2;
    color: var(--text);
    white-space: nowrap;
}

.metric .m-val.green { color: var(--green); }
.metric .m-val.sky { color: var(--sky); }
.metric .m-val.amber { color: var(--amber); }

[data-theme="light"] .metric .m-val.sky {
    color: var(--blue);
}

.metric .m-sub {
    font-size: 10px;
    color: var(--text3);
    margin-top: 4px;
    font-weight: 500;
}

/* ── CHARTS GRID ── */
.charts-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
    margin-bottom: 24px; /* Added spacing between charts and filters below */
}

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

.chart-card {
    min-height: 280px;
    display: flex;
    flex-direction: column;
}

.chart-container {
    position: relative;
    flex: 1;
    width: 100%;
    height: 100%;
    min-height: 220px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* ── FILTERS ── */
.table-filters {
    margin-bottom: 16px;
}

.filters-row {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: center;
}

.filter-col {
    flex: 1;
    min-width: 160px;
}

.filter-col.search-col {
    flex: 2.5;
    min-width: 250px;
}

.filter-col.action-col {
    flex: 0 0 auto;
    min-width: unset;
}

/* ── DATA TABLE ── */
.table-card {
    padding: 16px 0;
    overflow: hidden;
}

.table-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 24px;
    margin-bottom: 12px;
}

.table-header .sect-label {
    margin-bottom: 0;
}

.table-totals-label {
    font-size: 11px;
    font-weight: 500;
    color: var(--text3);
}

.table-responsive {
    width: 100%;
    max-height: 500px; /* Limit height to show scrollbar */
    overflow-y: auto; /* Enable vertical scrolling */
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
    text-align: left;
}

.data-table th, .data-table td {
    padding: 12px 24px;
    border-bottom: 1px solid var(--border);
}

.data-table th {
    position: sticky;
    top: 0;
    z-index: 10;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .05em;
    font-size: 9.5px;
    color: var(--text2);
    background-color: var(--th-bg);
    user-select: none;
    transition: background .2s;
    border-bottom: 2px solid var(--border);
}

.data-table th.sortable {
    cursor: pointer;
}

.data-table th.sortable:hover {
    background-color: var(--th-bg-hover);
    color: var(--text);
}

.data-table th .sort-icon {
    font-size: 11px;
    margin-left: 4px;
    opacity: 0.5;
}

.data-table tr {
    transition: background .2s;
}

.data-table tbody tr:hover {
    background: rgba(255, 255, 255, .02);
}

[data-theme="light"] .data-table tbody tr:hover {
    background: rgba(7, 26, 87, .01);
}

.data-table td {
    font-weight: 500;
    color: var(--text2);
    white-space: nowrap;
}

.data-table td.monto-val {
    font-weight: 600;
    color: var(--text);
}

.badge {
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 9.5px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .02em;
    display: inline-block;
}

.badge-instrument {
    background: rgba(103, 186, 228, .12);
    color: var(--sky);
}
[data-theme="light"] .badge-instrument {
    background: rgba(16, 63, 213, .08);
    color: var(--blue);
}

.badge-segment {
    background: rgba(255, 255, 255, .06);
    color: var(--text2);
    border: 1px solid var(--border);
}

.badge-segment.avalado {
    background: rgba(30, 199, 116, .1);
    color: var(--green);
    border-color: rgba(30, 199, 116, .15);
}

.badge-segment.patrocinado {
    background: rgba(103, 186, 228, .1);
    color: var(--sky);
    border-color: rgba(103, 186, 228, .15);
}
[data-theme="light"] .badge-segment.patrocinado {
    color: var(--blue);
    border-color: rgba(16, 63, 213, .12);
}

/* ── STATE PANELS ── */
.state-panel {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 40px;
    text-align: center;
    gap: 16px;
}

.state-panel h3 {
    font-size: 18px;
    font-weight: 600;
    margin-top: 8px;
}

.state-panel p {
    color: var(--text2);
    max-width: 450px;
    line-height: 1.6;
}

.state-panel.error {
    border-color: rgba(224, 82, 82, .3);
}

.error-icon {
    font-size: 40px;
    color: var(--red);
    line-height: 1;
}

/* Loading spinner */
.spinner {
    width: 44px;
    height: 44px;
    border: 4px solid var(--border);
    border-top: 4px solid var(--sky);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

[data-theme="light"] .spinner {
    border-top-color: var(--blue);
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* ── FOOTER ── */
.footer {
    width: 100%;
    padding: 32px 24px;
    text-align: center;
    border-top: 1px solid var(--border);
    color: var(--text3);
    font-size: 11px;
    background: rgba(0, 0, 0, .05);
}

/* ── ANIMATIONS ── */
.animate-slide-up {
    opacity: 0;
    transform: translateY(12px);
    animation: slideUp 0.5s cubic-bezier(0.1, 0.8, 0.2, 1) forwards;
}

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

.hidden {
    display: none !important;
}

/* Custom Scrollbars */
::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.1);
    border-radius: 6px;
}

[data-theme="light"] ::-webkit-scrollbar-track {
    background: rgba(7, 26, 87, 0.03);
}

::-webkit-scrollbar-thumb {
    background: rgba(103, 186, 228, 0.25);
    border: 2px solid transparent;
    background-clip: padding-box;
    border-radius: 6px;
    transition: background 0.3s;
}

[data-theme="light"] ::-webkit-scrollbar-thumb {
    background: rgba(16, 63, 213, 0.2);
    border: 2px solid transparent;
    background-clip: padding-box;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--sky);
    border: 2px solid transparent;
    background-clip: padding-box;
}

[data-theme="light"] ::-webkit-scrollbar-thumb:hover {
    background: var(--blue);
    border: 2px solid transparent;
    background-clip: padding-box;
}

/* For Firefox / standard scrollbar style compatibility */
html, .table-responsive {
    scrollbar-width: thin;
    scrollbar-color: rgba(103, 186, 228, 0.25) rgba(0, 0, 0, 0.1);
}

[data-theme="light"] html, [data-theme="light"] .table-responsive {
    scrollbar-color: rgba(16, 63, 213, 0.2) rgba(7, 26, 87, 0.03);
}
