* {
  box-sizing: border-box;
  margin: 0;
}

:root {
  --bg: #f5f4f0;
  --surface: #ffffff;
  --border: #ddd8ce;
  --text: #2b2a26;
  --muted: #7a766c;
  --accent: #3d6b57;
  --accent-soft: #e3ede8;
  --error: #a4443c;
}

html,
body {
  height: 100%;
}

body {
  display: flex;
  flex-direction: column;
  font-family: system-ui, -apple-system, sans-serif;
  color: var(--text);
  background: var(--bg);
}

.hidden {
  display: none !important;
}

/* --- auth ------------------------------------------------------------- */

#auth-view {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* The auth view has no header, so its language toggle floats in the corner. */
.lang-toggle-floating {
  position: fixed;
  top: 0.9rem;
  right: 1.25rem;
}

.auth-card {
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
  width: 20rem;
  padding: 1.5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
}

.auth-actions {
  display: flex;
  gap: 0.6rem;
}

.auth-actions button {
  flex: 1;
}

#auth-error {
  color: var(--error);
  font-size: 0.85rem;
}

/* --- provider setup dialog ---------------------------------------------- */

#provider-dialog,
#coachee-dialog,
#terms-dialog {
  margin: auto; /* re-center: the global reset removes the UA's auto margins */
  width: 24rem;
  max-width: calc(100vw - 2rem);
  padding: 1.5rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
}

#provider-dialog::backdrop,
#coachee-dialog::backdrop,
#terms-dialog::backdrop {
  background: rgba(43, 42, 38, 0.4);
}

#provider-dialog h2,
#coachee-dialog h2,
#terms-dialog h2 {
  font-size: 1.05rem;
  margin-bottom: 0.6rem;
}

#coachee-form {
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
}

#coachee-form textarea {
  resize: vertical;
}

#coachee-error {
  color: var(--error);
  font-size: 0.85rem;
}

#provider-dialog p {
  font-size: 0.9rem;
  line-height: 1.5;
  color: var(--muted);
}

#terms-dialog {
  width: 34rem;
}

.terms-body {
  max-height: 55vh;
  overflow-y: auto;
  font-size: 0.9rem;
  line-height: 1.5;
  color: var(--muted);
}

.terms-body p,
.terms-body ul {
  margin-bottom: 0.6rem;
}

.terms-body ul {
  padding-left: 1.2rem;
}

.terms-body li {
  margin-bottom: 0.35rem;
}

#terms-error {
  color: var(--error);
  font-size: 0.85rem;
  margin-top: 0.5rem;
}

.ai-notice {
  font-size: 0.75rem;
  color: var(--muted);
  text-align: center;
  padding: 0.3rem 1rem 0;
  margin: 0;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.6rem;
  margin-top: 1.1rem;
}

.dialog-actions .primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.dialog-actions .primary:hover {
  filter: brightness(1.1);
}

/* --- app frame ---------------------------------------------------------- */

#app-view {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

header {
  padding: 0.75rem 1.25rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.header-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.5rem;
}

.header-row h1 {
  font-size: 1.1rem;
  flex: 1;
}

#user-chip {
  font-size: 0.85rem;
  color: var(--muted);
}

.controls,
.provider-panel {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 0.75rem;
}

.provider-panel {
  margin-top: 0.6rem;
  padding-top: 0.6rem;
  border-top: 1px dashed var(--border);
}

/* --- prompt editor -------------------------------------------------------- */

.prompt-panel {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  margin-top: 0.6rem;
  padding-top: 0.6rem;
  border-top: 1px dashed var(--border);
}

.prompt-panel-row {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 0.75rem;
}

#prompt-dirty {
  font-size: 0.8rem;
  color: var(--error);
  align-self: center;
}

#prompt-content {
  width: 100%;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.82rem;
  line-height: 1.5;
  resize: vertical;
}

#prompt-preview {
  padding: 0.75rem 0.9rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  font-size: 0.9rem;
  line-height: 1.55;
  max-height: 24rem;
  overflow-y: auto;
}

/* The global margin reset strips the UA spacing the rendered markdown needs. */
#prompt-preview h1 { font-size: 1.15rem; }
#prompt-preview h2 { font-size: 1rem; }
#prompt-preview h3,
#prompt-preview h4 { font-size: 0.92rem; }
#prompt-preview h1,
#prompt-preview h2,
#prompt-preview h3,
#prompt-preview h4 { margin: 0.9em 0 0.35em; }
#prompt-preview h1:first-child { margin-top: 0; }
#prompt-preview p { margin: 0.4em 0; }
#prompt-preview ul { margin: 0.4em 0; padding-left: 1.4em; }
#prompt-preview code {
  padding: 0.05em 0.3em;
  border-radius: 4px;
  background: var(--accent-soft);
  font-size: 0.85em;
}

details.system-prompt {
  align-self: stretch;
  font-size: 0.8rem;
  color: var(--muted);
}

details.system-prompt summary {
  cursor: pointer;
}

details.system-prompt pre {
  margin-top: 0.4rem;
  padding: 0.6rem 0.9rem;
  border: 1px dashed var(--border);
  border-radius: 8px;
  background: var(--surface);
  white-space: pre-wrap;
}

#provider-hint {
  font-size: 0.8rem;
  color: var(--accent);
  align-self: center;
}

#status-banner {
  margin-top: 0.6rem;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--error);
  border-radius: 6px;
  color: var(--error);
  background: #f8ecea;
  font-size: 0.85rem;
}

label {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  font-size: 0.8rem;
  color: var(--muted);
}

select,
input,
textarea,
button {
  font: inherit;
  padding: 0.4rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
}

.provider-panel input {
  min-width: 16rem;
}

button {
  cursor: pointer;
}

button:hover {
  background: var(--accent-soft);
}

button:disabled {
  cursor: default;
  opacity: 0.5;
}

/* --- sidebar + chat ------------------------------------------------------ */

.content {
  flex: 1;
  display: flex;
  min-height: 0;
}

#sidebar {
  width: 16rem;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  padding: 0.9rem;
  background: var(--surface);
  border-right: 1px solid var(--border);
  overflow-y: auto;
}

#conversation-list {
  list-style: none;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

#conversation-list li {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.45rem 0.6rem;
  border-radius: 6px;
  cursor: pointer;
}

.conv-text {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  min-width: 0;
}

.conv-delete {
  order: -1; /* trashcan sits to the left of the text */
  flex-shrink: 0;
  padding: 0.1rem 0.25rem;
  border: none;
  background: none;
  font-size: 0.85rem;
  line-height: 1;
  opacity: 0;
  transition: opacity 0.12s;
}

#conversation-list li:hover .conv-delete,
.conv-delete:focus-visible {
  opacity: 1;
}

.conv-delete:hover {
  background: none;
  filter: brightness(0.7);
}

#conversation-list li:hover {
  background: var(--accent-soft);
}

#conversation-list li.active {
  background: var(--accent-soft);
  outline: 1px solid var(--accent);
}

.conv-title {
  font-size: 0.85rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.conv-meta {
  font-size: 0.72rem;
  color: var(--muted);
}

.chat-pane {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

main {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  padding: 1.25rem;
  max-width: 52rem;
  width: 100%;
  margin: 0 auto;
}

.bubble {
  max-width: 75%;
  padding: 0.6rem 0.9rem;
  border-radius: 12px;
  white-space: pre-wrap;
  line-height: 1.45;
}

.bubble.user {
  align-self: flex-end;
  background: var(--accent);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.bubble.assistant {
  align-self: flex-start;
  background: var(--surface);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

/* Reasoning phase: a bare status line, not a boxed reply. The box returns
   with the first real words. */
.bubble.assistant.thinking {
  background: none;
  border: none;
  padding-left: 0.2rem;
  color: var(--muted);
  font-style: italic;
  font-size: 0.85rem;
}

.bubble.assistant.pending::after {
  content: "•••";
  color: var(--muted);
  letter-spacing: 0.2em;
  animation: pending-pulse 1.2s ease-in-out infinite;
}

@keyframes pending-pulse {
  0%, 100% { opacity: 0.25; }
  50% { opacity: 0.9; }
}

@media (prefers-reduced-motion: reduce) {
  .bubble.assistant.pending::after {
    animation: none;
  }
}

.bubble.error {
  align-self: center;
  background: none;
  border: 1px dashed var(--error);
  color: var(--error);
  font-size: 0.85rem;
}

/* --- supervisor feedback pane -------------------------------------------- */

#feedback-pane {
  width: 19rem;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  padding: 0.9rem;
  background: var(--surface);
  border-left: 1px solid var(--border);
  overflow-y: auto;
}

.feedback-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
}

.feedback-head h2 {
  font-size: 0.95rem;
}

/* The global label rule stacks vertically; the switch wants its text beside it. */
.feedback-toggle {
  flex-direction: row;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  user-select: none;
}

/* The checkbox is drawn as a sliding switch: the input is the track, ::before the thumb.
   appearance: none also sheds the global input border/padding box styling. */
.feedback-toggle input {
  appearance: none;
  width: 34px;
  height: 20px;
  margin: 0;
  padding: 0;
  flex-shrink: 0;
  position: relative;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--border);
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.feedback-toggle input::before {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--surface);
  box-shadow: 0 1px 2px rgb(0 0 0 / 0.25);
  transition: transform 0.15s ease;
}

.feedback-toggle input:checked {
  background: var(--accent);
  border-color: var(--accent);
}

.feedback-toggle input:checked::before {
  transform: translateX(14px);
}

.feedback-toggle input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

#feedback-empty {
  font-size: 0.85rem;
  color: var(--muted);
}

#feedback-list {
  list-style: none;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.feedback-entry {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.85rem;
  line-height: 1.45;
  white-space: pre-wrap;
}

.feedback-meta {
  font-size: 0.72rem;
  color: var(--muted);
}

/* Rendered markdown: restore the spacing the global margin reset strips. */
.feedback-body h1,
.feedback-body h2,
.feedback-body h3,
.feedback-body h4 {
  font-size: 0.9rem;
  margin: 0.7em 0 0.25em;
}
.feedback-body h1:first-child,
.feedback-body h2:first-child,
.feedback-body h3:first-child,
.feedback-body h4:first-child {
  margin-top: 0;
}
.feedback-body p {
  margin: 0.3em 0;
}
.feedback-body ul {
  margin: 0.3em 0;
  padding-left: 1.3em;
}

.feedback-entry.evaluation {
  border-left: 3px solid var(--accent);
  background: var(--accent-soft);
}

.feedback-entry.error {
  border-style: dashed;
  border-color: var(--error);
  color: var(--error);
}

.feedback-entry.pending {
  color: var(--muted);
  animation: pending-pulse 1.2s ease-in-out infinite;
}

@media (prefers-reduced-motion: reduce) {
  .feedback-entry.pending {
    animation: none;
  }
}

/* Narrow windows: shrink the side panes rather than dropping the feedback
   pane — it holds the only route to the final evaluation. */
@media (max-width: 64rem) {
  #sidebar {
    width: 12rem;
  }

  #feedback-pane {
    width: 14rem;
  }
}

footer {
  padding: 0.75rem 1.25rem 1rem;
  background: var(--surface);
  border-top: 1px solid var(--border);
}

#chat-form {
  display: flex;
  gap: 0.6rem;
  max-width: 52rem;
  margin: 0 auto;
}

#message-input {
  flex: 1;
  resize: none;
}

#readonly-note {
  text-align: center;
  color: var(--muted);
  font-size: 0.85rem;
}
