/* ============================================
   Book Editor - Light Modern Theme
   ============================================ */

:root {
    /* Colors */
    --bg-app: #f5f5f7;
    --bg-sidebar: #ffffff;
    --bg-main: #ffffff;
    --bg-panel: #ffffff;
    --bg-hover: #f0f0f5;
    --bg-active: #eef0ff;
    --bg-toolbar: #ffffff;
    --bg-input: #fafafe;
    --bg-code: #f5f5f7;

    --text-primary: #1d1d1f;
    --text-secondary: #6e6e73;
    --text-muted: #a1a1a6;
    --text-inverse: #ffffff;

    --border-color: #e5e5ea;
    --border-light: #f0f0f5;

    --accent: #5856d6;
    --accent-hover: #4a48c7;
    --accent-light: #eef0ff;
    --accent-text: #5856d6;

    --success: #34c759;
    --success-bg: #eafbf0;
    --warning: #ff9f0a;
    --danger: #ff3b30;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04);
    --shadow-md: 0 2px 8px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 4px 16px rgba(0, 0, 0, 0.08);

    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 14px;

    --sidebar-width: 260px;
    --ai-panel-width: 380px;
    --toolbar-height: 60px;

    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --font-serif: 'Lora', Georgia, 'Times New Roman', serif;
}

/* Reset */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: var(--font-sans);
    background: var(--bg-app);
    color: var(--text-primary);
    min-height: 100vh;
    overflow: hidden;
}

/* ============================================
   Layout
   ============================================ */

.app-layout {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* ============================================
   Sidebar
   ============================================ */

.sidebar {
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: margin-left 0.25s ease;
}

.sidebar.collapsed {
    margin-left: calc(-1 * var(--sidebar-width));
}

.sidebar-header {
    padding: 18px 20px;
    border-bottom: 1px solid var(--border-color);
}

.logo {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 600;
    font-size: 15px;
    color: var(--text-primary);
}

.logo svg {
    color: var(--accent);
}

.sidebar-section {
    flex: 1;
    overflow-y: auto;
    padding: 12px 0;
}

.sidebar-section-title {
    padding: 8px 20px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--text-muted);
}

.chapter-list {
    display: flex;
    flex-direction: column;
    gap: 1px;
}

.chapter-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 20px;
    text-decoration: none;
    color: var(--text-primary);
    font-size: 13px;
    transition: background 0.15s ease;
    cursor: pointer;
}

.chapter-item:hover {
    background: var(--bg-hover);
}

.chapter-item.active {
    background: var(--bg-active);
    color: var(--accent);
    font-weight: 500;
}

.chapter-number {
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
    background: var(--bg-app);
    font-size: 11px;
    font-weight: 600;
    color: var(--text-secondary);
    flex-shrink: 0;
}

.chapter-item.active .chapter-number {
    background: var(--accent);
    color: var(--text-inverse);
}

.chapter-title {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.empty-state-small {
    padding: 20px;
    text-align: center;
    color: var(--text-muted);
    font-size: 13px;
}

/* ============================================
   Main Content
   ============================================ */

.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-width: 0;
}

/* Toolbar */
.toolbar {
    height: var(--toolbar-height);
    min-height: var(--toolbar-height);
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 24px;
    background: var(--bg-toolbar);
    border-bottom: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm);
    z-index: 10;
}

.sidebar-toggle {
    background: none;
    border: none;
    cursor: pointer;
    padding: 6px;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    transition: all 0.15s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.sidebar-toggle:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.toolbar-title {
    flex: 1;
    min-width: 0;
}

.toolbar-title h1 {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.toolbar-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    border: none;
    border-radius: var(--radius-sm);
    font-family: var(--font-sans);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s ease;
    white-space: nowrap;
}

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

.btn-primary {
    background: var(--accent);
    color: var(--text-inverse);
}

.btn-primary:hover:not(:disabled) {
    background: var(--accent-hover);
    box-shadow: var(--shadow-md);
}

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

.btn-secondary:hover:not(:disabled) {
    background: var(--bg-hover);
    border-color: var(--accent);
    color: var(--accent);
}

.btn-full {
    width: 100%;
    justify-content: center;
    padding: 10px 16px;
}

.save-indicator {
    font-size: 12px;
    color: var(--success);
    font-weight: 500;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.save-indicator.visible {
    opacity: 1;
}

/* ============================================
   Editor
   ============================================ */

.editor-container {
    flex: 1;
    overflow: hidden;
    padding: 0;
}

.editor-wrapper {
    height: 100%;
    overflow: auto;
    padding: 32px;
}

.editor-textarea {
    width: 100%;
    min-height: calc(100vh - var(--toolbar-height) - 80px);
    max-width: 780px;
    margin: 0 auto;
    display: block;
    padding: 40px;
    background: var(--bg-main);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    font-family: var(--font-serif);
    font-size: 16px;
    line-height: 1.8;
    color: var(--text-primary);
    resize: none;
    outline: none;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.editor-textarea:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(88, 86, 214, 0.1), var(--shadow-md);
}

/* ============================================
   Empty State
   ============================================ */

.empty-state {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    color: var(--text-muted);
}

.empty-state svg {
    opacity: 0.3;
}

.empty-state h2 {
    font-size: 20px;
    font-weight: 600;
    color: var(--text-secondary);
}

.empty-state p {
    font-size: 14px;
}

/* ============================================
   AI Panel
   ============================================ */

.ai-panel {
    width: var(--ai-panel-width);
    min-width: var(--ai-panel-width);
    background: var(--bg-panel);
    border-left: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: margin-right 0.25s ease, opacity 0.25s ease;
    margin-right: calc(-1 * var(--ai-panel-width));
    opacity: 0;
    pointer-events: none;
}

.ai-panel.open {
    margin-right: 0;
    opacity: 1;
    pointer-events: all;
}

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

.ai-panel-header h2 {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
}

.ai-panel-close {
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    transition: all 0.15s ease;
    display: flex;
    align-items: center;
}

.ai-panel-close:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.ai-panel-body {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.ai-selected-text label,
.ai-instruction-picker label {
    display: block;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    margin-bottom: 8px;
}

.ai-quote {
    background: var(--bg-code);
    border-left: 3px solid var(--accent);
    padding: 12px 14px;
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
    font-family: var(--font-serif);
    font-size: 13px;
    line-height: 1.6;
    color: var(--text-secondary);
    max-height: 120px;
    overflow-y: auto;
    word-break: break-word;
}

.ai-instruction-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.ai-instruction-btn {
    padding: 6px 12px;
    border: 1px solid var(--border-color);
    border-radius: 20px;
    background: var(--bg-main);
    font-family: var(--font-sans);
    font-size: 12px;
    font-weight: 500;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.15s ease;
}

.ai-instruction-btn:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.ai-instruction-btn.active {
    background: var(--accent-light);
    border-color: var(--accent);
    color: var(--accent);
}

.ai-response {
    flex: 1;
    overflow-y: auto;
}

.ai-placeholder {
    padding: 24px 16px;
    text-align: center;
    font-size: 13px;
    color: var(--text-muted);
    line-height: 1.6;
}

.ai-response-content {
    font-size: 13px;
    line-height: 1.7;
    color: var(--text-primary);
    white-space: pre-wrap;
    word-break: break-word;
}

.ai-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 32px 16px;
    color: var(--text-muted);
    font-size: 13px;
}

.ai-loading .spinner {
    width: 18px;
    height: 18px;
    border: 2px solid var(--border-color);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

.ai-error {
    padding: 12px 14px;
    background: #fff5f5;
    border: 1px solid #fecaca;
    border-radius: var(--radius-sm);
    color: var(--danger);
    font-size: 13px;
    line-height: 1.5;
}

/* ============================================
   Scrollbar Styling
   ============================================ */

::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* ============================================
   Responsive
   ============================================ */

@media (max-width: 900px) {
    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        height: 100vh;
        z-index: 100;
        box-shadow: var(--shadow-lg);
    }

    .sidebar.collapsed {
        margin-left: calc(-1 * var(--sidebar-width));
    }

    .ai-panel {
        position: fixed;
        right: 0;
        top: 0;
        height: 100vh;
        z-index: 100;
        box-shadow: var(--shadow-lg);
    }
}
