/* ERD Practice Tutor: small hand-written stylesheet. Mobile first; works at 360 px. */

:root {
  color-scheme: light dark;  /* native controls (date pickers, scrollbars) follow the theme */
  --bg: #f7f7f5;
  --surface: #ffffff;
  --text: #1d1d1f;
  --muted: #555b61;
  --border: #d4d6d9;
  --accent: #0b4f8a;        /* links, primary buttons */
  --accent-hover: #083c69;
  --focus: #f5b301;
  --error-bg: #fdecec;  --error-text: #8a1c1c;  --error-border: #e8b4b4;
  --ok-bg: #eaf6ec;     --ok-text: #1d5b2a;     --ok-border: #b5dbbd;
  --info-bg: #eef4fb;   --info-text: #1c3d5e;   --info-border: #bcd3ea;
  --radius: 8px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16181b;
    --surface: #1f2226;
    --text: #ececec;
    --muted: #a9b0b8;
    --border: #3a3f45;
    --accent: #7db7ec;
    --accent-hover: #a8cff3;
    --error-bg: #3a1f1f;  --error-text: #f3b9b9;  --error-border: #6b3434;
    --ok-bg: #1d3323;     --ok-text: #b6e2c0;     --ok-border: #355c40;
    --info-bg: #1c2a38;   --info-text: #c4dcf3;   --info-border: #34506b;
  }
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 1.0625rem;
  line-height: 1.55;
}

a { color: var(--accent); }
a:hover { color: var(--accent-hover); }

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.skip-link {
  position: absolute;
  left: -999px;
  top: 0;
  background: var(--surface);
  padding: .5rem 1rem;
  z-index: 10;
}
.skip-link:focus { left: .5rem; }

/* Header ----------------------------------------------------------------- */
.site-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.site-header__inner {
  max-width: 60rem;
  margin: 0 auto;
  padding: .6rem 1rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: .5rem 1rem;
}
.brand {
  font-weight: 700;
  color: var(--text);
  text-decoration: none;
}
.site-nav a[aria-current="page"] { font-weight: 700; text-decoration: none; }
.site-nav {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .25rem 1rem;
}

/* Layout ----------------------------------------------------------------- */
.container {
  max-width: 48rem;
  margin: 0 auto;
  padding: 1.25rem 1rem 3rem;
}
.container.narrow { max-width: 30rem; }
.container.wide { max-width: 72rem; }

h1 { font-size: 1.6rem; line-height: 1.25; margin: .5rem 0 1rem; }
h2 { font-size: 1.2rem; margin: 1.75rem 0 .5rem; }

.help { color: var(--muted); font-size: .95rem; margin: .1rem 0 .4rem; }
.breadcrumb { color: var(--muted); font-size: .95rem; margin: 0; }

/* Forms ------------------------------------------------------------------ */
.stack { display: flex; flex-direction: column; gap: .35rem; margin: 0 0 1rem; }
.stack label { font-weight: 600; margin-top: .5rem; }
.stack .button { margin-top: 1rem; align-self: flex-start; }

input[type="email"], input[type="password"], input[type="text"], input[type="number"], input[type="date"],
input[type="file"], textarea, select {
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .6rem .7rem;
  width: 100%;
  min-height: 44px;
}
textarea { resize: vertical; }

.button, .small-button, .link-button {
  font: inherit;
  cursor: pointer;
}
.button {
  display: inline-block;
  background: var(--accent);
  color: #fff;
  border: 0;
  border-radius: var(--radius);
  padding: .65rem 1.2rem;
  min-height: 44px;
  font-weight: 600;
  text-decoration: none;
}
.button:hover { background: var(--accent-hover); color: #fff; }
@media (prefers-color-scheme: dark) {
  .button, .button:hover { color: #0d1117; }
}

.small-button {
  background: var(--surface);
  color: var(--accent);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .3rem .7rem;
  min-height: 36px;
  font-size: .95rem;
}
.small-button--danger { color: var(--error-text); }

.link-button {
  background: none;
  border: 0;
  padding: 0;
  color: var(--accent);
  text-decoration: underline;
}

.inline-form { display: inline; margin: 0; }

/* Messages --------------------------------------------------------------- */
.alert {
  border: 1px solid;
  border-radius: var(--radius);
  padding: .7rem .9rem;
  margin: 0 0 1rem;
}
.alert p { margin: .2rem 0; }
.alert h2 { margin-top: 0; font-size: 1.05rem; }
.alert--error { background: var(--error-bg); color: var(--error-text); border-color: var(--error-border); }
.alert--ok    { background: var(--ok-bg);    color: var(--ok-text);    border-color: var(--ok-border); }
.alert--info  { background: var(--info-bg);  color: var(--info-text);  border-color: var(--info-border); }

.notice-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  border-radius: var(--radius);
  padding: .4rem 1rem;
  margin: 1.5rem 0;
}
.notice-box h2 { font-size: 1rem; margin: .5rem 0 0; }

.facts { display: grid; grid-template-columns: max-content 1fr; gap: .25rem 1rem; }
.facts dt { font-weight: 600; }
.facts dd { margin: 0; overflow-wrap: anywhere; }

.link-list { padding-left: 1.2rem; }
.link-list li { margin: .4rem 0; }

/* Tables ----------------------------------------------------------------- */
.table-wrap { overflow-x: auto; margin: .75rem 0; }
table { border-collapse: collapse; width: 100%; background: var(--surface); font-size: .95rem; }
th, td { text-align: left; padding: .5rem .6rem; border-bottom: 1px solid var(--border); vertical-align: top; }
th { white-space: nowrap; }
td.actions { white-space: nowrap; }
td.actions .inline-form + .inline-form { margin-left: .3rem; }

.badge {
  display: inline-block;
  border-radius: 999px;
  padding: 0 .55rem;
  font-size: .85rem;
  border: 1px solid var(--border);
}
.badge--active   { background: var(--ok-bg);    color: var(--ok-text); }
.badge--invited  { background: var(--info-bg);  color: var(--info-text); }
.badge--disabled { background: var(--error-bg); color: var(--error-text); }

code { font-size: .92em; overflow-wrap: anywhere; }

/* Utilities --------------------------------------------------------------- */
.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0);
  white-space: nowrap; border: 0;
}

.secondary-button {
  display: inline-block;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  background: var(--surface);
  color: var(--accent);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  padding: .55rem 1.1rem;
  min-height: 44px;
}
.secondary-button:hover { color: var(--accent-hover); border-color: var(--accent-hover); }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .4rem 1rem 1rem;
  margin: 0 0 1rem;
}
.card--accent { border-left: 4px solid var(--accent); }
.card h2 { margin-top: .6rem; }

/* Home: slot checklist and results ---------------------------------------- */
.slot-list { border: 0; padding: 0; margin: 0 0 1rem; display: grid; gap: .25rem; }
@media (min-width: 640px) { .slot-list { grid-template-columns: 1fr 1fr; column-gap: 1rem; } }
.slot-option {
  display: flex; align-items: flex-start; gap: .5rem;
  padding: .35rem .25rem; border-radius: 6px; cursor: pointer;
}
.slot-option:hover { background: var(--bg); }
.slot-option input { margin-top: .35rem; width: 1.1rem; height: 1.1rem; flex: none; }
.slot-option__num { font-weight: 700; min-width: 1.6rem; text-align: right; }

.result { white-space: nowrap; }
.result--correct_first_try { color: var(--ok-text); font-weight: 600; }
.result--correct_after_hints { color: var(--ok-text); }
.result--revealed { color: var(--error-text); }
.result--abandoned, .result--none { color: var(--muted); }
.summary-counts { font-size: 1.05rem; }
.seen { display: block; color: var(--muted); font-size: .85rem; }

/* The question ------------------------------------------------------------ */
.q-meta { color: var(--muted); font-size: .95rem; margin: 0 0 .5rem; }

.stem { margin-bottom: 1rem; }
.stem p { margin: 0 0 .75rem; }
.stem img, .choice img {
  display: block;
  max-width: 100%;
  height: auto;
  background: #fff;            /* diagrams are drawn on white */
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px;
}
.diagram-link { display: inline-block; max-width: 100%; }
.stem select { margin: .15rem 0; width: auto; min-width: 9rem; max-width: 100%; display: inline-block; }

.choices { border: 0; padding: 0; margin: 0 0 1rem; display: grid; gap: .6rem; }
.choice {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .6rem .75rem;
}
.choice--correct { border: 2px solid var(--ok-border); background: var(--ok-bg); }
.choice--wrong { border: 2px solid var(--error-border); }
.choice__label { display: grid; grid-template-columns: auto auto 1fr; gap: .5rem; align-items: start; cursor: pointer; }
.choice__label input { margin-top: .3rem; width: 1.15rem; height: 1.15rem; }
.choice__letter { font-weight: 700; }
.choice__body p { margin: 0 0 .4rem; }
.choice__body p:last-child { margin-bottom: 0; }
.enlarge { display: inline-block; font-size: .9rem; margin-top: .35rem; }

.matching { display: grid; gap: .5rem; margin: 0 0 1rem; }
.matching__row {
  display: grid; gap: .35rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .55rem .75rem;
}
@media (min-width: 640px) { .matching__row { grid-template-columns: 1fr 14rem auto; align-items: center; } }
.matching__row--ok { border-color: var(--ok-border); }
.matching__row--wrong { border-color: var(--error-border); }
.matching__prompt { font-weight: 600; overflow-wrap: anywhere; }

.numeric { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem 1rem; margin: 0 0 1rem; }
.numeric label { font-weight: 600; width: 100%; }
.numeric input { max-width: 10rem; }

.mark { display: inline-block; font-size: .9rem; font-weight: 600; margin-left: .35rem; }
.mark--ok { color: var(--ok-text); }
.mark--key { color: var(--error-text); }

.actions { display: flex; flex-wrap: wrap; gap: .6rem; align-items: center; margin: .5rem 0 1rem; }
.actions form { margin: 0; }
.actions--nav { justify-content: flex-end; border-top: 1px solid var(--border); padding-top: 1rem; }

.confirm summary { list-style: none; }
.confirm summary::-webkit-details-marker { display: none; }
.confirm[open] summary { border-bottom-left-radius: 0; border-bottom-right-radius: 0; }
.confirm__body {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0 var(--radius) var(--radius) var(--radius);
  padding: .6rem .9rem .9rem;
  max-width: 28rem;
}
.confirm__body p { margin: 0 0 .6rem; }

/* Conversation ------------------------------------------------------------ */
.chat { margin: 1rem 0; }
.chat__log { display: flex; flex-direction: column; gap: .5rem; margin-bottom: .75rem; }
.msg { border-radius: var(--radius); padding: .5rem .8rem; max-width: 46rem; }
.msg p { margin: 0; white-space: pre-line; }
.msg__who { display: block; font-size: .8rem; font-weight: 700; color: var(--muted); margin-bottom: .1rem; }
.msg--tutor { background: var(--info-bg); color: var(--info-text); border: 1px solid var(--info-border); }
.msg--student { background: var(--surface); border: 1px solid var(--border); align-self: flex-end; }
.msg--event { color: var(--muted); font-size: .85rem; font-style: italic; padding: 0 .2rem; }
.chat__form { display: grid; grid-template-columns: 1fr auto; gap: .5rem; align-items: end; }
.chat__form textarea { min-height: 44px; }

/* Feedback once the answer is known (P8.10) ---------------------------------- */
.feedback { border-top: 1px solid var(--border); padding-top: .75rem; margin: 1rem 0 .5rem; }
.feedback__title { font-size: 1rem; margin: 0 0 .4rem; }
.feedback form { margin: 0; }
.feedback__row { display: flex; flex-wrap: wrap; align-items: center; gap: .3rem .75rem; margin: .35rem 0; }
.feedback__label { flex: 1 1 14rem; }
.feedback__label .note { display: block; }
.feedback__buttons { display: flex; flex-wrap: wrap; gap: .35rem; }
.rate-button {
  font: inherit;
  cursor: pointer;
  min-width: 44px;
  min-height: 44px;
  padding: .3rem .6rem;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.rate-button:hover { border-color: var(--accent); }
.rate-button.is-chosen { background: var(--accent); color: #fff; border-color: var(--accent); font-weight: 700; }
@media (prefers-color-scheme: dark) {
  .rate-button.is-chosen { color: #0d1117; }
}
.feedback__saved { color: var(--ok-text); font-size: .9rem; margin: .4rem 0 0; }

/* A request that failed (app.js, P8.11) ------------------------------------ */
.request-problem {
  position: fixed;
  left: 1rem;
  right: 1rem;
  bottom: 1rem;
  z-index: 10;
  max-width: 40rem;
  margin: 0 auto;
  box-shadow: 0 4px 16px rgba(0, 0, 0, .25);
}

/* Tutor is thinking ------------------------------------------------------- */
.msg--pending { opacity: .85; font-style: italic; }
button:disabled, textarea:disabled { opacity: .55; cursor: not-allowed; }

/* Instructor pages ------------------------------------------------------- */
.admin-nav { display: flex; flex-wrap: wrap; gap: .25rem .9rem; padding: .5rem 0 .75rem; margin-bottom: .5rem; border-bottom: 1px solid var(--border); font-size: .95rem; }
.admin-nav a[aria-current="page"] { font-weight: 700; text-decoration: none; color: var(--text); }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(13rem, 1fr)); gap: .75rem; margin: .5rem 0 1.25rem; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .75rem .9rem; display: flex; flex-direction: column; gap: .2rem; }
.stat--alert { border-color: var(--error-border); }
.stat__value { font-size: 1.6rem; font-weight: 700; line-height: 1.2; }
.stat__label { color: var(--muted); font-size: .9rem; }
.filters { display: flex; flex-wrap: wrap; gap: .5rem .9rem; align-items: flex-end; margin: .5rem 0 1rem; }
.filters label { display: flex; flex-direction: column; font-size: .85rem; font-weight: 600; gap: .2rem; }
.filters input, .filters select { width: auto; min-width: 8rem; min-height: 38px; padding: .35rem .5rem; }
th a { color: inherit; }
td.num, th.num { text-align: right; white-space: nowrap; }
.note { color: var(--muted); font-size: .85rem; }
.hidden-notes { background: var(--surface); border: 1px dashed var(--border); border-radius: var(--radius); padding: .5rem 1rem; margin: 1rem 0; }
.hidden-notes dt { font-weight: 700; margin-top: .6rem; }
.hidden-notes dd { margin: .1rem 0 0; }
.hidden-notes dd.pre { white-space: pre-wrap; }
.hidden-notes li { margin-bottom: .4rem; }
pre.request { white-space: pre-wrap; word-break: break-word; background: var(--bg); border: 1px solid var(--border); border-radius: 6px; padding: .6rem; font-size: .8rem; max-height: 28rem; overflow: auto; }
.msg details { margin-top: .4rem; font-size: .85rem; }
.toggle-row { display: flex; flex-wrap: wrap; gap: .6rem; align-items: center; margin: .5rem 0 1rem; }
.badge--on { background: var(--ok-bg); color: var(--ok-text); }
.badge--off { background: var(--error-bg); color: var(--error-text); }
.editor textarea { min-height: 5rem; }
.pager { display: flex; gap: 1rem; margin: 1rem 0; }
.button--danger { background: var(--error-text); }
.button--danger:hover { background: var(--error-text); filter: brightness(1.1); }
.export-kind { min-width: 7rem; align-self: center; }
.preview { border: 0; padding: 0; margin: 0; }
