/* ============================================================
   FONTS — ThmanyahSans (same as حياتي)
============================================================ */

@font-face {
  font-family: 'ThmanyahSans';
  src: url('thmanyahsans-Regular.woff2') format('woff2');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'ThmanyahSans';
  src: url('thmanyahsans-Medium.woff2') format('woff2');
  font-weight: 500;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'ThmanyahSans';
  src: url('thmanyahsans-Bold.woff2') format('woff2');
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'ThmanyahSans';
  src: url('thmanyahsans-Black.woff2') format('woff2');
  font-weight: 900;
  font-style: normal;
  font-display: swap;
}

/* ============================================================
   VARIABLES
============================================================ */

:root {
  /* Sidebar (dark — matches حياتي exactly) */
  --sidebar-bg:       #0f172a;
  --sidebar-border:   rgba(71, 85, 105, 0.5);
  --nav-text:         #94a3b8;
  --nav-hover-bg:     #1e293b;
  --nav-active-bg:    #ea580c;
  --nav-active-text:  #ffffff;
  --logo-sub:         #64748b;

  /* Main area (light — matches حياتي) */
  --bg-main:    #f8fafc;
  --bg-card:    #ffffff;
  --bg-input:   #f1f5f9;
  --bg-header:  #ffffff;

  /* Borders */
  --border:       #e2e8f0;
  --border-light: rgba(226, 232, 240, 0.7);

  /* Text */
  --text-primary:   #0f172a;
  --text-secondary: #475569;
  --text-muted:     #94a3b8;

  /* Accent — orange like حياتي */
  --accent:       #ea580c;
  --accent-hover: #c2410c;
  --accent-dim:   rgba(234, 88, 12, 0.1);
  --accent-light: #fff7ed;

  /* Semantic colors */
  --emerald:     #059669;
  --emerald-bg:  #d1fae5;
  --emerald-text:#065f46;
  --amber:       #d97706;
  --amber-bg:    #fef3c7;
  --amber-text:  #92400e;
  --violet:      #7c3aed;
  --violet-bg:   #ede9fe;
  --violet-text: #4c1d95;
  --blue:        #2563eb;
  --blue-bg:     #dbeafe;
  --blue-text:   #1e3a5f;
  --rose:        #e11d48;
  --rose-bg:     #ffe4e6;
  --rose-text:   #881337;

  --success:  #059669;
  --danger:   #dc2626;
  --danger-bg:#fee2e2;

  /* Dimensions */
  --sidebar-w:      224px;
  --chapter-list-w: 256px;
  --radius-xl:      16px;
  --radius:         12px;
  --radius-sm:      8px;
  --radius-xs:      6px;

  --shadow-sm: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --shadow:    0 4px 16px rgba(0,0,0,0.08), 0 2px 4px rgba(0,0,0,0.04);
  --shadow-lg: 0 10px 40px rgba(0,0,0,0.12), 0 4px 8px rgba(0,0,0,0.06);
}

/* ============================================================
   RESET & BASE
============================================================ */

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

html, body {
  height: 100%;
  font-family: 'ThmanyahSans', sans-serif;
  background: var(--bg-main);
  color: var(--text-primary);
  direction: rtl;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

ul { list-style: none; }
button { font-family: 'ThmanyahSans', sans-serif; cursor: pointer; }
input, select, textarea { font-family: 'ThmanyahSans', sans-serif; }

/* Lucide icons */
i[data-lucide] svg, svg.lucide { display: block; }

/* ============================================================
   APP LAYOUT
============================================================ */

#app {
  display: flex;
  height: 100vh;
  /* RTL: sidebar (first child) → right side */
}

/* ============================================================
   SIDEBAR  (matches حياتي exactly)
============================================================ */

#sidebar {
  width: var(--sidebar-w);
  background: var(--sidebar-bg);
  border-left: 1px solid var(--sidebar-border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 18px 16px 16px;
  border-bottom: 1px solid var(--sidebar-border);
}

.logo-icon-wrap {
  width: 32px;
  height: 32px;
  background: var(--accent);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: white;
}

.logo-icon-wrap svg { width: 16px; height: 16px; }

.logo-title {
  display: block;
  font-size: 14px;
  font-weight: 700;
  color: #ffffff;
  line-height: 1;
}

.logo-sub {
  display: block;
  font-size: 11px;
  color: var(--logo-sub);
  margin-top: 2px;
}

.nav-links {
  flex: 1;
  padding: 10px 10px 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
  overflow-y: auto;
}

.nav-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 9px 12px;
  background: none;
  border: none;
  color: var(--nav-text);
  font-size: 13px;
  font-weight: 500;
  text-align: right;
  direction: rtl;
  border-radius: var(--radius-sm);
  transition: background 0.15s, color 0.15s;
}

.nav-btn svg { width: 16px; height: 16px; flex-shrink: 0; }

.nav-btn:hover {
  background: var(--nav-hover-bg);
  color: #ffffff;
}

.nav-btn.active {
  background: var(--nav-active-bg);
  color: var(--nav-active-text);
  font-weight: 600;
}

.sidebar-footer {
  border-top: 1px solid var(--sidebar-border);
  padding: 8px 10px;
}

/* ============================================================
   MAIN CONTENT
============================================================ */

#main-content {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  background: var(--bg-main);
  min-width: 0;
}

.section {
  display: none;
  flex: 1;
  overflow: hidden;
  flex-direction: column;
}
.section.active { display: flex; }

/* ============================================================
   SECTION HEADER (shared)
============================================================ */

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-header);
  flex-shrink: 0;
}

.section-header h2 {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-primary);
}

/* ============================================================
   DASHBOARD
============================================================ */

#dashboard { overflow-y: auto; }

.dashboard-hero {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 24px 24px 20px;
  background: var(--bg-header);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.hero-text h1 {
  font-size: 28px;
  font-weight: 900;
  color: var(--text-primary);
  line-height: 1.2;
  margin-bottom: 8px;
}

.hero-meta { display: flex; gap: 8px; flex-wrap: wrap; }

.hero-badge {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  background: var(--bg-input);
  padding: 3px 10px;
  border-radius: 99px;
  border: 1px solid var(--border);
}
.hero-badge:empty { display: none; }
.hero-badge.accent {
  background: var(--accent-dim);
  color: var(--accent);
  border-color: rgba(234,88,12,0.2);
}

/* Stats */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  padding: 20px 24px;
  flex-shrink: 0;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-xl);
  padding: 18px 16px;
  display: flex;
  align-items: center;
  gap: 14px;
  box-shadow: var(--shadow-sm);
  transition: box-shadow 0.2s, transform 0.2s;
}
.stat-card:hover { box-shadow: var(--shadow); transform: translateY(-1px); }

.stat-icon-wrap {
  width: 42px;
  height: 42px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.stat-icon-wrap svg { width: 20px; height: 20px; }

.stat-icon-wrap.orange  { background: #fff7ed; color: #ea580c; }
.stat-icon-wrap.emerald { background: #d1fae5; color: #059669; }
.stat-icon-wrap.violet  { background: #ede9fe; color: #7c3aed; }
.stat-icon-wrap.amber   { background: #fef3c7; color: #d97706; }

.stat-number {
  font-size: 24px;
  font-weight: 900;
  line-height: 1;
  margin-bottom: 2px;
}
.stat-number.orange  { color: #ea580c; }
.stat-number.emerald { color: #059669; }
.stat-number.violet  { color: #7c3aed; }
.stat-number.amber   { color: #d97706; }

.stat-label { font-size: 12px; color: var(--text-muted); font-weight: 500; }

/* Dashboard grid */
.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  padding: 0 24px 24px;
}

.dashboard-card {
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-xl);
  padding: 18px;
  box-shadow: var(--shadow-sm);
}

.dashboard-card.span-2 { grid-column: span 2; }

.card-header {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 13px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.4px;
  margin-bottom: 14px;
}
.card-header svg { width: 14px; height: 14px; }

.synopsis-text {
  font-size: 14px;
  line-height: 1.8;
  color: var(--text-secondary);
}

.empty-hint { color: var(--text-muted); font-size: 13px; font-style: italic; }

/* Recent list */
.recent-list { display: flex; flex-direction: column; gap: 4px; }

.recent-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 13px;
  color: var(--text-secondary);
  transition: background 0.12s;
}
.recent-item:hover { background: var(--bg-input); color: var(--text-primary); }

.status-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  flex-shrink: 0;
}
.status-dot.status-draft   { background: var(--text-muted); }
.status-dot.status-writing { background: var(--amber); }
.status-dot.status-complete{ background: var(--emerald); }

.recent-words { margin-right: auto; font-size: 11px; color: var(--text-muted); }

/* Chars & events preview */
.chars-preview, .events-preview { display: flex; flex-direction: column; gap: 6px; }

.char-mini {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 8px;
  background: var(--bg-input);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.12s;
}
.char-mini:hover { background: #e2e8f0; }

.char-mini-avatar {
  width: 28px; height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 900;
  flex-shrink: 0;
}

.char-mini-name { font-size: 13px; font-weight: 600; }
.char-mini-role { font-size: 11px; color: var(--text-muted); }

.event-mini {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-secondary);
  padding: 5px 0;
  border-bottom: 1px solid var(--border);
}
.event-mini:last-child { border: none; }
.event-type-dot { width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0; }

/* ============================================================
   CHAPTERS
============================================================ */

#chapters { overflow: hidden; }

.chapters-layout {
  display: flex;
  height: 100%;
}

/* Chapter list panel */
.chapters-sidebar {
  width: var(--chapter-list-w);
  background: var(--bg-header);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.chapters-sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 14px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.chapters-sidebar-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-primary);
}

.chapters-sidebar-body { flex: 1; overflow-y: auto; padding: 6px 0; }

.chapters-nav-list {}

.empty-hint-pad {
  padding: 16px;
  color: var(--text-muted);
  font-size: 13px;
  font-style: italic;
}

.chapter-item { padding: 2px 8px; cursor: pointer; }

.chapter-item-inner {
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  display: flex;
  flex-direction: column;
  gap: 3px;
  transition: background 0.12s;
}
.chapter-item:hover .chapter-item-inner { background: var(--bg-input); }
.chapter-item.active .chapter-item-inner {
  background: var(--accent-dim);
  border: 1px solid rgba(234,88,12,0.15);
}

.chapter-num { font-size: 10px; color: var(--text-muted); letter-spacing: 0.3px; }
.chapter-title-preview {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chapter-status-badge {
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 99px;
  width: fit-content;
  font-weight: 600;
}
.chapter-status-badge.status-draft    { background:#f1f5f9; color:var(--text-muted); }
.chapter-status-badge.status-writing  { background:var(--amber-bg); color:var(--amber-text); }
.chapter-status-badge.status-complete { background:var(--emerald-bg); color:var(--emerald-text); }

/* Editor */
.editor-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg-main);
  min-width: 0;
}

.editor-placeholder {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  gap: 12px;
  text-align: center;
  padding: 40px;
  font-size: 14px;
}

.placeholder-icon-wrap {
  width: 56px;
  height: 56px;
  background: var(--bg-input);
  border-radius: var(--radius-xl);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
}
.placeholder-icon-wrap svg { width: 24px; height: 24px; }

.editor-container {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.editor-top-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-header);
  flex-shrink: 0;
}

.chapter-title-input {
  flex: 1;
  background: none;
  border: none;
  font-family: 'ThmanyahSans', sans-serif;
  font-size: 18px;
  font-weight: 700;
  color: var(--text-primary);
  outline: none;
  direction: rtl;
  text-align: right;
  min-width: 0;
}
.chapter-title-input::placeholder { color: var(--text-muted); }

.top-bar-actions { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }

.status-select {
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 500;
  padding: 5px 8px;
  border-radius: var(--radius-xs);
  cursor: pointer;
  direction: rtl;
  outline: none;
  transition: border-color 0.15s;
}
.status-select:focus { border-color: var(--accent); }

.format-toolbar {
  display: flex;
  align-items: center;
  gap: 1px;
  padding: 6px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-header);
  flex-shrink: 0;
}

.fmt-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  padding: 5px 7px;
  border-radius: var(--radius-xs);
  transition: background 0.12s, color 0.12s;
  display: flex;
  align-items: center;
}
.fmt-btn svg { width: 15px; height: 15px; }
.fmt-btn:hover { background: var(--bg-input); color: var(--text-primary); }

.fmt-sep {
  width: 1px;
  height: 18px;
  background: var(--border);
  margin: 0 4px;
  flex-shrink: 0;
}

.chapter-editor {
  flex: 1;
  padding: 32px 10%;
  font-size: 17px;
  line-height: 2;
  color: var(--text-primary);
  outline: none;
  overflow-y: auto;
  direction: rtl;
  text-align: right;
  caret-color: var(--accent);
  font-family: 'ThmanyahSans', sans-serif;
  background: var(--bg-main);
}

.chapter-editor:empty::before {
  content: attr(data-placeholder);
  color: var(--text-muted);
  pointer-events: none;
  display: block;
}

.chapter-editor h2 {
  font-size: 22px;
  font-weight: 800;
  margin: 28px 0 10px;
  color: var(--accent);
}
.chapter-editor h3 {
  font-size: 18px;
  font-weight: 700;
  margin: 20px 0 8px;
}
.chapter-editor p { margin-bottom: 14px; }
.chapter-editor ul { padding-right: 20px; margin-bottom: 14px; }
.chapter-editor hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 28px 15%;
}

.editor-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 7px 20px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  font-weight: 500;
  flex-shrink: 0;
  background: var(--bg-header);
}

.footer-words {
  display: flex;
  align-items: center;
  gap: 5px;
  color: var(--text-muted);
}
.footer-words svg { width: 12px; height: 12px; }

.save-ok {
  display: flex;
  align-items: center;
  gap: 4px;
  color: var(--emerald);
}
.save-ok svg { width: 12px; height: 12px; }

.save-pending {
  display: flex;
  align-items: center;
  gap: 4px;
  color: var(--amber);
}

/* Focus mode */
body.focus-mode #sidebar          { display: none; }
body.focus-mode .chapters-sidebar { display: none; }
body.focus-mode .format-toolbar   { display: none; }
body.focus-mode .editor-top-bar   { padding: 10px 5%; }
body.focus-mode .chapter-editor   { padding: 48px 16%; font-size: 18px; }

/* ============================================================
   CHARACTERS
============================================================ */

#characters { overflow: hidden; }

.characters-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 14px;
  padding: 20px 24px;
  overflow-y: auto;
  flex: 1;
  align-content: start;
}

.character-card {
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-xl);
  padding: 20px;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: box-shadow 0.2s, transform 0.2s;
}
.character-card:hover {
  box-shadow: var(--shadow);
  transform: translateY(-2px);
}

.char-avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  font-weight: 900;
  margin-bottom: 12px;
}

.char-name { font-size: 16px; font-weight: 700; margin-bottom: 2px; }
.char-role-label { font-size: 12px; color: var(--text-muted); margin-bottom: 2px; }
.char-age-label  { font-size: 12px; color: var(--text-secondary); }

.char-excerpt {
  font-size: 12px;
  color: var(--text-secondary);
  line-height: 1.6;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}

/* ============================================================
   PLOT MAP
============================================================ */

#plot { overflow: hidden; }

.plot-wrapper {
  flex: 1;
  overflow-x: auto;
  overflow-y: auto;
  padding: 20px 24px;
}

.plot-acts {
  display: flex;
  gap: 14px;
  min-height: calc(100% - 40px);
  min-width: 900px;
}

.act-column {
  flex: 1;
  min-width: 170px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.act-header {
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  text-align: center;
  font-weight: 700;
  font-size: 13px;
  flex-shrink: 0;
  border: 1px solid transparent;
}

.act-header.act-start      { background:var(--emerald-bg); color:var(--emerald-text); border-color:rgba(5,150,105,.2); }
.act-header.act-conflict   { background:var(--amber-bg);   color:var(--amber-text);   border-color:rgba(217,119,6,.2); }
.act-header.act-climax     { background:var(--rose-bg);    color:var(--rose-text);    border-color:rgba(225,29,72,.2); }
.act-header.act-resolution { background:var(--blue-bg);    color:var(--blue-text);    border-color:rgba(37,99,235,.2); }
.act-header.act-end        { background:var(--violet-bg);  color:var(--violet-text);  border-color:rgba(124,58,237,.2); }

.act-add-btn {
  background: none;
  border: 1px dashed var(--border);
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  padding: 10px;
  font-size: 12px;
  font-family: 'ThmanyahSans', sans-serif;
  font-weight: 500;
  transition: all 0.15s;
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
}
.act-add-btn svg { width: 13px; height: 13px; }
.act-add-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-dim);
}

.event-card {
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  padding: 13px;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: box-shadow 0.18s, transform 0.18s;
  border-right: 3px solid transparent;
}
.event-card:hover { box-shadow: var(--shadow); transform: translateY(-1px); }

.event-card.type-start      { border-right-color: var(--emerald); }
.event-card.type-conflict   { border-right-color: var(--amber); }
.event-card.type-climax     { border-right-color: var(--rose); }
.event-card.type-resolution { border-right-color: var(--blue); }
.event-card.type-end        { border-right-color: var(--violet); }

.event-card-title  { font-size: 13px; font-weight: 700; margin-bottom: 5px; color: var(--text-primary); }
.event-card-desc   { font-size: 12px; color: var(--text-secondary); line-height: 1.5; margin-bottom: 7px; }
.event-card-chapter{ font-size: 11px; color: var(--text-muted); margin-bottom: 5px; }

.event-card-chars  { display: flex; flex-wrap: wrap; gap: 3px; }
.event-char-tag    { font-size: 10px; padding: 2px 6px; border-radius: 99px; font-weight: 600; }

.plot-empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 260px;
  width: 100%;
  color: var(--text-muted);
  gap: 12px;
  font-size: 14px;
  grid-column: 1 / -1;
}

/* ============================================================
   EMPTY STATES
============================================================ */

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 40px;
  color: var(--text-muted);
  gap: 10px;
  text-align: center;
  grid-column: 1 / -1;
}

.empty-icon-wrap {
  width: 64px; height: 64px;
  background: var(--bg-input);
  border-radius: var(--radius-xl);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  margin-bottom: 4px;
}
.empty-icon-wrap svg { width: 28px; height: 28px; }

.empty-title { font-size: 15px; font-weight: 700; color: var(--text-secondary); }
.empty-sub   { font-size: 13px; color: var(--text-muted); }

/* ============================================================
   MODALS
============================================================ */

.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
}
.modal.hidden { display: none; }

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.5);
  backdrop-filter: blur(4px);
}

.modal-content {
  position: relative;
  z-index: 1;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  width: 92%;
  max-width: 500px;
  max-height: 88vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
  animation: modal-in 0.2s ease;
}
.modal-large { max-width: 680px; }

@keyframes modal-in {
  from { opacity: 0; transform: scale(0.97) translateY(-8px); }
  to   { opacity: 1; transform: scale(1)    translateY(0); }
}

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

.modal-title-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-primary);
}
.modal-title-wrap svg { width: 16px; height: 16px; color: var(--accent); }
.modal-title-wrap h3  { font-size: 15px; font-weight: 700; }

.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  padding: 4px;
  border-radius: var(--radius-xs);
  display: flex;
  align-items: center;
  transition: background 0.12s, color 0.12s;
}
.modal-close svg { width: 16px; height: 16px; }
.modal-close:hover { background: var(--bg-input); color: var(--text-primary); }

.modal-body { padding: 20px; overflow-y: auto; flex: 1; }

.modal-footer {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

/* ============================================================
   FORMS
============================================================ */

.form-group { margin-bottom: 14px; }

.form-group label {
  display: block;
  font-size: 12px;
  font-weight: 700;
  color: var(--text-secondary);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 14px;
  font-weight: 400;
  padding: 9px 11px;
  direction: rtl;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
  background: var(--bg-card);
}
.form-group input::placeholder,
.form-group textarea::placeholder { color: var(--text-muted); }
.form-group select option { background: var(--bg-card); }
.form-group textarea { resize: vertical; min-height: 72px; line-height: 1.6; }

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.color-picker { display: flex; gap: 7px; margin-top: 6px; }
.color-swatch {
  width: 26px; height: 26px;
  border-radius: 50%;
  border: 2px solid transparent;
  outline: 2px solid transparent;
  transition: transform 0.15s, outline-color 0.15s;
}
.color-swatch.selected {
  outline-color: var(--accent);
  outline-offset: 2px;
  transform: scale(1.15);
}

.checkboxes-group {
  display: flex;
  flex-direction: column;
  gap: 5px;
  max-height: 140px;
  overflow-y: auto;
}
.checkbox-label {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-size: 13px;
  padding: 5px 7px;
  border-radius: var(--radius-xs);
  transition: background 0.12s;
}
.checkbox-label:hover { background: var(--bg-input); }
.checkbox-label input[type="checkbox"] {
  width: 14px; height: 14px;
  accent-color: var(--accent);
  cursor: pointer;
  flex-shrink: 0;
}

/* ============================================================
   BUTTONS
============================================================ */

.btn-primary {
  background: var(--accent);
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: background 0.15s, transform 0.15s;
}
.btn-primary svg { width: 14px; height: 14px; }
.btn-primary:hover { background: var(--accent-hover); transform: translateY(-1px); }
.btn-primary:active { transform: translateY(0); }

.btn-primary.btn-sm { padding: 6px 12px; font-size: 12px; }
.btn-primary.btn-sm svg { width: 12px; height: 12px; }

.btn-secondary {
  background: var(--bg-input);
  color: var(--text-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 500;
  transition: background 0.15s, color 0.15s;
}
.btn-secondary:hover { background: #e2e8f0; color: var(--text-primary); }

.btn-danger {
  background: var(--danger-bg);
  color: var(--danger);
  border: none;
  border-radius: var(--radius-sm);
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: background 0.15s;
}
.btn-danger svg { width: 14px; height: 14px; }
.btn-danger:hover { background: #fecaca; }

.btn-icon-sm {
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  border-radius: var(--radius-xs);
  padding: 5px 7px;
  display: flex;
  align-items: center;
  transition: all 0.15s;
}
.btn-icon-sm svg { width: 15px; height: 15px; }
.btn-icon-sm:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-dim); }

.btn-danger-sm {
  background: var(--danger-bg);
  color: var(--danger);
  border: none;
  border-radius: var(--radius-xs);
  padding: 5px 7px;
  display: flex;
  align-items: center;
  transition: background 0.15s;
}
.btn-danger-sm svg { width: 15px; height: 15px; }
.btn-danger-sm:hover { background: #fecaca; }

/* ============================================================
   SCROLLBARS
============================================================ */

::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #cbd5e1; }

/* ============================================================
   UTILITIES
============================================================ */

.hidden { display: none !important; }
body.modal-open { overflow: hidden; }

/* ============================================================
   RESPONSIVE — MOBILE & TABLET
============================================================ */

/* ── Tablet (< 1024px) ── */
@media (max-width: 1024px) {
  .stats-grid       { grid-template-columns: repeat(2, 1fr); }
  .dashboard-grid   { grid-template-columns: 1fr 1fr; }
  .dashboard-card.span-2 { grid-column: span 2; }
  :root { --sidebar-w: 200px; --chapter-list-w: 220px; }
}

/* ── Mobile (< 768px) ── */
@media (max-width: 768px) {

  /* Body: leave room for bottom nav */
  html, body { overflow: hidden; }
  #app { flex-direction: column; height: 100dvh; }

  /* ── Sidebar → Bottom nav bar ── */
  #sidebar {
    width: 100%;
    height: 60px;
    border-left: none;
    border-top: 1px solid var(--sidebar-border);
    flex-direction: row;
    order: 2;
    padding: 0;
    flex-shrink: 0;
  }

  .logo { display: none; }

  .nav-links {
    flex-direction: row;
    flex: 1;
    padding: 0;
    gap: 0;
    justify-content: space-around;
    overflow: visible;
  }

  .nav-links li { flex: 1; }

  .nav-btn {
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 4px;
    padding: 8px 4px;
    font-size: 10px;
    border-radius: 0;
    width: 100%;
    height: 100%;
  }

  .nav-btn svg { width: 20px; height: 20px; }

  .nav-btn.active {
    background: var(--accent-dim);
    color: var(--accent);
  }

  .sidebar-footer { display: none; }

  /* ── Main content ── */
  #main-content { order: 1; flex: 1; overflow: hidden; }

  /* ── Dashboard ── */
  .dashboard-hero {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
    padding: 16px;
  }

  .hero-text h1 { font-size: 20px; }

  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
    padding: 12px 16px;
  }

  .stat-card { padding: 14px 12px; gap: 10px; }
  .stat-icon-wrap { width: 36px; height: 36px; }
  .stat-icon-wrap svg { width: 16px; height: 16px; }
  .stat-number { font-size: 20px; }

  .dashboard-grid {
    grid-template-columns: 1fr;
    gap: 8px;
    padding: 0 16px 80px;
  }

  .dashboard-card.span-2 { grid-column: span 1; }
  .dashboard-card { padding: 14px; }

  /* ── Chapters ── */
  .chapters-layout { flex-direction: column; }

  .chapters-sidebar {
    width: 100%;
    height: auto;
    max-height: 40%;
    border-left: none;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
  }

  .chapters-sidebar-body { max-height: 120px; }

  .editor-panel { flex: 1; min-height: 0; }

  .chapter-editor {
    padding: 20px 16px;
    font-size: 16px;
  }

  .editor-top-bar { padding: 8px 12px; gap: 6px; }
  .chapter-title-input { font-size: 15px; }

  .format-toolbar {
    padding: 4px 12px;
    overflow-x: auto;
    flex-wrap: nowrap;
  }

  /* ── Characters ── */
  .characters-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    padding: 12px 16px 80px;
  }

  /* ── Plot ── */
  .plot-wrapper { padding: 12px 16px 80px; }

  .plot-acts {
    flex-direction: column;
    min-width: unset;
    gap: 16px;
  }

  .act-column { min-width: unset; }

  /* ── Modals ── */
  .modal-content {
    width: 100%;
    max-width: 100%;
    max-height: 90dvh;
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    margin: 0;
  }

  .modal {
    align-items: flex-end;
  }

  .form-row { grid-template-columns: 1fr; }

  /* ── Section header ── */
  .section-header { padding: 14px 16px; }
  .section-header h2 { font-size: 16px; }
}

/* ── Small mobile (< 400px) ── */
@media (max-width: 400px) {
  .characters-grid { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .nav-btn span { display: none; }
  .nav-btn { gap: 0; padding: 10px; }
}
