/* ===== FABULA CSS — Cinematic Dark Theme ===== */
* { margin: 0; padding: 0; box-sizing: border-box; }
:root {
  --bg: #0a0a0c; --bg-card: #13131a; --bg-elevated: #1a1a24;
  --border: #2a2a36; --border-light: #353542;
  --gold: #c9a84c; --gold-light: #e8d48b; --gold-dim: rgba(201,168,76,0.12);
  --cream: #f0ece4; --cream-dim: rgba(240,236,228,0.6);
  --gray: #8a8a96; --gray-dark: #5a5a66;
  --white: #eeeef2; --red: #e85d5d; --green: #5ec96a; --blue: #5b8fd9;
  --page-bg: #faf8f2; --page-text: #1a1a1e;
  --sidebar-w: 260px; --header-h: 56px;
  --radius: 10px; --radius-sm: 6px;
}
html { height: 100%; }
body { font-family: 'Inter', -apple-system, sans-serif; color: var(--cream); background: var(--bg); height: 100%; overflow: hidden; -webkit-font-smoothing: antialiased; }
h1, h2, h3 { font-family: 'Playfair Display', Georgia, serif; font-weight: 600; }
a { color: var(--gold); text-decoration: none; }
button { cursor: pointer; font-family: inherit; }
input, textarea, select { font-family: inherit; }
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ===== AUTH PAGES ===== */
.auth-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 2rem; }
.auth-card { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); padding: 2.5rem; width: 100%; max-width: 420px; }
.auth-card h1 { font-size: 1.8rem; margin-bottom: 0.5rem; color: var(--gold); }
.auth-card p { color: var(--gray); margin-bottom: 1.5rem; font-size: 0.9rem; }
.auth-card .logo { font-family: 'Playfair Display', serif; font-size: 1.1rem; color: var(--gold); letter-spacing: 2px; text-transform: uppercase; margin-bottom: 1.5rem; display: block; }
.form-group { margin-bottom: 1rem; }
.form-group label { display: block; font-size: 0.8rem; color: var(--gray); margin-bottom: 0.4rem; text-transform: uppercase; letter-spacing: 0.5px; }
.form-group input { width: 100%; padding: 0.7rem 1rem; background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-sm); color: var(--cream); font-size: 0.95rem; transition: border 0.2s; }
.form-group input:focus { outline: none; border-color: var(--gold); }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 0.5rem; padding: 0.7rem 1.5rem; border-radius: var(--radius-sm); font-size: 0.9rem; font-weight: 600; border: none; transition: all 0.2s; }
.btn-primary { background: var(--gold); color: #0a0a0c; width: 100%; }
.btn-primary:hover { background: var(--gold-light); }
.btn-secondary { background: var(--bg-elevated); color: var(--cream); border: 1px solid var(--border); }
.btn-secondary:hover { border-color: var(--gold); color: var(--gold); }
.btn-danger { background: rgba(232,93,93,0.15); color: var(--red); border: 1px solid rgba(232,93,93,0.3); }
.btn-danger:hover { background: rgba(232,93,93,0.25); }
.btn-sm { padding: 0.4rem 0.8rem; font-size: 0.8rem; }
.btn-ghost { background: transparent; color: var(--gray); padding: 0.4rem 0.8rem; font-size: 0.8rem; }
.btn-ghost:hover { color: var(--gold); }
.auth-error { background: rgba(232,93,93,0.1); border: 1px solid rgba(232,93,93,0.3); color: var(--red); padding: 0.6rem 1rem; border-radius: var(--radius-sm); font-size: 0.85rem; margin-bottom: 1rem; display: none; }
.auth-error.show { display: block; }
.auth-footer { text-align: center; margin-top: 1.5rem; font-size: 0.85rem; color: var(--gray); }
.auth-footer a { color: var(--gold); }

/* ===== APP LAYOUT ===== */
.app-layout { display: flex; height: 100vh; }
.sidebar { width: var(--sidebar-w); background: var(--bg-card); border-right: 1px solid var(--border); display: flex; flex-direction: column; flex-shrink: 0; overflow: hidden; }
.sidebar-header { padding: 1.2rem 1.5rem; border-bottom: 1px solid var(--border); }
.sidebar-logo { font-family: 'Playfair Display', serif; font-size: 1rem; color: var(--gold); letter-spacing: 2px; text-transform: uppercase; }
.sidebar-nav { flex: 1; padding: 0.5rem 0; overflow-y: auto; }
.nav-item { display: flex; align-items: center; gap: 0.75rem; padding: 0.65rem 1.5rem; color: var(--gray); font-size: 0.85rem; font-weight: 500; cursor: pointer; transition: all 0.15s; border-left: 3px solid transparent; }
.nav-item:hover { color: var(--cream); background: rgba(255,255,255,0.03); }
.nav-item.active { color: var(--gold); border-left-color: var(--gold); background: var(--gold-dim); }
.nav-item svg { width: 18px; height: 18px; flex-shrink: 0; }
.nav-section { padding: 1rem 1.5rem 0.4rem; font-size: 0.7rem; text-transform: uppercase; letter-spacing: 1px; color: var(--gray-dark); }
.sidebar-footer { padding: 1rem 1.5rem; border-top: 1px solid var(--border); }
.user-info { display: flex; align-items: center; gap: 0.75rem; }
.user-avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--gold-dim); color: var(--gold); display: flex; align-items: center; justify-content: center; font-size: 0.8rem; font-weight: 700; flex-shrink: 0; }
.user-name { font-size: 0.85rem; color: var(--cream); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-plan { font-size: 0.7rem; color: var(--gray); }

.main-content { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.main-header { height: var(--header-h); padding: 0 1.5rem; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--border); background: var(--bg); flex-shrink: 0; }
.main-header h2 { font-size: 1.1rem; font-weight: 600; }
.header-actions { display: flex; align-items: center; gap: 0.5rem; }
.main-body { flex: 1; overflow-y: auto; padding: 1.5rem; }

/* ===== LANG TOGGLE ===== */
.lang-toggle { display: flex; background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-sm); overflow: hidden; }
.lang-toggle button { background: none; border: none; color: var(--gray); font-size: 0.75rem; font-weight: 600; padding: 0.3rem 0.6rem; letter-spacing: 1px; cursor: pointer; transition: all 0.15s; }
.lang-toggle button.active { background: var(--gold-dim); color: var(--gold); }

/* ===== DASHBOARD ===== */
.dashboard-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 1rem; }
.project-card { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.5rem; cursor: pointer; transition: all 0.2s; position: relative; }
.project-card:hover { border-color: var(--gold); transform: translateY(-2px); }
.project-card h3 { font-size: 1.1rem; margin-bottom: 0.5rem; color: var(--cream); }
.project-card .logline { font-size: 0.85rem; color: var(--gray); line-height: 1.5; margin-bottom: 1rem; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.project-card .meta { display: flex; gap: 1rem; font-size: 0.75rem; color: var(--gray-dark); }
.project-card .meta span { display: flex; align-items: center; gap: 0.3rem; }
.project-card .badge { position: absolute; top: 1rem; right: 1rem; font-size: 0.65rem; text-transform: uppercase; letter-spacing: 1px; padding: 0.2rem 0.5rem; border-radius: 3px; background: var(--gold-dim); color: var(--gold); }
.new-project-card { border: 2px dashed var(--border); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0.5rem; min-height: 160px; color: var(--gray); }
.new-project-card:hover { border-color: var(--gold); color: var(--gold); }
.new-project-card .plus { font-size: 2rem; line-height: 1; }
.empty-state { text-align: center; padding: 4rem 2rem; }
.empty-state h2 { color: var(--cream); font-size: 1.5rem; margin-bottom: 0.5rem; }
.empty-state p { color: var(--gray); margin-bottom: 1.5rem; }

/* ===== MODAL ===== */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.7); display: flex; align-items: center; justify-content: center; z-index: 1000; }
.modal { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); padding: 2rem; width: 90%; max-width: 500px; max-height: 90vh; overflow-y: auto; }
.modal h2 { font-size: 1.3rem; margin-bottom: 1rem; }
.modal-actions { display: flex; gap: 0.5rem; justify-content: flex-end; margin-top: 1.5rem; }

/* ===== EDITOR ===== */
.editor-container { display: flex; flex-direction: column; height: 100%; }
.editor-toolbar { display: flex; align-items: center; gap: 0.5rem; padding: 0.5rem 1rem; background: var(--bg-card); border-bottom: 1px solid var(--border); flex-shrink: 0; flex-wrap: wrap; }
.element-type-select { background: var(--bg); border: 1px solid var(--border); color: var(--cream); padding: 0.35rem 0.6rem; border-radius: var(--radius-sm); font-size: 0.8rem; font-weight: 600; cursor: pointer; }
.element-type-select:focus { outline: none; border-color: var(--gold); }
.save-status { font-size: 0.75rem; color: var(--gray); margin-left: auto; display: flex; align-items: center; gap: 0.3rem; }
.save-status.saving { color: var(--gold); }
.save-status.saved { color: var(--green); }
.save-status.unsaved { color: var(--red); }
.word-count { font-size: 0.75rem; color: var(--gray-dark); }
.editor-page-wrap { flex: 1; overflow-y: auto; display: flex; justify-content: center; padding: 2rem 1rem; background: #0e0e12; }
.screenplay-page { width: 100%; max-width: 680px; min-height: 800px; background: var(--page-bg); color: var(--page-text); padding: 60px 60px 80px; font-family: 'Courier Prime', 'Courier New', monospace; font-size: 12pt; line-height: 1.5; box-shadow: 0 4px 30px rgba(0,0,0,0.5); border-radius: 2px; }
.sp-element { padding: 2px 4px; min-height: 1.5em; outline: none; border-radius: 2px; transition: background 0.1s; cursor: text; white-space: pre-wrap; word-wrap: break-word; }
.sp-element:focus { background: rgba(201,168,76,0.08); }
.sp-element:empty::before { content: attr(data-placeholder); color: #bbb; font-style: italic; }
.sp-element.sp-scene_heading { text-transform: uppercase; font-weight: bold; margin-top: 1.5em; }
.sp-element.sp-action { margin-top: 0.8em; }
.sp-element.sp-character { text-transform: uppercase; text-align: center; margin-top: 1em; padding-left: 25%; padding-right: 25%; }
.sp-element.sp-dialogue { text-align: center; padding-left: 15%; padding-right: 15%; }
.sp-element.sp-parenthetical { text-align: center; padding-left: 22%; padding-right: 22%; font-style: italic; color: #555; }
.sp-element.sp-transition { text-align: right; text-transform: uppercase; margin-top: 1em; }

/* ===== BEAT SHEET ===== */
.beat-list { display: flex; flex-direction: column; gap: 0.75rem; max-width: 800px; }
.beat-card { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem 1.2rem; cursor: grab; transition: all 0.2s; }
.beat-card:hover { border-color: var(--gold-dim); }
.beat-card.editing { border-color: var(--gold); }
.beat-card .beat-header { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; margin-bottom: 0.3rem; }
.beat-card .beat-title { font-weight: 600; font-size: 0.95rem; color: var(--cream); }
.beat-card .beat-act { font-size: 0.7rem; text-transform: uppercase; letter-spacing: 1px; padding: 0.15rem 0.5rem; border-radius: 3px; font-weight: 600; }
.beat-act.act-1 { background: rgba(94,201,106,0.15); color: var(--green); }
.beat-act.act-2 { background: rgba(91,143,217,0.15); color: var(--blue); }
.beat-act.act-3 { background: rgba(201,168,76,0.15); color: var(--gold); }
.beat-card .beat-desc { font-size: 0.85rem; color: var(--gray); line-height: 1.5; }
.beat-card .beat-page { font-size: 0.7rem; color: var(--gray-dark); margin-top: 0.5rem; }
.beat-card .beat-actions { display: flex; gap: 0.3rem; }
.beat-template-selector { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-bottom: 1rem; }
.template-btn { background: var(--bg-card); border: 1px solid var(--border); color: var(--cream); padding: 0.5rem 1rem; border-radius: var(--radius-sm); font-size: 0.85rem; cursor: pointer; transition: all 0.2s; }
.template-btn:hover { border-color: var(--gold); color: var(--gold); }

/* ===== CHARACTER ARCS ===== */
.character-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(350px, 1fr)); gap: 1rem; max-width: 1200px; }
.character-card { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.2rem; transition: all 0.2s; }
.character-card:hover { border-color: var(--border-light); }
.character-card h3 { font-size: 1.05rem; margin-bottom: 0.2rem; color: var(--cream); }
.character-card .char-role { font-size: 0.8rem; color: var(--gold); text-transform: uppercase; letter-spacing: 1px; margin-bottom: 0.8rem; }
.character-card .arc-field { margin-bottom: 0.5rem; }
.arc-field label { font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.5px; color: var(--gray-dark); display: block; margin-bottom: 0.2rem; }
.arc-field textarea { width: 100%; padding: 0.4rem 0.6rem; background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-sm); color: var(--cream); font-size: 0.85rem; resize: vertical; min-height: 50px; line-height: 1.4; }
.arc-field textarea:focus { outline: none; border-color: var(--gold); }
.arc-field input[type="text"] { width: 100%; padding: 0.4rem 0.6rem; background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-sm); color: var(--cream); font-size: 0.85rem; }
.arc-field input:focus { outline: none; border-color: var(--gold); }
.character-card .card-actions { display: flex; gap: 0.3rem; justify-content: flex-end; margin-top: 0.75rem; }
.add-character-card { border: 2px dashed var(--border); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0.5rem; min-height: 200px; color: var(--gray); cursor: pointer; border-radius: var(--radius); transition: all 0.2s; }
.add-character-card:hover { border-color: var(--gold); color: var(--gold); }

/* ===== UPGRADE BANNER ===== */
.upgrade-banner { background: linear-gradient(135deg, rgba(201,168,76,0.1), rgba(201,168,76,0.05)); border: 1px solid rgba(201,168,76,0.3); border-radius: var(--radius); padding: 1.2rem 1.5rem; display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1rem; }
.upgrade-banner p { color: var(--cream); font-size: 0.9rem; }
.upgrade-banner .price { color: var(--gold); font-weight: 700; }

/* ===== RESPONSIVE ===== */
@media (max-width: 768px) {
  .sidebar { display: none; }
  .main-body { padding: 1rem; }
  .screenplay-page { padding: 30px 20px 40px; }
  .sp-element.sp-character { padding-left: 10%; padding-right: 10%; }
  .sp-element.sp-dialogue { padding-left: 5%; padding-right: 5%; }
  .sp-element.sp-parenthetical { padding-left: 10%; padding-right: 10%; }
  .dashboard-grid { grid-template-columns: 1fr; }
  .character-grid { grid-template-columns: 1fr; }
  .mobile-header { display: flex !important; }
}

.mobile-header { display: none; padding: 0.75rem 1rem; background: var(--bg-card); border-bottom: 1px solid var(--border); align-items: center; justify-content: space-between; flex-shrink: 0; height: 48px; }
.mobile-header-logo { font-family: 'Playfair Display', serif; font-size: 1rem; color: var(--gold); letter-spacing: 2px; text-transform: uppercase; }
.mobile-menu-btn { background: none; border: none; color: var(--cream); cursor: pointer; padding: 0.25rem; display: flex; align-items: center; justify-content: center; border-radius: var(--radius-sm); transition: color 0.15s; }
.mobile-menu-btn:hover { color: var(--gold); }
.mobile-menu-btn svg { width: 22px; height: 22px; }

/* ===== MOBILE MENU DRAWER ===== */
.mobile-menu-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.72); z-index: 200; }
.mobile-menu-overlay.open { display: block; }
.mobile-menu-drawer { position: fixed; top: 0; left: 0; bottom: 0; width: 280px; background: var(--bg-card); border-right: 1px solid var(--border); z-index: 201; transform: translateX(-100%); transition: transform 0.25s cubic-bezier(0.4,0,0.2,1); display: flex; flex-direction: column; overflow: hidden; }
.mobile-menu-drawer.open { transform: translateX(0); }
.mobile-drawer-header { padding: 1rem 1.5rem; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; flex-shrink: 0; height: 56px; }
.mobile-drawer-close { background: none; border: none; color: var(--gray); cursor: pointer; padding: 0.3rem; display: flex; align-items: center; justify-content: center; border-radius: var(--radius-sm); transition: color 0.15s; }
.mobile-drawer-close:hover { color: var(--cream); }
.mobile-drawer-close svg { width: 20px; height: 20px; }
.mobile-drawer-nav { flex: 1; padding: 0.5rem 0; overflow-y: auto; }
.mobile-drawer-footer { padding: 1rem 1.5rem; border-top: 1px solid var(--border); flex-shrink: 0; }

/* ===== RAW NOTES ===== */
.notes-helper-bar { display: flex; align-items: center; justify-content: space-between; padding: 0.5rem 1rem; background: var(--bg-card); border-bottom: 1px solid var(--border); flex-shrink: 0; }
.notes-helper-text { font-size: 0.8rem; color: var(--gray); display: flex; align-items: center; gap: 0.4rem; }
.notes-helper-text svg { width: 14px; height: 14px; color: var(--gold); }
.notes-layout { flex: 1; display: flex; overflow: hidden; min-height: 0; }
.notes-editor-pane { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.notes-textarea {
  flex: 1; width: 100%; border: none; outline: none; resize: none;
  background: var(--bg); color: var(--cream); font-family: 'Inter', sans-serif;
  font-size: 0.95rem; line-height: 1.7; padding: 1.5rem 2rem;
  overflow-y: auto;
}
.notes-textarea::placeholder { color: var(--gray-dark); font-style: italic; }
.notes-suggestions-pane {
  width: 420px; flex-shrink: 0; background: var(--bg-card); border-left: 1px solid var(--border);
  display: flex; flex-direction: column; overflow-y: auto; padding: 1rem;
}
.suggestions-empty { text-align: center; padding: 2rem; color: var(--gray); font-size: 0.9rem; }
.analysis-summary { font-size: 0.85rem; color: var(--cream-dim); margin-bottom: 1rem; padding: 0.75rem; background: var(--gold-dim); border-radius: var(--radius-sm); border: 1px solid rgba(201,168,76,0.2); line-height: 1.5; }
.suggestion-section { margin-bottom: 1.2rem; }
.suggestion-section h3 { font-size: 0.85rem; color: var(--gold); margin-bottom: 0.6rem; display: flex; align-items: center; gap: 0.4rem; font-family: 'Inter', sans-serif; font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px; }
.suggestion-section h3 svg { width: 16px; height: 16px; }
.suggestion-card {
  background: var(--bg-elevated); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 0.75rem; margin-bottom: 0.5rem; transition: all 0.2s;
}
.suggestion-card:hover { border-color: var(--border-light); }
.sugg-header { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.sugg-badge { font-size: 0.65rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px; padding: 0.15rem 0.4rem; border-radius: 3px; }
.sugg-new { background: rgba(94,201,106,0.15); color: var(--green); }
.sugg-update { background: rgba(91,143,217,0.15); color: var(--blue); }
.sugg-title { font-weight: 600; font-size: 0.9rem; color: var(--cream); flex: 1; min-width: 0; }
.sugg-role { font-size: 0.75rem; color: var(--gold); text-transform: uppercase; letter-spacing: 0.5px; }
.sugg-actions { display: flex; gap: 0.2rem; margin-left: auto; flex-shrink: 0; }
.sugg-btn { background: none; border: 1px solid var(--border); color: var(--gray); padding: 0.2rem; border-radius: 4px; display: flex; align-items: center; justify-content: center; width: 26px; height: 26px; cursor: pointer; transition: all 0.15s; }
.sugg-btn svg { width: 14px; height: 14px; }
.sugg-btn.sugg-accept.active { background: rgba(94,201,106,0.2); border-color: rgba(94,201,106,0.4); color: var(--green); }
.sugg-btn.sugg-reject.active { background: rgba(232,93,93,0.2); border-color: rgba(232,93,93,0.4); color: var(--red); }
.sugg-desc { font-size: 0.82rem; color: var(--cream-dim); margin-top: 0.4rem; line-height: 1.4; }
.sugg-fields { font-size: 0.8rem; color: var(--cream-dim); margin-top: 0.4rem; line-height: 1.6; }
.sugg-fields b { color: var(--gray); font-weight: 500; font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.3px; }
.sugg-meta { font-size: 0.72rem; color: var(--gray-dark); margin-top: 0.3rem; }
.sugg-source { font-size: 0.75rem; color: var(--gray); margin-top: 0.4rem; font-style: italic; border-left: 2px solid var(--border); padding-left: 0.5rem; }
.sugg-source-label { font-style: normal; color: var(--gray-dark); font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.3px; }
.suggestions-actions { display: flex; gap: 0.5rem; padding: 0.75rem 0; border-top: 1px solid var(--border); margin-top: 0.5rem; flex-wrap: wrap; }
.suggestions-actions .btn { flex: 1; min-width: 80px; }

@media (max-width: 768px) {
  .notes-layout { flex-direction: column; }
  .notes-suggestions-pane { width: 100%; border-left: none; border-top: 1px solid var(--border); max-height: 50vh; }
  .notes-textarea { padding: 1rem; }
}

/* ===== ANIMATIONS ===== */
@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
.fade-in { animation: fadeIn 0.3s ease-out; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.5; } }
.pulse { animation: pulse 1.5s ease-in-out infinite; }

/* ===== TOAST ===== */
.toast { position: fixed; bottom: 2rem; right: 2rem; background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); padding: 0.8rem 1.2rem; font-size: 0.85rem; color: var(--cream); z-index: 2000; animation: fadeIn 0.3s ease-out; }
.toast.success { border-color: var(--green); }
.toast.error { border-color: var(--red); }
