/**
 * EPUB Splitter - Application Styles
 */

/* CSS 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;
    line-height: 1.6;
    color: #333;
    background-color: #f5f5f5;
}

/* Layout */
#app {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.page {
    display: none;
    flex-direction: column;
    min-height: 100vh;
}

.page.active {
    display: flex;
}

/* Header */
.app-header {
    background: #fff;
    border-bottom: 1px solid #e0e0e0;
    padding: 1rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.app-header h1 {
    font-size: 1.8rem;
    font-weight: 600;
    color: #2c3e50;
}

.app-header h2 {
    font-size: 1.4rem;
    font-weight: 500;
    color: #2c3e50;
}

.header-nav {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.header-actions {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

/* Mode Toggle */
.mode-toggle {
    display: flex;
    background: #f8f9fa;
    border-radius: 6px;
    padding: 2px;
    margin-right: 1rem;
}

.btn-toggle {
    padding: 0.5rem 1rem;
    border: none;
    background: transparent;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 500;
    transition: all 0.2s ease;
}

.btn-toggle:hover {
    background: #e9ecef;
}

.btn-toggle.active {
    background: #007bff;
    color: white;
}

/* View Modes */
.view-mode {
    display: none;
}

.view-mode.active {
    display: block;
}

/* Chunks Configuration */
.chunks-config {
    background: white;
    border-radius: 8px;
    padding: 1.5rem;
    margin-bottom: 1.5rem;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.config-section {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1rem;
}

.config-section label {
    font-weight: 600;
    color: #495057;
}

.chunk-input {
    padding: 0.5rem;
    border: 1px solid #ced4da;
    border-radius: 4px;
    font-size: 1rem;
    width: 100px;
}

.chunk-input:focus {
    outline: none;
    border-color: #007bff;
    box-shadow: 0 0 0 2px rgba(0,123,255,0.25);
}

.chunk-preview {
    margin-top: 1rem;
    padding: 1rem;
    background: #f8f9fa;
    border-radius: 6px;
    border-left: 4px solid #007bff;
}

.preview-info {
    margin-bottom: 1rem;
}

.preview-info p {
    margin-bottom: 0.5rem;
    font-size: 0.95rem;
}

.preview-info span {
    font-weight: 600;
    color: #007bff;
}

/* Chapter and Chunk Lists */
.chapter-list {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    padding: 1rem 0;
}

.chunk-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 0.75rem;
    padding: 1rem 0;
}

@media (max-width: 768px) {
    .chunk-list {
        grid-template-columns: 1fr;
        gap: 0.5rem;
    }
}

@media (min-width: 1200px) {
    .chunk-list {
        grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    }
}

.chunk-item {
    background: white;
    border-radius: 6px;
    padding: 0.75rem;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    border: 1px solid #e9ecef;
    transition: all 0.2s ease;
    font-size: 0.9rem;
}

.chunk-item:hover {
    box-shadow: 0 4px 8px rgba(0,0,0,0.15);
}

.chunk-item.selected {
    border-color: #007bff;
    background: #f8f9ff;
}

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

.chunk-title {
    font-weight: 600;
    color: #2c3e50;
    font-size: 0.95rem;
}

.chunk-meta {
    color: #6c757d;
    font-size: 0.9rem;
}

.chunk-preview-text {
    color: #495057;
    font-size: 0.85rem;
    line-height: 1.4;
    margin-top: 0.4rem;
    padding: 0.5rem;
    background: #f8f9fa;
    border-radius: 4px;
    border-left: 3px solid #dee2e6;
    max-height: 80px;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 4;
    line-clamp: 4;
    -webkit-box-orient: vertical;
}

/* Main Content */
.main-content {
    flex: 1;
    padding: 2rem;
    overflow-y: auto;
}

/* Footer */
.app-footer {
    background: #fff;
    border-top: 1px solid #e0e0e0;
    padding: 1rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 -2px 4px rgba(0,0,0,0.1);
}

/* Buttons */
.btn {
    padding: 0.5rem 1rem;
    border: none;
    border-radius: 6px;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}

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

.btn-primary {
    background: #3498db;
    color: white;
}

.btn-primary:hover:not(:disabled) {
    background: #2980b9;
}

.btn-secondary {
    background: #95a5a6;
    color: white;
}

.btn-secondary:hover:not(:disabled) {
    background: #7f8c8d;
}

.btn-back {
    background: #ecf0f1;
    color: #2c3e50;
}

.btn-back:hover {
    background: #d5dbdb;
}

.btn-small {
    padding: 0.25rem 0.5rem;
    font-size: 0.8rem;
}

.btn-large {
    padding: 0.75rem 1.5rem;
    font-size: 1rem;
}

/* File List */
.file-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 1.5rem;
    margin-top: 1rem;
}

.file-card {
    background: white;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    padding: 1.5rem;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 1rem;
}

.file-card:hover {
    border-color: #3498db;
    box-shadow: 0 4px 12px rgba(52, 152, 219, 0.15);
    transform: translateY(-2px);
}

.file-icon {
    font-size: 2.5rem;
    flex-shrink: 0;
}

.file-info {
    flex: 1;
    min-width: 0;
}

.file-title {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
    word-break: break-word;
}

.file-meta {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    font-size: 0.85rem;
    color: #666;
}

.file-actions {
    flex-shrink: 0;
}

/* No Files Message */
.no-files {
    text-align: center;
    padding: 4rem 2rem;
    color: #666;
}

.no-files-icon {
    font-size: 4rem;
    margin-bottom: 1rem;
}

.no-files h3 {
    font-size: 1.5rem;
    margin-bottom: 1rem;
    color: #333;
}

/* Loading Indicator */
.loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 3rem;
    text-align: center;
}

.loading.hidden {
    display: none;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid #f3f3f3;
    border-top: 4px solid #3498db;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 1rem;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* EPUB Info */
.epub-info {
    background: white;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    padding: 1.5rem;
    margin-bottom: 2rem;
}

.epub-info.hidden {
    display: none;
}

.epub-metadata h3 {
    font-size: 1.4rem;
    margin-bottom: 0.5rem;
    color: #2c3e50;
}

.epub-metadata p {
    color: #666;
    margin-bottom: 0.25rem;
}

/* Chapter List */
.chapter-list {
    background: white;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    overflow: hidden;
}

.chapter-item {
    display: flex;
    align-items: center;
    padding: 1rem 1.5rem;
    border-bottom: 1px solid #f0f0f0;
    transition: background-color 0.2s ease;
}

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

.chapter-item:hover {
    background-color: #f8f9fa;
}

.chapter-item.level-1 {
    padding-left: 2.5rem;
    background-color: #fafbfc;
}

.chapter-item.level-2 {
    padding-left: 3.5rem;
    background-color: #f5f6f7;
}

.chapter-item input[type="checkbox"] {
    margin-right: 1rem;
    transform: scale(1.2);
}

.chapter-label {
    flex: 1;
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
}

.chapter-title {
    font-weight: 500;
    color: #2c3e50;
}

.chapter-meta {
    font-size: 0.85rem;
    color: #666;
}

.no-chapters {
    padding: 2rem;
    text-align: center;
    color: #666;
    font-style: italic;
}

/* Selection Summary */
.selection-summary {
    font-weight: 500;
    color: #2c3e50;
}

/* Export Content */
.export-info {
    background: white;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    padding: 1rem 1.5rem;
    margin-bottom: 2rem;
    text-align: center;
}

.export-content {
    background: white;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    padding: 2rem;
    max-height: 70vh;
    overflow-y: auto;
    line-height: 1.8;
}

.export-document {
    max-width: none;
}

.export-title {
    font-size: 2rem;
    font-weight: 700;
    color: #2c3e50;
    margin-bottom: 0.5rem;
    text-align: center;
}

.export-author {
    font-size: 1.1rem;
    color: #666;
    text-align: center;
    margin-bottom: 2rem;
    font-style: italic;
}

.export-separator {
    border: none;
    border-top: 2px solid #3498db;
    margin: 2rem 0;
}

.export-chapter {
    margin-bottom: 3rem;
}

.export-chapter-title {
    font-size: 1.5rem;
    font-weight: 600;
    color: #2c3e50;
    margin-bottom: 1rem;
    border-bottom: 1px solid #e0e0e0;
    padding-bottom: 0.5rem;
}

.export-chapter-content {
    color: #333;
}

.export-chapter-content h1,
.export-chapter-content h2,
.export-chapter-content h3,
.export-chapter-content h4,
.export-chapter-content h5,
.export-chapter-content h6 {
    margin: 1.5rem 0 1rem 0;
    color: #2c3e50;
}

.export-chapter-content p {
    margin-bottom: 1rem;
}

.export-chapter-content em {
    font-style: italic;
}

.export-chapter-content strong {
    font-weight: 600;
}

.export-chapter-separator {
    border: none;
    border-top: 1px solid #e0e0e0;
    margin: 2rem 0;
}

/* Copy Success Message */
.copy-success {
    position: fixed;
    top: 2rem;
    right: 2rem;
    background: #27ae60;
    color: white;
    padding: 1rem 1.5rem;
    border-radius: 6px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    font-weight: 500;
    z-index: 1000;
    animation: slideIn 0.3s ease;
}

.copy-success.hidden {
    display: none;
}

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

/* Error Section */
.error-section {
    background: #fff5f5;
    border: 1px solid #fed7d7;
    border-radius: 8px;
    margin-top: 2rem;
    overflow: hidden;
}

.error-section.hidden {
    display: none;
}

.error-header {
    padding: 1rem 1.5rem;
    background: #feb2b2;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    user-select: none;
}

.error-header h3 {
    color: #742a2a;
    font-size: 1rem;
    font-weight: 600;
}

.toggle-icon {
    color: #742a2a;
    font-weight: bold;
    transition: transform 0.2s ease;
}

.error-list {
    max-height: 300px;
    overflow-y: auto;
}

.error-list.collapsed {
    display: none;
}

.error-item {
    padding: 1rem 1.5rem;
    border-bottom: 1px solid #fed7d7;
}

.error-item:last-child {
    border-bottom: none;
}

.error-file {
    font-weight: 600;
    color: #742a2a;
    margin-bottom: 0.5rem;
}

.error-message {
    color: #c53030;
    font-size: 0.9rem;
}

/* General Error Message */
.error-message {
    background: #fff5f5;
    border: 1px solid #fed7d7;
    border-radius: 8px;
    padding: 1.5rem;
    text-align: center;
}

.error-message.hidden {
    display: none;
}

.error-message h3 {
    color: #742a2a;
    margin-bottom: 1rem;
}

.error-message p {
    color: #c53030;
}

/* Utility Classes */
.hidden {
    display: none !important;
}

.text-center {
    text-align: center;
}

.text-muted {
    color: #666;
}

/* Responsive Design */
@media (max-width: 768px) {
    .main-content {
        padding: 1rem;
    }
    
    .app-header {
        padding: 1rem;
        flex-direction: column;
        gap: 1rem;
        align-items: stretch;
    }
    
    .header-nav,
    .header-actions {
        justify-content: center;
    }
    
    .app-footer {
        padding: 1rem;
        flex-direction: column;
        gap: 1rem;
        text-align: center;
    }
    
    .file-grid {
        grid-template-columns: 1fr;
        gap: 1rem;
    }
    
    .file-card {
        flex-direction: column;
        text-align: center;
    }
    
    .chapter-item {
        padding: 0.75rem 1rem;
    }
    
    .chapter-item.level-1 {
        padding-left: 1.5rem;
    }
    
    .chapter-item.level-2 {
        padding-left: 2rem;
    }
    
    .export-content {
        padding: 1rem;
        max-height: 60vh;
    }
    
    .export-title {
        font-size: 1.5rem;
    }
    
    .copy-success {
        top: 1rem;
        right: 1rem;
        left: 1rem;
        text-align: center;
    }
}

@media (max-width: 480px) {
    .app-header h1 {
        font-size: 1.4rem;
    }
    
    .app-header h2 {
        font-size: 1.2rem;
    }
    
    .btn {
        padding: 0.4rem 0.8rem;
        font-size: 0.8rem;
    }
    
    .chapter-label {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.25rem;
    }
    
    .export-content {
        padding: 0.75rem;
    }
}
