* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary-color: #6366f1;
    --primary-hover: #4f46e5;
    --success-color: #10b981;
    --error-color: #ef4444;
    --warning-color: #f59e0b;
    --bg-color: #0f172a;
    --surface-color: #1e293b;
    --surface-hover: #334155;
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --border-color: #334155;
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.3);
}

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

.container {
    max-width: 1600px;
    margin: 0 auto;
    padding: clamp(1.5rem, 2.5vh, 2rem);
    padding-bottom: clamp(4rem, 6vh, 5rem);
}

.main-layout {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: clamp(1.2rem, 2vh, 1.8rem);
    align-items: start;
    min-height: 0;
}

.main-layout > main {
    min-width: 0;
}

header {
    margin-bottom: clamp(2rem, 4vh, 3rem);
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.header-content > div {
    text-align: center;
    flex: 1;
}

header h1 {
    font-size: clamp(1.75rem, 3vh, 2.5rem);
    font-weight: 700;
    background: linear-gradient(135deg, var(--primary-color), #a855f7);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.subtitle {
    color: var(--text-secondary);
    font-size: clamp(0.9rem, 1.2vh, 1.1rem);
}

.btn-stats {
    padding: 0.75rem 1.5rem;
    background: var(--surface-hover);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    text-decoration: none;
    font-weight: 600;
    transition: all 0.3s ease;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}

.btn-stats:hover {
    background: var(--primary-color);
    border-color: var(--primary-color);
    transform: translateY(-2px);
}

section {
    background: var(--surface-color);
    border-radius: 12px;
    padding: clamp(1.5rem, 2.5vh, 2rem);
    margin-bottom: clamp(1rem, 1.8vh, 1.5rem);
    box-shadow: var(--shadow);
}

#upload-section {
    min-height: clamp(260px, 40vh, 300px);
}

h2 {
    font-size: clamp(1.1rem, 1.8vh, 1.5rem);
    margin-top: clamp(0.1rem, 0.3vh, 0.2rem);
    margin-bottom: clamp(0.6rem, 1vh, 1rem);
    color: var(--text-primary);
}

/* Upload Zone */
.upload-zone {
    border: 2px dashed var(--border-color);
    border-radius: 12px;
    padding: clamp(1.25rem, 2.5vh, 1.5rem) 2rem;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s ease;
    min-height: clamp(220px, 35vh, 250px);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}

.upload-zone:hover,
.upload-zone.drag-over {
    border-color: var(--primary-color);
    background: var(--surface-hover);
}

.upload-icon {
    color: var(--text-secondary);
    margin-bottom: clamp(0.75rem, 1.5vh, 1rem);
}

.upload-zone h2 {
    font-size: clamp(1rem, 1.6vh, 1.25rem);
    margin-bottom: clamp(0.3rem, 0.6vh, 0.5rem);
}

.upload-hint {
    color: var(--text-secondary);
    margin-bottom: clamp(0.75rem, 1.5vh, 1rem);
}

.supported-formats {
    color: var(--text-secondary);
    font-size: clamp(0.75rem, 1.2vh, 0.875rem);
}

/* File Info */
.file-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem;
    background: var(--surface-hover);
    border-radius: 8px;
}

.file-details {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.file-name {
    font-weight: 600;
}

.file-size {
    color: var(--text-secondary);
    font-size: 0.875rem;
}

/* Mode Selection */
.mode-options {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.75rem;
}

.mode-option {
    cursor: pointer;
}

.mode-option input[type="radio"] {
    display: none;
}

.mode-card {
    padding: clamp(1.25rem, 2.5vh, 1.5rem);
    border: 2px solid var(--border-color);
    border-radius: 8px;
    transition: all 0.3s ease;
}

.mode-option input[type="radio"]:checked + .mode-card {
    border-color: var(--primary-color);
    background: var(--surface-hover);
}

.mode-card h3 {
    font-size: clamp(1rem, 1.6vh, 1.25rem);
    margin-bottom: clamp(0.3rem, 0.6vh, 0.5rem);
}

.mode-card p {
    color: var(--text-secondary);
    font-size: clamp(0.75rem, 1.2vh, 0.875rem);
}

.mode-tag {
    display: inline-block;
    padding: 0.25rem 0.5rem;
    background: var(--primary-color);
    border-radius: 4px;
    font-size: clamp(0.65rem, 1vh, 0.75rem);
    margin-top: clamp(0.3rem, 0.6vh, 0.5rem);
}

/* Format Selection */
.format-options {
    display: flex;
    flex-wrap: wrap;
    gap: clamp(0.75rem, 1.5vh, 1rem);
}

.format-option {
    cursor: pointer;
}

.format-option input[type="radio"] {
    display: none;
}

.format-option span {
    display: inline-block;
    padding: clamp(0.6rem, 1.2vh, 0.75rem) clamp(1rem, 1.8vh, 1.5rem);
    border: 2px solid var(--border-color);
    border-radius: 8px;
    transition: all 0.3s ease;
}

.format-option input[type="radio"]:checked + span {
    border-color: var(--primary-color);
    background: var(--surface-hover);
}

/* Buttons */
.btn-primary {
    width: 100%;
    padding: clamp(0.8rem, 1.5vh, 1rem) clamp(1.5rem, 2.5vh, 2rem);
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: clamp(1rem, 1.6vh, 1.1rem);
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
}

.btn-primary:hover:not(:disabled) {
    background: var(--primary-hover);
}

.btn-primary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-cancel,
.btn-remove,
.btn-new {
    padding: 0.5rem 1rem;
    background: transparent;
    border: 1px solid var(--error-color);
    color: var(--error-color);
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.3s ease;
}

.btn-cancel:hover,
.btn-remove:hover {
    background: var(--error-color);
    color: white;
}

.btn-new {
    border-color: var(--primary-color);
    color: var(--primary-color);
}

.btn-new:hover {
    background: var(--primary-color);
    color: white;
}

/* Submit Status */
.submit-status {
    margin-top: 1rem;
    text-align: center;
}

.submit-status.error {
    color: var(--error-color);
}

.submit-status.success {
    color: var(--success-color);
}

/* Queue Info Section */
.queue-sidebar {
    position: sticky;
    top: 2rem;
    height: fit-content;
    overflow-y: auto;
}

.queue-info-section {
    background: linear-gradient(135deg, var(--surface-color), var(--surface-hover));
    border-left: 4px solid var(--primary-color);
    min-height: clamp(260px, 40vh, 320px);
    max-height: clamp(600px, 85vh, 900px);
    display: flex;
    flex-direction: column;
}

.queue-info-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.queue-info-header h2 {
    margin: 0;
    font-size: 1.5rem;
}

.queue-title {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.queue-polling-indicator {
    font-family: 'Courier New', monospace;
    font-weight: bold;
    font-size: 1.25rem;
    color: var(--primary-color);
    animation: pulse 0.5s ease-in-out infinite alternate;
}

@keyframes pulse {
    0% { opacity: 0.5; }
    100% { opacity: 1; }
}

.queue-status {
    padding: 0.25rem 0.75rem;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.queue-status.empty {
    background: var(--surface-color);
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
}

.queue-status.light {
    background: rgba(16, 185, 129, 0.2);
    color: var(--success-color);
    border: 1px solid var(--success-color);
}

.queue-status.moderate {
    background: rgba(245, 158, 11, 0.2);
    color: var(--warning-color);
    border: 1px solid var(--warning-color);
}

.queue-status.busy {
    background: rgba(249, 115, 22, 0.5);
    color: #f97316;
    border: 1px solid #f97316;
}

.queue-status.very-busy {
    background: rgba(239, 68, 68, 0.2);
    color: var(--error-color);
    border: 1px solid var(--error-color);
}

.queue-status.error {
    background: rgba(239, 68, 68, 0.2);
    color: var(--error-color);
    border: 1px solid var(--error-color);
}

.queue-jobs-list {
    flex: 1;
    overflow-y: auto;
}

.queue-loading,
.queue-empty,
.queue-error {
    text-align: center;
    padding: 2rem;
    color: var(--text-secondary);
}

.queue-error {
    color: var(--error-color);
}

.jobs-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.job-item {
    display: flex;
    gap: 1rem;
    padding: 1rem;
    background: var(--surface-color);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    transition: all 0.3s ease;
}

.job-item:hover {
    background: var(--surface-hover);
    transform: translateX(4px);
}

.job-item.job-highlight {
    background: linear-gradient(135deg, rgba(99, 102, 241, 0.1), var(--surface-color));
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.1);
}

.job-icon {
    font-size: 2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 50px;
    height: 50px;
    background: var(--surface-hover);
    border-radius: 8px;
    flex-shrink: 0;
}

.job-details {
    flex: 1;
    min-width: 0;
}

.job-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
}

.job-status {
    padding: 0.25rem 0.5rem;
    border-radius: 6px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
}

.job-status-pending {
    background: rgba(245, 158, 11, 0.2);
    color: var(--warning-color);
    border: 1px solid var(--warning-color);
}

.job-status-processing {
    background: rgba(99, 102, 241, 0.2);
    color: var(--primary-color);
    border: 1px solid var(--primary-color);
}

.job-status-completed {
    background: rgba(16, 185, 129, 0.2);
    color: var(--success-color);
    border: 1px solid var(--success-color);
}

.job-status-failed {
    background: rgba(239, 68, 68, 0.2);
    color: var(--error-color);
    border: 1px solid var(--error-color);
}

.job-time {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.job-name {
    font-weight: 600;
    margin-bottom: 0.5rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.job-meta {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.job-mode {
    font-size: 0.75rem;
    color: var(--text-secondary);
    padding: 0.25rem 0.5rem;
    background: var(--surface-hover);
    border-radius: 4px;
}

.job-tag {
    font-size: 0.75rem;
    color: var(--primary-color);
    padding: 0.25rem 0.5rem;
    background: rgba(99, 102, 241, 0.2);
    border-radius: 4px;
    font-weight: 600;
}

/* Status Section */
.status-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.progress-bar {
    width: 100%;
    height: 8px;
    background: var(--surface-hover);
    border-radius: 4px;
    overflow: hidden;
    margin-bottom: 1rem;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--primary-color), #a855f7);
    border-radius: 4px;
    transition: width 0.3s ease;
    width: 0%;
}

.status-text {
    display: flex;
    justify-content: space-between;
    margin-bottom: 1rem;
}

.status-message {
    color: var(--text-secondary);
}

.status-percent {
    font-weight: 600;
    color: var(--primary-color);
}

.job-info {
    color: var(--text-secondary);
    font-size: 0.875rem;
}

.job-info code {
    background: var(--surface-hover);
    padding: 0.125rem 0.375rem;
    border-radius: 4px;
    font-family: monospace;
}

/* Results Section */
.results-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.results-content {
    display: grid;
    gap: 1rem;
}

.stem-result {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem;
    background: var(--surface-hover);
    border-radius: 8px;
}

.stem-info {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.stem-name {
    font-weight: 600;
}

.stem-format {
    color: var(--text-secondary);
    font-size: 0.875rem;
}

.btn-download {
    padding: 0.5rem 1.5rem;
    background: var(--success-color);
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.3s ease;
}

.btn-download:hover {
    opacity: 0.9;
}

/* Footer */
footer {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    text-align: center;
    padding: 1rem 0;
    color: var(--text-secondary);
    font-size: 0.875rem;
    background: var(--bg-color);
    border-top: 1px solid var(--border-color);
}

/* Responsive */
@media (max-height: 1200px) {
    /* Intermediate breakpoint for gradual scaling */
    section {
        margin-bottom: clamp(0.8rem, 1.5vh, 1.2rem);
    }

    h2 {
        margin-top: 0;
        margin-bottom: clamp(0.5rem, 1vh, 0.9rem);
    }

    #upload-section {
        min-height: 270px;
    }

    .queue-info-section {
        min-height: 270px;
        max-height: 700px;
    }

    .upload-zone {
        min-height: 210px;
        max-height: 210px;
    }

    .upload-icon svg {
        width: clamp(44px, 4.5vh, 48px);
        height: clamp(44px, 4.5vh, 48px);
    }
}

@media (max-height: 1080px) {
    /* Less aggressive scaling - mostly fine-tuning heights */
    section {
        margin-bottom: clamp(0.6rem, 1.2vh, 1rem);
    }

    h2 {
        margin-top: 0;
        margin-bottom: clamp(0.4rem, 0.7vh, 0.6rem);
    }

    #upload-section {
        min-height: 240px;
    }

    .queue-info-section {
        min-height: 240px;
        max-height: 600px;
    }

    .upload-zone {
        min-height: 190px;
        max-height: 190px;
    }

    .upload-icon svg {
        width: clamp(36px, 4vh, 40px);
        height: clamp(36px, 4vh, 40px);
    }
}

@media (max-width: 1100px) {
    .main-layout {
        grid-template-columns: 1fr;
    }

    .queue-sidebar {
        position: static;
    }
}

@media (max-width: 640px) {
    .container {
        padding: 1rem;
    }

    header h1 {
        font-size: 1.75rem;
    }

    section {
        padding: 1.5rem;
    }

    .mode-options {
        grid-template-columns: 1fr;
    }

    .mode-card h3 {
        font-size: 1.1rem;
    }

    .mode-card p {
        font-size: 0.8rem;
    }
}

/* Health Status Styles */
.header-actions {
    display: flex;
    align-items: center;
    gap: 1.5rem;
}

.health-status {
    display: flex;
    gap: 1rem;
    align-items: center;
}

.health-indicator {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    border-radius: 8px;
    background: var(--surface-color);
    border: 1px solid var(--border-color);
    font-size: 0.875rem;
    transition: all 0.3s ease;
}

.health-indicator .status-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--text-secondary);
    transition: background 0.3s ease;
}

.health-indicator .status-label {
    color: var(--text-secondary);
    font-weight: 500;
}

.health-indicator.healthy .status-dot {
    background: var(--success-color);
    box-shadow: 0 0 8px rgba(16, 185, 129, 0.5);
}

.health-indicator.healthy .status-label {
    color: var(--success-color);
}

.health-indicator.unhealthy .status-dot {
    background: var(--warning-color);
    box-shadow: 0 0 8px rgba(245, 158, 11, 0.5);
}

.health-indicator.unhealthy .status-label {
    color: var(--warning-color);
}

.health-indicator.offline .status-dot {
    background: var(--error-color);
    box-shadow: 0 0 8px rgba(239, 68, 68, 0.5);
}

.health-indicator.offline .status-label {
    color: var(--error-color);
}

.health-indicator.error .status-dot {
    background: var(--error-color);
    box-shadow: 0 0 8px rgba(239, 68, 68, 0.5);
}

.health-indicator.error .status-label {
    color: var(--error-color);
}

/* Service Warning Styles */
.service-warning {
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid var(--error-color);
    border-radius: 8px;
    padding: 1rem;
    margin-bottom: 1.5rem;
    animation: fadeIn 0.3s ease;
}

.warning-content {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.warning-icon {
    font-size: 1.5rem;
}

.warning-text {
    flex: 1;
    color: var(--error-color);
    font-weight: 500;
}

.btn-refresh-services {
    padding: 0.5rem 1rem;
    background: var(--surface-hover);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
}

.btn-refresh-services:hover {
    background: var(--primary-color);
    border-color: var(--primary-color);
}



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