/* ── Reset & Base ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: var(--tg-theme-bg-color, #1a1a2e);
  --bg2: var(--tg-theme-secondary-bg-color, #16213e);
  --text: var(--tg-theme-text-color, #eaeaea);
  --hint: var(--tg-theme-hint-color, #8a8a9a);
  --accent: var(--tg-theme-button-color, #6c63ff);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --link: var(--tg-theme-link-color, #a78bfa);
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 4px 24px rgba(0,0,0,0.25);
  --green: #22c55e;
  --red: #ef4444;
  --yellow: #f59e0b;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 15px;
  overscroll-behavior: none;
}

#app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  padding-bottom: 70px;
}

/* ── Header ── */
.header {
  background: var(--bg2);
  padding: 14px 16px 12px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
  position: sticky;
  top: 0;
  z-index: 10;
}
.header-inner { display: flex; align-items: center; gap: 12px; }
.header-avatar {
  width: 44px; height: 44px;
  background: linear-gradient(135deg, var(--accent), #a78bfa);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 22px;
  flex-shrink: 0;
}
.header-name { font-size: 17px; font-weight: 700; }
.header-role { font-size: 12px; color: var(--hint); margin-top: 1px; }
.header-badge {
  margin-left: auto;
  font-size: 12px;
  padding: 3px 10px;
  border-radius: 20px;
  font-weight: 600;
}
.badge-free { background: rgba(255,255,255,0.1); color: var(--hint); }
.badge-paid { background: linear-gradient(135deg, #f59e0b, #f97316); color: #fff; }
.badge-admin { background: linear-gradient(135deg, #6c63ff, #a78bfa); color: #fff; }

/* ── Stats grid ── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  padding: 14px 12px 6px;
}
.stat-card {
  background: var(--bg2);
  border-radius: var(--radius-sm);
  padding: 12px 6px;
  text-align: center;
  cursor: pointer;
  transition: transform 0.15s, background 0.15s;
  border: 1px solid rgba(255,255,255,0.05);
}
.stat-card:active { transform: scale(0.95); background: rgba(108,99,255,0.15); }
.stat-icon { font-size: 22px; margin-bottom: 4px; }
.stat-value { font-size: 18px; font-weight: 700; color: var(--accent); }
.stat-label { font-size: 11px; color: var(--hint); margin-top: 2px; }

/* ── Pages ── */
.pages { flex: 1; overflow: hidden; }
.page { display: none; padding: 12px; animation: fadeIn 0.2s ease; }
.page.active { display: block; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ── Section title ── */
.section-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--hint);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin: 14px 0 8px;
  padding-left: 2px;
}

/* ── Card list ── */
.card-list { display: flex; flex-direction: column; gap: 8px; }

.card {
  background: var(--bg2);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  border: 1px solid rgba(255,255,255,0.06);
  transition: transform 0.1s;
}
.card:active { transform: scale(0.98); }

.card-row { display: flex; align-items: center; gap: 10px; }
.card-title { font-size: 15px; font-weight: 500; flex: 1; }
.card-sub { font-size: 12px; color: var(--hint); margin-top: 3px; }
.card-actions { display: flex; gap: 6px; margin-top: 10px; }

/* Task card */
.task-card { cursor: default; }
.task-done .card-title { text-decoration: line-through; opacity: 0.5; }
.priority-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.priority-high { background: var(--red); }
.priority-medium { background: var(--yellow); }
.priority-low { background: var(--green); }

.status-badge {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 20px;
  font-weight: 500;
}
.status-pending { background: rgba(245,158,11,0.15); color: var(--yellow); }
.status-in_progress { background: rgba(108,99,255,0.15); color: var(--accent); }
.status-done { background: rgba(34,197,94,0.15); color: var(--green); }

/* Habit card */
.habit-card { cursor: pointer; }
.habit-check { font-size: 22px; margin-left: auto; }
.streak-badge {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 20px;
  background: rgba(239,68,68,0.15);
  color: #f87171;
  font-weight: 600;
}

/* Finance */
.finance-overview, .finance-summary {
  background: var(--bg2);
  border-radius: var(--radius);
  padding: 16px;
  border: 1px solid rgba(255,255,255,0.06);
}
.finance-row { display: flex; justify-content: space-between; align-items: center; padding: 6px 0; }
.finance-label { color: var(--hint); font-size: 14px; }
.finance-value { font-weight: 700; font-size: 16px; }
.income-val { color: var(--green); }
.expense-val { color: var(--red); }
.balance-val { color: var(--accent); font-size: 20px; }
.balance-pos { color: var(--green); }
.balance-neg { color: var(--red); }
.divider { height: 1px; background: rgba(255,255,255,0.07); margin: 6px 0; }

.finance-btns { display: flex; gap: 10px; margin-bottom: 12px; }
.btn-income {
  flex: 1; padding: 14px;
  background: rgba(34,197,94,0.15);
  color: var(--green);
  border: 1px solid rgba(34,197,94,0.3);
  border-radius: var(--radius-sm);
  font-size: 15px; font-weight: 600; cursor: pointer;
  transition: background 0.15s;
}
.btn-income:active { background: rgba(34,197,94,0.25); }
.btn-expense {
  flex: 1; padding: 14px;
  background: rgba(239,68,68,0.15);
  color: var(--red);
  border: 1px solid rgba(239,68,68,0.3);
  border-radius: var(--radius-sm);
  font-size: 15px; font-weight: 600; cursor: pointer;
  transition: background 0.15s;
}
.btn-expense:active { background: rgba(239,68,68,0.25); }

.transaction-card { display: flex; align-items: center; gap: 12px; }
.t-icon { font-size: 22px; }
.t-info { flex: 1; }
.t-title { font-size: 14px; font-weight: 500; }
.t-date { font-size: 12px; color: var(--hint); }
.t-amount { font-size: 16px; font-weight: 700; }

/* Reminder card */
.reminder-card { display: flex; gap: 10px; align-items: flex-start; }
.reminder-icon { font-size: 20px; }
.reminder-info { flex: 1; }
.reminder-text { font-size: 14px; font-weight: 500; }
.reminder-time { font-size: 12px; color: var(--hint); margin-top: 2px; }

/* Note card */
.note-card { cursor: pointer; }
.note-title { font-size: 15px; font-weight: 600; }
.note-preview { font-size: 13px; color: var(--hint); margin-top: 4px; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.note-tags { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 8px; }
.tag { font-size: 11px; padding: 2px 8px; border-radius: 20px; background: rgba(108,99,255,0.15); color: var(--accent); }

/* ── Bottom nav ── */
.bottom-nav {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  display: flex;
  background: var(--bg2);
  border-top: 1px solid rgba(255,255,255,0.07);
  padding: 6px 0 max(6px, env(safe-area-inset-bottom));
  z-index: 20;
}
.nav-btn {
  flex: 1;
  display: flex; flex-direction: column; align-items: center;
  background: none; border: none; cursor: pointer;
  padding: 6px 4px;
  color: var(--hint);
  transition: color 0.15s;
  font-family: inherit;
}
.nav-btn.active { color: var(--accent); }
.nav-icon { font-size: 22px; }
.nav-label { font-size: 10px; margin-top: 2px; font-weight: 500; }

/* ── Page actions ── */
.page-actions {
  display: flex; gap: 8px; margin-bottom: 12px; align-items: center;
}

/* ── Buttons ── */
.btn-primary {
  background: var(--accent);
  color: var(--accent-text);
  border: none; border-radius: var(--radius-sm);
  padding: 10px 18px;
  font-size: 14px; font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.1s;
  font-family: inherit;
  white-space: nowrap;
}
.btn-primary:active { opacity: 0.85; transform: scale(0.97); }

.btn-secondary {
  background: rgba(255,255,255,0.08);
  color: var(--text);
  border: none; border-radius: var(--radius-sm);
  padding: 10px 18px;
  font-size: 14px; font-weight: 500;
  cursor: pointer;
  font-family: inherit;
}

.btn-sm {
  font-size: 12px;
  padding: 5px 12px;
  border-radius: 8px;
  border: none; cursor: pointer; font-family: inherit; font-weight: 500;
  transition: opacity 0.1s;
}
.btn-sm:active { opacity: 0.7; }
.btn-done { background: rgba(34,197,94,0.15); color: var(--green); }
.btn-progress { background: rgba(108,99,255,0.15); color: var(--accent); }
.btn-del { background: rgba(239,68,68,0.12); color: #f87171; }

/* ── Input ── */
.input {
  width: 100%;
  background: rgba(255,255,255,0.07);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  color: var(--text);
  font-size: 15px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s;
  margin-bottom: 10px;
}
.input:focus { border-color: var(--accent); }
.input::placeholder { color: var(--hint); }
textarea.input { resize: vertical; min-height: 80px; }
.search-input { flex: 1; margin-bottom: 0; }

/* ── Priority buttons ── */
.priority-row { display: flex; gap: 8px; margin-bottom: 10px; }
.priority-btn {
  flex: 1; padding: 8px 4px;
  background: rgba(255,255,255,0.07);
  border: 1.5px solid transparent;
  border-radius: 8px;
  color: var(--text);
  font-size: 12px; font-weight: 500;
  cursor: pointer; font-family: inherit;
  transition: background 0.1s, border-color 0.1s;
}
.priority-btn.active { border-color: var(--accent); background: rgba(108,99,255,0.15); color: var(--accent); }

/* ── Emoji picker ── */
.emoji-row {
  display: flex; flex-wrap: wrap; gap: 8px;
  margin-bottom: 12px;
  background: rgba(255,255,255,0.04);
  border-radius: 10px;
  padding: 10px;
}
.emoji-row span {
  font-size: 26px; cursor: pointer;
  transition: transform 0.1s;
  padding: 2px;
  border-radius: 6px;
}
.emoji-row span:active { transform: scale(1.3); }
.emoji-row span.selected { background: rgba(108,99,255,0.2); }

/* ── Modal ── */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex; align-items: flex-end;
  z-index: 50;
  padding: 0;
}
.modal.hidden { display: none; }
.modal-inner {
  background: var(--bg2);
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 20px 16px max(20px, env(safe-area-inset-bottom));
  width: 100%;
  animation: slideUp 0.25s ease;
}
@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}
.modal-title { font-size: 18px; font-weight: 700; margin-bottom: 16px; }
.modal-actions { display: flex; gap: 10px; margin-top: 6px; }
.modal-actions .btn-primary, .modal-actions .btn-secondary { flex: 1; }

/* ── Empty state ── */
.empty {
  text-align: center;
  padding: 32px 16px;
  color: var(--hint);
}
.empty-icon { font-size: 40px; margin-bottom: 8px; }
.empty-text { font-size: 14px; }

/* ── Toast ── */
.toast {
  position: fixed;
  bottom: 80px; left: 50%; transform: translateX(-50%);
  background: rgba(30,30,50,0.97);
  color: #fff;
  padding: 10px 20px;
  border-radius: 24px;
  font-size: 14px; font-weight: 500;
  box-shadow: var(--shadow);
  z-index: 100;
  white-space: nowrap;
  transition: opacity 0.3s;
  border: 1px solid rgba(108,99,255,0.3);
}
.toast.hidden { opacity: 0; pointer-events: none; }

/* ── Filter tabs ── */
.filter-tabs {
  display: flex; gap: 6px; margin-bottom: 10px;
}
.filter-tab {
  flex: 1; padding: 7px 4px;
  background: rgba(255,255,255,0.06);
  border: 1.5px solid transparent;
  border-radius: 8px;
  color: var(--hint);
  font-size: 13px; font-weight: 500;
  cursor: pointer; font-family: inherit;
  transition: all 0.15s;
}
.filter-tab.active {
  border-color: var(--accent);
  background: rgba(108,99,255,0.15);
  color: var(--accent);
}

/* ── Voice button ── */
.voice-btn {
  flex-shrink: 0;
  width: 42px; height: 42px;
  padding: 0;
  font-size: 20px;
  border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
}
.voice-text {
  font-size: 15px; color: var(--text);
  min-height: 40px;
  padding: 10px 0;
  line-height: 1.5;
}

/* ── Habit chart ── */
.habit-chart {
  background: var(--bg2);
  border-radius: var(--radius-sm);
  padding: 12px 10px;
  margin-bottom: 10px;
  border: 1px solid rgba(255,255,255,0.06);
}
.habit-chart.hidden { display: none; }
.chart-header {
  display: flex; align-items: center; gap: 6px;
  margin-bottom: 6px; padding-bottom: 6px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}
.chart-habit-col { width: 90px; flex-shrink: 0; }
.chart-days-col { display: flex; gap: 2px; flex: 1; }
.chart-pct-col { width: 34px; text-align: right; font-size: 11px; color: var(--hint); flex-shrink: 0; }
.chart-day-lbl { flex: 1; font-size: 9px; color: var(--hint); text-align: center; }
.chart-row {
  display: flex; align-items: center; gap: 6px;
  margin-bottom: 6px;
}
.chart-habit-name {
  width: 90px; flex-shrink: 0;
  font-size: 12px; font-weight: 500;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.chart-cell {
  flex: 1; height: 16px;
  border-radius: 3px;
}
.chart-cell.done { background: var(--green); }
.chart-cell.miss { background: rgba(255,255,255,0.07); }

/* ── Loader ── */
.loader {
  display: flex; align-items: center; justify-content: center;
  padding: 40px;
}
.spinner {
  width: 32px; height: 32px;
  border: 3px solid rgba(108,99,255,0.2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Pro page ── */
.pro-hero {
  display: flex; flex-direction: column; align-items: center;
  padding: 28px 16px 20px;
  gap: 8px;
}
.pro-badge {
  font-size: 36px; line-height: 1;
  background: linear-gradient(135deg, #ffd700, #ffb300);
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
  font-weight: 700;
}
.pro-status {
  font-size: 14px; color: var(--hint);
  text-align: center;
}
.pro-status.active { color: var(--green); font-weight: 600; }
.pro-features { display: flex; flex-direction: column; gap: 10px; padding-top: 6px; }
.pro-feature {
  display: flex; align-items: center; gap: 10px;
  font-size: 14px; color: var(--text);
}
.pro-cta {
  padding: 16px;
  display: flex; flex-direction: column; gap: 10px; align-items: center;
}
.pro-price {
  font-size: 20px; font-weight: 700; color: #ffd700;
  letter-spacing: 0.3px;
}
.btn-pro {
  width: 100%;
  padding: 15px;
  background: linear-gradient(135deg, #ffd700, #ff9500);
  color: #1a1a1a;
  border: none; border-radius: var(--radius-sm);
  font-size: 16px; font-weight: 700;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.1s;
  box-shadow: 0 4px 16px rgba(255, 185, 0, 0.35);
  letter-spacing: 0.2px;
}
.btn-pro:active { opacity: 0.85; transform: scale(0.98); }
.pro-hint {
  font-size: 12px; color: var(--hint);
  text-align: center; line-height: 1.4;
}
.pro-expiry {
  font-size: 16px; font-weight: 600; color: var(--green);
  letter-spacing: 0.2px;
}

/* ══════════════════════════════════════════════════════
   MODULE I3 — Knowledge Graph (vis-network, graphify look)
   ══════════════════════════════════════════════════════ */

/* Graph page fills the viewport below header/nav; dark navy like graphify.
   Definite (viewport-based) height so the vis-network canvas always has a size to
   render into — a % height collapsed to 0 in the Telegram WebView and the whole
   graph vanished. touch-action:none stops canvas pan/zoom gestures from also
   scrolling the page (which dragged the floating toolbar with it). */
#page-graph { padding: 0; position: relative; }

#graphWrap {
  position: relative;
  display: flex;
  height: calc(100dvh - 124px);   /* minus header + bottom nav (dvh = mobile-safe) */
  min-height: 320px;
  background: #0f0f1a;
  overflow: hidden;
}

.graph-canvas {
  flex: 1;
  height: 100%;
  background: #0f0f1a;
  outline: none;
  /* Keep canvas pan/zoom gestures from bubbling up as page scroll on touch. */
  touch-action: none;
  overscroll-behavior: contain;
}

/* ── Floating top toolbar over the canvas ── */
.graph-topbar {
  position: absolute;
  top: 10px; left: 10px; right: 10px;
  display: flex; gap: 8px; align-items: flex-start;
  z-index: 15;
}
.graph-search-wrap { flex: 1; position: relative; }
.graph-search {
  width: 100%;
  background: rgba(15,15,26,0.92);
  border: 1px solid #3a3a5e;
  color: #e0e0e0;
  padding: 9px 12px;
  border-radius: 8px;
  font-size: 13px; font-family: inherit;
  outline: none;
  backdrop-filter: blur(4px);
}
.graph-search:focus { border-color: #4E79A7; }
.graph-search::placeholder { color: #6a6a8a; }

.graph-search-results {
  display: none;
  position: absolute;
  top: 42px; left: 0; right: 0;
  max-height: 220px; overflow-y: auto;
  background: #1a1a2e;
  border: 1px solid #2a2a4e;
  border-radius: 8px;
  box-shadow: 0 8px 28px rgba(0,0,0,0.5);
}
.search-item {
  padding: 7px 8px; cursor: pointer; font-size: 13px; color: #ccc;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.search-item:hover { background: #2a2a4e; }

.graph-icon-btn {
  flex-shrink: 0;
  width: 40px; height: 40px;
  background: rgba(15,15,26,0.92);
  border: 1px solid #3a3a5e;
  border-radius: 8px;
  color: #e0e0e0; font-size: 18px;
  cursor: pointer; backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
  transition: border-color 0.15s, background 0.15s;
}
.graph-icon-btn:active { transform: scale(0.94); }
.graph-icon-btn.active-toggle {
  border-color: #59A14F; color: #59A14F;
  background: rgba(89,161,79,0.15);
}

/* ── Sidebar: right column (wide) / bottom-sheet (narrow) ── */
.graph-sidebar {
  width: 280px; flex-shrink: 0;
  background: #1a1a2e;
  border-left: 1px solid #2a2a4e;
  display: flex; flex-direction: column;
  overflow: hidden;
}
.sidebar-handle { display: none; }

.sidebar-section {
  padding: 12px 14px;
  border-bottom: 1px solid #2a2a4e;
}
.sidebar-grow { flex: 1; overflow-y: auto; }
.sidebar-h3 {
  font-size: 12px; color: #aaa; margin-bottom: 8px;
  text-transform: uppercase; letter-spacing: 0.05em;
}

/* Info panel */
.graph-info { font-size: 13px; color: #ccc; line-height: 1.5; }
.info-empty { color: #555; font-style: italic; }
.info-title { font-size: 15px; font-weight: 700; color: #fff; margin-bottom: 8px; }
.info-field {
  display: flex; justify-content: space-between;
  padding: 3px 0; font-size: 12px; color: #8a8aa5;
}
.info-field b { color: #e0e0e0; font-weight: 600; }
.info-tags { display: flex; flex-wrap: wrap; gap: 4px; margin: 6px 0; }
.info-tags .tag {
  font-size: 11px; padding: 2px 8px; border-radius: 20px;
  background: rgba(108,99,255,0.18); color: #a78bfa;
}
.info-actions { display: flex; gap: 6px; margin: 10px 0 6px; }
.info-actions .btn-sm { flex: 0 0 auto; }

.info-neighbors-title {
  margin-top: 8px; color: #aaa; font-size: 11px;
  text-transform: uppercase; letter-spacing: 0.04em;
}
.neighbors-list { max-height: 180px; overflow-y: auto; margin-top: 4px; }
.neighbor-link {
  display: block; padding: 4px 8px; margin: 3px 0;
  border-radius: 4px; cursor: pointer; font-size: 12px; color: #ccc;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  border-left: 3px solid #333; background: rgba(255,255,255,0.02);
}
.neighbor-link:hover { background: #2a2a4e; }

/* Note content box (markdown, expandable) */
.note-content-box {
  margin-top: 10px; padding-top: 10px;
  border-top: 1px solid #2a2a4e;
  font-size: 13px; line-height: 1.6; color: #ddd;
}
.note-content-box.hidden { display: none; }
.note-md p { margin: 0 0 6px; }
.note-md h1, .note-md h2, .note-md h3 { font-size: 14px; font-weight: 700; margin: 8px 0 4px; }
.note-md code { background: rgba(255,255,255,0.08); border-radius: 4px; padding: 1px 5px; font-size: 12px; }
.note-md pre { background: rgba(0,0,0,0.3); border-radius: 6px; padding: 8px; overflow-x: auto; font-size: 11px; }
.note-md-links { margin-top: 8px; display: flex; flex-wrap: wrap; gap: 6px; }
.link-section-title {
  width: 100%; font-size: 11px; font-weight: 600; color: #888;
  text-transform: uppercase; letter-spacing: 0.4px; margin-bottom: 2px;
}
.backlink-chip {
  font-size: 12px; padding: 3px 10px; border-radius: 20px;
  background: rgba(108,99,255,0.18); color: #a78bfa; cursor: pointer;
}
.backlink-chip:active { opacity: 0.7; }
.wikilink {
  color: #a78bfa; cursor: pointer;
  text-decoration: underline dotted; text-decoration-color: rgba(167,139,250,0.5);
}

/* Legend (graphify-style checkboxes) */
.legend-controls { margin-bottom: 8px; }
.legend-controls label {
  display: flex; align-items: center; gap: 6px; cursor: pointer;
  font-size: 12px; color: #aaa; user-select: none;
}
.graph-legend { display: flex; flex-direction: column; gap: 2px; }
.legend-item {
  display: flex; align-items: center; gap: 8px;
  padding: 5px 4px; cursor: pointer; border-radius: 4px; font-size: 12px;
}
.legend-item:hover { background: #2a2a4e; }
.legend-item.dimmed { opacity: 0.4; }
.legend-dot { width: 12px; height: 12px; border-radius: 50%; flex-shrink: 0; }
.legend-label { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: #ddd; }
.legend-count { color: #666; font-size: 11px; }

.legend-cb, #selectAllCb {
  appearance: none; -webkit-appearance: none;
  width: 15px; height: 15px; border: 1.5px solid #3a3a5e;
  border-radius: 3px; background: #0f0f1a; cursor: pointer;
  position: relative; flex-shrink: 0;
}
.legend-cb:checked, #selectAllCb:checked { background: #4E79A7; border-color: #4E79A7; }
.legend-cb:checked::after, #selectAllCb:checked::after {
  content: ''; position: absolute; left: 4px; top: 1px;
  width: 4px; height: 8px; border: solid #fff; border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}
#selectAllCb:indeterminate { background: #4E79A7; border-color: #4E79A7; }
#selectAllCb:indeterminate::after {
  content: ''; position: absolute; left: 2px; top: 6px;
  width: 9px; height: 2px; background: #fff; transform: none;
}

.graph-stats {
  padding: 9px 14px; border-top: 1px solid #2a2a4e;
  font-size: 11px; color: #666; flex-shrink: 0;
}
.graph-stat { display: inline-flex; align-items: center; gap: 3px; }

/* FAB (add knowledge note) */
.fab {
  position: absolute;
  bottom: 16px; left: 16px;
  width: 48px; height: 48px;
  background: #4E79A7; color: #fff;
  border: none; border-radius: 50%;
  font-size: 26px; line-height: 1; cursor: pointer;
  box-shadow: 0 4px 16px rgba(78,121,167,0.5);
  display: flex; align-items: center; justify-content: center;
  z-index: 14;
  transition: transform 0.15s;
}
.fab:active { transform: scale(0.92); }

/* Tall modal variant for note editor */
.modal-tall { max-height: 90vh; overflow-y: auto; }
.textarea-tall { min-height: 140px; }

/* ── Adaptive: narrow screens → sidebar becomes a bottom sheet ── */
@media (max-width: 700px) {
  .graph-sidebar {
    position: fixed;
    bottom: 56px; left: 0; right: 0;
    width: auto;
    max-height: 62vh;
    border-left: none;
    border-top: 1px solid #2a2a4e;
    border-radius: 16px 16px 0 0;
    transform: translateY(calc(100% + 70px));
    transition: transform 0.25s ease;
    z-index: 40;
    box-shadow: 0 -8px 30px rgba(0,0,0,0.5);
  }
  .graph-sidebar.open { transform: translateY(0); }
  .sidebar-handle {
    display: block;
    width: 40px; height: 4px;
    background: #3a3a5e; border-radius: 3px;
    margin: 8px auto 2px;
    cursor: pointer;
  }
  .sidebar-grow { max-height: 38vh; }
}

/* ══════════════════════════════════════════════════════
   MODULE I5/I6 — Analytics
   ══════════════════════════════════════════════════════ */

.analytics-cards {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  padding: 10px 12px 4px;
}

.analytics-card {
  background: var(--bg2);
  border-radius: var(--radius-sm);
  padding: 12px 10px 10px;
  border: 1px solid rgba(255,255,255,0.06);
  text-align: center;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
}
.analytics-card-icon { font-size: 22px; }
.analytics-card-value { font-size: 18px; font-weight: 700; }
.analytics-card-label { font-size: 11px; color: var(--hint); }

.analytics-rate-bar {
  width: 100%; height: 4px;
  background: rgba(255,255,255,0.08);
  border-radius: 2px;
  margin-top: 5px;
  overflow: hidden;
}
.analytics-rate-fill {
  height: 100%; border-radius: 2px;
  transition: width 0.5s ease;
}

.chart-wrap {
  margin: 0 12px;
  padding: 12px;
  background: var(--bg2);
  border-radius: var(--radius-sm);
  border: 1px solid rgba(255,255,255,0.06);
}

/* AI Insights card */
.insights-card {
  margin: 0 12px;
  padding: 14px;
  min-height: 80px;
}
.insights-text {
  font-size: 13px; line-height: 1.65; color: var(--text);
}
.insights-text strong { color: var(--accent); }
.insights-text em { color: var(--hint); }

/* ── Scrollable bottom nav (for 8 items) ── */
.bottom-nav {
  overflow-x: auto;
  scrollbar-width: none;
}
.bottom-nav::-webkit-scrollbar { display: none; }
.nav-btn {
  min-width: 56px;
  flex: none;
}

#page-analytics {
  padding-bottom: 20px;
}
