@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');
@import url('https://fonts.googleapis.com/css2?family=Merriweather:ital,wght@0,300;0,400;0,700;1,400&display=swap');
@import url('https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;500&display=swap');

:root {
    --primary: #4f46e5;
    --primary-hover: #4338ca;
    --bg-body: #f3f4f6;
    --bg-card: #ffffff;
    --text-main: #1f2937;
    --text-muted: #6b7280;
    --border: #e5e7eb;
    --sidebar-bg: #ffffff;
    --sidebar-text: #4b5563;
    --sidebar-active-bg: #eff6ff;
    --sidebar-active-text: #2563eb;
    --danger: #ef4444;
    --success: #10b981;
    --font-ui: 'Inter', sans-serif;
    --font-editor: 'Inter', sans-serif;
    --font-book: 'Merriweather', serif;
    --font-mono: 'JetBrains Mono', monospace;
}

body.dark {
    --primary: #6366f1;
    --primary-hover: #818cf8;
    --bg-body: #111827;
    --bg-card: #1f2937;
    --text-main: #f3f4f6;
    --text-muted: #9ca3af;
    --border: #374151;
    --sidebar-bg: #1f2937;
    --sidebar-text: #d1d5db;
    --sidebar-active-bg: #374151;
    --sidebar-active-text: #fff;
}

body {
    font-family: var(--font-ui);
    margin: 0;
    min-height: 100vh;
    background: var(--bg-body);
    color: var(--text-main);
    display: flex;
    transition: background 0.3s, color 0.3s;
}

/* AUTH PAGES */
body.auth-page { display: flex; justify-content: center; align-items: center; height: 100vh; width: 100vw; }
.auth-card { background: var(--bg-card); padding: 40px; border-radius: 16px; box-shadow: 0 10px 40px -10px rgba(0,0,0,0.1); width: 100%; max-width: 400px; text-align: center; border: 1px solid var(--border); }
.auth-card h2 { margin-bottom: 30px; font-weight: 700; color: var(--text-main); }
.auth-card input { width: 100%; padding: 12px 16px; margin-bottom: 16px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg-body); color: var(--text-main); box-sizing: border-box; }
.auth-card button { width: 100%; padding: 12px; font-weight: 600; background: var(--primary); color: white; border: none; border-radius: 8px; cursor: pointer; }

/* SIDEBAR */
#sidebar { width: 260px; background: var(--sidebar-bg); border-right: 1px solid var(--border); padding: 24px; display: flex; flex-direction: column; gap: 8px; flex-shrink: 0; z-index: 10; }
#sidebar .brand { font-size: 1.25rem; font-weight: 800; color: var(--text-main); display: flex; align-items: center; gap: 10px; margin-bottom: 24px; padding-left: 12px; }
#sidebar button.nav-item { background: transparent; border: none; color: var(--sidebar-text); padding: 12px; text-align: left; border-radius: 8px; font-weight: 500; cursor: pointer; display: flex; align-items: center; gap: 12px; font-size: 0.95rem; width: 100%; }
#sidebar button.nav-item:hover { background: var(--bg-body); color: var(--text-main); }
#sidebar button.nav-item.active { background: var(--sidebar-active-bg); color: var(--sidebar-active-text); }
.logout-btn { margin-top: auto; color: var(--danger) !important; }

#main { flex: 1; padding: 32px; height: 100vh; overflow-y: auto; box-sizing: border-box; }

/* CARDS */
.book-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 24px; }
.card { background: var(--bg-card); border: 1px solid var(--border); border-radius: 12px; padding: 24px; transition: 0.2s; display: flex; flex-direction: column; height: 100%; box-sizing: border-box; }
.card:hover { transform: translateY(-4px); box-shadow: 0 12px 30px -10px rgba(0,0,0,0.08); border-color: var(--primary); }
.card h3 { margin: 0 0 8px 0; font-size: 1.1rem; color: var(--text-main); }
.card .meta { font-size: 0.85rem; color: var(--text-muted); margin-bottom: 20px; }

/* BUTTONS */
.btn { padding: 8px 16px; border-radius: 6px; font-weight: 500; font-size: 0.9rem; border: none; cursor: pointer; transition: 0.2s; display: inline-flex; align-items: center; gap: 8px; }
.btn-primary { background: var(--primary); color: white; }
.btn-outline { background: transparent; border: 1px solid var(--border); color: var(--text-main); }
.btn-outline:hover { background: var(--bg-body); }
.btn-danger-ghost { background: transparent; color: var(--danger); padding: 8px; }

/* EDITOR AREA */
.editor-layout { display: flex; height: 100%; gap: 32px; }
.chapter-sidebar { width: 240px; flex-shrink: 0; display: flex; flex-direction: column; }
.chapter-list { flex: 1; overflow-y: auto; padding-right: 8px; margin-top: 16px; }
.chapter-item { padding: 10px 12px; border-radius: 6px; margin-bottom: 4px; cursor: pointer; font-size: 0.9rem; color: var(--text-muted); display: flex; justify-content: space-between; align-items: center; }
.chapter-item:hover { background: var(--bg-body); color: var(--text-main); }
.chapter-item.active { background: var(--sidebar-active-bg); color: var(--sidebar-active-text); font-weight: 600; }

#main-editor-area { flex: 1; display: flex; flex-direction: column; max-width: 800px; margin: 0 auto; width: 100%; }

/* FONT LOGIC */
input#chap-title {
    font-family: var(--font-editor);
    font-size: 2rem; font-weight: 700;
    border: none; background: transparent;
    color: var(--text-main);
    padding: 10px 0; margin-bottom: 20px;
    width: 100%; outline: none;
}
textarea#raw-editor {
    flex: 1;
    font-family: var(--font-editor);
    font-size: 1.1rem; line-height: 1.6;
    color: var(--text-main);
    border: none; background: transparent;
    resize: none; outline: none; padding: 0;
}

#preview-pane { 
    display: none; 
    font-family: var(--font-book);
    line-height: 1.8; 
    color: var(--text-main); 
    overflow-y: auto;
    font-size: 1.1rem;
}
#preview-pane h1, #preview-pane h2, #preview-pane h3 { font-family: var(--font-ui); font-weight: 700; margin-top: 1.5em; }
#preview-pane p { margin-bottom: 1.2em; text-align: justify; }
#preview-pane.show { display: block; height: 100%; }

.view { display: none; height: 100%; flex-direction: column; }
.view.active { display: flex; }