/* Ask the Sage (sage-mode.js): the question box, the answer with its sources, questions to try. */
.app.sage #sagePanel { max-width: 1060px; margin-inline: auto; }
#sagePanel .sg-layout { display: grid; grid-template-columns: 250px minmax(0, 1fr); gap: 28px; align-items: start; }
#sagePanel h1 { font-size: 24px; margin: 0 0 6px; }
#sagePanel .sg-wrap { display: flex; flex-direction: column; min-height: calc(100dvh - 48px); }
#sagePanel .sg-thread { flex: 1; display: flex; flex-direction: column; gap: 22px; padding-bottom: 12px; }
#sagePanel .sg-hello { margin-top: auto; }
#sagePanel .sg-turn { display: flex; flex-direction: column; gap: 10px; }
#sagePanel .sg-ask { position: sticky; bottom: 0; padding: 10px 0 12px; background: var(--panel, #fff); }
#sagePanel .sg-box { display: flex; gap: 8px; align-items: flex-end; padding: 6px; border: 1px solid var(--line); border-radius: 18px; background: var(--d-panel, #fff); box-shadow: 0 4px 18px rgba(20, 24, 33, .08); }
#sagePanel .sg-box:focus-within { border-color: var(--indigo); }
#sagePanel .sg-ask textarea { flex: 1; min-width: 0; min-height: 40px; max-height: 160px; padding: 9px 10px; border: 0; outline: 0; background: none;
  color: var(--ink); font: 15px/1.4 "Plus Jakarta Sans", Heebo, system-ui, sans-serif; resize: none; field-sizing: content; }
#sagePanel .sg-ask .next { flex: none; min-height: 40px; padding: 0 16px; border: 0; border-radius: 12px; background: var(--indigo); color: #fff; font-weight: 800; cursor: pointer; }
#sagePanel .sg-foot { display: flex; flex-wrap: wrap; justify-content: center; gap: 4px 12px; margin: 6px 0 0; font-size: 12px; color: var(--muted); text-align: center; }
#sagePanel .sg-left { font: 600 12px "JetBrains Mono", ui-monospace, monospace; }
#sagePanel .sg-q { align-self: flex-end; max-width: 80%; padding: 10px 14px; border-radius: 18px 18px 4px 18px; background: var(--d-soft, var(--indigo-soft)); font-weight: 700; }
#sagePanel .sg-a p { margin: 0 0 10px; line-height: 1.6; }
#sagePanel .sg-a > p:first-child { font-size: 16px; }
#sagePanel .sg-a ul, #sagePanel .sg-a ol { margin: 0 0 12px; padding-inline-start: 22px; }
#sagePanel .sg-a li { margin: 7px 0; line-height: 1.5; padding-inline-start: 2px; }
#sagePanel .sg-a li::marker { color: var(--indigo); }
#sagePanel .sg-a .sg-h { margin: 18px 0 6px; padding-bottom: 4px; border-bottom: 1px solid var(--line); font: 800 13px "Plus Jakarta Sans", Heebo, system-ui, sans-serif; letter-spacing: .04em; text-transform: uppercase; color: var(--indigo); }
#sagePanel .sg-a b { font-weight: 800; }
#sagePanel .sg-a p.sg-cau { padding: 10px 12px; border-radius: 12px; background: var(--d-warn, #fff6dc); color: var(--d-warn-ink, #7a5600); font-size: 14px; }
#sagePanel .sg-pt { display: inline; min-height: 0; padding: 1px 6px; border: 1px solid var(--indigo); border-radius: 6px; background: none; color: var(--indigo);
  font: 700 13px "JetBrains Mono", ui-monospace, monospace; cursor: pointer; }
#sagePanel .sg-src { margin: 4px 0 0; padding: 10px 12px; border-radius: 12px; border: 1px solid var(--line); font-size: 13px; }
#sagePanel .sg-beyond { margin: 8px 0 0; padding: 10px 12px; border-radius: 12px; border: 1px dashed var(--line); font-size: 14px; }
#sagePanel .sg-beyond .muted { margin: 2px 0 6px; font-size: 12px; }
#sagePanel .sg-took { margin: 6px 2px 0; font-size: 12px; }
#sagePanel .sg-src ul { margin: 6px 0 0; padding-inline-start: 18px; color: var(--muted); }
#sagePanel .sg-note { margin: 10px 0; padding: 10px 12px; border-radius: 12px; background: var(--d-warn, #fff6dc); color: var(--d-warn-ink, #7a5600); font-size: 13px; }
#sagePanel .sg-note.bad { background: var(--d-bad, #fdecec); color: var(--d-bad-ink, #a12a2e); }
#sagePanel .sg-wait { color: var(--muted); }
#sagePanel .sn-label { margin: 18px 0 8px; font: 700 11px "JetBrains Mono", ui-monospace, monospace; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
#sagePanel .sg-chips { display: flex; flex-wrap: wrap; gap: 8px; }
#sagePanel .sg-chip { min-height: 36px; padding: 6px 12px; border: 1px solid var(--line); border-radius: 999px; background: var(--d-panel, #fff); color: var(--ink);
  font: 14px "Plus Jakarta Sans", Heebo, system-ui, sans-serif; text-align: start; cursor: pointer; }
#sagePanel .sg-chip:hover { border-color: var(--indigo); }

#sagePanel .sg-pill { display: none; } /* phone.css shows it once a point is opened from an answer */

/* Chat history, as in other chats: New chat, a search box, then past chats by day (kept in this browser only). */
#sagePanel .sg-hist { position: sticky; top: 0; display: flex; flex-direction: column; gap: 4px; max-height: 100dvh; overflow-y: auto; padding: 4px 0 12px; }
#sagePanel .sg-new { min-height: 40px; padding: 0 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--d-panel, #fff); color: var(--ink); font: 700 14px "Plus Jakarta Sans", Heebo, system-ui, sans-serif; text-align: start; cursor: pointer; }
#sagePanel .sg-new:hover { border-color: var(--indigo); }
#sagePanel .sg-search { min-height: 38px; margin: 6px 0 2px; padding: 0 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--d-panel, #fff); color: var(--ink); font: 14px "Plus Jakarta Sans", Heebo, system-ui, sans-serif; }
#sagePanel .sg-search:focus { outline: 0; border-color: var(--indigo); }
#sagePanel .sg-hist .sn-label { margin: 14px 8px 4px; }
#sagePanel .sg-hrow { position: relative; display: flex; border-radius: 10px; }
#sagePanel .sg-hrow:hover, #sagePanel .sg-hrow.on { background: var(--d-soft, var(--indigo-soft)); }
#sagePanel .sg-hi { flex: 1; min-width: 0; min-height: 38px; padding: 6px 34px 6px 10px; padding-inline: 10px 34px; border: 0; background: none; color: var(--ink); font: 14px/1.3 "Plus Jakarta Sans", Heebo, system-ui, sans-serif; text-align: start; cursor: pointer; }
#sagePanel .sg-hi span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#sagePanel .sg-hi small { display: block; margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); font-size: 12px; }
#sagePanel .sg-hx { position: absolute; inset-block: 0; inset-inline-end: 4px; width: 28px; min-height: 0; border: 0; background: none; color: var(--muted); font-size: 18px; cursor: pointer; opacity: 0; }
#sagePanel .sg-hrow:hover .sg-hx, #sagePanel .sg-hx:focus-visible { opacity: 1; }
#sagePanel .sg-none { margin: 10px 8px; font-size: 13px; }
#sagePanel .sg-histbtn { display: none; }

/* ChatGPT-like look: greeting and question cards, a round send button in a pill, marked search matches. */
#sagePanel .sg-hello { text-align: center; margin: auto; padding: 8px 0 18px; }
#sagePanel .sg-hello h1 { font-size: 28px; margin: 0 0 8px; }
#sagePanel .sg-chips { justify-content: center; }
#sagePanel .sg-chip { padding: 6px 14px; font-size: 13.5px; }
#sagePanel .sg-box { border-radius: 28px; padding: 6px 6px 6px 14px; padding-inline: 14px 6px; }
#sagePanel .sg-ask .next { width: 40px; height: 40px; min-height: 40px; padding: 0; border-radius: 50%; font-size: 0; background: var(--ink); color: var(--panel, #fff); }
#sagePanel .sg-ask .next::before { content: "↑"; font-size: 20px; font-weight: 800; line-height: 40px; }
#sagePanel .sg-ask .next:disabled { opacity: .4; }
#sagePanel mark { background: color-mix(in srgb, var(--indigo) 28%, transparent); color: inherit; border-radius: 3px; padding: 0 1px; }
#sagePanel mark.sg-hit.cur { background: #ffc83d88; }
#sagePanel .sg-count { margin: 8px 8px 0; font-size: 12px; }
#sagePanel .sg-askq { display: flex; flex-direction: column; gap: 2px; margin: 12px 0 0; padding: 12px 14px; border: 1px solid var(--line); border-radius: 16px; background: none; color: var(--ink); font: inherit; text-align: start; cursor: pointer; }
#sagePanel .sg-askq b { font-size: 14px; } #sagePanel .sg-askq small { color: var(--muted); font-size: 12px; }
#sagePanel .sg-found { position: sticky; top: 0; z-index: 3; display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 0 0 10px; padding: 6px 8px; border: 1px solid var(--line); border-radius: 14px; background: var(--d-glass, color-mix(in srgb, var(--panel, #fff) 88%, transparent)); backdrop-filter: blur(10px); font-size: 13px; }
#sagePanel .sg-found button { min-height: 32px; padding: 0 10px; border: 0; border-radius: 10px; background: none; color: var(--indigo); font: 700 13px inherit; font-family: inherit; cursor: pointer; }
#sagePanel .sg-nav { display: flex; align-items: center; gap: 2px; color: var(--muted); } #sagePanel .sg-pos { min-width: 34px; text-align: center; font: 600 12px "JetBrains Mono", monospace; }
#sagePanel .sg-dim, #sagePanel .sg-hclose { display: none; }

/* Desktop: the body is a big picture above an empty chat, and a strip above a running one. */
@media (min-width: 1025px) {
  /* :not(:has(#patToggle…)) matches d-orbit.html's desktop row rule, which carries an ID and would win otherwise. */
  .app.app.app.app.exam.sage:not(:has(#patToggle:not([hidden]))) { --sg-hero: clamp(300px, 46vh, 460px); grid-template-areas: "bar bar bar" "rail stage stage" "rail aside aside"; grid-template-columns: 0 minmax(0, 1fr) 0; grid-template-rows: 0 var(--sg-hero) minmax(0, 1fr); transition: grid-template-rows .3s ease; }
  .app.app.app.app.exam.sage.sg-talk:not(:has(#patToggle:not([hidden]))) { --sg-hero: clamp(220px, 34vh, 320px); }
  /* History is a full-height column at the edge; the body stands above the chat only (the stage overlaps the aside). */
  .app.exam.sage { --sg-histw: 260px; }
  .app.exam.sage > .stage { grid-row: 2; grid-column: 2 / 4; z-index: 2; min-height: 0; margin-inline-start: var(--sg-histw); }
  .app.exam.sage > aside { grid-row: 2 / 4; grid-column: 2 / 4; }
  .app.exam.sage > aside { border: 0; padding: 0; }
  .app.sage #sagePanel { max-width: none; margin: 0; }
  .app.sage #anatList { display: none; } /* the body keeps its toolbar (views, layers, centre); the parts list belongs to the Anatomy tab */
  .app.sage > aside > .legal { display: none; } /* the question box already says it is a study aid */
  #sagePanel .sg-layout { grid-template-columns: var(--sg-histw) minmax(0, 1fr); gap: 0; }
  #sagePanel .sg-wrap { min-height: 100dvh; padding: var(--sg-hero) 24px 0; transition: padding-top .3s ease; }
  #sagePanel .sg-hello { margin: 8px auto auto; }
  #sagePanel .sg-hist { height: 100dvh; max-height: none; padding: 14px 12px; border-inline-end: 1px solid var(--line); background: var(--d-panel2, #f7f8fb); }
  #sagePanel .sg-thread { max-width: 760px; width: 100%; margin-inline: auto; }
  #sagePanel .sg-ask { max-width: 760px; width: 100%; margin-inline: auto; }
}

/* Desktop: the chat folds away (its ⇥ button) into a pill, and the body takes the whole page until the pill is clicked. */
#sagePanel .sg-fold { display: none; }
@media (min-width: 1025px) {
  #sagePanel .sg-wrap { position: relative; }
  #sagePanel .sg-fold { display: grid; place-items: center; position: sticky; z-index: 3; top: 10px; align-self: flex-end; width: 34px; height: 34px; min-height: 0; margin: 10px 0 6px; padding: 0;
    border: 1px solid var(--line); border-radius: 10px; background: var(--d-panel, #fff); color: var(--muted); cursor: pointer; }
  #sagePanel .sg-fold::before { content: ""; width: 16px; height: 12px; border: 1.8px solid currentColor; border-radius: 3px; border-inline-end-width: 6px; }
  #sagePanel .sg-fold:hover { color: var(--indigo); border-color: var(--indigo); }
  #sagePanel[data-mini] > .sg-layout { display: none; }
  #sagePanel[data-mini] > .sg-pill { display: block; min-height: 44px; padding: 0 22px; border: 0; border-radius: 999px; background: var(--indigo); color: #fff; font-weight: 800; cursor: pointer; box-shadow: 0 6px 20px #0004; }
  .app.app.app.exam.sage > aside:has(#sagePanel[data-mini]) { position: fixed; z-index: 6; inset: auto 24px 24px auto; inset-inline: auto 24px; width: auto; height: auto; overflow: visible; border: 0; background: none; }
  .app.app.app.exam.sage:has(#sagePanel[data-mini]) > .stage { grid-row: 2 / 4; grid-column: 2 / 4; margin: 0; }
}

/* Wide desktop: the body has its own full-height column beside the chat instead of a picture above it. */
@media (min-width: 1280px) {
  .app.app.app.app.exam.sage:not(:has(#patToggle:not([hidden]))), .app.app.app.app.exam.sage.sg-talk:not(:has(#patToggle:not([hidden]))) {
    --sg-hero: 0px; --sg-chatw: clamp(460px, 36vw, 660px); grid-template-columns: 0 calc(var(--sg-histw) + var(--sg-chatw)) minmax(0, 1fr); grid-template-rows: 0 minmax(0, 1fr) 0; }
  .app.app.app.exam.sage > .stage { grid-row: 2 / 4; grid-column: 3; margin: 0; }
  .app.app.app.exam.sage > aside { grid-column: 2; border-inline-end: 1px solid var(--line); }
  #sagePanel .sg-layout { grid-template-columns: var(--sg-histw) minmax(0, 1fr); }
  #sagePanel .sg-wrap { padding-top: 0; }
  #sagePanel .sg-hello { margin: auto; }
}

/* Share under an answer (sage-mode.js), and the note on an answer someone shared. */
#sagePanel .sg-share { display: inline-flex; align-items: center; gap: 6px; margin: 8px 0 0; padding: 4px 10px; border: 1px solid var(--line); border-radius: 999px; background: transparent; color: var(--muted, inherit); font: inherit; font-size: 13px; cursor: pointer; }
#sagePanel .sg-share:hover { background: var(--indigo-soft); }
#sagePanel .sg-share svg { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 1.8; }
#sagePanel .sg-from { margin: 0 0 4px; font-size: 12px; }
.sg-sharedlg blockquote { margin: 10px 0 14px; padding: 10px 12px; border-radius: 10px; background: var(--indigo-soft); white-space: pre-wrap; }
/* A channel answer (answers/sage.js): headings and lists, then a button to the channel's full page. */
#sagePanel .sg-a h4 { margin: 14px 0 6px; font-size: 15px; }
#sagePanel .sg-a h4:first-child { margin-top: 0; }
#sagePanel .sg-a ul { margin: 0 0 10px; padding-inline-start: 20px; line-height: 1.5; }
#sagePanel .sg-a li { margin-bottom: 4px; }
#sagePanel .sg-open { margin: 4px 0 10px; }
#sagePanel bdi { white-space: nowrap; }

/* The answer's points at the body's foot (sage-mode.js): the pain circles, smaller. */
.stage > .pfoot.sg-pts { bottom: 10px; }
.pfoot.sg-pts .pf-row { gap: 8px 10px; max-height: 96px; padding: 4px; }
.pfoot.sg-pts .pf-c { width: 38px; height: 38px; border-width: 2px; font-size: 10.5px; cursor: pointer; }
@media (max-width: 1024px) {
  .app.sage:not(:has(#sagePanel[data-mini])) .stage > .pfoot.sg-pts { display: none; }
  /* Above the "Chinese Sage" pill, clear of the share button at the edge. */
  .app.sage .stage > .pfoot.sg-pts { bottom: calc(var(--sab, 0px) + 72px); inset-inline: 48px; }
}
