/* ════════════════════════════════════════════════════════════════
   Ask CoffeeBean AI: study assistant chat page (app/views/ask/index.html.erb, ask_controller.js).
   Three columns on desktop: chats · chat · popular topics. Uses the tokens from design.css,
   so it follows the dark and light themes. Code blocks stay dark ("islands") in both themes.
   ════════════════════════════════════════════════════════════════ */

.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

.ask-page { background: transparent; }
.ask-layout { display: grid; grid-template-columns: 300px minmax(0, 1fr) 384px; height: calc(100dvh - 64px); }

/* ── Left: chats ─────────────────────────────────────────────── */
.ask-side { display: flex; flex-direction: column; gap: 6px; padding: 26px 18px 24px 28px; overflow-y: auto; border-right: 1px solid var(--border);
  background: radial-gradient(420px 380px at 0% 100%, rgba(139,92,246,.16), transparent 70%), rgba(255,255,255,.012); }
.ask-new { display: flex; align-items: center; justify-content: center; gap: 10px; width: 100%; min-height: 54px; border: 0; border-radius: 12px;
  background: var(--grad-brand); color: #fff; font: 600 16px/1 var(--font); cursor: pointer; box-shadow: 0 10px 26px -10px rgba(99,102,241,.8);
  transition: transform .15s var(--ease), box-shadow .15s var(--ease); }
.ask-new:hover { transform: translateY(-1px); box-shadow: 0 14px 30px -10px rgba(99,102,241,.9); }
.ask-side-title { margin: 26px 0 8px; font-size: 16px; font-weight: 700; color: var(--txt); }
.ask-side-empty { color: var(--txt3); font-size: 14px; line-height: 1.6; padding: 6px 2px; }
.ask-side-empty a { color: var(--brand); font-weight: 600; }
.ask-chats { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.ask-chat { position: relative; border-radius: 12px; transition: background .15s; }
.ask-chat:hover { background: rgba(255,255,255,.04); }
.ask-chat.is-active { background: var(--bg3); }
.ask-chat-link { display: flex; align-items: flex-start; gap: 12px; padding: 12px 40px 12px 12px; color: var(--txt); text-decoration: none; border-radius: 12px; }
.ask-chat-icon { flex-shrink: 0; margin-top: 1px; color: var(--txt2); }
.ask-chat-text { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.ask-chat-title { font-size: 14.5px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ask-chat-time { font-size: 13px; color: var(--txt3); }
.ask-chat-more { position: absolute; top: 50%; right: 8px; transform: translateY(-50%); width: 28px; height: 28px; display: grid; place-items: center;
  border: 0; border-radius: 8px; background: transparent; color: var(--txt2); cursor: pointer; opacity: 0; transition: opacity .15s, background .15s; }
.ask-chat:hover .ask-chat-more, .ask-chat.is-active .ask-chat-more, .ask-chat-more:focus-visible { opacity: 1; }
.ask-chat-more:hover { background: var(--bg4); color: var(--txt); }
.ask-chat-menu { position: absolute; right: 8px; top: calc(100% - 6px); z-index: 20; min-width: 140px; padding: 6px; border-radius: 12px;
  background: var(--bg2); border: 1px solid var(--border2); box-shadow: var(--shadow-lg); display: flex; flex-direction: column; }
.ask-chat-menu[hidden] { display: none; }
.ask-chat-menu button { text-align: left; padding: 9px 12px; border: 0; border-radius: 8px; background: none; color: var(--txt); font: 500 14px var(--font); cursor: pointer; }
.ask-chat-menu button:hover { background: var(--bg3); }
.ask-chat-menu .is-danger { color: #f87171; }

/* ── Middle: chat ────────────────────────────────────────────── */
.ask-main { position: relative; display: flex; flex-direction: column; min-width: 0; min-height: 0; padding: 30px 32px 22px;
  background: radial-gradient(700px 360px at 20% -10%, rgba(139,92,246,.16), transparent 70%), radial-gradient(500px 300px at 95% 0%, rgba(59,130,246,.10), transparent 70%); }
.ask-mobilebar { display: none; }
.ask-hero { text-align: center; padding-top: 8px; }
.ask-pill { display: inline-flex; align-items: center; gap: 8px; padding: 9px 16px; border-radius: 99px; border: 1px solid rgba(139,92,246,.6);
  background: rgba(139,92,246,.12); color: #c4b5fd; font-size: 14px; font-weight: 600; letter-spacing: .02em; text-transform: uppercase; }
.ask-title { margin: 22px 0 8px; font-size: clamp(36px, 4.6vw, 62px); font-weight: 800; letter-spacing: -.035em; line-height: 1.05; color: var(--txt); }
.ask-sub { margin: 0 auto; max-width: 720px; font-size: 19px; line-height: 1.5; color: var(--txt2); }

.ask-thread { display: none; }
.ask-dock { width: 100%; max-width: 920px; margin: 40px auto 0; }
.ask-composer { position: relative; display: flex; flex-direction: column; gap: 12px; padding: 20px 18px 16px 26px; border-radius: 20px;
  border: 1.5px solid rgba(139,92,246,.6); background: rgba(21,21,52,.72);
  box-shadow: 0 0 0 1px rgba(139,92,246,.08), 0 18px 50px -20px rgba(99,102,241,.55), inset 0 1px 0 rgba(255,255,255,.04);
  transition: border-color .15s, box-shadow .15s; }
.ask-composer:focus-within { border-color: #a78bfa; box-shadow: var(--ring), 0 18px 50px -20px rgba(99,102,241,.6); }
.ask-composer textarea { width: 100%; min-height: 30px; max-height: 220px; resize: none; border: 0; outline: 0; background: transparent;
  color: var(--txt); font: 400 18px/1.55 var(--font); padding: 0 80px 0 0; }
.ask-composer textarea::placeholder { color: var(--txt2); }
.ask-tools { display: flex; align-items: center; gap: 14px; min-height: 40px; padding-right: 84px; }
.ask-tool { display: grid; place-items: center; width: 36px; height: 36px; border-radius: 10px; color: var(--txt2); cursor: pointer; transition: background .15s, color .15s; }
.ask-tool:hover { background: rgba(255,255,255,.06); color: var(--txt); }
.ask-divider { width: 1px; height: 22px; background: var(--border2); }
.ask-web { display: inline-flex; align-items: center; gap: 9px; color: var(--txt2); font-size: 15px; cursor: pointer; user-select: none; }
.ask-switch { appearance: none; -webkit-appearance: none; position: relative; width: 46px; height: 26px; margin: 0 0 0 6px; border-radius: 99px;
  background: var(--bg4); border: 1px solid var(--border2); cursor: pointer; transition: background .2s; flex-shrink: 0; }
.ask-switch::before { content: ""; position: absolute; top: 2px; left: 2px; width: 20px; height: 20px; border-radius: 50%; background: #e5e7eb;
  box-shadow: 0 1px 3px rgba(0,0,0,.35); transition: transform .2s var(--ease); }
.ask-switch:checked { background: var(--grad-brand); border-color: transparent; }
.ask-switch:checked::before { transform: translateX(20px); background: #fff; }
.ask-send { position: absolute; right: 14px; bottom: 14px; width: 68px; height: 62px; display: grid; place-items: center; border: 0; border-radius: 16px;
  background: var(--grad-brand); color: #fff; cursor: pointer; box-shadow: 0 10px 24px -8px rgba(99,102,241,.8); transition: transform .15s var(--ease), filter .15s; }
.ask-send:hover { transform: translateY(-1px); filter: brightness(1.08); }
.ask-send .ask-stop-icon, .ask-send.is-stop .ask-send-icon { display: none; }
.ask-send.is-stop .ask-stop-icon { display: block; }
.ask-file-chip { display: inline-flex; align-self: flex-start; align-items: center; gap: 10px; max-width: 100%; padding: 6px 8px 6px 12px; border-radius: 10px;
  background: var(--bg3); color: var(--txt); font-size: 13.5px; }
.ask-file-chip[hidden] { display: none; }
.ask-file-chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ask-file-chip button { border: 0; background: none; color: var(--txt2); cursor: pointer; font-size: 13px; padding: 2px 6px; border-radius: 6px; }
.ask-file-chip button:hover { background: var(--bg4); color: var(--txt); }
.ask-note { margin: 10px 4px 0; text-align: center; font-size: 12.5px; color: var(--txt3); }
.ask-flash { margin-bottom: 10px; padding: 10px 14px; border-radius: 10px; background: rgba(248,113,113,.12); border: 1px solid rgba(248,113,113,.35); color: var(--txt); font-size: 14px; }
.ask-flash a { color: var(--brand); font-weight: 600; }

.ask-chips { display: flex; flex-wrap: wrap; justify-content: center; gap: 18px; margin-top: 24px; }
.ask-chip { display: inline-flex; align-items: center; gap: 12px; padding: 15px 28px; border-radius: 99px; border: 1px solid var(--border2);
  background: rgba(255,255,255,.02); color: var(--txt); font: 500 16px var(--font); cursor: pointer; transition: border-color .15s, background .15s, transform .15s var(--ease); }
.ask-chip:hover { border-color: rgba(139,92,246,.6); background: rgba(139,92,246,.08); transform: translateY(-1px); }
.ask-chip-book svg { color: #a855f7; }
.ask-chip-code svg { color: #3b82f6; }
.ask-chip-note svg { color: #ec4899; }

/* Chat started: the thread fills the middle and the composer sits at the bottom. */
.has-thread .ask-hero, .has-thread .ask-chips { display: none; }
.has-thread .ask-thread { display: flex; flex-direction: column; gap: 22px; flex: 1; min-height: 0; overflow-y: auto; width: 100%; max-width: 920px;
  margin: 0 auto; padding: 4px 6px 20px; scroll-behavior: smooth; }
.has-thread .ask-dock { margin-top: 8px; }

.ask-msg { display: flex; gap: 14px; }
.ask-msg-user { justify-content: flex-end; }
.ask-bubble { max-width: min(78%, 640px); padding: 13px 18px; border-radius: 18px 18px 4px 18px; background: rgba(139,92,246,.2);
  border: 1px solid rgba(139,92,246,.3); color: var(--txt); font-size: 15.5px; line-height: 1.6; overflow-wrap: anywhere; }
.ask-bubble p { margin: 0; }
.ask-bubble p + p { margin-top: 8px; }
.ask-file-tag { display: inline-block; margin-bottom: 6px; padding: 3px 9px; border-radius: 8px; background: rgba(255,255,255,.08); font-size: 13px; }
.ask-avatar { flex-shrink: 0; width: 34px; height: 34px; display: grid; place-items: center; border-radius: 10px; background: var(--grad-brand); color: #fff;
  box-shadow: 0 6px 16px -6px rgba(99,102,241,.8); }
.ask-avatar svg { width: 18px; height: 18px; }
.ask-answer { min-width: 0; flex: 1; padding-top: 4px; color: var(--txt); font-size: 15.5px; line-height: 1.7; overflow-wrap: anywhere; }
.ask-md > :first-child { margin-top: 0; }
.ask-md p { margin: 0 0 12px; }
.ask-md h4 { margin: 18px 0 8px; font-size: 16.5px; font-weight: 700; }
.ask-md ul, .ask-md ol { margin: 0 0 12px; padding-left: 22px; }
.ask-md li { margin: 4px 0; }
.ask-md strong { font-weight: 700; color: var(--txt); }
.ask-md a { color: #a78bfa; text-decoration: underline; text-underline-offset: 2px; }
.ask-md blockquote { margin: 0 0 12px; padding: 4px 14px; border-left: 3px solid var(--brand); color: var(--txt2); }
.ask-md :not(pre) > code { padding: 2px 6px; border-radius: 6px; background: rgba(139,92,246,.16); color: #c4b5fd; font-size: .9em; }
.ask-code { margin: 0 0 14px; border-radius: 12px; overflow: hidden; background: #0d0d22; border: 1px solid #26264f; }
.ask-code-bar { display: flex; align-items: center; justify-content: space-between; padding: 7px 12px; background: #15153a; color: #a3a1c2; font-size: 12.5px; }
.ask-code-copy, .ask-copy { border: 1px solid var(--border2); background: transparent; color: var(--txt2); font: 500 12.5px var(--font); padding: 4px 10px; border-radius: 7px; cursor: pointer; }
.ask-code-copy { border-color: #2e2e5c; color: #a3a1c2; }
.ask-code-copy:hover, .ask-copy:hover { color: var(--txt); border-color: var(--brand); }
.ask-code-copy:hover { color: #ecebf7; }
.ask-code pre { margin: 0; padding: 14px 16px; overflow-x: auto; color: #e2e0f0; font-size: 13.5px; line-height: 1.6; }
.ask-table { margin: 0 0 14px; overflow-x: auto; }
.ask-table table { border-collapse: collapse; font-size: 14px; min-width: 60%; }
.ask-table th, .ask-table td { padding: 8px 12px; border: 1px solid var(--border2); text-align: left; vertical-align: top; }
.ask-table th { background: var(--bg3); font-weight: 600; }
.ask-sources { margin-top: 6px; padding: 12px 16px; border-radius: 12px; background: var(--bg2); border: 1px solid var(--border); font-size: 14px; }
.ask-sources[hidden] { display: none; }
.ask-sources-title { margin: 0 0 6px; font-weight: 600; color: var(--txt2); font-size: 13px; text-transform: uppercase; letter-spacing: .06em; }
.ask-sources ol { margin: 0; padding-left: 20px; }
.ask-sources a { color: #a78bfa; }
.ask-suggest-frame { display: block; width: 100%; height: 64px; margin-top: 10px; border: 0; border-radius: 12px; background: transparent; }
.ask-actions { margin-top: 8px; }
.ask-actions[hidden] { display: none; }
.ask-error { color: #f87171; }
.ask-error a { color: var(--brand); font-weight: 600; }
.ask-warn { color: var(--txt3); font-size: 14px; font-style: italic; }
.ask-dots { display: none; gap: 5px; padding: 10px 0; }
.is-thinking .ask-dots { display: flex; }
.ask-dots span { width: 8px; height: 8px; border-radius: 50%; background: #a78bfa; animation: ask-dot 1.2s infinite ease-in-out; }
.ask-dots span:nth-child(2) { animation-delay: .15s; }
.ask-dots span:nth-child(3) { animation-delay: .3s; }
@keyframes ask-dot { 0%, 80%, 100% { opacity: .25; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-4px); } }

/* ── Right: topics ───────────────────────────────────────────── */
.ask-topics { align-self: start; margin: 26px 28px 24px 4px; padding: 22px 20px; border-radius: 20px; border: 1px solid var(--border);
  background: rgba(21,21,52,.55); display: flex; flex-direction: column; gap: 12px; }
.ask-topics h2 { margin: 2px 2px 8px; font-size: 19px; font-weight: 700; color: var(--txt); }
/* 13 questions: compact rows, and the panel scrolls if the screen is short */
.ask-topics { gap: 6px; max-height: calc(100% - 50px); overflow-y: auto; scrollbar-width: thin; }
.ask-topics .ask-topic { padding: 8px 12px 8px 14px; border-radius: 10px; font-size: 13.5px; line-height: 1.3; }
.ask-topic { display: flex; align-items: center; justify-content: space-between; gap: 12px; width: 100%; padding: 17px 18px 17px 20px; border-radius: 16px;
  border: 1px solid var(--border); background: rgba(255,255,255,.025); color: var(--txt); font: 500 15.5px var(--font); text-align: left; cursor: pointer;
  transition: border-color .15s, background .15s, transform .15s var(--ease); }
.ask-topic svg { flex-shrink: 0; color: var(--txt2); transition: transform .15s var(--ease), color .15s; }
.ask-topic:hover { border-color: rgba(139,92,246,.55); background: rgba(139,92,246,.08); }
.ask-topic:hover svg { transform: translateX(3px); color: var(--txt); }

/* ── Light theme ─────────────────────────────────────────────── */
html[data-theme="light"] .ask-side { background: radial-gradient(420px 380px at 0% 100%, rgba(139,92,246,.10), transparent 70%), #fbfaff; }
html[data-theme="light"] .ask-chat:hover { background: var(--bg2); }
html[data-theme="light"] .ask-pill { color: #6d28d9; background: rgba(124,58,237,.08); border-color: rgba(124,58,237,.45); }
html[data-theme="light"] .ask-composer { background: #fff; border-color: rgba(124,58,237,.5); box-shadow: 0 18px 50px -24px rgba(99,102,241,.45); }
html[data-theme="light"] .ask-tool:hover { background: var(--bg2); }
html[data-theme="light"] .ask-switch::before { background: #fff; }
html[data-theme="light"] .ask-chip, html[data-theme="light"] .ask-topic { background: #fff; }
html[data-theme="light"] .ask-chip:hover, html[data-theme="light"] .ask-topic:hover { background: #f5f3ff; }
html[data-theme="light"] .ask-topics { background: #fff; box-shadow: var(--shadow-sm); }
html[data-theme="light"] .ask-bubble { background: #ede9fe; border-color: #ddd6fe; }
html[data-theme="light"] .ask-file-tag { background: rgba(124,58,237,.1); }
html[data-theme="light"] .ask-md a, html[data-theme="light"] .ask-sources a { color: #6d28d9; }
html[data-theme="light"] .ask-md :not(pre) > code { background: #ede9fe; color: #5b21b6; }
html[data-theme="light"] .ask-chat-menu .is-danger, html[data-theme="light"] .ask-error { color: #dc2626; }
html[data-theme="light"] .ask-dots span { background: #7c3aed; }

/* ── Smaller screens ─────────────────────────────────────────── */
@media (max-width: 1180px) {
  .ask-layout { grid-template-columns: 270px minmax(0, 1fr); }
  .ask-topics { display: none; }
  .ask-page:not(.has-thread) .ask-layout { height: auto; min-height: calc(100dvh - 64px); grid-template-rows: auto 1fr; }
  .ask-page:not(.has-thread) .ask-side { grid-row: 1 / span 2; }
  .ask-page:not(.has-thread) .ask-topics { display: flex; grid-column: 2; margin: 0 32px 32px; max-width: 920px; justify-self: center; width: calc(100% - 64px); }
}

@media (max-width: 760px) {
  .ask-layout, .ask-page:not(.has-thread) .ask-layout { grid-template-columns: minmax(0, 1fr); }
  .ask-page:not(.has-thread) .ask-topics { grid-column: 1; margin: 0 16px 28px; width: auto; }
  .ask-side { position: fixed; z-index: 90; top: 64px; bottom: 0; left: 0; width: min(86vw, 320px); padding: 20px 16px; background: var(--bg1);
    transform: translateX(-102%); transition: transform .25s var(--ease); box-shadow: var(--shadow-lg); }
  .side-open .ask-side { transform: none; }
  .ask-scrim { position: fixed; inset: 64px 0 0; z-index: 80; background: rgba(0,0,0,.45); opacity: 0; pointer-events: none; transition: opacity .25s; }
  .side-open .ask-scrim { opacity: 1; pointer-events: auto; }
  .ask-chat-more { opacity: 1; }
  .ask-main { padding: 14px 16px 14px; }
  .ask-mobilebar { display: flex; justify-content: space-between; gap: 10px; margin-bottom: 18px; }
  .ask-pill { font-size: 12px; padding: 7px 13px; }
  .ask-title { margin-top: 16px; }
  .ask-sub { font-size: 16px; }
  .ask-dock { margin-top: 26px; }
  .ask-composer { padding: 14px 12px 12px 16px; border-radius: 16px; }
  .ask-composer textarea { font-size: 16px; padding-right: 0; }
  .ask-tools { gap: 8px; padding-right: 60px; }
  .ask-web span { display: none; }
  .ask-send { width: 52px; height: 48px; right: 10px; bottom: 10px; border-radius: 13px; }
  .ask-chips { gap: 10px; margin-top: 18px; }
  .ask-chip { padding: 11px 16px; font-size: 14.5px; gap: 9px; }
  .ask-chip svg { width: 18px; height: 18px; }
  .ask-bubble { max-width: 88%; }
  .ask-msg { gap: 10px; }
  .ask-avatar { width: 30px; height: 30px; }
}
@media (min-width: 761px) { .ask-scrim { display: none; } }
.ask-guest { display: block; margin-top: 4px; }
.ask-guest a { color: var(--brand); font-weight: 600; }
.ask-web[hidden], .ask-divider[hidden] { display: none; }
