:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-soft: #f7f9fc;
  --text: #172033;
  --muted: #64748b;
  --line: #dbe2ee;
  --primary: #2254d8;
  --primary-dark: #173da7;
  --accent: #0f766e;
  --danger: #b42318;
  --warning-bg: #fff7e6;
  --warning-line: #f4c56a;
  --shadow: 0 18px 50px rgba(36, 55, 96, 0.10);
  --app-viewport-height: 100dvh;
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; color: var(--text); background: var(--bg); font-family: Inter, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif; }
button, input, textarea { font: inherit; }
button { cursor: pointer; touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
button:disabled { cursor: not-allowed; opacity: .58; }
a { color: inherit; }
.hidden, [hidden] { display: none !important; }
.sr-only { position: absolute !important; width: 1px !important; height: 1px !important; overflow: hidden !important; margin: -1px !important; padding: 0 !important; border: 0 !important; clip: rect(0 0 0 0) !important; clip-path: inset(50%) !important; white-space: nowrap !important; }
.muted { color: var(--muted); }
.error { min-height: 1.4em; color: var(--danger); }
.row { display: flex; align-items: center; }
.gap { gap: 12px; flex-wrap: wrap; }
.full { width: 100%; }
.stack { display: grid; gap: 18px; }
label { display: grid; gap: 7px; font-size: 14px; font-weight: 650; }
input, textarea { width: 100%; border: 1px solid var(--line); border-radius: 12px; background: white; padding: 12px 14px; color: var(--text); outline: none; }
input:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(34, 84, 216, 0.12); }
textarea { resize: vertical; line-height: 1.65; }
button, .button-link { border: 0; border-radius: 11px; padding: 10px 16px; font-weight: 700; text-decoration: none; display: inline-flex; align-items: center; justify-content: center; }
.primary { color: white; background: var(--primary); }
.primary:hover { background: var(--primary-dark); }
.secondary { color: var(--primary); background: #eaf0ff; }
.ghost { color: var(--text); background: white; border: 1px solid var(--line); }
.text-link { color: var(--primary); text-decoration: none; font-weight: 650; }
:where(button, a, input, textarea, summary):focus-visible { outline: 3px solid rgba(34, 84, 216, .28); outline-offset: 2px; }
.brand-mark { display: inline-flex; align-items: center; border-radius: 999px; padding: 8px 12px; background: #e9efff; color: var(--primary); font-weight: 800; letter-spacing: .04em; }
.brand-mark.small { font-size: 12px; padding: 6px 10px; }

.login-shell { min-height: 100vh; display: grid; place-items: center; padding: 32px; background: radial-gradient(circle at 16% 8%, #dce8ff, transparent 34%), radial-gradient(circle at 88% 88%, #d8f5ec, transparent 30%), var(--bg); }
.login-layout { width: min(1120px, 100%); display: grid; grid-template-columns: minmax(0, 1.18fr) minmax(350px, .82fr); gap: 20px; align-items: stretch; }
.login-brand-panel { position: relative; isolation: isolate; overflow: hidden; border: 1px solid rgba(255,255,255,.12); border-radius: 28px; background: linear-gradient(145deg, #0f1930 0%, #152c59 60%, #153f56 100%); padding: clamp(36px, 5vw, 58px); color: white; box-shadow: 0 28px 70px rgba(15, 29, 61, .22); }
.login-brand-panel::after { content: ""; position: absolute; z-index: -1; right: -105px; bottom: -145px; width: 340px; height: 340px; border: 1px solid rgba(147,197,253,.18); border-radius: 50%; background: radial-gradient(circle, rgba(45,212,191,.16), transparent 67%); }
.login-brand-panel .course-brand-mark { border: 1px solid rgba(255,255,255,.15); background: rgba(255,255,255,.1); color: #dbe8ff; }
.course-kicker { margin: clamp(38px, 6vw, 66px) 0 10px; color: #9fb9e8; font-size: 12px; font-weight: 800; letter-spacing: .18em; }
.login-brand-panel h1 { max-width: none; margin: 0; font-size: clamp(34px, 4.3vw, 54px); line-height: 1.12; letter-spacing: -.035em; }
.course-instructor { display: flex; align-items: baseline; gap: 10px 14px; flex-wrap: wrap; margin: 19px 0 0; color: #dce9ff; }
.course-instructor strong { font-size: 17px; }
.course-instructor span { color: #9eb0ce; font-size: 13px; }
.course-intro { max-width: 55ch; margin: 22px 0 0; color: #c3d0e7; font-size: 14px; line-height: 1.78; }
.course-link-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin-top: clamp(30px, 5vw, 52px); }
.course-link-card { min-width: 0; min-height: 176px; display: flex; flex-direction: column; border: 1px solid rgba(189,211,246,.2); border-radius: 17px; background: rgba(8,18,38,.28); padding: 17px; color: white; text-decoration: none; transition: transform .18s ease, border-color .18s ease, background .18s ease; }
.course-link-card:hover { border-color: rgba(189,211,246,.48); background: rgba(27,50,91,.62); transform: translateY(-2px); }
.course-link-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; color: #a9c2ed; }
.course-link-label { overflow: hidden; font-size: 11px; font-weight: 800; letter-spacing: .08em; text-overflow: ellipsis; white-space: nowrap; }
.course-link-arrow { display: inline-grid; width: 28px; height: 28px; flex: 0 0 28px; place-items: center; border: 1px solid rgba(255,255,255,.15); border-radius: 50%; font-size: 13px; }
.course-link-card > strong { font-size: 16px; line-height: 1.4; }
.course-link-subtitle { margin-top: 6px; color: #c5d3e8; font-size: 11px; line-height: 1.55; }
.course-link-detail { margin-top: auto; padding-top: 13px; color: #96a9c6; font-size: 10px; line-height: 1.55; }
.login-card { min-width: 0; display: grid; align-content: center; border: 1px solid rgba(255,255,255,.85); border-radius: 28px; background: rgba(255,255,255,.94); padding: clamp(34px, 5vw, 50px); box-shadow: var(--shadow); }
.login-card-heading { max-width: 35rem; }
.login-eyebrow { margin: 0 0 10px; color: var(--primary); font-size: 12px; font-weight: 800; letter-spacing: .12em; }
.login-card h2 { margin: 0 0 9px; font-size: 28px; letter-spacing: -.02em; }
.login-card-heading .muted { margin: 0; font-size: 13px; line-height: 1.65; }
.login-card .stack { margin-top: 30px; }
.login-card .primary { min-height: 46px; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 280px 1fr; }
.sidebar { height: 100vh; position: sticky; top: 0; display: flex; flex-direction: column; gap: 18px; padding: 24px 18px; background: #111a2d; color: white; }
.sidebar-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.sidebar-brand-block { min-width: 0; display: grid; justify-items: start; }
.sidebar-course-name { max-width: 100%; margin-top: 13px; overflow: hidden; color: #edf3ff; font-size: 15px; line-height: 1.4; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-course-instructor { margin-top: 3px; color: #9fb0ce; font-size: 11px; }
.sidebar-official-links { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 7px; }
.sidebar-official-link { min-width: 0; min-height: 44px; display: flex; align-items: center; justify-content: space-between; gap: 5px; border: 1px solid #30415f; border-radius: 10px; background: #16233b; padding: 8px 9px; color: #c8d7ef; font-size: 11px; font-weight: 700; text-decoration: none; transition: border-color .16s ease, background .16s ease, color .16s ease; }
.sidebar-official-link:hover { border-color: #526b96; background: #1c2d4c; color: white; }
.sidebar-official-link span:first-child { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mobile-icon-button, .sidebar-backdrop { display: none; }
.conversation-list { flex: 1; overflow-y: auto; display: grid; align-content: start; gap: 8px; }
.conversation-row { min-width: 0; display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 2px; border: 1px solid transparent; border-radius: 11px; transition: background .16s ease, border-color .16s ease; }
.conversation-row:hover, .conversation-row:focus-within, .conversation-row.active { background: #1c2943; border-color: #31415f; }
.conversation-item { min-width: 0; width: 100%; justify-content: flex-start; text-align: left; background: transparent; color: #dce4f4; border: 0; padding: 11px 10px 11px 12px; border-radius: 10px; white-space: nowrap; overflow: hidden; }
.conversation-item:hover, .conversation-item.active { background: transparent; }
.conversation-title { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conversation-rename { min-width: 46px; min-height: 34px; border-radius: 8px; background: transparent; padding: 5px 7px; color: #aebdd7; font-size: 11px; }
.conversation-rename:hover { background: #2b3b5d; color: white; }
.conversation-rename-form { grid-column: 1 / -1; min-width: 0; display: grid; grid-template-columns: minmax(0, 1fr) auto auto; gap: 6px; padding: 7px; }
.conversation-rename-input { min-width: 0; height: 38px; border-color: #536582; border-radius: 8px; background: #0d1628; padding: 7px 9px; color: white; font-size: 13px; }
.conversation-rename-save, .conversation-rename-cancel { min-height: 38px; border-radius: 8px; padding: 7px 9px; font-size: 11px; }
.conversation-rename-save { background: #eaf0ff; color: var(--primary); }
.conversation-rename-cancel { border: 1px solid #465573; background: transparent; color: #c8d4e8; }
.conversation-rename-status { grid-column: 1 / -1; min-height: 0; color: #f7c8c3; font-size: 11px; line-height: 1.4; }
.sidebar-footer { display: grid; gap: 12px; }
.sidebar-current-user { min-width: 0; display: grid; gap: 2px; border-bottom: 1px solid #2c3951; padding: 0 2px 10px; }
.sidebar-current-user span { color: #8291ad; font-size: 10px; }
.sidebar-current-user strong { overflow: hidden; color: #dce7fa; font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.sidebar .ghost { color: white; background: transparent; border-color: #3b4861; }
.sidebar .text-link { color: #b8cfff; }
.sidebar-nav-button { width: 100%; min-height: 44px; justify-content: space-between; border: 1px solid #344361; background: #17243c; padding: 9px 11px; color: #dce7fa; text-align: left; }
.sidebar-nav-button:hover { border-color: #536a95; background: #1c2b49; }
.sidebar-count { min-width: 24px; border-radius: 999px; background: #dce6ff; padding: 3px 7px; color: var(--primary); font-size: 11px; text-align: center; }
.account-settings summary { cursor: pointer; color: #b8cfff; font-weight: 650; font-size: 14px; }
.account-settings .compact { gap: 8px; margin-top: 10px; }
.account-settings input { padding: 9px 10px; border-radius: 9px; font-size: 13px; }
.sidebar-status { color: #b7c3da; font-size: 12px; line-height: 1.4; }
.chat-main { min-width: 0; min-height: 0; display: grid; grid-template-rows: auto minmax(0, 1fr) auto auto; height: 100vh; height: 100dvh; }
.topbar { display: flex; justify-content: space-between; align-items: center; gap: 20px; padding: 22px 34px; border-bottom: 1px solid var(--line); background: rgba(255,255,255,.9); backdrop-filter: blur(10px); }
.topbar-copy { min-width: 0; }
.topbar-kicker { display: block; margin-bottom: 3px; color: var(--primary); font-size: 10px; font-weight: 800; letter-spacing: .07em; }
.topbar h1 { margin: 0; font-size: 22px; }
.topbar p { margin: 5px 0 0; color: var(--muted); font-size: 14px; }
.grounding-badge { background: #e6f7f3; color: var(--accent); border: 1px solid #b6e4d9; border-radius: 999px; padding: 8px 12px; font-size: 13px; font-weight: 750; white-space: nowrap; }
.messages { min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 30px clamp(20px, 6vw, 92px) 36px; display: grid; align-content: start; gap: 24px; scroll-padding-block: 24px; }
.message { width: min(100%, 940px); overflow-wrap: anywhere; }
.message.user { justify-self: end; width: auto; max-width: min(75%, 48rem); padding: 13px 17px 15px; border: 1px solid #1d49bd; border-radius: 18px 18px 5px 18px; background: linear-gradient(145deg, #285bdd, #1f4fca); color: white; box-shadow: 0 7px 18px rgba(34, 84, 216, .16); }
.message.assistant { justify-self: center; padding: 2px 0 12px; }
.message-header { display: flex; align-items: center; gap: 10px; min-height: 30px; margin-bottom: 7px; }
.message.user .message-header { justify-content: flex-end; min-height: auto; margin-bottom: 4px; }
.assistant-avatar { display: inline-grid; place-items: center; width: 32px; height: 32px; flex: 0 0 32px; border-radius: 10px; background: #e9efff; color: var(--primary); font-size: 11px; font-weight: 850; letter-spacing: .03em; }
.message-role { color: #4b5f7d; font-size: 13px; font-weight: 800; }
.message.user .message-role { color: rgba(255,255,255,.82); font-size: 11px; }
.message.assistant .message-body { margin-left: 42px; max-width: 78ch; }
.message-content { line-height: 1.78; }
.message.user .message-content { white-space: pre-wrap; line-height: 1.65; }
.user-image-note { display: inline-flex; min-height: 28px; align-items: center; margin-top: 9px; border: 1px solid rgba(255,255,255,.25); border-radius: 999px; background: rgba(10,30,80,.18); padding: 4px 9px; color: rgba(255,255,255,.9); font-size: 11px; font-weight: 700; }
.message.assistant .message-content { color: #1e293b; font-size: 15.5px; }
.conversation-context-hint { display: block; margin-top: 12px; border-left: 2px solid #b8c8ef; padding-left: 9px; color: var(--muted); font-size: 12px; line-height: 1.55; }
.message-error .message-content { color: var(--danger); }
.message.loading .message-content::after { content: ""; display: inline-block; width: 7px; height: 7px; margin-left: 7px; border-radius: 50%; background: currentColor; animation: pulse 1s infinite alternate; }
@keyframes pulse { to { opacity: .25; transform: translateX(8px); } }

.markdown-body > :first-child { margin-top: 0; }
.markdown-body > :last-child { margin-bottom: 0; }
.markdown-body p { margin: 0 0 .9em; }
.markdown-body h2, .markdown-body h3, .markdown-body h4, .markdown-body h5, .markdown-body h6 { margin: 1.45em 0 .55em; color: #15213a; line-height: 1.35; }
.markdown-body h2 { font-size: 1.28em; }
.markdown-body h3 { font-size: 1.14em; }
.markdown-body h4, .markdown-body h5, .markdown-body h6 { font-size: 1em; }
.markdown-body ul, .markdown-body ol { margin: .55em 0 1em; padding-left: 1.5em; }
.markdown-body li { margin: .32em 0; }
.markdown-body blockquote { margin: 1em 0; padding: 10px 14px; border-left: 3px solid #8aa6ef; background: #f4f7ff; color: #465b79; }
.markdown-body code { border-radius: 5px; background: #eef2f8; padding: .12em .38em; color: #8b2451; font-family: "SFMono-Regular", Consolas, monospace; font-size: .9em; }
.markdown-body pre { max-width: 100%; overflow-x: auto; margin: 1em 0; border-radius: 12px; background: #111827; padding: 14px 16px; color: #e5edf9; line-height: 1.6; }
.markdown-body pre code { background: transparent; padding: 0; color: inherit; }
.markdown-body table { display: block; width: max-content; max-width: 100%; overflow-x: auto; margin: 1em 0; border-collapse: collapse; }
.markdown-body th, .markdown-body td { min-width: 7rem; padding: 8px 10px; border: 1px solid var(--line); background: white; }
.markdown-body th { background: #f2f5fa; }
.markdown-body a { color: var(--primary); text-underline-offset: 3px; }
.markdown-image-placeholder { color: var(--muted); font-style: italic; }
.katex-display { max-width: 100%; overflow-x: auto; overflow-y: hidden; padding: .35em 0; }
.citation-ref { display: inline-flex; min-height: 26px; align-items: center; margin: 0 .08em; border: 0; border-radius: 6px; background: #e8efff; padding: 1px 5px; color: var(--primary); font-size: .82em; font-weight: 800; vertical-align: .08em; }
.citation-ref:hover { background: #d9e5ff; }

.evidence-panel { margin-top: 18px; border-top: 1px solid var(--line); color: #334155; }
.evidence-backdrop, .mobile-evidence-header { display: none; }
.evidence-summary { display: flex; align-items: center; justify-content: space-between; gap: 14px; min-height: 44px; padding: 10px 2px; color: #41536e; font-size: 13px; cursor: pointer; list-style: none; }
.evidence-summary::-webkit-details-marker, .candidate-sources > summary::-webkit-details-marker, .reflection-panel > summary::-webkit-details-marker { display: none; }
.evidence-summary::after, .candidate-sources > summary::after, .reflection-panel > summary::after { content: "›"; margin-left: 4px; color: #8290a6; font-size: 20px; line-height: 1; transform: rotate(90deg); transition: transform .18s ease; }
.evidence-panel[open] > .evidence-summary::after, .candidate-sources[open] > summary::after, .reflection-panel[open] > summary::after { transform: rotate(-90deg); }
.evidence-summary-label { display: inline-flex; align-items: center; gap: 8px; font-weight: 780; }
.source-icon { display: inline-grid; place-items: center; width: 25px; height: 25px; border-radius: 7px; background: #e8efff; color: var(--primary); font-size: 12px; font-weight: 850; }
.evidence-count { margin-left: auto; color: var(--muted); font-size: 12px; font-weight: 650; }
.evidence-panel.has-no-citations .evidence-count { color: #9a6700; }
.evidence-body { padding: 4px 0 8px; }
.evidence-group-title { margin: 4px 0 9px; font-size: 13px; color: var(--accent); }
.sources { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 260px), 1fr)); gap: 10px; }
.source-card { min-width: 0; border: 1px solid var(--line); border-radius: 12px; padding: 13px; background: var(--surface-soft); transition: border-color .2s ease, box-shadow .2s ease; }
.source-card.is-cited { border-color: #a9d9cf; background: #f2fbf8; }
.source-card.is-candidate { color: #68768b; background: #f8fafc; opacity: .74; }
.source-card-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.source-card strong { color: var(--primary); font-size: 13px; }
.source-badge { flex: 0 0 auto; border-radius: 999px; background: #dff4ee; padding: 3px 7px; color: var(--accent); font-size: 10px; font-weight: 800; }
.is-candidate .source-badge { background: #e9edf3; color: #6c788b; }
.source-meta { margin: 5px 0 8px; color: var(--muted); font-size: 12px; }
.source-excerpt { color: #334155; font-size: 13px; line-height: 1.62; white-space: pre-wrap; }
.textbook-page-link { display: inline-flex; margin-top: 10px; color: var(--primary); font-size: 12px; font-weight: 750; text-decoration: none; }
.textbook-page-link:hover { text-decoration: underline; }
.evidence-note { margin: 4px 0 10px; border-radius: 9px; padding: 9px 11px; font-size: 12px; line-height: 1.55; }
.evidence-note.warning { border: 1px solid #eed18b; background: #fff8e8; color: #765715; }
.candidate-sources { margin-top: 11px; border-radius: 10px; background: #f6f8fb; }
.candidate-sources > summary { display: flex; align-items: center; gap: 8px; padding: 10px 12px; color: #69778c; font-size: 12px; font-weight: 700; cursor: pointer; list-style: none; }
.candidate-sources > summary::after { margin-left: auto; }
.candidate-source-grid { padding: 0 10px 10px; }
.source-card.source-flash { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(34,84,216,.14); animation: source-highlight 1.3s ease; }
@keyframes source-highlight { 0%, 100% { background-color: #f2fbf8; } 45% { background-color: #e1ebff; } }

.reflection-panel { margin: 0 clamp(20px, 6vw, 90px) 10px; border: 1px solid var(--line); border-radius: 13px; background: rgba(255,255,255,.82); }
.reflection-panel > summary { display: flex; align-items: center; padding: 11px 14px; color: #4b5f7d; font-size: 13px; font-weight: 750; cursor: pointer; list-style: none; }
.reflection-panel > summary::after { margin-left: auto; }
.reflection-body { padding: 0 14px 14px; }
.reflection-body p { margin: 2px 0 10px; }
.inline-text-button { display: inline; border: 0; background: transparent; padding: 0; color: var(--primary); font-size: inherit; font-weight: 750; text-decoration: underline; text-underline-offset: 2px; }
.inline-check { display: inline-flex; align-items: center; gap: 8px; font-weight: 550; }
.inline-check input { width: auto; }
.composer { position: relative; z-index: 4; padding: 10px clamp(20px, 6vw, 90px) calc(18px + env(safe-area-inset-bottom)); background: linear-gradient(to top, var(--bg) 82%, rgba(244,246,251,.78)); }
.composer-box { display: grid; border: 1px solid #cbd5e1; border-radius: 17px; background: white; padding: 8px 9px 8px 14px; box-shadow: 0 10px 28px rgba(36,55,96,.11); transition: border-color .18s ease, box-shadow .18s ease; }
.composer-box:focus-within { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(34,84,216,.1), 0 10px 28px rgba(36,55,96,.1); }
.image-attachment { min-width: 0; display: grid; grid-template-columns: 58px minmax(0, 1fr) auto; align-items: center; gap: 11px; margin: 0 0 6px -5px; border-bottom: 1px solid var(--line); padding: 0 2px 9px 0; }
.image-preview { display: block; width: 58px; height: 58px; border: 1px solid var(--line); border-radius: 11px; background: var(--surface-soft); object-fit: cover; }
.image-attachment-copy { min-width: 0; display: grid; gap: 2px; }
.image-attachment-copy strong { overflow: hidden; font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.image-meta { color: var(--muted); font-size: 11px; }
.image-retention-note { width: fit-content; border-radius: 999px; background: #e8f7f2; padding: 2px 7px; color: var(--accent); font-size: 10px; font-weight: 750; }
.composer .image-remove { min-width: 52px; height: 36px; border: 1px solid var(--line); background: var(--surface-soft); padding: 6px 9px; color: #52647f; font-size: 11px; }
.image-status { min-height: 0; margin: 0; overflow-wrap: anywhere; color: var(--muted); font-size: 11px; line-height: 1.45; }
.image-status:empty { display: none; }
.image-status.is-error { margin-bottom: 3px; color: var(--danger); font-weight: 650; }
.composer textarea { min-height: 34px; max-height: 180px; resize: none; overflow-y: auto; border: 0; padding: 7px 2px; box-shadow: none; }
.composer textarea:focus { border: 0; box-shadow: none; }
.composer-footer { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.composer-tools { min-width: 0; display: flex; align-items: center; gap: 10px; }
.composer .image-pick { min-width: 70px; height: 36px; border: 1px solid #cbd5e1; background: var(--surface-soft); padding: 6px 10px; color: #405371; font-size: 12px; }
.composer .image-pick:hover { border-color: #9eb2d2; background: #edf2fa; color: var(--primary); }
.composer-hint { color: #8491a5; font-size: 11px; }
.composer button { min-width: 72px; height: 39px; border-radius: 11px; }

.portfolio-dialog { width: min(720px, calc(100% - 32px)); max-height: min(80dvh, 760px); overflow: hidden; border: 0; border-radius: 21px; background: var(--surface); padding: 0; color: var(--text); box-shadow: 0 24px 80px rgba(9, 20, 43, .28); }
.portfolio-dialog::backdrop { background: rgba(7, 15, 33, .56); backdrop-filter: blur(2px); }
.portfolio-sheet { max-height: min(80dvh, 760px); display: flex; flex-direction: column; }
.portfolio-header { flex: 0 0 auto; display: flex; align-items: center; justify-content: space-between; gap: 18px; border-bottom: 1px solid var(--line); padding: 19px 22px 16px; }
.portfolio-eyebrow { margin: 0 0 3px; color: var(--primary); font-size: 11px; font-weight: 800; letter-spacing: .08em; }
.portfolio-header h2 { margin: 0; font-size: 21px; }
.portfolio-close { width: 44px; height: 44px; flex: 0 0 44px; border-radius: 12px; background: var(--surface-soft); padding: 0; color: var(--text); font-size: 24px; }
.portfolio-description { flex: 0 0 auto; margin: 0; border-bottom: 1px solid var(--line); background: #f7f9fd; padding: 13px 22px; color: #52647f; font-size: 13px; line-height: 1.62; }
.portfolio-status { min-height: 20px; margin: 10px 22px 0; font-size: 12px; }
.portfolio-list { min-height: 130px; overflow-y: auto; overscroll-behavior: contain; display: grid; align-content: start; gap: 10px; padding: 8px 22px 22px; }
.portfolio-empty { display: grid; place-items: center; min-height: 170px; border: 1px dashed #cbd5e1; border-radius: 14px; padding: 24px; text-align: center; }
.portfolio-empty p { max-width: 32rem; margin: 8px 0 0; color: var(--muted); font-size: 13px; line-height: 1.55; }
.portfolio-item { min-width: 0; display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 16px; border: 1px solid var(--line); border-radius: 14px; background: white; padding: 15px; }
.portfolio-item-copy { min-width: 0; }
.portfolio-item h3 { overflow: hidden; margin: 0; font-size: 15px; line-height: 1.45; text-overflow: ellipsis; white-space: nowrap; }
.portfolio-item-meta { margin: 4px 0 8px; color: var(--muted); font-size: 11px; }
.portfolio-item-note { margin: 0; overflow-wrap: anywhere; color: #334155; font-size: 13px; line-height: 1.58; }
.portfolio-item-question { margin: 8px 0 0; overflow: hidden; color: #607089; font-size: 12px; line-height: 1.55; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; }
.portfolio-item-actions { display: flex; flex-direction: column; justify-content: center; gap: 7px; }
.portfolio-item-actions button { min-width: 96px; min-height: 38px; padding: 8px 10px; font-size: 12px; }
.portfolio-remove.confirming { border-color: #e5a8a2; background: #fff1f0; color: var(--danger); }

body.admin-page { min-width: 320px; overflow-x: hidden; background: #f2f5fa; }
.admin-shell { width: min(1680px, 100%); min-height: 100vh; margin: 0 auto; padding: 22px clamp(16px, 3vw, 44px) 44px; }
.admin-header { display: flex; justify-content: space-between; align-items: center; gap: 24px; margin-bottom: 14px; }
.admin-heading-copy { min-width: 0; display: flex; align-items: center; gap: 14px; }
.admin-header h1 { margin: 0 0 4px; font-size: 25px; line-height: 1.2; }
.admin-header p { margin: 0; color: var(--muted); font-size: 13px; }
.admin-header-actions { flex: 0 0 auto; }
.notice { border: 1px solid; border-radius: 14px; padding: 14px 16px; margin-bottom: 20px; line-height: 1.6; }
.notice.warning { background: var(--warning-bg); border-color: var(--warning-line); }
.admin-policy { margin-bottom: 14px; padding: 0; }
.admin-policy > summary { min-height: 44px; display: flex; align-items: center; padding: 9px 14px; cursor: pointer; font-weight: 750; }
.admin-policy > p { margin: 0; border-top: 1px solid var(--warning-line); padding: 10px 14px 13px; font-size: 13px; }
.panel { min-width: 0; border: 1px solid var(--line); border-radius: 16px; background: white; box-shadow: 0 8px 28px rgba(31, 47, 78, .055); }
.admin-summary { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; margin-bottom: 14px; }
.summary-card { min-width: 0; display: grid; gap: 5px; border: 1px solid var(--line); border-radius: 14px; background: white; padding: 13px 15px; }
.summary-card span { overflow: hidden; color: var(--muted); font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.summary-card strong { font-size: 24px; line-height: 1; }
.summary-card.attention { border-color: #edd18d; background: #fffaf0; }
.summary-card.attention strong { color: #9a6700; }
.account-create-panel { margin-bottom: 14px; padding: 0; }
.account-create-panel > summary { min-height: 46px; display: flex; align-items: center; padding: 10px 16px; cursor: pointer; color: #405371; font-size: 13px; font-weight: 750; }
.account-create-panel[open] > summary { border-bottom: 1px solid var(--line); }
.account-create-panel .inline-form { padding: 15px 16px 6px; }
.account-create-panel #student-create-status { min-height: 20px; margin: 3px 16px 13px; font-size: 12px; }
.inline-form { display: grid; grid-template-columns: repeat(3, minmax(150px, 1fr)) auto; gap: 12px; align-items: end; }
.admin-inbox { min-width: 0; display: grid; grid-template-columns: minmax(260px, 300px) minmax(0, 1fr); gap: 14px; align-items: start; }
.admin-directory { position: sticky; top: 12px; min-height: 640px; max-height: calc(100dvh - 24px); display: flex; flex-direction: column; overflow: hidden; padding: 15px 12px 12px; }
.directory-heading, .pane-heading, .section-heading, .student-identity, .conversation-title-row, .portfolio-card-header, .snapshot-card-top, .admin-source-header, .source-card-footer, .score-preview-heading { min-width: 0; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.directory-heading { padding: 0 3px 8px; }
.directory-heading h2, .student-workspace-header h2, .section-heading h3, .pane-heading h3, .conversation-detail-header h3, .snapshot-pane h3 { margin: 0; }
.admin-eyebrow { margin: 0 0 3px; color: var(--primary); font-size: 10px; font-weight: 850; letter-spacing: .09em; text-transform: uppercase; }
.icon-text-button { min-height: 44px; padding: 8px 11px; font-size: 12px; }
.directory-search { margin: 4px 2px 8px; }
.directory-search input { min-height: 44px; padding: 10px 12px; font-size: 14px; }
.pending-filter { min-height: 44px; display: flex; grid-auto-flow: column; align-items: center; gap: 8px; margin: 0 3px 4px; color: #52647f; font-size: 12px; cursor: pointer; }
.pending-filter input { width: 18px; height: 18px; flex: 0 0 18px; }
.list-status { min-height: 20px; margin: 3px 4px; overflow-wrap: anywhere; font-size: 11px; line-height: 1.5; }
.student-directory, .admin-conversation-list { min-width: 0; min-height: 0; overflow-y: auto; overscroll-behavior: contain; display: grid; align-content: start; gap: 6px; padding: 3px; }
.student-directory > [role="listitem"], .admin-conversation-list > [role="listitem"] { min-width: 0; }
.student-directory { flex: 1; }
.student-directory-item, .admin-conversation-item { min-width: 0; width: 100%; min-height: 72px; display: grid; align-items: stretch; justify-content: stretch; gap: 7px; border: 1px solid transparent; border-radius: 12px; background: transparent; padding: 11px; color: var(--text); text-align: left; }
.student-directory-item:hover, .admin-conversation-item:hover { border-color: #c8d5eb; background: #f5f8fd; }
.student-directory-item.active, .admin-conversation-item.active { border-color: #9db5eb; background: #edf3ff; box-shadow: inset 3px 0 var(--primary); }
.directory-item-top, .conversation-item-title-row { min-width: 0; display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.directory-item-identity { min-width: 0; display: grid; gap: 2px; }
.directory-item-identity strong, .conversation-item-title-row strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.directory-item-identity small { color: var(--muted); }
.directory-item-activity, .conversation-preview { overflow: hidden; color: #52647f; font-size: 12px; line-height: 1.5; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; }
.directory-item-footer, .conversation-item-meta { min-width: 0; display: flex; align-items: center; gap: 5px; overflow: hidden; }
.meta-chip { min-width: 0; display: inline-flex; align-items: center; border-radius: 999px; background: #edf1f6; padding: 3px 7px; color: #627086; font-size: 10px; font-weight: 750; line-height: 1.3; white-space: nowrap; }
.meta-chip.pending { background: #fff0cc; color: #865c00; }
.meta-chip.reviewed, .meta-chip.cited { background: #ddf5ed; color: #0c6b61; }
.meta-chip.selected { background: #e7efff; color: #2451bf; }
.meta-chip.candidate { background: #edf0f4; color: #667386; }
.meta-chip.unknown { background: #f4f0e7; color: #786746; }
.meta-chip.portfolio { background: #f0eaff; color: #6741b5; }
.list-empty, .workspace-empty, .conversation-empty { display: grid; place-items: center; align-content: center; min-height: 180px; border: 1px dashed #ccd6e5; border-radius: 13px; padding: 24px; color: var(--muted); text-align: center; }
.workspace-empty { min-height: 620px; border: 0; }
.workspace-empty h2, .conversation-empty h3 { margin: 8px 0 4px; color: var(--text); }
.workspace-empty p, .conversation-empty p { max-width: 32rem; margin: 0; line-height: 1.6; }
.empty-icon { font-size: 32px; }
.student-workspace { min-height: 720px; overflow: hidden; }
.workspace-content { min-width: 0; }
.student-workspace-header { padding: 17px 19px 13px; }
.student-identity { align-items: flex-start; }
.student-identity > div { min-width: 0; }
.student-identity h2 { overflow: hidden; font-size: 22px; text-overflow: ellipsis; white-space: nowrap; }
.student-identity .muted { margin: 4px 0 0; font-size: 12px; }
.pending-badge { flex: 0 0 auto; border-radius: 999px; background: #fff0cc; padding: 6px 9px; color: #865c00; font-size: 11px; font-weight: 800; }
.pending-badge.is-clear { background: #ddf5ed; color: #0c6b61; }
.compact-metrics { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 7px; margin-top: 13px; }
.compact-metrics > div { display: flex; align-items: baseline; gap: 6px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface-soft); padding: 8px 10px; }
.compact-metrics strong { font-size: 17px; }
.compact-metrics span { color: var(--muted); font-size: 10px; }
.student-tabs { display: flex; gap: 4px; overflow-x: auto; border-block: 1px solid var(--line); background: #fafbfd; padding: 7px 12px; }
.student-tab { min-height: 44px; flex: 0 0 auto; border: 1px solid transparent; background: transparent; padding: 8px 13px; color: #52647f; font-size: 12px; }
.student-tab.active { border-color: #c8d7f6; background: #eaf0ff; color: var(--primary); }
.workspace-panel { min-width: 0; }
.conversation-review-grid { min-width: 0; display: grid; grid-template-columns: minmax(250px, 310px) minmax(0, 1fr); min-height: 590px; }
.conversation-list-pane { min-width: 0; height: 640px; display: flex; flex-direction: column; border-right: 1px solid var(--line); padding: 14px 10px 10px; }
.pane-heading { padding: 0 4px 7px; }
.pane-heading p { margin: 3px 0 0; font-size: 11px; }
.conversation-filters { min-width: 0; display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 6px; padding: 0 3px 5px; }
.conversation-filters label { min-width: 0; }
.conversation-filters :is(input, select) { min-width: 0; min-height: 44px; border: 1px solid var(--line); border-radius: 10px; background: white; padding: 8px 9px; color: var(--text); font: inherit; font-size: 12px; }
.conversation-filters input { width: 100%; }
.conversation-filters select { max-width: 104px; }
.admin-conversation-list { flex: 1; }
.load-more { width: calc(100% - 6px); min-height: 44px; margin: 7px 3px 1px; }
.conversation-detail { min-width: 0; height: 640px; overflow: hidden; }
.conversation-empty { min-height: 100%; border: 0; border-radius: 0; }
.conversation-content { min-width: 0; height: 100%; display: flex; flex-direction: column; }
.conversation-detail-header { flex: 0 0 auto; border-bottom: 1px solid var(--line); padding: 14px 17px 11px; background: rgba(255,255,255,.96); }
.conversation-title-row { align-items: flex-start; }
.conversation-title-row > div { min-width: 0; }
.conversation-title-row h3 { overflow: hidden; font-size: 17px; text-overflow: ellipsis; white-space: nowrap; }
.conversation-title-row .muted { margin: 4px 0 0; font-size: 11px; }
.student-workspace-header h2[tabindex="-1"]:focus, .conversation-detail-header h3[tabindex="-1"]:focus { outline: none; }
.review-button { min-height: 44px; flex: 0 0 auto; padding: 8px 11px; font-size: 11px; }
.review-button.is-reviewed { border: 1px solid #ddd2bd; background: #fff8ea; color: #775718; }
.conversation-content > .list-status { margin-inline: 18px; }
.older-message-row { flex: 0 0 auto; padding: 0 16px; text-align: center; }
.older-message-row .load-more { width: auto; min-width: 160px; }
.admin-transcript { min-width: 0; min-height: 0; flex: 1; overflow-y: auto; overscroll-behavior: contain; display: grid; align-content: start; gap: 13px; padding: 10px 18px 22px; scroll-padding-block: 16px; }
.admin-transcript-message { min-width: 0; width: min(100%, 880px); border: 1px solid var(--line); border-radius: 14px; background: white; padding: 13px 15px; overflow-wrap: anywhere; }
.admin-transcript-message.user { width: min(88%, 700px); justify-self: end; border-color: #c9d7f2; background: #f3f7ff; }
.admin-transcript-message.assistant { justify-self: start; }
.admin-transcript-message > header { min-width: 0; display: flex; align-items: center; gap: 8px; margin-bottom: 9px; color: var(--muted); font-size: 10px; }
.admin-transcript-message > header strong { color: #334155; font-size: 12px; }
.admin-message-content { min-width: 0; color: #253247; font-size: 13px; line-height: 1.7; }
.admin-message-content.user-copy { white-space: pre-wrap; }
.admin-message-content pre, .admin-message-content .katex-display { max-width: 100%; overflow-x: auto; }
.admin-image-note, .admin-feedback-note { margin: 10px 0 0; border-radius: 9px; padding: 8px 10px; font-size: 11px; line-height: 1.55; white-space: pre-wrap; }
.admin-image-note { background: #eef5ff; color: #3d5f91; }
.admin-feedback-note { border-left: 3px solid #9fcbbf; background: #f0faf7; color: #38645c; }
.admin-evidence-panel { margin-top: 11px; border-top: 1px solid var(--line); }
.admin-evidence-panel > summary { min-height: 44px; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 2px 2px; color: #405371; cursor: pointer; font-size: 12px; font-weight: 750; }
.admin-evidence-body { display: grid; gap: 9px; padding: 9px 0 3px; }
.admin-evidence-body h5 { margin: 2px 0 0; color: #405371; font-size: 11px; }
.admin-source-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 260px), 1fr)); gap: 8px; }
.admin-source-card { min-width: 0; border: 1px solid var(--line); border-radius: 11px; background: #f8fafc; padding: 10px; }
.admin-source-card.is-cited { border-color: #9dd4c5; background: #f1fbf8; }
.admin-source-card.is-selected { border-color: #aebfe9; background: #f2f6ff; }
.admin-source-card.is-candidate { color: #5d6a7d; background: #f7f8fa; }
.admin-source-card.is-unknown { border-style: dashed; border-color: #cfc4ad; background: #fbf9f4; }
.admin-source-header { align-items: flex-start; }
.admin-source-header strong { min-width: 0; overflow-wrap: anywhere; color: #244aaf; font-size: 11px; }
.admin-source-card .source-meta { margin: 5px 0; font-size: 10px; }
.admin-source-card .source-excerpt { max-height: 7.4em; overflow: auto; margin: 0; font-size: 11px; line-height: 1.55; white-space: pre-wrap; }
.source-card-footer { align-items: flex-end; margin-top: 8px; }
.source-card-footer small { color: var(--muted); font-size: 9px; }
.source-card-footer .textbook-page-link { min-height: 44px; flex: 0 0 auto; align-items: center; margin: 0; }
.candidate-evidence-group { border-radius: 9px; background: #f4f6f9; }
.candidate-evidence-group > summary { min-height: 44px; display: flex; align-items: center; padding: 8px 10px; color: #617086; cursor: pointer; font-size: 11px; font-weight: 750; }
.candidate-evidence-group .admin-source-grid { padding: 0 8px 8px; }
.evidence-empty { margin: 0; border-radius: 9px; background: #fff8e8; padding: 9px 10px; color: #765715; font-size: 11px; }
.evidence-retry { min-height: 44px; white-space: normal; }
.mobile-back { display: none; }
.section-heading { padding: 18px 20px 10px; }
.section-heading p { margin: 4px 0 0; color: var(--muted); font-size: 12px; }
.admin-portfolio-list { display: grid; gap: 10px; padding: 6px 20px 22px; }
.admin-portfolio-card { min-width: 0; border: 1px solid var(--line); border-radius: 13px; padding: 14px; }
.portfolio-card-header { align-items: flex-start; }
.portfolio-card-header h4 { min-width: 0; margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.portfolio-card-header button { min-height: 44px; flex: 0 0 auto; font-size: 11px; }
.portfolio-note { margin: 10px 0; border-left: 3px solid #8aa6ef; background: #f4f7ff; padding: 9px 11px; color: #3e5579; }
.admin-portfolio-card blockquote { margin: 9px 0; color: #334155; }
.portfolio-answer { overflow: hidden; color: var(--muted); font-size: 12px; line-height: 1.55; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 3; }
.admin-portfolio-card small { color: var(--muted); }
.score-layout { min-width: 0; display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(260px, .6fr); }
.score-editor { min-width: 0; border-right: 1px solid var(--line); padding-bottom: 22px; }
.score-form { display: grid; grid-template-columns: repeat(2, minmax(160px, 1fr)); gap: 13px; padding: 4px 20px; }
.score-form .wide { grid-column: 1 / -1; }
.score-actions { display: flex; gap: 9px; flex-wrap: wrap; }
.score-actions button { min-height: 44px; }
.score-result { min-height: 84px; margin: 14px 20px 0; border: 1px solid var(--line); border-radius: 13px; background: #f8fafc; padding: 14px; overflow-wrap: anywhere; }
.score-result > p { margin: 0; }
.score-preview-heading strong { font-size: 27px; }
.score-components { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 7px 12px; margin: 14px 0; font-size: 12px; }
.score-components dt, .score-components dd { margin: 0; }
.score-components dd { color: #52647f; text-align: right; }
.score-safeguards { margin: 10px 0 0; padding-left: 19px; color: #52647f; font-size: 11px; line-height: 1.6; }
.snapshot-success { margin-top: 12px !important; color: var(--accent); font-weight: 750; }
.snapshot-pane { min-width: 0; padding: 18px 16px; }
.snapshot-list { display: grid; gap: 8px; margin-top: 8px; }
.snapshot-card { min-width: 0; border: 1px solid var(--line); border-radius: 11px; background: #fafbfd; padding: 11px; }
.snapshot-card-top strong { font-size: 18px; }
.snapshot-card p { margin: 6px 0; overflow-wrap: anywhere; color: #52647f; font-size: 11px; line-height: 1.5; }
.snapshot-card small { color: var(--muted); font-size: 9px; }
.score-confirm-dialog { width: min(520px, calc(100% - 28px)); border: 0; border-radius: 18px; padding: 0; color: var(--text); box-shadow: 0 24px 80px rgba(9,20,43,.3); }
.score-confirm-dialog::backdrop { background: rgba(7,15,33,.58); backdrop-filter: blur(2px); }
.confirm-sheet { padding: 22px; }
.confirm-sheet h2 { margin: 0 0 10px; }
.confirm-sheet > p:not(.notice) { line-height: 1.65; }
.confirm-sheet .notice { margin: 15px 0; font-size: 12px; }
.confirm-actions { display: flex; justify-content: flex-end; gap: 9px; }
.confirm-actions button { min-height: 44px; }
.admin-shell.is-saving-score :where(.student-directory-item, .student-tab, .admin-conversation-item, .mobile-back) { pointer-events: none; opacity: .55; }

@media (max-width: 1180px) and (min-width: 901px) {
  .admin-inbox { grid-template-columns: minmax(240px, 270px) minmax(0, 1fr); }
  .conversation-review-grid { grid-template-columns: minmax(220px, 270px) minmax(0, 1fr); }
  .score-layout { grid-template-columns: minmax(0, 1fr); }
  .score-editor { border-right: 0; border-bottom: 1px solid var(--line); }
}

@media (max-width: 900px) {
  .login-shell { place-items: start center; }
  .login-layout { max-width: 720px; grid-template-columns: minmax(0, 1fr); }
  .login-brand-panel, .login-card { border-radius: 24px; }
  .course-kicker { margin-top: 32px; }
  .login-brand-panel h1 { max-width: none; }
  .course-link-grid { margin-top: 32px; }

  body.admin-page { width: 100%; min-width: 320px; }
  .admin-shell { width: 100%; padding: calc(12px + env(safe-area-inset-top)) calc(10px + env(safe-area-inset-right)) calc(24px + env(safe-area-inset-bottom)) calc(10px + env(safe-area-inset-left)); }
  .admin-header { align-items: flex-start; gap: 10px; }
  .admin-heading-copy { align-items: flex-start; }
  .admin-heading-copy .brand-mark { display: none; }
  .admin-header h1 { font-size: 21px; }
  .admin-header p { max-width: 38rem; font-size: 11px; }
  .admin-header-actions { gap: 6px; }
  .admin-header-actions :where(.button-link, button) { min-height: 44px; padding: 8px 10px; font-size: 12px; }
  .admin-summary { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 7px; }
  .summary-card { padding: 11px 12px; }
  .summary-card strong { font-size: 21px; }
  .inline-form { grid-template-columns: minmax(0, 1fr); }
  .inline-form input, .score-form input, .score-form textarea, .directory-search input { font-size: 16px; }
  .inline-form button { min-height: 46px; }
  .admin-inbox { display: block; }
  .admin-directory { position: static; min-height: 0; max-height: none; padding: 13px 10px 10px; }
  .student-directory { max-height: none; overflow: visible; }
  .student-directory-item { min-height: 86px; }
  .student-workspace { min-height: 0; border-radius: 14px; }
  .workspace-empty { display: none; }
  .mobile-back { min-height: 44px; display: inline-flex; margin-bottom: 8px; padding: 8px 10px; }
  .student-workspace-header { padding: 12px 12px 10px; }
  .student-identity h2 { font-size: 20px; }
  .compact-metrics { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 5px; }
  .compact-metrics > div { min-width: 0; display: grid; justify-items: center; gap: 1px; padding: 7px 4px; }
  .compact-metrics strong { font-size: 16px; }
  .student-tabs { position: sticky; top: 0; z-index: 5; padding: 6px 8px; }
  .student-tab { min-height: 44px; flex: 1 0 auto; padding-inline: 10px; }
  .conversation-review-grid { display: block; min-height: 0; }
  .conversation-list-pane, .conversation-detail { width: 100%; height: auto; min-height: 0; border: 0; }
  .conversation-list-pane { padding: 12px 8px; }
  .conversation-filters :is(input, select) { min-height: 44px; font-size: 16px; }
  .admin-conversation-list { overflow: visible; }
  .admin-conversation-item { min-height: 82px; }
  .conversation-empty { min-height: 240px; }
  .conversation-content { height: auto; }
  .conversation-detail-header { position: sticky; top: 0; z-index: 6; padding: calc(8px + env(safe-area-inset-top)) 10px 8px; }
  .conversation-title-row { align-items: flex-start; }
  .conversation-title-row h3 { max-width: 64vw; }
  .review-button { min-height: 44px; }
  .admin-transcript { max-height: none; overflow: visible; padding: 9px 9px 18px; }
  .admin-transcript-message { width: 100%; padding: 12px; }
  .admin-transcript-message.user { width: min(94%, 700px); }
  .admin-message-content { font-size: 13px; }
  .admin-evidence-panel > summary { min-height: 48px; }
  .admin-source-grid { grid-template-columns: minmax(0, 1fr); }
  .source-card-footer { align-items: center; }
  .source-card-footer .textbook-page-link { min-height: 44px; }
  .candidate-evidence-group > summary { min-height: 44px; }
  .section-heading { padding: 14px 13px 8px; }
  .admin-portfolio-list { padding: 5px 12px 16px; }
  .portfolio-card-header { display: grid; }
  .portfolio-card-header button { min-height: 44px; }
  .score-layout { grid-template-columns: minmax(0, 1fr); }
  .score-editor { border-right: 0; border-bottom: 1px solid var(--line); }
  .score-form { grid-template-columns: minmax(0, 1fr); padding: 4px 12px; }
  .score-form .wide { grid-column: auto; }
  .score-actions { display: grid; }
  .score-actions button { width: 100%; min-height: 46px; }
  .score-result { margin-inline: 12px; }
  .snapshot-pane { padding: 14px 12px; }
  .score-confirm-dialog[open] { position: fixed; inset: auto 0 0; width: 100%; max-width: none; margin: 0; border-radius: 20px 20px 0 0; }
  .confirm-sheet { padding: 22px 14px calc(14px + env(safe-area-inset-bottom)); }
  .confirm-actions button { flex: 1; min-height: 46px; }

  .admin-shell[data-mobile-view="directory"] .student-workspace { display: none; }
  .admin-shell[data-mobile-view="workspace"] :is(.admin-summary, .admin-policy, .account-create-panel, .admin-directory),
  .admin-shell[data-mobile-view="conversation"] :is(.admin-summary, .admin-policy, .account-create-panel, .admin-directory) { display: none; }
  .admin-shell[data-mobile-view="workspace"] .conversation-detail { display: none; }
  .admin-shell[data-mobile-view="conversation"] :is(.student-workspace-header, .student-tabs, .conversation-list-pane) { display: none; }
  .admin-shell[data-mobile-view="conversation"] .conversation-detail { display: block; }
}

@media (max-width: 820px) {
  body.chat-page { height: 100%; overflow: hidden; }
  body.sidebar-open, body.evidence-open, body.portfolio-open { overscroll-behavior: none; }
  .app-shell { display: block; height: var(--app-viewport-height, 100dvh); min-height: 0; overflow: hidden; }
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 50;
    width: min(86vw, 340px);
    height: var(--app-viewport-height, 100dvh);
    visibility: hidden;
    transform: translateX(-105%);
    transition: transform .24s ease, visibility 0s linear .24s;
    overflow: hidden;
    padding: calc(16px + env(safe-area-inset-top)) calc(16px + env(safe-area-inset-right)) calc(16px + env(safe-area-inset-bottom)) calc(16px + env(safe-area-inset-left));
    box-shadow: 18px 0 45px rgba(7, 15, 33, .32);
  }
  body.sidebar-open .sidebar { visibility: visible; transform: translateX(0); transition-delay: 0s; }
  .mobile-icon-button {
    display: inline-flex;
    width: 44px;
    height: 44px;
    flex: 0 0 44px;
    align-items: center;
    justify-content: center;
    border: 1px solid rgba(255,255,255,.16);
    border-radius: 12px;
    background: transparent;
    padding: 0;
    color: white;
    font-size: 25px;
    line-height: 1;
  }
  .sidebar-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 49;
    visibility: hidden;
    opacity: 0;
    border: 0;
    border-radius: 0;
    background: rgba(7, 15, 33, .5);
    padding: 0;
    cursor: pointer;
    touch-action: manipulation;
    transition: opacity .2s ease, visibility 0s linear .2s;
  }
  body.sidebar-open .sidebar-backdrop { visibility: visible; opacity: 1; transition-delay: 0s; }
  .sidebar > #new-chat { min-height: 44px; }
  .conversation-list { min-height: 0; overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
  .conversation-row { flex: 0 0 auto; }
  .conversation-item { width: 100%; min-height: 44px; padding: 10px 12px; }
  .conversation-rename { min-width: 48px; min-height: 44px; font-size: 12px; }
  .conversation-rename-form { grid-template-columns: minmax(0, 1fr) repeat(2, 44px); gap: 7px; padding: 8px; }
  .conversation-rename-input { height: 44px; font-size: 16px; }
  .conversation-rename-save, .conversation-rename-cancel { min-width: 44px; min-height: 44px; padding: 5px; }
  .sidebar-footer { flex: 0 0 auto; }
  .sidebar-footer :where(button, .text-link, summary) { min-height: 44px; }
  .sidebar-footer .text-link, .account-settings summary { display: flex; align-items: center; }
  .account-settings input { min-height: 44px; font-size: 16px; }
  .chat-main { width: 100%; height: var(--app-viewport-height, 100dvh); min-height: 0; grid-template-rows: auto minmax(0, 1fr) auto auto; }
  .topbar { min-height: 58px; gap: 11px; padding: calc(7px + env(safe-area-inset-top)) calc(12px + env(safe-area-inset-right)) 8px calc(10px + env(safe-area-inset-left)); }
  .topbar .menu-button { border-color: var(--line); color: var(--text); font-size: 21px; }
  .topbar-copy { flex: 1; }
  .topbar h1 { font-size: 18px; }
  .topbar p { overflow: hidden; margin-top: 2px; font-size: 12px; line-height: 1.35; text-overflow: ellipsis; white-space: nowrap; }
  .grounding-badge { display: none; }
  .messages { padding: 18px 14px 24px; gap: 20px; overscroll-behavior-y: contain; -webkit-overflow-scrolling: touch; scroll-padding-block: 16px; }
  .message { width: 100%; }
  .message.user { width: auto; max-width: 92%; padding: 11px 14px 13px; }
  .message.assistant { padding-bottom: 6px; }
  .message.assistant .message-body { margin-left: 0; max-width: none; }
  .message-header { margin-bottom: 6px; }
  .assistant-avatar { width: 30px; height: 30px; flex-basis: 30px; }
  .markdown-body { overflow-wrap: anywhere; }
  .markdown-body pre, .katex-display { -webkit-overflow-scrolling: touch; }
  .citation-ref { min-height: 30px; padding-inline: 6px; }
  .evidence-summary { min-height: 48px; }
  .evidence-panel[open] > .evidence-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 60;
    border: 0;
    border-radius: 0;
    background: rgba(15, 23, 42, .54);
    padding: 0;
  }
  .evidence-panel[open] > .evidence-body {
    position: fixed;
    inset: auto 0 0;
    z-index: 61;
    max-height: min(85dvh, 720px);
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    border: 1px solid var(--line);
    border-bottom: 0;
    border-radius: 22px 22px 0 0;
    background: var(--surface);
    padding: 0 14px calc(18px + env(safe-area-inset-bottom));
    box-shadow: 0 -18px 48px rgba(15, 23, 42, .22);
    animation: sheet-up .2s ease-out;
  }
  .mobile-evidence-header {
    position: sticky;
    top: 0;
    z-index: 2;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    min-height: 62px;
    margin: 0 -2px 8px;
    border-bottom: 1px solid var(--line);
    background: rgba(255,255,255,.96);
    backdrop-filter: blur(10px);
    font-size: 16px;
    font-weight: 800;
  }
  .mobile-evidence-header::before { content: ""; position: absolute; top: 6px; left: 50%; width: 42px; height: 4px; border-radius: 999px; background: #cbd5e1; transform: translateX(-50%); }
  .mobile-evidence-close { width: 44px; height: 44px; border-radius: 12px; background: var(--surface-soft); padding: 0; color: var(--text); font-size: 24px; }
  .sources { grid-template-columns: minmax(0, 1fr); }
  .source-card { padding: 12px; }
  .textbook-page-link { min-height: 44px; align-items: center; }
  .reflection-panel { margin: 0 12px 8px; }
  .reflection-panel > summary { min-height: 46px; }
  .reflection-panel[open] { max-height: 46dvh; overflow-y: auto; overscroll-behavior: contain; }
  .reflection-body textarea { font-size: 16px; }
  .reflection-body :where(button, .inline-check) { min-height: 44px; }
  .candidate-sources > summary { min-height: 44px; }
  body.reflection-open .composer { display: none; }
  .composer { position: relative; bottom: auto; padding: 8px calc(10px + env(safe-area-inset-right)) calc(8px + env(safe-area-inset-bottom)) calc(10px + env(safe-area-inset-left)); }
  .composer-box { border-radius: 16px; padding: 6px 7px 6px 12px; }
  .image-attachment { max-width: 100%; grid-template-columns: 52px minmax(0, 1fr) 52px; gap: 8px; margin: 0 0 4px -5px; padding-bottom: 7px; overflow: hidden; }
  .image-preview { width: 52px; height: 52px; border-radius: 10px; }
  .image-attachment-copy { overflow: hidden; }
  .composer .image-remove { min-width: 52px; min-height: 44px; height: 44px; padding: 5px; }
  .image-status { max-width: 100%; padding: 1px 0 2px; font-size: 11px; }
  .composer textarea { min-height: 40px; max-height: 112px; padding: 8px 2px; font-size: 16px; }
  .composer button { min-width: 64px; height: 44px; }
  .composer-tools { min-width: 0; gap: 7px; }
  .composer .image-pick { min-width: 72px; min-height: 44px; height: 44px; padding: 6px 8px; }
  .desktop-key-hint { display: none; }
  .portfolio-dialog[open] { position: fixed; inset: auto 0 0; width: 100%; max-width: none; max-height: min(86dvh, 720px); margin: 0; border-radius: 22px 22px 0 0; }
  .portfolio-sheet { max-height: min(86dvh, 720px); padding-bottom: env(safe-area-inset-bottom); }
  .portfolio-header { position: relative; min-height: 66px; padding: 20px 14px 12px; }
  .portfolio-header::before { content: ""; position: absolute; top: 7px; left: 50%; width: 42px; height: 4px; border-radius: 999px; background: #cbd5e1; transform: translateX(-50%); }
  .portfolio-header h2 { font-size: 19px; }
  .portfolio-description { padding: 11px 14px; font-size: 12px; }
  .portfolio-status { margin: 8px 14px 0; }
  .portfolio-list { -webkit-overflow-scrolling: touch; padding: 7px 14px 16px; }
  .portfolio-item { grid-template-columns: minmax(0, 1fr); gap: 12px; padding: 13px; }
  .portfolio-item-actions { flex-direction: row; }
  .portfolio-item-actions button { min-width: 0; min-height: 44px; flex: 1; font-size: 13px; }
}

@keyframes sheet-up { from { opacity: .5; transform: translateY(24px); } to { opacity: 1; transform: translateY(0); } }

@media (max-width: 480px) {
  .login-shell { min-height: 100dvh; align-items: start; padding: calc(28px + env(safe-area-inset-top)) calc(16px + env(safe-area-inset-right)) calc(24px + env(safe-area-inset-bottom)) calc(16px + env(safe-area-inset-left)); }
  .login-layout { gap: 12px; }
  .login-brand-panel { border-radius: 20px; padding: 24px 20px; }
  .course-kicker { margin-top: 24px; }
  .login-brand-panel h1 { font-size: clamp(25px, 8vw, 31px); white-space: nowrap; }
  .course-instructor { display: grid; gap: 5px; margin-top: 15px; }
  .course-intro { margin-top: 17px; font-size: 13px; }
  .course-link-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin-top: 22px; }
  .course-link-card { min-height: 126px; padding: 13px; }
  .course-link-top { margin-bottom: 10px; }
  .course-link-label { font-size: 9px; }
  .course-link-card > strong { font-size: 14px; }
  .course-link-subtitle { display: none; }
  .course-link-detail { max-height: 3.2em; overflow: hidden; padding-top: 8px; font-size: 9px; }
  .login-card { border-radius: 20px; padding: 26px 22px; }
  .login-card h2 { font-size: 25px; }
  .login-card .stack { margin-top: 22px; }
  .login-card input { min-height: 48px; font-size: 16px; }
  .login-card button { min-height: 48px; }
  .topbar p { display: none; }
  .message.assistant .message-content { font-size: 15px; }
  .source-card-heading { display: grid; }
  .source-badge { justify-self: start; }
  .composer-hint { max-width: 160px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
  .reflection-body .row { align-items: stretch; }
  .reflection-body .row button { flex: 1 1 100%; }
}

@media (max-width: 480px) and (max-height: 700px) {
  .login-card { order: -1; }
}

@media (max-width: 820px) and (max-height: 640px) {
  .sidebar { gap: 12px; overflow-y: auto; }
  .conversation-list { flex: 0 0 auto; max-height: clamp(64px, 24dvh, 120px); }
  .topbar p { display: none; }
  .topbar { min-height: 52px; padding-top: calc(4px + env(safe-area-inset-top)); padding-bottom: 4px; }
  .evidence-panel[open] > .evidence-body { max-height: 88dvh; }
  .portfolio-dialog[open], .portfolio-sheet { max-height: 90dvh; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
