:root {
  --bg: #ffffff;
  --sidebar: #f9f9f9;
  --bubble: #e9e9e980;
  --text: #0d0d0d;
  --text2: #5d5d5d;
  --border: #0000001a;
  --composer: #ffffff;
  --composer-shadow: 0 0 0 1px #0000000f, 0 4px 16px #0000000d;
  --hover: #ececec;
  --active: #e3e3e3;
  --send-bg: #000000;
  --send-fg: #ffffff;
  --send-disabled: #d7d7d7;
  --inline-code: #ececec;
  --code-bg: #171717;
  --code-head: #2f2f2f;
  --error-bg: #fef2f2;
  --error-border: #fca5a5;
  --error-text: #b91c1c;
  --chip-border: #0000001f;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #212121;
    --sidebar: #181818;
    --bubble: #303030;
    --text: #ececec;
    --text2: #b4b4b4;
    --border: #ffffff1a;
    --composer: #303030;
    --composer-shadow: 0 0 0 1px #ffffff0d;
    --hover: #ffffff12;
    --active: #ffffff1c;
    --send-bg: #ffffff;
    --send-fg: #000000;
    --send-disabled: #676767;
    --inline-code: #ffffff1a;
    --code-bg: #0d0d0d;
    --code-head: #2f2f2f;
    --error-bg: #ef44441a;
    --error-border: #ef444466;
    --error-text: #fca5a5;
    --chip-border: #ffffff26;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: ui-sans-serif, -apple-system, system-ui, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; padding: 0; }

.app { display: flex; height: 100dvh; width: 100%; overflow: hidden; }

.sidebar {
  width: 260px; flex: 0 0 260px;
  background: var(--sidebar);
  display: flex; flex-direction: column;
  padding: 8px;
  transition: margin-left .2s ease, transform .2s ease;
  overflow: hidden;
  z-index: 30;
}
.app.collapsed .sidebar { margin-left: -260px; }
.sb-top { display: flex; align-items: center; justify-content: space-between; height: 44px; padding: 0 4px 0 10px; }
.brand { font-weight: 600; font-size: 16px; }
.icon-btn {
  width: 36px; height: 36px; border-radius: 8px;
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--text2);
}
.icon-btn:hover { background: var(--hover); color: var(--text); }
.sb-row {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: 10px; text-align: left; font-size: 14px; margin-top: 6px;
}
.sb-row:hover { background: var(--hover); }
.sb-row[hidden] { display: none; }
a.sb-row { color: inherit; text-decoration: none; }
.sb-label { font-size: 13px; color: var(--text2); padding: 18px 10px 6px; }
.conv-list { flex: 1; overflow-y: auto; overflow-x: hidden; }
.conv-item {
  position: relative; display: flex; align-items: center;
  border-radius: 10px; font-size: 14px; cursor: pointer; margin-bottom: 1px;
}
.conv-item:hover { background: var(--hover); }
.conv-item.active { background: var(--active); }
.conv-item .t {
  flex: 1; min-width: 0; padding: 8px 10px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.conv-item .del {
  display: none; width: 28px; height: 28px; margin-right: 4px; border-radius: 6px;
  align-items: center; justify-content: center; color: var(--text2); flex: 0 0 28px;
}
.conv-item:hover .del, .conv-item.active .del { display: inline-flex; }
.conv-item .del:hover { color: #ef4444; background: var(--hover); }
.sb-user-wrap { position: relative; border-top: 1px solid var(--border); margin-top: 6px; padding-top: 6px; }
.sb-user { display: flex; align-items: center; gap: 10px; padding: 10px; width: 100%; background: none; border: 0; color: inherit; font: inherit; text-align: left; cursor: pointer; border-radius: 10px; }
.sb-user:hover { background: var(--hover); }
.user-menu { position: absolute; bottom: calc(100% + 4px); left: 0; right: 0; z-index: 60; background: var(--bg); border: 1px solid var(--border); border-radius: 14px; box-shadow: 0 8px 28px #00000026; padding: 6px; }
.user-menu-head { font-size: 12.5px; color: var(--text2); padding: 8px 10px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-menu-item { display: block; width: 100%; text-align: left; padding: 9px 10px; border-radius: 8px; background: none; border: 0; font: inherit; font-size: 14px; color: inherit; text-decoration: none; cursor: pointer; }
.user-menu-item:hover, .user-menu-item:focus-visible { background: var(--hover); outline: none; }
.user-menu-label { font-size: 12px; font-weight: 600; color: var(--text2); padding: 8px 10px 4px; }
.user-menu-sep { height: 1px; background: var(--border); margin: 6px 4px; }
.switcher-list { max-height: min(46vh, 360px); overflow-y: auto; font-size: 13px; color: var(--text2); }
.switcher-item { display: flex; align-items: center; gap: 8px; width: 100%; text-align: left; padding: 7px 10px; border-radius: 8px; background: none; border: 0; font: inherit; font-size: 13.5px; color: var(--text); cursor: pointer; }
.switcher-item:hover:not([aria-checked="true"]), .switcher-item:focus-visible { background: var(--hover); outline: none; }
.switcher-item[aria-checked="true"] { cursor: default; font-weight: 600; }
.switcher-item:disabled { opacity: .6; cursor: progress; }
.switcher-item svg { margin-left: auto; flex: 0 0 auto; }
.switcher-tag { flex: 0 0 52px; font-size: 11.5px; color: var(--text2); font-weight: 500; }
.switcher-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.switcher-empty, .switcher-error { padding: 6px 10px; }
.switcher-error { color: var(--error-text); }
.sb-user.viewing-as .avatar { box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px #e0a100; }
.view-as-bar { display: flex; align-items: center; justify-content: center; gap: 12px; flex-wrap: wrap; padding: 6px 16px; font-size: 13px; background: #fff4d6; color: #5c4300; border-bottom: 1px solid #f0d58a; }
.view-as-bar[hidden] { display: none; }
.view-as-back { font: inherit; font-size: 12.5px; font-weight: 600; color: inherit; background: #ffffff99; border: 1px solid #e3c46c; border-radius: 999px; padding: 3px 12px; cursor: pointer; }
.view-as-back:hover { background: #fff; }
@media (prefers-color-scheme: dark) {
  .view-as-bar { background: #3a2f10; color: #f3d98a; border-bottom-color: #5c4a17; }
  .view-as-back { background: #ffffff14; border-color: #7a6320; }
  .view-as-back:hover { background: #ffffff24; }
}
.avatar {
  width: 28px; height: 28px; border-radius: 50%;
  background: #10a37f; color: #fff; font-size: 11px; font-weight: 600;
  display: flex; align-items: center; justify-content: center;
}
.user-name { font-size: 14px; }

.backdrop { display: none; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; position: relative; background: var(--bg); }
.topbar { height: 52px; flex: 0 0 52px; display: flex; align-items: center; padding: 0 8px; }
.topbar-left { display: flex; align-items: center; gap: 2px; }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 8px; padding-right: 6px; }
.topbar-link { font-size: 13px; color: var(--muted, #8e8ea0); text-decoration: none; padding: 5px 10px; border-radius: 8px; }
.topbar-link:hover { background: var(--hover, rgba(127,127,127,.12)); color: inherit; }
.only-collapsed { display: none; }
.app.collapsed .only-collapsed { display: inline-flex; }
.model-label {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 18px; font-weight: 500; padding: 6px 10px; border-radius: 8px; cursor: pointer;
  background: none; border: 0; color: inherit; font-family: inherit;
}
.model-label svg { color: var(--text2); }
.model-label:hover { background: var(--hover); }

.scroller { flex: 1; overflow-y: auto; overflow-x: hidden; }
.empty {
  min-height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 16px 16px 12vh;
}
.empty-title { font-size: 28px; font-weight: 500; margin: 0 0 28px; text-align: center; }
.empty .composer-slot { width: 100%; max-width: 768px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 18px; max-width: 768px; }
.chip {
  border: 1px solid var(--chip-border); border-radius: 999px; padding: 8px 14px;
  font-size: 13px; color: var(--text2);
}
.chip:hover { background: var(--hover); color: var(--text); }

.app.has-thread .empty { display: none; }
.app:not(.has-thread) .thread { display: none; }
.app:not(.has-thread) .bottom { display: none; }

.thread { max-width: 768px; margin: 0 auto; padding: 16px 16px 32px; }
.msg { margin: 0 0 24px; }
.msg.user { display: flex; justify-content: flex-end; }
.bubble {
  background: var(--bubble); border-radius: 20px; padding: 10px 18px;
  max-width: 70%; white-space: pre-wrap; word-wrap: break-word; overflow-wrap: anywhere; line-height: 1.5;
}
.msg.assistant { width: 100%; }
.md { line-height: 1.65; overflow-wrap: break-word; }
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md p { margin: 0 0 14px; }
.md h1, .md h2, .md h3, .md h4 { line-height: 1.3; margin: 22px 0 10px; font-weight: 600; }
.md h1 { font-size: 1.6em; } .md h2 { font-size: 1.35em; } .md h3 { font-size: 1.15em; } .md h4 { font-size: 1em; }
.md ul, .md ol { padding-left: 1.6em; margin: 0 0 14px; }
.md li { margin: 4px 0; }
.md li > p { margin: 0 0 6px; }
.md a { color: #3b82f6; }
.md hr { border: 0; border-top: 1px solid var(--border); margin: 24px 0; }
.md blockquote { margin: 0 0 14px; padding: 2px 0 2px 14px; border-left: 3px solid var(--border); color: var(--text2); }
.md code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .875em; }
.md :not(pre) > code { background: var(--inline-code); padding: 2px 5px; border-radius: 6px; }
.md table { border-collapse: collapse; margin: 0 0 14px; display: block; overflow-x: auto; max-width: 100%; }
.md th, .md td { border: 1px solid var(--border); padding: 6px 12px; text-align: left; }
.md th { font-weight: 600; background: var(--hover); }
.code-wrap { background: var(--code-bg); border-radius: 12px; overflow: hidden; margin: 0 0 14px; }
.code-head {
  display: flex; justify-content: space-between; align-items: center;
  background: var(--code-head); color: #b4b4b4; font-size: 12px; padding: 6px 14px;
}
.code-head button { color: #b4b4b4; font-size: 12px; display: inline-flex; gap: 4px; align-items: center; }
.code-head button:hover { color: #fff; }
.code-wrap pre { margin: 0; padding: 14px; overflow-x: auto; color: #ececec; }
.code-wrap pre code { background: none; padding: 0; font-size: 13.5px; line-height: 1.5; }
.md .katex-display { overflow-x: auto; overflow-y: hidden; padding: 4px 0; margin: 10px 0 14px; }
.md .katex { font-size: 1.08em; }

.actions { display: flex; gap: 2px; margin-top: 6px; opacity: .75; }
.msg.assistant:hover .actions { opacity: 1; }
.actions button {
  width: 30px; height: 30px; border-radius: 8px; color: var(--text2);
  display: inline-flex; align-items: center; justify-content: center;
}
.actions button:hover { background: var(--hover); color: var(--text); }

.thinking { display: inline-block; width: 12px; height: 12px; border-radius: 50%; background: var(--text); animation: pulse 1.1s ease-in-out infinite; margin-top: 8px; }
@keyframes pulse { 0%, 100% { transform: scale(.7); opacity: .5; } 50% { transform: scale(1); opacity: 1; } }
.tool-status { display: flex; align-items: center; gap: 8px; min-width: 0; font-size: 13px; line-height: 20px; color: var(--text2); }
.tool-status.live { margin-top: 8px; }
.tool-status.steps { display: block; margin-bottom: 6px; opacity: .8; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tool-label { min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; animation: tool-fade 1.6s ease-in-out infinite; }
.tool-spin { flex: 0 0 12px; width: 12px; height: 12px; border-radius: 50%; border: 2px solid var(--border); border-top-color: var(--text2); animation: tool-spin .8s linear infinite; }
@keyframes tool-spin { to { transform: rotate(360deg); } }
@keyframes tool-fade { 0%, 100% { opacity: 1; } 50% { opacity: .55; } }
@media (prefers-reduced-motion: reduce) { .tool-spin, .tool-label { animation: none; } }

.err {
  background: var(--error-bg); border: 1px solid var(--error-border); color: var(--error-text);
  border-radius: 10px; padding: 10px 14px; font-size: 14px; margin-top: 8px;
}

.bottom { position: relative; padding: 0 16px 8px; }
.bottom .composer-slot { max-width: 768px; margin: 0 auto; }
.disclaimer { text-align: center; font-size: 12px; color: var(--text2); padding: 8px 0 2px; }
.usage-meter { display: flex; align-items: center; justify-content: center; gap: 8px; font-size: 12px; color: var(--text2); padding: 2px 0 4px; }
.usage-meter[hidden] { display: none; }
.usage-bar { width: 96px; height: 4px; border-radius: 2px; background: var(--border); overflow: hidden; }
.usage-bar > span { display: block; height: 100%; width: 0; background: var(--text2); }
.usage-meter.blocked { color: #c0392b; }
.usage-meter.blocked .usage-bar > span { background: #c0392b; }
.scroll-down {
  position: absolute; left: 50%; top: -48px; transform: translateX(-50%);
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--bg); border: 1px solid var(--border); color: var(--text);
  display: none; align-items: center; justify-content: center;
  box-shadow: 0 2px 8px #0000001a; z-index: 5;
}
.scroll-down.show { display: inline-flex; }

.composer {
  display: flex; flex-wrap: wrap; align-items: flex-end; gap: 8px;
  background: var(--composer); border-radius: 26px; box-shadow: var(--composer-shadow);
  padding: 10px 10px 10px 10px; width: 100%;
}
.composer textarea {
  min-width: 0;
  flex: 1; resize: none; border: 0; outline: 0; background: transparent; color: var(--text);
  font: inherit; font-size: 16px; line-height: 24px; max-height: 200px; padding: 6px 0; overflow-y: auto;
}

/* Contextual composer tips remain in flow, so they never cover the draft. */
.feature-tip { flex-basis: 100%; background: var(--sidebar); border: 1px solid var(--border); border-radius: 16px; padding: 14px; text-align: left; }
.feature-tip[hidden], .voice-status[hidden], .voice-status button[hidden] { display: none; }
.feature-tip strong { font-size: 14px; color: var(--text); }
.feature-tip p { margin: 5px 0 12px; font-size: 13px; line-height: 1.5; color: var(--text2); }
.feature-tip-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.feature-tip-actions button { padding: 8px 10px; min-height: 36px; border-radius: 8px; color: var(--text2); font-size: 12px; }
.feature-tip-actions button:first-child { background: var(--send-bg); color: var(--send-fg); }
.feature-tip-actions button:hover { box-shadow: inset 0 0 0 1px var(--border); }
.feature-tip button:focus-visible, .mic-btn:focus-visible, .voice-status button:focus-visible { outline: 2px solid var(--text); outline-offset: 2px; }
.mic-btn { width: 36px; height: 36px; flex: 0 0 36px; display: inline-flex; align-items: center; justify-content: center; border-radius: 50%; color: var(--text2); }
.mic-btn:hover:not(:disabled) { background: var(--hover); color: var(--text); }
.mic-btn:disabled { opacity: .4; cursor: not-allowed; }
.mic-btn[hidden] { display: none; }
.mic-btn[aria-pressed="true"] { color: var(--error-text); background: var(--error-bg); box-shadow: inset 0 0 0 1px var(--error-border); }
.voice-status { flex-basis: 100%; display: flex; align-items: center; gap: 8px; padding: 2px 6px; color: var(--text2); font-size: 12px; line-height: 1.45; text-align: left; }
.voice-status span { flex: 1; }
.voice-status button { padding: 6px 8px; text-decoration: underline; }
.composer textarea::placeholder { color: var(--text2); }
.send-btn {
  width: 36px; height: 36px; flex: 0 0 36px; border-radius: 50%;
  background: var(--send-bg); color: var(--send-fg);
  display: inline-flex; align-items: center; justify-content: center;
}
.send-btn:disabled { background: var(--send-disabled); cursor: default; }
.send-btn .ic-stop { display: none; }
.send-btn.stop .ic-stop { display: block; }
.send-btn.stop .ic-send { display: none; }

@media (max-width: 767px) {
  .sidebar {
    position: fixed; top: 0; left: 0; bottom: 0; margin-left: 0 !important;
    transform: translateX(-100%);
  }
  .app.mobile-open .sidebar { transform: translateX(0); }
  .app.mobile-open .backdrop { display: block; position: fixed; inset: 0; background: #0006; z-index: 25; }
  .only-collapsed { display: inline-flex; }
  .bubble { max-width: 85%; }
  .empty-title { font-size: 24px; }
}

.gate {
  position: fixed; inset: 0; z-index: 100;
  background: var(--bg);
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
}
.gate[hidden] { display: none; }
.gate-card {
  width: 100%; max-width: 360px;
  display: flex; flex-direction: column; align-items: stretch;
  text-align: center;
}
.gate-title { font-size: 32px; font-weight: 600; margin: 0 0 8px; }
.gate-sub { color: var(--text2); margin: 0 0 24px; font-size: 16px; }
.gate-input {
  width: 100%; height: 52px; padding: 0 20px;
  border: 1px solid var(--chip-border); border-radius: 26px;
  background: var(--composer); color: var(--text);
  font: inherit; font-size: 16px; outline: none;
}
.gate-input:focus { border-color: var(--text2); }
.gate-input.invalid { border-color: var(--error-text); }
.gate-error { color: var(--error-text); font-size: 14px; text-align: left; margin: 8px 20px 0; }
.gate-error[hidden] { display: none; }
.gate-btn {
  width: 100%; height: 52px; margin-top: 16px; border-radius: 26px;
  background: var(--send-bg); color: var(--send-fg);
  font-weight: 500; font-size: 16px;
}
.gate-btn:disabled { background: var(--send-disabled); cursor: default; }

/* Tutoring-style picker */
.style-picker { position: relative; }
.style-btn-icon { font-size: 16px; }
.style-btn-name { color: var(--text2); font-weight: 400; margin-left: 4px; }
.style-btn-name:empty { display: none; }
.style-menu {
  position: absolute; top: calc(100% + 6px); left: 0; z-index: 60;
  width: 360px; max-width: calc(100vw - 32px);
  background: var(--bg); border: 1px solid var(--border); border-radius: 16px;
  box-shadow: 0 8px 28px #00000026; padding: 6px;
}
.style-menu-head { font-size: 13px; color: var(--text2); padding: 8px 10px 6px; }
.style-menu-sep { font-size: 12px; color: var(--text2); padding: 8px 10px 4px; margin-top: 4px; border-top: 1px solid var(--border); }
.style-item {
  display: flex; align-items: flex-start; gap: 10px; width: 100%; text-align: left;
  background: none; border: 0; color: inherit; font: inherit; cursor: pointer;
  padding: 10px; border-radius: 10px;
}
.style-item:hover, .style-item:focus-visible { background: var(--hover); outline: none; }
.style-item[aria-disabled="true"] { opacity: .5; cursor: not-allowed; }
.si-icon { font-size: 18px; line-height: 22px; width: 22px; text-align: center; flex: 0 0 22px; }
.si-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.si-name { font-size: 15px; font-weight: 500; }
.si-desc { font-size: 13px; color: var(--text2); line-height: 1.35; }
.si-check { margin-left: auto; flex: 0 0 16px; padding-top: 3px; }
.style-note { text-align: center; font-size: 12.5px; color: var(--text2); margin: 10px auto; }
.decision-note { font-size: 12.5px; line-height: 1.5; color: var(--text2); border-left: 3px solid var(--border); padding: 4px 0 4px 10px; margin: 0 0 10px; }
.decision-note.is-jev { border-left-color: #d97706; }
.decision-note > div:first-child { color: var(--text); font-weight: 500; }
@media (max-width: 480px) {
  .style-btn-name { display: none; }
  .style-menu { position: fixed; top: 56px; left: 16px; right: 16px; width: auto; }
}

/* ---- Settings modal (public/settings.js) ---- */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 100; background: #0006;
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.modal-backdrop[hidden] { display: none; }
.modal-panel {
  width: 100%; max-width: 480px; max-height: calc(100dvh - 32px);
  display: flex; flex-direction: column;
  background: var(--bg); color: var(--text); border: 1px solid var(--border); border-radius: 20px;
  box-shadow: 0 16px 48px #0000004d; overflow: hidden;
}
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 14px 10px 22px; border-bottom: 1px solid var(--border); flex: none; }
.modal-title { font-size: 18px; font-weight: 600; margin: 0; }
.modal-body { overflow-y: auto; overscroll-behavior: contain; padding: 18px 22px 22px; flex: 1 1 auto; min-height: 0; }

/* ---- Student uploads: attach button, tray, chips ---- */
.attach-btn { width: 36px; height: 36px; flex: 0 0 36px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; color: var(--text2); background: none; border: 0; cursor: pointer; }
.attach-btn:hover { background: var(--hover); color: var(--text); }
.att-tray { flex-basis: 100%; display: flex; flex-wrap: wrap; gap: 8px; padding: 2px 4px 4px; }
.att-tray[hidden] { display: none; }
.att-chip { display: inline-flex; align-items: center; gap: 8px; max-width: 100%; border: 1px solid var(--border); background: var(--bg); border-radius: 12px; padding: 6px 6px 6px 10px; font-size: 13px; }
.att-chip.needs-review { border-color: #d97706; background: #fffbeb; }
.att-chip.failed { border-color: var(--error-border); background: var(--error-bg); }
.att-chip.busy { opacity: .75; }
.att-icon { font-size: 16px; }
.att-open { display: flex; flex-direction: column; align-items: flex-start; min-width: 0; background: none; border: 0; padding: 0 2px; font: inherit; color: inherit; text-align: left; cursor: pointer; }
.att-open:disabled { cursor: default; }
.att-name { font-weight: 500; max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.att-status { color: var(--text2); font-size: 12px; }
.att-chip.needs-review .att-status { color: #b45309; font-weight: 500; }
.att-chip.failed .att-status { color: var(--error-text); white-space: normal; }
.att-chip.busy .att-status::after { content: ''; display: inline-block; width: 8px; height: 8px; margin-left: 6px; border-radius: 50%; background: currentColor; animation: pulse 1s infinite ease-in-out; }
.att-remove { width: 22px; height: 22px; border-radius: 50%; border: 0; background: none; color: var(--text2); font-size: 16px; line-height: 1; cursor: pointer; }
.att-remove:hover { background: var(--hover); color: var(--text); }
.att-sent { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 6px; margin-bottom: 6px; }
.msg.user { flex-direction: column; align-items: flex-end; }

/* ---- Review window ---- */
body.modal-open { overflow: hidden; }
.att-modal { position: fixed; inset: 0; z-index: 100; background: #0007; display: flex; align-items: center; justify-content: center; padding: 24px; }
.att-modal[hidden] { display: none; }
.att-dialog { background: var(--bg); color: var(--text); width: min(1100px, 100%); max-height: calc(100vh - 48px); border-radius: 18px; box-shadow: 0 20px 60px #0005; display: flex; flex-direction: column; overflow: hidden; }
.att-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 18px 20px 6px; }
.att-head h2 { font-size: 17px; margin: 0 0 6px; word-break: break-all; }
.att-badge { font-size: 12px; font-weight: 500; padding: 3px 9px; border-radius: 999px; }
.att-badge.warn { background: #fef3c7; color: #92400e; }
.att-badge.ok { background: #dcfce7; color: #166534; }
.att-x { width: 32px; height: 32px; border-radius: 50%; border: 0; background: none; font-size: 22px; color: var(--text2); cursor: pointer; }
.att-x:hover { background: var(--hover); }
.att-help { margin: 0; padding: 0 20px 10px; font-size: 13.5px; color: var(--text2); line-height: 1.45; }
.att-help[hidden] { display: none; }
.att-help code { background: var(--inline-code); padding: 1px 5px; border-radius: 5px; }
.att-tabs { display: none; }
.att-body { display: grid; grid-template-columns: 1fr 1fr; gap: 0; min-height: 0; flex: 1; border-top: 1px solid var(--border); }
.att-pane { min-height: 0; overflow: auto; padding: 16px 20px; }
.att-pane-original { background: var(--sidebar); border-right: 1px solid var(--border); }
.att-original img { width: 100%; height: auto; border-radius: 10px; border: 1px solid var(--border); background: #fff; display: block; cursor: zoom-in; }
.att-doc { display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 40px 10px; text-align: center; }
.att-doc-icon { font-size: 42px; }
.att-doc a { color: var(--text); }
.att-pane-text { display: flex; flex-direction: column; gap: 8px; }
.att-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.att-unsure { font-size: 13px; font-weight: 500; color: #b45309; }
.att-unsure.none { color: #15803d; }
.att-small { font: inherit; font-size: 12.5px; border: 1px solid var(--border); background: var(--bg); color: var(--text); border-radius: 8px; padding: 5px 10px; cursor: pointer; }
.att-small:disabled { opacity: .45; cursor: default; }
.att-editor { width: 100%; min-height: 170px; height: 34vh; resize: vertical; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13.5px; line-height: 22px; color: var(--text); background: var(--bg); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; outline: none; }
.att-editor:focus { border-color: var(--text2); }
.att-preview-label { font-size: 12px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--text2); margin-top: 4px; }
.att-preview { border: 1px dashed var(--border); border-radius: 10px; padding: 10px 14px; font-size: 15px; line-height: 1.6; overflow-x: auto; }
.att-preview p { margin: 0 0 8px; }
mark.unsure { background: #fde68a; color: #78350f; border-radius: 4px; padding: 0 4px; font-weight: 600; }
.att-foot { display: flex; align-items: center; justify-content: flex-end; gap: 10px; padding: 12px 20px; border-top: 1px solid var(--border); }
.att-dirty { margin-right: auto; font-size: 13px; color: var(--text2); }
.att-error { font-size: 13px; color: var(--error-text); }
.att-error:empty { display: none; }
.att-btn { font: inherit; font-size: 14.5px; font-weight: 500; border-radius: 999px; padding: 9px 18px; border: 0; background: var(--send-bg); color: var(--send-fg); cursor: pointer; }
.att-btn.secondary { background: none; color: var(--text); border: 1px solid var(--border); }
.att-btn:disabled { opacity: .5; }
@media (prefers-color-scheme: dark) {
  .att-chip.needs-review { background: #451a03; border-color: #b45309; }
  .att-chip.needs-review .att-status, .att-unsure { color: #fbbf24; }
  .att-badge.warn { background: #451a03; color: #fcd34d; }
  .att-badge.ok { background: #052e16; color: #86efac; }
  mark.unsure { background: #92400e; color: #fef3c7; }
}
@media (max-width: 767px) {
  .att-modal { padding: 0; }
  .att-dialog { max-height: 100vh; height: 100%; border-radius: 0; }
  .att-tabs { display: flex; gap: 4px; padding: 0 16px 8px; }
  .att-tab { flex: 1; font: inherit; font-size: 14px; padding: 8px; border-radius: 10px; border: 1px solid var(--border); background: var(--bg); color: var(--text); }
  .att-tab[aria-selected="true"] { background: var(--text); color: var(--bg); }
  .att-body { grid-template-columns: 1fr; }
  .att-modal[data-tab="original"] .att-pane-text, .att-modal[data-tab="text"] .att-pane-original { display: none; }
  .att-pane-original { border-right: 0; }
  .att-editor { height: 30vh; }
}

/* PDF preview and drag-and-drop */
.att-pages { display: flex; flex-direction: column; gap: 14px; }
.att-pages figure { margin: 0; }
.att-pages img { width: 100%; height: auto; border: 1px solid var(--border); border-radius: 8px; background: #fff; display: block; }
.att-pages figcaption { font-size: 12px; color: var(--text2); margin-top: 4px; text-align: center; }
.att-pdf-link { display: inline-block; margin-top: 8px; font-size: 13px; color: var(--text2); }
.drop-overlay { position: fixed; inset: 0; z-index: 90; background: #0006; display: flex; align-items: center; justify-content: center; padding: 24px; pointer-events: none; }
.drop-overlay[hidden] { display: none; }
.drop-card { width: min(520px, 100%); padding: 44px 24px; text-align: center; border-radius: 22px; background: var(--bg); border: 2px dashed var(--text2); box-shadow: 0 20px 60px #0004; }
.drop-icon { font-size: 36px; margin-bottom: 8px; }
.drop-title { font-size: 20px; font-weight: 600; }
.drop-sub { margin-top: 6px; color: var(--text2); font-size: 14px; }

@media (max-width: 480px) {
  .composer textarea { flex-basis: 100%; order: 1; }
  .composer > .attach-btn, .composer > .whiteboard-btn, .composer > .mic-btn, .composer > .send-btn { order: 2; }
  .composer > .mic-btn { margin-left: auto; }
  .composer > .voice-status { order: 3; }
  .feature-tip-actions button, .voice-status button { min-height: 44px; }
  .composer > .attach-btn, .composer > .whiteboard-btn, .composer > .mic-btn, .composer > .send-btn { width: 44px; height: 44px; flex-basis: 44px; }
}
/* Flow-style dictation stays local to this composer, with an editable draft. */
.voice-hint { flex-basis: 100%; margin: 0; padding: 0 6px; color: var(--text2); font-size: 11px; line-height: 1.6; }
.voice-hint[hidden], .voice-clock[hidden] { display: none; }
.voice-hint kbd { font: inherit; border: 1px solid var(--border); border-radius: 4px; padding: 1px 3px; }
.voice-status { flex-wrap: wrap; padding: 10px; border-radius: 14px; background: var(--sidebar); }
.voice-status span.voice-clock { flex: 0 0 auto; font-variant-numeric: tabular-nums; font-weight: 600; color: var(--text); }
.voice-status[data-phase="recording"] .voice-clock::before { content: ''; display: inline-block; width: 7px; height: 7px; margin-right: 6px; border-radius: 50%; background: var(--error-text); }
.voice-status #voiceMessage { min-width: 140px; }
.voice-status #voiceStop { text-decoration: none; border-radius: 8px; background: var(--send-bg); color: var(--send-fg); }
@media (max-width: 480px) {
  .composer > .voice-hint { order: 3; }
  .composer > .voice-status { order: 4; }
  .voice-status #voiceMessage { flex-basis: calc(100% - 90px); }
}
@media (hover: none) { .voice-hint { display: none; } }

/* ---- Feedback (public/feedback.js): top-bar button, thumbs under a reply, and the dialog ---- */
.topbar-feedback {
  display: inline-flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 500;
  padding: 6px 12px; border: 1px solid var(--chip-border); border-radius: 999px; color: var(--text);
}
.topbar-feedback:hover { background: var(--hover); }
.topbar-feedback:focus-visible, .fb-thumb:focus-visible, .actions button:focus-visible { outline: 2px solid var(--text2); outline-offset: 2px; }
.actions button[aria-pressed="true"] { color: var(--text); background: var(--active); }
.fb-about-line { margin: 0; font-size: 14px; color: var(--text2); line-height: 1.45; }
.fb-quote { position: relative; max-height: 7.6em; overflow: hidden; margin: 6px 0 0; padding: 8px 12px; border-left: 3px solid var(--border); background: var(--sidebar); border-radius: 0 10px 10px 0; font-size: 13.5px; line-height: 1.5; color: var(--text); overflow-wrap: anywhere; }
.fb-quote p, .fb-quote ul, .fb-quote ol, .fb-quote pre { margin: 0 0 6px; }
.fb-quote .katex-display { margin: 4px 0; }
.fb-quote.clamped::after { content: ''; position: absolute; left: 0; right: 0; bottom: 0; height: 2.4em; background: linear-gradient(transparent, var(--sidebar)); }
.fb-rating { display: flex; gap: 10px; flex-wrap: wrap; }
.fb-thumb {
  display: inline-flex; align-items: center; gap: 8px; font-size: 14px; padding: 9px 14px;
  border: 1px solid var(--border); border-radius: 999px; color: var(--text);
}
.fb-thumb:hover { background: var(--hover); }
.fb-thumb[aria-pressed="true"] { background: var(--send-bg); color: var(--send-fg); border-color: var(--send-bg); }
.fb-form textarea {
  font: inherit; font-size: 15px; color: var(--text); background: var(--bg); resize: vertical; min-height: 120px;
  border: 1px solid var(--border); border-radius: 12px; padding: 11px 14px; outline: none; line-height: 1.45;
}
.fb-form textarea:focus { border-color: var(--text2); }
.fb-count { font-size: 12px; color: var(--text2); text-align: right; min-height: 1em; }
.fb-count:empty { display: none; }
.fb-note { font-size: 12.5px; color: var(--text2); line-height: 1.5; margin: 0; }
.fb-form[hidden], .fb-done[hidden] { display: none; }
.fb-done { display: flex; flex-direction: column; gap: 6px; }
.fb-done-title { font-size: 17px; font-weight: 600; margin: 0; outline: none; }
.fb-done-text { color: var(--text2); margin: 0 0 8px; font-size: 14.5px; }
@media (max-width: 480px) {
  .topbar-feedback { padding: 6px 10px; }
  .topbar-feedback ~ .topbar-link { display: none; }
  .fb-thumb { flex: 1; justify-content: center; min-height: 44px; }
}
