* { box-sizing: border-box; }

/* display:flex/grid on an element would otherwise override the hidden attribute */
[hidden] { display: none !important; }

/* DATA 8014 · Deep Representation Learning — "latent space" theme.
   Cool graph-paper neutrals, ultramarine primary, magenta reserved for the
   off-manifold points in the brand mark. */
:root {
  --bg: #fafbfd;
  --sidebar-bg: #eff1f7;
  --hover: #e6e9f2;
  --active: #dde1ee;
  --border: #e2e5f0;
  --text: #1b1d27;
  --text-dim: #767b8c;
  --accent: #3d47c4;
  --accent-hover: #2f38a4;
  --accent-soft: #eaecfb;
  --accent-alt: #c2417e;
  --bubble: #edeff6;
  --danger: #b23a2f;
  --disabled: #ccd0de;
  --font-display: "Avenir Next", Avenir, Futura, "Segoe UI", system-ui, sans-serif;
  --font-mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
  --dot-grid: radial-gradient(circle, rgba(61, 71, 196, 0.13) 1px, transparent 1.4px);
}

html, body {
  height: 100%;
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--text);
}
body { background: var(--bg); }

button { font: inherit; cursor: pointer; color: inherit; }

/* Links carry accent ink and a little weight instead of underlines;
   hovering washes them in accent-soft so the target reads as a surface. */
a {
  color: var(--accent);
  text-decoration: none;
}
.md a,
.course-info-content a,
.admin-sub a {
  font-weight: 500;
  border-radius: 4px;
  padding: 1px 3px;
  margin: -1px -3px;
  transition: background 0.12s, color 0.12s;
}
.md a:hover,
.course-info-content a:hover,
.admin-sub a:hover {
  background: var(--accent-soft);
  color: var(--accent-hover);
}

button:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ------------------------------ icons ------------------------------ */

svg.icon {
  width: 15px;
  height: 15px;
  flex-shrink: 0;
  pointer-events: none;
}

/* ------------------------------ brand ------------------------------ */

.brand {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 600;
  letter-spacing: 0.04em;
}
.brand em {
  color: var(--accent);
  font-style: normal;
  font-family: var(--font-mono);
  font-size: 0.92em;
  letter-spacing: 0.02em;
}
.brand-mark { width: 22px; height: 22px; flex-shrink: 0; color: var(--accent); overflow: visible; }
.mark-curve { stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; fill: none; }
.mark-pt { fill: currentColor; }
.mark-pt.alt { fill: var(--accent-alt); }

/* ------------------------------ layout ------------------------------ */

#app { display: flex; height: 100dvh; }

#sidebar {
  width: 264px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
}

.sidebar-head { padding: 14px 12px 8px; }
.sidebar-head .brand { padding: 2px 6px 12px; }

#new-chat-btn {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  font-weight: 500;
  text-align: left;
  transition: background 0.15s;
}
#new-chat-btn:hover { background: var(--hover); }
#new-chat-btn svg.icon { color: var(--accent); }

#library-btn,
#course-btn,
#classmates-btn {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 6px;
  padding: 8px 12px;
  border: none;
  border-radius: 10px;
  background: transparent;
  font-weight: 500;
  color: var(--text);
  text-align: left;
}
#library-btn:hover,
#course-btn:hover,
#classmates-btn:hover { background: var(--hover); }
#library-btn svg.icon,
#course-btn svg.icon,
#classmates-btn svg.icon { color: var(--accent); }

#search-wrap {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-top: 6px;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text-dim);
}
#search-wrap:focus-within { border-color: var(--accent); color: var(--text); }
#search-input {
  flex: 1;
  min-width: 0;
  border: none;
  outline: none;
  background: transparent;
  font: inherit;
  font-size: 13.5px;
  color: var(--text);
}
#search-kbd {
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--text-dim);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 1px 5px;
}
#search-results { flex: 1; overflow-y: auto; padding: 8px; }
.search-hit {
  padding: 7px 10px;
  border-radius: 8px;
  cursor: pointer;
}
.search-hit:hover { background: var(--hover); }
.search-hit-title { font-size: 13.5px; font-weight: 500; }
.search-hit-sub {
  font-size: 12px;
  color: var(--text-dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#chat-list { flex: 1; overflow-y: auto; padding: 8px; }

.chat-item {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 8px 6px 8px 10px;
  border-radius: 8px;
  font-size: 14px;
  cursor: pointer;
  color: var(--text);
}
.chat-item:hover { background: var(--hover); }
.chat-item.active { background: var(--active); font-weight: 500; }
.chat-item .title {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-item .ann-icon {
  flex-shrink: 0;
  display: inline-flex;
  color: var(--accent);
  margin-right: 3px;
}
.chat-item .ann-icon svg.icon { width: 13px; height: 13px; }
.chat-item .delete-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: none;
  color: var(--text-dim);
  padding: 3px 4px;
  border-radius: 6px;
  visibility: hidden;
  line-height: 1;
}
.chat-item .delete-btn svg.icon { width: 12px; height: 12px; }
.chat-item:hover .delete-btn { visibility: visible; }
.chat-item .delete-btn:hover { color: var(--text); background: var(--active); }
.chat-item.dragging { opacity: 0.5; }

/* Per-chat “⋯” options menu (pin / archive / copy / delete). */
.chat-menu {
  position: fixed;
  z-index: 50;
  min-width: 160px;
  max-width: 240px;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(40, 45, 70, 0.12);
  padding: 4px;
}
.chat-menu button {
  border: none;
  background: none;
  text-align: left;
  font-size: 13.5px;
  padding: 7px 10px;
  border-radius: 7px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-menu button:hover { background: var(--sidebar-bg); }
.chat-menu button.danger { color: var(--danger); }

.chat-section.archived-toggle { cursor: pointer; user-select: none; }
.chat-section.archived-toggle:hover { color: var(--text); }
.archived-label { display: inline-flex; align-items: center; gap: 4px; }
.archived-label svg.icon { width: 12px; height: 12px; }

.sidebar-foot {
  border-top: 1px solid var(--border);
  padding: 12px;
  font-size: 13px;
}
#user-email {
  color: var(--text-dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-bottom: 8px;
}
.sidebar-foot button {
  width: 100%;
  padding: 7px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  margin-bottom: 8px;
}
.sidebar-foot button:last-child { margin-bottom: 0; }
.sidebar-foot button:hover { background: var(--hover); }
#admin-btn { font-weight: 500; }

.chat-section {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-family: var(--font-mono);
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--text-dim);
  padding: 12px 8px 4px;
}
.chat-section:first-child { padding-top: 4px; }
.chat-section .section-new {
  display: inline-flex;
  border: none;
  background: none;
  color: var(--text-dim);
  padding: 1px 2px;
  border-radius: 6px;
  line-height: 1;
}
.chat-section .section-new svg.icon { width: 13px; height: 13px; }
.chat-section .section-new:hover { color: var(--accent); }
.section-buttons { display: inline-flex; gap: 2px; }
.chat-section .section-del { visibility: hidden; }
.chat-section:hover .section-del { visibility: visible; }
.chat-section .section-del:hover { color: var(--danger); }

/* ------------------------------ chat area ------------------------------ */

#main { flex: 1; display: flex; flex-direction: column; min-width: 0; }

/* New chat: nothing in the thread yet — the greeting and composer sit
   vertically centered, then drop to the bottom once messages exist. */
#main.centered { justify-content: center; }
#main.centered #messages { flex: 0 0 auto; }
#main.centered .empty-state { margin: 0 0 14px; }

#messages {
  flex: 1;
  overflow-y: auto;
  padding: 28px 16px 12px;
}
.messages-inner { max-width: 760px; margin: 0 auto; }

/* Empty thread: the latent-space moment — a faint coordinate grid behind the
   greeting, and the manifold mark drawing itself while its points settle. */
#main.centered {
  background: var(--dot-grid) 0 0 / 24px 24px;
}
.empty-state {
  text-align: center;
  color: var(--text-dim);
  margin-top: 22vh;
}
.empty-state svg.icon {
  width: 42px;
  height: 42px;
  stroke-width: 1.3;
  color: #aab1cb;
  margin-bottom: 12px;
}
.empty-state .latent-hero {
  width: 64px;
  height: 64px;
  overflow: visible;
  color: var(--accent);
  margin-bottom: 14px;
}
.latent-hero .mark-curve {
  stroke-dasharray: 40;
  stroke-dashoffset: 40;
  animation: draw-manifold 0.9s ease-out 0.15s forwards;
}
.latent-hero .mark-pt {
  opacity: 0;
  animation: settle-pt 0.4s ease-out forwards;
}
.latent-hero .mark-pt:nth-of-type(1) { animation-delay: 0.25s; }
.latent-hero .mark-pt:nth-of-type(2) { animation-delay: 0.45s; }
.latent-hero .mark-pt:nth-of-type(3) { animation-delay: 0.65s; }
.latent-hero .mark-pt:nth-of-type(4) { animation-delay: 0.9s; }
.latent-hero .mark-pt:nth-of-type(5) { animation-delay: 1.05s; }
@keyframes draw-manifold { to { stroke-dashoffset: 0; } }
@keyframes settle-pt { from { opacity: 0; transform: translateY(3px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) {
  .latent-hero .mark-curve { animation: none; stroke-dashoffset: 0; }
  .latent-hero .mark-pt { animation: none; opacity: 1; }
}
.empty-state h1 {
  font-family: var(--font-display);
  font-size: 29px;
  font-weight: 600;
  letter-spacing: 0.005em;
  color: var(--text);
  margin: 0 0 8px;
}
.empty-state p { max-width: 440px; margin: 0 auto; }

.message { margin-bottom: 22px; line-height: 1.6; font-size: 15px; }

.message.user { display: flex; flex-direction: column; align-items: flex-end; }
.message.user .bubble {
  background: var(--bubble);
  border-radius: 18px;
  padding: 10px 16px;
  max-width: 75%;
  white-space: pre-wrap;
  overflow-wrap: break-word;
}

/* Group chats: other members' messages sit left, labelled with their name. */
.message.user.theirs { align-items: flex-start; }
.message.user.theirs .bubble { background: var(--accent-soft); }
.sender-name {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-dim);
  margin: 0 6px 3px;
}

/* ----- moderation & deadlines ----- */

.deadline-tag {
  flex-shrink: 0;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-dim);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 1px 7px;
  white-space: nowrap;
}
.deadline-tag.overdue { color: var(--danger); border-color: var(--danger); }

.status-board { display: flex; gap: 8px; padding: 6px 0 10px; }
.status-chip {
  display: inline-block;
  font-size: 12px;
  font-weight: 600;
  border-radius: 999px;
  padding: 2px 10px;
  margin-left: 6px;
  border: 1px solid var(--border);
  color: var(--text-dim);
}
.status-board .status-chip { margin-left: 0; }
.status-chip.submitted { color: #2c6e49; border-color: #2c6e49; background: #eef5f0; }
.status-chip.late { color: #9a6a00; border-color: #c9992e; background: #faf4e6; }
.status-chip.missing { color: var(--danger); border-color: var(--danger); background: #f8ecea; }

.deleted-msg { font-size: 13.5px; font-style: italic; color: var(--text-dim); }
.edited-tag { font-size: 11px; color: var(--text-dim); margin: 2px 6px 0; }
.message.user .edited-tag { align-self: flex-end; }

.endorsed-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  font-weight: 600;
  color: #2c6e49;
  margin-bottom: 3px;
}
.endorsed-badge svg.icon { width: 13px; height: 13px; }
.message.endorsed .bubble,
.message.endorsed .md { border: 1.5px solid #2c6e49 !important; }
.message.assistant.endorsed .md {
  border-radius: 18px;
  padding: 10px 16px;
}

.message.flash .bubble,
.message.flash .md,
.message.flash .deleted-msg {
  animation: flash-bg 1.8s ease-out;
}
@keyframes flash-bg {
  0%, 40% { box-shadow: 0 0 0 3px var(--accent-soft), 0 0 0 4px var(--accent); }
  100% { box-shadow: none; }
}

/* ----- emoji reactions (public posts & group chats) ----- */

.reactions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 6px;
}
.reaction-chip {
  border: 1px solid var(--border);
  background: var(--bg);
  border-radius: 999px;
  font-size: 12.5px;
  padding: 2px 9px;
  line-height: 1.5;
}
.reaction-chip:hover { border-color: var(--accent); }
.reaction-chip.mine { background: var(--accent-soft); border-color: var(--accent); }
.reaction-add {
  display: inline-flex;
  align-items: center;
  border: none;
  background: none;
  color: var(--text-dim);
  padding: 2px;
  border-radius: 999px;
  visibility: hidden;
}
.reaction-add svg.icon { width: 15px; height: 15px; }
.message:hover .reaction-add { visibility: visible; }
.reaction-add:hover { color: var(--accent); }
.reaction-picker {
  position: fixed;
  z-index: 60;
  width: 304px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 10px;
  box-shadow: 0 8px 28px rgba(40, 45, 70, 0.16);
}
.emoji-search {
  width: 100%;
  padding: 7px 10px;
  font: inherit;
  font-size: 13.5px;
  border: 1px solid var(--border);
  border-radius: 8px;
  outline: none;
  background: var(--sidebar-bg);
}
.emoji-search:focus { border-color: var(--accent); background: var(--bg); }
.emoji-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 2px;
  max-height: 232px;
  overflow-y: auto;
  overscroll-behavior: contain;
}
.emoji-grid button {
  border: none;
  background: none;
  font-size: 18px;
  line-height: 1.4;
  padding: 3px 0;
  border-radius: 7px;
}
.emoji-grid button:hover { background: var(--sidebar-bg); }
.emoji-grid .reply-none { grid-column: 1 / -1; text-align: center; padding: 14px 0; }

/* ----- quote-replies ----- */

.quote-block {
  max-width: 75%;
  border-left: 3px solid var(--accent);
  background: var(--accent-soft);
  border-radius: 8px;
  padding: 5px 10px;
  margin-bottom: 4px;
  font-size: 12.5px;
  overflow-wrap: break-word;
}
.quote-block .q-sender { font-weight: 600; color: var(--accent); }
.quote-block .q-text { color: var(--text); }

#quote-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  background: var(--accent-soft);
  border-radius: 10px;
  padding: 6px 10px;
  margin-bottom: 8px;
  font-size: 13px;
}
#quote-bar[hidden] { display: none; }
.quote-bar-text {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
#quote-bar button {
  display: inline-flex;
  border: none;
  background: none;
  color: var(--text-dim);
  padding: 2px;
}
#quote-bar button svg.icon { width: 13px; height: 13px; }
#quote-bar button:hover { color: var(--danger); }

/* ----- AI as a boxed participant in public posts ----- */

.message.assistant.boxed { display: flex; flex-direction: column; align-items: flex-start; }
.message.assistant.boxed .md {
  background: var(--sidebar-bg);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 10px 16px;
  max-width: 85%;
}

/* ----- shared chat links: chip + preview modal ----- */

.share-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  vertical-align: middle;
  border: 1px solid var(--accent);
  background: var(--bg);
  color: var(--accent);
  border-radius: 999px;
  font-size: 12.5px;
  font-weight: 600;
  padding: 2px 10px;
  margin: 0 2px;
}
.share-chip svg.icon { width: 12px; height: 12px; }
.share-chip:hover { background: var(--accent-soft); }

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 70;
  background: rgba(36, 37, 43, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.share-modal {
  width: min(580px, 100%);
  max-height: 78vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: 0 16px 48px rgba(30, 32, 45, 0.28);
  overflow: hidden;
}
.share-head {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}
.share-title {
  flex: 1;
  min-width: 0;
  font-family: var(--font-display);
  font-size: 17px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.share-close {
  display: inline-flex;
  border: none;
  background: none;
  color: var(--text-dim);
  padding: 3px;
  border-radius: 6px;
  align-self: center;
}
.share-close:hover { color: var(--text); }
.share-body { overflow-y: auto; padding: 16px 18px 6px; }
.share-body .message { font-size: 14px; margin-bottom: 16px; }
.share-foot {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 12px 18px;
  border-top: 1px solid var(--border);
}
.share-foot .ghost-btn { padding: 8px 13px; font-size: 13.5px; }

/* ----- library page ----- */

.library-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 2px;
  border-bottom: 1px dashed var(--border);
  font-size: 13.5px;
}
.library-row:last-child { border-bottom: none; }
.library-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.library-toggle { font-size: 13px; color: var(--text-dim); }
.library-toggle input { accent-color: var(--accent); }
.library-upload { display: flex; flex-direction: column; gap: 8px; margin-bottom: 6px; }
.library-upload > input {
  width: 100%;
  padding: 9px 12px;
  font: inherit;
  border: 1px solid var(--border);
  border-radius: 10px;
  outline: none;
  background: var(--bg);
}
.library-upload > input:focus { border-color: var(--accent); }
.library-upload .group-create { margin-top: 0; }
.lib-repo-row { display: flex; gap: 8px; align-items: stretch; }
.lib-repo-row input {
  flex: 1;
  min-width: 0;
  padding: 9px 12px;
  font: inherit;
  border: 1px solid var(--border);
  border-radius: 10px;
  outline: none;
  background: var(--bg);
}
.lib-repo-row input:focus { border-color: var(--accent); }
.lib-repo-row .ghost-btn { white-space: nowrap; }

.message.assistant .md { overflow-wrap: break-word; }
.message.assistant .md > :first-child { margin-top: 0; }
.message.assistant .md > :last-child { margin-bottom: 0; }
.message.error .md { color: var(--danger); }

.md pre {
  background: var(--sidebar-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  overflow-x: auto;
  font-size: 13px;
}
.md code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.92em;
  background: #eceef6;
  padding: 1px 5px;
  border-radius: 5px;
}
.md pre code { background: none; padding: 0; }
.md table { border-collapse: collapse; display: block; overflow-x: auto; }
.md th, .md td { border: 1px solid var(--border); padding: 6px 10px; }
.md blockquote {
  margin: 0;
  padding-left: 12px;
  border-left: 3px solid var(--border);
  color: var(--text-dim);
}
.md img { max-width: 100%; }

.attachment-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 6px; justify-content: flex-end; }
.attachment-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  border: 1px solid var(--border);
  background: var(--sidebar-bg);
  border-radius: 8px;
  padding: 4px 9px;
  max-width: 240px;
}
.attachment-chip > svg.icon { width: 13px; height: 13px; color: var(--text-dim); }
.attachment-chip .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attachment-image {
  max-width: 220px;
  max-height: 180px;
  border-radius: 12px;
  border: 1px solid var(--border);
  display: block;
  margin-bottom: 6px;
}

.typing-cursor::after {
  content: '▍';
  color: var(--accent);
  animation: blink 1s steps(1) infinite;
}
@keyframes blink { 50% { opacity: 0; } }
@media (prefers-reduced-motion: reduce) {
  .typing-cursor::after { animation: none; }
}

/* ------------------------------ composer ------------------------------ */

#composer-wrap { padding: 0 16px 10px; }
.composer-inner { max-width: 760px; margin: 0 auto; }

#file-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
#file-chips .attachment-chip button {
  display: inline-flex;
  border: none;
  background: none;
  color: var(--text-dim);
  padding: 0;
  line-height: 1;
}
#file-chips .attachment-chip button svg.icon { width: 12px; height: 12px; }
#file-chips .attachment-chip button:hover { color: var(--danger); }

#composer {
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border);
  border-radius: 24px;
  padding: 10px 10px 8px 16px;
  background: var(--bg);
  box-shadow: 0 2px 12px rgba(40, 45, 70, 0.05);
}
#composer:focus-within { border-color: #c0c5d6; }

#input {
  width: 100%;
  border: none;
  outline: none;
  resize: none;
  font: inherit;
  font-size: 15px;
  line-height: 1.45;
  max-height: 180px;
  padding: 2px 2px 10px;
  background: transparent;
}

#composer-controls {
  display: flex;
  align-items: center;
  gap: 2px;
  margin-left: -8px; /* optically align the paperclip with the text column */
}
#composer-controls .spacer { flex: 1; }

.chip-select {
  appearance: none;
  -webkit-appearance: none;
  font: inherit;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text-dim);
  border: none;
  border-radius: 999px;
  padding: 7px 24px 7px 10px;
  background: transparent
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='%2382807a' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M4.5 6.5 8 10l3.5-3.5'/%3E%3C/svg%3E")
    no-repeat right 7px center / 14px;
  cursor: pointer;
  max-width: 170px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.chip-select:hover { background-color: var(--sidebar-bg); color: var(--text); }
.chip-select:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.icon-btn {
  width: 36px;
  height: 36px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--text-dim);
}
.icon-btn:hover { background: var(--sidebar-bg); color: var(--text); }
.icon-btn svg { width: 20px; height: 20px; }

#send-btn { background: var(--accent); color: #fff; }
#send-btn:hover { background: var(--accent-hover); color: #fff; }
#send-btn:disabled { background: var(--disabled); cursor: default; }

.hint {
  text-align: center;
  font-size: 12px;
  color: var(--text-dim);
  padding: 8px 0 2px;
}

/* ------------------------------ login page ------------------------------ */

.auth-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100dvh;
  background: var(--sidebar-bg);
  background-image: var(--dot-grid);
  background-size: 24px 24px;
}
.auth-course {
  text-align: center;
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-dim);
  margin: 2px 0 20px;
}
.auth-card {
  width: 380px;
  max-width: calc(100vw - 32px);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 36px 32px;
  box-shadow: 0 4px 24px rgba(40, 45, 70, 0.06);
}
.auth-card .brand {
  display: flex;
  justify-content: center;
  margin-bottom: 6px;
}
.auth-sub {
  text-align: center;
  color: var(--text-dim);
  font-size: 14px;
  margin: 0 0 24px;
}
.auth-card label { display: block; font-size: 13px; font-weight: 500; margin: 14px 0 5px; }
.auth-card input {
  width: 100%;
  padding: 10px 12px;
  font: inherit;
  border: 1px solid var(--border);
  border-radius: 10px;
  outline: none;
  background: var(--bg);
}
.auth-card input:focus { border-color: var(--accent); }
#auth-submit {
  width: 100%;
  margin-top: 22px;
  padding: 11px;
  border: none;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
}
#auth-submit:hover { background: var(--accent-hover); }
#auth-submit:disabled { background: var(--disabled); }
#auth-error {
  color: var(--danger);
  font-size: 13.5px;
  min-height: 18px;
  margin: 12px 0 0;
  text-align: center;
}
.auth-toggle {
  text-align: center;
  font-size: 14px;
  color: var(--text-dim);
  margin-top: 18px;
}
.auth-toggle a { color: var(--accent); cursor: pointer; font-weight: 500; }
.auth-toggle a:hover { color: var(--accent-hover); }

/* ------------------------------ admin page ------------------------------ */

.admin-body { background: var(--sidebar-bg); min-height: 100dvh; }
.admin-page { max-width: 720px; margin: 0 auto; padding: 32px 16px 64px; }
.admin-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 6px 12px;
  margin-bottom: 20px;
}
.admin-tag {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  color: var(--accent);
  background: var(--accent-soft);
  border-radius: 999px;
  padding: 3px 9px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  align-self: center;
}
.admin-back { font-size: 14px; color: var(--accent); font-weight: 500; }
.admin-back:hover { color: var(--accent-hover); }

.admin-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 24px;
  margin-bottom: 28px;
}
.admin-card h2 {
  font-family: var(--font-display);
  margin: 0 0 6px;
  font-size: 19px;
  font-weight: 600;
}
.admin-sub { color: var(--text-dim); font-size: 13.5px; line-height: 1.5; margin: 0 0 8px; }
.admin-card label { display: block; font-size: 13px; font-weight: 500; margin: 14px 0 5px; }
/* Radios and checkboxes keep their native size — the text-field styling below
   (width: 100%, padding) makes Safari paint the dot across the label text. */
.admin-card input:not([type="radio"]):not([type="checkbox"]),
.admin-card textarea {
  width: 100%;
  padding: 10px 12px;
  font: inherit;
  border: 1px solid var(--border);
  border-radius: 10px;
  outline: none;
  resize: vertical;
  background: var(--bg);
}
.admin-card input:focus,
.admin-card textarea:focus { border-color: var(--accent); }
#publish-btn {
  padding: 10px 18px;
  border: none;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
}
#publish-btn:hover { background: var(--accent-hover); }
#publish-btn:disabled { background: var(--disabled); }
.admin-error { color: var(--danger); font-size: 13.5px; min-height: 18px; margin: 10px 0 0; }

.admin-list-title {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 600;
  color: var(--text-dim);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  margin: 0 0 10px 4px;
}
.ann-item {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 16px 18px;
  margin-bottom: 12px;
}
.ann-item-head {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 2px 10px;
}
.ann-item-head h3 {
  margin: 0;
  font-size: 15px;
  flex: 1 1 auto;
  min-width: 0;
  overflow-wrap: break-word;
}
.ann-meta { font-size: 12.5px; color: var(--text-dim); }
.ann-content { font-size: 14px; margin: 8px 0 12px; white-space: pre-wrap; overflow-wrap: break-word; }
.ann-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.ann-actions button {
  font-size: 13px;
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
}
.ann-actions button:hover { background: var(--sidebar-bg); }
.ann-actions .retract:hover { color: var(--danger); border-color: var(--danger); background: var(--bg); }
.ann-replies { border-top: 1px solid var(--border); margin-top: 12px; padding-top: 8px; }
.reply-row { font-size: 13.5px; padding: 7px 0; border-bottom: 1px dashed var(--border); }
.reply-row:last-child { border-bottom: none; }
.reply-email { font-weight: 600; overflow-wrap: anywhere; }
.reply-time { color: var(--text-dim); font-size: 12px; margin-left: 8px; }
.reply-text { margin-top: 3px; white-space: pre-wrap; overflow-wrap: break-word; }
.reply-none { color: var(--text-dim); font-style: italic; }

/* -------- admin: compose extras, groups, harvest, roster, records -------- */

.label-hint { font-weight: 400; color: var(--text-dim); font-size: 12px; }
.audience-row { display: flex; flex-wrap: wrap; gap: 8px 18px; margin: 4px 0 6px; }
.admin-card label.radio,
.radio {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  font-weight: 400;
  cursor: pointer;
  margin: 0;
  white-space: nowrap;
  flex-shrink: 0;
}
.radio input {
  accent-color: var(--accent);
  width: 14px;
  height: 14px;
  margin: 0;
  padding: 0;
  flex-shrink: 0;
}
.audience-detail { margin-top: 4px; }
#audience-groups { display: flex; flex-wrap: wrap; gap: 14px; padding: 6px 2px; }
.btn-row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-top: 16px; }
.ghost-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 10px 16px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text); /* anchors styled as ghost buttons match the button variant */
  font-weight: 500;
}
.ghost-btn svg.icon { color: var(--accent); }
.ghost-btn:hover { background: var(--sidebar-bg); }
.ghost-btn:disabled { color: var(--text-dim); }
.ghost-btn:disabled svg.icon { color: var(--text-dim); }

.harvest-box {
  border-top: 1px solid var(--border);
  margin-top: 12px;
  padding-top: 10px;
}
.harvest-title { font-size: 12.5px; font-weight: 600; color: var(--accent); margin-bottom: 4px; }
.harvest-summary { font-size: 13.5px; white-space: pre-wrap; overflow-wrap: break-word; }

.group-item {
  background: var(--sidebar-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
  margin-top: 12px;
}
.group-create { display: flex; gap: 8px; margin-top: 10px; }
.group-create input {
  flex: 1;
  min-width: 0;
  padding: 9px 12px;
  font: inherit;
  border: 1px solid var(--border);
  border-radius: 10px;
  outline: none;
  background: var(--bg);
}
.group-create input:focus { border-color: var(--accent); }
.group-create button {
  padding: 9px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  font-weight: 500;
  white-space: nowrap;
}
.group-create button:hover { background: var(--sidebar-bg); }
.group-del { border: 1px solid var(--border); border-radius: 8px; background: var(--bg); font-size: 13px; padding: 5px 10px; }
.group-del:hover { color: var(--danger); border-color: var(--danger); }
.member-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.member-chips .attachment-chip { background: var(--bg); }
.member-chips .attachment-chip button {
  display: inline-flex;
  border: none;
  background: none;
  color: var(--text-dim);
  padding: 0;
}
.member-chips .attachment-chip button svg.icon { width: 12px; height: 12px; }
.member-chips .attachment-chip button:hover { color: var(--danger); }

.record-row {
  display: flex;
  align-items: baseline;
  gap: 10px;
  flex-wrap: wrap;
  font-size: 13.5px;
  padding: 7px 0;
  border-bottom: 1px dashed var(--border);
}
.record-row:last-child { border-bottom: none; }
.record-kind {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
  text-transform: capitalize;
  white-space: nowrap;
}
.record-kind svg.icon { width: 13px; height: 13px; }
.record-label { font-weight: 500; }
.record-value { color: var(--text); }
.record-detail { width: 100%; color: var(--text-dim); font-size: 12.5px; }

/* ------------------------------ profile page ------------------------------ */

.profile-grid { display: flex; gap: 28px; margin-top: 6px; }
.fields-cell { flex: 1; min-width: 0; }
.two-col { display: flex; gap: 14px; }
.two-col > div { flex: 1; min-width: 0; }
.avatar-cell { display: flex; flex-direction: column; align-items: center; gap: 10px; width: 120px; flex-shrink: 0; }
.avatar-img, .avatar-placeholder {
  width: 104px;
  height: 104px;
  border-radius: 50%;
  border: 1px solid var(--border);
  object-fit: cover;
}
.avatar-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--sidebar-bg);
  color: #a9afc6;
}
.avatar-placeholder svg { width: 42px; height: 42px; }
.admin-card select {
  width: 100%;
  padding: 10px 12px;
  font: inherit;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
}
#save-btn {
  margin-top: 18px;
  padding: 10px 18px;
  border: none;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
}
#save-btn:hover { background: var(--accent-hover); }
#save-btn:disabled { background: var(--disabled); }

/* ----- classmates page ----- */

.classmate-item { display: flex; align-items: flex-start; gap: 14px; }
.classmate-avatar {
  width: 44px;
  height: 44px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--sidebar-bg);
  color: var(--accent);
  overflow: hidden;
}
.classmate-avatar img { width: 100%; height: 100%; object-fit: cover; }
.classmate-avatar svg.icon { width: 20px; height: 20px; }
.classmate-info { flex: 1; min-width: 0; }
.classmate-name { font-weight: 600; font-size: 14.5px; }
.classmate-github {
  display: inline-block;
  font-size: 12.5px;
  color: var(--accent);
  text-decoration: none;
  margin-top: 2px;
}
.classmate-github:hover { color: var(--accent-hover); }
.classmate-actions { display: flex; flex-direction: column; gap: 6px; align-items: flex-end; }
.accept-btn {
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  padding: 6px 12px;
}
.accept-btn:hover { background: var(--accent-hover); }
.notif-toggle { display: flex; margin-top: 18px; font-size: 14px; }

/* ------------------------------ small screens ------------------------------ */

/* Hamburger + backdrop exist on all sizes but only show on phones. */
#menu-btn {
  display: none;
  position: fixed;
  top: 10px;
  left: 10px;
  z-index: 45;
  width: 40px;
  height: 40px;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  box-shadow: 0 2px 10px rgba(40, 45, 70, 0.08);
}
#menu-btn svg.icon { width: 18px; height: 18px; }
#backdrop {
  position: fixed;
  inset: 0;
  z-index: 39;
  background: rgba(36, 37, 43, 0.35);
}

/* ----- analytics table ----- */

.analytics-table {
  border-collapse: collapse;
  width: 100%;
  font-size: 13px;
}
.analytics-table th,
.analytics-table td {
  text-align: left;
  padding: 7px 10px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.analytics-table th {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-dim);
}
.analytics-table tr:last-child td { border-bottom: none; }

/* Touch devices have no hover — always show the hover-revealed controls. */
@media (hover: none) {
  .chat-item .delete-btn,
  .reaction-add,
  .chat-section .section-del { visibility: visible; }
}

@media (max-width: 720px) {
  #menu-btn { display: flex; }
  #sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100dvh;
    width: min(300px, 84vw);
    z-index: 40;
    transform: translateX(-105%);
    transition: transform 0.22s ease;
    box-shadow: 0 0 30px rgba(36, 37, 43, 0.18);
  }
  #sidebar.open { transform: translateX(0); }
  #messages { padding-top: 60px; } /* clear the floating hamburger */
  .message.user .bubble,
  .quote-block { max-width: 88%; }
  .chip-select { max-width: 32vw; }
  .profile-grid { flex-direction: column; align-items: center; }
  .fields-cell { width: 100%; }
  .two-col { flex-direction: column; gap: 0; }
  .group-create { flex-wrap: wrap; }
  .share-modal { max-height: 88vh; }
}

/* Send button doubles as Stop while a reply is streaming. */
#send-btn.stop { background: var(--danger); }
#send-btn.stop:hover { background: #9b2f26; }

/* ----- in-app views (Library / Classmates / Profile inside #main) ----- */

.page-view {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  background: var(--sidebar-bg);
}
.page-view .admin-page { padding-top: 20px; }
.view-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}
.view-head h2 {
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 600;
  margin: 0;
}
.view-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--bg);
  color: var(--text-dim);
}
.view-close:hover { color: var(--text); background: var(--hover); }
@media (max-width: 720px) {
  .page-view .admin-page { padding-top: 60px; } /* clear the hamburger */
}

/* --------------------------------------------------------------------------
   Course info view
   -------------------------------------------------------------------------- */
.course-info-actions { display: flex; gap: 8px; justify-content: flex-end; margin-bottom: 10px; }
.course-info-content { line-height: 1.65; font-size: 15px; overflow-wrap: break-word; }
.course-head { margin: 2px 4px 22px; }
.course-head h1 { font-family: var(--font-display); font-size: 26px; margin: 0 0 2px; }
.course-head p { margin: 4px 0 0; color: var(--text-dim); }
.course-card { margin-bottom: 18px; }
.course-card .md > :first-child { margin-top: 0; }
.course-card .md > :last-child { margin-bottom: 0; }
.course-info-content h3 { font-size: 16px; margin: 14px 0 6px; }
.course-info-content ul, .course-info-content ol { padding-left: 24px; }
.course-info-content a { color: var(--accent); }
.course-card textarea { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13.5px; }
.course-sec { position: relative; }
.course-edit-btn { position: absolute; top: 12px; right: 12px; font-size: 12.5px; padding: 4px 12px; opacity: .6; }
.course-sec:hover .course-edit-btn, .course-edit-btn:focus { opacity: 1; }
.course-head.course-sec { padding-right: 76px; } /* keep the Edit button clear of the title */
.course-add-btn { display: block; margin: 0 0 28px; }
.course-del-btn { color: var(--danger); margin-right: auto; }

/* Staff cards inside the Course info Staff section */
.staff-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; margin-top: 14px; }
.staff-card { border: 1px solid var(--border); border-radius: 12px; padding: 14px 16px; }
.staff-role { font-family: var(--font-mono); font-size: 10.5px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; color: var(--accent); margin-bottom: 6px; }
.staff-name { font-weight: 600; font-size: 15.5px; margin-bottom: 2px; }
.staff-contact { font-size: 13px; overflow-wrap: anywhere; }
.staff-note { font-size: 12.5px; color: var(--text-dim); margin-top: 2px; }

/* Course schedule table — compact single-line rows, hover bubbles on event dates */
.md table.sched { display: table; width: 100%; font-size: 13.5px; border-collapse: collapse; }
.md table.sched td { border: none; border-bottom: 1px solid var(--border); padding: 8px 10px 8px 0; vertical-align: baseline; }
.md table.sched tr:last-child td { border-bottom: none; }
.sched td.n { width: 26px; color: var(--text-dim); font-size: 12px; white-space: nowrap; }
.sched td:nth-child(2) { width: 96px; white-space: nowrap; }
.sched .d { font-weight: 500; }
.sched tr.off td { color: var(--text-dim); font-style: italic; }
.md table.sched tr.event td { background: var(--accent-soft); }
.sched tr.event td:last-child { font-weight: 600; }
.sched tr.event td.n { color: var(--accent); }
.sched .ev {
  position: relative;
  color: var(--accent);
  font-weight: 600;
  border-bottom: 1.5px dashed var(--accent);
  cursor: help;
}
.sched .ev::after {
  content: attr(data-ev);
  position: absolute;
  left: 0;
  bottom: calc(100% + 7px);
  z-index: 30;
  white-space: nowrap;
  background: var(--text);
  color: var(--bg);
  font-size: 12px;
  font-weight: 500;
  padding: 5px 10px;
  border-radius: 8px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.18);
  opacity: 0;
  pointer-events: none;
  transform: translateY(3px);
  transition: opacity 0.12s, transform 0.12s;
}
.sched .ev::before {
  content: '';
  position: absolute;
  bottom: calc(100% + 2px);
  left: 12px;
  border: 5px solid transparent;
  border-top-color: var(--text);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.12s;
}
.sched .ev:hover::after, .sched .ev:focus::after { opacity: 1; transform: translateY(0); }
.sched .ev:hover::before, .sched .ev:focus::before { opacity: 1; }

/* Staff & key-dates tables — share the schedule's compact row style */
.sched td.r { font-size: 10.5px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--text-dim); white-space: nowrap; }
.staff-tbl td.r { width: 140px; }
.sched td.nm { font-weight: 600; white-space: nowrap; }
.staff-tbl td.nm { width: 130px; }
.staff-tbl td.note { color: var(--text-dim); font-size: 12.5px; white-space: nowrap; text-align: right; }
