/* KAIROS ACADEMY TECH — teacher AI module
 * public/shared/css/tetra-ai-module.css
 *
 * Prefix: .ai-*   (the retired Studio used .ss-*; the v2 prototype used bare
 * names that leaked into the global scope. Neither is reused here.)
 *
 * TWO THINGS THIS FILE DELIBERATELY DOES NOT DO
 *
 * 1. It does not define its own palette. The Tetrahedron skin
 *    (tetra-kairos-skin.css) is a DARK theme and publishes real tokens on
 *    :root — --bg, --panel, --line, --text, --muted. This module consumes those
 *    rather than hardcoding colors, so it stays legible if the skin is retuned
 *    and cannot drift into the white-card-on-black-canvas state an independent
 *    palette produced. Fallbacks keep the file sane if loaded standalone.
 *
 * 2. It does not hardcode a tutor's color. --ai-accent is set inline from the
 *    teacher's chosen guide (GUIDE_ACCENT in kairos-guides.js), so swapping the
 *    guide repaints the module instead of requiring a second stylesheet.
 *
 * Load order: after tetra-shell-v2.css, before tetra-kairos-skin.css — matching
 * the portal's established cascade. The skin still wins on shell chrome, which
 * is why everything here reads its colors FROM the skin's tokens.
 */

.ai-page {
  /* Overwritten inline per-guide; socrates violet is only the fallback. */
  --ai-accent: #7b6cf6;

  --ai-text:  var(--text,  #f4f1ff);
  --ai-muted: var(--muted, #a9a3c4);
  --ai-line:  var(--line,  rgba(255, 255, 255, .14));
  --ai-panel: var(--panel, #161130);

  /* Elevation is derived from the panel token, so a lighter or darker skin
   * keeps the same relative depth instead of inverting. */
  --ai-raise: color-mix(in srgb, var(--ai-panel) 88%, #ffffff);
  --ai-sink:  color-mix(in srgb, var(--ai-panel) 94%, #000000);

  --ai-accent-soft: color-mix(in srgb, var(--ai-accent) 16%, var(--ai-panel));
  --ai-accent-line: color-mix(in srgb, var(--ai-accent) 42%, var(--ai-panel));

  --ai-radius: 16px;
  --ai-shadow: 0 16px 40px rgba(0, 0, 0, .32);

  display: grid;
  gap: 18px;
  color: var(--ai-text);
}

/* ── Hero: the tutor introduces themselves ───────────────────────────────── */

.ai-hero {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 20px;
  align-items: center;
  padding: 22px 24px;
  border-radius: var(--ai-radius);
  border: 1px solid var(--ai-accent-line);
  background:
    radial-gradient(120% 140% at 0% 0%, var(--ai-accent-soft) 0%, var(--ai-panel) 62%);
  box-shadow: var(--ai-shadow);
}

.ai-hero-avatar { width: 84px; height: 84px; flex: 0 0 auto; }

/* The registry's face rig renders into .guide-avatar > .gf-disc > svg. */
.ai-hero-avatar .guide-avatar,
.ai-hero-avatar .gf-disc { display: block; width: 100%; height: 100%; }

.ai-hero-avatar .gf-disc {
  border-radius: 50%;
  overflow: hidden;
  border: 2px solid var(--ai-accent-line);
  background: var(--ai-accent-soft);
  box-shadow: 0 8px 20px rgba(0, 0, 0, .35);
}

.ai-hero-avatar svg { display: block; width: 100%; height: 100%; }

/* The portrait itself is warm-toned artwork; it keeps a light disc behind it so
 * the face reads at avatar size instead of sinking into the dark canvas. */
.ai-hero-avatar .gf-bg { fill: color-mix(in srgb, var(--ai-accent) 22%, #ffffff); }

/* A slow idle breath — the only motion on the tutor. It reads as "present and
 * listening" without implying the module is computing anything. */
.ai-hero-avatar .gf-breath {
  transform-origin: 60px 70px;
  animation: ai-breath 5.2s ease-in-out infinite;
}

@keyframes ai-breath {
  0%, 100% { transform: translateY(0) scale(1); }
  50%      { transform: translateY(-1.1px) scale(1.012); }
}

/* Blink on a loop offset from the breath so the two never visibly sync. */
.ai-hero-avatar .gf-eye { animation: ai-blink 6.7s infinite; transform-origin: center; }
@keyframes ai-blink {
  0%, 92%, 100% { transform: scaleY(1); }
  95%           { transform: scaleY(.08); }
}

/* The mouth opens ONLY while real work is in flight (.is-thinking is added
 * around an actual await, never on a decorative timer). */
.ai-hero-avatar .gf-mouth { opacity: 0; transition: opacity .2s ease; }
.ai-hero.is-thinking .ai-hero-avatar .gf-mouth {
  opacity: .85;
  animation: ai-speak 1.05s ease-in-out infinite;
  transform-origin: center;
}
@keyframes ai-speak {
  0%, 100% { transform: scaleY(.35); }
  50%      { transform: scaleY(1); }
}

@media (prefers-reduced-motion: reduce) {
  .ai-hero-avatar .gf-breath,
  .ai-hero-avatar .gf-eye,
  .ai-hero.is-thinking .ai-hero-avatar .gf-mouth { animation: none; }
}

.ai-hero-copy { min-width: 0; }

.ai-hero-eyebrow {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--ai-accent);
}

/* Explicit color on headings: the skin sets a global heading color that would
 * otherwise win over inherited text on these cards. */
.ai-page h1, .ai-page h2, .ai-page h3, .ai-page h4 { color: var(--ai-text); }

.ai-hero-name { font-size: 22px; font-weight: 700; margin: 2px 0 4px; color: var(--ai-text); }

.ai-hero-greeting {
  font-size: 14px;
  color: var(--ai-text);
  opacity: .92;
  font-style: italic;
  margin: 0 0 8px;
}

.ai-hero-frame { font-size: 13px; color: var(--ai-muted); margin: 0; }

.ai-hero-meta { display: flex; flex-direction: column; gap: 6px; align-items: flex-end; }

/* ── Chips ───────────────────────────────────────────────────────────────── */

.ai-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  border: 1px solid var(--ai-line);
  background: var(--ai-sink);
  color: var(--ai-muted);
  white-space: nowrap;
}

/* Status tints are mixed into the panel so they stay legible on a dark canvas
 * instead of glowing as pastel blocks. */
.ai-chip.ok     { background: color-mix(in srgb, #34d399 18%, var(--ai-panel)); color: #6ee7b7; border-color: color-mix(in srgb, #34d399 34%, var(--ai-panel)); }
.ai-chip.warn   { background: color-mix(in srgb, #fbbf24 18%, var(--ai-panel)); color: #fcd34d; border-color: color-mix(in srgb, #fbbf24 34%, var(--ai-panel)); }
.ai-chip.danger { background: color-mix(in srgb, #f87171 18%, var(--ai-panel)); color: #fca5a5; border-color: color-mix(in srgb, #f87171 34%, var(--ai-panel)); }

/* ── Tabs ────────────────────────────────────────────────────────────────── */

.ai-tabs {
  display: flex;
  gap: 4px;
  padding: 5px;
  border-radius: 12px;
  border: 1px solid var(--ai-line);
  background: var(--ai-sink);
  overflow-x: auto;
}

.ai-tab {
  appearance: none;
  border: 0;
  background: transparent;
  padding: 9px 15px;
  border-radius: 9px;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  color: var(--ai-muted);
  cursor: pointer;
  white-space: nowrap;
  transition: background .15s ease, color .15s ease;
}

.ai-tab:hover { color: var(--ai-text); background: var(--ai-raise); }

.ai-tab[aria-selected="true"] {
  background: var(--ai-accent-soft);
  color: var(--ai-accent);
  box-shadow: inset 0 0 0 1px var(--ai-accent-line);
}

.ai-tab-count {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 6px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--ai-accent) 26%, var(--ai-panel));
  color: var(--ai-text);
  font-size: 11px;
}

.ai-panel[hidden] { display: none; }

/* ── Cards ───────────────────────────────────────────────────────────────── */

.ai-card {
  border: 1px solid var(--ai-line);
  border-radius: var(--ai-radius);
  background: var(--ai-panel);
  color: var(--ai-text);
  padding: 18px 20px;
  box-shadow: var(--ai-shadow);
}

.ai-card + .ai-card { margin-top: 14px; }

.ai-card-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.ai-card-title { font-size: 15px; font-weight: 700; margin: 0; color: var(--ai-text); }
.ai-card-sub { font-size: 12px; color: var(--ai-muted); margin: 3px 0 0; }

/* ── Suggestion / proposal rows ──────────────────────────────────────────── */

.ai-list { display: grid; gap: 10px; }

.ai-item {
  display: grid;
  grid-template-columns: 4px 1fr auto;
  gap: 14px;
  align-items: start;
  padding: 14px 16px;
  border: 1px solid var(--ai-line);
  border-radius: 12px;
  background: var(--ai-raise);
}

/* The priority rail is the only place color carries meaning alone, so it is
 * always paired with the word "prioridad <x>" in .ai-item-detail. */
.ai-item-rail { border-radius: 999px; align-self: stretch; background: var(--ai-line); }
.ai-item.p-high   .ai-item-rail { background: #f87171; }
.ai-item.p-medium .ai-item-rail { background: #fbbf24; }
.ai-item.p-low    .ai-item-rail { background: #7c8399; }

.ai-item-body { min-width: 0; }
.ai-item-title { font-size: 14px; font-weight: 650; margin: 0 0 3px; color: var(--ai-text); }
.ai-item-detail { font-size: 12.5px; color: var(--ai-muted); margin: 0; }

/* Evidence is deliberately always visible, never behind a disclosure. A claim
 * and the record it rests on should not be separated by a click. */
.ai-evidence {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 9px;
  padding-top: 9px;
  border-top: 1px dashed var(--ai-line);
}

.ai-evidence-item {
  font-size: 11px;
  color: var(--ai-muted);
  background: var(--ai-sink);
  border: 1px solid var(--ai-line);
  border-radius: 6px;
  padding: 3px 8px;
}

.ai-evidence-item b { color: var(--ai-text); font-weight: 650; }

.ai-item-actions { display: flex; flex-direction: column; gap: 6px; align-items: stretch; }

/* ── Buttons ─────────────────────────────────────────────────────────────── */

.ai-btn {
  appearance: none;
  display: inline-block;
  text-align: center;
  text-decoration: none;
  font: inherit;
  font-size: 12.5px;
  font-weight: 600;
  padding: 8px 14px;
  border-radius: 9px;
  border: 1px solid var(--ai-line);
  background: var(--ai-raise);
  color: var(--ai-text);
  cursor: pointer;
  white-space: nowrap;
  transition: border-color .15s ease, background .15s ease, transform .1s ease;
}

.ai-btn:hover:not(:disabled) { border-color: var(--ai-accent); color: var(--ai-accent); }
.ai-btn:active:not(:disabled) { transform: translateY(1px); }

.ai-btn.primary {
  background: var(--ai-accent);
  border-color: var(--ai-accent);
  /* The guide accents are light pastels, so dark ink is the legible pairing. */
  color: #14101f;
}

.ai-btn.primary:hover:not(:disabled) { filter: brightness(1.1); color: #14101f; }

.ai-btn:disabled { opacity: .5; cursor: not-allowed; }

.ai-btn.is-done {
  background: color-mix(in srgb, #34d399 20%, var(--ai-panel));
  border-color: color-mix(in srgb, #34d399 40%, var(--ai-panel));
  color: #6ee7b7;
}

/* ── Trends ──────────────────────────────────────────────────────────────── */

.ai-trend-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 12px;
}

.ai-trend {
  border: 1px solid var(--ai-line);
  border-radius: 12px;
  padding: 14px 16px;
  background: var(--ai-raise);
}

.ai-trend-label { font-size: 12px; color: var(--ai-muted); margin: 0 0 6px; }
.ai-trend-value { font-size: 26px; font-weight: 700; line-height: 1.1; color: var(--ai-text); }

.ai-trend-delta { font-size: 12px; font-weight: 600; margin-top: 4px; }
.ai-trend-delta.up   { color: #6ee7b7; }
.ai-trend-delta.down { color: #fca5a5; }
.ai-trend-delta.flat { color: var(--ai-muted); }

/* An unmeasurable trend is styled DELIBERATELY inert — dashed, muted, smaller,
 * and with no arrow at all. It must never be mistaken for a confident reading. */
.ai-trend.is-insufficient { background: transparent; border-style: dashed; }
.ai-trend.is-insufficient .ai-trend-value { color: var(--ai-muted); font-size: 20px; }

.ai-trend-note { font-size: 11.5px; color: var(--ai-muted); margin-top: 8px; }

/* ── Reports ─────────────────────────────────────────────────────────────── */

.ai-report-section { border-top: 1px solid var(--ai-line); padding-top: 14px; margin-top: 14px; }
.ai-report-section:first-of-type { border-top: 0; padding-top: 0; margin-top: 0; }
.ai-report-heading { font-size: 13.5px; font-weight: 700; margin: 0 0 10px; color: var(--ai-text); }

.ai-figures { display: flex; flex-wrap: wrap; gap: 18px; }
.ai-figure { min-width: 110px; }
.ai-figure-value { font-size: 21px; font-weight: 700; color: var(--ai-text); }
.ai-figure-label { font-size: 11.5px; color: var(--ai-muted); margin-top: 2px; }

/* A section awaiting the teacher's judgement is drawn as an OPEN SLOT, not as
 * finished content — the engine leaves these blank on purpose. */
.ai-needs-input {
  border: 1px dashed var(--ai-accent-line);
  border-radius: 10px;
  background: var(--ai-accent-soft);
  padding: 12px 14px;
}

.ai-needs-input textarea,
.ai-composer textarea {
  width: 100%;
  resize: vertical;
  border: 1px solid var(--ai-line);
  border-radius: 8px;
  padding: 9px 11px;
  font: inherit;
  font-size: 13px;
  background: var(--ai-sink);
  color: var(--ai-text);
}

.ai-needs-input textarea { min-height: 76px; }

.ai-needs-input textarea:focus,
.ai-composer textarea:focus {
  outline: 2px solid var(--ai-accent-line);
  outline-offset: 1px;
  border-color: var(--ai-accent);
}

/* ── Composer ────────────────────────────────────────────────────────────── */

.ai-composer { display: flex; gap: 10px; align-items: flex-end; }

.ai-composer textarea {
  flex: 1;
  min-height: 46px;
  max-height: 160px;
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 13.5px;
}

.ai-prompt-chips { display: flex; flex-wrap: wrap; gap: 7px; margin-bottom: 10px; }

.ai-prompt-chip {
  appearance: none;
  font: inherit;
  font-size: 12px;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--ai-line);
  background: var(--ai-raise);
  color: var(--ai-muted);
  cursor: pointer;
}

.ai-prompt-chip:hover { border-color: var(--ai-accent); color: var(--ai-accent); }

/* ── Transcript ──────────────────────────────────────────────────────────── */

.ai-thread { display: grid; gap: 12px; margin-bottom: 16px; }

.ai-bubble {
  max-width: 78%;
  padding: 11px 14px;
  border-radius: 13px;
  font-size: 13.5px;
  line-height: 1.55;
  white-space: pre-wrap;
}

.ai-bubble.teacher {
  justify-self: end;
  background: var(--ai-accent);
  color: #14101f;
  border-bottom-right-radius: 4px;
}

.ai-bubble.guide {
  justify-self: start;
  background: var(--ai-raise);
  border: 1px solid var(--ai-line);
  color: var(--ai-text);
  border-bottom-left-radius: 4px;
}

.ai-bubble-author {
  font-size: 11px;
  font-weight: 700;
  color: var(--ai-accent);
  margin-bottom: 4px;
}

/* ── States ──────────────────────────────────────────────────────────────── */

.ai-empty, .ai-loading {
  text-align: center;
  padding: 34px 20px;
  color: var(--ai-muted);
  font-size: 13px;
}

.ai-empty-title { font-size: 14px; font-weight: 650; color: var(--ai-text); margin-bottom: 5px; }

/* A blocked read must look like a PROBLEM, not like an empty state. A teacher
 * shown "0 alerts" when the query was actually rejected is being misinformed. */
.ai-blocked {
  border: 1px solid color-mix(in srgb, #f87171 40%, var(--ai-panel));
  background: color-mix(in srgb, #f87171 14%, var(--ai-panel));
  border-radius: 12px;
  padding: 13px 16px;
  font-size: 12.5px;
  color: #fca5a5;
}

.ai-blocked b { display: block; margin-bottom: 3px; color: #fecaca; }

/* ── Honesty banner ──────────────────────────────────────────────────────── */

/* Permanent and non-dismissible. The module states plainly how its output is
 * produced; the surfaces it replaces implied a reasoning model that was never
 * there, and a teacher acting on these suggestions is entitled to know. */
.ai-disclosure {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  border: 1px solid var(--ai-line);
  border-left: 3px solid var(--ai-accent);
  border-radius: 10px;
  background: var(--ai-raise);
  padding: 11px 14px;
  font-size: 12px;
  color: var(--ai-muted);
  line-height: 1.5;
}

.ai-disclosure b { color: var(--ai-text); }

/* ── Responsive ──────────────────────────────────────────────────────────── */

@media (max-width: 900px) {
  .ai-hero { grid-template-columns: auto 1fr; }
  .ai-hero-meta { grid-column: 1 / -1; flex-direction: row; align-items: center; }
  .ai-item { grid-template-columns: 4px 1fr; }
  .ai-item-actions { grid-column: 2; flex-direction: row; }
  .ai-bubble { max-width: 92%; }
}

@media (max-width: 560px) {
  .ai-hero-avatar { width: 60px; height: 60px; }
  .ai-hero-name { font-size: 18px; }
  .ai-figures { gap: 12px; }
  .ai-composer { flex-direction: column; align-items: stretch; }
}
