/* Feedback UI Wireframe — Web App */

:root {
  --bg: #f8f9fa;
  --surface: #fff;
  --border: #dee2e6;
  --text: #212529;
  --text-muted: #6c757d;
  --primary: #0d6efd;
  --primary-hover: #0b5ed7;
  --success: #198754;
  --danger: #dc3545;
  --radius: 6px;
  --shadow: 0 1px 3px rgba(0,0,0,0.08);
  --indent: 1.25rem;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
}

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

/* Header */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.5rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.app-title {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 600;
}

.nav-link {
  color: var(--primary);
  text-decoration: none;
}

.nav-link:hover {
  text-decoration: underline;
}

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

.view {
  animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* Query view */
.query-input-block label {
  display: block;
  font-weight: 500;
  margin-bottom: 0.5rem;
}

#question-input {
  width: 100%;
  padding: 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font: inherit;
  resize: vertical;
  margin-bottom: 1rem;
}

#question-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(13, 110, 253, 0.15);
}

/* Buttons */
.btn {
  padding: 0.5rem 1rem;
  border: 1px solid transparent;
  border-radius: var(--radius);
  font: inherit;
  cursor: pointer;
  background: var(--surface);
  color: var(--text);
}

.btn:hover {
  background: #e9ecef;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}

.btn-primary:hover {
  background: var(--primary-hover);
}

.btn-secondary {
  border-color: var(--border);
}

.btn-small {
  padding: 0.35rem 0.65rem;
  font-size: 0.875rem;
}

.btn-icon {
  padding: 0.4rem 0.6rem;
  margin: 0 0.25rem;
}

/* Result view */
.question-display {
  margin-bottom: 1.5rem;
}

.question-display h2,
.answer-card h2,
.trace-section h2 {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-muted);
  margin: 0 0 0.5rem 0;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.question-text {
  font-size: 1.1rem;
  margin: 0 0 0.75rem 0;
  padding: 0.75rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.answer-card {
  margin-bottom: 1.5rem;
  padding: 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.answer-content {
  white-space: pre-wrap;
  margin-bottom: 0.75rem;
}

/* Run feedback */
.run-feedback {
  margin-bottom: 1.5rem;
  padding: 0.75rem 0;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}

.feedback-label {
  margin-right: 0.5rem;
  font-weight: 500;
}

.run-feedback .btn-icon {
  vertical-align: middle;
}

.feedback-text {
  margin-top: 0.5rem;
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.feedback-text input {
  flex: 1;
  max-width: 320px;
  padding: 0.4rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font: inherit;
}

/* Trace section */
.trace-section {
  margin-top: 1.5rem;
}

.trace-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.trace-actions {
  display: flex;
  gap: 0.5rem;
}

.trace-tree {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  overflow: hidden;
}

/* Run summary card */
.run-summary-card {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
}

.run-summary-card .summary-title {
  font-size: 1.05rem;
  margin-bottom: 0.5rem;
}

.run-summary-card .summary-sequence {
  font-size: 0.95rem;
  line-height: 1.8;
  margin: 0.75rem 0;
  padding: 0.5rem 0;
}

.run-summary-card .summary-exit {
  color: var(--success);
  font-weight: 500;
  margin: 0.5rem 0;
}

.run-summary-card .summary-memory {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-top: 0.5rem;
}

.run-summary-card .summary-line {
  margin: 0.25rem 0;
  color: var(--text);
}

.run-summary-card .summary-meta {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-top: 0.5rem;
}

/* Sequential searches container */
.trace-searches {
  padding: 1rem 1.25rem;
}

/* Search block */
.search-block {
  margin-bottom: 1.5rem;
  padding: 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.search-block:last-child {
  margin-bottom: 0;
}

.search-header {
  font-size: 1.05rem;
  font-weight: 600;
  margin-bottom: 0.75rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.search-query {
  font-style: italic;
  padding: 0.5rem 0.75rem;
  background: #f8f9fa;
  border-radius: 4px;
  margin: 0.5rem 0;
  border-left: 3px solid var(--primary);
}

.search-context {
  font-size: 0.9rem;
  color: var(--text-muted);
  margin: 0.75rem 0;
  padding: 0.5rem 0.75rem;
  background: #f8f9fa;
  border-radius: 4px;
  line-height: 1.6;
}

.search-context .context-label {
  font-weight: 600;
  color: var(--text);
}

/* Memory badge */
.memory-badge {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin: 0.75rem 0;
  padding: 0.4rem 0.6rem;
  background: #e7f5ff;
  border: 1px solid #a5d8ff;
  border-radius: 4px;
  display: inline-block;
}

.memory-badge.warning {
  background: #fff3cd;
  border-color: #ffc107;
  color: #664d03;
}

/* Summarization event */
.summarization-event {
  margin: 0.75rem 0;
  padding: 0.75rem;
  background: #fff3cd;
  border: 1px solid #ffc107;
  border-radius: 4px;
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.summarization-event .icon {
  font-size: 1.1rem;
}

.summarization-event .detail {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-left: 1.5rem;
}

.summarization-event .toggle-btn {
  margin-left: auto;
  padding: 0.25rem 0.5rem;
  font-size: 0.8rem;
}

.summarization-event.technical {
  background: #f8d7da;
  border-color: #dc3545;
}

/* Summarization detail */
.summarization-detail {
  margin: 1rem 0;
  padding: 1rem;
  background: #fffbf0;
  border: 1px solid #ffc107;
  border-radius: 4px;
}

.sum-title {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 0.75rem;
}

.sum-explanation,
.sum-action,
.sum-before-after {
  font-size: 0.9rem;
  margin: 0.5rem 0;
}

.sum-facts-section {
  margin: 1rem 0;
}

.sum-facts-label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 0.35rem;
}

.sum-facts-list {
  list-style: disc;
  padding-left: 1.5rem;
  margin: 0.35rem 0;
}

.sum-facts-list li {
  font-size: 0.85rem;
  margin: 0.25rem 0;
  line-height: 1.5;
}

.summarization-feedback {
  margin-top: 1rem;
  padding-top: 0.75rem;
  border-top: 1px solid rgba(255, 193, 7, 0.4);
}

.summarization-feedback .btn {
  font-size: 0.85rem;
}

.summarization-feedback-form label {
  display: block;
  font-size: 0.9rem;
  font-weight: 500;
  margin-bottom: 0.35rem;
}

.summarization-feedback-form textarea {
  width: 100%;
  max-width: 100%;
  padding: 0.5rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font: inherit;
  resize: vertical;
  margin-bottom: 0.5rem;
}

.summarization-feedback-actions {
  display: flex;
  gap: 0.5rem;
}

/* Search expand controls */
.search-expand {
  margin-top: 0.75rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.search-expand .toggle-btn {
  font-size: 0.85rem;
  padding: 0.35rem 0.65rem;
}

.search-expand .no-facts {
  font-size: 0.85rem;
  color: var(--text-muted);
  padding: 0.35rem 0;
}

/* Search tabs (Findings | Retrieved documents) */
.search-tabs-wrapper {
  margin-top: 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #f8f9fa;
  overflow: hidden;
}

.search-tabs {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  padding: 0 0.25rem;
}

.search-tab {
  padding: 0.5rem 1rem;
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text-muted);
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  cursor: pointer;
  font: inherit;
}

.search-tab:hover {
  color: var(--text);
}

.search-tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

.search-tab-panels {
  padding: 0.75rem 1rem;
  background: var(--surface);
  min-height: 2rem;
}

.search-tab-panel.facts-list,
.search-tab-panel.documents-list {
  margin: 0;
  padding: 0;
  border: none;
  background: transparent;
}

/* Add missing fact */
.add-missing-fact {
  margin-top: 1rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
}

.add-missing-fact .btn-secondary {
  font-size: 0.85rem;
}

.add-missing-form {
  margin-top: 0.75rem;
  padding: 1rem;
  background: #f8f9fa;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.add-missing-form label {
  display: block;
  font-size: 0.9rem;
  font-weight: 500;
  margin-top: 0.75rem;
  margin-bottom: 0.35rem;
}

.add-missing-form label:first-child {
  margin-top: 0;
}

.add-missing-form textarea,
.add-missing-form select {
  width: 100%;
  max-width: 100%;
  padding: 0.5rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font: inherit;
  margin-bottom: 0.25rem;
}

.add-missing-form select {
  cursor: pointer;
}

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

/* Technical toggle button */
#toggle-technical {
  background: #e9ecef;
  border: 1px solid var(--border);
}

#toggle-technical:hover {
  background: #dee2e6;
}

.toggle-btn {
  margin-top: 0.5rem;
  padding: 0.35rem 0.65rem;
  font-size: 0.875rem;
  color: var(--primary);
  background: none;
  border: none;
  cursor: pointer;
  font: inherit;
}

.toggle-btn:hover {
  text-decoration: underline;
}

.toggle-btn .icon {
  display: inline-block;
  transition: transform 0.15s ease;
}

.toggle-btn.expanded .icon {
  transform: rotate(90deg);
}

/* State row */
.state-row {
  border-bottom: 1px solid var(--border);
}

.state-row:last-child {
  border-bottom: none;
}

.state-row-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem 1.25rem;
  cursor: pointer;
  background: #fafbfc;
  user-select: none;
}

.state-row-header:hover {
  background: #f1f3f5;
}

.state-row-header .toggle-btn {
  margin: 0;
  padding: 0.2rem 0.4rem;
  margin-right: 0.25rem;
}

.state-name {
  font-weight: 600;
  margin-right: 0.35rem;
}

.state-meta {
  color: var(--text-muted);
  font-size: 0.9rem;
}

.badge {
  display: inline-block;
  padding: 0.2rem 0.5rem;
  font-size: 0.75rem;
  font-weight: 500;
  border-radius: 4px;
  background: #e9ecef;
  color: var(--text);
}

.badge-success {
  background: #d1e7dd;
  color: #0f5132;
}

.badge-warning {
  background: #fff3cd;
  color: #664d03;
}

.state-feedback {
  margin-left: auto;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.state-row-content {
  padding: 0 1.25rem 1rem 2.5rem;
  border-left: 3px solid var(--border);
  margin-left: 1.25rem;
}

/* Iteration block */
.iteration-block {
  margin-bottom: 1rem;
  padding: 0.75rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.iteration-block:last-child {
  margin-bottom: 0;
}

.iteration-query {
  font-style: italic;
  padding: 0.5rem 0.75rem;
  background: #f8f9fa;
  border-radius: 4px;
  margin: 0.5rem 0;
  border-left: 3px solid var(--primary);
}

.iteration-rationale {
  font-size: 0.9rem;
  color: var(--text-muted);
  margin: 0.5rem 0;
}

.iteration-rationale .show-more {
  color: var(--primary);
  cursor: pointer;
  font-size: 0.85rem;
}

.iteration-badges {
  margin: 0.5rem 0;
}

.iteration-badges .badge {
  margin-right: 0.35rem;
}

.iteration-expand {
  margin-top: 0.5rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.iteration-expand .toggle-btn {
  font-size: 0.85rem;
}

.iteration-feedback {
  margin-top: 0.5rem;
  font-size: 0.85rem;
  color: var(--text-muted);
}

/* Facts list */
.facts-list,
.documents-list {
  margin-top: 0.75rem;
  padding: 0.5rem 0;
}

.fact-item,
.doc-item {
  padding: 0.6rem 0.75rem;
  margin-bottom: 0.5rem;
  background: #f8f9fa;
  border-radius: 4px;
  border: 1px solid var(--border);
}

.fact-item:last-child,
.doc-item:last-child {
  margin-bottom: 0;
}

.fact-text,
.doc-text {
  font-size: 0.9rem;
  margin-bottom: 0.35rem;
}

.fact-text.truncated {
  max-height: 3.6em;
  overflow: hidden;
  text-overflow: ellipsis;
}

.doc-id {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-family: ui-monospace, monospace;
  margin-bottom: 0.25rem;
}

.doc-score,
.doc-refs {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 0.2rem;
}

.fact-support {
  font-size: 0.8rem;
  color: var(--primary);
  cursor: pointer;
  margin-top: 0.25rem;
}

.fact-support:hover {
  text-decoration: underline;
}

.item-feedback {
  margin-top: 0.5rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  align-items: center;
}

.item-feedback .btn-small {
  font-size: 0.8rem;
}

.item-feedback input {
  flex: 1;
  min-width: 120px;
  padding: 0.3rem 0.5rem;
  font-size: 0.85rem;
  border: 1px solid var(--border);
  border-radius: 4px;
}

/* Footer */
.app-footer {
  padding: 0.75rem 1.5rem;
  text-align: center;
  font-size: 0.85rem;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
  background: var(--surface);
}

/* Responsive */
@media (max-width: 640px) {
  .app-main {
    padding: 1rem;
  }

  .state-row-header {
    padding: 0.6rem 1rem;
  }

  .state-row-content {
    margin-left: 0.75rem;
    padding-left: 1rem;
  }

  .trace-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .search-block {
    padding: 0.75rem;
  }

  .search-header {
    font-size: 0.95rem;
  }

  .search-context {
    font-size: 0.85rem;
  }
}
