/* 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, #667eea 0%, #764ba2 100%);
    color: #333;
    line-height: 1.6;
    min-height: 100vh;
    padding: 20px;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
}

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

header h1 {
    color: white;
    font-size: 2.5rem;
    margin-bottom: 20px;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.2);
}

/* Stats */
.stats {
    display: flex;
    gap: 15px;
    justify-content: center;
    flex-wrap: wrap;
}

.stat-item {
    background: white;
    padding: 15px 25px;
    border-radius: 10px;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
    display: flex;
    flex-direction: column;
    align-items: center;
    min-width: 120px;
}

.stat-label {
    font-size: 0.85rem;
    color: #666;
    margin-bottom: 5px;
}

.stat-value {
    font-size: 1.8rem;
    font-weight: bold;
    color: #667eea;
}

/* Card */
.card {
    background: white;
    border-radius: 15px;
    padding: 30px;
    margin-bottom: 30px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.2);
}

/* Tabs */
.tabs {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
    border-bottom: 2px solid #eee;
}

.tab-button {
    background: none;
    border: none;
    padding: 12px 24px;
    cursor: pointer;
    font-size: 1rem;
    color: #666;
    border-bottom: 3px solid transparent;
    transition: all 0.3s;
}

.tab-button:hover {
    color: #667eea;
}

.tab-button.active {
    color: #667eea;
    border-bottom-color: #667eea;
    font-weight: 600;
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

/* Forms */
.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 500;
    color: #333;
}

.form-group input[type="text"],
.form-group input[type="url"],
.form-group input[type="file"],
.form-group textarea,
.form-group select {
    width: 100%;
    padding: 12px;
    border: 2px solid #eee;
    border-radius: 8px;
    font-size: 1rem;
    transition: border-color 0.3s;
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
    outline: none;
    border-color: #667eea;
}

.form-group textarea {
    resize: vertical;
    font-family: inherit;
}

.form-group small {
    display: block;
    margin-top: 5px;
    color: #666;
    font-size: 0.85rem;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}

.form-group input[type="checkbox"] {
    width: auto;
    margin-right: 8px;
}

/* Buttons */
.btn {
    padding: 12px 30px;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
}

.btn-primary {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(102, 126, 234, 0.4);
}

.btn-secondary {
    background: #f0f0f0;
    color: #333;
}

.btn-secondary:hover {
    background: #e0e0e0;
}

.btn-success {
    background: #10b981;
    color: white;
    padding: 8px 16px;
    font-size: 0.9rem;
}

.btn-danger {
    background: #ef4444;
    color: white;
    padding: 8px 16px;
    font-size: 0.9rem;
}

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

/* Jobs Section */
.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.controls {
    display: flex;
    gap: 10px;
    align-items: center;
}

#status-filter {
    padding: 8px 12px;
    border: 2px solid #eee;
    border-radius: 6px;
    font-size: 0.9rem;
}

/* Jobs List */
.jobs-list {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.job-item {
    border: 2px solid #eee;
    border-radius: 10px;
    padding: 20px;
    transition: all 0.3s;
}

.job-item:hover {
    border-color: #667eea;
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.1);
}

.job-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 15px;
}

.job-title {
    font-size: 1.1rem;
    font-weight: 600;
    color: #333;
    margin-bottom: 5px;
}

.job-id {
    font-size: 0.85rem;
    color: #666;
    font-family: monospace;
}

.job-status {
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 0.85rem;
    font-weight: 600;
    text-transform: uppercase;
}

.status-pending {
    background: #fef3c7;
    color: #92400e;
}

.status-processing {
    background: #dbeafe;
    color: #1e40af;
}

.status-completed {
    background: #d1fae5;
    color: #065f46;
}

.status-failed {
    background: #fee2e2;
    color: #991b1b;
}

.status-cancelled {
    background: #f3f4f6;
    color: #4b5563;
}

/* Progress Bar */
.job-progress {
    margin: 15px 0;
}

.progress-bar {
    width: 100%;
    height: 8px;
    background: #f0f0f0;
    border-radius: 4px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #667eea 0%, #764ba2 100%);
    transition: width 0.3s ease;
}

.progress-text {
    font-size: 0.85rem;
    color: #666;
    margin-top: 5px;
}

/* Job Details */
.job-details {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 15px;
    margin: 15px 0;
}

.job-detail {
    display: flex;
    flex-direction: column;
}

.job-detail-label {
    font-size: 0.85rem;
    color: #666;
    margin-bottom: 3px;
}

.job-detail-value {
    font-weight: 500;
    color: #333;
}

/* Job Actions */
.job-actions {
    display: flex;
    gap: 10px;
    margin-top: 15px;
}

/* Error Message */
.error-message {
    background: #fee2e2;
    color: #991b1b;
    padding: 12px;
    border-radius: 6px;
    margin-top: 10px;
    font-size: 0.9rem;
}

/* Loading State */
.loading {
    text-align: center;
    color: #666;
    padding: 40px;
}

.empty-state {
    text-align: center;
    color: #666;
    padding: 40px;
}

/* Toast Notifications */
#toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.toast {
    background: white;
    padding: 16px 20px;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    min-width: 300px;
    animation: slideIn 0.3s ease;
}

.toast.success {
    border-left: 4px solid #10b981;
}

.toast.error {
    border-left: 4px solid #ef4444;
}

.toast.info {
    border-left: 4px solid #3b82f6;
}

@keyframes slideIn {
    from {
        transform: translateX(400px);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

/* Responsive */
@media (max-width: 768px) {
    .form-row {
        grid-template-columns: 1fr;
    }
    
    .stats {
        justify-content: center;
    }
    
    .section-header {
        flex-direction: column;
        gap: 15px;
    }
    
    .job-header {
        flex-direction: column;
        gap: 10px;
    }
    
    .job-details {
        grid-template-columns: 1fr;
    }
}

/* Batch/Book job styles */
.batch-badge {
    display: inline-block;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    font-size: 0.65rem;
    font-weight: 700;
    padding: 2px 8px;
    border-radius: 10px;
    margin-right: 6px;
    vertical-align: middle;
    letter-spacing: 0.5px;
}

.batch-job {
    border-left: 3px solid #764ba2;
}

.child-jobs-section {
    margin: 10px 0;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    overflow: hidden;
}

.child-jobs-header {
    background: #f7f8fa;
    padding: 8px 14px;
    font-size: 0.85rem;
    font-weight: 600;
    color: #4a5568;
    cursor: pointer;
    user-select: none;
}

.child-jobs-header:hover {
    background: #edf2f7;
}

.child-jobs-list {
    padding: 4px 0;
}

.chapter-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 14px;
    font-size: 0.82rem;
    border-bottom: 1px solid #f0f0f0;
}

.chapter-row:last-child {
    border-bottom: none;
}

.chapter-index {
    color: #a0aec0;
    font-weight: 600;
    min-width: 24px;
}

.chapter-name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chapter-row .job-status {
    font-size: 0.7rem;
    padding: 1px 8px;
}

.chapter-progress-bar {
    width: 60px;
    height: 4px;
    background: #e2e8f0;
    border-radius: 2px;
    overflow: hidden;
}

.chapter-progress-bar .progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #667eea, #764ba2);
}

/* Awaiting review status */
.status-awaiting_review {
    background: #fef3c7;
    color: #92400e;
}

/* Character Review Modal */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    animation: fadeIn 0.2s;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.modal-content {
    background: white;
    border-radius: 12px;
    width: 90%;
    max-width: 700px;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}

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

.modal-header h2 {
    margin: 0;
    font-size: 1.2rem;
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: #a0aec0;
    padding: 4px 8px;
}

.modal-close:hover {
    color: #4a5568;
}

.modal-body {
    padding: 16px 24px;
    overflow-y: auto;
    flex: 1;
}

.modal-subtitle {
    color: #718096;
    font-size: 0.85rem;
    margin: 0 0 16px 0;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    padding: 16px 24px;
    border-top: 1px solid #e2e8f0;
}

/* Character cards in modal */
.character-card {
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 12px 16px;
    margin-bottom: 12px;
}

.character-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
}

.character-number {
    font-weight: 700;
    color: #764ba2;
    font-size: 0.85rem;
    min-width: 20px;
}

.char-name {
    flex: 1;
    font-weight: 600;
    font-size: 0.95rem;
    padding: 4px 8px;
    border: 1px solid #e2e8f0;
    border-radius: 4px;
}

.voice-badge {
    font-size: 0.6rem;
    font-weight: 700;
    padding: 2px 8px;
    border-radius: 10px;
    letter-spacing: 0.5px;
}

.voice-badge.generated {
    background: #e2e8f0;
    color: #4a5568;
}

.voice-badge.clone {
    background: #c6f6d5;
    color: #22543d;
}

.character-fields {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.field-group label {
    font-size: 0.75rem;
    font-weight: 600;
    color: #718096;
    margin-bottom: 2px;
    display: block;
}

.field-group input[type="text"] {
    width: 100%;
    padding: 6px 10px;
    border: 1px solid #e2e8f0;
    border-radius: 4px;
    font-size: 0.85rem;
}

.voice-upload-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.voice-upload-row input[type="file"] {
    font-size: 0.8rem;
    flex: 1;
}

.char-ref-text {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font-family: inherit;
    font-size: 0.85rem;
    resize: vertical;
    min-height: 48px;
    transition: border-color 0.2s;
}

.char-ref-text:focus {
    border-color: #4f46e5;
    outline: none;
    box-shadow: 0 0 0 2px rgba(79, 70, 229, 0.15);
}

.field-hint {
    font-size: 0.75rem;
    color: #6b7280;
    font-weight: 400;
}

/* Review prompt in job card */
.review-prompt {
    background: #fffbeb;
    border: 1px solid #fbbf24;
    border-radius: 8px;
    padding: 12px 16px;
    margin: 10px 0;
}

.review-prompt-header {
    font-weight: 600;
    font-size: 0.85rem;
    color: #92400e;
    margin-bottom: 8px;
}

.review-char-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.review-char-row {
    display: flex;
    align-items: baseline;
    gap: 8px;
    font-size: 0.82rem;
}

.review-char-name {
    font-weight: 600;
    color: #4a5568;
    min-width: 100px;
}

.review-char-traits {
    color: #718096;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.btn-sm {
    padding: 4px 10px;
    font-size: 0.75rem;
    border-radius: 2px;
    transition: width 0.3s;
}

/* Voice Preset Selection */
.voice-preset-section {
    margin-top: 12px;
    padding: 10px 12px;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
}

.voice-preset-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.voice-preset-row select {
    flex: 1;
    padding: 6px 10px;
    border: 1px solid #d1d5db;
    border-radius: 4px;
    font-size: 0.85rem;
    background: white;
}

.voice-preset-row button {
    padding: 6px 12px;
    font-size: 0.8rem;
}

.voice-badge.preset {
    background: #dbeafe;
    color: #1e40af;
}

.voice-preset-info {
    margin-top: 8px;
    padding: 8px 10px;
    background: #eff6ff;
    border-radius: 4px;
    font-size: 0.8rem;
}

.voice-preset-info strong {
    color: #1e40af;
}

.voice-preset-info p {
    margin: 4px 0 0 0;
    color: #64748b;
}

/* Voice Library Section */
.voice-library-section .section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.voice-library-section .section-header h2 {
    margin: 0;
}

.voice-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 16px;
}

.voice-list .loading {
    grid-column: 1 / -1;
    text-align: center;
    color: #64748b;
    padding: 24px;
}

/* Voice Library */
.voice-library {
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.voice-presets-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 16px;
}

.voice-preset-card {
    background: white;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 16px;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 12px;
}

.voice-preset-card:hover {
    border-color: #cbd5e1;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.voice-info h4 {
    margin: 0 0 4px 0;
    font-size: 1rem;
    color: #1e293b;
}

.voice-description {
    margin: 0 0 8px 0;
    font-size: 0.85rem;
    color: #64748b;
}

.voice-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.voice-tags .tag {
    padding: 2px 8px;
    font-size: 0.75rem;
    border-radius: 12px;
    background: #f1f5f9;
    color: #475569;
}

.voice-tags .tag.system {
    background: #dbeafe;
    color: #1e40af;
}

.voice-tags .tag.user {
    background: #dcfce7;
    color: #166534;
}

.voice-actions {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.voice-actions .btn-sm {
    white-space: nowrap;
}

.btn-danger {
    background: #fee2e2;
    color: #dc2626;
    border: 1px solid #fecaca;
}

.btn-danger:hover {
    background: #fecaca;
}

.no-voices {
    text-align: center;
    color: #64748b;
    padding: 24px;
    background: #f8fafc;
    border-radius: 8px;
}

/* Voice Generator */
.voice-generator,
.voice-uploader {
    background: white;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 20px;
}

.voice-generator h3,
.voice-uploader h3 {
    margin: 0 0 16px 0;
    font-size: 1.1rem;
    color: #1e293b;
}

.voice-form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 12px;
    margin-bottom: 16px;
}

.voice-form-grid .form-group {
    margin-bottom: 0;
}

.voice-form-grid label {
    display: block;
    margin-bottom: 4px;
    font-size: 0.85rem;
    font-weight: 500;
    color: #374151;
}

.voice-form-grid input,
.voice-form-grid select,
.voice-form-grid textarea {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font-size: 0.9rem;
}

.voice-form-grid textarea {
    min-height: 60px;
    resize: vertical;
}

.voice-form-full {
    grid-column: 1 / -1;
}
