/* Reset & Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary: #3b82f6;
    --primary-dark: #2563eb;
    --secondary: #8b5cf6;
    --success: #10b981;
    --danger: #ef4444;
    --warning: #f59e0b;
    --background: #f8fafc;
    --surface: #ffffff;
    --surface-light: #f1f5f9;
    --text: #0f172a;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --sidebar-width: 280px;
    --topbar-height: 60px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--background);
    color: var(--text);
    line-height: 1.6;
    height: 100vh;
    overflow: hidden;
}

/* Top Bar */
.top-bar {
    height: var(--topbar-height);
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 100;
}

.top-bar-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    height: 100%;
    padding: 0 1.5rem;
}

.top-bar-left {
    display: flex;
    align-items: center;
}

.logo {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text);
}

.top-bar-right {
    display: flex;
    align-items: center;
    gap: 1rem;
}

/* User Avatar */
.user-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 600;
    font-size: 0.9rem;
    cursor: pointer;
    transition: transform 0.2s;
    position: relative;
}

.user-avatar:hover {
    transform: scale(1.05);
}

/* User Dropdown */
.user-dropdown {
    position: fixed;
    top: 55px;
    right: 1.5rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
    min-width: 200px;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-10px);
    transition: all 0.2s ease;
    z-index: 1000;
}

.user-dropdown.active {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.user-dropdown-header {
    padding: 1rem;
    border-bottom: 1px solid var(--border);
    color: var(--text);
    font-weight: 500;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.user-email {
    font-size: 0.8rem;
    color: var(--text-muted);
    font-weight: 400;
}

.dropdown-item {
    width: 100%;
    padding: 0.75rem 1rem;
    background: none;
    border: none;
    color: var(--text);
    text-align: left;
    cursor: pointer;
    font-size: 0.95rem;
    transition: background 0.2s;
}

.dropdown-item:hover {
    background: var(--surface-light);
}

/* Pending Approval Overlay */
.pending-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--background);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 200;
}

.pending-card {
    background: var(--surface);
    border-radius: 1rem;
    padding: 3rem;
    text-align: center;
    max-width: 500px;
    border: 1px solid var(--border);
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.pending-card h2 {
    color: var(--warning);
    margin-bottom: 1rem;
    font-size: 1.75rem;
}

.pending-card p {
    color: var(--text-muted);
    margin-bottom: 1rem;
    line-height: 1.6;
}

.pending-actions {
    display: flex;
    gap: 1rem;
    justify-content: center;
    margin-top: 2rem;
}

/* Main Layout */
.main-layout {
    display: flex;
    height: 100vh;
    padding-top: var(--topbar-height);
}

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
}

.new-generation-btn {
    margin: 0.75rem;
    padding: 0.75rem 1.25rem;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 0.5rem;
    font-weight: 600;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    box-shadow: 0 2px 8px rgba(59, 130, 246, 0.1);
}

.new-generation-btn:hover {
    box-shadow: 0 2px 8px rgba(59, 130, 246, 0.5);
    filter: brightness(1.1);
}

.plus-icon {
    font-size: 1.2rem;
    font-weight: bold;
}

.history-list {
    flex: 1;
    overflow-y: auto;
    padding: 0.75rem;
}

.history-card {
    background: var(--surface-light);
    border: 1px solid var(--border);
    border-radius: 0.75rem; /* Rounded corners */
    padding: 1rem;
    margin-bottom: 0.75rem;
    cursor: pointer;
    transition: border-color 0.2s, background-color 0.2s;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    position: relative;
}

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

.history-card.active {
    border-color: var(--primary);
    background: var(--surface-light);
    box-shadow: 0 0 0 2px var(--primary);
}

.history-date {
    font-size: 0.65rem;
    color: var(--text-muted);
    margin-bottom: 0.3rem;
}

.history-user {
    font-size: 0.7rem;
    color: var(--primary);
    margin-bottom: 0.4rem;
    font-weight: 500;
}

.history-prompt {
    color: var(--text);
    font-size: 0.8rem;
    line-height: 1.3;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.history-status {
    display: inline-block;
    padding: 0.1rem 0.3rem;
    border-radius: 0.2rem;
    font-size: 0.55rem;
    font-weight: 600;
    color: white !important;
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    cursor: pointer;
    transition: background-color 0.2s;
}

.history-status .status-text {
    display: inline;
}

.history-status .archive-text {
    display: none;
}

.history-status:hover .status-text {
    display: none;
}

.history-status:hover .archive-text {
    display: inline;
}

.history-status:hover {
    background-color: var(--text-muted) !important;
}

/* Archive Toggle */
.archive-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.5rem 0.75rem;
    margin: 0 0.75rem 0.5rem;
    background: var(--surface-light);
    border-radius: 0.5rem;
    font-size: 0.8rem;
    color: var(--text-muted);
}

.archive-toggle label {
    font-weight: 500;
    margin-bottom: 0;
    cursor: pointer;
}

.toggle-switch {
    position: relative;
    width: 36px;
    height: 20px;
}

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

.toggle-slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: var(--border);
    transition: 0.2s;
    border-radius: 20px;
}

.toggle-slider:before {
    position: absolute;
    content: "";
    height: 14px;
    width: 14px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: 0.2s;
    border-radius: 50%;
}

.toggle-switch input:checked + .toggle-slider {
    background-color: var(--primary);
}

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

/* Main Panel */
.main-panel {
    flex: 1;
    overflow: hidden; /* Prevent scrolling on the main panel */
    background: var(--background);
    display: flex;
}

.panel-content {
    flex: 1;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
    padding: 1.5rem;
    height: calc(100vh - var(--topbar-height));
    overflow: hidden;
}

.results-column, .config-column {
    overflow-y: auto; /* Allow scrolling within columns if needed */
    height: 100%;
    padding-right: 0.5rem; /* For scrollbar */
}

/* Configuration Section */
.config-section {
    margin-bottom: 1.5rem;
}

.config-card {
    background: var(--surface);
    border-radius: 0.5rem;
    padding: 1rem;
    border: 1px solid var(--border);
}

.config-card h4 {
    margin-bottom: 0.75rem;
    color: var(--text);
    font-size: 0.95rem;
}

/* Form Styles */
.form-group {
    margin-bottom: 1rem;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    margin-bottom: 1rem;
}

label {
    display: block;
    margin-bottom: 0.4rem;
    font-weight: 600;
    color: var(--text);
    font-size: 0.9rem;
}

input[type="text"],
input[type="number"],
select,
textarea {
    width: 100%;
    padding: 0.625rem 0.75rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    color: var(--text);
    font-size: 0.95rem;
    transition: border-color 0.2s, box-shadow 0.2s;
}

input:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

textarea {
    resize: vertical;
    font-family: inherit;
}

small {
    display: block;
    margin-top: 0.25rem;
    color: var(--text-muted);
    font-size: 0.85rem;
}

/* Volume Controls */
.volume-controls {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 0.75rem;
    margin-top: 0.4rem;
}

.volume-input {
    display: flex;
    flex-direction: column;
}

.volume-input label {
    font-size: 0.8rem;
    margin-bottom: 0.25rem;
    font-weight: normal;
}

.volume-input input {
    padding: 0.5rem 0.625rem;
}

/* Buttons */
.btn {
    padding: 0.75rem 1.5rem;
    font-size: 0.95rem;
    font-weight: 600;
    border: none;
    border-radius: 0.5rem;
    cursor: pointer;
    transition: background-color 0.2s, box-shadow 0.2s;
    display: inline-block;
    text-decoration: none;
    text-align: center;
}

.btn-primary {
    background: var(--primary);
    color: white;
    width: 100%;
    box-shadow: 0 2px 8px rgba(59, 130, 246, 0.1);
    margin-top: 0.5rem;
}

.btn-primary:hover:not(:disabled) {
    box-shadow: 0 2px 8px rgba(59, 130, 246, 0.5);
    filter: brightness(1.1);
}

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

.btn-secondary {
    background: var(--surface-light);
    color: var(--text);
    margin-top: 0.5rem;
    padding: 0.625rem 1.25rem;
    font-size: 0.875rem;
    transition: background-color 0.2s;
}

.btn-secondary:hover {
    background: var(--border);
}

/* Status Section */
.status-section {
    margin-bottom: 1.5rem;
    padding-top: 0;
    border-top: none;
}

.status-card {
    background: var(--surface);
    border-radius: 0.5rem;
    padding: 1rem;
    border: 1px solid var(--border);
}

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

.status-badges {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.status-card h4 {
    margin-bottom: 0;
    color: var(--text);
    font-size: 0.95rem;
}

.status-badge {
    display: inline-block;
    padding: 0.25rem 0.5rem;
    border-radius: 0.375rem;
    font-weight: 600;
    font-size: 0.75rem;
    line-height: 1;
    color: white !important;
}

.status-details {
    margin-bottom: 1rem;
}

.status-details p {
    margin-bottom: 0.4rem;
    color: var(--text-muted);
    font-size: 0.85rem;
}

.status-details strong {
    color: var(--text);
}

#status-prompt {
    color: var(--text);
    font-style: italic;
}

/* Progress Bar */
.progress-bar {
    width: 100%;
    height: 8px;
    background: var(--surface-light);
    border-radius: 4px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: var(--primary);
    transition: width 0.5s ease, background-color 0.3s ease;
    border-radius: 4px;
}

/* Results Section */
.results-section {
    margin-bottom: 1rem;
    padding-top: 1rem;
    border-top: none;
}

.results-section h3 {
    display: none;
}

.result-card {
    background: var(--surface);
    border-radius: 0.5rem;
    padding: 1rem;
    border: 1px solid var(--border);
}

.audio-player-container {
    margin-bottom: 1rem;
}

.audio-player-container h4 {
    margin-bottom: 0.625rem;
    color: var(--text);
    font-size: 0.95rem;
}

.execution-time-badge {
    background: var(--success);
    color: white;
    padding: 0.25rem 0.5rem;
    border-radius: 0.375rem;
    font-size: 0.75rem;
    font-weight: 600;
    line-height: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 1.5rem;
    box-sizing: border-box;
}

/* Spinner animation for execution time badge */
@keyframes spin {
    from {
        transform: rotate(0deg);
    }
    to {
        transform: rotate(360deg);
    }
}

#audio-player {
    width: 100%;
    margin-bottom: 0.75rem;
    border-radius: 0.5rem;
}

/* Source Audio Tracks Collapsible */
details.source-audios {
    margin-top: 1rem;
    margin-bottom: 1rem;
}

details.source-audios > summary {
    cursor: pointer;
    color: var(--text);
    padding: 0.5rem 0.75rem;
    border-radius: 0.375rem;
    background-color: var(--surface-light);
    border: 1px solid var(--border);
    font-weight: 500;
    font-size: 0.9rem;
    user-select: none;
    transition: background-color 0.2s, border-color 0.2s;
    list-style: none;
}

details.source-audios > summary::-webkit-details-marker {
    display: none;
}

details.source-audios > summary:hover {
    background-color: var(--border);
    border-color: var(--primary);
}

details.source-audios > summary::before {
    content: '▶ ';
    font-size: 0.75em;
    margin-right: 0.5rem;
    display: inline-block;
    transition: transform 0.2s;
}

details.source-audios[open] > summary::before {
    transform: rotate(90deg);
}

details.source-audios[open] > summary {
    margin-bottom: 0.75rem;
}

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

.source-batch-container {
    background: var(--surface-light);
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    padding: 0.75rem;
}

.batch-label {
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--text);
    margin-bottom: 0.75rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--border);
}

.batch-tracks {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.source-track {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 0.75rem;
}

.track-label {
    font-weight: 500;
    font-size: 0.8rem;
    color: var(--text-muted);
    min-width: 60px;
    flex-shrink: 0;
}

.source-track audio {
    flex: 1;
    min-width: 0;
}

.job-details h4 {
    margin-bottom: 0.625rem;
    color: var(--text);
    font-size: 0.95rem;
}

.job-details pre {
    background: var(--background);
    padding: 0.75rem;
    border-radius: 0.5rem;
    overflow-x: auto;
    font-size: 0.8rem;
    color: var(--text-muted);
    border: 1px solid var(--border);
    max-height: 200px;
    overflow-y: auto;
}

.job-details {
    display: none !important;
}

.placeholder {
    text-align: center;
    color: var(--text-muted);
    padding: 1.5rem 1rem;
    font-size: 0.85rem;
}

/* Scrollbar Styling */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--surface);
}

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--surface-light);
}

/* Responsive Design */
@media (max-width: 768px) {
    .main-layout {
        flex-direction: column;
    }

    .sidebar {
        width: 100%;
        height: 200px;
        border-right: none;
        border-bottom: 1px solid var(--border);
    }

    .panel-content {
        padding: 1rem;
    }

    .form-row {
        grid-template-columns: 1fr;
    }

    .volume-controls {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* Desktop layout improvements: two-column layout */
.status-section,
.results-section {
    /* Removed sticky positioning - align to top */
}

/* Compact density adjustments */
.config-section { margin-bottom: 0.75rem; }
.status-section, .results-section { padding-top: 0; }
.status-card, .result-card, .config-card { padding: 0.875rem; }
label { font-size: 0.85rem; }
input[type="text"],
input[type="number"],
select,
textarea { padding: 0.5rem 0.625rem; font-size: 0.9rem; }

/* Sidebar density */
.history-card { padding: 0.5rem 0.6rem; }
.history-prompt { -webkit-line-clamp: 2; font-size: 0.78rem; }
.history-date { font-size: 0.62rem; }

/* Advanced options disclosure */
details.advanced {
    margin-bottom: 0.5rem;
}

details.advanced > summary {
    cursor: pointer;
    color: var(--text);
    margin: 0;
    list-style: none;
    padding: 0.5rem 0.75rem;
    border-radius: 0.375rem;
    transition: background-color 0.2s, color 0.2s;
    background-color: transparent;
    border: 1px solid var(--border);
    font-weight: normal;
    font-size: 0.9rem;
    user-select: none;
}

details.advanced > summary:hover {
    background-color: var(--surface-light);
    border-color: var(--primary);
}

details.advanced > summary::before {
    content: '▶ ';
    font-size: 0.9em;
    margin-right: 0.5rem;
    display: inline-block;
    transition: transform 0.2s;
}

details.advanced[open] > summary::before {
    transform: rotate(90deg);
}

details.advanced[open] {
    margin-bottom: 0.5rem;
}

details.advanced[open] > summary {
    margin-bottom: 0.75rem;
}

/* Range slider minimal styling */
input[type="range"] {
    width: 100%;
}

/* Credits Display in Top Bar */
.credits-display {
    display: flex;
    align-items: center;
    padding: 0.4rem 0.75rem;
    background: var(--surface-light);
    border: 1px solid var(--border);
    border-radius: 0.375rem;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text);
    cursor: default;
}

.credits-amount {
    font-variant-numeric: tabular-nums;
}

/* Generate Button with Cost */
.btn-primary {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.btn-cost {
    font-size: 0.8rem;
    font-weight: 500;
    opacity: 0.9;
    padding: 0.15rem 0.5rem;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 1rem;
}

.btn-cost:empty {
    display: none;
}

/* ==================== Login Screen ==================== */
.login-screen {
    position: fixed;
    top: var(--topbar-height);
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--surface);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 50;
}

.login-card {
    background: var(--surface);
    border-radius: 1rem;
    padding: 2.5rem;
    width: 100%;
    max-width: 400px;
    border: 1px solid var(--border);
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    animation: slideUp 0.4s ease-out;
}

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

.login-header {
    text-align: center;
    margin-bottom: 2rem;
}

.login-header h2 {
    font-size: 1.75rem;
    color: var(--text);
    margin-bottom: 0.5rem;
    font-weight: 700;
}

.login-header p {
    color: var(--text-muted);
    font-size: 0.95rem;
}

.login-options {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.login-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    width: 100%;
    padding: 0.875rem 1.25rem;
    border-radius: 0.5rem;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    border: none;
}

.login-btn-icon {
    flex-shrink: 0;
}

.login-btn-google {
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
}

.login-btn-google:hover {
    background: var(--surface-light);
    border-color: var(--text-muted);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.login-btn-email {
    background: var(--primary);
    color: white;
}

.login-btn-email:hover {
    filter: brightness(1.1);
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.4);
}

.login-btn-email:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.login-divider {
    display: flex;
    align-items: center;
    gap: 1rem;
    color: var(--text-muted);
    font-size: 0.85rem;
    margin: 0.5rem 0;
}

.login-divider::before,
.login-divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--border);
}

.email-login-form {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.email-input {
    width: 100%;
    padding: 0.875rem 1rem;
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    font-size: 0.95rem;
    color: var(--text);
    background: var(--surface);
    transition: border-color 0.2s, box-shadow 0.2s;
}

.email-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}

.email-input::placeholder {
    color: var(--text-muted);
}

/* Email Sent Message */
.email-sent-message {
    text-align: center;
    padding: 1rem 0;
}

.email-sent-icon {
    font-size: 3rem;
    margin-bottom: 1rem;
}

.email-sent-message h3 {
    font-size: 1.25rem;
    color: var(--text);
    margin-bottom: 0.5rem;
}

.email-sent-message p {
    color: var(--text-muted);
    font-size: 0.9rem;
    margin-bottom: 1rem;
}

.email-sent-message strong {
    color: var(--text);
}

.login-btn-text {
    background: none;
    border: none;
    color: var(--primary);
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    padding: 0.5rem;
    transition: color 0.2s;
}

.login-btn-text:hover {
    color: var(--primary-dark);
    text-decoration: underline;
}

/* Email Confirmation Form (cross-device sign-in) */
.email-confirm-form {
    text-align: center;
    padding: 1rem 0;
}

.email-confirm-form h3 {
    font-size: 1.25rem;
    color: var(--text);
    margin-bottom: 0.5rem;
}

.email-confirm-form p {
    color: var(--text-muted);
    font-size: 0.9rem;
    margin-bottom: 1rem;
}

.email-confirm-form .email-input {
    margin-bottom: 0.75rem;
}

/* Responsive Login */
@media (max-width: 480px) {
    .login-card {
        margin: 1rem;
        padding: 1.5rem;
    }
}

