:root {
  --bg: #ffffff;
  --bg-elevated: #f8f9fa;
  --bg-card: #ffffff;
  --border: #e2e8f0;
  --border-hover: #cbd5e1;
  --text: #1a1a1a;
  --text-secondary: #4a5568;
  --text-muted: #718096;
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --primary-muted: rgba(79, 70, 229, 0.1);
  --success: #059669;
  --success-muted: rgba(5, 150, 105, 0.1);
  --warning: #d97706;
  --warning-muted: rgba(217, 119, 6, 0.1);
  --error: #dc2626;
  --error-muted: rgba(220, 38, 38, 0.1);
  --radius: 8px;
  --radius-lg: 12px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.1), 0 1px 2px rgba(0, 0, 0, 0.06);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.1);
  --transition: 150ms ease;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background: var(--bg-elevated);
  color: var(--text);
  line-height: 1.7;
  min-height: 100vh;
  font-size: 16px;
}

.app {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 32px;
}

/* Header */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 24px 0;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  margin: 0 -32px;
  padding-left: 32px;
  padding-right: 32px;
}

.logo {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo h1 {
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.02em;
}

/* User Menu */
.user-menu {
  display: none;
  align-items: center;
  gap: 12px;
}

.user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid var(--border);
}

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

.logout-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: var(--radius);
  color: var(--text-muted);
  background: var(--bg);
  border: 1px solid var(--border);
  cursor: pointer;
  transition: all var(--transition);
  text-decoration: none;
}

.logout-btn:hover {
  color: var(--error);
  border-color: var(--error);
  background: var(--error-muted);
}

/* Main */
.main {
  padding: 40px 0;
}

/* Query Section */
.query-section {
  margin-bottom: 40px;
  background: var(--bg);
  padding: 28px;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}

.query-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.input-group textarea {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  color: var(--text);
  font-size: 17px;
  font-family: inherit;
  resize: vertical;
  min-height: 100px;
  transition: border-color var(--transition), box-shadow var(--transition);
  box-shadow: var(--shadow);
}

.input-group textarea::placeholder {
  color: var(--text-muted);
}

.input-group textarea:hover {
  border-color: var(--border-hover);
}

.input-group textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-muted);
}

.options-row {
  display: flex;
  gap: 16px;
}

.option-group {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.option-group label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
}

.option-group select,
.option-group input {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  color: var(--text);
  font-size: 14px;
  transition: border-color var(--transition);
}

.option-group select:hover,
.option-group input:hover {
  border-color: var(--border-hover);
}

.option-group select:focus,
.option-group input:focus {
  outline: none;
  border-color: var(--primary);
}

.option-group input::placeholder {
  color: var(--text-muted);
}

.submit-row {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 16px;
}

.submit-hint {
  font-size: 13px;
  color: var(--text-muted);
}

.submit-btn {
  background: var(--primary);
  color: white;
  border: none;
  border-radius: var(--radius);
  padding: 14px 36px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition), transform var(--transition);
  display: flex;
  align-items: center;
  gap: 8px;
  box-shadow: var(--shadow-md);
}

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

.submit-btn:active:not(:disabled) {
  transform: scale(0.98);
}

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

.submit-btn .btn-loading {
  display: none;
}

.submit-btn.loading .btn-loading {
  display: flex;
}

.spinner {
  width: 20px;
  height: 20px;
  animation: spin 1s linear infinite;
}

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

/* Results Section */
.results-section {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.results-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
}

.results-header h2 {
  font-size: 20px;
  font-weight: 600;
  color: var(--text);
}

.meta-badges {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 500;
}

.badge.product {
  background: var(--primary-muted);
  color: var(--primary);
}

.badge.type {
  background: var(--success-muted);
  color: var(--success);
}

.badge.tool {
  background: var(--warning-muted);
  color: var(--warning);
}

/* Result Cards */
.result-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-elevated);
}

.card-header h3 {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
}

.copy-btn {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 14px;
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
}

.copy-btn:hover {
  border-color: var(--primary);
  color: var(--primary);
  background: var(--primary-muted);
}

.copy-btn.copied {
  border-color: var(--success);
  color: var(--success);
  background: var(--success-muted);
}

.card-content {
  padding: 20px;
  font-size: 16px;
  line-height: 1.7;
  color: var(--text-secondary);
}

.card-content.preserve-whitespace {
  white-space: pre-wrap;
}

.card-content code {
  background: var(--bg-elevated);
  padding: 3px 8px;
  border-radius: 4px;
  font-family: 'SF Mono', Monaco, 'Cascadia Code', monospace;
  font-size: 14px;
  color: var(--text);
}

/* Engineer Details Timeline */
.details-section-header {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  margin-top: 20px;
  margin-bottom: 12px;
}

.details-section-header:first-child {
  margin-top: 0;
}

.details-paragraph {
  font-size: 15px;
  line-height: 1.7;
  color: var(--text-secondary);
  margin-bottom: 12px;
}

.details-paragraph:last-child {
  margin-bottom: 0;
}

.timeline {
  position: relative;
  padding-left: 28px;
  margin: 16px 0;
}

.timeline::before {
  content: '';
  position: absolute;
  left: 7px;
  top: 8px;
  bottom: 8px;
  width: 2px;
  background: linear-gradient(to bottom, var(--primary), var(--primary-muted));
  border-radius: 1px;
}

.timeline-item {
  position: relative;
  padding: 12px 0;
  display: flex;
  align-items: flex-start;
  gap: 16px;
}

.timeline-item:first-child {
  padding-top: 0;
}

.timeline-item:last-child {
  padding-bottom: 0;
}

.timeline-dot {
  position: absolute;
  left: -28px;
  top: 18px;
  width: 16px;
  height: 16px;
  background: var(--bg-card);
  border: 3px solid var(--primary);
  border-radius: 50%;
  flex-shrink: 0;
  box-shadow: 0 0 0 4px var(--bg-card);
}

.timeline-item:first-child .timeline-dot {
  top: 6px;
}

.timeline-content {
  flex: 1;
  font-size: 15px;
  line-height: 1.7;
  color: var(--text-secondary);
  background: var(--bg-elevated);
  padding: 14px 18px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

/* Files List */
.file-item {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  padding: 16px 0;
  border-bottom: 1px solid var(--border);
}

.file-item:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.file-item:first-child {
  padding-top: 0;
}

.file-icon {
  color: var(--primary);
  flex-shrink: 0;
  margin-top: 3px;
}

.file-ref-number {
  font-family: 'SF Mono', Monaco, monospace;
  font-size: 14px;
  font-weight: 600;
  color: var(--primary);
  background: var(--primary-muted);
  padding: 4px 8px;
  border-radius: 4px;
  flex-shrink: 0;
}

.file-info {
  flex: 1;
  min-width: 0;
}

.file-path {
  font-family: 'SF Mono', Monaco, monospace;
  font-size: 14px;
  color: var(--text);
  word-break: break-all;
}

.file-lines {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 4px;
}

.file-excerpt {
  margin-top: 12px;
  background: var(--bg-elevated);
  border-radius: var(--radius);
  padding: 16px;
  font-family: 'SF Mono', Monaco, monospace;
  font-size: 13px;
  overflow-x: auto;
  white-space: pre;
  color: var(--text-secondary);
  border: 1px solid var(--border);
}

/* Sources List */
.source-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}

.source-item:first-child {
  padding-top: 0;
}

.source-item:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.source-badge {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  padding: 4px 10px;
  border-radius: 4px;
  background: var(--bg-elevated);
  color: var(--text-muted);
}

.source-label {
  flex: 1;
  font-size: 15px;
}

.source-link {
  color: var(--primary);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
}

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

/* Empty State */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  text-align: center;
  background: var(--bg);
  border-radius: var(--radius-lg);
  border: 1px dashed var(--border);
}

.empty-title {
  font-size: 18px;
  color: var(--text-secondary);
  margin-bottom: 16px;
}

.hint-examples {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  max-width: 600px;
}

.hint-btn {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 8px 16px;
  font-size: 13px;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition);
}

.hint-btn:hover {
  border-color: var(--primary);
  color: var(--primary);
  background: var(--primary-muted);
}

/* Recent Questions */
.recent-questions {
  margin-top: 32px;
  padding-top: 24px;
  border-top: 1px solid var(--border);
  width: 100%;
  max-width: 600px;
}

.recent-title {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 12px;
}

.recent-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.recent-item {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
  font-size: 13px;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition);
  text-align: left;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.recent-item:hover {
  border-color: var(--primary);
  color: var(--primary);
  background: var(--primary-muted);
}

/* Diagram */
.diagram-content {
  display: flex;
  flex-direction: column;
  align-items: center;
}

#diagram-container {
  width: 100%;
  overflow-x: auto;
  padding: 16px 0;
}

#diagram-container svg {
  max-width: 100%;
  height: auto;
}

#diagram-source {
  width: 100%;
  margin-top: 12px;
  padding: 12px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: 'SF Mono', Monaco, monospace;
  font-size: 12px;
  overflow-x: auto;
  white-space: pre;
}

.diagram-error {
  padding: 16px;
  background: var(--warning-muted);
  border: 1px solid var(--warning);
  border-radius: var(--radius);
  font-family: 'SF Mono', Monaco, monospace;
  font-size: 12px;
  color: var(--text-secondary);
  overflow-x: auto;
  white-space: pre;
}

/* Error Section */
.error-section {
  padding: 20px 0;
}

.error-card {
  background: var(--error-muted);
  border: 1px solid var(--error);
  border-radius: var(--radius-lg);
  padding: 24px;
}

.error-card h3 {
  color: var(--error);
  font-size: 16px;
  margin-bottom: 10px;
}

.error-card p {
  color: var(--text-secondary);
  font-size: 15px;
}

/* Utilities */
.hidden {
  display: none !important;
}

/* Responsive */
@media (max-width: 640px) {
  .app {
    padding: 0 16px;
  }

  .options-row {
    flex-direction: column;
  }

  .header {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
  }

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