:root {
  --primary: #004AAD;
  --primary-light: #1a5fc4;
  --primary-dark: #003a8a;
  --pro: #059669;
  --pro-light: #10b981;
  --con: #dc2626;
  --con-light: #ef4444;
  --moderator: #6b7280;
  --judge-bg: #f0f4ff;
  --judge-border: #004AAD;
  --bg: #ffffff;
  --bg-secondary: #f9fafb;
  --text: #111827;
  --text-muted: #6b7280;
  --border: #e5e7eb;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 4px 6px -1px rgba(0,74,173,.08), 0 2px 4px -2px rgba(0,74,173,.06);
  --shadow-lg: 0 10px 25px -5px rgba(0,74,173,.1), 0 8px 10px -6px rgba(0,74,173,.08);

  /* Agent color palette — edit these six values to change all agent colors globally */
  --agent-0: #2563eb;
  --agent-1: #7c3aed;
  --agent-2: #d97706;
  --agent-3: #0d9488;
  --agent-4: #e05252;
  --agent-5: #16a34a;
}

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

body {
  font-family: 'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.6;
}

.app { display: flex; min-height: 100vh; position: relative; }

/* ── Left sidebar ──────────────────────────────────────────────────────────── */
.sidebar {
  width: 260px;
  min-width: 260px;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}

.sidebar-header { padding: 16px; border-bottom: 1px solid var(--border); }

.new-debate-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 12px 16px;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background .2s, transform .1s;
}
.new-debate-btn:hover { background: var(--primary-light); }
.new-debate-btn:active { transform: scale(.98); }

.debate-list { flex: 1; overflow-y: auto; padding: 12px; }

.debate-item {
  padding: 12px 14px;
  margin-bottom: 6px;
  background: white;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: border-color .2s, box-shadow .2s;
}
.debate-item:hover { border-color: var(--primary); box-shadow: var(--shadow); }
.debate-item.active { border-color: var(--primary); background: rgba(0,74,173,.04); }
.debate-item-in-progress { cursor: default; }
.debate-item-in-progress .debate-item-date { color: var(--primary); font-style: italic; }
.debate-item-title { font-size: 13px; font-weight: 500; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.debate-item-date { font-size: 11px; color: var(--text-muted); margin-top: 4px; }
.debate-list-empty { padding: 24px 16px; text-align: center; color: var(--text-muted); font-size: 13px; }

/* ── Main ──────────────────────────────────────────────────────────────────── */
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; overflow-y: auto; }

.chat-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  max-width: 820px;
  width: 100%;
  margin: 0 auto;
  padding: 24px;
}

/* ── Welcome screen ────────────────────────────────────────────────────────── */
.welcome-screen { flex: 1; display: flex; align-items: flex-start; justify-content: center; padding: 40px 0; }

.welcome-content { text-align: center; max-width: 640px; width: 100%; }

.welcome-content h1 { font-size: 2rem; font-weight: 600; color: var(--primary); margin-bottom: 12px; }
.welcome-content > p { color: var(--text-muted); font-size: 15px; margin-bottom: 24px; line-height: 1.7; }

/* ── Agent cards ───────────────────────────────────────────────────────────── */
.agents-section { margin-bottom: 24px; text-align: left; }

.agents-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.agents-section-title { font-size: 13px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: .05em; }

.agents-actions { display: flex; gap: 8px; }

.add-agent-btn, .persona-toggle-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--border);
  background: white;
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  color: var(--text);
  transition: border-color .2s, background .2s;
}
.add-agent-btn:hover, .persona-toggle-btn:hover { border-color: var(--primary); color: var(--primary); }
.add-agent-btn:disabled { opacity: .4; cursor: not-allowed; }

.agent-cards { display: flex; flex-direction: column; gap: 10px; }

.agent-card {
  background: white;
  border: 2px solid var(--border);
  border-left-width: 4px;
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  transition: border-color .2s;
}
.agent-card.agent-0 { border-left-color: var(--agent-0); }
.agent-card.agent-1 { border-left-color: var(--agent-1); }
.agent-card.agent-2 { border-left-color: var(--agent-2); }
.agent-card.agent-3 { border-left-color: var(--agent-3); }
.agent-card.agent-4 { border-left-color: var(--agent-4); }
.agent-card.agent-5 { border-left-color: var(--agent-5); }

.agent-card-header { display: flex; gap: 12px; align-items: flex-start; }

.agent-card-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 15px;
  flex-shrink: 0;
  margin-top: 4px;
}
.agent-card-avatar.agent-0 { background: var(--agent-0); color: white; }
.agent-card-avatar.agent-1 { background: var(--agent-1); color: white; }
.agent-card-avatar.agent-2 { background: var(--agent-2); color: white; }
.agent-card-avatar.agent-3 { background: var(--agent-3); color: white; }
.agent-card-avatar.agent-4 { background: var(--agent-4); color: white; }
.agent-card-avatar.agent-5 { background: var(--agent-5); color: white; }

.agent-card-fields { flex: 1; display: flex; flex-direction: column; gap: 8px; }

.agent-field-row { display: flex; align-items: center; gap: 8px; }

.agent-field-label { font-size: 11px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; width: 80px; flex-shrink: 0; }

.agent-field-input, .agent-field-select {
  flex: 1;
  padding: 7px 10px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-family: inherit;
  font-size: 13px;
  outline: none;
  transition: border-color .2s;
  background: white;
}
.agent-field-input:focus, .agent-field-select:focus { border-color: var(--primary); }

.agent-card-actions { display: flex; flex-direction: column; gap: 6px; }

.agent-persona-btn, .agent-remove-btn {
  width: 28px;
  height: 28px;
  border: 1.5px solid var(--border);
  border-radius: 50%;
  background: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color .2s, background .2s;
  font-size: 11px;
}
.agent-persona-btn:hover { border-color: var(--primary); color: var(--primary); }
.agent-remove-btn:hover { border-color: var(--con); color: var(--con); background: rgba(220,38,38,.06); }

.stance-helper-text {
  font-size: 11px;
  color: var(--text-muted);
  font-style: italic;
  margin-top: 6px;
  padding-left: 48px;
}

.agent-persona-chip {
  display: inline-block;
  margin-top: 8px;
  padding: 2px 10px;
  background: rgba(0,74,173,.08);
  color: var(--primary);
  border-radius: 20px;
  font-size: 11px;
  font-weight: 500;
}

/* ── Topic form ────────────────────────────────────────────────────────────── */
.topic-form {
  display: flex;
  gap: 12px;
  background: white;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 8px;
  box-shadow: var(--shadow);
  transition: border-color .2s, box-shadow .2s;
}
.topic-form:focus-within { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(0,74,173,.15); }
.topic-form input { flex: 1; padding: 14px 18px; border: none; border-radius: var(--radius-sm); font-family: inherit; font-size: 15px; outline: none; }
.topic-form button { padding: 14px 24px; background: var(--primary); color: white; border: none; border-radius: var(--radius-sm); font-family: inherit; font-size: 14px; font-weight: 600; cursor: pointer; transition: background .2s; }
.topic-form button:hover { background: var(--primary-light); }
.topic-form button:disabled { opacity: .6; cursor: not-allowed; }

/* ── Rounds row ─────────────────────────────────────────────────────────────── */
.max-turns-row { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; text-align: left; flex-wrap: wrap; }
.max-turns-label { font-size: 14px; font-weight: 500; color: var(--text); white-space: nowrap; }
.max-turns-input { padding: 10px 14px; border: 2px solid var(--border); border-radius: 10px; font-family: inherit; font-size: 14px; outline: none; transition: border-color .2s; width: 80px; }
.rounds-helper { font-size: 12px; color: var(--text-muted); }

/* ── Document upload ───────────────────────────────────────────────────────── */
.upload-area { display: flex; align-items: center; gap: 8px; margin-bottom: 20px; }
.upload-label { display: inline-flex; align-items: center; gap: 8px; padding: 10px 16px; border: 2px dashed var(--border); border-radius: var(--radius-sm); font-size: 13px; color: var(--text-muted); cursor: pointer; transition: border-color .2s, color .2s, background .2s; width: 100%; text-align: left; }
.upload-label:hover { border-color: var(--primary); color: var(--primary); background: rgba(0,74,173,.04); }
.upload-label.attached { border-style: solid; border-color: var(--pro); color: var(--pro); background: rgba(5,150,105,.06); }
.upload-remove-btn { flex-shrink: 0; width: 28px; height: 28px; border: none; border-radius: 50%; background: rgba(220,38,38,.1); color: var(--con); cursor: pointer; font-size: 12px; display: flex; align-items: center; justify-content: center; transition: background .2s; }
.upload-remove-btn:hover { background: rgba(220,38,38,.2); }

/* ── Messages ──────────────────────────────────────────────────────────────── */
.messages-container { flex: 1; display: flex; flex-direction: column; }

.debate-header { padding: 16px 0; margin-bottom: 24px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.debate-header-left { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.debate-topic { font-size: 18px; font-weight: 600; color: var(--primary); }
.debate-round-badge { font-size: 12px; font-weight: 600; color: var(--text-muted); letter-spacing: .02em; }

.download-report-btn { padding: 10px 18px; background: var(--primary); color: white; border-radius: var(--radius-sm); font-size: 14px; font-weight: 500; text-decoration: none; transition: background .2s; white-space: nowrap; }
.download-report-btn:hover { background: var(--primary-light); color: white; }

.messages { flex: 1; display: flex; flex-direction: column; gap: 28px; }

.message-block { scroll-margin-bottom: 24px; }

.message {
  display: flex;
  gap: 16px;
  padding: 20px 24px;
  border-radius: var(--radius);
  animation: messageIn .3s ease-out;
}

@keyframes messageIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── Agent message colors (current format) ─────────────────────────────────── */
.message.agent-0 { background: rgba(37,99,235,.07); border-left: 4px solid var(--agent-0); }
.message.agent-1 { background: rgba(124,58,237,.07); border-left: 4px solid var(--agent-1); }
.message.agent-2 { background: rgba(217,119,6,.07); border-left: 4px solid var(--agent-2); }
.message.agent-3 { background: rgba(13,148,136,.07); border-left: 4px solid var(--agent-3); }
.message.agent-4 { background: rgba(224,82,82,.07); border-left: 4px solid var(--agent-4); }
.message.agent-5 { background: rgba(22,163,74,.07); border-left: 4px solid var(--agent-5); }

.message.agent-0 .message-avatar { background: var(--agent-0); color: white; }
.message.agent-1 .message-avatar { background: var(--agent-1); color: white; }
.message.agent-2 .message-avatar { background: var(--agent-2); color: white; }
.message.agent-3 .message-avatar { background: var(--agent-3); color: white; }
.message.agent-4 .message-avatar { background: var(--agent-4); color: white; }
.message.agent-5 .message-avatar { background: var(--agent-5); color: white; }

.message.agent-0 .message-speaker { color: var(--agent-0); }
.message.agent-1 .message-speaker { color: var(--agent-1); }
.message.agent-2 .message-speaker { color: var(--agent-2); }
.message.agent-3 .message-speaker { color: var(--agent-3); }
.message.agent-4 .message-speaker { color: var(--agent-4); }
.message.agent-5 .message-speaker { color: var(--agent-5); }

.message.agent-0 .message-role { background: rgba(37,99,235,.18); color: var(--agent-0); }
.message.agent-1 .message-role { background: rgba(124,58,237,.18); color: var(--agent-1); }
.message.agent-2 .message-role { background: rgba(217,119,6,.18); color: var(--agent-2); }
.message.agent-3 .message-role { background: rgba(13,148,136,.18); color: var(--agent-3); }
.message.agent-4 .message-role { background: rgba(224,82,82,.18); color: var(--agent-4); }
.message.agent-5 .message-role { background: rgba(22,163,74,.18); color: var(--agent-5); }

/* Legacy colors — kept for backward compat with old saved runs */
.message.pro { background: rgba(5,150,105,.08); border-left: 4px solid var(--pro); }
.message.con { background: rgba(220,38,38,.06); border-left: 4px solid var(--con); }
.message.pro .message-avatar { background: var(--pro); color: white; }
.message.con .message-avatar { background: var(--con); color: white; }
.message.pro .message-speaker { color: var(--pro); }
.message.con .message-speaker { color: var(--con); }
.message.pro .message-role { background: rgba(5,150,105,.2); color: var(--pro); }
.message.con .message-role { background: rgba(220,38,38,.2); color: var(--con); }

.message.moderator { background: rgba(107,114,128,.06); border-left: 4px solid var(--moderator); }
.message.judge    { background: var(--judge-bg); border: 2px solid var(--judge-border); border-radius: var(--radius); padding: 24px 28px; }

.message-avatar { width: 36px; height: 36px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-weight: 600; font-size: 14px; flex-shrink: 0; }
.message.moderator .message-avatar { background: var(--moderator); color: white; }
.message.judge .message-avatar    { background: var(--primary); color: white; }

.message-body { flex: 1; min-width: 0; }
.message-header { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.message-speaker { font-weight: 600; font-size: 15px; }

.message.moderator .message-speaker { color: var(--moderator); }
.message.judge .message-speaker    { color: var(--primary); }

.message-role { font-size: 11px; padding: 2px 8px; border-radius: 6px; font-weight: 500; }
.message.moderator .message-role { background: rgba(107,114,128,.2); color: var(--moderator); }
.message.judge .message-role     { background: rgba(0,74,173,.15); color: var(--primary); }

.message-text { font-size: 15px; line-height: 1.7; white-space: pre-wrap; word-break: break-word; }

.message-text .typing-cursor { display: inline-block; width: 2px; height: 1em; background: var(--text); animation: blink .8s step-end infinite; vertical-align: text-bottom; }

@keyframes blink { 50% { opacity: 0; } }

/* ── Judge summary ─────────────────────────────────────────────────────────── */
.judge-summary {
  margin-top: 32px;
  padding: 28px 32px;
  background: var(--judge-bg);
  border: 2px solid var(--judge-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  animation: messageIn .35s ease-out;
}
.judge-summary-title { font-size: 18px; font-weight: 600; color: var(--primary); margin-bottom: 16px; display: flex; align-items: center; gap: 10px; }
.judge-summary-content { font-size: 15px; line-height: 1.8; white-space: pre-wrap; }

/* ── Loading dots ──────────────────────────────────────────────────────────── */
.loading-dots { display: inline-flex; gap: 4px; }
.loading-dots span { width: 6px; height: 6px; border-radius: 50%; background: var(--text-muted); animation: loadingBounce 1.4s ease-in-out infinite both; }
.loading-dots span:nth-child(1) { animation-delay: 0s; }
.loading-dots span:nth-child(2) { animation-delay: .2s; }
.loading-dots span:nth-child(3) { animation-delay: .4s; }
@keyframes loadingBounce { 0%, 80%, 100% { transform: scale(.6); opacity: .5; } 40% { transform: scale(1); opacity: 1; } }

/* ── Persona sidebar (right) ───────────────────────────────────────────────── */
.persona-sidebar {
  position: fixed;
  top: 0;
  right: 0;
  width: 320px;
  height: 100vh;
  background: white;
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform .25s ease;
  z-index: 100;
  box-shadow: var(--shadow-lg);
}
.persona-sidebar.open { transform: translateX(0); }

.persona-sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.persona-sidebar-title { font-size: 15px; font-weight: 600; color: var(--text); }
.persona-sidebar-close { background: none; border: none; cursor: pointer; font-size: 16px; color: var(--text-muted); padding: 4px; border-radius: 6px; transition: background .2s; }
.persona-sidebar-close:hover { background: var(--bg-secondary); }

.persona-search-wrap { padding: 12px 14px; border-bottom: 1px solid var(--border); flex-shrink: 0; }
.persona-search { width: 100%; padding: 8px 12px; border: 1.5px solid var(--border); border-radius: var(--radius-sm); font-family: inherit; font-size: 13px; outline: none; transition: border-color .2s; }
.persona-search:focus { border-color: var(--primary); }

.persona-list { flex: 1; overflow-y: auto; padding: 12px; }

.persona-section { margin-bottom: 20px; }
.persona-section-title { font-size: 11px; font-weight: 700; color: var(--text-muted); text-transform: uppercase; letter-spacing: .07em; margin-bottom: 8px; padding: 0 2px; }

.persona-cards { display: flex; flex-direction: column; gap: 6px; }

.persona-card {
  padding: 10px 12px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: border-color .15s, background .15s;
  background: white;
}
.persona-card:hover { border-color: var(--primary); background: rgba(0,74,173,.03); }

.persona-card-top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 4px; }
.persona-card-name { font-size: 13px; font-weight: 600; color: var(--text); }
.persona-card-cat { font-size: 10px; padding: 2px 7px; border-radius: 20px; background: rgba(0,74,173,.1); color: var(--primary); font-weight: 500; }
.persona-card-desc { font-size: 12px; color: var(--text-muted); line-height: 1.5; }

.persona-card-actions { display: flex; gap: 6px; margin-top: 8px; }
.persona-edit-btn, .persona-delete-btn, .preset-load-btn, .preset-delete-btn {
  padding: 4px 10px;
  border-radius: 6px;
  border: 1.5px solid var(--border);
  background: white;
  font-size: 11px;
  font-family: inherit;
  cursor: pointer;
  transition: border-color .2s;
}
.persona-edit-btn:hover, .preset-load-btn:hover { border-color: var(--primary); color: var(--primary); }
.persona-delete-btn:hover, .preset-delete-btn:hover { border-color: var(--con); color: var(--con); }

.persona-card--preset { cursor: default; }
.persona-card--preset:hover { border-color: var(--border); background: white; }

.persona-add-custom-wrap { margin: 8px 0; }
.persona-add-custom-btn {
  width: 100%;
  padding: 9px 14px;
  border: 1.5px dashed var(--border);
  border-radius: var(--radius-sm);
  background: white;
  font-family: inherit;
  font-size: 13px;
  color: var(--text-muted);
  cursor: pointer;
  transition: border-color .2s, color .2s;
}
.persona-add-custom-btn:hover { border-color: var(--primary); color: var(--primary); }

/* ── Modal ─────────────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.35);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
}
.modal {
  background: white;
  border-radius: var(--radius);
  padding: 28px;
  width: 440px;
  max-width: 95vw;
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.modal-title { font-size: 16px; font-weight: 600; color: var(--text); margin-bottom: 4px; }
.modal-label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; font-weight: 500; color: var(--text); }
.modal-input {
  padding: 9px 12px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-family: inherit;
  font-size: 13px;
  outline: none;
  transition: border-color .2s;
}
.modal-input:focus { border-color: var(--primary); }
.modal-textarea {
  padding: 9px 12px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-family: inherit;
  font-size: 13px;
  outline: none;
  resize: vertical;
  min-height: 90px;
  transition: border-color .2s;
}
.modal-textarea:focus { border-color: var(--primary); }
.modal-actions { display: flex; gap: 10px; margin-top: 4px; }
.modal-btn {
  padding: 10px 20px;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--border);
  background: white;
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background .2s, border-color .2s;
}
.modal-btn--primary { background: var(--primary); color: white; border-color: var(--primary); }
.modal-btn--primary:hover { background: var(--primary-light); }
.modal-btn:not(.modal-btn--primary):hover { border-color: var(--primary); color: var(--primary); }

/* ── Responsive ────────────────────────────────────────────────────────────── */
@media (max-width: 600px) {
  .sidebar { width: 220px; min-width: 220px; }
  .persona-sidebar { width: 100vw; }
  .agent-field-row { flex-wrap: wrap; }
  .agent-field-label { width: auto; }
}
