/* UI Components */

/* Cards & fields */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow-xs);
  transition: box-shadow var(--transition-fast), border-color var(--transition-fast);
}

.card:hover { box-shadow: var(--shadow-sm); }

.field { margin-bottom: 12px; }
.field:last-child { margin-bottom: 0; }

.field label {
  display: block;
  font-size: 0.76rem;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.field input[type="text"],
.field input[type="password"],
.field select {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 0.88rem;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast), background var(--transition-fast);
}

.field input:focus,
.field select:focus,
textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: var(--focus-ring);
  background: var(--surface);
}

.field input::placeholder,
textarea::placeholder { color: var(--placeholder); }

.btn-row {
  display: flex;
  gap: 8px;
  margin-top: 4px;
}

.btn-row .btn { flex: 1; }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.84rem;
  font-weight: 500;
  transition: all var(--transition-fast);
  white-space: nowrap;
}

.btn-secondary {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-secondary);
}

.btn-secondary:hover:not(:disabled) {
  border-color: var(--accent-border);
  color: var(--accent);
  background: var(--accent-soft);
  transform: translateY(-1px);
}

.btn-primary {
  background: var(--accent);
  color: var(--bg);
  border: none;
  font-weight: 600;
  min-width: 90px;
}

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

.btn-primary:active:not(:disabled) { transform: translateY(0) scale(0.98); }

.btn-primary:disabled,
.btn-secondary:disabled {
  opacity: 0.5;
  transform: none;
  box-shadow: none;
}

.btn-stop {
  background: var(--error-soft);
  color: var(--error);
  border: 1px solid var(--error-border);
  min-width: 70px;
}

.btn-stop:hover:not(:disabled) {
  background: var(--error);
  color: #fff;
}

.btn-ghost {
  padding: 6px 10px;
  font-size: 0.78rem;
  color: var(--muted);
  border-radius: var(--radius-sm);
}

.btn-ghost:hover {
  color: var(--accent);
  background: var(--accent-soft);
}

/* Upload zone */
.upload-zone {
  display: block;
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--radius);
  padding: 22px 14px;
  text-align: center;
  background: var(--surface);
  cursor: pointer;
  transition: all var(--transition-base);
  position: relative;
  overflow: hidden;
}

.upload-zone::before {
  content: "";
  position: absolute;
  inset: 0;
  background: var(--accent-soft);
  opacity: 0;
  transition: opacity var(--transition-fast);
}

.upload-zone:hover,
.upload-zone.dragover {
  border-color: var(--accent);
  transform: translateY(-2px);
  box-shadow: var(--shadow-sm);
}

.upload-zone:hover::before,
.upload-zone.dragover::before { opacity: 1; }

.upload-zone > * { position: relative; z-index: 1; }

.upload-zone input { display: none; }

.upload-zone svg {
  width: 28px;
  height: 28px;
  color: var(--accent);
  margin-bottom: 8px;
}

.upload-zone strong {
  display: block;
  font-size: 0.86rem;
  font-weight: 600;
  margin-bottom: 4px;
}

.upload-zone .hint {
  font-size: 0.73rem;
  color: var(--muted);
}

.upload-progress {
  display: none;
  margin-top: 10px;
  height: 4px;
  background: var(--border);
  border-radius: var(--radius-full);
  overflow: hidden;
}

.upload-progress.visible { display: block; }

.upload-progress-bar {
  height: 100%;
  width: 0%;
  background: var(--gradient-brand);
  border-radius: var(--radius-full);
  transition: width 0.3s ease;
  animation: shimmer 1.5s infinite linear;
  background-size: 200% 100%;
}

/* Lists */
.item-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 10px;
}

.list-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 0.8rem;
  line-height: 1.4;
  animation: fadeInUp 0.3s ease both;
  transition: border-color var(--transition-fast), transform var(--transition-fast);
}

.list-item:hover {
  border-color: var(--accent-border);
  transform: translateX(2px);
}

.list-item .label {
  font-size: 0.66rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--accent);
}

.list-item .title {
  font-weight: 600;
  margin-top: 2px;
}

.list-item .detail {
  color: var(--muted);
  margin-top: 4px;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.empty-note {
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.45;
  padding: 8px 0;
}

/* Quick prompts */
.prompt-btn {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  text-align: left;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  margin-bottom: 5px;
  font-size: 0.8rem;
  line-height: 1.35;
  transition: all var(--transition-fast);
}

.prompt-btn:hover {
  border-color: var(--accent-border);
  background: var(--accent-soft);
  color: var(--accent);
  transform: translateX(3px);
}

.prompt-btn .arrow {
  opacity: 0;
  transform: translateX(-4px);
  transition: all var(--transition-fast);
  color: var(--accent);
  font-size: 0.9rem;
}

.prompt-btn:hover .arrow {
  opacity: 1;
  transform: translateX(0);
}

/* Template catalog */
.templates-panel-header {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 10px;
}

.templates-saved-wrap {
  margin-bottom: 12px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
}

.templates-saved-header {
  display: flex;
  justify-content: flex-start;
}

.templates-saved-note {
  margin: 8px 0 10px;
  font-size: 0.73rem;
  color: var(--muted);
}

.templates-saved-list {
  display: grid;
  gap: 8px;
}

.template-saved-item {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  padding: 8px 10px;
}

.template-saved-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.template-saved-head strong {
  font-size: 0.78rem;
}

.template-saved-prompt {
  margin: 7px 0;
  font-size: 0.74rem;
  line-height: 1.45;
  color: var(--text-secondary);
  white-space: pre-wrap;
}

.template-saved-actions {
  display: flex;
  gap: 6px;
}

.templates-auto-send-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.74rem;
  color: var(--text-secondary);
  cursor: pointer;
}

.templates-auto-send-input {
  accent-color: var(--accent);
}

.templates-search-wrap {
  margin-bottom: 12px;
}

.templates-search {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 0.85rem;
}

.templates-catalog {
  display: grid;
  gap: 10px;
}

.template-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 12px;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.template-card:hover {
  border-color: var(--accent-border);
  box-shadow: var(--shadow-xs);
}

.template-card-head {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}

.template-card-title {
  margin: 0 0 4px;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text);
}

.template-card-desc {
  margin: 0;
  font-size: 0.76rem;
  line-height: 1.45;
  color: var(--muted);
}

.template-badges {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
  flex-shrink: 0;
}

.template-badge {
  font-size: 0.62rem;
  font-weight: 600;
  padding: 3px 7px;
  border-radius: var(--radius-full);
  background: var(--accent-soft);
  color: var(--accent);
  font-family: var(--font-mono);
}

.template-badge--upload {
  background: #fff7ed;
  color: #c2410c;
}

.template-tools {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-bottom: 8px;
}

.template-card-hint {
  margin: 0 0 8px;
  font-size: 0.72rem;
  color: var(--warning);
}

.template-tool-pill {
  font-size: 0.62rem;
  padding: 3px 7px;
  border-radius: var(--radius-full);
  background: var(--sidebar);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  font-family: var(--font-mono);
}

.template-tool-pill--muted {
  font-family: inherit;
  font-style: italic;
}

.template-preview {
  margin-bottom: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
}

.template-preview summary {
  cursor: pointer;
  padding: 8px 10px;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-secondary);
  list-style: none;
}

.template-preview summary::-webkit-details-marker {
  display: none;
}

.template-preview-body {
  padding: 0 10px 10px;
  font-size: 0.74rem;
  line-height: 1.5;
  color: var(--text-secondary);
  max-height: 180px;
  overflow: auto;
}

.template-preview-body table {
  font-size: 0.68rem;
}

.template-card-actions {
  display: flex;
  gap: 6px;
}

.template-btn {
  flex: 1;
  padding: 7px 10px;
  border-radius: var(--radius-sm);
  font-size: 0.74rem;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-secondary);
}

.template-btn--tiny {
  flex: 0 0 auto;
  font-size: 0.68rem;
  padding: 5px 8px;
}

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

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

.template-btn--ghost:hover {
  border-color: var(--accent-border);
  color: var(--accent);
}

.template-btn--live {
  background: var(--success-soft);
  border-color: var(--success-border);
  color: var(--success);
}

.template-btn--live:hover:not(:disabled) {
  background: var(--success);
  border-color: var(--success);
  color: #fff;
}

/* Messages — document-style thread */
.msg {
  width: 100%;
  padding: 0;
  line-height: 1.7;
  word-break: break-word;
  font-size: 0.9375rem;
  position: relative;
  animation: fadeInUp 0.3s ease both;
}

.msg.user {
  align-self: stretch;
  background: var(--user-bg);
  color: var(--user-text);
  border-radius: var(--radius-lg);
  padding: 14px 18px;
}

.msg.assistant {
  align-self: stretch;
  background: transparent;
  color: var(--text);
  padding: 4px 0;
}

.msg.system {
  align-self: center;
  max-width: 100%;
  color: var(--muted);
  font-size: 0.8125rem;
  background: var(--accent-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  padding: 8px 16px;
  text-align: center;
}

.msg.streaming .cursor {
  display: inline-block;
  width: 2px;
  height: 1em;
  background: var(--accent);
  margin-left: 2px;
  vertical-align: text-bottom;
  animation: blink 0.8s step-end infinite;
}

.msg.user.streaming .cursor { background: var(--user-text); }

.msg-actions {
  display: flex;
  gap: 4px;
  margin-top: 8px;
  opacity: 0;
  transition: opacity var(--transition-fast);
}

.msg:hover .msg-actions,
.msg:focus-within .msg-actions { opacity: 1; }

.msg-action-btn {
  width: 28px;
  height: 28px;
  border-radius: var(--radius-sm);
  display: grid;
  place-items: center;
  background: var(--surface-hover);
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.75rem;
  transition: all var(--transition-fast);
}

.msg-action-btn:hover {
  color: var(--text);
  border-color: var(--border-strong);
  background: var(--surface);
}

/* Typing indicator */
.typing-indicator {
  align-self: stretch;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  animation: fadeInUp 0.3s ease both;
}

.typing-dots {
  display: flex;
  gap: 4px;
}

.typing-dots span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
  animation: bounce 1.2s ease-in-out infinite;
}

.typing-dots span:nth-child(2) { animation-delay: 0.15s; }
.typing-dots span:nth-child(3) { animation-delay: 0.3s; }

.typing-label {
  font-size: 0.78rem;
  color: var(--muted);
}

/* Message content typography */
.msg h2 {
  font-size: 1.05rem;
  font-weight: 700;
  margin: 0 0 10px;
  letter-spacing: -0.02em;
}

.msg h3 {
  font-size: 0.95rem;
  font-weight: 600;
  margin: 14px 0 8px;
}

.msg.user h2, .msg.user h3, .msg.user strong { color: var(--user-text); }
.msg.assistant strong { color: var(--text); }

.msg ul, .msg ol {
  margin: 8px 0;
  padding-left: 1.4em;
}

.msg li { margin: 4px 0; }

.msg code {
  font-family: var(--font-mono);
  font-size: 0.84em;
  background: var(--sidebar);
  padding: 2px 6px;
  border-radius: 4px;
}

.msg.user code {
  background: rgba(0, 0, 0, 0.06);
}

.msg pre {
  margin: 10px 0;
  padding: 12px 14px;
  background: var(--sidebar);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: 0.82rem;
  line-height: 1.5;
}

.msg.user pre {
  background: rgba(0, 0, 0, 0.05);
  border-color: var(--border);
}

.msg-meta {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
  font-size: 0.7rem;
  color: var(--muted);
  font-weight: 500;
}

.msg.user .msg-meta {
  border-top-color: var(--border);
  color: var(--muted);
}

.msg-tools {
  margin-top: 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.tool-chip {
  font-size: 0.65rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: var(--radius-full);
  background: var(--accent-soft);
  color: var(--accent);
  border: 1px solid var(--accent-border);
}

/* Tables */
.msg table {
  border-collapse: collapse;
  width: 100%;
  margin: 10px 0;
  font-size: 0.82rem;
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.msg th, .msg td {
  border: 1px solid var(--border);
  padding: 8px 10px;
  text-align: left;
}

.msg th {
  background: var(--sidebar);
  font-weight: 600;
  color: var(--text-secondary);
}

.msg.user table th {
  background: rgba(0, 0, 0, 0.04);
}

.char-count {
  font-size: 0.68rem;
  color: var(--muted);
  text-align: right;
  padding: 4px 4px 0;
  max-width: var(--composer-max);
  margin: 0 auto;
  opacity: 0;
  transition: opacity var(--transition-fast);
}

.char-count.visible { opacity: 1; }
.char-count.warn { color: var(--warning); }

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.5);
  backdrop-filter: blur(6px);
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  opacity: 0;
  visibility: hidden;
  transition: all var(--transition-base);
}

.modal-overlay.open {
  opacity: 1;
  visibility: visible;
}

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 440px;
  max-height: 85vh;
  overflow-y: auto;
  transform: scale(0.95) translateY(10px);
  transition: transform var(--transition-spring);
}

.modal-overlay.open .modal {
  transform: scale(1) translateY(0);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
}

.modal-header h2 {
  font-size: 1rem;
  font-weight: 700;
}

.modal-body { padding: 18px 20px; }

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 14px 20px;
  border-top: 1px solid var(--border);
}

/* Company profile mini card */
.company-card {
  display: none;
  margin-top: 10px;
  padding: 10px 12px;
  background: var(--accent-soft);
  border: 1px solid var(--accent-border);
  border-radius: var(--radius-sm);
  font-size: 0.78rem;
  animation: fadeInUp 0.3s ease both;
}

.company-card.visible { display: block; }

.company-card .sector {
  color: var(--accent);
  font-weight: 600;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.company-card .details {
  color: var(--muted);
  margin-top: 4px;
}

/* Spinner */
.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

/* Toast notifications */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--text);
  color: var(--surface);
  padding: 10px 18px;
  border-radius: var(--radius-full);
  font-size: 0.82rem;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: all var(--transition-base);
}

.toast.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.toast.warn { background: var(--warning); color: #fff; }

/* Scroll-to-bottom FAB */
.scroll-fab {
  position: absolute;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(10px);
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-md);
  display: grid;
  place-items: center;
  color: var(--text-secondary);
  z-index: 5;
  opacity: 0;
  pointer-events: none;
  transition: all var(--transition-base);
}

.scroll-fab.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
  pointer-events: auto;
}

.scroll-fab:hover {
  background: var(--surface-hover);
  color: var(--text);
}

/* Collapsible tools & sources */
.msg-tools-collapse {
  margin-top: 10px;
  font-size: 0.78rem;
}

.msg-tools-collapse summary {
  cursor: pointer;
  color: var(--muted);
  font-weight: 600;
  user-select: none;
  list-style: none;
}

.msg-tools-collapse summary::-webkit-details-marker { display: none; }

.msg-tools-collapse summary::before {
  content: "▸ ";
  display: inline-block;
  transition: transform var(--transition-fast);
}

.msg-tools-collapse[open] summary::before {
  transform: rotate(90deg);
}

.msg-tools-collapse .msg-tools {
  margin-top: 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.msg-sources {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
  font-size: 0.72rem;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.msg-sources .sources-label {
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-size: 0.65rem;
}

.msg-sources a {
  padding: 2px 8px;
  background: var(--accent-soft);
  border-radius: var(--radius-full);
  border: 1px solid var(--accent-border);
  font-size: 0.7rem;
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.msg.user .msg-sources {
  border-top-color: rgba(255, 255, 255, 0.2);
}

/* Expandable memory items */
.memory-expand {
  padding: 0;
  overflow: hidden;
}

.memory-expand summary {
  padding: 10px 12px;
  cursor: pointer;
  list-style: none;
}

.memory-expand summary::-webkit-details-marker { display: none; }

.memory-expand .detail {
  padding: 0 12px 10px;
  -webkit-line-clamp: unset;
  display: block;
}

/* Tools list in settings */
.tools-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  max-height: 120px;
  overflow-y: auto;
}

.about-card {
  padding: 12px 14px;
  background: var(--accent-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.8125rem;
  line-height: 1.55;
  color: var(--text-secondary);
}

.about-card p {
  margin: 0 0 8px;
}

.about-card p:last-child {
  margin-bottom: 0;
}

.about-card a {
  color: var(--text);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.modal { max-width: 480px; }

/* Session history */
.history-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 200px;
  overflow-y: auto;
}

.history-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
  text-align: left;
  padding: 8px 12px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background var(--transition-fast);
  border: none;
  background: transparent;
  font: inherit;
  color: inherit;
}

.history-item:hover {
  background: var(--surface-hover);
}

.history-item.active {
  background: var(--surface-hover);
}

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

.history-title {
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: block;
}

.history-delete {
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border-radius: var(--radius-sm);
  font-size: 1.1rem;
  line-height: 1;
  color: var(--muted);
  opacity: 0;
  border: none;
  background: transparent;
  cursor: pointer;
  transition: opacity var(--transition-fast), background var(--transition-fast);
  flex-shrink: 0;
}

.history-item:hover .history-delete {
  opacity: 1;
}

.history-delete:hover {
  background: var(--error-soft);
  color: var(--error);
}

/* Welcome chips */
.welcome-chip {
  padding: 8px 14px;
  border-radius: var(--radius-full);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-secondary);
  font-size: 0.8125rem;
  font-weight: 500;
  transition: background var(--transition-fast), border-color var(--transition-fast);
}

.welcome-chip:hover {
  background: var(--surface-hover);
  border-color: var(--border-strong);
  color: var(--text);
}

/* Keyboard shortcuts */
.shortcut-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.84rem;
}

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

.shortcut-keys {
  display: flex;
  gap: 4px;
}

kbd {
  display: inline-block;
  padding: 3px 8px;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: 0 1px 0 var(--border-strong);
}

.shortcut-action { color: var(--muted); }

/* Skip link */
.skip-link {
  position: absolute;
  top: -100px;
  left: 16px;
  padding: 10px 16px;
  background: var(--accent);
  color: #fff;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 0.84rem;
  z-index: 200;
  transition: top var(--transition-fast);
}

.skip-link:focus {
  top: 16px;
  outline: none;
}

/* Table charts */
.msg-chart-wrap { margin: 10px 0; }

.chart-toggle {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  margin-bottom: 8px;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--accent);
  background: var(--accent-soft);
  border: 1px solid var(--accent-border);
  border-radius: var(--radius-full);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.chart-toggle:hover {
  background: var(--accent);
  color: #fff;
}

.chart-container.hidden { display: none; }

.msg-chart {
  margin-top: 10px;
  padding: 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  animation: fadeInUp 0.3s ease both;
}

.chart-title {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 10px;
}

.chart-row {
  display: grid;
  grid-template-columns: 90px 1fr 64px;
  gap: 8px;
  align-items: center;
  margin-bottom: 6px;
  font-size: 0.76rem;
}

.chart-label {
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chart-bar-wrap {
  height: 8px;
  background: var(--border);
  border-radius: var(--radius-full);
  overflow: hidden;
}

.chart-bar {
  height: 100%;
  background: var(--gradient-brand);
  border-radius: var(--radius-full);
  transition: width 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
  min-width: 3px;
}

.chart-row.negative .chart-bar {
  background: linear-gradient(90deg, #dc2626, #f87171);
}

.chart-value {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  text-align: right;
  color: var(--text);
}

.msg-download-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 8px;
  padding: 8px 14px;
  border-radius: var(--radius);
  background: var(--accent);
  color: #fff !important;
  font-weight: 600;
  text-decoration: none !important;
  font-size: 0.875rem;
}

.msg-download-link:hover {
  background: var(--accent-hover);
}

.msg-export-card {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 14px;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow-xs);
}

.msg-export-icon {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  border-radius: var(--radius);
  background: var(--success-soft);
  color: var(--success);
  display: grid;
  place-items: center;
}

.msg-export-body {
  flex: 1;
  min-width: 0;
}

.msg-export-title {
  font-weight: 600;
  font-size: 0.9rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.msg-export-desc {
  font-size: 0.8rem;
  color: var(--muted);
  margin-top: 2px;
}

.msg-export-download-btn {
  flex-shrink: 0;
  padding: 8px 16px;
  border: none;
  border-radius: var(--radius-full);
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  font-size: 0.85rem;
  cursor: pointer;
}

.msg-export-download-btn:hover:not(:disabled) {
  background: var(--accent-hover);
}

.msg-export-download-btn.loading {
  opacity: 0.7;
  cursor: wait;
}

/* Excel import / export UI */
.upload-zone.uploading {
  pointer-events: none;
  opacity: 0.85;
}

.upload-zone-inner,
.upload-zone-active {
  position: relative;
  z-index: 1;
}

.upload-zone-active {
  display: none;
  align-items: center;
  justify-content: center;
  gap: 10px;
  font-size: 0.82rem;
  color: var(--accent);
  font-weight: 500;
}

.upload-zone.dragover .upload-zone-inner { opacity: 0.35; }
.upload-zone.dragover .upload-zone-active { display: flex; }

.upload-progress-wrap {
  margin-top: 10px;
}

.upload-progress-label {
  display: none;
  font-size: 0.74rem;
  color: var(--muted);
  margin-bottom: 6px;
}

.upload-progress-label.visible { display: block; }

.import-summary-host {
  margin-top: 14px;
}

.import-summary-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  animation: fadeInUp 0.35s ease both;
}

.import-summary-card.status-success {
  border-color: var(--success-border);
  background: linear-gradient(180deg, var(--success-soft) 0%, var(--surface) 42%);
}

.import-summary-card.status-warning {
  border-color: color-mix(in srgb, var(--warning) 35%, var(--border));
  background: linear-gradient(180deg, var(--warning-soft) 0%, var(--surface) 42%);
}

.import-summary-card.status-error {
  border-color: var(--error-border);
  background: linear-gradient(180deg, var(--error-soft) 0%, var(--surface) 42%);
}

.import-summary-header {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 12px;
}

.import-status-icon {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 0.85rem;
  font-weight: 700;
  flex-shrink: 0;
  background: var(--accent-soft);
  color: var(--accent);
}

.status-success .import-status-icon {
  background: var(--success-soft);
  color: var(--success);
}

.status-warning .import-status-icon {
  background: var(--warning-soft);
  color: var(--warning);
}

.status-error .import-status-icon {
  background: var(--error-soft);
  color: var(--error);
}

.import-summary-title {
  font-size: 0.88rem;
  font-weight: 600;
}

.import-summary-file {
  font-size: 0.76rem;
  color: var(--muted);
  margin-top: 2px;
  word-break: break-all;
}

.import-ready-badge {
  margin-left: auto;
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--success);
  background: var(--success-soft);
  border: 1px solid var(--success-border);
  border-radius: var(--radius-full);
  padding: 4px 8px;
  white-space: nowrap;
}

.import-stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 12px;
}

.import-stat {
  text-align: center;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 4px;
}

.import-stat-value {
  display: block;
  font-size: 1rem;
  font-weight: 700;
  line-height: 1.1;
}

.import-stat-label {
  display: block;
  font-size: 0.66rem;
  color: var(--muted);
  margin-top: 2px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.import-section-label {
  display: block;
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  margin-bottom: 6px;
}

.import-statements,
.import-products,
.import-coverage {
  margin-bottom: 12px;
}

.import-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.import-badge {
  font-size: 0.72rem;
  font-weight: 600;
  padding: 4px 8px;
  border-radius: var(--radius-full);
  background: var(--accent-soft);
  border: 1px solid var(--border);
  color: var(--text-secondary);
}

.import-badge.muted {
  color: var(--muted);
  font-weight: 500;
}

.import-product-counts {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.import-product-chip {
  font-size: 0.76rem;
  color: var(--text-secondary);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
}

.import-product-chip strong {
  color: var(--text);
  margin-right: 4px;
}

.import-coverage-bars {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.import-coverage-head {
  display: flex;
  justify-content: space-between;
  font-size: 0.74rem;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

.import-coverage-pct {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--muted);
}

.import-coverage-track {
  height: 6px;
  background: var(--border);
  border-radius: var(--radius-full);
  overflow: hidden;
}

.import-coverage-fill {
  height: 100%;
  border-radius: var(--radius-full);
  background: var(--muted);
  transition: width 0.4s ease;
}

.import-coverage-fill.partial { background: var(--warning); }
.import-coverage-fill.full { background: var(--success); }

.import-warnings-title {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--warning);
  margin-bottom: 6px;
}

.import-warnings-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.import-warning-item {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  font-size: 0.76rem;
  line-height: 1.4;
  color: var(--text-secondary);
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
}

.import-warning-item.severity-high {
  border-color: var(--error-border);
  background: var(--error-soft);
  color: var(--error);
}

.import-warning-icon {
  flex-shrink: 0;
  width: 16px;
  text-align: center;
}

.import-details-collapse {
  margin-top: 10px;
  font-size: 0.78rem;
}

.import-details-collapse summary {
  cursor: pointer;
  color: var(--accent);
  font-weight: 500;
  padding: 4px 0;
}

.import-sheet-list {
  margin-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.import-sheet-row {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px;
  background: var(--bg-elevated);
}

.import-sheet-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.import-sheet-type {
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--accent);
}

.import-sheet-warn {
  font-size: 0.68rem;
  color: var(--warning);
  margin-left: auto;
}

.import-sheet-meta,
.import-sheet-lines {
  font-size: 0.72rem;
  color: var(--muted);
  margin-top: 4px;
}

.msg.import-summary-msg {
  background: transparent;
  padding: 8px 0 16px;
  max-width: var(--message-max);
}

.upload-history-item .upload-history-head {
  display: flex;
  gap: 10px;
  align-items: flex-start;
}

.upload-history-icon { font-size: 1rem; line-height: 1; }

.upload-history-badges {
  margin-top: 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.export-section-hint {
  font-size: 0.74rem;
  color: var(--muted);
  line-height: 1.45;
  margin: -4px 0 12px;
}

.export-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.export-action-btn {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  text-align: left;
  gap: 2px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  transition: all var(--transition-fast);
  position: relative;
}

.export-action-btn:hover:not(:disabled) {
  border-color: var(--accent);
  background: var(--accent-soft);
  transform: translateY(-1px);
}

.export-action-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.export-action-btn.loading::after {
  content: "";
  position: absolute;
  right: 10px;
  top: 50%;
  width: 14px;
  height: 14px;
  margin-top: -7px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

.export-action-label {
  font-size: 0.8rem;
  font-weight: 600;
}

.export-action-desc {
  font-size: 0.68rem;
  color: var(--muted);
  line-height: 1.3;
}

.export-confirm {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--success-soft);
  border: 1px solid var(--success-border);
  font-size: 0.76rem;
  color: var(--text-secondary);
}

.export-confirm-icon {
  color: var(--success);
  font-weight: 700;
}

.export-original-btn {
  width: 100%;
  margin-top: 10px;
}

.toast.success { background: var(--success); color: #fff; }

/* Document upload UI */
.upload-format-badges {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
  margin-top: 12px;
}

.upload-zone .upload-format-badges .doc-type-badge {
  font-size: 0.65rem;
  padding: 3px 8px;
  opacity: 0.85;
}

.upload-zone:hover .upload-format-badges .doc-type-badge,
.upload-zone.dragover .upload-format-badges .doc-type-badge {
  opacity: 1;
}

.doc-type-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: var(--radius-full);
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text-secondary);
  animation: fadeInUp 0.3s ease both;
}

.doc-type-badge-icon {
  display: grid;
  place-items: center;
  width: 14px;
  height: 14px;
}

.doc-type-badge-icon svg {
  width: 14px;
  height: 14px;
}

.doc-type-excel {
  color: #059669;
  background: var(--success-soft);
  border-color: var(--success-border);
}

.doc-type-pdf {
  color: #dc2626;
  background: var(--error-soft);
  border-color: var(--error-border);
}

.doc-type-word {
  color: #2563eb;
  background: #eff6ff;
  border-color: #bfdbfe;
}

[data-theme="dark"] .doc-type-word {
  background: rgba(37, 99, 235, 0.15);
  border-color: rgba(37, 99, 235, 0.35);
}

.doc-type-image {
  color: #7c3aed;
  background: #f5f3ff;
  border-color: #ddd6fe;
}

[data-theme="dark"] .doc-type-image {
  background: rgba(124, 58, 237, 0.15);
  border-color: rgba(124, 58, 237, 0.35);
}

.ocr-badge {
  display: inline-flex;
  align-items: center;
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 3px 8px;
  border-radius: var(--radius-full);
  color: #7c3aed;
  background: #f5f3ff;
  border: 1px solid #ddd6fe;
}

[data-theme="dark"] .ocr-badge {
  background: rgba(124, 58, 237, 0.15);
  border-color: rgba(124, 58, 237, 0.35);
  color: #c4b5fd;
}

.document-preview-host {
  margin-top: 12px;
  animation: fadeInUp 0.3s ease both;
}

.document-preview-card {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.document-preview-card:hover {
  border-color: var(--accent-border);
  box-shadow: var(--shadow-xs);
}

.document-preview-visual {
  flex-shrink: 0;
  width: 56px;
  height: 56px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  display: grid;
  place-items: center;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
}

.document-preview-thumb {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.document-preview-icon {
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
}

.document-preview-icon svg {
  width: 28px;
  height: 28px;
}

.document-preview-icon.doc-type-excel svg { color: #059669; }
.document-preview-icon.doc-type-pdf svg { color: #dc2626; }
.document-preview-icon.doc-type-word svg { color: #2563eb; }
.document-preview-icon.doc-type-image svg { color: #7c3aed; }

.document-preview-meta {
  flex: 1;
  min-width: 0;
}

.document-preview-name {
  font-size: 0.84rem;
  font-weight: 600;
  margin-top: 6px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.document-preview-size {
  font-size: 0.72rem;
  color: var(--muted);
  margin-top: 2px;
}

.document-summary-card .import-summary-header-text {
  flex: 1;
  min-width: 0;
}

.import-summary-title-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin-bottom: 4px;
}

.document-type-chip {
  font-size: 0.68rem;
  font-weight: 500;
  padding: 3px 8px;
  border-radius: var(--radius-full);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--muted);
  text-transform: capitalize;
}

.extraction-stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 12px;
}

.extraction-stat-card {
  text-align: center;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 6px;
  transition: transform var(--transition-fast), border-color var(--transition-fast);
  animation: fadeInUp 0.35s ease both;
}

.extraction-stat-card:nth-child(2) { animation-delay: 0.05s; }
.extraction-stat-card:nth-child(3) { animation-delay: 0.1s; }
.extraction-stat-card:nth-child(4) { animation-delay: 0.15s; }

.extraction-stat-card.highlight {
  border-color: var(--accent-border);
  background: var(--accent-soft);
}

.extraction-stat-value {
  display: block;
  font-size: 1.1rem;
  font-weight: 700;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}

.extraction-stat-label {
  display: block;
  font-size: 0.64rem;
  color: var(--muted);
  margin-top: 3px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.import-extraction-methods {
  margin-bottom: 12px;
}

.extraction-method-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.extraction-method-chip {
  font-size: 0.72rem;
  font-weight: 500;
  padding: 4px 10px;
  border-radius: var(--radius-full);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  transition: background var(--transition-fast);
}

.extraction-method-chip:hover {
  background: var(--accent-soft);
}

.provenance-list summary {
  cursor: pointer;
  color: var(--accent);
  font-weight: 500;
  padding: 4px 0;
  font-size: 0.78rem;
}

.provenance-rows {
  margin-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 200px;
  overflow-y: auto;
}

.provenance-row {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-elevated);
  font-size: 0.74rem;
  animation: fadeInUp 0.25s ease both;
}

.provenance-row-head {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.provenance-page {
  font-weight: 600;
  color: var(--text);
}

.provenance-method {
  font-size: 0.68rem;
  color: var(--muted);
  text-transform: capitalize;
}

.provenance-confidence {
  margin-left: auto;
  font-family: var(--font-mono);
  font-size: 0.68rem;
  color: var(--success);
  font-weight: 600;
}

.provenance-confidence.low {
  color: var(--warning);
}

.provenance-label {
  margin-top: 4px;
  color: var(--text-secondary);
}

.low-confidence-warnings .import-warnings-title {
  color: var(--warning);
}

.hidden { display: none !important; }

@media (max-width: 900px) {
  .msg { max-width: 92%; }
  .msg-actions { opacity: 1; }
  .import-stats-grid { grid-template-columns: repeat(2, 1fr); }
  .extraction-stats-grid { grid-template-columns: repeat(2, 1fr); }
  .export-actions { grid-template-columns: 1fr; }
}

/* Company data hub — quick stats in company panel */
.company-quick-stats {
  margin: 0 0 12px;
}

.stat-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.stat-pill {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 500;
  background: var(--surface-2, rgba(0, 0, 0, 0.05));
  color: var(--text-secondary);
  border: 1px solid var(--border);
}

.stat-pill-ready {
  background: color-mix(in srgb, var(--success) 12%, transparent);
  color: var(--success);
  border-color: color-mix(in srgb, var(--success) 30%, transparent);
}

.btn-block {
  display: block;
  width: 100%;
  text-align: center;
  margin-bottom: 16px;
}

.recent-upload-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  border-radius: var(--radius-sm, 6px);
  background: var(--surface-2, rgba(0, 0, 0, 0.03));
  border: 1px solid var(--border);
  font-size: 0.8rem;
}

.recent-upload-name {
  font-weight: 500;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.recent-upload-meta {
  flex-shrink: 0;
  font-size: 0.72rem;
  color: var(--muted);
}
