:root {
  --bg-primary: #0b0f19;
  --bg-secondary: #131a2c;
  --border: #243049;
  --text-primary: #f3f4f6;
  --text-muted: #9ca3af;
  --accent-teal: #14b8a6;
  --accent-amber: #f59e0b;
  --accent-red: #ef4444;
  --accent-orange: #f97316;
  --accent-purple: #a855f7;
  --accent-slate: #64748b;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.5;
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* Layout */
#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

.hidden {
  display: none !important;
}

.overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.signin-panel {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 2rem;
  width: 100%;
  max-width: 400px;
}

.signin-panel h1 {
  margin: 0 0 1.5rem 0;
  font-size: 1.25rem;
  text-align: center;
}

.signin-panel form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.signin-panel label {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-muted);
}

.signin-panel input {
  padding: 0.75rem;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text-primary);
  font-size: 1rem;
}

.signin-panel input:focus {
  outline: 2px solid var(--accent-teal);
  outline-offset: 2px;
}

.error-text {
  color: var(--accent-red);
  font-size: 0.875rem;
  margin-top: 0.5rem;
}

/* Header */
.header {
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  padding: 1rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 2rem;
  flex-wrap: wrap;
}

.header-title {
  font-size: 1.125rem;
  font-weight: 600;
  white-space: nowrap;
}

.header-status {
  display: flex;
  align-items: center;
  gap: 2rem;
  flex: 1;
  min-width: 300px;
}

.status-counts {
  display: flex;
  gap: 1.5rem;
  font-size: 0.875rem;
}

.count-item {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

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

.count-value {
  font-weight: 600;
  color: var(--text-primary);
}

.status-info {
  display: flex;
  gap: 1rem;
  font-size: 0.875rem;
  color: var(--text-muted);
  align-items: center;
}

.status-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--accent-teal);
  flex-shrink: 0;
}

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

/* Buttons */
.btn {
  padding: 0.75rem 1.5rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.btn:focus {
  outline: 2px solid var(--accent-teal);
  outline-offset: 2px;
}

.btn-primary {
  background: var(--accent-teal);
  color: var(--bg-primary);
  border-color: var(--accent-teal);
}

.btn-primary:hover:not(:disabled) {
  background: #0d9488;
}

.btn-secondary {
  background: transparent;
  color: var(--text-primary);
}

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

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

/* Panel */
.panel {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 999;
}

.panel-content {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 2rem;
  width: 100%;
  max-width: 500px;
  max-height: 90vh;
  overflow-y: auto;
}

.panel-content h2 {
  margin: 0 0 1.5rem 0;
  font-size: 1.25rem;
}

.panel-content form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.panel-content label {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-muted);
}

.panel-content input,
.panel-content textarea {
  padding: 0.75rem;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text-primary);
  font-size: 1rem;
  font-family: inherit;
}

.panel-content input:focus,
.panel-content textarea:focus {
  outline: 2px solid var(--accent-teal);
  outline-offset: 2px;
}

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

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

#signal-result {
  margin-top: 1rem;
  padding: 1rem;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 0.875rem;
}

/* Main layout */
#main-layout {
  display: flex;
  flex-direction: column;
  flex: 1;
  overflow: hidden;
}

.layout-container {
  display: grid;
  grid-template-columns: 1fr 2fr 1fr;
  gap: 1px;
  flex: 1;
  overflow: hidden;
  background: var(--border);
}

.column {
  background: var(--bg-primary);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.column h2 {
  margin: 0;
  padding: 1rem 1.5rem;
  font-size: 1rem;
  font-weight: 600;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.column-signals {
  min-width: 250px;
}

.column-queue {
  min-width: 300px;
}

.column-log {
  min-width: 200px;
}

/* Tabs */
.tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.tab-btn {
  flex: 1;
  padding: 1rem;
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: all 0.2s;
}

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

.tab-btn.active {
  color: var(--accent-teal);
  border-bottom-color: var(--accent-teal);
}

.tab-btn:focus {
  outline: 2px solid var(--accent-teal);
  outline-offset: -2px;
}

/* Lists */
.list {
  flex: 1;
  overflow-y: auto;
  border-top: 1px solid var(--border);
}

.list-item {
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.2s;
}

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

.list-item.active {
  background: var(--bg-secondary);
  border-left: 3px solid var(--accent-teal);
  padding-left: calc(1.5rem - 3px);
}

.list-empty {
  padding: 2rem 1.5rem;
  color: var(--text-muted);
  text-align: center;
  font-size: 0.875rem;
}

.list-loading {
  padding: 2rem 1.5rem;
  color: var(--text-muted);
  text-align: center;
  font-size: 0.875rem;
}

/* Signal row */
.signal-row {
  display: flex;
  gap: 1rem;
  align-items: flex-start;
}

.signal-source {
  display: inline-block;
  padding: 0.25rem 0.75rem;
  border-radius: 3px;
  font-size: 0.75rem;
  font-weight: 600;
  white-space: nowrap;
  flex-shrink: 0;
  margin-top: 0.125rem;
}

.signal-source.hn {
  background: var(--accent-orange);
  color: var(--bg-primary);
}

.signal-source.reddit {
  background: var(--accent-red);
  color: white;
}

.signal-source.rss {
  background: var(--accent-amber);
  color: var(--bg-primary);
}

.signal-source.github {
  background: var(--accent-purple);
  color: white;
}

.signal-source.other {
  background: var(--accent-slate);
  color: white;
}

.signal-content {
  flex: 1;
  min-width: 0;
}

.signal-title {
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 0.5rem;
}

.signal-title a {
  color: var(--accent-teal);
  text-decoration: none;
}

.signal-title a:hover {
  text-decoration: underline;
}

.signal-meta {
  display: flex;
  gap: 1rem;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.signal-status {
  display: inline-block;
  padding: 0.25rem 0.5rem;
  border-radius: 3px;
  font-size: 0.75rem;
  font-weight: 500;
}

.signal-status.dropped {
  background: var(--accent-slate);
  color: white;
}

.signal-status.queued {
  background: var(--accent-amber);
  color: var(--bg-primary);
}

.signal-status.analyzed {
  background: var(--accent-teal);
  color: var(--bg-primary);
}

.signal-status.archived {
  background: var(--text-muted);
  color: var(--bg-primary);
}

.signal-status.error {
  background: var(--accent-red);
  color: white;
}

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

/* Proposal row */
.proposal-row {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.proposal-company {
  font-weight: 500;
}

.proposal-meta {
  display: flex;
  gap: 1rem;
  font-size: 0.875rem;
  color: var(--text-muted);
}

.proposal-tei {
  font-weight: 600;
  color: var(--accent-teal);
}

.proposal-tier {
  display: inline-block;
  padding: 0.25rem 0.5rem;
  background: var(--bg-secondary);
  border-radius: 3px;
  font-size: 0.75rem;
}

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

/* Editor */
.editor {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  padding: 1.5rem;
  overflow-y: auto;
}

.editor-header {
  display: flex;
  align-items: baseline;
  gap: 1rem;
  flex-wrap: wrap;
}

.editor-company {
  font-size: 1.25rem;
  font-weight: 600;
}

.editor-domain {
  color: var(--text-muted);
  font-size: 0.875rem;
}

.editor-tier {
  display: inline-block;
  padding: 0.25rem 0.75rem;
  background: var(--bg-secondary);
  border-radius: 3px;
  font-size: 0.75rem;
  font-weight: 500;
}

.editor-tei {
  font-weight: 600;
  color: var(--accent-teal);
}

.editor-section {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.editor-section-title {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

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

.tei-table th,
.tei-table td {
  padding: 0.75rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.tei-table th {
  font-weight: 600;
  color: var(--text-muted);
  background: var(--bg-secondary);
}

.tei-value {
  font-weight: 600;
  color: var(--accent-teal);
}

.tei-evidence {
  color: var(--text-muted);
  font-size: 0.8125rem;
}

.tei-evidence a {
  color: var(--accent-teal);
  text-decoration: none;
}

.tei-evidence a:hover {
  text-decoration: underline;
}

.editor-textarea-group {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.editor-textarea-group label {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-muted);
}

.editor-textarea-group textarea {
  padding: 0.75rem;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text-primary);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, monospace;
  font-size: 0.875rem;
  resize: vertical;
  min-height: 80px;
}

.editor-textarea-group textarea:focus {
  outline: 2px solid var(--accent-teal);
  outline-offset: 2px;
}

.char-count {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-align: right;
}

.claims-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  border-radius: 4px;
  font-size: 0.875rem;
  font-weight: 500;
}

.claims-badge.ok {
  background: rgba(20, 184, 166, 0.1);
  color: var(--accent-teal);
}

.claims-badge.verify {
  background: rgba(245, 158, 11, 0.1);
  color: var(--accent-amber);
}

.claims-badge.rewrite {
  background: rgba(239, 68, 68, 0.1);
  color: var(--accent-red);
}

.claims-findings {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-top: 0.75rem;
  padding: 0.75rem;
  background: var(--bg-secondary);
  border-radius: 4px;
  font-size: 0.875rem;
}

.finding {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.finding-quote {
  font-style: italic;
  color: var(--text-muted);
}

.finding-reason {
  color: var(--text-primary);
}

.finding-suggestion {
  color: var(--accent-amber);
}

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

.editor-actions .btn {
  flex: 1;
  min-width: 150px;
}

.lane-result {
  padding: 0.75rem;
  background: var(--bg-secondary);
  border-radius: 4px;
  font-size: 0.875rem;
  font-family: monospace;
  color: var(--text-muted);
  white-space: pre-wrap;
  word-break: break-word;
}

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

.storyboard-segment {
  display: flex;
  gap: 1rem;
  padding: 0.75rem;
  background: var(--bg-secondary);
  border-radius: 4px;
  border-left: 3px solid var(--accent-teal);
}

.storyboard-time {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 600;
  white-space: nowrap;
  padding-top: 0.125rem;
}

.storyboard-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.storyboard-title {
  font-weight: 500;
  font-size: 0.875rem;
}

.storyboard-detail {
  font-size: 0.8125rem;
  color: var(--text-muted);
}

/* Audit log */
.log-entry {
  padding: 0.75rem 1.5rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.8125rem;
  font-family: monospace;
  display: flex;
  gap: 0.75rem;
  align-items: flex-start;
}

.log-marker {
  flex-shrink: 0;
  width: 1rem;
  text-align: center;
  font-weight: 600;
}

.log-marker.alarm {
  color: var(--accent-red);
}

.log-marker.normal {
  color: var(--accent-teal);
}

.log-text {
  flex: 1;
  word-break: break-word;
  color: var(--text-muted);
}

/* Toast */
.toast {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1rem 1.5rem;
  font-size: 0.875rem;
  z-index: 2000;
  max-width: 90%;
  animation: slideUp 0.3s ease-out;
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateX(-50%) translateY(1rem);
  }
  to {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
  }
}

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

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

/* Responsive */
@media (max-width: 1000px) {
  .layout-container {
    grid-template-columns: 1fr;
  }

  .column {
    display: none;
  }

  .column.active {
    display: flex;
  }

  .tabs {
    display: flex;
  }

  .tab-btn {
    flex: 1;
  }
}

@media (max-width: 640px) {
  .header {
    flex-direction: column;
    align-items: flex-start;
    gap: 1rem;
  }

  .header-status {
    flex-direction: column;
    gap: 0.75rem;
    width: 100%;
  }

  .status-counts {
    flex-wrap: wrap;
    gap: 1rem;
  }

  .header-actions {
    width: 100%;
  }

  .header-actions .btn {
    flex: 1;
  }

  .panel-content {
    margin: 1rem;
  }

  .signin-panel {
    margin: 1rem;
  }
}

/* Layout fixes after browser review: header never overlaps, queue and editor share the middle column */
.header { gap: 0.75rem 1.5rem; }
.header-status { flex-wrap: wrap; gap: 0.5rem 1.5rem; min-width: 0; flex: 1 1 320px; }
.status-counts { flex-wrap: wrap; gap: 0.25rem 1rem; }
.status-info { flex-wrap: wrap; gap: 0.25rem 1rem; }
.header-actions { flex-shrink: 0; }
.column-queue { min-height: 0; }
.column-queue #queue-list { flex: 0 0 auto; min-height: 4.5rem; max-height: 26%; overflow-y: auto; border-bottom: 1px solid var(--border); }
.column-queue .editor { flex: 1 1 auto; min-height: 0; overflow-y: auto; }
.column-signals .list, .column-log .list { overflow-y: auto; min-height: 0; }
.editor-links { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
