/* Reset and base styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: linear-gradient(135deg, #61a1f9 0%, #408be4 100%);
    min-height: 100vh;
    color: #333;
}

/* Top bar */
.top-bar {
    position: sticky;
    top: 0;
    z-index: 10;
    background: rgba(255, 255, 255, 0.2);
    backdrop-filter: blur(8px);
    border-bottom: 1px solid rgba(255,255,255,0.3);
    padding: 10px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 70px; /* keep consistent height for provider details vs last-run */
}

.provider-toggle {
    display: flex;
    align-items: center;
    gap: 12px;
}

.toggle-label {
    color: white;
    font-weight: 600;
}

.toggle-switch {
    display: inline-flex;
    background: rgba(255,255,255,0.3);
    border: 1px solid rgba(255,255,255,0.5);
    border-radius: 999px;
    overflow: hidden;
}

.toggle-option {
    padding: 10px 16px;
    border: none;
    background: transparent;
    color: white;
    font-weight: 600;
    cursor: pointer;
}

.toggle-option.active {
    background: white;
    color: #4a5568;
}

/* Settings next to provider toggle */
.settings {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    margin-left: auto; /* Push to right */
}

#userLabel {
    color: white;
    background: rgba(255, 255, 255, 0.15);
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 0.9rem;
    font-weight: 600;
    margin-right: 8px;
    border: 1px solid rgba(255,255,255,0.25);
    backdrop-filter: blur(4px);
}

.settings-btn {
    border: none;
    background: transparent;
    color: #ffffff;
    padding: 6px 10px;
    cursor: pointer;
    line-height: 1;
    font-size: 18px;
    transition: transform 0.15s ease, text-shadow 0.15s ease, filter 0.15s ease, opacity 0.15s ease;
}

.settings-btn:hover {
    transform: scale(1.08);
    text-shadow: 0 0 10px rgba(255,255,255,0.9);
    filter: drop-shadow(0 0 6px rgba(255,255,255,0.55));
}

.settings-menu {
    position: absolute;
    top: 115%;
    right: 0;
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    box-shadow: 0 10px 24px rgba(0,0,0,0.15);
    padding: 6px;
    min-width: 160px;
    z-index: 20;
}

.settings-item {
    width: 100%;
    text-align: left;
    padding: 8px 10px;
    border: none;
    background: transparent;
    cursor: pointer;
    border-radius: 8px;
    font-weight: 600;
    color: #4a5568;
}

.settings-item:hover {
    background: #f1f5f9;
}

.user-badge {
    display: inline-block;
    padding: 4px 8px;
    border-radius: 999px;
    background: rgba(255,255,255,0.25);
    color: #fff;
    font-weight: 700;
    font-size: 0.85rem;
}

.inference-meta {
    color: white;
    font-weight: 600;
}

.inference-meta .dot {
    margin: 0 8px;
    opacity: 0.8;
}

.provider-info {
    color: white;
    text-align: right;
}

.provider-info-line {
    font-size: 0.9rem;
    opacity: 0.95;
}

/* Centered title in top bar on desktop */
.top-title {
    display: none;
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    color: white;
    font-weight: 800;
    text-shadow: 0 2px 4px rgba(0,0,0,0.3);
}

@media (min-width: 768px) {
    .top-title { display: block; font-size: 1.5rem; }
    header { display: none; }
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Header */
header {
    text-align: center;
    margin-bottom: 30px;
    color: white;
}

header h1 {
    font-size: 2.5rem;
    font-weight: 700;
    margin-bottom: 10px;
    text-shadow: 0 2px 4px rgba(0,0,0,0.3);
}

header p {
    font-size: 1.1rem;
    opacity: 0.9;
}

/* Main content */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 30px;
}

/* Image preview container */
.image-preview-container {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 30px;
    margin-bottom: 20px;
}

.image-panel {
    background: white;
    border-radius: 16px;
    padding: 20px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.1);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255,255,255,0.2);
}

.image-panel h3 {
    font-size: 1.2rem;
    margin-bottom: 15px;
    color: #4a5568;
    text-align: center;
}

/* Upload area */
.image-upload-area {
    position: relative;
    width: 100%;
    aspect-ratio: 1;
    border: 2px dashed #cbd5e0;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    cursor: pointer;
    overflow: hidden;
}

.image-upload-area:hover {
    border-color: #61a1f9;
    background-color: #f7fafc;
}

.image-upload-area.dragover {
    border-color: #61a1f9;
    background-color: #edf2f7;
    transform: scale(1.02);
}

.upload-placeholder {
    text-align: center;
    color: #718096;
}

.upload-icon {
    font-size: 3rem;
    margin-bottom: 15px;
}

.upload-placeholder p {
    margin-bottom: 8px;
    font-size: 1rem;
}

.click-to-upload {
    color: #61a1f9;
    font-weight: 600;
    cursor: pointer;
}

.file-info {
    font-size: 0.85rem;
    color: #a0aec0;
}

/* Output area */
.image-output-area {
    position: relative;
    width: 100%;
    aspect-ratio: 1;
    border: 2px solid #e2e8f0;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: #f8fafc;
    overflow: hidden;
}

.output-placeholder {
    text-align: center;
    color: #a0aec0;
}

.output-icon {
    font-size: 3rem;
    margin-bottom: 15px;
}

/* Preview images */
.preview-image {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 8px;
}

/* Try Another overlay */
.upload-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.0);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s ease;
    pointer-events: none;
}

.try-another-btn {
    opacity: 0;
    transform: translateY(6px);
    transition: opacity 0.2s ease, transform 0.2s ease;
    background: transparent;
    color: #ffffff;
    border: 1px solid #ffffff;
    border-radius: 999px;
    padding: 10px 16px;
    font-weight: 700;
    cursor: inherit;
}

.image-upload-area.show-try-another:hover .upload-overlay {
    background: rgba(0,0,0,0.35);
    pointer-events: auto;
}

.image-upload-area.show-try-another:hover .try-another-btn {
    opacity: 1;
    transform: translateY(0);
}

/* Loading spinner */
.loading-spinner {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    color: #61a1f9;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid #e2e8f0;
    border-top: 4px solid #61a1f9;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 15px;
}

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

/* Controls */
.controls {
    background: white;
    border-radius: 16px;
    padding: 25px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.1);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255,255,255,0.2);
}

.parameter-controls {
    display: flex;
    gap: 30px;
    margin-bottom: 25px;
    flex-wrap: wrap;
}

.control-group {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 1;
    min-width: 200px;
}

.control-group label {
    font-weight: 600;
    color: #4a5568;
    min-width: 120px;
}

.control-group input[type="range"] {
    flex: 1;
    height: 6px;
    border-radius: 3px;
    background: #e2e8f0;
    outline: none;
    -webkit-appearance: none;
}

.control-group input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #61a1f9;
    cursor: pointer;
    box-shadow: 0 2px 6px rgba(0,0,0,0.2);
}

.control-group input[type="range"]::-moz-range-thumb {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #61a1f9;
    cursor: pointer;
    border: none;
    box-shadow: 0 2px 6px rgba(0,0,0,0.2);
}

.control-group input[type="checkbox"] {
    width: 20px;
    height: 20px;
    accent-color: #61a1f9;
}

#aiStrengthValue {
    font-weight: 600;
    color: #61a1f9;
    min-width: 20px;
    text-align: center;
}

/* Whitening Section */
.whitening-section {
    margin-bottom: 25px;
    background: #f8fafc;
    border-radius: 12px;
    padding: 15px;
    border: 1px solid #e2e8f0;
}

.whitening-header {
    display: flex;
    align-items: center;
    gap: 12px;
}

.whitening-label {
    font-weight: 600;
    color: #4a5568;
    font-size: 1rem;
}

/* Toggle Switch */
.switch-container {
    position: relative;
    display: inline-block;
    width: 48px;
    height: 26px;
}

.switch-container input {
    opacity: 0;
    width: 0;
    height: 0;
}

.switch-slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #cbd5e0;
    transition: .4s;
    border-radius: 34px;
}

.switch-slider:before {
    position: absolute;
    content: "";
    height: 20px;
    width: 20px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: .4s;
    border-radius: 50%;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

input:checked + .switch-slider {
    background-color: #61a1f9;
}

input:checked + .switch-slider:before {
    transform: translateX(22px);
}

.whitening-options {
    margin-top: 15px;
    padding-top: 15px;
    border-top: 1px solid #e2e8f0;
    display: flex;
    flex-direction: column;
    gap: 15px;
    animation: slideDown 0.3s ease-out;
}

@keyframes slideDown {
    from { opacity: 0; transform: translateY(-10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Run button */
.run-button {
    width: 100%;
    padding: 15px 30px;
    background: linear-gradient(135deg, #61a1f9 0%, #408be4 100%);
    color: white;
    border: none;
    border-radius: 12px;
    font-size: 1.1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4);
}

.run-button:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.6);
}

.run-button:disabled {
    background: #cbd5e0;
    cursor: not-allowed;
    box-shadow: none;
    transform: none;
}

.button-text {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}

/* Footer */
footer {
    text-align: center;
    margin-top: 30px;
    color: white;
    opacity: 0.8;
}

.inference-info {
    display: none; /* removed from output area */
}

.history-box {
    margin-top: 20px;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    padding: 15px;
}

.history-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 10px;
}

.history-box h4 {
    margin-bottom: 10px;
    color: #4a5568;
}

.run-history {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-height: 220px;
    overflow-y: auto;
}

.run-history li {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 10px;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    background: white;
    font-size: 0.95rem;
}

/* Telemetry modal */
.telemetry-button {
    margin-top: 10px;
    padding: 8px 12px;
    border-radius: 8px;
    border: 1px solid rgba(255,255,255,0.7);
    background: rgba(255,255,255,0.2);
    color: white;
    font-weight: 600;
    cursor: pointer;
}

.telemetry-button--purple {
    margin-top: 0;
    background: linear-gradient(135deg, #61a1f9 0%, #408be4 100%);
    color: #ffffff;
    border: none;
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

.telemetry-button--purple:hover {
    filter: brightness(1.05);
}

.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: none;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.5);
}

.modal-content {
    position: relative;
    max-width: 980px;
    margin: 110px auto 40px;
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.2);
    overflow: hidden;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid #e2e8f0;
}

.modal-body {
    padding: 16px 20px 24px;
}

.close-btn {
    border: none;
    background: transparent;
    font-size: 24px;
    cursor: pointer;
    appearance: none;
    -webkit-appearance: none;
}

.chart-controls {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
}

/* Pill selector for timeframe */
#candleToggle {
    display: inline-flex;
    background: #eef2ff;
    border: 1px solid #c7d2fe;
    border-radius: 999px;
    overflow: hidden;
}

#candleToggle .toggle-option {
    padding: 6px 14px;
    border: none;
    background: transparent;
    color: #4f46e5;
    font-weight: 700;
    cursor: pointer;
}

#candleToggle .toggle-option.active {
    background: #4f46e5;
    color: white;
}

.telemetry-table table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 16px;
}

.telemetry-table th, .telemetry-table td {
    text-align: left;
    padding: 8px;
    border-bottom: 1px solid #edf2f7;
}

/* Make chart responsive to container width */
.telemetry-chart {
    width: 100%;
    height: 280px;
}

/* Responsive design */
@media (max-width: 768px) {
    .image-preview-container {
        grid-template-columns: 1fr;
        gap: 20px;
    }
    
    .parameter-controls {
        flex-direction: column;
        gap: 20px;
    }
    
    .control-group {
        min-width: auto;
    }
    
    header h1 {
        font-size: 2rem;
    }
    
    .container {
        padding: 15px;
    }
}

/* Error states */
.error {
    border-color: #e53e3e !important;
    background-color: #fed7d7 !important;
}

.error-message {
    color: #e53e3e;
    font-size: 0.9rem;
    margin-top: 10px;
    text-align: center;
}
