:root,
[data-theme="light"] {
  --bg: #eef0f6;
  --bg-elevated: #ffffff;
  --bg-card: #ffffff;
  --border: #e7e9f4;
  --text: #12131a;
  --text-muted: #6b7280;
  --accent: #5b4fe9;
  --accent-2: #8b7cf6;
  --accent-soft: rgba(91, 79, 233, 0.1);
  --green: #16a34a;
  --green-soft: rgba(22, 163, 74, 0.12);
  --red: #dc2626;
  --red-soft: rgba(220, 38, 38, 0.12);
  --amber: #d97706;
  --amber-text: #92400e;
  --amber-soft: rgba(217, 119, 6, 0.12);
  --radius: 16px;
  --radius-sm: 10px;
  --radius-lg: 20px;
  --radius-pill: 999px;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.04), 0 1px 3px rgba(16, 24, 40, 0.06);
  --shadow-md: 0 4px 12px rgba(16, 24, 40, 0.08);
  --sidebar-w: 280px;
}

[data-theme="dark"] {
  --bg: #14141f;
  --bg-elevated: #1b1b2b;
  --bg-card: #1b1b2a;
  --border: #2b2b40;
  --text: #eeeef5;
  --text-muted: #9696ab;
  --accent: #7c6fff;
  --accent-2: #9d8dff;
  --accent-soft: rgba(124, 111, 255, 0.18);
  --green: #34d399;
  --green-soft: rgba(52, 211, 153, 0.16);
  --red: #f87171;
  --red-soft: rgba(248, 113, 113, 0.16);
  --amber: #fbbf24;
  --amber-text: #fbbf24;
  --amber-soft: rgba(251, 191, 36, 0.14);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.2), 0 1px 3px rgba(0, 0, 0, 0.24);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.32);
}

* { box-sizing: border-box; }

.icon {
  width: 1em;
  height: 1em;
  display: inline-block;
  vertical-align: -0.15em;
  flex-shrink: 0;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  line-height: 1.55;
  transition: background 0.15s ease, color 0.15s ease;
}

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

/* ---------- Sidebar ---------- */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--bg-elevated);
  box-shadow: 1px 0 0 var(--border), var(--shadow-sm);
  padding: 20px 16px 40px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  z-index: 6;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 20px;
}
.brand-info { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; }
.theme-toggle {
  width: 34px; height: 34px; flex-shrink: 0;
  border-radius: var(--radius-sm); border: 1px solid var(--border); box-shadow: var(--shadow-sm);
  background: var(--bg-card); color: var(--text);
  font-size: 15px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.theme-toggle:hover { border-color: var(--accent); }
.brand-badge {
  width: 36px; height: 36px;
  border-radius: var(--radius-sm);
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; color: white; font-size: 14px;
}
.brand-title { font-weight: 700; font-size: 14.5px; }
.brand-sub { font-size: 12px; color: var(--text-muted); }

.progress-block {
  background: var(--accent-soft);
  border: 1px solid transparent;
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 18px;
}
.progress-label {
  display: flex; justify-content: space-between;
  font-size: 12px; color: var(--text-muted); margin-bottom: 8px;
}
.progress-label span:last-child { color: var(--green); font-weight: 700; }
.progress-bar {
  height: 6px; border-radius: 4px; background: var(--border); overflow: hidden;
}
.progress-fill {
  height: 100%; width: 0%;
  background: linear-gradient(90deg, var(--accent), var(--green));
  transition: width 0.3s ease;
}

.nav-group { margin-bottom: 18px; }
.nav-heading {
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--text-muted); margin: 0 8px 6px;
}
.nav-item {
  display: flex; align-items: flex-start; gap: 8px;
  width: 100%; text-align: left;
  background: transparent; border: none;
  color: var(--text); font-size: 13px;
  padding: 9px 12px; border-radius: var(--radius-sm);
  cursor: pointer; line-height: 1.35;
}
.nav-item:hover { background: var(--bg); }
.nav-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 700; }
.nav-item.module-start { border-top: 1px solid var(--border); margin-top: 4px; padding-top: 12px; }
.nav-item .nav-check {
  width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid var(--border); flex-shrink: 0;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 10px; color: white; margin-top: 1px;
}
.nav-item .nav-check.done { background: var(--green); border-color: var(--green); }
.nav-item .nav-item-text small { color: var(--text-muted); font-weight: 400; font-size: 11px; }
.nav-item.active .nav-item-text small { color: var(--accent); opacity: 0.8; }

/* ---------- Content ---------- */
.content-area { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 44px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}
.topbar-breadcrumb { font-size: 13px; font-weight: 600; color: var(--text-muted); }
.topbar-search-wrap { position: relative; width: 260px; max-width: 40vw; }
.topbar-search {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border-radius: var(--radius-pill);
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-muted);
}
.topbar-search .icon { flex-shrink: 0; }
.topbar-search input {
  border: none;
  outline: none;
  background: transparent;
  color: var(--text);
  font-size: 13px;
  width: 100%;
  font-family: inherit;
}
.topbar-search input::placeholder { color: var(--text-muted); }
.topbar-search:focus-within { border-color: var(--accent); }

.search-results {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  right: 0;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  max-height: 400px;
  overflow-y: auto;
  padding: 6px;
  z-index: 20;
}
.search-result-item {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  cursor: pointer;
  padding: 9px 11px;
  border-radius: var(--radius-sm);
  color: var(--text);
}
.search-result-item:hover { background: var(--accent-soft); }
.search-result-meta { font-size: 11px; color: var(--accent); font-weight: 700; margin-bottom: 3px; }
.search-result-snippet {
  font-size: 12.5px;
  color: var(--text-muted);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  line-height: 1.4;
}
.search-results-empty { padding: 14px; font-size: 12.5px; color: var(--text-muted); text-align: center; }

.content { flex: 1; padding: 28px 44px 44px; max-width: 920px; }

/* ---------- Notes panel ---------- */
.notes-toggle { display: none; }
.notes-panel {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--bg-elevated);
  box-shadow: -1px 0 0 var(--border), var(--shadow-sm);
  padding: 20px 16px;
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 6;
}
.notes-header { display: flex; align-items: center; justify-content: space-between; }
.notes-header-title { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 14px; }
.notes-close { display: inline-flex; align-items: center; justify-content: center; background: var(--accent-soft); border: none; color: var(--accent); cursor: pointer; padding: 6px; border-radius: 6px; }
.notes-close:hover { background: var(--accent); color: #fff; }

/* Above the notes-panel collapse breakpoint (1181px+), the panel is normally docked via
   position:sticky inside the .app flex row — collapsing it (display:none) removes it from
   that flex row entirely, so .content-area's flex:1 reclaims the freed width automatically. */
@media (min-width: 1181px) {
  .notes-panel.collapsed { display: none; }
  .notes-toggle.desktop-visible {
    display: flex; align-items: center; justify-content: center;
    position: fixed; top: 14px; right: 14px; z-index: 20;
    background: var(--bg-card); border: 1px solid var(--border); color: var(--text);
    width: 40px; height: 40px; border-radius: 8px; cursor: pointer; box-shadow: var(--shadow-sm);
  }
  /* .content keeps a readable max-width normally; widen the cap once the notes panel is
     collapsed so the freed space is actually visible instead of just becoming empty margin. */
  body.notes-collapsed-desktop .content { max-width: 1200px; }
}
.notes-day-select {
  width: 100%;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  font-size: 12.5px;
  font-family: inherit;
  cursor: pointer;
}
.notes-textarea {
  flex: 1;
  width: 100%;
  min-height: 240px;
  resize: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  color: var(--text);
  padding: 12px;
  font-size: 13.5px;
  font-family: inherit;
  line-height: 1.6;
}
.notes-textarea:focus { outline: none; border-color: var(--accent); }
.notes-save-status { font-size: 11.5px; color: var(--text-muted); min-height: 14px; text-align: right; }
.notes-save-status.saved { color: var(--green); }
.notes-hint { font-size: 11px; color: var(--text-muted); line-height: 1.5; margin: 0; }

.view-eyebrow { color: var(--accent); font-size: 12.5px; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; margin-bottom: 6px; }
.view-title { font-size: 26px; font-weight: 800; margin: 0 0 6px; }
.view-subtitle { color: var(--text-muted); margin: 0 0 26px; font-size: 14.5px; }

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 22px 24px;
  margin-bottom: 20px;
}
.card h3 { margin: 0 0 14px; font-size: 15px; font-weight: 700; display: flex; align-items: center; gap: 8px; }
.card ul { margin: 0; padding-left: 20px; }
.card li { margin-bottom: 7px; font-size: 14px; color: var(--text); }
.card li:last-child { margin-bottom: 0; }

.topik-block { padding-top: 16px; margin-top: 16px; border-top: 1px dashed var(--border); }
.topik-block:first-of-type { padding-top: 0; margin-top: 0; border-top: none; }
.topik-block h4 { margin: 0 0 8px; font-size: 14px; color: var(--accent); }
.topik-block p { margin: 0 0 10px; font-size: 13.5px; color: var(--text); line-height: 1.65; }
.topik-block p:last-child { margin-bottom: 0; }

.tag-row { display: flex; flex-wrap: wrap; gap: 8px; }
.tag {
  background: var(--accent-soft); color: var(--accent);
  padding: 5px 11px; border-radius: var(--radius-pill); font-size: 12.5px; font-weight: 600;
}

.checklist-item {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 8px 0; border-bottom: 1px dashed var(--border); font-size: 14px;
}
.checklist-item:last-child { border-bottom: none; }
.checklist-item input[type="checkbox"] {
  margin-top: 3px; width: 17px; height: 17px; accent-color: var(--green); cursor: pointer; flex-shrink: 0;
}
.checklist-item label { cursor: pointer; }
.checklist-item.checked label { color: var(--text-muted); text-decoration: line-through; }

.task-card {
  border: 1px solid var(--border);
  background: var(--bg-card);
  box-shadow: var(--shadow-sm);
  position: relative;
}
.task-card::before {
  content: ""; position: absolute; left: 0; top: 16px; bottom: 16px; width: 3px;
  background: var(--accent); border-radius: 0 3px 3px 0;
}
.task-card h3 { color: var(--accent); }
.deliverables { margin-top: 12px; }
.deliverables-title { font-size: 12px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; margin-bottom: 6px; }

/* Quiz */
.quiz-card-header { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.quiz-card-header h3 { margin: 0; }
.quiz-generate-btn {
  display: inline-flex; align-items: center; gap: 6px; flex-shrink: 0;
  border: 1px solid var(--accent); background: var(--accent-soft); color: var(--accent);
  cursor: pointer; border-radius: var(--radius-pill);
  padding: 7px 14px; font-size: 12.5px; font-weight: 700;
}
.quiz-generate-btn:hover { background: var(--accent); color: #fff; }
.quiz-generate-btn:disabled { opacity: 0.65; cursor: default; }
.quiz-generate-status { color: var(--red); font-size: 12.5px; margin: -8px 0 14px; }
.quiz-intro { color: var(--text-muted); font-size: 13px; margin: 0 0 16px; }
.quiz-question { margin-bottom: 20px; }
.quiz-question:last-of-type { margin-bottom: 16px; }
.quiz-question-text { font-weight: 700; font-size: 14px; margin-bottom: 10px; }
.quiz-options { display: flex; flex-direction: column; gap: 8px; }
.quiz-option {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--bg);
  cursor: pointer; font-size: 13.5px; color: var(--text);
}
.quiz-option:hover { border-color: var(--accent); }
.quiz-option input[type="radio"] { accent-color: var(--accent); cursor: pointer; flex-shrink: 0; }
.quiz-option-correct { border-color: var(--green); background: var(--green-soft); color: var(--green); font-weight: 600; }
.quiz-option-wrong { border-color: var(--red); background: var(--red-soft); color: var(--red); font-weight: 600; }
.quiz-explain {
  margin-top: 10px; padding: 10px 14px; border-radius: var(--radius-sm);
  background: var(--accent-soft); color: var(--text); font-size: 13px; line-height: 1.5;
}
.quiz-warning { color: var(--red); font-size: 12.5px; margin-bottom: 12px; }
.quiz-actions { display: flex; gap: 10px; margin-top: 4px; }
.quiz-submit-btn, .quiz-retry-btn {
  border: none; cursor: pointer; border-radius: var(--radius-sm);
  padding: 10px 18px; font-size: 13.5px; font-weight: 700;
  background: var(--accent); color: #fff; box-shadow: var(--shadow-sm);
}
.quiz-submit-btn:hover, .quiz-retry-btn:hover { filter: brightness(1.08); }
.quiz-revert-btn {
  border: 1px solid var(--border); cursor: pointer; border-radius: var(--radius-sm);
  padding: 10px 18px; font-size: 13.5px; font-weight: 700;
  background: transparent; color: var(--text-muted);
}
.quiz-revert-btn:hover { border-color: var(--accent); color: var(--accent); }
.quiz-score { margin-top: 14px; font-weight: 700; font-size: 14px; color: var(--accent); }

.session-meta { display: flex; gap: 10px; margin-bottom: 18px; flex-wrap: wrap; }
.meta-pill {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--bg-card); border: 1px solid var(--border); box-shadow: var(--shadow-sm);
  padding: 6px 13px; border-radius: var(--radius-pill); font-size: 12.5px; color: var(--text-muted); font-weight: 600;
}

.nav-arrows { display: flex; justify-content: space-between; margin-top: 30px; gap: 12px; }
.nav-arrow-btn {
  background: var(--bg-card); border: 1px solid var(--border); box-shadow: var(--shadow-sm); color: var(--text);
  padding: 10px 18px; border-radius: var(--radius-sm); cursor: pointer; font-size: 13.5px; font-weight: 600;
}
.nav-arrow-btn:hover { border-color: var(--accent); color: var(--accent); }
.nav-arrow-btn:disabled { opacity: 0.35; cursor: not-allowed; }

/* Overview page */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 14px; margin-bottom: 24px; }
.stat-box {
  background: var(--bg-card); border: 1px solid var(--border); box-shadow: var(--shadow-sm);
  border-radius: var(--radius); padding: 18px; text-align: center;
}
.stat-box .num { font-size: 26px; font-weight: 800; color: var(--text); }
.stat-box .label { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

/* Dashboard page */
.dashboard-hero { display: flex; align-items: center; gap: 26px; flex-wrap: wrap; }
.dashboard-ring {
  --size: 116px;
  width: var(--size); height: var(--size); border-radius: 50%; flex-shrink: 0;
  background: conic-gradient(var(--accent) calc(var(--pct) * 1%), var(--border) 0);
  display: flex; align-items: center; justify-content: center; position: relative;
}
.dashboard-ring::before { content: ""; position: absolute; inset: 9px; border-radius: 50%; background: var(--bg-card); }
.dashboard-ring-value { position: relative; z-index: 1; font-size: 21px; font-weight: 800; color: var(--text); }
.dashboard-hero-info { display: flex; flex-direction: column; gap: 10px; flex: 1; min-width: 220px; }
.dashboard-hero-stat { font-size: 14px; font-weight: 600; color: var(--text); }
.dashboard-cta {
  align-self: flex-start; margin-top: 4px; border: none; cursor: pointer;
  background: var(--accent); color: #fff; box-shadow: var(--shadow-md);
  padding: 11px 18px; border-radius: var(--radius-sm); font-size: 13.5px; font-weight: 700;
}
.dashboard-cta:hover { filter: brightness(1.08); }
.dashboard-cta-done { background: none; color: var(--green); padding: 4px 0; font-size: 14px; }

.module-progress-list { display: flex; flex-direction: column; gap: 12px; }
.module-progress-row { cursor: pointer; }
.module-progress-top { display: flex; justify-content: space-between; font-size: 13px; margin-bottom: 6px; }
.module-progress-title { color: var(--text); font-weight: 600; }
.module-progress-row:hover .module-progress-title { color: var(--accent); }
.module-progress-count { color: var(--text-muted); font-size: 12px; }
.module-progress-bar { height: 6px; border-radius: 4px; background: var(--border); overflow: hidden; }
.module-progress-fill { height: 100%; background: linear-gradient(90deg, var(--accent), var(--green)); }

.disclaimer {
  background: var(--amber-soft);
  border: 1px solid transparent;
  color: var(--amber-text);
  padding: 12px 16px; border-radius: var(--radius-sm); font-size: 13px; margin-bottom: 22px;
}

/* Resources page */
.resource-card { display: flex; flex-direction: column; gap: 10px; }
.resource-badge {
  align-self: flex-start;
  background: var(--amber-soft); color: var(--amber-text);
  padding: 4px 10px; border-radius: var(--radius-pill); font-size: 11.5px; font-weight: 700;
}
.download-btn {
  align-self: flex-start;
  background: var(--accent); color: #fff; font-weight: 700; box-shadow: var(--shadow-sm);
  border: none; padding: 10px 18px; border-radius: var(--radius-sm); cursor: pointer;
  text-decoration: none; font-size: 13.5px; margin-top: 6px; display: inline-flex; align-items: center; gap: 6px;
}
.download-btn:hover { filter: brightness(1.08); }

/* Kurikulum table (overview) */
.table-scroll { overflow-x: auto; }
.curriculum-table { width: 100%; border-collapse: collapse; font-size: 13px; min-width: 620px; }
.curriculum-table th {
  text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--text-muted); padding: 8px 10px; border-bottom: 1px solid var(--border);
}
.curriculum-table td { padding: 10px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
.curriculum-table tr:last-child td { border-bottom: none; }
.curriculum-row { cursor: pointer; }
.curriculum-row:hover td { background: var(--accent-soft); }
.curriculum-table .muted { color: var(--text-muted); font-size: 12px; margin-top: 3px; }

/* ---------------- Slide-style visual summary ---------------- */
.slide-card { background: linear-gradient(160deg, var(--bg-card), var(--bg-elevated)); }
.slide-summary { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.slide-point {
  display: flex; flex-direction: column; gap: 8px;
  background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 14px 16px; min-height: 90px;
}
.slide-num {
  width: 26px; height: 26px; border-radius: 50%; background: var(--accent-soft); color: var(--accent);
  display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 12.5px;
}
.slide-text { font-size: 13px; color: var(--text); line-height: 1.4; font-weight: 600; }

/* ---------------- Topik extras: video / diagram / code ---------------- */
.topik-extras { display: flex; flex-direction: column; gap: 14px; margin-top: 14px; }

.video-card {
  display: flex; align-items: center; gap: 12px;
  background: var(--accent-soft); border: 1px solid transparent; border-radius: var(--radius-sm);
  padding: 10px 14px; text-decoration: none; color: var(--text);
}
.video-card:hover { border-color: var(--accent); }
.video-play {
  width: 32px; height: 32px; border-radius: 50%; background: var(--accent); color: white;
  display: flex; align-items: center; justify-content: center; font-size: 12px; flex-shrink: 0;
}
.video-info { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.video-badge { font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--accent); font-weight: 700; }
.video-title { font-size: 13px; color: var(--text); }

.code-block { background: #0a0c10; border: 1px solid var(--border); border-radius: var(--radius-sm); overflow: hidden; }
.code-lang {
  background: var(--bg-elevated); color: var(--text-muted); font-size: 11px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.05em; padding: 6px 12px; border-bottom: 1px solid var(--border);
}
.code-block pre { margin: 0; padding: 14px 16px; overflow-x: auto; }
.code-block code { font-family: "SF Mono", Menlo, Consolas, monospace; font-size: 12.5px; color: #d4e2ff; line-height: 1.6; white-space: pre; }

.diagram { padding: 14px; background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-sm); }

/* hierarchy (nested concentric-ish rings, rendered as stacked indented bars) */
.diagram-hierarchy { display: flex; flex-direction: column; gap: 8px; }
.hierarchy-ring {
  display: flex; flex-direction: column; gap: 2px;
  background: color-mix(in srgb, var(--accent) calc(15% + var(--depth) * 12%), var(--bg));
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 10px 14px; margin-left: calc(var(--depth) * 22px);
}
.hierarchy-label { font-weight: 700; font-size: 13px; color: var(--text); }
.hierarchy-desc { font-size: 11.5px; color: var(--text-muted); }

/* timeline */
.diagram-timeline { display: flex; flex-wrap: wrap; gap: 0; align-items: flex-start; }
.timeline-item { flex: 1 1 140px; text-align: center; padding: 0 8px; position: relative; }
.timeline-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); margin: 0 auto 8px; }
.timeline-period { font-size: 11px; color: var(--accent); font-weight: 700; margin-bottom: 4px; }
.timeline-label { font-size: 12px; color: var(--text); }

/* grid */
.diagram-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 10px; }
.grid-card { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 12px; }
.grid-label { font-weight: 700; font-size: 13px; color: var(--accent); margin-bottom: 4px; }
.grid-desc { font-size: 11.5px; color: var(--text-muted); }

/* compare */
.diagram-compare { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; }
.compare-col { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 12px; }
.compare-label { font-weight: 700; font-size: 13px; color: var(--accent); margin-bottom: 8px; }
.compare-col ul { margin: 0; padding-left: 16px; }
.compare-col li { font-size: 11.5px; color: var(--text); margin-bottom: 5px; }

/* layers */
.diagram-layers { display: flex; flex-direction: column; align-items: stretch; gap: 4px; }
.layer-box { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 10px 14px; }
.layer-label { font-weight: 700; font-size: 13px; color: var(--accent); }
.layer-desc { font-size: 11.5px; color: var(--text-muted); margin-top: 2px; }
.layer-arrow { text-align: center; color: var(--text-muted); font-size: 14px; }

/* flow */
.diagram-flow { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.flow-step { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 8px 12px; font-size: 12px; color: var(--text); }
.flow-arrow { color: var(--accent); font-size: 14px; }

/* Mobile */
.menu-toggle { display: none; }

@media (max-width: 880px) {
  .menu-toggle {
    display: flex; align-items: center; justify-content: center;
    position: fixed; top: 14px; left: 14px; z-index: 20;
    background: var(--bg-card); border: 1px solid var(--border); color: var(--text);
    width: 40px; height: 40px; border-radius: 8px; font-size: 16px; cursor: pointer;
  }
  .sidebar {
    position: fixed; left: -100%; top: 0; z-index: 15; width: 84%;
    max-width: 320px; transition: left 0.25s ease; box-shadow: 0 0 40px rgba(0,0,0,0.5);
  }
  .sidebar.open { left: 0; }
  .topbar { padding: 16px 20px 16px 64px; flex-wrap: wrap; }
  .topbar-search-wrap { max-width: 100%; width: 100%; order: 3; }
  .content { padding: 20px 20px 40px; }
}

/* Notes panel collapses to an overlay earlier than the left sidebar — with both docked at
   once (280px + 300px) content gets uncomfortably squeezed well before the 880px breakpoint. */
@media (max-width: 1180px) {
  .notes-toggle {
    display: flex; align-items: center; justify-content: center;
    position: fixed; top: 14px; right: 14px; z-index: 20;
    background: var(--bg-card); border: 1px solid var(--border); color: var(--text);
    width: 40px; height: 40px; border-radius: 8px; cursor: pointer; box-shadow: var(--shadow-sm);
  }
  .notes-panel {
    position: fixed; right: -100%; top: 0; z-index: 25; width: 84%;
    max-width: 340px; transition: right 0.25s ease; box-shadow: 0 0 40px rgba(0, 0, 0, 0.5);
  }
  .notes-panel.open { right: 0; }
}

/* ---------------- Guru AI Chatbot ---------------- */
.chat-toggle {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 60;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 18px;
  border-radius: var(--radius-pill);
  border: none;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: var(--shadow-md);
  transition: transform 0.15s ease, opacity 0.15s ease, right 0.2s ease;
}
.chat-toggle:hover { transform: translateY(-2px); }
.chat-toggle-hidden { opacity: 0; pointer-events: none; transform: scale(0.9); }
.chat-toggle-icon { font-size: 18px; }

.chat-panel {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 61;
  width: 380px;
  max-width: calc(100vw - 32px);
  height: 560px;
  max-height: calc(100vh - 48px);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-md), 0 20px 60px rgba(16, 24, 40, 0.16);
  overflow: hidden;
  transition: right 0.2s ease;
}
.chat-panel[hidden] { display: none; }
.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-card);
  flex-shrink: 0;
}
.chat-header-title { font-size: 14.5px; font-weight: 700; color: var(--text); }
.chat-header-sub { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.chat-header-actions { display: flex; align-items: center; gap: 2px; }
.chat-close,
.chat-icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 16px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
}
.chat-close:hover,
.chat-icon-btn:hover { background: var(--border); color: var(--text); }

.chat-apikey-setup {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow-y: auto;
}
.chat-apikey-setup[hidden] { display: none; }
.chat-apikey-intro { font-size: 12.5px; line-height: 1.6; color: var(--text-muted); margin: 0; }
.chat-apikey-link {
  display: inline-block;
  font-size: 13px;
  font-weight: 600;
  color: var(--accent);
  text-decoration: none;
  padding: 8px 12px;
  border: 1px solid var(--accent-soft);
  border-radius: var(--radius-sm);
  background: var(--accent-soft);
}
.chat-apikey-link:hover { opacity: 0.85; }
.chat-apikey-input {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 9px 12px;
  font-size: 13px;
  font-family: inherit;
}
.chat-apikey-input:focus { outline: none; border-color: var(--accent); }
.chat-apikey-save {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.chat-apikey-save:hover { opacity: 0.9; }

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.chat-messages[hidden] { display: none; }
.chat-msg { display: flex; }
.chat-msg-user { justify-content: flex-end; }
.chat-msg-assistant { justify-content: flex-start; }
.chat-msg-bubble {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 13.5px;
  line-height: 1.55;
  white-space: pre-wrap;
}
.chat-msg-user .chat-msg-bubble {
  background: var(--accent);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.chat-msg-assistant .chat-msg-bubble {
  background: var(--bg-card);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  color: var(--text);
  border-bottom-left-radius: 4px;
}
.chat-msg-pending .chat-msg-bubble { color: var(--text-muted); font-style: italic; }
.chat-msg-bubble strong { font-weight: 700; }
.chat-list { margin: 4px 0; padding-left: 20px; }
.chat-list li { margin: 2px 0; }

.chat-link-card {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 6px 0;
  padding: 6px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  text-decoration: none;
  color: inherit;
  max-width: 320px;
}
.chat-link-thumb {
  width: 64px;
  height: 48px;
  object-fit: cover;
  border-radius: 6px;
  background: var(--border);
  flex-shrink: 0;
}
.chat-link-card-no-thumb .chat-link-thumb { display: none; }
.chat-link-info { display: flex; flex-direction: column; min-width: 0; }
.chat-link-label {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--accent);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.chat-link-domain {
  font-size: 11px;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-footer-note {
  font-size: 10.5px;
  color: var(--text-muted);
  text-align: center;
  padding: 6px 12px;
  background: var(--bg-card);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.chat-input-row {
  display: flex;
  gap: 8px;
  padding: 12px;
  background: var(--bg-card);
  flex-shrink: 0;
}
.chat-input-row[hidden] { display: none; }
.chat-input {
  flex: 1;
  resize: none;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 9px 12px;
  font-size: 13.5px;
  font-family: inherit;
  max-height: 120px;
}
.chat-input:focus { outline: none; border-color: var(--accent); }
.chat-send {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  width: 40px;
  flex-shrink: 0;
  cursor: pointer;
  font-size: 16px;
}
.chat-send:hover { opacity: 0.9; }

@media (max-width: 520px) {
  .chat-panel { width: calc(100vw - 24px); right: 12px; bottom: 12px; height: calc(100vh - 24px); }
  .chat-toggle { right: 16px; bottom: 16px; padding: 12px 14px; }
  .chat-toggle-text { display: none; }
}

/* Above the notes-panel collapse breakpoint, the notes panel is normally docked on the right —
   shift the floating chat widget left so it doesn't sit on top of it. Scoped to :not(.notes-
   collapsed-desktop) so that when the user collapses the notes panel (see app.js
   applyNotesCollapsedState), the widget falls back to hugging the real right edge (right: 24px)
   instead of leaving a 280px gap where the panel used to be. The flag class lives on <body>
   (not .app) because #chatToggle/#chatPanel are siblings of .app, not descendants of it. */
@media (min-width: 1181px) {
  body:not(.notes-collapsed-desktop) .chat-toggle,
  body:not(.notes-collapsed-desktop) .chat-panel { right: calc(24px + var(--sidebar-w)); }
}
