/* Prompt Research Sessions — clean, minimal UI in European Portuguese.
   Mobile-first for /participant, sidebar layout for /researcher,
   high-contrast large-font layout for /display. */

* { box-sizing: border-box; }

:root {
  --bg: #f5f5f4;
  --surface: #ffffff;
  --text: #1a1a1a;
  --muted: #6b7280;
  --border: #e5e7eb;
  --primary: #1f2937;
  --primary-text: #f9fafb;
  --accent: #2563eb;
  --grey: #6b7280;
  --amber: #d97706;
  --green: #059669;
  --warn: #b91c1c;
  --sidebar: #1f2937;
  --sidebar-text: #f9fafb;
}

html, body, #root {
  height: 100%;
  margin: 0;
  padding: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea {
  font-family: inherit;
  font-size: 1rem;
}

textarea, input[type=text], input[type=number], select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
}

textarea {
  min-height: 100px;
  resize: vertical;
}

button {
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  padding: 10px 14px;
  border-radius: 6px;
  font-weight: 500;
}

button:hover:not(:disabled) {
  background: #f3f4f6;
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

button.primary {
  background: var(--primary);
  color: var(--primary-text);
  border-color: var(--primary);
}
button.primary:hover:not(:disabled) {
  background: #111827;
}

button.warn {
  background: var(--warn);
  color: white;
  border-color: var(--warn);
}

a {
  color: var(--accent);
  text-decoration: none;
}
a:hover { text-decoration: underline; }

.error {
  color: var(--warn);
  font-size: 0.9rem;
}

.muted {
  color: var(--muted);
}

.center {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 20px;
}

/* ---------- Landing page ---------- */
.landing {
  max-width: 480px;
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 28px;
}
.landing h1 { margin-top: 0; }
.landing .links { display: flex; gap: 12px; margin-top: 16px; flex-wrap: wrap; }

/* ---------- Researcher layout ---------- */
.researcher-layout {
  display: flex;
  min-height: 100vh;
}
.sidebar {
  background: var(--sidebar);
  color: var(--sidebar-text);
  width: 320px;
  padding: 20px;
  overflow-y: auto;
  flex-shrink: 0;
}
.sidebar h2 { margin: 0 0 4px 0; font-size: 1.1rem; }
.sidebar .session-code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 1.6rem;
  letter-spacing: 0.06em;
  margin-bottom: 16px;
}
.sidebar .section { margin-bottom: 18px; padding-bottom: 14px; border-bottom: 1px solid #374151; }
.sidebar .section:last-child { border-bottom: none; }
.sidebar h3 { margin: 0 0 8px 0; font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.05em; color: #9ca3af; }
.sidebar button {
  width: 100%;
  margin-bottom: 6px;
  background: #374151;
  color: var(--sidebar-text);
  border-color: #4b5563;
  text-align: left;
}
.sidebar button:hover:not(:disabled) { background: #4b5563; }
.sidebar button.primary { background: var(--accent); border-color: var(--accent); }
.sidebar .participant-list { font-size: 0.9rem; }
.sidebar .participant-row {
  display: flex; justify-content: space-between; padding: 4px 0;
}
.sidebar .dot {
  width: 8px; height: 8px; border-radius: 50%; background: #6b7280; display: inline-block; margin-right: 6px;
}
.sidebar .dot.connected { background: #10b981; }

.main {
  flex: 1;
  padding: 24px;
  overflow-y: auto;
}
.main h1 { margin-top: 0; }
.task-banner {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px 18px;
  margin-bottom: 16px;
}
.phase-pill {
  display: inline-block;
  background: var(--primary);
  color: var(--primary-text);
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.85rem;
  margin-left: 8px;
}

.prompt-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 12px;
}
.prompt-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px;
  position: relative;
}
.prompt-card.winner {
  border-color: var(--green);
  border-width: 2px;
  box-shadow: 0 0 0 3px rgba(5, 150, 105, 0.1);
}
.prompt-card .meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}
.prompt-card .code {
  font-family: ui-monospace, monospace;
  font-weight: 600;
}
.prompt-card .prompt-text { white-space: pre-wrap; }
.prompt-card .footer {
  margin-top: 10px;
  display: flex;
  justify-content: space-between;
  font-size: 0.85rem;
  color: var(--muted);
  align-items: center;
}

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
  color: white;
}
.badge-grey  { background: var(--grey); }
.badge-amber { background: var(--amber); }
.badge-green { background: var(--green); }

.dim-breakdown {
  display: inline-flex;
  gap: 4px;
  font-size: 0.75rem;
  margin-left: 8px;
}
.dim-pill {
  display: inline-block;
  width: 18px; height: 18px;
  text-align: center; line-height: 18px;
  border-radius: 4px;
  font-weight: 600;
  background: #e5e7eb; color: var(--muted);
}
.dim-pill.on { background: var(--green); color: white; }

/* ---------- Participant view ---------- */
.participant {
  max-width: 640px;
  margin: 0 auto;
  padding: 16px;
}
.participant-header {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.9rem;
}
.participant-header .me {
  font-family: ui-monospace, monospace;
  font-weight: 600;
}
.task-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 12px;
}
.status-banner {
  background: #fef3c7;
  border: 1px solid #fcd34d;
  color: #78350f;
  padding: 10px 12px;
  border-radius: 6px;
  margin-bottom: 12px;
  font-weight: 500;
  text-align: center;
}
.status-banner.ok { background: #d1fae5; border-color: #6ee7b7; color: #064e3b; }
.status-banner.muted { background: #f3f4f6; border-color: var(--border); color: var(--muted); }

.choice-row { display: flex; gap: 8px; flex-wrap: wrap; }
.choice-row label {
  flex: 1; min-width: 100px;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px;
  background: var(--surface);
  cursor: pointer;
  text-align: center;
}
.choice-row label.selected {
  border-color: var(--accent);
  background: #eff6ff;
  color: var(--accent);
  font-weight: 600;
}
.choice-row input { display: none; }

.vote-card {
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: 8px;
  padding: 14px;
  margin-bottom: 10px;
  cursor: pointer;
}
.vote-card.selected {
  border-color: var(--accent);
  background: #eff6ff;
}
.vote-card .code {
  font-family: ui-monospace, monospace;
  font-weight: 600;
  margin-bottom: 6px;
}

/* ---------- Display view ---------- */
.display {
  min-height: 100vh;
  padding: 36px 56px;
  display: flex;
  flex-direction: column;
  background: #ffffff;
}
.display h1 { font-size: 2.6rem; margin: 0 0 12px 0; }
.display .task-desc { font-size: 1.4rem; color: var(--muted); margin-bottom: 24px; }
.display .phase-label {
  font-size: 1.6rem;
  font-weight: 700;
  margin-bottom: 24px;
  color: var(--accent);
}
.display .prompt-grid .prompt-card { font-size: 1.15rem; }
.display .ai-output {
  font-size: 1.4rem;
  line-height: 1.6;
  white-space: pre-wrap;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 24px;
}
.display .assumption-block {
  font-size: 1.4rem;
  white-space: pre-wrap;
  background: #fef3c7;
  border: 2px solid #f59e0b;
  border-radius: 8px;
  padding: 24px;
  margin-bottom: 16px;
}

/* ---------- Tables ---------- */
.data-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  font-size: 0.9rem;
}
.data-table th, .data-table td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}
.data-table th {
  background: #f3f4f6;
  font-weight: 600;
}

/* ---------- Mobile ---------- */
@media (max-width: 800px) {
  .researcher-layout { flex-direction: column; }
  .sidebar { width: 100%; max-height: 50vh; }
  .display { padding: 18px; }
  .display h1 { font-size: 1.8rem; }
  .display .task-desc { font-size: 1.1rem; }
  .display .ai-output { font-size: 1.1rem; padding: 16px; }
}


/* ---------- Markdown rendering of AI output ---------- */
.markdown { color: inherit; line-height: 1.6; }
.markdown > *:first-child { margin-top: 0; }
.markdown > *:last-child  { margin-bottom: 0; }
.markdown p { margin: 0.6em 0; }
.markdown h1, .markdown h2, .markdown h3, .markdown h4 {
  margin: 1em 0 0.4em;
  font-weight: 700;
  line-height: 1.25;
}
.markdown h1 { font-size: 1.6em; }
.markdown h2 { font-size: 1.35em; }
.markdown h3 { font-size: 1.15em; }
.markdown h4 { font-size: 1em; }
.markdown ul, .markdown ol { margin: 0.4em 0; padding-left: 1.5em; }
.markdown li { margin: 0.2em 0; }
.markdown li > p { margin: 0.2em 0; }
.markdown strong { font-weight: 700; }
.markdown em { font-style: italic; }
.markdown code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  background: rgba(0,0,0,0.06);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 0.95em;
}
.markdown pre {
  background: rgba(0,0,0,0.06);
  padding: 12px;
  border-radius: 6px;
  overflow: auto;
  margin: 0.6em 0;
}
.markdown pre code { background: transparent; padding: 0; }
.markdown blockquote {
  border-left: 3px solid var(--border);
  padding: 0 0.8em;
  color: var(--muted);
  margin: 0.6em 0;
}
.markdown table {
  border-collapse: collapse;
  margin: 0.6em 0;
  font-size: 0.95em;
}
.markdown th, .markdown td {
  border: 1px solid var(--border);
  padding: 6px 10px;
  text-align: left;
}
.markdown hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 1em 0;
}
.markdown a { color: var(--accent); text-decoration: underline; }

/* Display view: bigger fonts for the projected AI output */
.display .ai-output .markdown { font-size: inherit; }
.display .assumption-block .markdown { font-size: inherit; }
