/* ================================================================
   AI TUTOR PAGE (ai-tutor.js): the chat list down the side, and the chat
   in STUDY'S look (styles/conceptual/tutor.css: .ct-thread, .ct-msg,
   .ct-bubble, .ct-dock, .ct-chat, .ct-send). This file adds only what Study
   has no need for: the list, the empty-state greeting, code blocks and the
   drill card. Height is set by ai-tutor.js. Tokens: styles/variables.css.
   🔴 Load AFTER styles/conceptual/tutor.css is NOT required: every rule
   here is scoped under #page-ai-tutor, which outranks tutor.css's classes.
   ================================================================ */

#page-ai-tutor {
  padding: 0;
  display: flex;
  min-height: 0;
  position: relative;
  background: var(--bg);
}

#page-ai-tutor.hidden { display: none; }

/* ---- the chat list ------------------------------------------------------ */
#page-ai-tutor .at-side {
  flex: 0 0 260px;
  /* A flex item's min-width is its content by default, so one long
     (nowrap) title would widen the list to its full length. */
  width: 260px;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-height: 0;
  box-sizing: border-box;
  /* Clears the notch that hangs below the topbar. */
  padding: 30px 10px 12px;
  background: var(--panel-deep);
  border-right: 1px solid var(--border);
}

#page-ai-tutor .at-new {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: var(--ui-font);
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
  background: transparent;
  border: 0;
  border-radius: 10px;
  padding: 9px 10px;
  cursor: pointer;
  text-align: left;
}

#page-ai-tutor .at-new:hover { background: rgb(var(--tint-rgb) / calc(0.06 * var(--tint-k))); }

/* A plus in a filled circle, drawn with gradients: no icon font. */
#page-ai-tutor .at-new-plus {
  flex: 0 0 auto;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background:
    linear-gradient(var(--on-accent), var(--on-accent)) center / 10px 2px no-repeat,
    linear-gradient(var(--on-accent), var(--on-accent)) center / 2px 10px no-repeat,
    var(--accent);
}

#page-ai-tutor .at-threads {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  scrollbar-width: thin;
}

#page-ai-tutor .at-group {
  margin: 14px 10px 4px;
  font-family: var(--ui-font);
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--muted-dim);
}

#page-ai-tutor .at-group:first-child { margin-top: 2px; }

#page-ai-tutor .at-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

#page-ai-tutor .at-thread {
  position: relative;
  display: flex;
  align-items: center;
  border-radius: 8px;
}

#page-ai-tutor .at-thread:hover,
#page-ai-tutor .at-thread.is-current {
  background: rgb(var(--tint-rgb) / calc(0.07 * var(--tint-k)));
}

#page-ai-tutor .at-thread-btn {
  flex: 1 1 auto;
  min-width: 0;
  font-family: var(--ui-font);
  font-size: 13.5px;
  color: var(--muted);
  background: none;
  border: 0;
  border-radius: 8px;
  padding: 8px 10px;
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
}

#page-ai-tutor .at-thread.is-current .at-thread-btn,
#page-ai-tutor .at-thread:hover .at-thread-btn { color: var(--text); }

#page-ai-tutor .at-thread-del {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  min-width: 28px;
  height: 28px;
  margin-right: 2px;
  font-family: var(--ui-font);
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  background: none;
  border: 0;
  border-radius: 6px;
  padding: 0 6px;
  cursor: pointer;
  opacity: 0;   /* not visibility: a hidden button can't take keyboard focus */
}

#page-ai-tutor .at-thread:hover .at-thread-del,
#page-ai-tutor .at-thread-del:focus-visible,
#page-ai-tutor .at-thread.is-armed .at-thread-del { opacity: 1; }
#page-ai-tutor .at-thread-del:hover { color: var(--text); background: rgb(var(--tint-rgb) / calc(0.08 * var(--tint-k))); }
#page-ai-tutor .at-thread.is-armed .at-thread-del { color: var(--danger); }

/* An × from two crossed bars. */
#page-ai-tutor .at-x {
  position: relative;
  width: 11px;
  height: 11px;
}

#page-ai-tutor .at-x::before,
#page-ai-tutor .at-x::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 0;
  width: 1.6px;
  height: 100%;
  margin-left: -0.8px;
  border-radius: 1px;
  background: currentColor;
  transform: rotate(45deg);
}

#page-ai-tutor .at-x::after { transform: rotate(-45deg); }

#page-ai-tutor .at-empty {
  margin: 6px 10px;
  font-family: var(--ui-font);
  font-size: 13px;
  color: var(--muted-dim);
}

/* ---- the chat column (Study's #concept-study-root) ------------------------ */
#page-ai-tutor .at-main {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

#page-ai-tutor .at-col {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  width: min(760px, 100%);
  margin: 0 auto;
  box-sizing: border-box;
  padding: 0 16px;
}

/* The notch hangs over the top of the column. */
#page-ai-tutor .ct-thread { padding-top: 40px; }

/* The newest exchange is as tall as the view (ai-tutor.js sizeTail), so it
   can scroll to the top with the reply growing under it. */
#page-ai-tutor .at-tail {
  display: flex;
  flex-direction: column;
  gap: 26px;
}

#page-ai-tutor .at-reply.is-live { animation: none; }

/* A new chat: the greeting and the box together in the middle, like a
   blank chat anywhere. */
#page-ai-tutor .at-col.is-empty { justify-content: center; }
#page-ai-tutor .at-col.is-empty .ct-thread { flex: 0 0 auto; overflow: visible; padding: 0 0 8px; }
#page-ai-tutor .at-col.is-empty .ct-dock { padding-bottom: 12vh; }

#page-ai-tutor .at-hello { text-align: center; animation: ct-rise 0.32s ease both; }

#page-ai-tutor .at-hello-title {
  margin: 0 0 10px;
  font-family: var(--prose-heading);
  font-size: 34px;
  font-weight: 400;
  line-height: 1.2;
  color: var(--prose-head);
}

#page-ai-tutor .at-hello-sub {
  max-width: 520px;
  margin: 0 auto;
  font-family: var(--prose-font);
  font-size: 17px;
  line-height: 1.55;
  color: var(--muted);
}

/* ---- the reply's markdown (ai-tutor-md.js) -------------------------------- */
/* :where() keeps these at the spacing rule's weight, so the rule after them wins. */
#page-ai-tutor .at-md :where(p, .ct-list, .at-code, .at-quote, .at-hr) { margin: 0; }
#page-ai-tutor .at-md .ct-list { padding-left: 1.4em; }
#page-ai-tutor .at-md > * + * { margin-top: 14px; }
#page-ai-tutor .at-md .ct-list li + li { margin-top: 6px; }

#page-ai-tutor .at-h {
  font-family: var(--prose-heading);
  font-weight: 600;
  color: var(--prose-head);
}

#page-ai-tutor .at-h1 { font-size: 1.3em; }
#page-ai-tutor .at-h2 { font-size: 1.15em; }
#page-ai-tutor .at-md > .at-h + * { margin-top: 6px; }

/* Code the learner pasted, inside their bubble. */
#page-ai-tutor .at-said { max-width: min(82%, 640px); }
#page-ai-tutor .at-said > * + * { margin-top: 8px; }
#page-ai-tutor .at-said .at-md { font-size: inherit; }
#page-ai-tutor .at-said .at-code { background: var(--panel-deep); }
#page-ai-tutor .at-said .at-pre { font-size: 12.5px; }

#page-ai-tutor .at-md strong { color: var(--prose-head); font-weight: 600; }

#page-ai-tutor .at-ic {
  font-family: var(--code-font);
  font-size: 0.82em;
  padding: 1px 5px;
  border-radius: 5px;
  background: rgb(var(--tint-rgb) / calc(0.08 * var(--tint-k)));
  color: var(--text);
}

#page-ai-tutor .at-link {
  color: var(--prose-link);
  text-underline-offset: 2px;
}

#page-ai-tutor .at-quote {
  margin: 0;
  padding-left: 18px;
  border-left: 3px solid var(--border-strong);
  color: var(--muted);
}

#page-ai-tutor .at-hr { border: 0; border-top: 1px solid var(--border); }
#page-ai-tutor .at-math { overflow-x: auto; white-space: pre-wrap; }

#page-ai-tutor .at-code {
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--panel-deep);
  overflow: hidden;
}

#page-ai-tutor .at-code-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 5px 8px 5px 14px;
  border-bottom: 1px solid var(--border);
  font-family: var(--ui-font);
  font-size: 12px;
  color: var(--muted);
}

#page-ai-tutor .at-code-copy {
  font: inherit;
  color: var(--muted);
  background: none;
  border: 0;
  border-radius: 6px;
  padding: 3px 8px;
  cursor: pointer;
}

#page-ai-tutor .at-code-copy:hover { color: var(--text); background: rgb(var(--tint-rgb) / calc(0.08 * var(--tint-k))); }

#page-ai-tutor .at-pre {
  margin: 0;
  padding: 12px 14px;
  overflow-x: auto;
  font-family: var(--code-font);
  font-size: 13.5px;
  line-height: 1.55;
  color: var(--text);
  tab-size: 4;
}

/* ---- the drill card (on top of the chat box) ------------------------------ */
#page-ai-tutor .at-drill {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 14px;
  padding: 12px 14px 12px 16px;
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: 12px;
  background: var(--surface);
  animation: ct-rise 0.32s ease both;
}

#page-ai-tutor .at-drill-text {
  flex: 1 1 320px;
  margin: 0;
  font-family: var(--prose-font);
  font-size: 15.5px;
  line-height: 1.45;
  color: var(--text);
}

#page-ai-tutor .at-drill-btn { flex: 0 0 auto; font-weight: 600; }

#page-ai-tutor .at-chips {
  order: 3;
  flex: 1 1 100%;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

#page-ai-tutor .at-chip {
  font-family: var(--ui-font);
  font-size: 12px;
  color: var(--muted);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 2px 9px;
}

#page-ai-tutor .at-drill-err {
  order: 4;
  flex: 1 1 100%;
  margin: 0;
  font-family: var(--ui-font);
  font-size: 13px;
  color: var(--danger);
}

/* ---- the dock ---------------------------------------------------------------- */
#page-ai-tutor .at-dock { gap: 6px; }

#page-ai-tutor .at-send.is-stop { background: var(--text); }
#page-ai-tutor .at-send.is-stop:hover { background: var(--muted); }

#page-ai-tutor .at-stop-glyph {
  width: 10px;
  height: 10px;
  border-radius: 2px;
  background: var(--bg);
}

#page-ai-tutor .at-foot {
  margin: 0;
  text-align: center;
  font-family: var(--ui-font);
  font-size: 11.5px;
  color: var(--muted-dim);
}

/* ---- phone: the list becomes a drawer ---------------------------------------- */
#page-ai-tutor .at-bar,
#page-ai-tutor .at-scrim { display: none; }

@media (max-width: 760px) {
  #page-ai-tutor .at-side {
    position: absolute;
    z-index: 30;
    top: 0;
    bottom: 0;
    left: 0;
    width: min(290px, 84vw);
    flex-basis: auto;
    transform: translateX(-102%);
    transition: transform 0.22s ease;
    box-shadow: 0 0 28px var(--shadow-soft);
  }

  #page-ai-tutor.is-drawer .at-side { transform: none; }

  #page-ai-tutor.is-drawer .at-scrim {
    display: block;
    position: absolute;
    inset: 0;
    z-index: 29;
    background: rgb(0 0 0 / 0.45);
  }

  /* The list's button and the open chat's title, above the thread. */
  #page-ai-tutor .at-bar {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 16px;
    border-bottom: 1px solid var(--border);
  }

  #page-ai-tutor .at-bar-title {
    min-width: 0;
    font-family: var(--ui-font);
    font-size: 14px;
    font-weight: 500;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  #page-ai-tutor .at-menu {
    flex: 0 0 auto;
    display: grid;
    place-items: center;
    width: 36px;
    height: 36px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--surface);
    cursor: pointer;
  }

  /* Three bars: one box and its two shadows. */
  #page-ai-tutor .at-menu-bars {
    width: 16px;
    height: 2px;
    border-radius: 1px;
    background: var(--text);
    box-shadow: 0 -5px 0 var(--text), 0 5px 0 var(--text);
  }

  #page-ai-tutor .ct-thread { padding-top: 20px; }
  #page-ai-tutor .at-hello-title { font-size: 28px; }
}

@media (prefers-reduced-motion: reduce) {
  #page-ai-tutor .at-side { transition: none; }
  #page-ai-tutor .at-hello,
  #page-ai-tutor .at-drill { animation: none; }
}
