/* ── Reset & base ── */
*,
*::before,
*::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --bg-primary: #ffffff;
  --bg-secondary: #f7f7f8;
  --bg-sidebar: #f4f4f5;
  --bg-input: #ffffff;
  --bg-user-msg: #e8eef7;
  --bg-assistant-msg: transparent;
  --text-primary: #1f2430;
  --text-secondary: #6b7280;
  --border-color: #e3e3e6;
  --accent: #10a37f;
  --accent-hover: #0d8c6d;
  --danger: #ef4444;
  --radius: 12px;
  --sidebar-width: 280px;
  --max-chat-width: 768px;
}

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

body {
  display: flex;
}

/* ── Scrollbar ── */
::-webkit-scrollbar {
  width: 6px;
}
::-webkit-scrollbar-thumb {
  background: #c4c4c8;
  border-radius: 3px;
}

/* ── Sidebar ── */
.sidebar {
  width: var(--sidebar-width);
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  transition: margin-left 0.2s ease;
  overflow: hidden;
}

.sidebar.hidden {
  margin-left: calc(-1 * var(--sidebar-width));
}

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

.sidebar-header h2 {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.sidebar-header button {
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  width: 32px;
  height: 32px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.sidebar-header button:hover {
  background: var(--accent);
}

.conversation-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}

.conversation-item {
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.conversation-item:hover {
  background: var(--bg-input);
}

.conversation-item.active {
  background: var(--bg-input);
}

.conversation-item .delete-btn {
  display: none;
  background: none;
  border: none;
  color: var(--danger);
  cursor: pointer;
  font-size: 14px;
  padding: 2px 6px;
  border-radius: 4px;
}

.conversation-item:hover .delete-btn {
  display: inline-block;
}

/* ── SPARQL editor in sidebar ── */
.sparql-editor {
  border-top: 1px solid var(--border-color);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.sparql-editor-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.sparql-editor-header h2 {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

#sparql-input {
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  color: var(--text-primary);
  font-family: "Fira Code", "Consolas", monospace;
  font-size: 12px;
  padding: 8px;
  resize: vertical;
  min-height: 120px;
  max-height: 300px;
  outline: none;
  line-height: 1.5;
}

#sparql-input:focus {
  border-color: var(--accent);
}

#sparql-run-btn {
  background: var(--accent);
  border: none;
  color: white;
  padding: 8px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  transition: background 0.15s;
}

#sparql-run-btn:hover {
  background: var(--accent-hover);
}

#sparql-run-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ── Graph overlay ── */
.graph-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
}

.graph-overlay.hidden {
  display: none;
}

.graph-panel {
  width: 90vw;
  height: 85vh;
  background: var(--bg-secondary);
  border-radius: 12px;
  border: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.graph-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-color);
}

.graph-header h2 {
  font-size: 16px;
  font-weight: 600;
}

.graph-container {
  flex: 1;
  width: 100%;
  min-height: 500px;
  background: #f8fafc;
  position: relative;
}

.graph-error {
  padding: 16px;
  color: var(--danger);
  font-size: 14px;
  text-align: center;
}

.graph-error.hidden {
  display: none;
}

.sidebar-footer {
  padding: 16px;
  border-top: 1px solid var(--border-color);
  text-align: center;
}

.brand {
  font-size: 12px;
  color: var(--text-secondary);
}

/* ── Chat area ── */
.chat-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.chat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-color);
  background: var(--bg-secondary);
  height: 52px;
}

.chat-header h1 {
  font-size: 16px;
  font-weight: 600;
}

.icon-btn {
  background: none;
  border: none;
  color: var(--text-primary);
  font-size: 20px;
  cursor: pointer;
  padding: 4px;
  border-radius: 6px;
}

.icon-btn:hover {
  background: var(--bg-input);
}

/* ── Messages ── */
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.welcome {
  text-align: center;
  margin: auto;
  max-width: 500px;
}

.welcome h2 {
  font-size: 24px;
  margin-bottom: 8px;
}

.welcome p {
  color: var(--text-secondary);
  font-size: 14px;
  line-height: 1.6;
}

.message-row {
  display: flex;
  justify-content: center;
  width: 100%;
}

.message {
  max-width: var(--max-chat-width);
  width: 100%;
  padding: 16px 20px;
  line-height: 1.6;
  font-size: 15px;
  border-radius: var(--radius);
}

.message.user {
  background: var(--bg-user-msg);
  margin-left: auto;
  max-width: 85%;
  width: fit-content;
  align-self: flex-end;
}

.message.assistant {
  background: var(--bg-assistant-msg);
}

.message p {
  margin-bottom: 8px;
}

.message p:last-child {
  margin-bottom: 0;
}

.message pre {
  background: #f3f4f6;
  padding: 12px;
  border-radius: 8px;
  overflow-x: auto;
  font-size: 13px;
  margin: 8px 0;
}

.message code {
  font-family: "Fira Code", "Consolas", monospace;
}

.typing-indicator {
  display: inline-flex;
  gap: 4px;
  padding: 8px 0;
}

.typing-indicator span {
  width: 8px;
  height: 8px;
  background: var(--text-secondary);
  border-radius: 50%;
  animation: bounce 1.4s ease-in-out infinite;
}

.typing-indicator span:nth-child(2) {
  animation-delay: 0.2s;
}

.typing-indicator span:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes bounce {
  0%, 60%, 100% { transform: translateY(0); }
  30% { transform: translateY(-6px); }
}

/* ── Figure images ── */
.figure-gallery {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 12px;
}

.figure-image {
  max-width: 100%;
  max-height: 400px;
  border-radius: 8px;
  border: 1px solid var(--border-color);
  cursor: pointer;
  transition: opacity 0.15s;
  object-fit: contain;
  background: #f3f4f6;
}

.figure-image:hover {
  opacity: 0.85;
}

/* ── SPARQL badge ── */
.sparql-badge {
  max-width: var(--max-chat-width);
  width: 100%;
  background: #eef4fb;
  border: 1px solid #cfe0f3;
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 13px;
  margin-bottom: 4px;
}

.sparql-badge-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: #1565c0;
  font-weight: 500;
}

.sparql-toggle {
  background: none;
  border: 1px solid #cfe0f3;
  color: #1565c0;
  font-size: 12px;
  padding: 2px 8px;
  border-radius: 4px;
  cursor: pointer;
}

.sparql-toggle:hover {
  background: #dbeafe;
}

.sparql-code {
  margin-top: 8px;
  background: #f5f7fa;
  padding: 10px;
  border-radius: 6px;
  overflow-x: auto;
  font-family: "Fira Code", "Consolas", monospace;
  font-size: 12px;
  color: #24303f;
  white-space: pre-wrap;
}

.sparql-code.hidden {
  display: none;
}

/* ── Input area ── */
.input-area {
  padding: 16px;
  background: var(--bg-primary);
  display: flex;
  flex-direction: column;
  align-items: center;
}

.input-form {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: 16px;
  padding: 10px 16px;
  width: 100%;
  max-width: var(--max-chat-width);
  transition: border-color 0.15s;
}

.input-form:focus-within {
  border-color: var(--accent);
}

.input-form textarea {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 15px;
  resize: none;
  max-height: 200px;
  line-height: 1.5;
}

.input-form textarea::placeholder {
  color: var(--text-secondary);
}

.input-form button[type="submit"] {
  background: var(--accent);
  border: none;
  color: white;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s;
}

.input-form button[type="submit"]:hover {
  background: var(--accent-hover);
}

.input-form button[type="submit"]:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.disclaimer {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 8px;
  text-align: center;
}

/* Image attach button + preview (Phase 2) */
#attach-btn {
  background: transparent;
  border: none;
  color: #8e8ea0;
  cursor: pointer;
  padding: 8px;
  display: flex;
  align-items: center;
}
#attach-btn:hover { color: #111827; }

.image-preview {
  position: relative;
  display: inline-block;
  margin-right: 8px;
}
.image-preview.hidden { display: none; }
.image-preview img {
  max-height: 56px;
  max-width: 56px;
  border-radius: 8px;
  border: 1px solid #cbd5e1;
  object-fit: cover;
}
#image-remove-btn {
  position: absolute;
  top: -6px;
  right: -6px;
  background: #333;
  color: #ececec;
  border: 1px solid #555;
  border-radius: 50%;
  width: 18px;
  height: 18px;
  line-height: 1;
  font-size: 11px;
  cursor: pointer;
  padding: 0;
}
.message .message-image {
  display: block;
  max-width: 220px;
  max-height: 220px;
  border-radius: 8px;
  margin-bottom: 6px;
  cursor: pointer;
}

/* ── Responsive ── */
@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    z-index: 100;
    height: 100%;
  }

  .sidebar.hidden {
    margin-left: calc(-1 * var(--sidebar-width));
  }
}

/* Inline graph in the SPARQL badge */
.sparql-actions { display: inline-flex; gap: 8px; }
.sparql-graph-toggle {
  background: transparent;
  border: 1px solid #cbd5e1;
  color: #1f2430;
  border-radius: 6px;
  padding: 2px 8px;
  font-size: 12px;
  cursor: pointer;
}
.sparql-graph-toggle:hover { background: #eef2f7; }
.sparql-graph-toggle:disabled { opacity: 0.6; cursor: default; }
.sparql-graph {
  height: 300px;
  margin-top: 8px;
  border: 1px solid #ddd;
  border-radius: 8px;
  background: #f8fafc;
  overflow: hidden;
}
.sparql-graph.hidden { display: none; }

/* ===== Curriculum Library ===== */
.lib-app { max-width: 1000px; margin: 0 auto; padding: 16px; }
.lib-header { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.lib-title { font-size: 1.4rem; margin: 0; }
.lib-nav a { margin-left: 12px; text-decoration: none; color: #2e7d32; font-weight: 600; }
.lib-nav a.active { text-decoration: underline; }
.breadcrumb { margin: 12px 0; font-size: 0.95rem; color: #555; }
.breadcrumb a { color: #2e7d32; text-decoration: none; }
.breadcrumb .sep { margin: 0 8px; color: #aaa; }
.lib-loading, .lib-error, .empty { padding: 24px; color: #666; text-align: center; }
.lib-error { color: #c62828; }
.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; }
.card { display: block; padding: 18px; border-radius: 12px; background: #e8f5e9; color: #1b5e20;
  text-decoration: none; box-shadow: 0 1px 3px rgba(0,0,0,.08); transition: transform .08s, box-shadow .08s; }
.card:hover { transform: translateY(-2px); box-shadow: 0 4px 10px rgba(0,0,0,.12); }
.card-title { font-weight: 700; font-size: 1.05rem; }
.card-sub { margin-top: 6px; font-size: .9rem; color: #33691e; }
.card-meta { margin-top: 10px; font-size: .8rem; color: #558b2f; }
.lesson-list { display: flex; flex-direction: column; gap: 8px; }
.lesson-row { display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: 14px 16px; border-radius: 10px; background: #f1f8e9; color: #1b5e20; text-decoration: none; }
.lesson-row:hover { background: #dcedc8; }
.lesson-pages { font-size: .8rem; color: #777; white-space: nowrap; }
.lesson-heading { margin: 8px 0 4px; }
.objectives { background: #fffde7; border-left: 4px solid #fbc02d; padding: 10px 14px; border-radius: 6px; margin: 10px 0; color: #4e4300; }
.objectives h3 { margin: 0 0 6px; font-size: 1rem; }
.objectives p { margin: 4px 0; line-height: 1.5; }
.tabbar { display: flex; gap: 4px; border-bottom: 2px solid #e0e0e0; margin: 16px 0 0; flex-wrap: wrap; }
.tab { border: none; background: none; padding: 10px 16px; cursor: pointer; font-size: .95rem;
  color: #555; border-bottom: 3px solid transparent; }
.tab.active { color: #2e7d32; border-bottom-color: #2e7d32; font-weight: 700; }
.tabpanel { display: none; padding: 16px 0; }
.tabpanel.active { display: block; }
.section { margin-bottom: 18px; }
.section-title { font-size: 1.05rem; color: #2e7d32; margin: 0 0 6px; }
.section p { line-height: 1.6; margin: 6px 0; }
.fig-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 14px; margin-bottom: 16px; }
.fig { margin: 0; }
.fig img { width: 100%; height: auto; border-radius: 8px; border: 1px solid #eee; }
.fig-noimg { font-size: 2rem; text-align: center; padding: 24px; background: #f5f5f5; border-radius: 8px; }
.fig figcaption { font-size: .85rem; color: #555; margin-top: 4px; }
.tbl { background: #f9fbe7; border-radius: 8px; padding: 12px 14px; margin-bottom: 12px; color: #33402a; }
.tbl-caption { font-weight: 600; margin-bottom: 4px; }
.tbl-text { margin: 0; line-height: 1.5; white-space: pre-line; }
.concept-list { display: flex; flex-direction: column; gap: 10px; }
.concept-item { background: #e1f5fe; color: #15323f; border-left: 4px solid #0288d1; border-radius: 8px; padding: 10px 14px; }
.concept-name { font-weight: 700; color: #01579b; }
.concept-def { margin: 6px 0 0; line-height: 1.55; }
.assessment { background: #fce4ec; border-radius: 8px; padding: 12px 14px; margin-bottom: 10px; color: #4a2f38; }
.assessment-type { font-weight: 600; color: #ad1457; margin-bottom: 4px; }
.assessment p { margin: 0; line-height: 1.55; }
.header-lib-link { margin-left: auto; text-decoration: none; color: #2e7d32; font-weight: 600; }

/* ===== Interactive exercise runner ===== */
.ex-runner { background: #f3f6fb; border: 1px solid #d8e2f0; border-radius: 10px; padding: 12px 14px; margin: 8px 0; color: #1f2a37; }
.ex-q { margin-bottom: 8px; line-height: 1.5; }
.ex-input { width: 100%; box-sizing: border-box; border: 1px solid #c3cfe0; border-radius: 8px; padding: 8px 10px; font: inherit; resize: vertical; }
.ex-actions { margin-top: 8px; }
.ex-submit, .ex-retry { background: #2e7d32; color: #fff; border: none; border-radius: 8px; padding: 7px 14px; cursor: pointer; font: inherit; }
.ex-submit:disabled { opacity: .6; cursor: default; }
.ex-retry { background: #607d8b; }
.ex-loading, .ex-hint { margin-top: 8px; color: #607d8b; }
.ex-error { margin-top: 8px; color: #c62828; }
.ex-result { margin-top: 8px; }
.ex-verdict { display: inline-block; font-weight: 700; padding: 3px 10px; border-radius: 12px; margin-bottom: 6px; }
.verdict-correct { background: #e8f5e9; color: #1b5e20; }
.verdict-partial { background: #fff8e1; color: #8d6e00; }
.verdict-incorrect { background: #ffebee; color: #b71c1c; }
.ex-feedback { line-height: 1.55; margin-bottom: 6px; }
.ex-model { background: #eef7ee; border-left: 4px solid #2e7d32; border-radius: 6px; padding: 8px 12px; }
.ex-model-h { font-weight: 700; color: #2e7d32; margin-bottom: 4px; }
/* Chat exercise offer */
.ex-offer { background: #eef3f8; border: 1px solid #d8e2f0; border-radius: 10px; padding: 10px 14px; margin: 8px 0; }
.ex-offer-q { margin-bottom: 8px; }
.ex-offer-actions { display: flex; gap: 8px; }
.ex-offer-yes { background: #2e7d32; color: #fff; border: none; border-radius: 8px; padding: 7px 14px; cursor: pointer; font: inherit; }
.ex-offer-no { background: #cfd8dc; color: #263238; border: none; border-radius: 8px; padding: 7px 14px; cursor: pointer; font: inherit; }

/* ===== Nội dung book part-images ===== */
.content-pages { display: flex; flex-direction: column; gap: 12px; }
.content-page { max-width: 100%; height: auto; border: 1px solid #e3e3e6; border-radius: 8px; background: #fff; }
