:root {
    --primary-gradient: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    --glass-bg: rgba(255, 255, 255, 0.05);
    --glass-border: rgba(255, 255, 255, 0.1);
    --text-primary: #ffffff;
    --text-secondary: rgba(255, 255, 255, 0.6);
    --accent-color: #a78bfa;
    --success-color: #10b981;
    --warning-color: #f59e0b;
    --error-color: #ef4444;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    /* Firefox */
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.2) transparent;
}

/* Custom Scrollbar Global */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.3);
}

body {
    font-family: 'Inter', sans-serif;
    background-color: #0f172a;
    color: var(--text-primary);
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow-y: auto;
    /* Allow scrolling if content overflows */
    position: relative;
}

/* Background Animation */
.background-blobs {
    position: absolute;
    width: 100%;
    height: 100%;
    z-index: 0;
    overflow: hidden;
}

.blob {
    position: absolute;
    border-radius: 50%;
    filter: blur(80px);
    opacity: 0.4;
    animation: drift 20s infinite alternate;
}

.blob-1 {
    top: -10%;
    left: -10%;
    width: 500px;
    height: 500px;
    background: #764ba2;
    animation-delay: 0s;
}

.blob-2 {
    bottom: -10%;
    right: -10%;
    width: 600px;
    height: 600px;
    background: #667eea;
    animation-delay: -5s;
}

.blob-3 {
    top: 40%;
    left: 40%;
    width: 300px;
    height: 300px;
    background: #ec4899;
    animation-delay: -10s;
}

@keyframes drift {
    0% {
        transform: translate(0, 0);
    }

    100% {
        transform: translate(50px, 30px);
    }
}

/* Main Layout */
.main-layout {
    width: 100%;
    /* max-width removed to allow full positioning context */
    padding: 20px;
    position: relative;
    z-index: 10;

    /* Default: Stacked (Mobile/Tablet methodology) */
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 24px;

    transition: all 0.3s ease;
}

/* Ensure card doesn't shrink */
.card {
    width: 100%;
    max-width: 420px;
    flex-shrink: 0;
    margin: 0 auto;
    /* Center in standard flow */

    /* Mobile Order: 1. Main Card */
    order: 1;
}

/* Side Panels Default (Mobile) Order */
.side-panel.left-panel {
    /* Mobile Order: 3. Models List (Bottom) */
    order: 3;
}

.side-panel:not(.left-panel) {
    /* Mobile Order: 2. Chart (Middle) */
    order: 2;
}

.card {
    background: var(--glass-bg);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--glass-border);
    border-radius: 24px;
    padding: 32px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    transition: transform 0.3s ease;

    /* Flex layout for height sync */
    display: flex;
    flex-direction: column;
}

/* Language Switcher */
.lang-switch {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    position: relative;
    margin-bottom: 8px;
    /* Add some space between switcher and header */
    width: 100%;
}

.lang-switch select {
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid var(--glass-border);
    border-radius: 8px;
    padding: 6px 32px 6px 12px;
    color: var(--text-secondary);
    font-size: 13px;
    outline: none;
    cursor: pointer;
    appearance: none;
    -webkit-appearance: none;
    font-family: 'Inter', sans-serif;
    transition: all 0.3s ease;
}

.lang-switch select:hover {
    background: rgba(0, 0, 0, 0.4);
    color: #fff;
    border-color: var(--accent-color);
}

.lang-switch .lang-icon {
    position: absolute;
    right: 10px;
    width: 14px;
    height: 14px;
    color: var(--text-secondary);
    pointer-events: none;
}

header {
    text-align: center;
    margin-bottom: 32px;
}

h1 {
    font-size: 28px;
    font-weight: 700;
    color: #ffffff;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
    margin-bottom: 8px;
}

.subtitle {
    color: rgba(255, 255, 255, 0.9);
    font-size: 14px;
    font-weight: 500;
}

/* Input Section */
.input-group {
    margin-bottom: 24px;
}

.input-wrapper {
    position: relative;
    margin-bottom: 16px;
}

.input-wrapper .icon {
    position: absolute;
    left: 16px;
    top: 50%;
    transform: translateY(-50%);
    width: 20px;
    height: 20px;
    color: var(--text-secondary);
}

input {
    width: 100%;
    padding: 14px 16px 14px 48px;
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    color: #fff;
    font-size: 14px;
    outline: none;
    transition: all 0.3s ease;
    font-family: 'Inter', sans-serif;
}

input:focus {
    border-color: var(--accent-color);
    box-shadow: 0 0 0 4px rgba(167, 139, 250, 0.1);
    background: rgba(0, 0, 0, 0.4);
}

button {
    width: 100%;
    padding: 14px;
    border: none;
    border-radius: 12px;
    background: var(--primary-gradient);
    color: #fff;
    font-weight: 600;
    font-size: 15px;
    cursor: pointer;
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
}

button:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 20px -10px rgba(118, 75, 162, 0.5);
}

button:active {
    transform: translateY(0);
}

button:disabled {
    opacity: 0.7;
    cursor: not-allowed;
    transform: none;
}

/* Loading State */
.btn-text {
    display: inline-block;
}

.btn-loader {
    display: none;
    width: 20px;
    height: 20px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top-color: #fff;
    animation: spin 0.8s linear infinite;
    position: absolute;
    left: 50%;
    top: 50%;
    margin-left: -10px;
    margin-top: -10px;
}

.loading .btn-text {
    visibility: hidden;
}

.loading .btn-loader {
    display: block;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* Result Section */
.hidden {
    display: none !important;
    opacity: 0;
}

.result-container {
    animation: fadeIn 0.5s ease forwards;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.user-info {
    display: flex;
    align-items: center;
    margin-bottom: 12px;
    padding: 12px;
    background: rgba(255, 255, 255, 0.03);
    border-radius: 12px;
}

.avatar-placeholder {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: linear-gradient(135deg, #a78bfa, #ec4899);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 18px;
    margin-right: 12px;
    color: #fff;
}

.details h2 {
    font-size: 16px;
    font-weight: 600;
}

.details p {
    font-size: 12px;
    color: var(--text-secondary);
}

.balance-card {
    background: linear-gradient(135deg, rgba(16, 185, 129, 0.1), rgba(5, 150, 105, 0.05));
    border: 1px solid rgba(16, 185, 129, 0.2);
    border-radius: 16px;
    padding: 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

.balance-item {
    text-align: center;
    flex: 1;
}

.balance-divider {
    width: 1px;
    height: 30px;
    background: rgba(255, 255, 255, 0.1);
    margin: 0 10px;
}

.label {
    display: block;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

.value {
    display: block;
    font-size: 18px;
    font-weight: 700;
    color: #fff;
}

.status-active {
    color: var(--success-color);
}

.info-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 13px;
    padding: 12px 16px;
    margin-bottom: 12px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
}

.value-text {
    color: var(--text-secondary);
    font-family: monospace;
}

/* Error Message */
.error-message {
    margin-top: 16px;
    padding: 12px;
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid rgba(239, 68, 68, 0.2);
    border-radius: 8px;
    display: flex;
    align-items: center;
    color: #fca5a5;
    font-size: 13px;
    animation: fadeIn 0.3s ease forwards;
}

.error-icon {
    width: 16px;
    height: 16px;
    margin-right: 8px;
    flex-shrink: 0;
}

/* Card Footer */
.card-footer {
    margin-top: auto;
    /* Push to bottom when card expands */
    padding-top: 20px;
    border-top: 1px solid var(--glass-border);
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 16px;
    font-size: 13px;
}

.card-footer a {
    color: var(--text-secondary);
    text-decoration: none;
    display: flex;
    align-items: center;
    transition: all 0.3s ease;
    gap: 6px;
}

.card-footer a:hover {
    color: #fff;
}

.footer-icon {
    width: 16px;
    height: 16px;
    opacity: 0.8;
}

.card-footer a:hover .footer-icon {
    opacity: 1;
}

.footer-divider {
    color: var(--glass-border);
}

/* Unified spacing for control items */
.result-container+.history-control,
.history-control+#trackingContainer,
#trackingContainer+.history-control,
.history-control+.history-control {
    margin-top: 12px;
}

/* Tracking Control */
.track-control {
    padding: 16px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    animation: fadeIn 0.5s ease forwards;
    cursor: pointer;
    transition: all 0.3s ease;
}

.track-control:hover {
    background: rgba(255, 255, 255, 0.05);
    border-color: var(--accent-color);
}

.track-checkbox {
    display: flex;
    align-items: center;
    cursor: pointer;
    user-select: none;
    position: relative;
    padding-left: 32px;
}

.track-checkbox input[type="checkbox"] {
    position: absolute;
    opacity: 0;
    cursor: pointer;
    height: 0;
    width: 0;
}

.track-checkbox .checkmark {
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    height: 20px;
    width: 20px;
    background: rgba(0, 0, 0, 0.3);
    border: 2px solid var(--glass-border);
    border-radius: 6px;
    transition: all 0.3s ease;
}

.track-checkbox:hover .checkmark {
    border-color: var(--accent-color);
    background: rgba(167, 139, 250, 0.1);
}

.track-checkbox input[type="checkbox"]:checked~.checkmark {
    background: linear-gradient(135deg, #667eea, #764ba2);
    border-color: #764ba2;
}

.track-checkbox .checkmark:after {
    content: "";
    position: absolute;
    display: none;
    left: 6px;
    top: 2px;
    width: 5px;
    height: 10px;
    border: solid white;
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
}

.track-checkbox input[type="checkbox"]:checked~.checkmark:after {
    display: block;
}

.track-label {
    font-size: 14px;
    font-weight: 600;
    color: #fff;
}

.track-hint {
    margin-top: 8px;
    margin-left: 32px;
    font-size: 12px;
    color: var(--text-secondary);
    line-height: 1.5;
}

/* History Control  */
.history-control {
    padding: 16px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.3s ease;
    animation: fadeIn 0.5s ease forwards;
}

.history-control:hover {
    background: rgba(255, 255, 255, 0.05);
    border-color: var(--accent-color);
}

.history-checkbox {
    display: flex;
    align-items: center;
    cursor: pointer;
    user-select: none;
    position: relative;
    padding-left: 32px;
}

.history-checkbox input[type="checkbox"] {
    position: absolute;
    opacity: 0;
    cursor: pointer;
    height: 0;
    width: 0;
}

.history-checkbox .checkmark {
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    height: 20px;
    width: 20px;
    background: rgba(0, 0, 0, 0.3);
    border: 2px solid var(--glass-border);
    border-radius: 6px;
    transition: all 0.3s ease;
}

.history-checkbox:hover .checkmark {
    border-color: var(--accent-color);
    background: rgba(167, 139, 250, 0.1);
}

.history-checkbox input[type="checkbox"]:checked~.checkmark {
    background: linear-gradient(135deg, #667eea, #764ba2);
    border-color: #764ba2;
}

.history-checkbox .checkmark:after {
    content: "";
    position: absolute;
    display: none;
    left: 6px;
    top: 2px;
    width: 5px;
    height: 10px;
    border: solid white;
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
}

.history-checkbox input[type="checkbox"]:checked~.checkmark:after {
    display: block;
}

.history-label {
    font-size: 14px;
    font-weight: 600;
    color: #fff;
}

.history-hint {
    margin-top: 8px;
    margin-left: 32px;
    font-size: 12px;
    color: var(--text-secondary);
    line-height: 1.5;
}

/* Disabled state for history-control when checkbox is disabled */
.history-control:has(input[type="checkbox"]:disabled) {
    opacity: 0.6;
    cursor: not-allowed;
}

.history-control:has(input[type="checkbox"]:disabled):hover {
    background: rgba(255, 255, 255, 0.03);
    border-color: var(--glass-border);
}

.history-checkbox input[type="checkbox"]:disabled~.checkmark {
    opacity: 0.6;
    cursor: not-allowed;
}

/* Query History List */
.history-list-container {
    margin-top: 16px;
    padding: 16px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    animation: fadeIn 0.5s ease forwards;
}

.history-list-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    font-size: 14px;
    font-weight: 600;
    color: #fff;
    margin-bottom: 12px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--glass-border);
}

.history-list-title .title-icon {
    width: 18px;
    height: 18px;
    color: var(--accent-color);
    flex-shrink: 0;
}

/* Overview Button */
.history-overview-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    font-size: 12px;
    font-weight: 500;
    background: rgba(167, 139, 250, 0.15);
    border: 1px solid rgba(167, 139, 250, 0.3);
    border-radius: 8px;
    color: var(--accent-color);
    cursor: pointer;
    transition: all 0.3s ease;
    white-space: nowrap;
    width: auto;
}

.history-overview-btn:hover {
    background: rgba(167, 139, 250, 0.25);
    border-color: var(--accent-color);
    color: #fff;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(167, 139, 250, 0.3);
}

.history-overview-btn:active {
    transform: translateY(0);
}

.history-overview-btn svg {
    flex-shrink: 0;
}

.history-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    overflow-y: auto;
    /* max-height is set dynamically by JavaScript based on available space */
}

.history-item {
    display: grid;
    grid-template-columns: 1fr auto auto auto;
    gap: 8px;
    align-items: center;
    padding: 10px 12px;
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid var(--glass-border);
    border-radius: 8px;
    transition: all 0.3s ease;
}

.history-item:hover {
    background: rgba(0, 0, 0, 0.3);
    border-color: var(--accent-color);
}

.history-key {
    font-size: 13px;
    color: var(--text-primary);
    font-family: monospace;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.history-time {
    font-size: 11px;
    color: var(--text-secondary);
}

.history-use-btn,
.history-delete-btn {
    padding: 4px 12px;
    font-size: 12px;
    border-radius: 6px;
    border: none;
    cursor: pointer;
    transition: all 0.3s ease;
    font-weight: 500;
}

.history-use-btn {
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: #fff;
}

.history-use-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(102, 126, 234, 0.3);
}

.history-delete-btn {
    background: rgba(239, 68, 68, 0.2);
    color: #ef4444;
    padding: 4px 8px;
    font-size: 18px;
    line-height: 1;
}

.history-delete-btn:hover {
    background: rgba(239, 68, 68, 0.3);
    color: #fca5a5;
}

.history-empty {
    text-align: center;
    padding: 20px;
    color: var(--text-secondary);
    font-size: 13px;
}

/* Side Panel */
.side-panel {
    /* Default: Width constrained for stacking */
    width: 100%;
    max-width: 580px;

    opacity: 1;
    transform: translateX(0);
    transition: all 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Desktop Layout (> 1100px) */
/* Desktop Layout (> 1280px) */
@media (min-width: 1280px) {
    .main-layout {
        display: grid;
        grid-template-columns: 1fr auto 1fr;
        /* 3 Columns: Flexible - Fixed - Flexible */
        align-items: center;
        /* Default: Center vertically (Idle state) */
        gap: 24px;

        /* Full height layout management */
        height: 100%;
        width: 100%;
        max-width: 100%;
        /* Allow full width for grid to work */

        /* Remove old padding hacks */
        padding: 20px;
    }

    /* 
       When any side panel is visible (Dashboard state), 
       switch to stretch to make all columns full height 
    */
    .main-layout:has(.side-panel:not(.hidden)) {
        align-items: stretch;
    }

    /* Shared layout properties */
    .card,
    .side-panel.left-panel,
    .side-panel:not(.left-panel) {
        margin: 0;
        display: flex;
        flex-direction: column;

        /* Reset positioning */
        position: relative;
        transform: none;
        opacity: 1;

        /* Ensure height management */
        height: 100%;
        min-height: 0;
        max-height: 100%;
    }

    /* Left Panel: In first column, pushed right */
    .side-panel.left-panel {
        grid-column: 1;
        justify-self: end;
        width: 400px;
        order: 1;
        /* Desktop Order: 1 */
    }

    /* Main Card: In center column */
    .card {
        grid-column: 2;
        width: 400px;
        order: 2;
        /* Desktop Order: 2 */
    }

    /* Right Panel: In third column, pushed left */
    .side-panel:not(.left-panel) {
        grid-column: 3;
        justify-self: start;
        width: 500px;
        order: 3;
        /* Desktop Order: 3 */
    }

    /* Specific overrides */

    /* Ensure scrolling works in panels */
    .models-list {
        flex: 1;
        overflow-y: auto;
        max-height: none;
        /* Reset constraint for desktop full height */
        /* Custom scrollbar styling matches global */
    }

    .chart-wrapper {
        flex: 1;
        /* Allow chart to expand to fill space */
    }

    .card {
        z-index: 10;
        overflow-y: auto;
        /* Allow scrolling in main card if content overflows */
    }

    /* Content containers */
    /* Content containers */
    .models-card {
        height: 100%;
        display: flex;
        flex-direction: column;
        overflow: hidden;
    }

    .stats-card,
    .chart-wrapper {
        display: flex;
        flex-direction: column;
        overflow: hidden;
    }

    .stats-card {
        flex: 0 0 auto;
        /* Don't shrink/grow, size to content */
    }

    .chart-wrapper {
        flex: 1;
        /* Fill remaining vertical space */
        height: 100%;
    }

    .chart-wrapper canvas {
        flex: 1;
    }

    /* Hide panels if toggled off */
    .side-panel.hidden {
        display: none;
    }
}

/* Stats Card */
.stats-card {
    background: var(--glass-bg);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--glass-border);
    border-radius: 24px;
    padding: 24px;
    margin-bottom: 24px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    position: relative;
    overflow: hidden;
}

.stats-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
}



.stats-percent-text {
    font-size: 24px;
    font-weight: 700;
    color: var(--success-color);
}

.stats-main {
    display: flex;
    align-items: center;
    gap: 32px;
    margin-bottom: 32px;
}

/* Circular Progress */
.circular-progress-container {
    position: relative;
    width: 100px;
    height: 100px;
}

.circular-progress {
    position: absolute;
    top: 0;
    left: 0;
    width: 100px;
    height: 100px;
    border-radius: 50%;
    background: conic-gradient(var(--success-color) 360deg, rgba(255, 255, 255, 0.1) 0deg);
    transition: background 1s ease-in-out;
    -webkit-mask: radial-gradient(transparent 42px, black 42.5px);
    mask: radial-gradient(transparent 42px, black 42.5px);
}

.inner-circle {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 84px;
    height: 84px;
    background: transparent;
    border-radius: 50%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 10;
}

.inner-circle span:first-child {
    font-size: 20px;
    font-weight: 700;
    color: #fff;
    line-height: 1.2;
}

.circle-label {
    font-size: 10px;
    color: var(--text-secondary);
    text-transform: lowercase;
}

/* Linear Progress */
.linear-progress-container {
    flex: 1;
}

.progress-bar-bg {
    width: 100%;
    height: 8px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 4px;
    margin-bottom: 8px;
    overflow: hidden;
}

.progress-bar-fill {
    height: 100%;
    background: var(--success-color);
    border-radius: 4px;
    width: 0%;
    transition: width 1s ease-in-out;
}

.progress-labels {
    display: flex;
    justify-content: space-between;
    font-size: 12px;
    color: var(--text-secondary);
}

/* Stats Grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 20px;
    padding-top: 24px;
    border-top: 1px solid var(--glass-border);
}

.stat-item {
    display: flex;
    flex-direction: column;
}

.stat-label {
    font-size: 11px;
    text-transform: uppercase;
    color: var(--text-secondary);
    margin-bottom: 4px;
    letter-spacing: 0.5px;
}

.stat-value {
    font-size: 15px;
    font-weight: 600;
    color: #fff;
}

.text-green {
    color: var(--success-color);
}

.text-orange {
    color: var(--warning-color);
}

.text-red {
    color: var(--error-color);
}

.bg-green {
    background: var(--success-color);
}

.bg-orange {
    background: var(--warning-color);
}

.bg-red {
    background: var(--error-color);
}

/* Chart Wrapper */
.chart-wrapper {
    background: var(--glass-bg);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--glass-border);
    border-radius: 24px;
    padding: 24px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    height: 100%;
    position: relative;
    display: flex;
    flex-direction: column;
}

.chart-title {
    font-size: 18px;
    font-weight: 600;
    font-weight: 600;
    color: #fff;
    display: flex;
    align-items: center;
    margin-bottom: 0;
}

.chart-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.chart-controls {
    display: flex;
    align-items: center;
    gap: 12px;
}

.chart-title::before {
    content: '';
    display: inline-block;
    width: 4px;
    height: 18px;
    background: var(--success-color);
    margin-right: 12px;
    border-radius: 2px;
}

.refresh-countdown {
    /* Restore missing font properties */
    font-size: 12px;
    font-weight: 500;
    color: var(--text-secondary);
    font-family: 'Inter', sans-serif;

    font-variant-numeric: tabular-nums;
    transition: all 0.3s ease;

    /* New styling */
    padding: 6px 12px;
    border: 1px solid var(--glass-border);
    border-radius: 20px;
    background: rgba(0, 0, 0, 0.2);
    display: flex;
    align-items: center;
    gap: 6px;

    /* Removed absolute positioning */
}

/* Optional: Add a small icon via CSS before? Or just keep text clean. Let's keep it text for now but maybe add a label or icon if requested later. */


.refresh-countdown.warning {
    color: var(--warning-color);
    border-color: rgba(245, 158, 11, 0.3);
    /* Warning color with opacity */
    background: rgba(245, 158, 11, 0.1);
}

/* History Range Selector */
/* Custom Select Dropdown (Ported from admin.css) */
.custom-select {
    position: relative;
    min-width: 120px;
    user-select: none;
}

.select-trigger {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 12px;
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid var(--glass-border);
    border-radius: 6px;
    /* Matches other controls */
    color: var(--text-secondary);
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    gap: 8px;
    height: 32px;
    /* Match countdown height */
    font-family: 'Inter', sans-serif;
}

.select-trigger:hover {
    background: rgba(0, 0, 0, 0.4);
    color: #fff;
    border-color: var(--accent-color);
}

.custom-select.open .select-trigger {
    border-color: var(--accent-color);
    box-shadow: 0 0 0 2px rgba(167, 139, 250, 0.2);
    color: #fff;
}

.select-value {
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.select-arrow {
    width: 14px;
    height: 14px;
    flex-shrink: 0;
    transition: transform 0.2s ease;
    color: inherit;
}

.custom-select.open .select-arrow {
    transform: rotate(180deg);
}

.select-options {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    background: rgba(30, 41, 59, 0.95);
    backdrop-filter: blur(16px);
    border: 1px solid var(--glass-border);
    border-radius: 6px;
    overflow: hidden;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-10px);
    transition: all 0.2s ease;
    z-index: 1000;
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.5);
}

.custom-select.open .select-options {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.select-option {
    padding: 8px 12px;
    color: var(--text-secondary);
    font-size: 12px;
    cursor: pointer;
    transition: all 0.15s ease;
    border-left: 2px solid transparent;
}

.select-option:hover {
    background: rgba(167, 139, 250, 0.15);
    border-left-color: var(--accent-color);
    color: #fff;
}

.select-option.selected {
    background: rgba(167, 139, 250, 0.2);
    border-left-color: var(--accent-color);
    color: #a78bfa;
}


.canvas-container {
    position: relative;
    /* height: 300px;  <-- Removed fixed height */
    flex: 1;
    /* Allow it to fill remaining space */
    min-height: 0;
    /* Critical for Chart.js in flex containers */
    width: 100%;
}

#balanceChart {
    width: 100% !important;
    height: 100% !important;
}

/* Responsive adjustments (Override desktop absolute if screen is narrow) */
@media (max-width: 1099px) {

    /* Already handled by default mobile-first styles up top, 
       but standardizing the query here if needed for specific overrides */
    .main-layout {
        max-width: 100%;
    }

    /* Constrain model list height on mobile/tablet */
    .models-list {
        max-height: 800px;
    }
}

@media (max-width: 480px) {
    .main-layout {
        padding: 12px;
    }

    .card {
        padding: 24px;
        border-radius: 16px;
    }

    #balanceCanvas {
        max-height: 250px;
    }
}

/* Models List Styles */
.models-card {
    background: var(--glass-bg);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--glass-border);
    border-radius: 24px;
    padding: 24px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    height: 100%;
    display: flex;
    flex-direction: column;
}

.models-list {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    margin-top: 16px;
    padding-right: 8px;
    /* max-height constraint moved to media query */
}



.model-item {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    padding: 12px 14px;
    margin-bottom: 8px;
    transition: all 0.3s ease;
    cursor: pointer;
}

.model-item:hover {
    background: rgba(255, 255, 255, 0.08);
    border-color: var(--accent-color);
    transform: translateX(4px);
}

.model-name {
    font-size: 13px;
    font-weight: 600;
    color: #fff;
    margin-bottom: 6px;
    word-break: break-word;
}

.model-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.model-badge {
    display: inline-flex;
    align-items: center;
    padding: 3px 8px;
    border-radius: 6px;
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.badge-text {
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: #fff;
}

.badge-image {
    background: linear-gradient(135deg, #ec4899, #f43f5e);
    color: #fff;
}

.badge-audio {
    background: linear-gradient(135deg, #10b981, #059669);
    color: #fff;
}

.badge-video {
    background: linear-gradient(135deg, #f59e0b, #d97706);
    color: #fff;
}

.model-owner {
    font-size: 10px;
    color: var(--text-secondary);
    margin-left: auto;
}

/* Loading State */
.models-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 20px;
    gap: 16px;
}

.loader-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid rgba(255, 255, 255, 0.1);
    border-radius: 50%;
    border-top-color: var(--accent-color);
    animation: spin 0.8s linear infinite;
}

.models-loading span {
    color: var(--text-secondary);
    font-size: 14px;
}

/* Empty State */
.models-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 20px;
    gap: 12px;
    color: var(--text-secondary);
}

.empty-icon {
    width: 48px;
    height: 48px;
    opacity: 0.5;
}

.models-empty span {
    font-size: 14px;
}

/* Toast Notification */
.toast {
    position: fixed;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: rgba(16, 185, 129, 0.95);
    /* Success Green */
    color: white;
    padding: 10px 20px;
    border-radius: 50px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
    z-index: 2000;
    font-weight: 500;
    font-size: 14px;
    display: flex;
    align-items: center;
    gap: 8px;

    /* Hidden State */
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    backdrop-filter: blur(8px);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.toast.show {
    opacity: 1;
    visibility: visible;
    transform: translateX(-50%) translateY(0);
}

.toast-icon {
    width: 18px;
    height: 18px;
    stroke-width: 2.5;
}

/* Models Header */
.models-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0;
    /* Let details handle spacing if needed, but previously h3 had inherent margin or padding */
    padding-right: 4px;
    /* Slight offset for visual balance */
}

.models-header .chart-title {
    margin-bottom: 0;
}

.model-count {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    background: rgba(255, 255, 255, 0.1);
    padding: 4px 10px;
    border-radius: 20px;
    letter-spacing: 0.5px;
    border: 1px solid var(--glass-border);
}

/* Query History Control (Always Visible) */
.history-control {
    margin-top: 24px;
    padding: 16px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.3s ease;
}

.history-control:hover {
    background: rgba(255, 255, 255, 0.05);
    border-color: var(--accent-color);
}

.history-checkbox {
    display: flex;
    align-items: center;
    cursor: pointer;
    user-select: none;
    position: relative;
    padding-left: 32px;
}

.history-checkbox input[type="checkbox"] {
    position: absolute;
    opacity: 0;
    cursor: pointer;
    height: 0;
    width: 0;
}

.history-checkbox .checkmark {
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    height: 20px;
    width: 20px;
    background: rgba(0, 0, 0, 0.3);
    border: 2px solid var(--glass-border);
    border-radius: 6px;
    transition: all 0.3s ease;
}

.history-checkbox:hover .checkmark {
    border-color: var(--accent-color);
    background: rgba(167, 139, 250, 0.1);
}

.history-checkbox input[type="checkbox"]:checked~.checkmark {
    background: linear-gradient(135deg, #667eea, #764ba2);
    border-color: #764ba2;
}

.history-checkbox .checkmark:after {
    content: "";
    position: absolute;
    display: none;
    left: 6px;
    top: 2px;
    width: 5px;
    height: 10px;
    border: solid white;
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
}

.history-checkbox input[type="checkbox"]:checked~.checkmark:after {
    display: block;
}

.history-label {
    font-size: 14px;
    font-weight: 600;
    color: #fff;
}

.history-hint {
    margin-top: 8px;
    margin-left: 32px;
    font-size: 12px;
    color: var(--text-secondary);
    line-height: 1.5;
}