/**
 * ai.css
 * Styles for the AI view and shared AI pieces (AI-ONLINE-FEATURES-PLAN.md,
 * Phase 11): what-it-sends labels, citation buttons, suggestion review and
 * the usage table. Colours come from the surrounding theme where possible.
 */

/* ============================================
   AI VIEW
   ============================================ */
.ts-ai-intro {
  margin: 0 0 12px;
  font-size: 13px;
  line-height: 1.5;
  opacity: 0.85;
}

.ts-ai-sends {
  display: block;
  margin-top: 3px;
  font-size: 11.5px;
  opacity: 0.75;
}

.ts-ai-inline {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 10px;
  margin: 8px 0;
}
.ts-ai-inline .ts-ai-sends { margin-top: 0; }
.ts-ai-inline .ts-studio-hint { flex-basis: 100%; margin: 0; }

/* Visually hidden, still read by screen readers. */
.ts-ai-sr {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* ============================================
   CITATIONS
   ============================================ */
.ts-ai-cite {
  display: inline;
  margin: 0 1px;
  padding: 0 4px;
  border: 1px solid rgba(37, 99, 235, 0.45);
  border-radius: 4px;
  background: rgba(37, 99, 235, 0.08);
  color: inherit;
  font: inherit;
  font-size: 0.85em;
  cursor: pointer;
}
.ts-ai-cite:hover { background: rgba(37, 99, 235, 0.18); }
.ts-ai-cite:focus-visible { outline: 2px solid #2563eb; outline-offset: 1px; }

/* ============================================
   SUGGESTIONS
   ============================================ */
.ts-ai-suggestion {
  margin: 10px 0;
  padding: 10px 12px;
  border: 1px solid rgba(128, 128, 128, 0.35);
  border-radius: 8px;
}
.ts-ai-reason { margin: 0 0 6px; font-size: 12.5px; opacity: 0.85; }
.ts-ai-diff { margin: 0 0 8px; line-height: 1.6; white-space: pre-wrap; }
.ts-ai-diff ins {
  text-decoration: underline;
  text-decoration-thickness: 2px;
  background: rgba(22, 163, 74, 0.18);
}
.ts-ai-diff del {
  text-decoration: line-through;
  background: rgba(220, 38, 38, 0.15);
}

/* ============================================
   PLAN AND USAGE
   ============================================ */
.ts-ai-usage {
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px solid rgba(128, 128, 128, 0.3);
}
.ts-ai-usage h4 { margin: 0 0 4px; font-size: 14px; }
.ts-ai-plan { margin: 10px 0 6px; font-weight: 600; }
.ts-ai-usage-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.ts-ai-usage-table caption { text-align: left; padding: 4px 0; opacity: 0.8; }
.ts-ai-usage-table th,
.ts-ai-usage-table td {
  padding: 4px 6px;
  text-align: left;
  border-bottom: 1px solid rgba(128, 128, 128, 0.25);
}
.ts-ai-usage-table td { font-variant-numeric: tabular-nums; }

/* ============================================
   PHASE 12 — CHAT WITH THIS DOCUMENT
   ============================================ */
.ts-ai-chat {
  max-height: 55vh;
  overflow-y: auto;
  margin: 8px 0;
  padding-right: 4px;
}
.ts-ai-msg {
  margin: 8px 0;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid rgba(128, 128, 128, 0.3);
}
.ts-ai-msg-user { background: rgba(37, 99, 235, 0.07); }
.ts-ai-msg-who { margin: 0 0 2px; font-size: 11.5px; font-weight: 700; opacity: 0.7; text-transform: uppercase; letter-spacing: 0.03em; }
.ts-ai-msg-text p { margin: 4px 0; line-height: 1.5; }
.ts-ai-sources { list-style: none; margin: 6px 0 0; padding: 0; }
.ts-ai-sources li { margin: 3px 0; }
.ts-ai-source {
  display: block;
  width: 100%;
  text-align: left;
  padding: 4px 6px;
  border: 1px dashed rgba(37, 99, 235, 0.45);
  border-radius: 6px;
  background: transparent;
  color: inherit;
  font: inherit;
  font-size: 12.5px;
  cursor: pointer;
}
.ts-ai-source:hover { background: rgba(37, 99, 235, 0.08); }
.ts-ai-ask-row { display: flex; gap: 6px; align-items: stretch; }
.ts-ai-ask-row .ts-ai-question { flex: 1; min-width: 0; resize: vertical; }
.ts-ai-check { display: inline-flex; align-items: center; gap: 4px; margin: 6px 0; font-size: 13px; cursor: pointer; }
.ts-ai-chat-actions { flex-wrap: wrap; }

/* ============================================
   PHASE 12 — EXPLAIN AND WORD CARD POPOVER
   ============================================ */
.ts-ai-popover {
  position: fixed;
  z-index: 10050;
  max-height: 70vh;
  overflow-y: auto;
  padding: 10px 12px 12px;
  border-radius: 10px;
  border: 1px solid rgba(128, 128, 128, 0.4);
  background: var(--surface-1, #fff);
  color: var(--text-color, #1c2430);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
  font-size: 14px;
}
.ts-ai-popover-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.ts-ai-popover-title { margin: 0; font-size: 15px; }
.ts-ai-popover-close { border: 0; background: transparent; color: inherit; font-size: 16px; cursor: pointer; padding: 2px 6px; }
.ts-ai-selection { margin: 6px 0; font-style: italic; opacity: 0.85; }
.ts-ai-tabs { display: flex; flex-wrap: wrap; gap: 4px; margin: 6px 0; }
.ts-ai-tab {
  padding: 3px 8px;
  border: 1px solid rgba(128, 128, 128, 0.45);
  border-radius: 999px;
  background: transparent;
  color: inherit;
  font: inherit;
  font-size: 12.5px;
  cursor: pointer;
}
.ts-ai-tab[aria-pressed="true"] { background: #2563eb; border-color: #2563eb; color: #fff; }
.ts-ai-popover-result p { margin: 6px 0; line-height: 1.5; }
.ts-ai-example { font-style: italic; }
.ts-ai-word-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.ts-ai-word { margin: 4px 0; font-size: 20px; font-weight: 700; }
.ts-ai-syllables { margin: 0 0 4px; font-size: 13px; opacity: 0.8; letter-spacing: 0.02em; }
.ts-ai-pos { margin: 2px 0; font-size: 12px; font-style: italic; opacity: 0.75; }
.ts-ai-meaning { margin: 4px 0; line-height: 1.5; }
.ts-ai-figure { margin: 8px 0 4px; text-align: center; }
.ts-ai-figure img {
  max-width: 100%;
  max-height: 220px;
  object-fit: contain;
  border-radius: 6px;
  background: #fff;
}
.ts-ai-figure figcaption { margin-top: 4px; text-align: left; }
.ts-picture-credit { margin: 0; font-size: 11.5px; line-height: 1.4; opacity: 0.85; }
.ts-picture-credit a { color: inherit; text-decoration: underline; }
.ts-picture-credits { padding-left: 18px; }
.ts-picture-credits li { margin: 6px 0; }

/* ============================================
   PHASE 12 — GLOSSARY
   ============================================ */
.ts-ai-glossary { margin: 8px 0; }
.ts-ai-letter { margin: 12px 0 4px; font-size: 13px; opacity: 0.7; }
.ts-ai-term { padding: 6px 0; border-bottom: 1px solid rgba(128, 128, 128, 0.2); }
.ts-ai-term-head { margin: 0; display: flex; gap: 6px; align-items: baseline; flex-wrap: wrap; }
.ts-ai-term-kind { font-size: 11px; opacity: 0.7; font-style: italic; }
.ts-ai-glossary-tip { max-height: 40vh; }

/* The floating selection toolbar's extra tools share its look. */
.library-sel-toolbar .sel-tool-btn[hidden] { display: none; }

/* ---- AI Phase 13: library chat and comparing documents with AI ---- */
.ts-ai-honest { font-style: italic; }
.ts-ai-lib-chooser { max-height: 180px; overflow-y: auto; margin: 6px 0; padding: 4px 6px; border: 1px solid rgba(128, 128, 128, 0.3); border-radius: 6px; }
.ts-ai-lib-chooser[hidden] { display: none; }
.ts-ai-source-doc { font-weight: 600; }
.ts-ai-lib-ask { margin-top: 6px; }
.ts-ai-cmp-chosen { margin: 4px 0; font-weight: 600; }
.ts-ai-cmp-docs { margin: 4px 0 10px; padding-left: 1.4em; }
.ts-ai-cmp-docs p { margin: 2px 0 6px; }
.ts-ai-cmp-scroll { overflow-x: auto; max-width: 100%; margin: 8px 0; }
.ts-ai-cmp-table { border-collapse: collapse; width: 100%; font-size: 13.5px; }
.ts-ai-cmp-table caption { text-align: left; font-weight: 700; padding: 4px 0; }
.ts-ai-cmp-table th,
.ts-ai-cmp-table td { border: 1px solid rgba(128, 128, 128, 0.35); padding: 6px 8px; vertical-align: top; text-align: left; min-width: 140px; }
.ts-ai-cmp-table thead th { background: rgba(128, 128, 128, 0.12); }
.ts-ai-cmp-table td p { margin: 4px 0; line-height: 1.45; }
.ts-ai-cmp-table td[data-stance="agrees"] { background: rgba(26, 127, 55, 0.1); }
.ts-ai-cmp-table td[data-stance="differs"] { background: rgba(154, 103, 0, 0.12); }
.ts-ai-cmp-table td[data-stance="adds"] { background: rgba(29, 78, 216, 0.1); }
.ts-ai-cmp-table td[data-stance="silent"] { opacity: 0.8; }
.ts-ai-quotes { list-style: none; margin: 4px 0 0; padding: 0; }
.ts-ai-quotes li { margin: 3px 0; }
.ts-ai-quote { font-style: italic; opacity: 0.85; }
.ts-ai-cmp-gaps { padding-left: 1.2em; }

/* ---- AI Phase 14: writing tools ---- */
.ts-ai-engine { margin: 0.75rem 0; padding: 0.5rem 0.75rem; border: 1px solid rgba(128, 128, 128, 0.35); border-radius: 6px; }
.ts-ai-engine legend { padding: 0 4px; font-size: 0.85rem; }
.ts-ai-engine label { display: block; margin: 0.25rem 0; cursor: pointer; }
#tsAITranslatePicker[hidden] { display: none; }
.ts-ai-engine-note { font-size: 0.8rem; opacity: 0.8; }
.ts-ai-prefs-area { width: 100%; box-sizing: border-box; resize: vertical; }
.ts-ai-prefs-preview { white-space: pre-wrap; font-size: 12px; padding: 6px 8px; border-radius: 6px; background: rgba(128, 128, 128, 0.12); max-height: 200px; overflow: auto; }
.ts-ai-section { border-left: 3px solid rgba(37, 99, 235, 0.5); padding: 4px 8px; margin: 10px 0; }
.ts-ai-section h4 { margin: 0 0 4px; }
.ts-ai-section blockquote { margin: 4px 0; padding: 4px 8px; background: rgba(128, 128, 128, 0.1); border-radius: 4px; }
.ts-ai-section p { margin: 4px 0; line-height: 1.5; }
.ts-ai-from { border: 0; background: transparent; color: inherit; font-size: 12px; text-decoration: underline; cursor: pointer; padding: 0; opacity: 0.8; }
.ts-ai-grammar { margin-top: 14px; }
.ts-ai-table-scroll { overflow-x: auto; max-width: 100%; margin: 8px 0; }
.ts-ai-table-editor { border-collapse: collapse; width: 100%; }
.ts-ai-table-editor th,
.ts-ai-table-editor td { border: 1px solid rgba(128, 128, 128, 0.35); padding: 2px; }
.ts-ai-table-editor input { width: 100%; min-width: 80px; box-sizing: border-box; padding: 4px; border: 0; background: transparent; color: inherit; font: inherit; }
.ts-ai-table-editor th input { font-weight: 700; }

/* ---- AI Phase 15: study with AI ---- */
.ts-study-ai-tools { display: grid; gap: 6px; }
.ts-study-ai-field { margin: 4px 0; }
.ts-study-ai-field label { display: block; font-size: 12.5px; margin-bottom: 2px; }
.ts-study-ai-field textarea { width: 100%; box-sizing: border-box; resize: vertical; }
.ts-study-ai-cards { padding-left: 1.4em; }
.ts-study-ai-card { margin: 10px 0; padding: 8px; border: 1px solid rgba(128, 128, 128, 0.3); border-radius: 8px; }
.ts-study-ai-source { margin: 6px 0; padding: 6px 10px; border-left: 3px solid rgba(128, 128, 128, 0.5); max-height: 8em; overflow: auto; }
.ts-study-ai-saved { padding-left: 1.2em; }
.ts-study-ai-saved li { margin: 4px 0; }
.ts-ai-quiz { padding-left: 1.4em; }
.ts-ai-quiz-q fieldset { border: 1px solid rgba(128, 128, 128, 0.3); border-radius: 8px; margin: 8px 0; padding: 8px 10px; }
.ts-ai-quiz-q legend { font-weight: 600; padding: 0 4px; }
.ts-ai-quiz-option { display: block; margin: 4px 0; cursor: pointer; }
.ts-ai-quiz-q textarea { width: 100%; box-sizing: border-box; }
.ts-ai-quiz-score { font-size: 16px; font-weight: 700; }
.ts-ai-quiz-result { margin: 10px 0; padding: 8px 10px; border-left: 4px solid rgba(128, 128, 128, 0.5); border-radius: 4px; }
.ts-ai-quiz-result[data-score="2"] { border-left-color: #16a34a; }
.ts-ai-quiz-result[data-score="1"] { border-left-color: #d97706; }
.ts-ai-quiz-result[data-score="0"] { border-left-color: #dc2626; }
.ts-ai-quiz-verdict { margin: 0; font-weight: 700; }
.ts-map-toolbar { margin: 6px 0; }
.ts-map-canvas { overflow: auto; max-width: 100%; max-height: 60vh; border: 1px solid rgba(128, 128, 128, 0.3); border-radius: 8px; background: #ffffff; }
.ts-map-canvas:focus-visible { outline: 3px solid #2563eb; outline-offset: 2px; }
.ts-map-node { cursor: pointer; }
.ts-ai-notes-section h4 { margin: 12px 0 4px; }
.ts-ai-notes-section li { margin: 4px 0; }
.is-late { color: #b42318; }
.ts-study-pack-part { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 6px 0; }
.ts-study-pack-state { font-size: 12.5px; opacity: 0.85; }
.hl-notes-btn { margin-right: auto; }

/* ---- AI Phase 16: plans and credits ---- */
.ts-plan-packs { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0; }
.ts-plan-credits { font-weight: 700; }
