/**
 * Emotional Storyteller - Frontend Styles
 */

:root {
    --es-primary: #c4a77d;
    --es-primary-dark: #a38b5f;
    --es-secondary: #7c9a6c;
    --es-terracotta: #c17f59;
    --es-terracotta-dark: #a66843;
    --es-background: linear-gradient(135deg, #faf7f2 0%, #f5f0e8 50%, #faf5ef 100%);
    --es-card-bg: #ffffff;
    --es-text: #3d3d3d;
    --es-text-muted: #6b6b6b;
    --es-border: #e5e0d8;
    --es-shadow: 0 4px 20px rgba(0, 0, 0, 0.06);
    --es-shadow-hover: 0 8px 30px rgba(0, 0, 0, 0.1);
    --es-radius: 16px;
    --es-radius-sm: 10px;
    --es-font-display: 'Playfair Display', Georgia, serif;
    --es-font-body: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}

.es-theme-dark {
    --es-background: linear-gradient(135deg, #1a1a1a 0%, #2d2d2d 50%, #1a1a1a 100%);
    --es-card-bg: #2a2a2a;
    --es-text: #e5e5e5;
    --es-text-muted: #a0a0a0;
    --es-border: #3d3d3d;
}

.emotional-storyteller-container {
    font-family: var(--es-font-body);
    color: var(--es-text);
    max-width: 720px;
    margin: 0 auto;
    padding: 2rem 1rem;
    background: var(--es-background);
    min-height: 100vh;
    line-height: 1.6;
}

.emotional-storyteller-error {
    background: #fee2e2;
    border: 1px solid #fecaca;
    color: #dc2626;
    padding: 1rem 1.5rem;
    border-radius: var(--es-radius-sm);
    text-align: center;
}

.emotional-storyteller-error a {
    color: #dc2626;
    font-weight: 600;
}

/* Header */
.es-header {
    text-align: center;
    margin-bottom: 2.5rem;
    padding: 1rem 0;
}

.es-header-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 64px;
    height: 64px;
    background: linear-gradient(135deg, var(--es-primary), var(--es-terracotta));
    border-radius: 50%;
    color: white;
    margin-bottom: 1rem;
}

.es-title {
    font-family: var(--es-font-display);
    font-size: 2rem;
    font-weight: 600;
    color: var(--es-text);
    margin: 0 0 0.5rem 0;
}

.es-subtitle {
    color: var(--es-text-muted);
    font-size: 1rem;
    margin: 0;
}

/* Form */
.es-form {
    display: flex;
    flex-direction: column;
    gap: 1.75rem;
}

.es-form-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.es-label {
    font-weight: 500;
    font-size: 0.95rem;
    color: var(--es-text);
}

.es-label-hint {
    font-weight: 400;
    color: var(--es-text-muted);
    font-size: 0.875rem;
}

.es-label-small {
    font-size: 0.875rem;
    color: var(--es-text-muted);
}

.es-input,
.es-textarea,
.es-select {
    width: 100%;
    padding: 0.875rem 1rem;
    font-size: 1rem;
    font-family: inherit;
    border: 1px solid var(--es-border);
    border-radius: var(--es-radius-sm);
    background: var(--es-card-bg);
    color: var(--es-text);
    transition: border-color 0.2s, box-shadow 0.2s;
    box-sizing: border-box;
}

.es-input:focus,
.es-textarea:focus,
.es-select:focus {
    outline: none;
    border-color: var(--es-primary);
    box-shadow: 0 0 0 3px rgba(196, 167, 125, 0.15);
}

.es-select {
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='%236b6b6b' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.75rem center;
    background-size: 20px;
    padding-right: 2.5rem;
}

.es-select optgroup {
    font-weight: 600;
    color: var(--es-text);
    padding: 0.5rem 0;
}

.es-select option {
    padding: 0.5rem;
    font-weight: normal;
}

.es-textarea {
    min-height: 100px;
    resize: vertical;
}

.es-textarea-small {
    min-height: 70px;
}

/* Style Cards */
.es-style-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.75rem;
}

.es-style-card {
    cursor: pointer;
}

.es-style-card input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.es-style-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.25rem;
    padding: 1rem;
    background: var(--es-card-bg);
    border: 2px solid var(--es-border);
    border-radius: var(--es-radius-sm);
    transition: all 0.2s;
    text-align: center;
}

.es-style-card input:checked + .es-style-content {
    border-color: var(--es-terracotta);
    background: rgba(193, 127, 89, 0.08);
}

.es-style-card:hover .es-style-content {
    border-color: var(--es-primary);
}

.es-style-icon {
    font-size: 1.5rem;
}

.es-style-name {
    font-weight: 600;
    font-size: 0.9rem;
}

.es-style-desc {
    font-size: 0.75rem;
    color: var(--es-text-muted);
}

/* Reference Section */
.es-toggle-reference {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: none;
    border: none;
    cursor: pointer;
    font-size: 0.95rem;
    font-weight: 500;
    color: var(--es-text);
    padding: 0;
}

.es-toggle-reference:hover {
    color: var(--es-primary);
}

.es-toggle-icon {
    transition: transform 0.2s;
}

.es-toggle-icon.rotated {
    transform: rotate(180deg);
}

.es-reference-section {
    margin-top: 1rem;
    padding: 1rem;
    background: var(--es-card-bg);
    border: 1px solid var(--es-border);
    border-radius: var(--es-radius-sm);
}

.es-reference-type-buttons {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.es-ref-type-btn {
    flex: 1;
}

.es-ref-type-btn.active {
    background: var(--es-terracotta);
    color: white;
    border-color: var(--es-terracotta);
}

/* Buttons */
.es-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.75rem 1.25rem;
    font-size: 0.9rem;
    font-weight: 500;
    font-family: inherit;
    border-radius: var(--es-radius-sm);
    border: 1px solid transparent;
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
}

.es-btn-primary {
    background: var(--es-terracotta);
    color: white;
    border-color: var(--es-terracotta);
}

.es-btn-primary:hover {
    background: var(--es-terracotta-dark);
    border-color: var(--es-terracotta-dark);
}

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

.es-btn-secondary {
    background: var(--es-card-bg);
    color: var(--es-text);
    border-color: var(--es-border);
}

.es-btn-secondary:hover {
    border-color: var(--es-primary);
}

.es-btn-ghost {
    background: transparent;
    color: var(--es-text-muted);
    border: none;
    padding: 0.5rem 0.75rem;
}

.es-btn-ghost:hover {
    color: var(--es-text);
}

.es-btn-full {
    width: 100%;
    padding: 1rem;
    font-size: 1rem;
}

/* Spinner */
.es-spinner {
    animation: es-spin 1s linear infinite;
}

@keyframes es-spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

/* Output View */
.es-output-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.es-output-actions {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

/* Cards */
.es-card {
    background: var(--es-card-bg);
    border-radius: var(--es-radius);
    padding: 1.5rem;
    box-shadow: var(--es-shadow);
    margin-bottom: 1.5rem;
}

.es-title-card {
    background: linear-gradient(135deg, var(--es-card-bg), rgba(196, 167, 125, 0.1));
}

.es-script-title {
    font-family: var(--es-font-display);
    font-size: 1.5rem;
    font-weight: 600;
    margin: 0 0 0.75rem 0;
}

.es-script-description {
    color: var(--es-text-muted);
    margin: 0 0 1rem 0;
}

.es-cta-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    background: rgba(124, 154, 108, 0.15);
    color: var(--es-secondary);
    border-radius: 50px;
    font-size: 0.875rem;
}

/* Scenes */
.es-scenes-section {
    margin-bottom: 1.5rem;
}

.es-section-title {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 1.1rem;
    font-weight: 600;
    margin: 0 0 1rem 0;
    color: var(--es-terracotta);
}

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

.es-scene-card {
    background: var(--es-card-bg);
    border-radius: var(--es-radius-sm);
    padding: 1rem 1.25rem;
    box-shadow: var(--es-shadow);
    border-left: 3px solid var(--es-primary);
}

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

.es-scene-media-toggle {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.es-media-upload {
    cursor: pointer;
    padding: 0.4rem;
    border-radius: 6px;
    background: var(--es-border);
    color: var(--es-text-muted);
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.es-media-upload:hover {
    background: var(--es-primary);
    color: white;
}

.es-scene-media-status {
    font-size: 0.75rem;
    font-weight: 500;
}

.es-scene-number {
    font-weight: 600;
    font-size: 0.8rem;
    color: var(--es-primary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.es-scene-voice {
    font-size: 1rem;
    margin: 0 0 0.5rem 0;
    line-height: 1.5;
}

.es-scene-visual {
    font-size: 0.85rem;
    color: var(--es-text-muted);
    margin: 0;
    font-style: italic;
}

/* Caption Card */
.es-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.75rem;
}

.es-card-title {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 1rem;
    font-weight: 600;
    margin: 0;
}

.es-copy-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: 0.5rem;
    color: var(--es-text-muted);
    border-radius: var(--es-radius-sm);
    transition: all 0.2s;
}

.es-copy-btn:hover {
    background: var(--es-border);
    color: var(--es-text);
}

.es-copy-btn.copied {
    color: var(--es-secondary);
}

.es-caption-text {
    margin: 0;
    white-space: pre-wrap;
    line-height: 1.7;
}

/* Guide Card */
.es-guide-card {
    background: rgba(124, 154, 108, 0.08);
}

.es-guide-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
}

.es-guide-item {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.es-guide-item.full-width {
    grid-column: 1 / -1;
}

.es-guide-label {
    font-size: 0.8rem;
    color: var(--es-text-muted);
}

.es-guide-value {
    font-size: 0.9rem;
}

/* Video Preview */
.es-video-preview {
    margin-bottom: 1.5rem;
}

.es-video-container {
    background: #000;
    border-radius: var(--es-radius);
    overflow: hidden;
    aspect-ratio: 9/16;
    max-height: 500px;
    margin: 0 auto;
    position: relative;
}

.es-video-screen {
    width: 100%;
    height: 100%;
    position: relative;
}

.es-video-image {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.es-video-overlay {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 2rem 1rem;
    background: linear-gradient(transparent, rgba(0,0,0,0.8));
}

.es-video-text {
    color: white;
    text-align: center;
    font-size: 1rem;
    margin: 0;
    text-shadow: 0 2px 4px rgba(0,0,0,0.5);
}

.es-video-controls {
    position: absolute;
    bottom: 1rem;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: 1rem;
    background: rgba(0,0,0,0.6);
    padding: 0.5rem 1rem;
    border-radius: 50px;
}

.es-video-btn {
    background: none;
    border: none;
    color: white;
    cursor: pointer;
    padding: 0.5rem;
    opacity: 0.8;
    transition: opacity 0.2s;
}

.es-video-btn:hover {
    opacity: 1;
}

.es-video-btn-play {
    background: white;
    color: #000;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.es-scene-counter {
    color: white;
    font-size: 0.8rem;
    opacity: 0.8;
}

/* Progress */
.es-generation-progress {
    padding: 1rem;
    text-align: center;
}

.es-progress-bar {
    height: 4px;
    background: var(--es-border);
    border-radius: 2px;
    overflow: hidden;
    margin-bottom: 0.75rem;
}

.es-progress-fill {
    height: 100%;
    background: var(--es-terracotta);
    width: 0%;
    transition: width 0.3s;
}

.es-progress-text {
    font-size: 0.85rem;
    color: var(--es-text-muted);
    margin: 0;
}

/* Toast */
.es-toast-container {
    position: fixed;
    bottom: 1rem;
    right: 1rem;
    z-index: 10000;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.es-toast {
    background: var(--es-card-bg);
    padding: 1rem 1.5rem;
    border-radius: var(--es-radius-sm);
    box-shadow: var(--es-shadow-hover);
    border-left: 4px solid var(--es-secondary);
    max-width: 300px;
    animation: es-slide-in 0.3s ease;
}

.es-toast.error {
    border-color: #dc2626;
}

.es-toast-title {
    font-weight: 600;
    font-size: 0.9rem;
    margin: 0 0 0.25rem 0;
}

.es-toast-message {
    font-size: 0.85rem;
    color: var(--es-text-muted);
    margin: 0;
}

@keyframes es-slide-in {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

/* Responsive */
@media (max-width: 600px) {
    .emotional-storyteller-container {
        padding: 1rem;
    }
    
    .es-style-grid {
        grid-template-columns: 1fr;
    }
    
    .es-guide-grid {
        grid-template-columns: 1fr;
    }
    
    .es-output-header {
        flex-direction: column;
        align-items: stretch;
    }
    
    .es-output-actions {
        justify-content: center;
    }
    
    .es-video-container {
        max-height: 400px;
    }
}

/* Video Player Wrapper */
.es-video-player-wrapper {
    margin-bottom: 1.5rem;
}

.es-video-player-container {
    background: #000;
    border-radius: var(--es-radius);
    overflow: hidden;
}

.es-final-video {
    width: 100%;
    max-height: 500px;
    display: block;
}

/* Caption Text - Long format */
.es-caption-text {
    margin: 0;
    white-space: pre-wrap;
    line-height: 1.8;
    font-size: 0.95rem;
}

.es-caption-card {
    max-height: 400px;
    overflow-y: auto;
}

/* Download Button */
#es-download-video-btn {
    background: var(--es-secondary);
    color: white;
    border-color: var(--es-secondary);
}

#es-download-video-btn:hover {
    background: #6a8a5c;
    border-color: #6a8a5c;
}

/* Video Player */
.es-video-player-container {
    margin-bottom: 1.5rem;
}

.es-final-video {
    width: 100%;
    max-height: 500px;
    border-radius: var(--es-radius);
    background: #000;
}

/* Success Button (Download) */
.es-btn-success {
    background: var(--es-secondary);
    color: white;
    border-color: var(--es-secondary);
}

.es-btn-success:hover {
    background: #6a8759;
    border-color: #6a8759;
}

/* Caption Formatting */
.es-caption-text {
    line-height: 1.8;
}

.es-hashtag {
    color: var(--es-primary);
    font-weight: 500;
}

/* Warning Toast */
.es-toast.warning {
    border-color: #f59e0b;
}

/* Caption Card Enhanced */
.es-caption-card .es-caption-text {
    max-height: 400px;
    overflow-y: auto;
    padding-right: 0.5rem;
}

.es-caption-card .es-caption-text::-webkit-scrollbar {
    width: 6px;
}

.es-caption-card .es-caption-text::-webkit-scrollbar-track {
    background: var(--es-border);
    border-radius: 3px;
}

.es-caption-card .es-caption-text::-webkit-scrollbar-thumb {
    background: var(--es-primary);
    border-radius: 3px;
}

/* Download Section */
.es-download-section {
    margin: 1rem 0;
    text-align: center;
}

.es-btn-download-video {
    font-size: 1rem;
    padding: 1rem 2rem;
    gap: 0.75rem;
}

.es-download-options {
    display: flex;
    justify-content: center;
    gap: 1rem;
    margin: 1rem 0;
    flex-wrap: wrap;
}

/* Caption Card - Better formatting for long text */
.es-caption-card .es-caption-text {
    font-size: 0.95rem;
    line-height: 1.8;
    white-space: pre-wrap;
    word-wrap: break-word;
}

.es-caption-card {
    max-height: 400px;
    overflow-y: auto;
}

/* Scrollbar styling */
.es-caption-card::-webkit-scrollbar {
    width: 6px;
}

.es-caption-card::-webkit-scrollbar-track {
    background: var(--es-border);
    border-radius: 3px;
}

.es-caption-card::-webkit-scrollbar-thumb {
    background: var(--es-primary);
    border-radius: 3px;
}

.es-caption-card::-webkit-scrollbar-thumb:hover {
    background: var(--es-primary-dark);
}
