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

:root {
  --sidebar-w: 220px;
  --bg: #f5f6fa;
  --sidebar-bg: #1e293b;
  --sidebar-text: #94a3b8;
  --sidebar-active: #e2e8f0;
  --primary: #3b82f6;
  --primary-dark: #2563eb;
  --text: #1e293b;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --card-bg: #fff;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,.08);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
}

#app { display: flex; min-height: 100vh; }

/* ─── Sidebar ─── */
.sidebar {
  width: var(--sidebar-w);
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  position: fixed; top: 0; left: 0; bottom: 0;
  z-index: 100;
}
.sidebar-header { padding: 24px 20px 20px; border-bottom: 1px solid rgba(255,255,255,.08); }
.sidebar-header h1 {
  font-size: 16px; font-weight: 700; color: #fff;
  letter-spacing: -.3px;
}
.sidebar-subtitle { font-size: 11px; color: var(--sidebar-text); margin-top: 2px; }

.sidebar-nav { padding: 12px 10px; flex: 1; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; margin-bottom: 2px;
  color: var(--sidebar-text); text-decoration: none;
  border-radius: 6px; font-size: 14px; font-weight: 500;
  transition: all .12s;
  cursor: pointer;
}
.nav-item:hover { background: rgba(255,255,255,.06); color: #cbd5e1; }
.nav-item.active { background: var(--primary); color: #fff; }
.nav-icon { font-size: 16px; width: 20px; text-align: center; }

/* ─── Main ─── */
.main { margin-left: var(--sidebar-w); flex: 1; display: flex; flex-direction: column; }

.topbar {
  padding: 20px 28px 16px;
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
}
.page-title { font-size: 20px; font-weight: 700; color: var(--text); }

.content { padding: 24px 28px; flex: 1; }

/* ─── Cards ─── */
.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}

/* ─── Buttons ─── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 16px; border-radius: 6px;
  font-size: 13px; font-weight: 600;
  border: 1px solid var(--border);
  background: var(--card-bg);
  color: var(--text);
  cursor: pointer;
  transition: all .12s;
  text-decoration: none;
  line-height: 1.4;
}
.btn:hover { border-color: var(--primary); color: var(--primary); }
.btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-dark); color: #fff; }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-danger { color: #dc2626; border-color: #fca5a5; }
.btn-danger:hover { background: #fef2f2; border-color: #dc2626; }

/* ─── Table ─── */
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); }
th { font-weight: 600; color: var(--text-muted); font-size: 12px; text-transform: uppercase; letter-spacing: .5px; }
tr:hover td { background: #f8fafc; }

/* ─── Forms ─── */
.form-group { margin-bottom: 14px; }
.form-group label { display: block; font-size: 12px; font-weight: 600; color: var(--text-muted); margin-bottom: 4px; }
.form-control {
  width: 100%; padding: 8px 10px; border: 1px solid var(--border);
  border-radius: 6px; font-size: 14px; color: var(--text);
  outline: none; transition: border-color .12s;
  font-family: inherit;
}
.form-control:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(59,130,246,.15); }
textarea.form-control { min-height: 200px; resize: vertical; font-family: monospace; font-size: 13px; line-height: 1.6; }
select.form-control { appearance: auto; }

/* ─── Modal ─── */
.modal {
  position: fixed; inset: 0; z-index: 200;
  display: flex; align-items: center; justify-content: center;
  background: rgba(0,0,0,.4);
}
.modal.hidden { display: none; }
.modal-content {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: 0 20px 60px rgba(0,0,0,.15);
  width: 90%; max-width: 700px;
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 16px; font-weight: 700; }
.modal-close {
  background: none; border: none; font-size: 20px;
  cursor: pointer; color: var(--text-muted);
  padding: 4px; line-height: 1;
}
.modal-close:hover { color: var(--text); }
.modal-body { padding: 20px; }
.modal-footer {
  display: flex; gap: 8px; justify-content: flex-end;
  padding: 12px 20px; border-top: 1px solid var(--border);
}

/* ─── Grid ─── */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* ─── Badges ─── */
.badge {
  display: inline-block; padding: 2px 8px; border-radius: 100px;
  font-size: 11px; font-weight: 600;
}
.badge-success { background: #dcfce7; color: #166534; }
.badge-pending { background: #fef9c3; color: #854d0e; }

/* ─── Import box ─── */
.import-box {
  border: 2px dashed var(--border); border-radius: var(--radius);
  padding: 32px; text-align: center; margin-bottom: 20px;
  transition: border-color .12s;
}
.import-box:hover { border-color: var(--primary); }
.import-box textarea { min-height: 300px; margin-top: 12px; }

/* ─── Chapter list ─── */
.chapter-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; border: 1px solid var(--border);
  border-radius: 6px; margin-bottom: 8px;
  cursor: pointer; transition: all .12s;
}
.chapter-item:hover { border-color: var(--primary); background: #f8fafc; }
.chapter-item .title { font-weight: 600; font-size: 14px; }
.chapter-item .meta { font-size: 12px; color: var(--text-muted); }

/* ─── Paragraph viewer ─── */
.para {
  padding: 12px 0; border-bottom: 1px solid var(--border);
  line-height: 1.8; font-size: 14px;
}
.para:last-child { border-bottom: none; }
.para .index { color: var(--text-muted); font-size: 11px; margin-right: 8px; }

/* ─── Keyword chip ─── */
.keyword-chip {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 4px 10px; background: #eff6ff; color: var(--primary-dark);
  border-radius: 100px; font-size: 13px; font-weight: 600;
  cursor: pointer; transition: all .12s;
  margin: 3px;
}
.keyword-chip:hover { background: #dbeafe; }

/* ─── Loading ─── */
.loading { text-align: center; padding: 60px; color: var(--text-muted); font-size: 14px; }

/* ─── Alert ─── */
.alert {
  padding: 12px 16px; border-radius: 6px; font-size: 13px; margin-bottom: 12px;
}
.alert-error { background: #fef2f2; color: #dc2626; border: 1px solid #fecaca; }
.alert-success { background: #f0fdf4; color: #166534; border: 1px solid #bbf7d0; }
.alert-info { background: #eff6ff; color: #1d4ed8; border: 1px solid #bfdbfe; }

.actions { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; }

/* ─── Responsive ─── */
@media (max-width: 768px) {
  .sidebar { width: 56px; }
  .sidebar-header h1, .sidebar-subtitle, .nav-item span:not(.nav-icon) { display: none; }
  .nav-item { justify-content: center; padding: 12px; }
  .main { margin-left: 56px; }
  .content { padding: 16px; }
  .grid-2 { grid-template-columns: 1fr; }
}

/* ─── Keyword editing ─── */
.kw-word {
  cursor: pointer;
  border-radius: 3px;
  padding: 0 1px;
  transition: background .1s;
  white-space: nowrap;
}
.kw-word:hover { background: #e0e7ff; }
.kw-word.is-kw { color: var(--primary); font-weight: 600; }
.kw-word.is-kw:hover { background: #dbeafe; }
