/* ============================================================================
   CSS Custom Properties
   ============================================================================ */

:root {
  --bg-primary: #08080e;
  --bg-secondary: #0e0e18;
  --bg-card: #131320;
  --bg-surface: #1a1a2e;
  --bg-hover: #22223a;
  --bg-input: #16162a;

  --border-subtle: #252540;
  --border-active: #4040aa;

  --text-primary: #e8e8f0;
  --text-secondary: #8888a0;
  --text-muted: #555570;

  --accent: #7c7cff;
  --accent-dim: #5555cc;
  --accent-glow: rgba(124, 124, 255, 0.15);

  --success: #22c55e;
  --success-dim: #166534;
  --error: #ef4444;
  --error-dim: #7f1d1d;
  --warning: #f59e0b;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;

  --shadow-card: 0 2px 12px rgba(0, 0, 0, 0.4);
  --shadow-modal: 0 16px 48px rgba(0, 0, 0, 0.6);

  --sidebar-width: 280px;
  --topbar-height: 60px;

  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono: "SF Mono", "Fira Code", "Cascadia Code", monospace;

  /* Sprite avatar palette */
  --sprite-hue-1: 260;
  --sprite-hue-2: 330;
  --sprite-hue-3: 180;
  --sprite-hue-4: 30;
  --sprite-hue-5: 120;
  --sprite-hue-6: 0;
  --sprite-hue-7: 210;
  --sprite-hue-8: 60;
  --sprite-hue-9: 300;
  --sprite-hue-10: 150;
}

/* ============================================================================
   Reset & Base
   ============================================================================ */

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

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  font-family: var(--font-sans);
  font-size: 14px;
  color: var(--text-primary);
  background: var(--bg-primary);
  line-height: 1.6;
}

/* ============================================================================
   Layout
   ============================================================================ */

#top-bar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--topbar-height);
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  z-index: 100;
}

#sidebar {
  position: fixed;
  top: var(--topbar-height);
  left: 0;
  bottom: 0;
  width: var(--sidebar-width);
  background: var(--bg-secondary);
  border-right: 1px solid var(--border-subtle);
  overflow-y: auto;
  padding: 12px;
  z-index: 50;
}

#main-content {
  position: fixed;
  top: var(--topbar-height);
  left: var(--sidebar-width);
  right: 0;
  bottom: 0;
  overflow-y: auto;
  padding: 24px 32px;
}

/* ============================================================================
   Top Bar
   ============================================================================ */

.top-bar-left {
  display: flex;
  align-items: center;
  gap: 14px;
}

.top-bar-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-primary);
  white-space: nowrap;
}

.sim-name {
  font-size: 14px;
  color: var(--text-secondary);
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.generate-group {
  display: flex;
  align-items: center;
  gap: 6px;
}

.generate-group .control-input {
  width: 52px;
  text-align: center;
}

/* ============================================================================
   Status Badge
   ============================================================================ */

.status-badge {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 3px 10px;
  border-radius: 20px;
  white-space: nowrap;
}

.status-badge.idle {
  background: var(--bg-surface);
  color: var(--text-muted);
}

.status-badge.running {
  background: var(--accent-glow);
  color: var(--accent);
  animation: pulse 2s ease-in-out infinite;
}

.status-badge.complete {
  background: var(--success-dim);
  color: var(--success);
}

.status-badge.error {
  background: var(--error-dim);
  color: var(--error);
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

/* ============================================================================
   Buttons
   ============================================================================ */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 16px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--accent);
  color: white;
}

.btn-primary:hover:not(:disabled) {
  background: #8e8eff;
  box-shadow: 0 0 20px var(--accent-glow);
}

.btn-secondary {
  background: var(--bg-surface);
  color: var(--text-primary);
  border: 1px solid var(--border-subtle);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--bg-hover);
  border-color: var(--border-active);
}

.btn-danger {
  background: var(--error-dim);
  color: var(--error);
  border: 1px solid var(--error);
}

.btn-danger:hover:not(:disabled) {
  background: var(--error);
  color: white;
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border: 1px dashed var(--border-subtle);
}

.btn-ghost:hover:not(:disabled) {
  background: var(--bg-surface);
  color: var(--text-primary);
  border-color: var(--border-active);
}

.btn-full {
  width: 100%;
}

.btn-icon {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 18px;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
}

.btn-icon:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

/* ============================================================================
   Form Controls
   ============================================================================ */

.control-select,
.control-input {
  background: var(--bg-input);
  color: var(--text-primary);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 7px 10px;
  font-size: 13px;
  font-family: var(--font-sans);
}

.control-select:focus,
.control-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-glow);
}

.form-label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 16px;
}

.form-input,
.form-textarea {
  background: var(--bg-input);
  color: var(--text-primary);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 14px;
  font-family: var(--font-sans);
  line-height: 1.5;
  resize: vertical;
}

.form-input:focus,
.form-textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-glow);
}

/* ============================================================================
   Sidebar
   ============================================================================ */

.sidebar-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all 0.15s ease;
  margin-bottom: 4px;
}

.sidebar-item:hover {
  background: var(--bg-hover);
}

.sidebar-item.selected {
  background: var(--accent-glow);
  border: 1px solid var(--accent-dim);
}

.sidebar-item:not(.selected) {
  border: 1px solid transparent;
}

.sidebar-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  font-weight: 700;
  flex-shrink: 0;
}

.orchestrator-avatar {
  background: var(--bg-surface);
  font-size: 20px;
}

.sprite-avatar {
  color: white;
  font-size: 13px;
}

.sidebar-info {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.sidebar-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-status {
  font-size: 11px;
  color: var(--text-muted);
}

.sidebar-divider {
  height: 1px;
  background: var(--border-subtle);
  margin: 8px 0;
}

/* ============================================================================
   Empty State
   ============================================================================ */

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  text-align: center;
  color: var(--text-secondary);
}

.empty-icon {
  font-size: 64px;
  margin-bottom: 20px;
  opacity: 0.5;
}

.empty-state h2 {
  font-size: 22px;
  color: var(--text-primary);
  margin-bottom: 10px;
}

.empty-state p {
  max-width: 480px;
  line-height: 1.7;
}

/* ============================================================================
   Content Area — Cards
   ============================================================================ */

.content-area {
  max-width: 800px;
}

.content-section {
  margin-bottom: 28px;
}

.content-section-title {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 12px;
}

.card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 20px;
  margin-bottom: 12px;
  box-shadow: var(--shadow-card);
  transition: border-color 0.2s ease;
}

.card:hover {
  border-color: var(--border-active);
}

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

.card-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-primary);
}

.card-subtitle {
  font-size: 12px;
  color: var(--text-muted);
}

.card-body {
  font-size: 14px;
  color: var(--text-secondary);
  line-height: 1.7;
  white-space: pre-wrap;
}

.card-body p {
  margin-bottom: 8px;
}

.card-body p:last-child {
  margin-bottom: 0;
}

.card.collapsible .card-header {
  cursor: pointer;
}

.card.collapsible .card-body {
  display: none;
}

.card.collapsible.expanded .card-body {
  display: block;
}

.card-toggle {
  font-size: 12px;
  color: var(--text-muted);
  transition: transform 0.2s ease;
}

.card.collapsible.expanded .card-toggle {
  transform: rotate(90deg);
}

/* ============================================================================
   Chat Bubbles (Conversations)
   ============================================================================ */

.chat-container {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.chat-bubble {
  max-width: 80%;
  padding: 12px 16px;
  border-radius: var(--radius-lg);
  font-size: 14px;
  line-height: 1.6;
  white-space: pre-wrap;
  animation: fadeSlideIn 0.3s ease;
}

.chat-bubble.self {
  align-self: flex-end;
  background: var(--accent-dim);
  color: var(--text-primary);
  border-bottom-right-radius: 4px;
}

.chat-bubble.other {
  align-self: flex-start;
  background: var(--bg-surface);
  color: var(--text-primary);
  border-bottom-left-radius: 4px;
}

.chat-speaker {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
  margin-bottom: 4px;
}

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

/* ============================================================================
   Pairings Table
   ============================================================================ */

.pairings-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.pairings-table th {
  text-align: left;
  padding: 8px 12px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border-subtle);
}

.pairings-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  vertical-align: top;
}

.pairings-table tr:last-child td {
  border-bottom: none;
}

.pairings-table .prompt-cell {
  font-style: italic;
  color: var(--accent);
  line-height: 1.6;
}

/* ============================================================================
   Costume Image
   ============================================================================ */

.costume-image-container {
  text-align: center;
  margin: 16px 0;
}

.costume-image {
  max-width: 320px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-subtle);
  box-shadow: var(--shadow-card);
}

.group-image {
  max-width: 100%;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-subtle);
  box-shadow: var(--shadow-card);
}

/* ============================================================================
   Summary Grid (Orchestrator view — side by side)
   ============================================================================ */

.summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 12px;
}

.summary-grid .card {
  margin-bottom: 0;
}

/* ============================================================================
   Loading Spinner
   ============================================================================ */

.spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid var(--text-muted);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.spinner-large {
  width: 32px;
  height: 32px;
  border-width: 3px;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.loading-overlay {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 40px;
  color: var(--text-secondary);
}

/* ============================================================================
   Modal
   ============================================================================ */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
}

.modal {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-modal);
  width: 560px;
  max-width: 90vw;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
}

.modal-small {
  width: 400px;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px 0;
}

.modal-header h2 {
  font-size: 18px;
  font-weight: 700;
}

.modal-body {
  padding: 20px 24px;
  overflow-y: auto;
  flex: 1;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 16px 24px;
  border-top: 1px solid var(--border-subtle);
}

/* ============================================================================
   Toast Notifications
   ============================================================================ */

#toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 300;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 12px 20px;
  font-size: 13px;
  color: var(--text-primary);
  box-shadow: var(--shadow-card);
  animation: toastIn 0.3s ease;
  max-width: 380px;
}

.toast.toast-error {
  border-color: var(--error);
  color: var(--error);
}

.toast.toast-success {
  border-color: var(--success);
  color: var(--success);
}

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

/* ============================================================================
   Step Progress Indicator
   ============================================================================ */

.step-progress {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}

.step-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  transition: all 0.3s ease;
}

.step-dot.active {
  background: var(--accent);
  border-color: var(--accent);
  box-shadow: 0 0 8px var(--accent-glow);
}

.step-dot.done {
  background: var(--success);
  border-color: var(--success);
}

.step-connector {
  width: 20px;
  height: 1px;
  background: var(--border-subtle);
}

.step-label {
  font-size: 11px;
  color: var(--text-muted);
  margin-left: 8px;
}

.step-label.active {
  color: var(--accent);
  font-weight: 600;
}

/* ============================================================================
   Scrollbar
   ============================================================================ */

::-webkit-scrollbar {
  width: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--border-subtle);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

/* ============================================================================
   Reportback Styling
   ============================================================================ */

.reportback-content {
  font-size: 15px;
  line-height: 1.8;
  color: var(--text-primary);
  white-space: pre-wrap;
}

.reportback-content p {
  margin-bottom: 12px;
}

/* ============================================================================
   Utility
   ============================================================================ */

/* ============================================================================
   View Header
   ============================================================================ */

.view-header {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 24px;
}

.view-header h2 {
  font-size: 22px;
  font-weight: 700;
}

.view-header-avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  font-weight: 700;
  flex-shrink: 0;
}

h3 {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 12px;
  margin-top: 4px;
}

.prose {
  white-space: pre-wrap;
}

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

/* ============================================================================
   Pairing Row (card-style)
   ============================================================================ */

.pairing-row {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 14px 18px;
  margin-bottom: 8px;
}

.pairing-names {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 6px;
}

.pairing-prompt {
  font-size: 13px;
  font-style: italic;
  color: var(--accent);
  line-height: 1.6;
}

/* ============================================================================
   Chat (conversation-specific)
   ============================================================================ */

.convo-prompt {
  padding: 10px 14px;
  background: var(--bg-surface);
  border-radius: var(--radius-sm);
  color: var(--accent);
  font-size: 13px;
  margin-bottom: 16px;
}

.chat-left {
  align-self: flex-start;
  background: var(--bg-surface);
  border-bottom-left-radius: 4px;
}

.chat-right {
  align-self: flex-end;
  background: var(--accent-dim);
  border-bottom-right-radius: 4px;
}

.chat-name {
  font-size: 11px;
  font-weight: 700;
  margin-bottom: 4px;
}

.chat-text {
  white-space: pre-wrap;
  line-height: 1.6;
}

/* ============================================================================
   Conversation Summary
   ============================================================================ */

.convo-summary {
  margin-top: 16px;
  padding: 14px;
  background: var(--bg-surface);
  border-radius: var(--radius-md);
  font-size: 13px;
}

.convo-summary h4 {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.convo-summary p {
  margin-bottom: 4px;
  color: var(--text-secondary);
}

/* ============================================================================
   Highlight Cards
   ============================================================================ */

.card-highlight {
  border-color: var(--accent-dim);
  background: linear-gradient(135deg, var(--bg-card) 0%, rgba(124, 124, 255, 0.05) 100%);
}

.card-reportback {
  border-color: var(--success-dim);
  background: linear-gradient(135deg, var(--bg-card) 0%, rgba(34, 197, 94, 0.04) 100%);
}

.card-reportback .card-body {
  color: var(--text-primary);
  font-size: 15px;
  line-height: 1.8;
}

/* ============================================================================
   Party Image
   ============================================================================ */

.costume-image-container {
  text-align: center;
  margin-bottom: 8px;
}

.costume-image {
  max-width: 320px;
  border-radius: var(--radius-lg);
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
}

.party-image {
  max-width: 100%;
  border-radius: var(--radius-md);
}

/* ============================================================================
   Grid
   ============================================================================ */

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

@media (max-width: 900px) {
  .grid-2 {
    grid-template-columns: 1fr;
  }
}

/* ============================================================================
   Step Progress (updated)
   ============================================================================ */

.step-item {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 8px;
  border-radius: 12px;
  font-size: 11px;
  color: var(--text-muted);
}

.step-item .step-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--border-subtle);
  flex-shrink: 0;
}

.step-item.step-active {
  color: var(--accent);
  background: var(--accent-glow);
}

.step-item.step-active .step-dot {
  background: var(--accent);
  box-shadow: 0 0 6px var(--accent);
}

.step-item.step-done {
  color: var(--success);
}

.step-item.step-done .step-dot {
  background: var(--success);
}

/* Toast visibility */
.toast {
  opacity: 0;
  transition: opacity 0.3s ease;
}

.toast.show {
  opacity: 1;
}

.text-muted { color: var(--text-muted); }
.text-accent { color: var(--accent); }
.text-success { color: var(--success); }
.text-error { color: var(--error); }
.mt-4 { margin-top: 4px; }
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mb-8 { margin-bottom: 8px; }
.mb-16 { margin-bottom: 16px; }
.hidden { display: none !important; }
