/* ===== AI Layer Variables ===== */
:root {
  --ai-purple: #7c3aed;
  --ai-purple-light: #f5f3ff;
  --ai-purple-border: #ddd6fe;
  --ai-purple-dark: #5b21b6;
}

/* ===== API Key Modal ===== */
.ai-key-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
}
.ai-key-overlay.hidden { display: none; }
.ai-key-modal {
  background: var(--card-bg);
  border-radius: 12px;
  padding: 32px;
  max-width: 420px;
  width: 90%;
  box-shadow: 0 20px 60px rgba(0,0,0,0.15);
}
.ai-key-modal h3 {
  font-size: 1.1rem;
  font-weight: 700;
  margin-bottom: 8px;
}
.ai-key-modal p {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-bottom: 16px;
  line-height: 1.6;
}
.ai-key-modal input {
  width: 100%;
  padding: 10px 14px;
  border: 1.5px solid var(--border);
  border-radius: 6px;
  font-family: var(--mono);
  font-size: 0.85rem;
  direction: ltr;
  margin-bottom: 12px;
}
.ai-key-modal input:focus {
  outline: none;
  border-color: var(--ai-purple);
}
.ai-key-modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-start;
}
.ai-key-save {
  padding: 8px 20px;
  background: var(--ai-purple);
  color: #fff;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-family: var(--font);
  font-size: 0.85rem;
  font-weight: 500;
}
.ai-key-save:hover { background: var(--ai-purple-dark); }
.ai-key-cancel {
  padding: 8px 16px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  font-family: var(--font);
  font-size: 0.85rem;
  color: var(--text-secondary);
}

/* ===== Selection Tooltip ===== */
.ai-tooltip {
  position: absolute;
  z-index: 500;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.12);
  padding: 4px;
  display: flex;
  gap: 2px;
}
.ai-tooltip.hidden { display: none; }
.ai-tooltip button {
  padding: 6px 12px;
  border: none;
  background: transparent;
  border-radius: 6px;
  cursor: pointer;
  font-family: var(--font);
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--ai-purple);
  white-space: nowrap;
  transition: background 0.15s;
}
.ai-tooltip button:hover {
  background: var(--ai-purple-light);
}

/* ===== AI Callout (inline responses) ===== */
.ai-callout {
  background: var(--ai-purple-light);
  border: 1px solid var(--ai-purple-border);
  border-radius: var(--radius);
  padding: 14px 18px;
  margin: 14px 0;
  font-size: 0.9rem;
  line-height: 1.7;
  position: relative;
}
.ai-callout-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}
.ai-callout-label {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--ai-purple);
  display: flex;
  align-items: center;
  gap: 4px;
}
.ai-callout-close {
  width: 24px;
  height: 24px;
  border: none;
  background: transparent;
  cursor: pointer;
  font-size: 1rem;
  color: var(--text-secondary);
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.ai-callout-close:hover { background: rgba(0,0,0,0.05); }
.ai-callout-body {
  color: var(--text);
}
.ai-callout-body p { margin-bottom: 8px; }
.ai-callout-body p:last-child { margin-bottom: 0; }

/* Streaming cursor */
.ai-streaming::after {
  content: '\25CF';
  color: var(--ai-purple);
  animation: ai-blink 0.6s infinite alternate;
  margin-inline-start: 2px;
}
@keyframes ai-blink { from { opacity: 1; } to { opacity: 0.2; } }

/* ===== Quick-Action Toolbar ===== */
.prose-block {
  position: relative;
}
.ai-quick-bar {
  position: absolute;
  top: 4px;
  left: 4px;
  display: flex;
  gap: 4px;
  opacity: 0;
  transition: opacity 0.2s;
  pointer-events: none;
  z-index: 50;
}
.prose-block:hover .ai-quick-bar {
  opacity: 1;
  pointer-events: auto;
}
.ai-quick-btn {
  padding: 4px 10px;
  border: 1px solid var(--ai-purple-border);
  background: var(--card-bg);
  border-radius: 6px;
  cursor: pointer;
  font-family: var(--font);
  font-size: 0.7rem;
  font-weight: 500;
  color: var(--ai-purple);
  white-space: nowrap;
  transition: all 0.15s;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}
.ai-quick-btn:hover {
  background: var(--ai-purple-light);
  border-color: var(--ai-purple);
}

/* ===== Side Chat Panel ===== */
.ai-chat-panel {
  position: fixed;
  top: 0;
  left: 0;
  width: 400px;
  height: 100%;
  background: var(--card-bg);
  border-right: 1px solid var(--border);
  box-shadow: 4px 0 24px rgba(0,0,0,0.08);
  z-index: 900;
  display: flex;
  flex-direction: column;
  transform: translateX(-100%);
  transition: transform 0.25s ease;
}
.ai-chat-panel.open {
  transform: translateX(0);
}
.ai-chat-header {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}
.ai-chat-header-title {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--ai-purple);
  display: flex;
  align-items: center;
  gap: 6px;
}
.ai-chat-close {
  width: 32px;
  height: 32px;
  border: none;
  background: transparent;
  cursor: pointer;
  font-size: 1.2rem;
  color: var(--text-secondary);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.ai-chat-close:hover { background: #f3f4f6; }
.ai-chat-context {
  padding: 10px 18px;
  background: #f9fafb;
  border-bottom: 1px solid var(--border);
  font-size: 0.78rem;
  color: var(--text-secondary);
  line-height: 1.5;
  max-height: 80px;
  overflow-y: auto;
  flex-shrink: 0;
}
.ai-chat-context strong {
  color: var(--text);
  font-weight: 600;
}
.ai-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 14px 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.ai-chat-msg {
  max-width: 92%;
  padding: 10px 14px;
  border-radius: 10px;
  font-size: 0.88rem;
  line-height: 1.65;
  word-break: break-word;
}
.ai-chat-msg.user {
  background: var(--accent-light);
  color: var(--text);
  align-self: flex-end;
  border-bottom-left: 4px;
}
.ai-chat-msg.assistant {
  background: var(--ai-purple-light);
  color: var(--text);
  align-self: flex-start;
  border-bottom-right: 4px;
}
.ai-chat-msg.assistant p { margin-bottom: 6px; }
.ai-chat-msg.assistant p:last-child { margin-bottom: 0; }
.ai-chat-input-row {
  padding: 12px 18px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}
.ai-chat-input {
  flex: 1;
  padding: 8px 12px;
  border: 1.5px solid var(--border);
  border-radius: 6px;
  font-family: var(--font);
  font-size: 0.88rem;
  resize: none;
  min-height: 38px;
  max-height: 100px;
}
.ai-chat-input:focus { outline: none; border-color: var(--ai-purple); }
.ai-chat-send {
  padding: 8px 16px;
  background: var(--ai-purple);
  color: #fff;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-family: var(--font);
  font-size: 0.85rem;
  font-weight: 500;
  flex-shrink: 0;
}
.ai-chat-send:hover { background: var(--ai-purple-dark); }
.ai-chat-send:disabled { opacity: 0.5; cursor: not-allowed; }

/* Suggest improvement button inside chat */
.ai-chat-suggest-btn {
  margin-top: 8px;
  padding: 6px 14px;
  background: transparent;
  border: 1px solid var(--ai-purple-border);
  border-radius: 6px;
  color: var(--ai-purple);
  font-family: var(--font);
  font-size: 0.78rem;
  font-weight: 500;
  cursor: pointer;
}
.ai-chat-suggest-btn:hover { background: var(--ai-purple-light); }

/* Improvement diff */
.ai-improve-box {
  margin: 10px 0;
  border: 1px solid var(--ai-purple-border);
  border-radius: 8px;
  overflow: hidden;
}
.ai-improve-preview {
  padding: 12px 14px;
  font-size: 0.82rem;
  line-height: 1.6;
  max-height: 200px;
  overflow-y: auto;
  background: #fefefe;
}
.ai-improve-actions {
  display: flex;
  gap: 6px;
  padding: 8px 14px;
  border-top: 1px solid var(--ai-purple-border);
  background: #f9fafb;
}
.ai-improve-accept {
  padding: 5px 14px;
  background: var(--green);
  color: #fff;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-family: var(--font);
  font-size: 0.78rem;
}
.ai-improve-discard {
  padding: 5px 14px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 4px;
  cursor: pointer;
  font-family: var(--font);
  font-size: 0.78rem;
  color: var(--text-secondary);
}

/* ===== Fix Feedback UI ===== */
.ai-fix-prompt {
  margin: 10px 0;
  padding: 10px 14px;
  background: #fef9f0;
  border: 1px solid #f0c674;
  border-radius: 8px;
}
.ai-fix-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text);
}
.ai-fix-cancel {
  padding: 2px 10px;
  border: none;
  background: transparent;
  cursor: pointer;
  font-family: var(--font);
  font-size: 0.78rem;
  color: var(--text-secondary);
  border-radius: 4px;
}
.ai-fix-cancel:hover { background: rgba(0,0,0,0.05); }
.ai-fix-row {
  display: flex;
  gap: 6px;
}
.ai-fix-input {
  flex: 1;
  padding: 7px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-family: var(--font);
  font-size: 0.82rem;
  outline: none;
}
.ai-fix-input:focus { border-color: var(--ai-purple); box-shadow: 0 0 0 2px rgba(124,58,237,0.12); }
.ai-fix-send {
  padding: 7px 16px;
  background: var(--ai-purple);
  color: #fff;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-family: var(--font);
  font-size: 0.82rem;
  font-weight: 500;
  white-space: nowrap;
}
.ai-fix-send:hover { opacity: 0.9; }
.ai-fix-loading {
  margin: 10px 0;
  padding: 10px 14px;
  font-size: 0.82rem;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 8px;
}
.ai-fix-spinner {
  display: inline-block;
  width: 16px; height: 16px;
  border: 2px solid var(--ai-purple-light);
  border-top-color: var(--ai-purple);
  border-radius: 50%;
  animation: ai-spin 0.7s linear infinite;
}
@keyframes ai-spin { to { transform: rotate(360deg); } }
.ai-fix-box {
  margin: 10px 0;
  border: 1px solid #f0c674;
  border-radius: 8px;
  overflow: hidden;
}
.ai-fix-box-header {
  padding: 8px 14px;
  font-size: 0.82rem;
  font-weight: 600;
  background: #fef9f0;
  border-bottom: 1px solid #f0c674;
}
.ai-fix-preview {
  padding: 12px 14px;
  font-size: 0.78rem;
  line-height: 1.5;
  max-height: 250px;
  overflow-y: auto;
  background: #fefefe;
  white-space: pre-wrap;
  font-family: monospace;
  direction: ltr;
}
.ai-fix-error {
  margin: 8px 0;
  padding: 8px 14px;
  background: #fef2f2;
  border: 1px solid #fecaca;
  border-radius: 6px;
  font-size: 0.82rem;
  color: #dc2626;
}
.ai-fix-applied {
  animation: ai-fix-flash 1.5s ease;
}
@keyframes ai-fix-flash {
  0% { box-shadow: 0 0 0 3px rgba(34,197,94,0.4); }
  100% { box-shadow: none; }
}

/* Dark mode for fix UI */
[data-theme="dark"] .ai-fix-prompt { background: #2a2215; border-color: #5a4a2a; }
[data-theme="dark"] .ai-fix-input { background: #1e1e2e; color: var(--text); border-color: #3a3a4a; }
[data-theme="dark"] .ai-fix-box { border-color: #5a4a2a; }
[data-theme="dark"] .ai-fix-box-header { background: #2a2215; border-color: #5a4a2a; }
[data-theme="dark"] .ai-fix-preview { background: #1e1e2e; color: #d4d4d4; }
[data-theme="dark"] .ai-fix-error { background: #2d1515; border-color: #5a2020; color: #f87171; }
[data-theme="dark"] .ai-fix-cancel:hover { background: rgba(255,255,255,0.1); }

/* ===== Wrong-Answer Tutor ===== */
.ai-tutor-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-top: 10px;
  padding: 6px 14px;
  background: transparent;
  border: 1px solid currentColor;
  border-radius: 6px;
  cursor: pointer;
  font-family: var(--font);
  font-size: 0.8rem;
  font-weight: 500;
  color: inherit;
  opacity: 0.8;
}
.ai-tutor-btn:hover { opacity: 1; background: rgba(255,255,255,0.3); }

.ai-tutor-response {
  margin-top: 12px;
  padding: 12px 16px;
  background: rgba(255,255,255,0.5);
  border-radius: var(--radius);
  font-size: 0.86rem;
  line-height: 1.7;
}

.ai-similar-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-top: 10px;
  padding: 6px 14px;
  background: var(--ai-purple);
  color: #fff;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-family: var(--font);
  font-size: 0.8rem;
  font-weight: 500;
}
.ai-similar-btn:hover { background: var(--ai-purple-dark); }

/* ===== Exam Question Generator ===== */
.ai-gen-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 16px;
  background: var(--ai-purple-light);
  border: 1px solid var(--ai-purple-border);
  border-radius: 6px;
  color: var(--ai-purple);
  font-family: var(--font);
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
}
.ai-gen-btn:hover { background: #ede9fe; border-color: var(--ai-purple); }
.ai-gen-btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ===== Smart Summary ===== */
.ai-summary-section {
  background: var(--ai-purple-light);
  border: 1px solid var(--ai-purple-border);
  border-radius: var(--radius);
  padding: 20px 24px;
  margin-bottom: 32px;
}
.ai-summary-title {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--ai-purple);
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.ai-summary-body {
  font-size: 0.9rem;
  line-height: 1.75;
  color: var(--text);
}
.ai-summary-body h3 { margin: 12px 0 6px; font-size: 0.95rem; }
.ai-summary-body ul { padding-right: 20px; margin: 6px 0; }
.ai-summary-body li { margin-bottom: 4px; }

.ai-summary-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 20px;
  background: var(--ai-purple);
  color: #fff;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-family: var(--font);
  font-size: 0.88rem;
  font-weight: 500;
  margin-top: 16px;
}
.ai-summary-btn:hover { background: var(--ai-purple-dark); }
.ai-summary-btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ===== Improved Prose Block Overlay ===== */
.prose-block--improved {
  position: relative;
}
.prose-block--improved::before {
  content: 'AI improved';
  position: absolute;
  top: -8px;
  left: 8px;
  font-size: 0.6rem;
  font-weight: 700;
  color: var(--ai-purple);
  background: var(--card-bg);
  padding: 0 6px;
  border-radius: 4px;
  border: 1px solid var(--ai-purple-border);
}

/* ===== Chat Panel Overlay (dim background) ===== */
.ai-chat-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.2);
  z-index: 899;
  transition: opacity 0.25s;
}
.ai-chat-backdrop.hidden { display: none; }

/* ===== Markdown Rendering in AI Responses ===== */
.ai-callout-body table,
.ai-chat-msg.assistant table,
.ai-tutor-response table {
  width: 100%;
  border-collapse: collapse;
  margin: 10px 0;
  font-size: 0.85rem;
  direction: rtl;
}
.ai-callout-body th,
.ai-chat-msg.assistant th,
.ai-tutor-response th {
  background: rgba(124, 58, 237, 0.08);
  font-weight: 600;
  text-align: right;
  padding: 8px 12px;
  border: 1px solid var(--ai-purple-border);
}
.ai-callout-body td,
.ai-chat-msg.assistant td,
.ai-tutor-response td {
  padding: 6px 12px;
  border: 1px solid var(--border);
  text-align: right;
}
.ai-callout-body tr:nth-child(even),
.ai-chat-msg.assistant tr:nth-child(even),
.ai-tutor-response tr:nth-child(even) {
  background: rgba(0, 0, 0, 0.02);
}
.ai-callout-body h2,
.ai-chat-msg.assistant h2,
.ai-tutor-response h2 {
  font-size: 1.05rem;
  font-weight: 700;
  margin: 12px 0 6px;
}
.ai-callout-body h3,
.ai-chat-msg.assistant h3,
.ai-tutor-response h3 {
  font-size: 0.95rem;
  font-weight: 600;
  margin: 10px 0 4px;
}
.ai-callout-body h4,
.ai-chat-msg.assistant h4,
.ai-tutor-response h4 {
  font-size: 0.88rem;
  font-weight: 600;
  margin: 8px 0 4px;
}
.ai-callout-body ul,
.ai-chat-msg.assistant ul,
.ai-tutor-response ul,
.ai-callout-body ol,
.ai-chat-msg.assistant ol,
.ai-tutor-response ol {
  padding-right: 20px;
  margin: 6px 0;
}
.ai-callout-body li,
.ai-chat-msg.assistant li,
.ai-tutor-response li {
  margin-bottom: 3px;
}
.ai-callout-body code,
.ai-chat-msg.assistant code,
.ai-tutor-response code {
  background: rgba(0, 0, 0, 0.06);
  padding: 1px 5px;
  border-radius: 3px;
  font-family: var(--mono);
  font-size: 0.85em;
}
.ai-callout-body p,
.ai-chat-msg.assistant p,
.ai-tutor-response p {
  margin-bottom: 6px;
}
.ai-callout-body p:last-child,
.ai-chat-msg.assistant p:last-child,
.ai-tutor-response p:last-child {
  margin-bottom: 0;
}

/* ===== Saved Highlight Mark ===== */
.ai-highlight {
  background: #fef08a;
  border-bottom: 2px solid #eab308;
  border-radius: 2px;
  padding: 0 1px;
  cursor: pointer;
  transition: background 0.15s;
}
.ai-highlight:hover {
  background: #fde047;
}
/* Delete tooltip that appears on highlight click */
.ai-hl-delete-tip {
  position: absolute;
  z-index: 501;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.12);
  padding: 4px;
  display: flex;
  gap: 2px;
}
.ai-hl-delete-tip button {
  padding: 6px 12px;
  border: none;
  background: transparent;
  border-radius: 6px;
  cursor: pointer;
  font-family: var(--font);
  font-size: 0.78rem;
  font-weight: 500;
  color: #dc2626;
  white-space: nowrap;
  transition: background 0.15s;
}
.ai-hl-delete-tip button:hover {
  background: #fef2f2;
}

/* ===== Highlight Badge ===== */
.hl-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  background: var(--ai-purple);
  color: #fff;
  border-radius: 10px;
  font-size: 0.7rem;
  font-weight: 700;
  margin-inline-start: 6px;
}

/* ===== Highlight Quiz Container ===== */
.highlight-quiz-container {
  background: var(--ai-purple-light);
  border: 1px solid var(--ai-purple-border);
  border-radius: var(--radius);
  padding: 20px 24px;
  margin-bottom: 32px;
}
.highlight-quiz-title {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--ai-purple);
  margin-bottom: 14px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.home-action-highlights {
  background: var(--ai-purple-light);
  border: 1.5px solid var(--ai-purple-border);
  color: var(--ai-purple);
}
.home-action-highlights:hover {
  background: #ede9fe;
  border-color: var(--ai-purple);
}
.ai-hl-clear-btn {
  margin-top: 12px;
  padding: 6px 14px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  font-family: var(--font);
  font-size: 0.78rem;
  color: var(--text-secondary);
}
.ai-hl-clear-btn:hover {
  border-color: #ef4444;
  color: #ef4444;
}

/* ===== Memory Aid ("תזכור לי") ===== */
.ai-remember-section {
  background: linear-gradient(135deg, #fffbeb 0%, #fef3c7 100%);
  border: 1px solid #fbbf24;
  border-radius: var(--radius);
  padding: 20px 24px;
  margin: 24px 0 32px;
}
.ai-remember-title {
  font-size: 0.85rem;
  font-weight: 700;
  color: #92400e;
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.ai-remember-body {
  font-size: 0.9rem;
  line-height: 1.75;
  color: var(--text);
}
.ai-remember-body h2 { font-size: 1.05rem; font-weight: 700; margin: 14px 0 6px; color: #92400e; }
.ai-remember-body h3 { font-size: 0.95rem; font-weight: 600; margin: 10px 0 4px; color: #b45309; }
.ai-remember-body ul { padding-right: 20px; margin: 6px 0; }
.ai-remember-body li { margin-bottom: 6px; }
.ai-remember-body p { margin-bottom: 6px; }
.ai-remember-body p:last-child { margin-bottom: 0; }
.ai-remember-body strong { color: #92400e; }
.ai-remember-body code {
  background: rgba(180, 83, 9, 0.08);
  padding: 1px 5px;
  border-radius: 3px;
  font-family: var(--mono);
  font-size: 0.85em;
}

.ai-remember-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 16px;
  background: #fffbeb;
  border: 1px solid #fbbf24;
  border-radius: 6px;
  color: #92400e;
  font-family: var(--font);
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  margin-inline-start: 6px;
}
.ai-remember-btn:hover { background: #fef3c7; border-color: #f59e0b; }
.ai-remember-btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ===== Dark Mode ===== */
[data-theme="dark"] {
  --ai-purple: #a78bfa;
  --ai-purple-light: #1e1b3a;
  --ai-purple-border: #3b327a;
  --ai-purple-dark: #7c3aed;
}
[data-theme="dark"] .ai-chat-context { background: #1a1a2e; }
[data-theme="dark"] .ai-chat-close:hover { background: rgba(255,255,255,0.1); }
[data-theme="dark"] .ai-callout-close:hover { background: rgba(255,255,255,0.1); }
[data-theme="dark"] .ai-improve-preview { background: #1e293b; }
[data-theme="dark"] .ai-improve-actions { background: #1a1a2e; }
[data-theme="dark"] .ai-tutor-response { background: rgba(255,255,255,0.08); }
[data-theme="dark"] .ai-tooltip button:hover { background: #2d2655; }
[data-theme="dark"] .ai-quick-btn:hover { background: #2d2655; }
[data-theme="dark"] .ai-gen-btn:hover { background: #2d2655; }
[data-theme="dark"] .ai-chat-suggest-btn:hover { background: #2d2655; }
[data-theme="dark"] .ai-hl-delete-tip button:hover { background: #450a0a; }
[data-theme="dark"] .ai-highlight { background: #854d0e; border-bottom-color: #a16207; }
[data-theme="dark"] .ai-highlight:hover { background: #a16207; }
[data-theme="dark"] .ai-callout-body code,
[data-theme="dark"] .ai-chat-msg.assistant code,
[data-theme="dark"] .ai-tutor-response code { background: rgba(255,255,255,0.1); }
[data-theme="dark"] .ai-callout-body tr:nth-child(even),
[data-theme="dark"] .ai-chat-msg.assistant tr:nth-child(even),
[data-theme="dark"] .ai-tutor-response tr:nth-child(even) { background: rgba(255,255,255,0.03); }
[data-theme="dark"] .home-action-highlights { background: #1e1b3a; border-color: #3b327a; color: #a78bfa; }
[data-theme="dark"] .home-action-highlights:hover { background: #2d2655; border-color: #a78bfa; }
[data-theme="dark"] .ai-remember-section { background: linear-gradient(135deg, #1c1a0e 0%, #292211 100%); border-color: #854d0e; }
[data-theme="dark"] .ai-remember-title { color: #fbbf24; }
[data-theme="dark"] .ai-remember-body h2 { color: #fbbf24; }
[data-theme="dark"] .ai-remember-body h3 { color: #f59e0b; }
[data-theme="dark"] .ai-remember-body strong { color: #fbbf24; }
[data-theme="dark"] .ai-remember-body code { background: rgba(251, 191, 36, 0.12); }
[data-theme="dark"] .ai-remember-btn { background: #1c1a0e; border-color: #854d0e; color: #fbbf24; }
[data-theme="dark"] .ai-remember-btn:hover { background: #292211; border-color: #f59e0b; }

/* ===== Responsive ===== */
@media (max-width: 700px) {
  .ai-chat-panel { width: 100%; }
  .ai-quick-bar { display: none; }
  .ai-tooltip { transform: scale(0.9); }
}
