/* AI PPT Generator - Modern Clean Styles */

:root {
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --primary-light: #3b82f6;
    --secondary: #059669;
    --danger: #dc2626;
    --warning: #d97706;
    --bg-dark: #f3f4f6;
    --bg-card: #ffffff;
    --bg-input: #f9fafb;
    --text-primary: #1f2937;
    --text-secondary: #4b5563;
    --text-muted: #9ca3af;
    --border: #e5e7eb;
    --border-light: #d1d5db;
    --shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
    --radius: 12px;
    --radius-sm: 8px;
    --transition: all 0.2s ease;
}

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

/* Hidden utility class */
.hidden {
    display: none !important;
}

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

/* App Container */
.app-container {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* Header */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 24px;
    background: linear-gradient(135deg, var(--bg-card) 0%, #e5e7eb 100%);
    border-bottom: 1px solid var(--border);
}

.logo {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 1.4rem;
    font-weight: 700;
}

.logo-icon {
    font-size: 1.8rem;
}

.logo-text {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.logo-icon-img {
    width: 32px;
    height: 32px;
    object-fit: contain;
}

.contact-info {
    font-size: 0.75rem;
    font-weight: 400;
    color: var(--text-muted);
    margin-left: 16px;
    padding-left: 16px;
    border-left: 1px solid var(--border);
}

.history-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 20px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 0.9rem;
    cursor: pointer;
    transition: var(--transition);
}

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

/* Main Content - 3 Columns */
.main-content {
    display: grid;
    grid-template-columns: 340px 1fr 1fr;
    gap: 20px;
    padding: 20px;
    flex: 1;
    overflow: hidden;
    height: calc(100vh - 80px);
    align-items: start;
    /* Allow panels to have individual heights */
}

/* Panels */
.panel {
    background: var(--bg-card);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    max-height: calc(100vh - 120px);
    /* Fixed max height for scrolling */
}

.panel-title {
    padding: 16px 20px;
    font-size: 1rem;
    font-weight: 600;
    background: linear-gradient(135deg, var(--bg-input) 0%, var(--bg-card) 100%);
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

.title-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

.regen-count-title {
    font-size: 0.8rem;
    color: var(--text-muted);
    white-space: nowrap;
}

/* Input Panel */
.panel-input {
    display: flex;
    flex-direction: column;
}

.input-content {
    flex: 1;
    overflow-y: auto;
    overscroll-behavior: contain;
    min-height: 0;
    /* Allow shrinking in flexbox */
}

.input-section {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
}

.section-label {
    display: block;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 12px;
}

/* Page Options */
.page-options {
    display: flex;
    gap: 8px;
}

.page-option {
    flex: 1;
    cursor: pointer;
}

.page-option input {
    display: none;
}

.option-box {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 12px 8px;
    background: var(--bg-input);
    border: 2px solid var(--border);
    border-radius: var(--radius-sm);
    transition: var(--transition);
}

.page-option input:checked+.option-box {
    border-color: var(--primary);
    background: rgba(99, 102, 241, 0.1);
}

.option-title {
    font-size: 0.9rem;
    font-weight: 600;
}

.option-price {
    font-size: 0.75rem;
    color: var(--secondary);
    margin-top: 4px;
}

/* Style Grid */
.style-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    margin-bottom: 16px;
}

.style-item {
    position: relative;
    aspect-ratio: 16/9;
    border-radius: var(--radius-sm);
    overflow: hidden;
    cursor: pointer;
    border: 2px solid var(--border);
    transition: var(--transition);
}

.style-item.selected {
    border-color: var(--primary);
    box-shadow: 0 0 20px rgba(99, 102, 241, 0.3);
}

.style-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.style-item .style-name {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 6px;
    background: linear-gradient(transparent, rgba(0, 0, 0, 0.8));
    font-size: 0.75rem;
    text-align: center;
}

/* Upload Section */
.custom-upload-section {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px dashed var(--border);
}

.upload-hint {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-bottom: 10px;
}

.upload-row {
    display: flex;
    gap: 10px;
}

.upload-box {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 16px;
    background: var(--bg-input);
    border: 2px dashed var(--border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: var(--transition);
}

.upload-box:hover {
    border-color: var(--primary);
}

.upload-icon {
    font-size: 1.4rem;
    margin-bottom: 4px;
}

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

.upload-previews {
    display: flex;
    gap: 8px;
    margin-top: 10px;
    flex-wrap: wrap;
}

.preview-row {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.preview-item {
    position: relative;
    display: inline-block;
}

.preview-item img {
    width: 60px;
    height: 60px;
    object-fit: cover;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
}

.preview-item .delete-btn {
    position: absolute;
    top: -6px;
    right: -6px;
    width: 18px;
    height: 18px;
    background: var(--danger);
    border: none;
    border-radius: 50%;
    color: white;
    font-size: 12px;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.preview-item .delete-btn:hover {
    background: #dc2626;
}

/* Content Input */
#content-input {
    width: 100%;
    padding: 14px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 0.9rem;
    resize: vertical;
    min-height: 150px;
}

#content-input:focus {
    outline: none;
    border-color: var(--primary);
}

.input-tip {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 8px;
}

/* Code Input */
.code-input-row {
    display: flex;
    gap: 8px;
}

.code-input-row input {
    width: 160px;
    min-width: 140px;
    padding: 12px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 0.85rem;
    text-transform: uppercase;
}

.validate-btn {
    padding: 12px 14px;
    background: var(--primary);
    border: none;
    border-radius: var(--radius-sm);
    color: white;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    white-space: nowrap;
}

.validate-btn:hover {
    background: var(--primary-dark);
}

.code-status {
    font-size: 0.8rem;
    margin-top: 8px;
    min-height: 20px;
}

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

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

.buy-btn {
    padding: 12px 14px;
    background: linear-gradient(135deg, var(--secondary) 0%, #059669 100%);
    border: none;
    border-radius: var(--radius-sm);
    color: white;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    white-space: nowrap;
}

.buy-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 15px rgba(16, 185, 129, 0.3);
}

/* Action Buttons */
.action-buttons {
    padding: 20px;
    display: flex;
    align-items: center;
    gap: 12px;
}

.action-buttons.centered {
    flex-direction: column;
    align-items: center;
}

.action-buttons.centered .regen-count {
    margin-bottom: 8px;
}

.btn {
    padding: 14px 24px;
    border: none;
    border-radius: var(--radius-sm);
    font-weight: 600;
    font-size: 0.9rem;
    cursor: pointer;
    transition: var(--transition);
}

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

.btn-primary {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: white;
}

.btn-primary:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(99, 102, 241, 0.4);
}

.btn-secondary {
    background: var(--bg-input);
    border: 1px solid var(--border);
    color: var(--text-primary);
}

.btn-danger {
    background: var(--danger);
    color: white;
}

.btn-download {
    background: linear-gradient(135deg, var(--secondary) 0%, #059669 100%);
    color: white;
}

.btn-download-small {
    padding: 8px 14px;
    font-size: 0.85rem;
    background: linear-gradient(135deg, var(--secondary) 0%, #059669 100%);
    border: none;
    border-radius: var(--radius-sm);
    color: white;
    cursor: pointer;
    transition: var(--transition);
}

.btn-download-small:hover {
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(16, 185, 129, 0.3);
}

/* Page Count Selector */
.page-count-row {
    display: flex;
    align-items: center;
    gap: 12px;
}

.page-count-select {
    padding: 10px 16px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 0.9rem;
    cursor: pointer;
    min-width: 120px;
}

.page-count-select:focus {
    outline: none;
    border-color: var(--primary);
}

.page-count-select:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.page-count-hint {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.regen-count {
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* Outline Panel */
.panel-outline {
    display: flex;
    flex-direction: column;
}

.outline-container {
    flex: 1;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 16px;
    min-height: 0;
    /* Allow shrinking in flexbox */
}

.outline-actions {
    padding: 20px;
    border-top: 1px solid var(--border);
    display: flex;
    flex-direction: row;
    justify-content: center;
    align-items: center;
    gap: 24px;
    flex-shrink: 0;
}

.outline-actions .btn-secondary {
    align-self: center;
}

.outline-actions .btn-primary {
    align-self: center;
}

/* Slide Card */
.slide-card {
    background: var(--bg-input);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    margin-bottom: 12px;
    overflow: hidden;
}

.slide-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    background: rgba(99, 102, 241, 0.1);
    border-bottom: 1px solid var(--border);
    cursor: pointer;
}

.slide-number {
    font-weight: 700;
    color: var(--primary-light);
}

.slide-title {
    flex: 1;
    margin-left: 12px;
    font-size: 0.9rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.slide-actions {
    display: flex;
    gap: 8px;
}

.slide-action-btn {
    padding: 4px 8px;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--text-secondary);
    font-size: 0.75rem;
    cursor: pointer;
    transition: var(--transition);
}

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

.slide-action-btn.delete:hover {
    background: var(--danger);
    border-color: var(--danger);
    color: white;
}

.collapse-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 1.2rem;
    transition: var(--transition);
}

.slide-content {
    padding: 16px;
}

.slide-content.collapsed {
    display: none;
}

.slide-field {
    margin-bottom: 12px;
}

.field-label {
    display: block;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 4px;
}

.field-input {
    width: 100%;
    padding: 10px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 0.85rem;
    resize: vertical;
    scrollbar-width: none;
    /* Firefox */
    -ms-overflow-style: none;
    /* IE/Edge */
}

.field-input::-webkit-scrollbar {
    display: none;
    /* Chrome/Safari */
}

.field-input:focus {
    outline: none;
    border-color: var(--primary);
}

/* Result Panel */
.panel-result {
    display: flex;
    flex-direction: column;
    min-height: 400px;
    /* Ensure minimum height for preview images */
}

.result-container {
    flex: 1;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    align-content: start;
    min-height: 300px;
    /* Ensure preview images are visible */
}

.result-actions {
    padding: 16px;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.result-item {
    background: var(--bg-input);
    border-radius: var(--radius-sm);
    overflow: hidden;
    border: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    /* Prevent squashing by flexbox - allow natural height */
}

.result-item-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 14px;
    background: rgba(99, 102, 241, 0.1);
    border-bottom: 1px solid var(--border);
}

.result-item-title {
    font-weight: 600;
    color: var(--primary-light);
    font-size: 0.9rem;
}

.result-item-actions {
    display: flex;
    gap: 8px;
}

.result-action-btn {
    padding: 4px 10px;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--text-secondary);
    font-size: 0.75rem;
    cursor: pointer;
    transition: var(--transition);
}

.result-action-btn:hover {
    background: var(--border);
    color: var(--text-primary);
}

.result-action-btn.retry:hover {
    background: var(--primary);
    border-color: var(--primary);
    color: white;
}

.result-item-image {
    width: 100%;
    aspect-ratio: 16/9;
    cursor: pointer;
    transition: var(--transition);
}

.result-item-image:hover {
    opacity: 0.9;
}

.result-item-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.result-item .slide-number-badge {
    position: absolute;
    top: 8px;
    left: 8px;
    padding: 4px 8px;
    background: rgba(0, 0, 0, 0.7);
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 600;
}

.result-item .regenerate-btn {
    position: absolute;
    bottom: 8px;
    right: 8px;
    padding: 6px 12px;
    background: var(--primary);
    border: none;
    border-radius: 4px;
    color: white;
    font-size: 0.75rem;
    cursor: pointer;
    opacity: 0;
    transition: var(--transition);
}

.result-item:hover .regenerate-btn {
    opacity: 1;
}

.result-item.loading::after {
    content: "";
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Empty State */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px;
    color: var(--text-muted);
    text-align: center;
    grid-column: 1 / -1;
}

.empty-icon {
    font-size: 3rem;
    margin-bottom: 12px;
    opacity: 0.5;
}

/* Modal */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    backdrop-filter: blur(4px);
}

.modal.hidden {
    display: none;
}

.modal-content {
    background: var(--bg-card);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    width: 90%;
    max-width: 500px;
    max-height: 80vh;
    overflow: hidden;
}

.modal-small {
    max-width: 400px;
}

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

.modal-header h3 {
    font-size: 1.1rem;
}

.close-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-size: 1.5rem;
    cursor: pointer;
}

.modal-body {
    padding: 20px;
    max-height: 60vh;
    overflow-y: auto;
}

/* Payment */
.payment-price {
    font-size: 2rem;
    font-weight: 700;
    color: var(--secondary);
    text-align: center;
    margin-bottom: 20px;
}

#qr-container {
    display: flex;
    justify-content: center;
    margin-bottom: 16px;
}

#qr-container img {
    max-width: 200px;
    border-radius: var(--radius-sm);
}

.payment-tip {
    text-align: center;
    color: var(--text-muted);
    font-size: 0.85rem;
}

.success-icon {
    font-size: 4rem;
    text-align: center;
    margin-bottom: 16px;
}

.success-text {
    text-align: center;
    font-size: 1.2rem;
    margin-bottom: 12px;
}

.success-code {
    text-align: center;
    margin-bottom: 20px;
    word-break: break-all;
}

.success-code strong {
    color: var(--primary-light);
    font-size: 1.1rem;
}

#payment-success-section {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
}

#payment-success-section .btn {
    margin-top: 10px;
}

/* Confirm Modal */
.confirm-buttons {
    display: flex;
    gap: 12px;
    margin-top: 20px;
    justify-content: flex-end;
}

/* History */
.history-item {
    padding: 16px;
    background: var(--bg-input);
    border-radius: var(--radius-sm);
    margin-bottom: 12px;
    border: 1px solid var(--border);
}

.history-item-code {
    font-weight: 600;
    margin-bottom: 4px;
}

.history-item-info {
    display: flex;
    justify-content: space-between;
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-bottom: 12px;
}

.history-item-actions {
    display: flex;
    gap: 8px;
}

.history-item-actions button {
    padding: 8px 16px;
    background: var(--primary);
    border: none;
    border-radius: var(--radius-sm);
    color: white;
    font-size: 0.8rem;
    cursor: pointer;
}

/* Loading Spinner */
.spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* Lightbox */
.lightbox {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.95);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    cursor: pointer;
}

.lightbox.hidden {
    display: none !important;
    visibility: hidden !important;
    opacity: 0 !important;
}

.lightbox-content {
    position: relative;
    max-width: 95%;
    max-height: 95%;
}

.lightbox-content img {
    max-width: 100%;
    max-height: 90vh;
    border-radius: var(--radius);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

.lightbox-close {
    position: absolute;
    top: -40px;
    right: 0;
    background: transparent;
    border: none;
    color: white;
    font-size: 2rem;
    cursor: pointer;
    transition: var(--transition);
}

.lightbox-close:hover {
    color: var(--danger);
}

/* Responsive */
@media (max-width: 1200px) {
    .main-content {
        grid-template-columns: 300px 1fr 1fr;
    }
}

@media (max-width: 992px) {
    .main-content {
        grid-template-columns: 1fr;
        grid-template-rows: auto auto auto;
        height: auto;
        overflow: visible;
    }

    .panel {
        max-height: none;
        height: auto;
    }

    .input-content,
    .outline-container,
    .result-container {
        max-height: none;
        overflow-y: visible;
    }

    .result-item img {
        width: 100%;
        height: auto;
    }
}