/* MelodyLand Admin — one stylesheet, light and dark from the same tokens. */

:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --panel-2: #f8f9fa;
  --border: #e3e6ea;
  --text: #16191d;
  --muted: #69707a;
  --accent: #0f8a6c;
  --accent-soft: #e2f4ee;
  --accent-text: #ffffff;
  --danger: #c0352b;
  --danger-soft: #fbe9e7;
  --warn: #a8660b;
  --warn-soft: #fdf1dc;
  --info-soft: #e8f0fb;
  --info: #2c5fa8;
  --bubble-in: #ffffff;
  --bubble-out: #d9fdd3;
  --bubble-console: #dcebfd;
  --chat-bg: #efeae2;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --radius: 10px;
  --nav-w: 216px;
  --top-h: 56px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1215;
    --panel: #171c20;
    --panel-2: #1d2328;
    --border: #2a3239;
    --text: #e7ebee;
    --muted: #98a2ab;
    --accent: #21b58f;
    --accent-soft: #123a30;
    --accent-text: #071a14;
    --danger: #f07167;
    --danger-soft: #3a1b19;
    --warn: #f0b458;
    --warn-soft: #3a2c14;
    --info-soft: #172a44;
    --info: #8bb4ec;
    --bubble-in: #202c33;
    --bubble-out: #005c4b;
    --bubble-console: #1d3d63;
    --chat-bg: #0b141a;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
h1 { font-size: 20px; margin: 0; font-weight: 650; }
h2 { font-size: 16px; margin: 0 0 8px; font-weight: 650; }
h3 { font-size: 14px; margin: 0 0 6px; font-weight: 650; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.booting { padding: 40px; color: var(--muted); }

/* --- layout --- */
.app {
  display: grid;
  grid-template-columns: var(--nav-w) 1fr;
  grid-template-rows: var(--top-h) 1fr;
  grid-template-areas: "top top" "nav main";
  height: 100vh;
}
.topbar {
  grid-area: top;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 15px; }
.brand.big { font-size: 20px; margin-bottom: 8px; }
.brand-mark {
  display: inline-grid; place-items: center;
  width: 28px; height: 28px; border-radius: 8px;
  background: var(--accent); color: var(--accent-text); font-size: 16px;
}
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 14px; min-width: 0; }
.who { text-align: right; line-height: 1.2; min-width: 0; }
.who-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 220px; }
.who-level { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.live { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.live .dot { width: 8px; height: 8px; border-radius: 50%; background: #9aa1a8; }
.live.on .dot { background: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.menu-btn { display: none; background: none; border: 0; font-size: 20px; cursor: pointer; padding: 4px 8px; }

.nav {
  grid-area: nav;
  background: var(--panel);
  border-right: 1px solid var(--border);
  padding: 12px 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow-y: auto;
}
.nav-link {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; border-radius: 8px;
  color: var(--text); text-decoration: none;
}
.nav-link:hover { background: var(--panel-2); }
.nav-link.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav-icon { width: 20px; text-align: center; }
.nav-section {
  margin: 14px 12px 4px; padding-top: 12px; border-top: 1px solid var(--border);
  font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted);
}
.nav-badge {
  margin-left: auto; min-width: 20px; padding: 0 6px; border-radius: 10px;
  background: var(--danger); color: #fff; font-size: 11px; font-weight: 700; text-align: center; line-height: 18px;
}

.main { grid-area: main; overflow: auto; min-width: 0; }
.view { padding: 20px 24px 40px; max-width: 1200px; }
.view-chats { padding: 0; max-width: none; height: 100%; }
.view-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.view-actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }
.card .view-head { margin-bottom: 4px; }
.card .view-head h3 { margin: 0; }
.mu-group { margin-top: 16px; }
.mu-group .item:last-child { border-bottom: 0; }

/* MU tracker */
.mu-progress-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.live-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); animation: mu-pulse 1.2s ease-in-out infinite; }
@keyframes mu-pulse { 50% { opacity: .35; } }
.mu-bar { margin-top: 10px; height: 6px; border-radius: 3px; background: var(--accent-soft); overflow: hidden; }
.mu-bar-fill { height: 100%; background: var(--accent); transition: width .3s ease; }
.mu-lines { margin: 6px 0; display: grid; gap: 4px; }
.mu-line { font-size: 13px; padding: 4px 8px; border-radius: 6px; background: var(--panel); border: 1px solid var(--border); overflow-wrap: anywhere; }
.mu-line.old { text-decoration: line-through; text-decoration-color: color-mix(in srgb, var(--danger) 60%, transparent); }
.mu-line.new { background: var(--accent-soft); border-color: transparent; }
.mu-line-label { display: inline-block; min-width: 80px; font-size: 11px; color: var(--muted); text-decoration: none; }
.mu-details summary { cursor: pointer; color: var(--muted); margin-top: 4px; }
.mu-details .item-sub { margin-top: 3px; overflow-wrap: anywhere; }
@media (max-width: 600px) { .mu-row { flex-direction: column; } .mu-row .item-actions { align-self: flex-end; } }

/* --- building blocks --- */
.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}
.card + .card { margin-top: 16px; }
.grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.stats { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); }
.stat-value { font-size: 20px; font-weight: 700; }
.stat-label { font-size: 12px; color: var(--muted); }
.stat-hint { font-size: 11px; color: var(--muted); }
.empty { padding: 28px 16px; text-align: center; color: var(--muted); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--border); background: var(--panel); color: var(--text);
  padding: 7px 14px; border-radius: 8px; cursor: pointer; font-weight: 550; white-space: nowrap;
}
.btn:hover { background: var(--panel-2); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover { filter: brightness(1.05); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.ghost { background: transparent; }
.btn.small { padding: 4px 10px; font-size: 12px; }

.input, select.input, textarea.input {
  width: 100%;
  border: 1px solid var(--border); background: var(--panel); border-radius: 8px;
  padding: 8px 10px;
}
.input:focus, .btn:focus-visible, .nav-link:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
textarea.input { resize: vertical; min-height: 44px; }
label.field { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); font-weight: 600; }
label.field > .input { color: var(--text); font-weight: 400; font-size: 14px; }
.choice { display: flex; gap: 8px; align-items: flex-start; padding: 6px 0; cursor: pointer; }
.choice input { margin-top: 3px; }

.badge {
  display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: 11px; font-weight: 650;
  background: var(--panel-2); color: var(--muted); border: 1px solid var(--border); white-space: nowrap;
}
.badge.good { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.badge.bad { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.badge.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.badge.info { background: var(--info-soft); color: var(--info); border-color: transparent; }

.notice { padding: 10px 12px; border-radius: 8px; background: var(--info-soft); color: var(--info); font-size: 13px; }
.notice.warn { background: var(--warn-soft); color: var(--warn); }
.notice.bad { background: var(--danger-soft); color: var(--danger); }
.notice ul { margin: 6px 0 0; padding-left: 18px; }

.table-wrap { overflow-x: auto; }
table.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
.table th { font-size: 12px; color: var(--muted); font-weight: 600; white-space: nowrap; }
.table tr:last-child td { border-bottom: 0; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12.5px; }
.pre { white-space: pre-wrap; word-break: break-word; }
mark { background: #ffe58a; color: #1a1a1a; border-radius: 2px; padding: 0 1px; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 12px; }
.tab { background: none; border: 0; padding: 8px 12px; cursor: pointer; border-bottom: 2px solid transparent; color: var(--muted); font-weight: 600; }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { border: 1px solid var(--border); background: var(--panel); border-radius: 16px; padding: 3px 12px; cursor: pointer; font-size: 12px; }
.chip.active { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }

/* --- toasts and dialog --- */
.toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 50; max-width: min(420px, calc(100vw - 32px)); }
.toast { padding: 10px 14px; border-radius: 8px; background: var(--text); color: var(--panel); box-shadow: 0 6px 20px rgba(0,0,0,.2); white-space: pre-wrap; }
.toast.success { background: var(--accent); color: var(--accent-text); }
.toast.error { background: var(--danger); color: #fff; }
.dialog { border: 1px solid var(--border); border-radius: 12px; padding: 20px; width: min(520px, calc(100vw - 32px)); background: var(--panel); color: var(--text); }
.dialog::backdrop { background: rgba(0, 0, 0, .45); }
.dialog-body { white-space: pre-wrap; word-break: break-word; max-height: 55vh; overflow: auto; margin: 8px 0 16px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }

/* --- sign in --- */
.signin {
  grid-column: 1 / -1; grid-row: 1 / -1;
  min-height: 100vh;
  display: grid; place-items: center; padding: 24px 16px;
  background:
    radial-gradient(60% 50% at 12% 8%, color-mix(in srgb, var(--accent) 22%, transparent), transparent 70%),
    radial-gradient(50% 45% at 92% 94%, color-mix(in srgb, var(--info) 18%, transparent), transparent 70%),
    var(--bg);
}
.signin-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: 18px;
  padding: 36px 32px 28px; width: min(420px, 100%);
  box-shadow: 0 12px 40px rgba(16, 24, 40, .12), 0 2px 6px rgba(16, 24, 40, .06);
  animation: signin-in .35s ease-out both;
}
@keyframes signin-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .signin-card { animation: none; } }
.signin-brand { display: flex; flex-direction: column; align-items: center; gap: 2px; text-align: center; margin-bottom: 20px; }
.signin-mark {
  display: grid; place-items: center; width: 56px; height: 56px; border-radius: 16px; margin-bottom: 10px;
  background: linear-gradient(145deg, var(--accent), color-mix(in srgb, var(--accent) 55%, var(--info)));
  color: var(--accent-text); font-size: 28px;
  box-shadow: 0 6px 16px color-mix(in srgb, var(--accent) 35%, transparent);
}
.signin-title { font-size: 22px; font-weight: 700; letter-spacing: -.01em; }
.signin-sub { font-size: 12px; font-weight: 650; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); }
.signin-lead { text-align: center; margin: 0 0 18px; color: var(--muted); }
.signin-form { display: flex; flex-direction: column; gap: 14px; }
.signin-field { display: flex; flex-direction: column; gap: 6px; font-size: 12px; font-weight: 650; color: var(--muted); }
.signin-field .input { font-size: 15px; padding: 11px 12px; border-radius: 10px; color: var(--text); font-weight: 400; }
.signin-field .input:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }
.signin-password { position: relative; display: flex; }
.signin-password .input { padding-right: 64px; }
.signin-reveal {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  border: 0; background: none; cursor: pointer; padding: 6px 10px; border-radius: 8px;
  font-size: 12px; font-weight: 650; color: var(--accent);
}
.signin-reveal:hover { background: var(--accent-soft); }
.signin-reveal:focus-visible { outline: 2px solid var(--accent); }
.signin-submit { width: 100%; padding: 12px 14px; border-radius: 10px; font-size: 15px; margin-top: 4px; }
.signin-error { padding: 10px 12px; border-radius: 10px; background: var(--danger-soft); color: var(--danger); font-size: 13px; }
.signin-error[hidden] { display: none; }
.signin-note { margin: 14px 0 0; font-size: 12px; line-height: 1.5; color: var(--muted); text-align: center; }
.signin-note + .signin-note { margin-top: 8px; }
.signin-note a { font-weight: 650; }
.signin-field .input.signin-code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; letter-spacing: .12em; text-transform: uppercase; }

/* the setup code shown to the head admin */
.invite-code {
  font: 700 26px/1.2 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; letter-spacing: .1em;
  text-align: center; padding: 14px 12px; margin: 4px 0 10px;
  background: var(--panel-2); border: 1px dashed var(--border); border-radius: 10px; user-select: all;
}

/* --- chats --- */
.chats { display: grid; grid-template-columns: 330px minmax(0, 1fr) 290px; height: 100%; }
.chats.no-card { grid-template-columns: 330px minmax(0, 1fr); }
.threads { border-right: 1px solid var(--border); background: var(--panel); display: flex; flex-direction: column; min-height: 0; }
.threads-search { padding: 12px; border-bottom: 1px solid var(--border); }
.threads-list { flex: 1; overflow-y: auto; }
.thread-row { display: flex; gap: 12px; padding: 11px 14px; cursor: pointer; border-bottom: 1px solid var(--border); text-decoration: none; color: inherit; }
.thread-row:hover { background: var(--panel-2); }
.thread-row.active { background: var(--accent-soft); }
.avatar { width: 40px; height: 40px; border-radius: 50%; background: var(--accent); color: var(--accent-text); display: grid; place-items: center; font-weight: 700; flex-shrink: 0; }
.avatar.parent { background: #7c5cc4; color: #fff; }
.avatar.staff { background: #2c7be5; color: #fff; }
.thread-body { min-width: 0; flex: 1; }
.thread-top { display: flex; gap: 8px; align-items: baseline; }
.thread-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.thread-time { margin-left: auto; font-size: 11px; color: var(--muted); flex-shrink: 0; }
.thread-sub { font-size: 11px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.thread-preview { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pin-btn { border: 0; background: none; cursor: pointer; padding: 0 2px; font-size: 13px; line-height: 1; opacity: .35; filter: grayscale(1); flex-shrink: 0; }
.pin-btn:hover, .pin-btn:focus-visible, .pin-btn.on { opacity: 1; filter: none; }
.pin-btn:not(.on) { transform: rotate(45deg); }
/* In a list row the pin stays out of the way until the row is hovered, unless it is doing something. */
.pin-btn.in-row:not(.on) { display: none; }
.thread-row:hover .pin-btn.in-row, .thread-row:focus-within .pin-btn.in-row { display: inline; }
@media (hover: none) { .pin-btn.in-row:not(.on) { display: inline; } }
.thread-row.pinned { background: var(--panel-2); }
.thread-row.pinned.active { background: var(--accent-soft); }
.section-label { padding: 10px 14px 4px; font-size: 11px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.hit { padding: 9px 14px; cursor: pointer; border-bottom: 1px solid var(--border); }
.hit:hover { background: var(--panel-2); }
.hit-snippet { font-size: 13px; color: var(--muted); margin-top: 2px; }

.convo { display: flex; flex-direction: column; min-height: 0; min-width: 0; background: var(--chat-bg); }
.convo-head { display: flex; align-items: center; gap: 12px; padding: 10px 16px; background: var(--panel); border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.convo-title { min-width: 0; }
.convo-name { font-weight: 650; font-size: 15px; }
.convo-meta { font-size: 12px; color: var(--muted); }
.convo-head .row { margin-left: auto; }
.back-btn { display: none; }
.messages { flex: 1; overflow-y: auto; padding: 16px 6%; display: flex; flex-direction: column; gap: 4px; }
.day-sep { align-self: center; margin: 10px 0 6px; font-size: 11.5px; color: var(--muted); background: var(--panel); padding: 3px 10px; border-radius: 8px; box-shadow: var(--shadow); }
.msg { display: flex; }
.msg.out { justify-content: flex-end; }
.bubble { max-width: min(640px, 75%); padding: 6px 10px 5px; border-radius: 8px; white-space: pre-wrap; word-break: break-word; box-shadow: 0 1px 1px rgba(0,0,0,.08); background: var(--bubble-in); }
.msg.out .bubble { background: var(--bubble-out); }
.msg.out.human .bubble { background: var(--bubble-console); }
.bubble-tag { font-size: 10.5px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; margin-bottom: 2px; }
.bubble-time { font-size: 10.5px; color: var(--muted); text-align: right; margin-top: 2px; }
.load-older { align-self: center; margin-bottom: 8px; }
.placeholder { flex: 1; display: grid; place-items: center; color: var(--muted); padding: 20px; text-align: center; }

/* --- assistant: the chat screen's parts, one conversation, no thread list --- */
.view-assistant { padding: 0; max-width: none; height: 100%; }
.convo.assistant { height: 100%; }
.proposal { margin-top: 8px; padding: 8px 10px; border-radius: 6px; background: var(--panel-2); border: 1px solid var(--border); display: flex; flex-direction: column; gap: 6px; white-space: normal; }
.proposal-text { font-weight: 600; white-space: pre-wrap; }

.composer { background: var(--panel); border-top: 1px solid var(--border); padding: 10px 12px; display: flex; flex-direction: column; gap: 8px; }
.composer-row { display: flex; gap: 8px; align-items: flex-end; }
.composer textarea { max-height: 180px; }

/* The Assistant's model/effort settings: a small button that opens a panel under it. */
.pick { position: relative; }
.pick-panel { position: absolute; right: 0; top: calc(100% + 6px); z-index: 20; width: 220px; display: flex; flex-direction: column; gap: 10px; padding: 12px; background: var(--panel); border: 1px solid var(--border); border-radius: 10px; box-shadow: 0 8px 24px rgba(0,0,0,.15); }
.pick-panel[hidden] { display: none; }
.pick-field { display: flex; flex-direction: column; gap: 4px; }
.window-pill { font-size: 12px; }

.contact { border-left: 1px solid var(--border); background: var(--panel); overflow-y: auto; padding: 16px; }
.contact .avatar { width: 56px; height: 56px; font-size: 22px; margin-bottom: 8px; }
.contact dl { display: grid; grid-template-columns: auto 1fr; gap: 4px 10px; margin: 10px 0; font-size: 13px; }
.contact dt { color: var(--muted); }
.contact dd { margin: 0; word-break: break-word; }
.student { padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; margin-bottom: 6px; font-size: 13px; }

/* --- lists of things --- */
.item { display: flex; gap: 12px; align-items: flex-start; padding: 12px 0; border-bottom: 1px solid var(--border); }
.item:last-child { border-bottom: 0; }
.item-main { flex: 1; min-width: 0; }
.item-title { font-weight: 600; }
.item-sub { font-size: 12.5px; color: var(--muted); }
.item-actions { display: flex; gap: 6px; flex-shrink: 0; }
.activity-kind { width: 86px; flex-shrink: 0; }
.kv { display: grid; grid-template-columns: minmax(120px, auto) 1fr; gap: 4px 12px; font-size: 13px; }
.kv > div:nth-child(odd) { color: var(--muted); }
.kv > div { word-break: break-word; }
.results { max-height: 320px; overflow: auto; }
.missing-list { margin: 4px 0 0; padding-left: 18px; font-size: 13px; }
.switch-state { font-size: 28px; font-weight: 800; }

/* --- narrow screens --- */
@media (max-width: 1100px) {
  .chats { grid-template-columns: 300px minmax(0, 1fr); }
  .contact { display: none; }
  .chats.show-card .contact { display: block; position: fixed; right: 0; top: var(--top-h); bottom: 0; width: min(320px, 90vw); z-index: 20; box-shadow: -8px 0 24px rgba(0,0,0,.15); }
}
@media (max-width: 760px) {
  :root { --nav-w: 0px; }
  .app { grid-template-columns: 1fr; grid-template-areas: "top" "main"; }
  .menu-btn { display: block; }
  .topbar { gap: 8px; padding: 0 10px; }
  .brand { white-space: nowrap; font-size: 14px; }
  .live > span:last-child { display: none; }
  .convo-head { gap: 8px; padding: 8px 10px; }
  .convo-head .avatar { display: none; }
  /* At the bottom a toast would sit over the reply box. */
  .toasts { top: calc(var(--top-h) + 8px); bottom: auto; left: 16px; right: 16px; max-width: none; }
  .nav { position: fixed; top: var(--top-h); left: 0; bottom: 0; width: 240px; z-index: 30; transform: translateX(-100%); transition: transform .15s ease; box-shadow: 8px 0 24px rgba(0,0,0,.15); }
  body.nav-open .nav { transform: none; }
  .who { display: none; }
  .view { padding: 16px; }
  .chats, .chats.no-card { grid-template-columns: 1fr; }
  .chats.open .threads { display: none; }
  .chats:not(.open) .convo { display: none; }
  .back-btn { display: inline-flex; }
  .messages { padding: 12px; }
  .bubble { max-width: 88%; }
  .activity-kind { width: auto; }
  .item { flex-wrap: wrap; }
}

/* --- term recap, weekly schedule, changes --- */
.view-recap, .view-week, .view-changes { max-width: none; }
.filters { margin-top: 12px; align-items: center; }
.legend { display: flex; gap: 6px; flex-wrap: wrap; margin: 12px 0 8px; }
.chip-s { display: inline-block; padding: 1px 8px; border-radius: 6px; font-size: 12px; border: 1px solid transparent; }

/* One set of colours for a recap cell's state, used by the cells, the legend and the change lists. */
.s-present { background: var(--accent-soft); color: var(--accent); }
.s-needmu { background: var(--warn-soft); color: var(--warn); }
.s-cancel { background: var(--danger-soft); color: var(--danger); }
.s-holiday { background: var(--info-soft); color: var(--info); }
.s-absent, .s-other { background: var(--panel-2); color: var(--text); }
.s-unknown { background: var(--danger-soft); color: var(--danger); }
.chip-s.s-absent, .chip-s.s-other { border-color: var(--border); }
.chip-s.s-note { background: transparent; color: var(--muted); font-style: italic; border: 1px dashed var(--border); }
.chip-s.s-unknown { border: 1px dashed var(--danger); }
.chip-s.s-empty { background: transparent; color: var(--muted); border: 1px dashed var(--border); }

.recap-wrap { overflow: auto; max-height: 72vh; border: 1px solid var(--border); border-radius: 8px; }
.recap-table { border-collapse: separate; border-spacing: 0; font-size: 12.5px; width: max-content; min-width: 100%; }
.recap-table th, .recap-table td { padding: 4px 6px; border-bottom: 1px solid var(--border); border-right: 1px solid var(--border); text-align: left; vertical-align: top; }
.recap-table thead th { position: sticky; top: 0; z-index: 3; background: var(--panel-2); font-size: 11px; color: var(--muted); white-space: nowrap; }
.recap-table th.holiday { background: var(--info-soft); color: var(--info); }
.recap-table .sticky { position: sticky; left: 0; z-index: 2; background: var(--panel); min-width: 150px; max-width: 210px; }
.recap-table thead .sticky { z-index: 4; background: var(--panel-2); }
.recap-table tr.group-start td { border-top: 2px solid var(--border); }
.rn { font-weight: 600; }
.rs { font-size: 11px; color: var(--muted); font-weight: 400; }
.name-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 6px; }
.icon-btn { flex: none; display: inline-flex; align-items: center; justify-content: center; width: 24px; height: 24px; padding: 0; border: 1px solid var(--border); border-radius: 6px; background: transparent; color: var(--muted); cursor: pointer; }
.icon-btn:hover:not(:disabled) { color: var(--accent); border-color: var(--accent); }
.icon-btn:disabled { opacity: .5; cursor: progress; }
.prev { max-width: 120px; font-size: 11px; color: var(--muted); }
.termcol { white-space: nowrap; font-size: 11px; font-weight: 600; color: var(--muted); }
td.rc { min-width: 74px; }
td.rc.holiday.s-empty { background: var(--panel-2); }
td.rc.s-note { background: transparent; color: var(--muted); font-style: italic; }
.rc-g { white-space: nowrap; font-weight: 600; }
.rc-type { margin-left: 4px; font-size: 10.5px; font-weight: 400; opacity: .85; }
.rc-note { font-size: 10.5px; opacity: .9; max-width: 150px; }

.wk-title { margin: 6px 0 8px; }
.wk-card { padding: 0; overflow: hidden; }
.wk-wrap { overflow: auto; max-height: 75vh; }
.wk-table { border-collapse: separate; border-spacing: 0; width: max-content; min-width: 100%; font-size: 12.5px; }
.wk-table th, .wk-table td { border-bottom: 1px solid var(--border); border-right: 1px solid var(--border); padding: 0; }
.wk-table thead th { position: sticky; top: 0; z-index: 3; background: var(--panel-2); padding: 6px 8px; text-align: left; min-width: 150px; }
.wk-table .wk-time { position: sticky; left: 0; z-index: 2; background: var(--panel-2); width: 56px; min-width: 56px; padding: 2px 6px; font-size: 11px; font-weight: 500; color: var(--muted); text-align: right; }
.wk-table thead .wk-time { z-index: 4; }
.wk-table tr.on-hour .wk-time { color: var(--text); font-weight: 650; }
.wk-teacher { font-weight: 650; }
.wk-loc { font-size: 11px; font-weight: 400; color: var(--muted); }
.wk-empty { height: 22px; }
.wk-cell { vertical-align: top; padding: 2px; }
.bk { height: 100%; padding: 3px 6px; border-radius: 6px; border-left: 3px solid var(--border); background: var(--panel-2); }
.bk-p { background: var(--accent-soft); border-left-color: var(--accent); }
.bk-anmu { background: var(--warn-soft); border-left-color: var(--warn); }
.bk-otdc { background: var(--danger-soft); border-left-color: var(--danger); }
.bk-note { background: transparent; border-left-color: transparent; color: var(--muted); font-style: italic; }
.bk-top { display: flex; justify-content: space-between; gap: 6px; }
.bk-name { font-weight: 600; }
.bk-code { font-size: 10px; font-weight: 700; opacity: .8; }
.bk-sub { font-size: 11px; color: var(--muted); }

.chg-row { display: flex; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--border); }
.chg-row:last-child { border-bottom: 0; }
.chg-who { width: 170px; flex-shrink: 0; font-weight: 600; }
.chg-list { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.chg-item { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.chg-week { min-width: 72px; font-size: 11px; color: var(--muted); }
.chg-arrow { color: var(--muted); }
.chg-line { padding: 4px 0; font-size: 13px; word-break: break-word; }
.chg-where { font-size: 12.5px; color: var(--muted); }

@media (max-width: 760px) {
  .recap-table .sticky { min-width: 110px; max-width: 130px; }
  .chg-row { flex-wrap: wrap; }
  .chg-who { width: 100%; }
}

/* Print: the page you are looking at, on white, without the menus. */
@media print {
  :root {
    --bg: #fff; --panel: #fff; --panel-2: #f3f4f6; --border: #d1d5db; --text: #111; --muted: #555;
    --accent: #0f8a6c; --accent-soft: #e2f4ee; --warn: #a8660b; --warn-soft: #fdf1dc;
    --danger: #c0352b; --danger-soft: #fbe9e7; --info: #2c5fa8; --info-soft: #e8f0fb;
    color-scheme: light;
  }
  .topbar, .nav, .no-print, .view-actions, .toasts { display: none !important; }
  .app { display: block; height: auto; }
  .main { overflow: visible; }
  .view { padding: 0; max-width: none; }
  .recap-wrap, .wk-wrap { max-height: none; overflow: visible; }
  .card { box-shadow: none; }
}

/* A wide table scrolls inside its card; it must not stretch the page (a bare 1fr track grows to fit it). */
.app { grid-template-columns: var(--nav-w) minmax(0, 1fr); }
@media (max-width: 760px) {
  .app { grid-template-columns: minmax(0, 1fr); }
}

/* Search and filters: what does not match is dimmed, not removed. */
.bk-dim { opacity: .25; }
.bk-dim:hover { opacity: .6; }
.hits { display: flex; flex-direction: column; max-height: 260px; overflow: auto; }
.hit-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 6px 4px; border: 0; border-bottom: 1px solid var(--border); background: none; text-align: left; cursor: pointer; }
.hit-row:hover, .hit-row:focus-visible { background: var(--panel-2); }
.hit-row:last-child { border-bottom: 0; }
.hit-when { min-width: 130px; font-size: 12px; color: var(--muted); }
.hit-who { font-weight: 600; }
.filters input[type="search"] { min-width: 0; }

/* Recap: quick views (needs a make-up, empty weeks, the schedule check). */
.quick { margin-top: 12px; align-items: center; }
.quick .btn .count { margin-left: 6px; padding: 0 7px; border-radius: 10px; font-size: 11px; font-weight: 700; background: var(--panel-2); color: var(--muted); }
.quick .btn.primary .count { background: rgba(255, 255, 255, .25); color: inherit; }
.recap-table td.owes { min-width: 150px; }
.owes-main { font-weight: 700; }
.recap-table td.gaps { max-width: 190px; }
.recap-table td.gaps .chip-s { margin: 0 4px 2px 0; }
td.rc.gap { background: transparent; color: var(--danger); text-align: center; outline: 1px dashed var(--danger); outline-offset: -3px; }
td.rc.flag { position: relative; outline: 2px solid var(--warn); outline-offset: -2px; }
.flag-mark { position: absolute; top: 1px; right: 3px; font-size: 11px; line-height: 1; color: var(--warn); }
.flag-note { color: var(--warn); }
.check-card { margin: 0 0 12px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; background: var(--panel-2); }
.chk-head { display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap; margin-bottom: 4px; }
.check-card details { margin-top: 8px; }
.check-card summary { cursor: pointer; font-weight: 600; }
.chk-line { display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; padding: 4px 0; border-bottom: 1px solid var(--border); font-size: 13px; }
.chk-line:last-child { border-bottom: 0; }
.chk-detail { color: var(--muted); font-size: 12.5px; flex-basis: 100%; }
button.link { border: 0; padding: 0; background: none; color: var(--accent); font-weight: 600; cursor: pointer; text-decoration: underline; }
.recap-table .rs.open { color: var(--warn); font-weight: 600; }
