/* iStream Tutor — mobile-first; system fonts so it loads fast on mobile data */
:root {
  --brand: #1D7874; --brand-ink: #135753; --brand-soft: #E3F0EF;
  --ink: #1F2933; --muted: #5B6670; --line: #DCE3E2;
  --bg: #F6F4EF; --surface: #FFFFFF; --me: #1D7874; --me-ink: #FFFFFF;
  --tip: #FFF4DB; --tip-ink: #6B4A00; --warn: #B42318; --warn-soft: #FDECEA; --ok: #12715B; --ok-soft: #E3F4EE;
  --radius: 16px; --on-brand: #FFFFFF;
  --serif: Georgia, "Iowan Old Style", "Noto Serif", serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --brand: #4FB3AC; --brand-ink: #7FCFC9; --brand-soft: #173533;
    --ink: #E7ECEB; --muted: #9AA7A6; --line: #2C3837;
    --bg: #111817; --surface: #1A2322; --me: #2A7F79; --me-ink: #FFFFFF;
    --on-brand: #0E1F1E; --tip: #33290F; --tip-ink: #F2D79A; --warn: #F49A8F; --warn-soft: #3A1E1B; --ok: #7FD6BD; --ok-soft: #173A31;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.55 var(--sans); }
a { color: var(--brand-ink); }
button, textarea, input, select { font: inherit; color: inherit; }

.app { max-width: 760px; margin: 0 auto; min-height: 100dvh; display: flex; flex-direction: column; }

/* header */
.bar { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between;
  gap: 10px; padding: 12px 16px; background: var(--bg); border-bottom: 1px solid var(--line); }
.home-btn { flex: none; display: inline-flex; align-items: center; gap: 4px; min-height: 40px; padding: 0 12px 0 8px;
  border: 1px solid var(--line); border-radius: 999px; background: var(--surface); color: var(--ink); text-decoration: none;
  font-size: 14px; font-weight: 600; }
.home-btn span { font-size: 22px; line-height: 1; color: var(--brand); margin-top: -2px; }
.brand { margin-right: auto; display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink); }
.mark { width: 28px; height: 28px; border-radius: 50%; flex: none;
  background: radial-gradient(circle at 50% 50%, var(--bg) 0 22%, var(--brand) 23% 62%, var(--brand-soft) 63% 100%);
  box-shadow: inset 0 0 0 2px var(--brand); }
.brand-text { white-space: nowrap; font-family: var(--serif); font-size: 19px; letter-spacing: .2px; }
.brand-text b { color: var(--brand); letter-spacing: .6px; }
.quota { font-size: 13px; color: var(--muted); background: var(--surface); border: 1px solid var(--line); padding: 4px 10px; border-radius: 999px; white-space: nowrap; }
.quota.low { color: var(--warn); border-color: currentColor; }

/* mode tabs */
.modes { position: sticky; top: 57px; z-index: 4; display: grid; grid-template-columns: repeat(5, 1fr); gap: 4px;
  padding: 8px 16px; background: var(--bg); }
.modes button { min-height: 44px; border: 1px solid var(--line); background: var(--surface); border-radius: 12px; cursor: pointer;
  font-size: 14px; font-weight: 600; color: var(--muted); white-space: nowrap; padding: 0 4px; }
.modes button[aria-selected="true"] { background: var(--brand); border-color: var(--brand); color: var(--on-brand); }

/* thread */
.thread { flex: 1; padding: 8px 16px 130px; display: flex; flex-direction: column; gap: 12px; }
.msg { max-width: 92%; padding: 12px 14px; border-radius: var(--radius); overflow-wrap: anywhere; }
.msg.me { align-self: flex-end; background: var(--me); color: var(--me-ink); border-bottom-right-radius: 6px; white-space: pre-wrap; }
.msg.tutor { align-self: flex-start; background: var(--surface); border: 1px solid var(--line); border-bottom-left-radius: 6px; max-width: 100%; }
.msg.tutor p { margin: 0 0 8px; } .msg.tutor p:last-child { margin-bottom: 0; }
.msg.tutor h4 { margin: 14px 0 6px; font-family: var(--serif); font-size: 17px; color: var(--brand-ink); }
.msg.tutor h4:first-child { margin-top: 0; }
.msg.tutor ul, .msg.tutor ol { margin: 4px 0 10px; padding-left: 22px; }
.msg.tutor li { margin: 3px 0; }
.msg.tutor hr { border: 0; border-top: 1px solid var(--line); margin: 12px 0; }
.msg.tutor code { background: var(--brand-soft); padding: 1px 5px; border-radius: 4px; font-size: .92em; }
.msg .tip { background: var(--tip); color: var(--tip-ink); padding: 8px 10px; border-radius: 10px; margin-top: 10px; }
.cite { display: inline-block; min-width: 18px; padding: 0 4px; margin-left: 1px; border-radius: 6px; background: var(--brand-soft);
  color: var(--brand-ink); font-size: 11px; font-weight: 700; text-align: center; line-height: 16px; vertical-align: super; }
.verify { font-size: 11px; font-weight: 700; color: var(--warn); border: 1px solid currentColor; border-radius: 6px; padding: 0 4px; }
.tbl { overflow-x: auto; margin: 8px 0; }
.tbl table { border-collapse: collapse; font-size: 14px; min-width: 100%; }
.tbl th, .tbl td { border: 1px solid var(--line); padding: 6px 8px; text-align: left; vertical-align: top; }
.tbl th { background: var(--brand-soft); }
.sources { margin-top: 12px; padding-top: 10px; border-top: 1px dashed var(--line); display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.src-h { font-size: 12px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); margin-right: 2px; }
.src { font-size: 13px; padding: 4px 9px; border-radius: 999px; background: var(--brand-soft); color: var(--brand-ink); text-decoration: none; max-width: 100%;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.src b { margin-right: 3px; }
.msg.error { align-self: stretch; background: var(--warn-soft); color: var(--warn); border-radius: 12px; }
.typing { color: var(--muted); display: flex; align-items: center; gap: 4px; }
.typing span { margin-right: 4px; }
.typing i { width: 6px; height: 6px; border-radius: 50%; background: var(--brand); animation: blink 1.2s infinite ease-in-out; }
.typing i:nth-child(3) { animation-delay: .2s; } .typing i:nth-child(4) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-3px); } }

.empty { padding: 20px 4px; color: var(--muted); }
.empty .hello { font-family: var(--serif); font-size: 24px; color: var(--ink); margin: 6px 0; }
.chips { display: flex; flex-direction: column; gap: 8px; margin-top: 16px; }
.chip { min-height: 44px; text-align: left; padding: 10px 14px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface); cursor: pointer; color: var(--ink); }
.chip:hover { border-color: var(--brand); }
.lock { color: var(--ink); font-weight: 600; }

@media (max-width: 440px) {
  .brand-text b { display: none; }
  .brand { gap: 8px; }
}
/* quick replies */
.quick { display: flex; flex-wrap: wrap; gap: 8px; margin: -2px 0 6px; }
.qbtn { min-height: 40px; padding: 0 14px; border-radius: 999px; border: 1px solid var(--brand); background: var(--surface);
  color: var(--brand-ink); font-size: 14px; font-weight: 600; cursor: pointer; }
.qbtn:hover { background: var(--brand-soft); }
.qbtn.opt { min-width: 48px; background: var(--brand); color: var(--on-brand); }
.msg.tutor { scroll-margin-top: 130px; }

/* composer */
.dock { position: fixed; left: 0; right: 0; bottom: 0; z-index: 6; max-width: 760px; margin: 0 auto;
  padding: 10px 16px calc(6px + env(safe-area-inset-bottom)); background: var(--bg); border-top: 1px solid var(--line); }
.composer { display: flex; align-items: flex-end; gap: 8px; }
.composer textarea { flex: 1; resize: none; min-height: 44px; max-height: 160px; padding: 10px 14px; border-radius: 22px;
  border: 1px solid var(--line); background: var(--surface); outline: none; line-height: 1.4; }
.composer textarea::placeholder { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.composer textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.send, .icon-btn { flex: none; width: 44px; height: 44px; border-radius: 50%; border: 0; cursor: pointer; font-size: 18px; }
.send { background: var(--brand); color: var(--on-brand); }
.send:disabled { opacity: .45; cursor: default; }
.icon-btn { background: var(--surface); border: 1px solid var(--line); color: var(--muted); font-size: 20px; }
.foot { margin: 6px 0 0; text-align: center; font-size: 11px; line-height: 1.3; color: var(--muted); }

/* logged-out */
.gate { flex: 1; display: grid; place-items: center; padding: 24px 16px; }
.gate-card { background: var(--surface); border: 1px solid var(--line); border-radius: 20px; padding: 28px 22px; max-width: 460px; }
.gate-card h1 { font-family: var(--serif); font-weight: 500; margin: 0 0 8px; font-size: 28px; }
.gate-card p { color: var(--muted); }

.btn { display: inline-flex; align-items: center; justify-content: center; min-height: 44px; padding: 0 18px; border-radius: 12px;
  border: 1px solid var(--brand); background: var(--brand); color: #fff; font-weight: 600; text-decoration: none; cursor: pointer; }
.btn.sm { min-height: 36px; padding: 0 12px; font-size: 14px; }
.btn.ghost { background: transparent; color: var(--brand-ink); }
.btn.danger { color: var(--warn); border-color: var(--warn); }

/* ---------------- admin ---------------- */
.admin-wrap { max-width: 1000px; margin: 0 auto; padding: 16px; }
.admin-wrap.narrow { max-width: 480px; padding-top: 48px; }
.admin h1 { font-family: var(--serif); font-weight: 500; margin: 0; font-size: 26px; }
.admin h2 { font-family: var(--serif); font-weight: 500; font-size: 21px; margin: 0 0 10px; }
.admin h3 { font-size: 16px; margin: 18px 0 6px; }
.admin-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 16px; }
.admin-head nav { display: flex; gap: 8px; }
.inline { display: inline; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 18px; margin-bottom: 16px; }
.note { padding: 10px 14px; border-radius: 10px; margin: 0 0 12px; }
.note.ok { background: var(--ok-soft); color: var(--ok); } .note.warn { background: var(--warn-soft); color: var(--warn); }
.badge { display: inline-block; font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 999px; margin-left: 4px; }
.badge.ok { background: var(--ok-soft); color: var(--ok); } .badge.warn { background: var(--warn-soft); color: var(--warn); }
.checks { list-style: none; padding: 0; margin: 0; } .checks li { padding: 6px 0; border-bottom: 1px solid var(--line); }
.checks li:last-child { border: 0; }
.muted { color: var(--muted); } .small, small { font-size: 13px; }
.table-scroll { overflow-x: auto; }
.grid { width: 100%; border-collapse: collapse; font-size: 14px; margin-bottom: 12px; }
.grid th, .grid td { text-align: left; padding: 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.grid tr.off { opacity: .55; }
.grid .actions form { display: flex; gap: 6px; flex-wrap: wrap; }
details.src { border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; margin: 8px 0; }
details.src summary { cursor: pointer; }
.src-form { display: grid; gap: 10px; margin-top: 10px; }
.src-form label, .narrow label { display: grid; gap: 4px; font-size: 14px; color: var(--muted); }
.src-form input, .src-form select, .narrow input, .file-row input, .search-row input {
  min-height: 40px; padding: 6px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--ink); }
.src-form fieldset { border: 1px solid var(--line); border-radius: 8px; display: flex; flex-wrap: wrap; gap: 6px 16px; }
.src-form .chk { display: flex; flex-direction: row; align-items: center; gap: 6px; color: var(--ink); }
.narrow form { display: grid; gap: 12px; }
.file-row { display: grid; grid-template-columns: 1fr; gap: 6px; padding: 8px 0; border-bottom: 1px solid var(--line); }
@media (min-width: 700px) { .file-row { grid-template-columns: 1fr 240px auto; align-items: center; } }
.path { font-family: ui-monospace, Menlo, monospace; font-size: 13px; overflow-wrap: anywhere; }
.search-row { display: flex; gap: 8px; } .search-row input { flex: 1; }
.hits li { margin-bottom: 10px; } .hits p { margin: 4px 0 0; color: var(--muted); font-size: 14px; }
.recent { list-style: none; padding: 0; } .recent li { padding: 8px 0; border-bottom: 1px solid var(--line); }
