/* ── Header ───────────────────────────────────────────────────────────── */
.header {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--header-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: 20px;
  z-index: 100;
  box-shadow: var(--shadow-sm);
  transition: background var(--transition), border-color var(--transition);
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}
.header-brand svg { color: var(--accent); }
.header-brand-name {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -.3px;
}

.header-meta {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-muted);
}
.dot-sep { color: var(--border-strong); }

.status-text { font-weight: 500; transition: color var(--transition); }
.status-idle  { color: var(--text-subtle); }
.status-busy  { color: var(--amber); }
.status-ok    { color: var(--success); }
.status-error { color: var(--danger); }

.header-actions { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.header-sep { width: 1px; height: 22px; background: var(--border); margin: 0 4px; }

/* ── App body ─────────────────────────────────────────────────────────── */
.app-body {
  display: flex;
  height: 100vh;
  padding-top: var(--header-h);
  overflow: hidden;
}

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

.editor-title-bar {
  padding: 16px 48px 0;
  background: var(--bg);
  flex-shrink: 0;
}

.chapter-title {
  width: 100%;
  max-width: 720px;
  display: block;
  margin: 0 auto;
  border: none;
  outline: none;
  background: transparent;
  font-family: 'Lora', Georgia, serif;
  font-size: 22px;
  font-weight: 600;
  color: var(--text);
  padding: 0 0 14px;
  border-bottom: 2px solid var(--border);
  transition: border-color var(--transition);
}
.chapter-title::placeholder { color: var(--text-subtle); font-weight: 400; }
.chapter-title:focus { border-bottom-color: var(--accent); }

/* Scroll container — THE single scrollbar for the editor */
.editor-scroll {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
}

/* Inner holds both the highlight overlay and the textarea */
.editor-inner {
  width: 100%;
  padding: 32px 80px 100px;
}

/* editor-surface is the positioning context for the highlight layer */
.editor-surface {
  position: relative;
  width: 100%;
}

/* Highlight overlay — same font/padding as textarea, clips silently */
.highlight-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  color: transparent;
  font-family: 'Lora', Georgia, serif;
  font-size: 16px;
  line-height: 1.9;
  white-space: pre-wrap;
  word-wrap: break-word;
  overflow-wrap: break-word;
  letter-spacing: .01em;
  z-index: 0;
}

.highlight-layer mark {
  color: transparent;
  background: transparent;
  border-bottom: 2.5px solid var(--amber);
  border-radius: 0;
}

/* The textarea — transparent so highlights show through */
.editor {
  display: block;
  width: 100%;
  min-height: 70vh;
  resize: none;
  overflow: hidden;  /* grows with content — container scrolls */
  border: none;
  outline: none;
  background: transparent;
  caret-color: var(--text);
  color: var(--text);
  font-family: 'Lora', Georgia, serif;
  font-size: 16px;
  line-height: 1.9;
  white-space: pre-wrap;
  word-wrap: break-word;
  overflow-wrap: break-word;
  letter-spacing: .01em;
  position: relative;
  z-index: 1;  /* above highlight layer */
  transition: color var(--transition);
}
.editor::placeholder {
  font-family: 'Inter', sans-serif;
  font-style: italic;
  font-size: 14px;
  color: var(--text-subtle);
  line-height: 1.7;
}

/* ── Sidebar ──────────────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--surface-2);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: background var(--transition), border-color var(--transition);
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
}
.sidebar-title { font-size: 14px; font-weight: 700; }
.sidebar-count { font-size: 12.5px; color: var(--text-muted); font-weight: 500; }

.sidebar-actions {
  display: flex;
  gap: 10px;
  padding: 12px 16px;
  background: var(--accent-light);
  border-bottom: 1px solid var(--accent-border);
  flex-shrink: 0;
}

.cards-list {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* ── Drawers ──────────────────────────────────────────────────────────── */
.backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.35);
  z-index: 200;
  backdrop-filter: blur(3px);
  animation: fadeIn .2s;
}
.backdrop.open { display: block; }

.drawer {
  position: fixed;
  top: 0;
  bottom: 0;
  width: var(--drawer-w);
  background: var(--surface);
  z-index: 201;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
  transition: transform var(--transition);
}

.drawer-left  { left: 0;  transform: translateX(-100%); }
.drawer-right { right: 0; transform: translateX(100%); }
.drawer-left.open  { transform: translateX(0); }
.drawer-right.open { transform: translateX(0); }

.drawer-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: 24px 24px 18px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.drawer-title { font-size: 18px; font-weight: 700; }
.drawer-sub   { font-size: 12.5px; color: var(--text-muted); margin-top: 3px; }

.drawer-toolbar {
  display: flex;
  gap: 10px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

/* Knowledge list */
.kb-list {
  flex: 1;
  overflow-y: auto;
}

.kb-form-wrap {
  border-top: 1px solid var(--border);
  padding: 20px 24px;
  background: var(--surface-2);
  flex-shrink: 0;
  max-height: 60vh;
  overflow-y: auto;
}
.kb-form-title { font-size: 15px; font-weight: 700; margin-bottom: 16px; }

/* Settings */
.settings-body {
  flex: 1;
  overflow-y: auto;
  padding: 0;
}
.setting-group {
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
}
.setting-label {
  display: block;
  font-size: 13px;
  font-weight: 700;
  margin-bottom: 5px;
  color: var(--text);
}
.setting-desc {
  font-size: 12.5px;
  color: var(--text-muted);
  line-height: 1.5;
  margin-bottom: 12px;
}
.setting-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.setting-status  { font-size: 12.5px; font-weight: 600; margin-top: 10px; min-height: 18px; }
.key-row { display: flex; gap: 8px; }
.key-row .form-input { flex: 1; }

@keyframes fadeIn { from { opacity: 0 } to { opacity: 1 } }

/* ── Responsive ───────────────────────────────────────────────────────── */
@media (max-width: 900px) {
  :root { --sidebar-w: 300px; }
  .editor-inner { padding: 24px 40px 80px; }
}
@media (max-width: 700px) {
  :root { --sidebar-w: 100%; --drawer-w: 100%; }
  .app-body { flex-direction: column; overflow: auto; }
  .sidebar { width: 100%; height: 50vh; border-left: none; border-top: 1px solid var(--border); }
  .editor-inner { padding: 20px 20px 60px; }
}
