/* ============================================================
   New Scholar Hub — black & white base, Old Gold (#CFB991) for
   structure, muted green (#3C6E4B) for actions/status.
   ============================================================ */

:root {
  --bg: #ffffff;
  --surface: #f6f5f2;
  --surface-2: #edebe5;
  --text: #171614;
  --muted: #6d6a63;
  --line: #e5e2db;
  --gold: #CFB991;
  --gold-soft: rgba(207, 185, 145, 0.16);
  --gold-deep: #8a7549;      /* readable gold for text on light */
  --green: #3C6E4B;
  --green-soft: rgba(60, 110, 75, 0.12);
  --green-text: #3C6E4B;
  --danger: #a13d3d;
  --danger-soft: rgba(161, 61, 61, 0.1);
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121211;
    --surface: #1c1b19;
    --surface-2: #262521;
    --text: #f0eee9;
    --muted: #9c978c;
    --line: #2e2c27;
    --gold-soft: rgba(207, 185, 145, 0.14);
    --gold-deep: #cfb991;
    --green: #3f7350;
    --green-soft: rgba(127, 182, 148, 0.15);
    --green-text: #85bb99;
    --danger: #cd7676;
    --danger-soft: rgba(205, 118, 118, 0.12);
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  --bg: #121211;
  --surface: #1c1b19;
  --surface-2: #262521;
  --text: #f0eee9;
  --muted: #9c978c;
  --line: #2e2c27;
  --gold-soft: rgba(207, 185, 145, 0.14);
  --gold-deep: #cfb991;
  --green: #3f7350;
  --green-soft: rgba(127, 182, 148, 0.15);
  --green-text: #85bb99;
  --danger: #cd7676;
  --danger-soft: rgba(205, 118, 118, 0.12);
  --shadow: none;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  min-height: 100dvh;
}
img { max-width: 100%; }
a { color: inherit; }
button { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
p { margin: 0.4em 0; }

/* ---------- Top bar ---------- */
#topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  background: var(--bg);
  border-bottom: 2px solid var(--gold);
}
.tb-inner {
  max-width: 960px;
  margin: 0 auto;
  padding: 10px 16px;
  display: flex;
  align-items: center;
  gap: 16px;
}
.brand { text-decoration: none; display: flex; flex-direction: column; line-height: 1.15; }
.brand-eyebrow {
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--gold-deep);
}
.brand-name {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.05rem;
  font-weight: 700;
}
.tb-nav { display: none; gap: 4px; margin-left: 8px; }
.tb-nav a {
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--muted);
  padding: 6px 10px;
  border-radius: 8px;
}
.tb-nav a:hover { background: var(--surface); color: var(--text); }
.tb-nav a.active { color: var(--green-text); background: var(--green-soft); }
.tb-actions { margin-left: auto; display: flex; gap: 4px; }
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border-radius: 10px;
  border: none;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  text-decoration: none;
}
.icon-btn:hover { background: var(--surface); color: var(--text); }
.icon-btn.active { color: var(--green-text); background: var(--green-soft); }
.icon-btn svg { width: 21px; height: 21px; }

/* ---------- Layout ---------- */
#main {
  max-width: 640px;
  margin: 0 auto;
  padding: 16px 16px calc(88px + env(safe-area-inset-bottom));
  width: 100%;
}
.page-title {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.45rem;
  margin: 6px 0 14px;
}
.section-title {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 1rem;
  font-weight: 700;
  margin: 22px 0 10px;
}
.section-title::before {
  content: "";
  width: 4px;
  height: 16px;
  border-radius: 2px;
  background: var(--gold);
}
.section-title .count { color: var(--muted); font-weight: 500; font-size: 0.9rem; }

/* ---------- Bottom tab bar (mobile) ---------- */
#tabbar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 40;
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  background: var(--bg);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
#tabbar a {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 8px 0 7px;
  text-decoration: none;
  color: var(--muted);
  font-size: 0.64rem;
  font-weight: 600;
}
#tabbar a svg { width: 21px; height: 21px; }
/* Six tabs at 375px leaves ~62px each — keep labels from wrapping. */
@media (max-width: 400px) {
  #tabbar a { font-size: 0.6rem; }
  #tabbar a svg { width: 20px; height: 20px; }
}
#tabbar a.active { color: var(--green-text); }

@media (min-width: 768px) {
  .tb-nav { display: flex; }
  #tabbar { display: none; }
  #main { padding-bottom: 40px; }
}

/* ---------- Cards, lists, badges ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px 16px;
  box-shadow: var(--shadow);
}
.card + .card { margin-top: 10px; }
.stack > * + * { margin-top: 10px; }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 2px 9px;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--muted);
  white-space: nowrap;
}
.badge-gold { background: var(--gold-soft); border-color: transparent; color: var(--gold-deep); }
.badge-green { background: var(--green-soft); border-color: transparent; color: var(--green-text); }
.badge-danger { background: var(--danger-soft); border-color: transparent; color: var(--danger); }

.progress {
  height: 6px;
  border-radius: 3px;
  background: var(--line);
  overflow: hidden;
}
.progress i { display: block; height: 100%; background: var(--green); border-radius: 3px; }

.empty { color: var(--muted); text-align: center; padding: 26px 8px; font-size: 0.95rem; }
.hint { color: var(--muted); font-size: 0.82rem; }
.muted { color: var(--muted); }

/* ---------- Buttons & forms ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border-radius: 10px;
  padding: 9px 15px;
  font-weight: 600;
  font-size: 0.92rem;
  border: 1px solid transparent;
  cursor: pointer;
  background: transparent;
  text-decoration: none;
}
.btn svg { width: 17px; height: 17px; }
.btn-primary { background: var(--green); color: #fff; }
.btn-primary:hover { filter: brightness(1.1); }
.btn-primary:disabled { opacity: 0.55; cursor: default; filter: none; }
.btn-ghost { border-color: var(--line); background: var(--bg); }
.btn-ghost:hover { background: var(--surface); }
.btn-danger { color: var(--danger); }
.btn-danger:hover { background: var(--danger-soft); }
.btn-sm { padding: 6px 11px; font-size: 0.84rem; border-radius: 8px; }
.btn-block { width: 100%; }

.field { margin-bottom: 12px; }
.field label {
  display: block;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 5px;
}
input[type="text"], input[type="password"], input[type="email"],
input[type="datetime-local"], textarea, select {
  width: 100%;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  font: inherit;
}
textarea { resize: vertical; min-height: 70px; }
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--green);
  box-shadow: 0 0 0 3px var(--green-soft);
}
.form-error { color: var(--danger); font-size: 0.88rem; margin-top: 8px; min-height: 1.2em; }
.radio-row { display: flex; gap: 16px; align-items: center; font-size: 0.92rem; }
.radio-row label { display: flex; gap: 6px; align-items: center; cursor: pointer; }
.check-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}
.check-list label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 12px;
  font-size: 0.88rem;
  cursor: pointer;
  background: var(--bg);
}
.check-list label:has(input:checked) {
  border-color: var(--green);
  background: var(--green-soft);
  color: var(--green-text);
}
.check-list input { accent-color: var(--green); }

/* ---------- To-dos ---------- */
.todo-row { display: flex; gap: 12px; align-items: flex-start; }
.todo-row.done .todo-title { text-decoration: line-through; color: var(--muted); }
.checkbox {
  flex: none;
  width: 26px;
  height: 26px;
  margin-top: 1px;
  border-radius: 9px;
  border: 2px solid var(--muted);
  background: transparent;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: transparent;
  padding: 0;
}
.checkbox svg { width: 15px; height: 15px; }
.checkbox.done { background: var(--green); border-color: var(--green); color: #fff; }
.todo-main { min-width: 0; flex: 1; }
.todo-title { font-weight: 600; overflow-wrap: anywhere; }
.todo-desc { font-size: 0.88rem; color: var(--muted); margin: 2px 0 4px; white-space: pre-wrap; overflow-wrap: anywhere; }
.todo-row .badge { margin-top: 4px; }

.task-head { display: flex; align-items: flex-start; gap: 10px; }
.task-head .todo-main { flex: 1; }
.roster { list-style: none; margin: 10px 0 0; padding: 0; font-size: 0.9rem; }
.roster li { display: flex; align-items: center; gap: 8px; padding: 3px 0; }
.roster .tick { color: var(--green-text); display: inline-flex; }
.roster .tick svg { width: 15px; height: 15px; }
.roster .pending-name { color: var(--muted); }
details.roster-details summary {
  cursor: pointer;
  font-size: 0.85rem;
  color: var(--muted);
  margin-top: 8px;
  user-select: none;
}

/* ---------- Calendar ---------- */
.cal-header { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.cal-header h2 { font-family: Georgia, serif; font-size: 1.15rem; flex: 1; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; }
.cal-dow { text-align: center; font-size: 0.66rem; font-weight: 700; letter-spacing: 0.06em; color: var(--muted); padding: 4px 0; }
.cal-day {
  aspect-ratio: 1 / 0.9;
  border: none;
  background: transparent;
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  font-size: 0.88rem;
  cursor: default;
  padding: 0;
}
.cal-day.clickable { cursor: pointer; }
.cal-day.clickable:hover { background: var(--surface); }
.cal-day.other { color: var(--muted); opacity: 0.45; }
.cal-day.today { border: 1.5px solid var(--gold); font-weight: 700; }
.cal-day .dots { display: flex; gap: 3px; height: 4px; }
.cal-day .dots i { width: 4px; height: 4px; border-radius: 50%; background: var(--gold-deep); }
.cal-day.selected { background: var(--green-soft); color: var(--green-text); font-weight: 700; }

.event-card { display: flex; gap: 12px; }
.event-date {
  flex: none;
  width: 48px;
  text-align: center;
  border-right: 2px solid var(--gold);
  padding-right: 10px;
}
.event-date .m { font-size: 0.64rem; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase; color: var(--gold-deep); }
.event-date .d { font-size: 1.3rem; font-weight: 700; font-family: Georgia, serif; line-height: 1.1; }
.event-main { flex: 1; min-width: 0; }
.event-title { font-weight: 700; overflow-wrap: anywhere; }
.event-meta { font-size: 0.85rem; color: var(--muted); }
.event-desc { font-size: 0.88rem; margin-top: 4px; white-space: pre-wrap; overflow-wrap: anywhere; }

/* ---------- Class board (threads + replies) ---------- */
.thread { padding: 12px 14px 10px; }
.thread-head {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 6px;
}
.thread-head .spacer { flex: 1; }
.thread-author { font-weight: 700; font-size: 0.92rem; }
.thread-head .icon-btn { width: 30px; height: 30px; }
.thread-head .icon-btn svg { width: 16px; height: 16px; }
.thread-body {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-size: 0.97rem;
}
.thread-foot { margin-top: 10px; }
.thread-foot .btn svg { width: 15px; height: 15px; }

/* The replies live in their own inset section, hung off the gold rule. */
.replies {
  margin: 12px 0 2px 4px;
  padding-left: 12px;
  border-left: 2px solid var(--gold);
}
.reply { padding: 7px 0; }
.reply + .reply { border-top: 1px solid var(--line); }
.reply-head { display: flex; align-items: center; gap: 8px; }
.reply-author { font-weight: 600; font-size: 0.85rem; color: var(--gold-deep); }
.reply-head .icon-btn {
  width: 24px;
  height: 24px;
  margin-left: auto;
  opacity: 0.6;
}
.reply-head .icon-btn svg { width: 13px; height: 13px; }
.reply-body {
  font-size: 0.92rem;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  margin-top: 1px;
}
.reply-list:not(:empty) { margin-bottom: 8px; }
.reply-form { display: flex; gap: 8px; align-items: flex-end; }
.reply-form textarea {
  flex: 1;
  min-height: 38px;
  max-height: 120px;
  border-radius: 19px;
  padding: 8px 14px;
  font-size: 0.92rem;
}
.reply-form .btn { border-radius: 19px; height: 38px; flex: none; }

/* ---------- Photo wall ---------- */
.post { padding: 0; overflow: hidden; }
.post-top { display: flex; align-items: center; gap: 8px; padding: 10px 14px; }
.post-author { font-weight: 700; font-size: 0.9rem; }
.post-time { color: var(--muted); font-size: 0.78rem; }
.post-top .spacer { flex: 1; }
.post img.photo { width: 100%; display: block; background: var(--surface-2); }
.post-body { padding: 10px 14px 12px; }
.post-caption { font-size: 0.93rem; margin-bottom: 8px; overflow-wrap: anywhere; }
.reactions { display: flex; gap: 6px; flex-wrap: wrap; }
.react {
  border: 1px solid var(--line);
  background: var(--bg);
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 0.85rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}
.react .n { font-size: 0.76rem; font-weight: 700; color: var(--muted); }
.react.mine { background: var(--green-soft); border-color: var(--green); }
.react.mine .n { color: var(--green-text); }
#photoPreview { width: 100%; border-radius: 10px; display: block; margin-bottom: 10px; }

/* ---------- Admin / account ---------- */
.person { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.person-main { flex: 1; min-width: 140px; }
.person-name { font-weight: 700; }
.person-sub { font-size: 0.82rem; color: var(--muted); overflow-wrap: anywhere; }
.person-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.person.inactive .person-name { color: var(--muted); text-decoration: line-through; }

dialog {
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--bg);
  color: var(--text);
  padding: 20px;
  max-width: 420px;
  width: calc(100vw - 48px);
}
dialog::backdrop { background: rgba(0, 0, 0, 0.45); }
.cred-box {
  background: var(--surface);
  border: 1px dashed var(--gold);
  border-radius: 10px;
  padding: 12px 14px;
  font-family: ui-monospace, Menlo, monospace;
  font-size: 0.95rem;
  margin: 12px 0;
  overflow-wrap: anywhere;
}

/* ---------- Login / setup ---------- */
body.page-auth {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.auth-card { width: 100%; max-width: 380px; }
.auth-brand { text-align: center; margin-bottom: 22px; }
.auth-brand .brand-eyebrow { display: block; margin-bottom: 2px; }
.auth-brand .brand-name { font-size: 1.6rem; display: block; }
.auth-brand::after {
  content: "";
  display: block;
  width: 56px;
  height: 3px;
  background: var(--gold);
  margin: 12px auto 0;
  border-radius: 2px;
}

/* ---------- Toast ---------- */
#toast {
  position: fixed;
  bottom: calc(78px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%) translateY(8px);
  background: var(--text);
  color: var(--bg);
  padding: 10px 18px;
  border-radius: 10px;
  font-size: 0.9rem;
  font-weight: 600;
  opacity: 0;
  transition: opacity 0.2s, transform 0.2s;
  pointer-events: none;
  z-index: 90;
  max-width: calc(100vw - 40px);
  text-align: center;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.row { display: flex; gap: 8px; align-items: center; }
.row .grow { flex: 1; }
.mt { margin-top: 14px; }
