:root {
  --primary: #0078d2;
  --primary-hover: #005fa8;
  --primary-light: #e6f3fc;
  --primary-dark: #0a2540;
  --accent: #00a3e0;
  --success: #10b981;
  --success-light: #ecfdf5;
  --warning: #f59e0b;
  --warning-light: #fffbeb;
  --danger: #ef4444;
  --danger-light: #fef2f2;
  
  --bg-page: #f8fafc;
  --bg-card: #ffffff;
  --bg-subtle: #f1f5f9;
  --border: #e2e8f0;
  --border-focus: #0078d2;
  
  --text-main: #0f172a;
  --text-secondary: #475569;
  --text-muted: #94a3b8;
  --text-on-primary: #ffffff;

  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.08), 0 2px 4px -2px rgba(0, 0, 0, 0.05);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.08), 0 4px 6px -4px rgba(0, 0, 0, 0.04);
  --shadow-input: 0 2px 10px rgba(0, 0, 0, 0.04), 0 1px 3px rgba(0, 0, 0, 0.02);
  --shadow-focus: 0 0 0 4px rgba(0, 120, 210, 0.14), 0 6px 16px rgba(0, 120, 210, 0.08);

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-full: 9999px;
  
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

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

body {
  font-family: var(--font-sans);
  background-color: var(--bg-page);
  color: var(--text-main);
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Header */
.app-header {
  background-color: var(--bg-card);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow-sm);
}

.header-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0.9rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.brand-group {
  display: flex;
  align-items: center;
  gap: 0.85rem;
}

.brand-icon {
  width: 38px;
  height: 38px;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  color: #fff;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 6px rgba(0, 120, 210, 0.3);
}

.brand-title {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--primary-dark);
  line-height: 1.2;
}

.brand-subtitle {
  font-size: 0.78rem;
  color: var(--text-secondary);
  font-weight: 500;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.3rem 0.75rem;
  border-radius: var(--radius-full);
  font-size: 0.8rem;
  font-weight: 600;
  background-color: var(--bg-subtle);
  color: var(--text-secondary);
  border: 1px solid var(--border);
  transition: all 0.2s ease;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: var(--text-muted);
}

.status-pill.online {
  background-color: var(--success-light);
  color: #065f46;
  border-color: #a7f3d0;
}
.status-pill.online .status-dot {
  background-color: var(--success);
  box-shadow: 0 0 0 2px rgba(16, 185, 129, 0.2);
}

.status-pill.offline {
  background-color: var(--danger-light);
  color: #991b1b;
  border-color: #fecaca;
}
.status-pill.offline .status-dot {
  background-color: var(--danger);
}

.docs-link {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--primary);
  text-decoration: none;
  padding: 0.35rem 0.75rem;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  transition: all 0.2s ease;
}

.docs-link:hover {
  background-color: var(--primary-light);
  border-color: #bfdbfe;
}

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

/* Tabs Navigation */
.tabs-nav {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1.25rem;
  border-bottom: 2px solid var(--border);
}

.tab-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem 1.25rem;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-secondary);
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  cursor: pointer;
  transition: all 0.2s ease;
}

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

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

.tab-icon {
  width: 18px;
  height: 18px;
}

/* Tab Panels */
.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

/* Cards */
.card {
  background-color: var(--bg-card);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  padding: 1.75rem;
  margin-bottom: 1.5rem;
}

.card-title {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--primary-dark);
  margin-bottom: 0.35rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.card-desc {
  font-size: 0.88rem;
  color: var(--text-secondary);
  margin-bottom: 1.25rem;
}

/* Modern Chat Input Box */
.chat-input-box {
  background-color: #ffffff;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-input);
  padding: 0.9rem 1.15rem 0.65rem 1.15rem;
  display: flex;
  flex-direction: column;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
  margin-bottom: 1.25rem;
}

.chat-input-box:focus-within {
  border-color: var(--primary);
  box-shadow: var(--shadow-focus);
}

.chat-input-textarea {
  width: 100%;
  min-height: 54px;
  max-height: 220px;
  padding: 0.2rem 0;
  font-family: inherit;
  font-size: 0.98rem;
  line-height: 1.55;
  color: var(--text-main);
  background: transparent;
  border: none;
  outline: none;
  resize: none;
  overflow-y: auto;
}

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

.chat-input-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: 0.6rem;
  margin-top: 0.4rem;
  border-top: 1px solid #f1f5f9;
  flex-wrap: wrap;
  gap: 0.6rem;
}

.chat-input-hints {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.kbd {
  display: inline-block;
  padding: 0.15rem 0.45rem;
  font-size: 0.72rem;
  font-weight: 600;
  font-family: var(--font-mono);
  background-color: var(--bg-subtle);
  border: 1px solid #cbd5e1;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
}

.chat-input-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* Quick Prompt Chips (evaluation__train.xlsx) */
.prompt-suggestions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-top: -0.25rem;
  margin-bottom: 1.25rem;
  flex-wrap: wrap;
}

.prompt-suggestions-label {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  white-space: nowrap;
}

.prompt-suggestions-label svg {
  color: var(--primary);
  flex-shrink: 0;
}

.prompt-chips-wrap {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.prompt-chip {
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.35rem 0.8rem;
  background-color: #ffffff;
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  font-family: inherit;
  font-size: 0.82rem;
  color: var(--text-main);
  cursor: pointer;
  outline: none;
  transition: all 0.18s cubic-bezier(0.16, 1, 0.3, 1);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.03);
}

.prompt-chip:hover {
  border-color: var(--primary);
  background-color: #f0f7ff;
  color: var(--primary-dark);
  transform: translateY(-1px);
  box-shadow: 0 3px 8px rgba(0, 120, 210, 0.12);
}

.prompt-chip:active,
.prompt-chip.active {
  border-color: var(--primary);
  background-color: #e0f2fe;
  color: var(--primary-dark);
  box-shadow: 0 0 0 2px rgba(0, 120, 210, 0.25);
}

.chip-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.dot-express {
  background-color: #6366f1;
  box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.2);
}

.dot-kaspersky {
  background-color: #10b981;
  box-shadow: 0 0 0 2px rgba(16, 185, 129, 0.2);
}

.dot-deckhouse {
  background-color: #0284c7;
  box-shadow: 0 0 0 2px rgba(2, 132, 199, 0.2);
}

.dot-homonym {
  background-color: #f59e0b;
  box-shadow: 0 0 0 2px rgba(245, 158, 11, 0.2);
}

.chip-label {
  font-weight: 500;
  color: var(--text-secondary);
}

.chip-term {
  font-weight: 700;
  color: var(--primary-dark);
  font-family: var(--font-mono, monospace);
  font-size: 0.78rem;
}

/* Buttons */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  padding: 0.55rem 1.15rem;
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.2s ease;
  user-select: none;
}

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

.btn-primary {
  background-color: var(--primary);
  color: var(--text-on-primary);
  box-shadow: 0 2px 5px rgba(0, 120, 210, 0.28);
}

.btn-primary:hover:not(:disabled) {
  background-color: var(--primary-hover);
  box-shadow: 0 3px 8px rgba(0, 120, 210, 0.38);
}

.btn-secondary {
  background-color: var(--bg-subtle);
  color: var(--text-secondary);
  border-color: var(--border);
}

.btn-secondary:hover:not(:disabled) {
  background-color: #e2e8f0;
  color: var(--text-main);
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid transparent;
  padding: 0.45rem 0.85rem;
  font-size: 0.85rem;
}

.btn-ghost:hover:not(:disabled) {
  background-color: var(--bg-subtle);
  color: var(--text-main);
}

/* Loading State */
.loading-box {
  display: none;
  text-align: center;
  padding: 2.5rem 1rem;
}

.loading-box.active {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.spinner {
  width: 36px;
  height: 36px;
  border: 3.5px solid rgba(0, 120, 210, 0.2);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-bottom: 0.85rem;
}

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

.loading-text {
  font-size: 0.92rem;
  color: var(--text-secondary);
  font-weight: 500;
}

/* Result Container */
.result-section {
  display: none;
}

.result-section.active {
  display: block;
}

.answer-card {
  background: linear-gradient(to bottom, #ffffff, #fafcff);
  border: 1px solid #d0e3f8;
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  margin-bottom: 1.25rem;
  position: relative;
  box-shadow: var(--shadow-sm);
}

.answer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
  padding-bottom: 0.6rem;
  border-bottom: 1px solid #e8f0fe;
}

.answer-badge {
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--primary);
  background-color: var(--primary-light);
  padding: 0.2rem 0.6rem;
  border-radius: var(--radius-full);
}

/* Answer Body with Rich Markdown Styling */
.answer-body {
  font-size: 0.96rem;
  line-height: 1.68;
  color: #1e293b;
}

.answer-body .md-h2 {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--primary-dark);
  margin: 1.25rem 0 0.55rem 0;
  padding-bottom: 0.35rem;
  border-bottom: 1px solid #e2e8f0;
}

.answer-body .md-h3 {
  font-size: 1.12rem;
  font-weight: 700;
  color: var(--primary-dark);
  margin: 1.1rem 0 0.5rem 0;
}

.answer-body .md-h4 {
  font-size: 1.02rem;
  font-weight: 700;
  color: var(--primary);
  margin: 0.95rem 0 0.45rem 0;
}

.answer-body .md-h5 {
  font-size: 0.96rem;
  font-weight: 600;
  color: var(--text-main);
  margin: 0.8rem 0 0.35rem 0;
}

.answer-body .md-h2:first-child,
.answer-body .md-h3:first-child,
.answer-body .md-h4:first-child,
.answer-body .md-h5:first-child {
  margin-top: 0;
}

.answer-body .md-p {
  margin-bottom: 0.8rem;
  line-height: 1.68;
}

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

.answer-body strong {
  font-weight: 700;
  color: #0f172a;
}

.answer-body em {
  font-style: italic;
  color: #334155;
}

.answer-body .md-ol,
.answer-body .md-ul {
  margin: 0.5rem 0 0.85rem 1.35rem;
  padding-left: 0.4rem;
}

.answer-body li {
  margin-bottom: 0.35rem;
  line-height: 1.6;
}

.answer-body li::marker {
  color: var(--primary);
  font-weight: 600;
}

.answer-body .inline-code {
  background-color: var(--bg-subtle);
  border: 1px solid #e2e8f0;
  border-radius: var(--radius-sm);
  padding: 0.15rem 0.42rem;
  font-family: var(--font-mono);
  font-size: 0.88em;
  color: #0369a1;
}

.answer-body .code-block {
  background-color: #0f172a;
  color: #f8fafc;
  padding: 0.9rem 1.2rem;
  border-radius: var(--radius-md);
  overflow-x: auto;
  margin: 0.85rem 0;
  font-family: var(--font-mono);
  font-size: 0.88rem;
  line-height: 1.5;
}

.answer-body .md-hr {
  border: none;
  border-top: 1.5px solid #d0e3f8;
  margin: 1.25rem 0;
  height: 0;
}

.answer-body .md-quote {
  border-left: 3px solid var(--primary);
  padding: 0.45rem 0.9rem;
  margin: 0.85rem 0;
  background-color: var(--primary-light);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  color: #334155;
  font-style: italic;
}

/* Detected Terms */
.terms-card {
  margin-bottom: 1.25rem;
}

.terms-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
}

.term-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  background-color: #f1f7fe;
  border: 1px solid #c7e0fb;
  border-radius: var(--radius-md);
  padding: 0.45rem 0.85rem;
}

.term-canonical {
  font-weight: 700;
  color: var(--primary);
  font-size: 0.9rem;
}

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

.term-expansion {
  color: var(--text-secondary);
  font-size: 0.88rem;
  font-style: italic;
}

/* Sources */
.sources-card {
  margin-bottom: 1.25rem;
}

.sources-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.source-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.6rem 0.9rem;
  background-color: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-size: 0.88rem;
}

.source-name {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  font-weight: 600;
  color: var(--text-main);
  word-break: break-all;
}

.source-page {
  display: inline-flex;
  align-items: center;
  font-size: 0.78rem;
  font-weight: 700;
  padding: 0.2rem 0.55rem;
  background-color: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  white-space: nowrap;
}

/* Telemetry Footer */
.telemetry-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 0.25rem;
  font-size: 0.78rem;
  color: var(--text-muted);
}

/* Upload Drop Zone */
.drop-zone {
  border: 2px dashed #cbd5e1;
  border-radius: var(--radius-lg);
  padding: 3rem 1.5rem;
  text-align: center;
  background-color: #fafbfc;
  cursor: pointer;
  transition: all 0.2s ease;
  position: relative;
}

.drop-zone:hover,
.drop-zone.dragover {
  border-color: var(--primary);
  background-color: var(--primary-light);
}

.drop-icon {
  width: 48px;
  height: 48px;
  color: var(--primary);
  margin-bottom: 0.75rem;
}

.drop-title {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--primary-dark);
  margin-bottom: 0.25rem;
}

.drop-desc {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-bottom: 1rem;
}

.file-input {
  display: none;
}

.selected-file-info {
  display: none;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  background-color: var(--primary-light);
  border: 1px solid #bfdbfe;
  border-radius: var(--radius-md);
  margin-top: 1rem;
}

.selected-file-info.active {
  display: flex;
}

.file-details {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--primary-dark);
}

.file-size {
  font-size: 0.8rem;
  color: var(--text-secondary);
  font-weight: 400;
}

/* Extracted Abbreviations Table */
.table-container {
  overflow-x: auto;
  margin-top: 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 0.88rem;
}

.data-table th {
  background-color: #f1f5f9;
  color: var(--text-secondary);
  font-weight: 700;
  padding: 0.75rem 1rem;
  border-bottom: 2px solid var(--border);
  position: sticky;
  top: 0;
}

.data-table td {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

.data-table tbody tr:hover {
  background-color: #f8fafc;
}

.quote-cell {
  max-width: 420px;
  font-style: italic;
  color: var(--text-secondary);
  font-size: 0.84rem;
  line-height: 1.4;
}

/* Alert Boxes */
.alert {
  display: none;
  padding: 0.85rem 1.15rem;
  border-radius: var(--radius-md);
  font-size: 0.88rem;
  margin-bottom: 1.25rem;
  align-items: center;
  gap: 0.5rem;
}

.alert.active {
  display: flex;
}

.alert-danger {
  background-color: var(--danger-light);
  border: 1px solid #fecaca;
  color: #991b1b;
}

.alert-success {
  background-color: var(--success-light);
  border: 1px solid #a7f3d0;
  color: #065f46;
}

/* Footer */
.app-footer {
  margin-top: auto;
  border-top: 1px solid var(--border);
  background-color: var(--bg-card);
  padding: 1rem 1.5rem;
  text-align: center;
  font-size: 0.82rem;
  color: var(--text-muted);
}

.app-footer strong {
  color: var(--primary-dark);
}

/* Responsive */
@media (max-width: 768px) {
  .header-container {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.75rem;
  }
  
  .header-actions {
    width: 100%;
    justify-content: space-between;
  }

  .chat-input-footer {
    flex-direction: column;
    align-items: stretch;
  }

  .chat-input-actions {
    justify-content: flex-end;
  }
}
