/* REFLEXIA: sober style (docs/maquettes). One accent color: the green of the logo. */

:root {
  --green: #1f6b2a;
  --green-dark: #16501f;
  --green-soft: #e8f1e9;
  --blue: #2b5b8a;
  --blue-soft: #e9f0f7;
  --text: #1c1c1a;
  --muted: #5c5a54;
  --border: #dcd8cd;
  --background: #f6f5f1;
  --surface: #ffffff;
  --error: #a3311f;
  --error-soft: #fdeceb;
  --warning-soft: #fff6df;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 16px;
  line-height: 1.5;
  color: var(--text);
  background: var(--background);
}

a { color: var(--green); }
a:hover { color: var(--green-dark); }

/* --- Header and footer ----------------------------------------------- */
.site-header {
  height: 64px;
  flex-shrink: 0;
  padding: 0 32px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 12px; text-decoration: none; }
.brand img { height: 46px; width: 35px; object-fit: contain; }
.brand span { font-size: 20px; font-weight: 700; letter-spacing: 0.08em; color: var(--green); }
.header-user { display: flex; align-items: center; gap: 16px; font-size: 14px; color: var(--muted); }
.header-user b { color: var(--text); }
.header-user form { margin: 0; }

.site-footer {
  height: 40px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  color: var(--muted);
  background: var(--surface);
  border-top: 1px solid var(--border);
}

main { flex-grow: 1; display: flex; justify-content: center; padding: 32px 24px; }
.page { width: 100%; max-width: 1000px; display: flex; flex-direction: column; gap: 20px; }
.page.narrow { max-width: 480px; }
h1 { margin: 0; font-size: 28px; }
.hint { font-size: 13px; color: var(--muted); }
.lead { margin: 0; font-size: 15px; color: var(--muted); }

/* --- Cards, forms and buttons --------------------------------------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 28px;
}
.stack { display: flex; flex-direction: column; gap: 16px; }
.field { display: flex; flex-direction: column; gap: 6px; }
label { font-size: 14px; font-weight: 600; }

input[type="text"], input[type="password"], input[type="number"], select, textarea {
  height: 44px;
  padding: 0 12px;
  border: 1px solid #b9b5aa;
  border-radius: 8px;
  font: inherit;
  font-size: 15px;
  background: var(--surface);
  color: var(--text);
}
input[readonly] { background: #f1efe9; color: var(--muted); }
input:focus, select:focus, textarea:focus, button:focus-visible, a:focus-visible {
  outline: 3px solid rgba(31, 107, 42, 0.35);
  outline-offset: 1px;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0 20px;
  border: 1px solid #c9dfcc;
  border-radius: 8px;
  background: #f3f8f3;  /* light green: no dark button in the application (D155) */
  color: var(--green-dark);
  font: inherit;
  font-size: 15px;
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
}
.button:hover { background: var(--green-soft); color: var(--green-dark); }
.button.secondary {
  min-height: 40px;
  padding: 0 16px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  font-weight: 500;
  font-size: 14px;
}
.button.secondary:hover { background: #f1efe9; }

/* --- Messages ---------------------------------------------------------- */
.message { padding: 10px 14px; border-radius: 8px; font-size: 14px; }
.message.error { background: var(--error-soft); border: 1px solid #efbcb6; color: #6b1f16; }
.message.info { background: var(--green-soft); border: 1px solid #b8d3bb; color: #173f1d; }
.message.placeholder { background: var(--warning-soft); border: 1px solid #e8d49a; color: #5a4a14; }

/* --- Login page ------------------------------------------------------- */
.login-layout { flex-grow: 1; display: flex; align-items: center; justify-content: center; gap: 48px; padding: 32px 24px; }
.login-layout img.illustration { width: 560px; max-width: 45vw; height: auto; border-radius: 16px; }
.login-layout .card { width: 400px; }

@media (max-width: 900px) {
  .login-layout { flex-direction: column; gap: 24px; }
  .login-layout img.illustration { max-width: 90vw; }
  .login-layout .card { width: 100%; max-width: 420px; }
  .site-header { padding: 0 16px; }
}

/* --- Forms generated from config/ (templates/macros/forms.html) -------- */
.form-page { max-width: 820px; }
.steps { list-style: none; margin: 0; padding: 0; display: flex; gap: 8px; flex-wrap: wrap; }
.steps li {
  padding: 6px 12px; border-radius: 999px; font-size: 13px; font-weight: 600;
  background: var(--surface); color: var(--muted); border: 1px solid var(--border);
}
.steps li.done { background: var(--green-soft); color: var(--green); border-color: var(--green); }
.steps li.current { background: var(--green); color: #ffffff; border-color: var(--green); }

fieldset.question {
  margin: 0; padding: 20px; display: flex; flex-direction: column; gap: 12px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
}
fieldset.question.has-error { border-color: var(--error); box-shadow: 0 0 0 1px var(--error); }
.question-meta { padding: 0 6px; font-size: 13px; color: var(--muted); }
.question-label { font-size: 16px; font-weight: 700; }
.question-text { font-size: 16px; font-weight: 600; }
.required { color: var(--error); }
.field-error { font-size: 14px; font-weight: 600; color: var(--error); }

.options { display: flex; gap: 8px; flex-wrap: wrap; }
.option {
  display: inline-flex; align-items: center; gap: 8px; min-height: 40px; padding: 0 12px;
  border: 1px solid var(--border); border-radius: 8px; background: var(--surface);
  font-size: 14px; font-weight: 400; cursor: pointer;
}
.option.muted { color: var(--muted); }
.other-field label { font-weight: 400; color: var(--muted); }

.likert { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.likert-label { font-size: 13px; color: var(--muted); max-width: 160px; }
.likert-values { display: flex; }
.likert-value {
  display: flex; flex-direction: column; align-items: center; gap: 4px; width: 52px;
  font-size: 14px; font-weight: 400; cursor: pointer;
}

.inline { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
input.number { width: 120px; }
textarea { height: auto; min-height: 96px; padding: 10px 12px; resize: vertical; }
fieldset.question input[type="text"] { width: 100%; }

.form-actions { display: flex; justify-content: space-between; align-items: center; gap: 16px; }

dl.answers { margin: 0; display: flex; flex-direction: column; gap: 6px; }
dl.answers dt { font-weight: 600; margin-top: 12px; }
dl.answers dt:first-child { margin-top: 0; }
dl.answers dd { margin: 0; color: var(--muted); white-space: pre-line; }

.button:disabled, .button:disabled:hover { background: #eef0ee; color: #9aa49b; border-color: #dcdfdc; cursor: not-allowed; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
h2 { margin: 0; font-size: 18px; }

/* --- Student home page --------------------------------------------------- */
.start-card { display: flex; align-items: center; justify-content: space-between; gap: 24px; padding: 22px 28px; }
.start-card form { margin: 0; }
.start-title { font-size: 17px; font-weight: 700; }
.section-title { display: flex; align-items: baseline; justify-content: space-between; gap: 16px; }
.table { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; overflow: hidden; font-size: 14px; }
.table th, .table td { padding: 10px 16px; text-align: left; border-bottom: 1px solid var(--border); }
.table th { font-size: 13px; color: var(--muted); font-weight: 600; background: #fbfaf7; }
.table tr:last-child td { border-bottom: 0; }
.badge { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--green-soft); color: var(--green); }

@media (max-width: 700px) {
  .start-card { flex-direction: column; align-items: stretch; }
}

/* --- Chat (templates/student/chat.html, static/js/chat.js) ------------- */
body:has(.chat-main) { height: 100vh; overflow: hidden; }
.chat-main { flex-grow: 1; display: flex; min-height: 0; padding: 0; }
.chat { flex-grow: 1; display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.chat-bar {
  flex-shrink: 0; min-height: 60px; padding: 8px 24px; display: flex; align-items: center;
  justify-content: space-between; gap: 16px; border-bottom: 1px solid var(--border); background: #fbfaf7;
}
.chat-info { font-size: 14px; color: var(--muted); }
.chat-notice { color: var(--text); }
.chat-alert { margin: 12px 24px 0; }
.chat-messages {
  flex-grow: 1; min-height: 0; overflow-y: auto; padding: 24px;
  display: flex; flex-direction: column; gap: 18px;
}
.chat-empty { margin: auto; }
.bubble-row { display: flex; flex-direction: column; gap: 4px; }
.bubble-row.mine { align-items: flex-end; }
.bubble-row.theirs { align-items: flex-start; }
.bubble { max-width: min(760px, 85%); padding: 12px 16px; font-size: 15px; line-height: 1.55; overflow-wrap: anywhere; }
.bubble-row.mine .bubble { background: var(--green-soft); border-radius: 14px 14px 4px 14px; white-space: pre-wrap; }
.bubble-row.theirs .bubble { background: var(--surface); border: 1px solid var(--border); border-radius: 14px 14px 14px 4px; }
.bubble-meta { font-size: 12px; color: var(--muted); }
.bubble-warning { color: var(--error); font-weight: 600; }

/* Markdown inside the answers */
.markdown > :first-child { margin-top: 0; }
.markdown > :last-child { margin-bottom: 0; }
.markdown p, .markdown ul, .markdown ol, .markdown pre, .markdown table, .markdown blockquote { margin: 0 0 10px; }
.markdown ul, .markdown ol { padding-left: 24px; }
.markdown h1, .markdown h2, .markdown h3, .markdown h4 { margin: 14px 0 8px; font-size: 16px; }
.markdown code { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 13px; background: #f1efe9; padding: 1px 4px; border-radius: 4px; }
.markdown pre { background: #f1efe9; padding: 10px 12px; border-radius: 8px; overflow-x: auto; }
.markdown pre code { background: none; padding: 0; }
.markdown table { border-collapse: collapse; font-size: 14px; }
.markdown th, .markdown td { border: 1px solid var(--border); padding: 4px 8px; }
.markdown blockquote { padding-left: 12px; border-left: 3px solid var(--border); color: var(--muted); }
.markdown .katex-display { overflow-x: auto; overflow-y: hidden; padding: 4px 0; }

.typing { display: inline-flex; gap: 4px; padding: 4px 0; }
.typing span { width: 7px; height: 7px; border-radius: 50%; background: var(--green); animation: typing 1.2s infinite ease-in-out; }
.typing span:nth-child(2) { animation-delay: 0.2s; }
.typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes typing { 0%, 80%, 100% { opacity: 0.25; } 40% { opacity: 1; } }

.chat-form { flex-shrink: 0; padding: 14px 24px; border-top: 1px solid var(--border); background: var(--surface); display: flex; flex-direction: column; gap: 6px; }
.chat-input-row { display: flex; gap: 12px; align-items: flex-end; }
.chat-input-row textarea { flex-grow: 1; min-height: 56px; max-height: 220px; resize: none; border-radius: 10px; }
.chat-form-meta { display: flex; justify-content: space-between; gap: 16px; }
.chat-status { font-size: 13px; color: var(--muted); }
.chat-status.error, .hint.error { color: var(--error); font-weight: 600; }

dialog.confirm { width: min(560px, calc(100vw - 32px)); border: 1px solid var(--border); border-radius: 12px; padding: 28px; color: var(--text); }
dialog.confirm::backdrop { background: rgba(28, 28, 26, 0.45); }
dialog.confirm p { margin: 0; }
dialog.confirm .form-actions { justify-content: flex-end; flex-wrap: wrap; }

@media (max-width: 700px) {
  .chat-bar { flex-direction: column; align-items: stretch; }
  .chat-messages, .chat-form { padding-left: 12px; padding-right: 12px; }
  .bubble { max-width: 95%; }
}

/* --- Comparison and positioning (step 7) ------------------------------- */
.notice { padding: 16px 20px; border-radius: 12px; background: var(--blue-soft); border: 1px solid #c4d5e6; color: #1d3a57; font-size: 14px; }
.notice p { margin: 0 0 8px; }
.message.waiting { display: flex; align-items: center; gap: 12px; }
.table.comparison td { vertical-align: top; }
.table.comparison td:first-child { width: 34%; }
.table.comparison td:nth-child(2) { width: 18%; }
.criterion-label { font-weight: 700; }
.answer { font-weight: 600; }
.answer.llm { color: var(--blue); }
.justification { margin-top: 4px; font-size: 14px; color: var(--muted); }
.criterion-card { padding: 22px 24px; }
.recap { display: flex; gap: 24px; flex-wrap: wrap; font-size: 15px; }
.criterion-card fieldset.question { padding: 14px 16px; }
@media (max-width: 700px) {
  .table.comparison thead { display: none; }
  .table.comparison td { display: block; width: auto !important; border-bottom: 0; }
  .table.comparison tr { display: block; border-bottom: 1px solid var(--border); }
}

/* Same answer as the LLM: no positioning asked (greyed) */
.criterion-card.identical { background: #f1efe9; color: var(--muted); border-style: dashed; }
.criterion-card.identical h2, .criterion-card.identical b { color: var(--muted); }
.identical-note { margin: 0; font-size: 14px; font-style: italic; }
.table.comparison tr.identical td { background: #faf9f6; }
.table.comparison .badge { margin-top: 6px; }

/* --- Teacher pages (step 9) ---------------------------------------------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; }
.stat { display: flex; flex-direction: column; gap: 2px; padding: 16px 18px; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; }
.stat b { font-size: 24px; color: var(--green); }
.stat span { font-size: 13px; color: var(--muted); }
.failed-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.failed-row form { margin: 0; }
.table tr.inactive td { color: var(--muted); font-style: italic; }
.transcript { display: flex; flex-direction: column; gap: 14px; }
.transcript-row { display: flex; flex-direction: column; gap: 4px; padding-bottom: 12px; border-bottom: 1px solid var(--border); }
.transcript-row:last-child { border-bottom: 0; padding-bottom: 0; }
.transcript-meta { font-size: 12px; font-weight: 600; color: var(--muted); }
.transcript-text { font-size: 15px; line-height: 1.55; overflow-wrap: anywhere; }
.transcript-text.plain { white-space: pre-wrap; }
details.run summary { cursor: pointer; }
details.run pre { margin: 6px 0 0; padding: 10px 12px; background: #f1efe9; border-radius: 8px; font-size: 12px; white-space: pre-wrap; overflow-wrap: anywhere; max-height: 420px; overflow-y: auto; }
details.run details summary { font-size: 14px; color: var(--green); }

/* --- Exports (step 10) --------------------------------------------------- */
.export-card { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 16px 24px;
  padding: 22px 28px; }
/* The text keeps room; with two filters, they go below it (aligned right). */
.export-card > .stack { flex: 1 1 380px; }
.export-actions { display: flex; gap: 12px; align-items: center; flex-shrink: 0; margin-left: auto; }
.export-actions select { min-width: 200px; max-width: 340px; }
@media (max-width: 700px) { .export-card { flex-direction: column; align-items: stretch; } }

/* --- Maintenance (teacher) ---------------------------------------------- */
.button.danger { background: var(--error); border-color: var(--error); color: #ffffff; }
.button.danger:hover { background: #7f2516; border-color: #7f2516; color: #ffffff; }
.maintenance-filters { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 16px; padding: 20px 24px; }
.maintenance-filters .field { min-width: 120px; }
label.choice { display: flex; gap: 10px; align-items: flex-start; font-size: 14px; }
label.choice input { margin-top: 3px; }

/* --- Class sessions and state of the LLM (teacher dashboard, D145, D148) ------------- */
.llm-line { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px;
  padding: 8px 14px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface); font-size: 15px; }
.llm-line.down { background: var(--error-soft); border-color: #e7b9b1; color: var(--error); }
.llm-line form { margin: 0; }
.llm-line .button { padding: 6px 12px; font-size: 14px; }
.session-banner { border-radius: 12px; padding: 16px 20px; display: flex; flex-direction: column; gap: 12px;
  border: 1px solid var(--border); }
.session-banner.closed { background: var(--warning-soft); border-color: #e6cf8f; }
.session-banner.open { background: var(--green-soft); border-color: #b9d4bc; }
.session-banner .row { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; }
.session-banner .actions { display: flex; flex-wrap: wrap; gap: 8px; }
.session-banner .actions form { margin: 0; }
.session-banner .big { font-size: 18px; }
.session-banner .figures { display: flex; gap: 22px; flex-wrap: wrap; }
.session-banner .figures b { font-size: 20px; margin-right: 4px; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; vertical-align: middle; }
.dot.on { background: var(--green); }
.dot.off { background: #b8860b; }
/* Dashboard: state of the class session in one line (D155). */
.session-status { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px;
  padding: 8px 14px; border-radius: 10px; border: 1px solid var(--border); font-size: 15px; }
.session-status.closed { background: var(--warning-soft); border-color: #e6cf8f; }
.session-status.open { background: var(--green-soft); border-color: #b9d4bc; }
.session-status .button { min-height: 32px; padding: 0 12px; font-size: 14px; }
.open-form { display: grid; grid-template-columns: 2fr 1.4fr 1fr auto; gap: 12px; align-items: end; background: var(--surface);
  border: 1px solid var(--border); border-radius: 10px; padding: 14px; }
.open-form .field { margin: 0; }
.field-label { font-size: 14px; font-weight: 600; }
.radio-line { display: flex; flex-direction: column; gap: 4px; }
.radio-line label { font-weight: 400; font-size: 15px; }
@media (max-width: 900px) { .open-form { grid-template-columns: 1fr; } }
