* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  background: linear-gradient(160deg, #f0f4f8 0%, #e2e8f0 100%);
  min-height: 100vh;
  color: #1e293b;
}

.app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* App bar */
.app-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.75rem 1.5rem;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

.app-bar .brand {
  color: #1e293b;
  text-decoration: none;
  font-weight: 600;
  font-size: 1.125rem;
}

.app-bar .brand:hover {
  color: #2563eb;
}

.tabs {
  display: flex;
  gap: 0.25rem;
}

.tabs button {
  padding: 0.5rem 1rem;
  border: none;
  border-radius: 6px;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  background: transparent;
  color: #64748b;
}

.tabs button:hover {
  background: #f1f5f9;
  color: #334155;
}

.tabs button.active {
  background: #2563eb;
  color: #fff;
}

.user-section {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.user-badge {
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.8125rem;
  color: #64748b;
  padding: 0.35rem 0.6rem;
  background: #f1f5f9;
  border-radius: 6px;
}

.logout-btn {
  padding: 0.4rem 0.9rem;
  font-size: 0.8125rem;
  font-weight: 500;
  color: #64748b;
  background: transparent;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  cursor: pointer;
}

.logout-btn:hover {
  background: #fef2f2;
  color: #b91c1c;
  border-color: #fecaca;
}

/* Main content */
.main-content {
  flex: 1;
  padding: 1.5rem;
  max-width: 960px;
  margin: 0 auto;
  width: 100%;
}

.main-content .panel {
  background: #fff;
  border-radius: 10px;
  padding: 1.25rem;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
  min-height: 200px;
}

/* Sign-in view */
.sign-in-view {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  text-align: center;
}

.sign-in-card {
  background: #fff;
  border-radius: 12px;
  padding: 2rem;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
  max-width: 400px;
  width: 100%;
}

.sign-in-card h2 {
  margin: 0 0 0.5rem 0;
  font-size: 1.25rem;
}

.sign-in-card .message {
  margin: 0 0 1.5rem 0;
  font-size: 0.9375rem;
  color: #64748b;
}

.sign-in-card .login-form label {
  display: block;
  text-align: left;
  margin-bottom: 1rem;
}

.sign-in-card .login-form input {
  display: block;
  width: 100%;
  padding: 0.5rem 0.75rem;
  margin-top: 0.25rem;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
}

.sign-in-card .login-form .error {
  color: #b91c1c;
  font-size: 0.875rem;
  margin-bottom: 0.5rem;
}

.sign-in-card .btn-primary {
  display: block;
  width: 100%;
  padding: 0.6rem 1rem;
  margin-top: 1rem;
  font-size: 0.9375rem;
  font-weight: 500;
  color: #fff;
  background: #2563eb;
  border: none;
  border-radius: 8px;
  cursor: pointer;
}

.sign-in-card .btn-primary:hover {
  background: #1d4ed8;
}

.sign-in-card .btn-primary:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

/* Loading */
.loading-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  padding: 2rem;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid #e2e8f0;
  border-top-color: #2563eb;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* Chat */
.chat-container {
  display: flex;
  flex-direction: column;
  height: 560px;
}

.chat-toolbar {
  margin-bottom: 0.5rem;
}

.chat-toolbar select {
  padding: 0.25rem 0.5rem;
  border: 1px solid #e2e8f0;
  border-radius: 4px;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 0.5rem 0;
}

.chat-messages .bubble {
  margin: 0.5rem 0;
}

.chat-messages .bubble.user {
  text-align: right;
}

.chat-messages .bubble .content {
  display: inline-block;
  max-width: 85%;
  padding: 0.75rem 1rem;
  border-radius: 12px;
  white-space: pre-wrap;
  text-align: left;
}

.chat-messages .bubble.user .content {
  background: #2563eb;
  color: #fff;
}

.chat-messages .bubble.assistant .content {
  background: #f1f5f9;
}

.chat-messages .bubble.assistant .message-flow {
  font-size: 0.8125rem;
  color: #64748b;
  margin-top: 0.4rem;
  margin-bottom: 0.35rem;
}

.chat-messages .meta {
  font-size: 0.75rem;
  color: #64748b;
  margin-top: 0.25rem;
}

.chat-messages .rate-btn,
.chat-messages .edit-feedback-btn {
  margin-top: 0.25rem;
  margin-left: 0.5rem;
  padding: 0.25rem 0.5rem;
  font-size: 0.75rem;
  border: none;
  border-radius: 4px;
  cursor: pointer;
}

.chat-messages .rate-btn {
  background: #f59e0b;
  color: #fff;
}

.chat-messages .edit-feedback-btn {
  background: #64748b;
  color: #fff;
}

.chat-messages .edit-feedback-btn:hover {
  background: #475569;
}

.chat-messages .rated-badge {
  font-size: 0.75rem;
  color: #64748b;
  font-style: italic;
}

.chat-messages .bubble.rated .content {
  background: #f1f5f9;
  border-left: 3px solid #94a3b8;
}

.chat-thinking {
  margin-top: 0.5rem;
  font-size: 0.8125rem;
  color: #64748b;
}

.chat-thinking summary {
  cursor: pointer;
}

.chat-thinking ul {
  margin: 0.25rem 0 0 1rem;
  padding-left: 1rem;
}

.chat-thinking.workflow-live summary.workflow-summary {
  font-weight: 500;
  color: #334155;
}

.chat-thinking .workflow-label {
  color: #2563eb;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.chat-thinking .workflow-steps {
  list-style: none;
  padding-left: 0;
  margin: 0.5rem 0 0 0;
}

.chat-thinking .workflow-step {
  padding: 0.35rem 0.5rem;
  margin-bottom: 0.25rem;
  border-radius: 6px;
  border-left: 3px solid #e2e8f0;
  background: #f8fafc;
}

.chat-thinking .workflow-step .step-num {
  color: #64748b;
  margin-right: 0.35rem;
}

.chat-thinking .workflow-step.workflow-plan {
  border-left-color: #8b5cf6;
  background: #f5f3ff;
}

.chat-thinking .workflow-step.workflow-call {
  border-left-color: #2563eb;
  background: #eff6ff;
}

.chat-thinking .workflow-step.workflow-result {
  border-left-color: #059669;
  background: #ecfdf5;
}

.chat-thinking .workflow-step.workflow-status {
  border-left-color: #f59e0b;
  background: #fffbeb;
}

.chat-thinking .step-args {
  color: #64748b;
  font-size: 0.75rem;
}

.chat-input-row {
  display: flex;
  gap: 0.5rem;
  margin-top: 1rem;
}

.chat-input-row textarea {
  flex: 1;
  padding: 0.5rem;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  resize: none;
  min-height: 44px;
}

.chat-input-row button {
  padding: 0.5rem 1rem;
  background: #2563eb;
  color: #fff;
  border: none;
  border-radius: 6px;
  cursor: pointer;
}

.chat-input-row button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Peer review */
.peer-toolbar {
  margin-bottom: 1rem;
}

.peer-toolbar label {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}

.peer-list {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.peer-card {
  padding: 1rem;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  background: #f9fafb;
}

.peer-from {
  font-size: 0.8125rem;
  color: #64748b;
  margin-bottom: 0.5rem;
}

.peer-chat-thread {
  background: #f8fafc;
  border-radius: 6px;
  padding: 0.75rem;
  margin-bottom: 0.75rem;
  max-height: 280px;
  overflow-y: auto;
}

.peer-chat-bubble {
  font-size: 0.875rem;
  margin-bottom: 0.5rem;
  padding: 0.35rem 0;
  border-bottom: 1px solid #e2e8f0;
}

.peer-chat-bubble:last-child {
  border-bottom: none;
}

.peer-chat-bubble.user {
  color: #1e40af;
}

.peer-chat-bubble.assistant {
  color: #334155;
}

.peer-chat-bubble.peer-rate-target {
  background: #fef3c7;
  margin: 0 -0.5rem;
  padding: 0.5rem;
  border-radius: 4px;
  border: 1px solid #f59e0b;
}

.peer-rate-hint {
  font-size: 0.75rem;
  color: #b45309;
}

.peer-actions {
  margin-top: 0.5rem;
}

.peer-card .prompt,
.peer-card .response {
  font-size: 0.875rem;
  margin-bottom: 0.5rem;
}

.peer-card .rate-btn,
.peer-card .edit-feedback-btn {
  padding: 0.25rem 0.5rem;
  font-size: 0.75rem;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  margin-right: 0.5rem;
}

.peer-card .rate-btn {
  background: #f59e0b;
  color: #fff;
}

.peer-card .edit-feedback-btn {
  background: #64748b;
  color: #fff;
}

.peer-card.rated {
  background: #f1f5f9;
  border-color: #cbd5e1;
}

.peer-card .rated-badge {
  font-size: 0.75rem;
  color: #64748b;
  font-style: italic;
  margin-right: 0.5rem;
}

.empty-state {
  padding: 2rem;
  text-align: center;
  color: #64748b;
}

/* Admin */
.admin-section {
  margin-bottom: 2rem;
}

.admin-section h2 {
  font-size: 1.125rem;
  margin: 0 0 1rem 0;
}

.admin-form {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.admin-form input,
.admin-form select {
  padding: 0.5rem;
  border: 1px solid #e2e8f0;
  border-radius: 4px;
}

.admin-form button {
  padding: 0.5rem 1rem;
  background: #2563eb;
  color: #fff;
  border: none;
  border-radius: 4px;
  cursor: pointer;
}

.admin-error {
  color: #b91c1c;
  font-size: 0.875rem;
  margin-bottom: 0.5rem;
}

.admin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

.admin-table th,
.admin-table td {
  padding: 0.5rem;
  border: 1px solid #e5e7eb;
  text-align: left;
}

.admin-table th {
  background: #f3f4f6;
}

.user-list {
  list-style: none;
  padding: 0;
}

.user-list li {
  padding: 0.25rem 0;
}

/* Rating modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal {
  background: #fff;
  padding: 1.5rem;
  border-radius: 8px;
  max-width: 400px;
  width: 90%;
}

.modal h3 {
  margin: 0 0 0.5rem 0;
}

.modal .preview {
  font-size: 0.875rem;
  color: #64748b;
  margin: 0 0 1rem 0;
}

.modal .rating-label {
  display: block;
  font-weight: 500;
  margin: 0 0 0.35rem 0;
}

.modal .rating-btn-group {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-bottom: 1rem;
}

.modal .rating-btn {
  padding: 0.45rem 0.75rem;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  background: #f8fafc;
  cursor: pointer;
  font-size: 0.875rem;
}

.modal .rating-btn:hover {
  background: #f1f5f9;
  border-color: #cbd5e1;
}

.modal .rating-btn.selected {
  background: #2563eb;
  color: #fff;
  border-color: #2563eb;
}

.modal label {
  display: block;
  margin-bottom: 1rem;
}

.modal label input,
.modal label select,
.modal label textarea {
  display: block;
  width: 100%;
  margin-top: 0.25rem;
  padding: 0.5rem;
  border: 1px solid #e2e8f0;
  border-radius: 4px;
}

.modal label textarea#rating-feedback {
  margin-bottom: 0.5rem;
}

.modal .actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 1rem;
}

.modal .btn-cancel {
  padding: 0.5rem 1rem;
  border: 1px solid #e2e8f0;
  border-radius: 4px;
  background: #fff;
  cursor: pointer;
}

.modal .btn-submit {
  padding: 0.5rem 1rem;
  background: #2563eb;
  color: #fff;
  border: none;
  border-radius: 4px;
  cursor: pointer;
}

.modal .btn-submit:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.hidden {
  display: none !important;
}
