/* Reset and base styles */
* { 
    margin: 0; 
    padding: 0; 
    box-sizing: border-box; 
}

body { 
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; 
    background: #f5f7fa; 
    color: #333; 
    height: 100vh;
    overflow: hidden;
}

/* Header */
.app-header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 1rem 2rem;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    max-width: 1800px;
    margin: 0 auto;
}

.header-content h1 {
    font-size: 1.5rem;
    font-weight: 600;
}

.project-controls {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.project-controls select {
    min-width: 250px;
}

.project-controls span {
    font-size: 0.9rem;
    opacity: 0.9;
}

/* Main three-panel layout */
.app-layout {
    display: grid;
    grid-template-columns: 320px 1fr 350px;
    height: calc(100vh - 80px); /* Account for header */
    gap: 0;
    background: #f5f7fa;
}

/* Left sidebar */
.sidebar {
    background: white;
    border-right: 1px solid #e1e5e9;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.sidebar-header {
    padding: 1.5rem;
    border-bottom: 1px solid #e1e5e9;
}

.sidebar-header h3 {
    margin-bottom: 1rem;
    color: #333;
    font-size: 1.1rem;
}

.structure-tree {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
}

.sidebar-stats {
    padding: 1rem 1.5rem;
    border-top: 1px solid #e1e5e9;
    background: #f8f9fa;
}

.stat-item {
    display: flex;
    justify-content: space-between;
    margin-bottom: 0.5rem;
    font-size: 0.9rem;
}

.stat-label {
    color: #666;
}

/* Center editor panel */
.editor-panel {
    background: white;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.editor-toolbar {
    padding: 1rem 1.5rem;
    border-bottom: 1px solid #e1e5e9;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #f8f9fa;
}

.toolbar-section {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.content-area {
    flex: 1;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.content-preview {
    flex: 1;
    padding: 1.5rem;
    overflow-y: auto;
    border: none;
    background: white;
}

.content-editor {
    flex: 1;
    padding: 1.5rem;
    border: none;
    background: white;
    font-family: ui-serif, Georgia, Cambria, serif;
    font-size: 1rem;
    line-height: 1.6;
    resize: none;
    outline: none;
}

/* Right contextual panel */
.contextual-panel {
    background: white;
    border-left: 1px solid #e1e5e9;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.panel-tabs {
    display: flex;
    border-bottom: 1px solid #e1e5e9;
    background: #f8f9fa;
}

.tab-btn {
    flex: 1;
    padding: 0.75rem 0.5rem;
    border: none;
    background: none;
    cursor: pointer;
    font-size: 0.85rem;
    color: #666;
    transition: all 0.3s ease;
    border-bottom: 3px solid transparent;
}

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

.tab-content {
    display: none;
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
}

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

.panel-section {
    margin-bottom: 1.5rem;
}

.panel-section h4 {
    margin-bottom: 0.75rem;
    color: #333;
    font-size: 0.95rem;
    border-bottom: 1px solid #e1e5e9;
    padding-bottom: 0.5rem;
}

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

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 600;
    color: #333;
    font-size: 0.9rem;
}

.form-control {
    width: 100%;
    padding: 0.5rem;
    border: 1px solid #e1e5e9;
    border-radius: 6px;
    font-size: 0.9rem;
    transition: border-color 0.3s ease;
}

.form-control:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 2px rgba(102, 126, 234, 0.1);
}

textarea.form-control {
    resize: vertical;
    min-height: 80px;
}

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

.btn-sm {
    padding: 0.25rem 0.75rem;
    font-size: 0.85rem;
}

.btn-block {
    width: 100%;
    justify-content: center;
}

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

.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

.btn-secondary {
    background: #6c757d;
    color: white;
}

.btn-secondary:hover {
    background: #5a6268;
}

.btn-success {
    background: #28a745;
    color: white;
}

.btn-success:hover {
    background: #218838;
}

.btn-danger {
    background: #dc3545;
    color: white;
}

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

/* Project structure navigation */
.chapter-item {
    margin-bottom: 0.5rem;
}

.chapter-title {
    font-weight: 600;
    color: #333;
    padding: 0.5rem;
    background: #f8f9fa;
    border-radius: 4px;
    border-left: 4px solid #667eea;
    cursor: pointer;
}

.subchapter-list {
    margin-left: 1rem;
    margin-top: 0.5rem;
}

.subchapter-item, .summary-item {
    padding: 0.35rem 0.75rem;
    margin-bottom: 0.25rem;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.3s ease;
    font-size: 0.9rem;
    color: #666;
    border-left: 3px solid transparent;
}

.subchapter-item:hover, .summary-item:hover {
    background: #f0f0f0;
    color: #333;
}

.subchapter-item.completed, .summary-item.completed {
    color: #28a745;
    border-left-color: #28a745;
    font-weight: 500;
}

.subchapter-item.approved::before {
    content: '✅ ';
}

.subchapter-item.active, .summary-item.active {
    background: #e8eaf6;
    color: #667eea;
    border-left-color: #667eea;
    font-weight: 600;
}

.summary-item {
    font-style: italic;
    color: #8a6d3b;
}

.summary-item.completed {
    font-style: normal;
    color: #28a745;
}

.summary-item.completed::before {
    content: '📋 ';
}

/* Progress bar */
.progress-bar {
    width: 100%;
    height: 8px;
    background: #e1e5e9;
    border-radius: 4px;
    overflow: hidden;
    margin: 0.5rem 0;
}

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

/* Quality check */
.quality-check {
    background: #f8f9fa;
    border: 1px solid #e1e5e9;
    border-radius: 6px;
    padding: 1rem;
}

.quality-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.4rem 0;
    border-bottom: 1px solid #eee;
    font-size: 0.9rem;
}

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

.validation-output {
    background: #f8f9fa;
    border: 1px solid #e1e5e9;
    border-radius: 6px;
    padding: 1rem;
    font-size: 0.9rem;
}

/* Loading spinner */
.loading {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid #f3f3f3;
    border-top: 2px solid #667eea;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

/* Status bar */
.status-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(255, 255, 255, 0.95);
    padding: 0.5rem 1rem;
    border-top: 1px solid #e1e5e9;
    font-size: 0.85rem;
    color: #666;
    backdrop-filter: blur(5px);
    z-index: 50;
}

/* Content preview styling */
.content-preview h1,
.content-preview h2,
.content-preview h3,
.content-preview h4,
.content-preview h5,
.content-preview h6 {
    margin-top: 1.5rem;
    margin-bottom: 0.75rem;
    color: #333;
}

.content-preview h3 {
    color: #667eea;
    border-bottom: 2px solid #e1e5e9;
    padding-bottom: 0.5rem;
}

.content-preview p {
    margin-bottom: 1rem;
    line-height: 1.6;
}

.content-preview ul,
.content-preview ol {
    margin-bottom: 1rem;
    padding-left: 2rem;
}

.content-preview blockquote {
    border-left: 4px solid #667eea;
    padding-left: 1rem;
    margin: 1rem 0;
    font-style: italic;
    color: #666;
}

.content-preview code {
    background: #f1f3f4;
    padding: 0.2rem 0.4rem;
    border-radius: 3px;
    font-family: 'Courier New', monospace;
    font-size: 0.9em;
}

/* Responsive design */
@media (max-width: 1200px) {
    .app-layout {
        grid-template-columns: 280px 1fr 300px;
    }
}

@media (max-width: 900px) {
    .app-layout {
        grid-template-columns: 1fr;
        grid-template-rows: auto 1fr auto;
    }
    
    .sidebar,
    .contextual-panel {
        display: none; /* Hide side panels on mobile - can be toggled */
    }
    
    .editor-panel {
        grid-row: 1 / -1;
    }
}

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

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

.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }