/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: 8px 14px;
  font-size: var(--fs-sm);
  font-weight: 600;
  border-radius: var(--radius-sm);
  border: 1px solid var(--color-border-strong);
  background: var(--color-surface);
  color: var(--color-text);
  cursor: pointer;
  transition: background var(--transition-fast), border-color var(--transition-fast);
}
.btn:hover { background: var(--color-surface-alt); text-decoration: none; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-primary { background: var(--color-primary); border-color: var(--color-primary); color: #fff; }
.btn-primary:hover { background: var(--color-primary-dark); }
.btn-danger { background: var(--color-danger); border-color: var(--color-danger); color: #fff; }
.btn-danger:hover { filter: brightness(0.92); }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: var(--color-surface-alt); }
.btn-sm { padding: 4px 10px; font-size: var(--fs-xs); }
.btn-block { width: 100%; justify-content: center; }

/* Cards */
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-4) var(--space-5);
}
.card + .card { margin-top: var(--space-4); }
.card__title { font-size: var(--fs-sm); font-weight: 700; text-transform: uppercase; letter-spacing: 0.03em; color: var(--color-text-muted); margin-bottom: var(--space-3); }

.stat-card { background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-md); padding: var(--space-4); }
.stat-card__value { font-size: var(--fs-xl); font-weight: 700; }
.stat-card__label { font-size: var(--fs-xs); color: var(--color-text-muted); margin-top: 2px; }

/* Forms */
.form-group { margin-bottom: var(--space-4); }
.form-label { display: block; font-size: var(--fs-sm); font-weight: 600; margin-bottom: 6px; }
.form-hint { font-size: var(--fs-xs); color: var(--color-text-muted); margin-top: 4px; }
.form-control {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  color: var(--color-text);
}
.form-control:focus { border-color: var(--color-primary); }
textarea.form-control { resize: vertical; min-height: 90px; line-height: var(--line-height-base); }
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: var(--space-3); }
.form-error { color: var(--color-danger); font-size: var(--fs-xs); margin-top: 4px; }
.checkbox-row { display: flex; align-items: center; gap: 8px; }

/* Tables */
.table-wrap { overflow-x: auto; border: 1px solid var(--color-border); border-radius: var(--radius-md); background: var(--color-surface); }
table.data-table { width: 100%; border-collapse: collapse; font-size: var(--fs-sm); }
.data-table th, .data-table td { padding: 10px 14px; text-align: left; border-bottom: 1px solid var(--color-border); white-space: nowrap; }
.data-table th { background: var(--color-surface-alt); font-weight: 600; color: var(--color-text-muted); font-size: var(--fs-xs); text-transform: uppercase; letter-spacing: 0.02em; }
.data-table tbody tr:hover { background: var(--color-surface-alt); }
.data-table td.wrap { white-space: normal; }
.data-table tbody tr.clickable { cursor: pointer; }

/* Badges */
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 999px; font-size: var(--fs-xs); font-weight: 600; }
.badge-neutral { background: #eceff2; color: var(--color-text-muted); }
.badge-primary { background: var(--color-primary-tint); color: var(--color-primary); }
.badge-success { background: var(--color-success-tint); color: var(--color-success); }
.badge-warning { background: var(--color-warning-tint); color: var(--color-warning); }
.badge-danger { background: var(--color-danger-tint); color: var(--color-danger); }
.badge-info { background: var(--color-info-tint); color: var(--color-info); }

/* Tabs */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--color-border); margin-bottom: var(--space-4); overflow-x: auto; }
.tab-btn { padding: 10px 16px; font-size: var(--fs-sm); font-weight: 600; color: var(--color-text-muted); background: none; border: none; border-bottom: 2px solid transparent; cursor: pointer; white-space: nowrap; }
.tab-btn:hover { color: var(--color-text); }
.tab-btn.active { color: var(--color-primary); border-bottom-color: var(--color-primary); }

/* Modal */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(15, 20, 26, 0.5);
  display: flex; align-items: center; justify-content: center; z-index: 100; padding: var(--space-4);
}
.modal {
  background: var(--color-surface); border-radius: var(--radius-md); box-shadow: var(--shadow-md);
  width: 100%; max-width: 520px; max-height: 90vh; overflow-y: auto;
}
.modal__header { display: flex; align-items: center; justify-content: space-between; padding: var(--space-4) var(--space-5); border-bottom: 1px solid var(--color-border); }
.modal__body { padding: var(--space-5); }
.modal__footer { padding: var(--space-4) var(--space-5); border-top: 1px solid var(--color-border); display: flex; justify-content: flex-end; gap: var(--space-2); }
.modal__close { background: none; border: none; font-size: 20px; cursor: pointer; color: var(--color-text-muted); line-height: 1; }

/* Confirm dialog reuses modal styles */

/* Toasts */
.toast-stack { position: fixed; bottom: var(--space-5); right: var(--space-5); display: flex; flex-direction: column; gap: var(--space-2); z-index: 200; max-width: 340px; }
.toast { padding: 12px 16px; border-radius: var(--radius-sm); font-size: var(--fs-sm); box-shadow: var(--shadow-md); color: #fff; }
.toast-success { background: var(--color-success); }
.toast-error { background: var(--color-danger); }
.toast-info { background: var(--color-info); }
.toast-warning { background: var(--color-warning); }

/* States */
.state-block { text-align: center; padding: var(--space-7) var(--space-4); color: var(--color-text-muted); }
.state-block__icon { font-size: 28px; margin-bottom: var(--space-3); opacity: 0.6; }
.spinner {
  width: 18px; height: 18px; border: 2px solid var(--color-border);
  border-top-color: var(--color-primary); border-radius: 50%;
  animation: spin 0.7s linear infinite; display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-row { display: flex; align-items: center; gap: var(--space-2); color: var(--color-text-muted); font-size: var(--fs-sm); padding: var(--space-4) 0; }

/* Alerts / warnings */
.alert { padding: 12px 14px; border-radius: var(--radius-sm); font-size: var(--fs-sm); border: 1px solid transparent; margin-bottom: var(--space-3); }
.alert-danger { background: var(--color-danger-tint); border-color: #e6b6b2; color: var(--color-danger); }
.alert-warning { background: var(--color-warning-tint); border-color: #edcf94; color: var(--color-warning); }
.alert-info { background: var(--color-info-tint); border-color: #b6cfe4; color: var(--color-info); }
.alert-success { background: var(--color-success-tint); border-color: #a9d9bd; color: var(--color-success); }

/* Pagination */
.pagination { display: flex; align-items: center; gap: var(--space-2); justify-content: flex-end; margin-top: var(--space-4); font-size: var(--fs-sm); }

/* Source viewer panel */
.source-panel { background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-md); padding: var(--space-4); align-self: start; position: sticky; top: calc(var(--topbar-height) + var(--space-4)); }
.source-panel__field { margin-bottom: var(--space-3); }
.source-panel__label { font-size: var(--fs-xs); color: var(--color-text-muted); text-transform: uppercase; letter-spacing: 0.03em; }
.source-panel__value { font-size: var(--fs-sm); margin-top: 2px; }

/* Progress meter for harvest (real numbers only, no fake percentage bar) */
.metric-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: var(--space-3); }
.metric-box { background: var(--color-surface-alt); border: 1px solid var(--color-border); border-radius: var(--radius-sm); padding: var(--space-3); text-align: center; }
.metric-box__value { font-size: var(--fs-lg); font-weight: 700; }
.metric-box__label { font-size: var(--fs-xs); color: var(--color-text-muted); }

/* Login page */
.login-shell { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: var(--color-primary-dark); }
.login-card { background: var(--color-surface); border-radius: var(--radius-md); box-shadow: var(--shadow-md); width: 100%; max-width: 380px; padding: var(--space-6); }
.login-card h1 { text-align: center; margin-bottom: var(--space-2); }
.login-card__sub { text-align: center; color: var(--color-text-muted); font-size: var(--fs-sm); margin-bottom: var(--space-5); }

/* Utility */
.flex { display: flex; align-items: center; }
.flex-between { display: flex; align-items: center; justify-content: space-between; }
.gap-2 { gap: var(--space-2); }
.gap-3 { gap: var(--space-3); }
.mt-3 { margin-top: var(--space-3); }
.mt-4 { margin-top: var(--space-4); }
.mb-0 { margin-bottom: 0; }
/* === Nong Nai (AI assistant) layout === */
.nong-nai-layout { display: grid; grid-template-columns: 240px 1.2fr 1fr; gap: var(--space-4); }
.conv-sidebar { display: flex; flex-direction: column; max-height: calc(100vh - 200px); position: sticky; top: calc(var(--topbar-height) + var(--space-4)); }
.conv-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 4px; margin-top: 4px; }
.conv-item { position: relative; padding: 8px; border-radius: var(--radius-sm); border: 1px solid var(--color-border); cursor: pointer; background: var(--color-surface); }
.conv-item:hover { background: var(--color-surface-alt); }
.conv-item--active { border-color: var(--color-primary); background: var(--color-primary-tint); }
.conv-item--pinned { border-color: var(--color-warning, var(--color-border)); }
.conv-item__row { display: flex; align-items: center; gap: 4px; font-size: 13px; font-weight: 600; }
.conv-item__title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-item__meta { font-size: 11px; color: var(--color-text-muted); margin-top: 2px; }
.conv-item__rename-input { font-size: 13px; padding: 2px 4px; }
.conv-item__actions { display: flex; gap: 2px; margin-top: 6px; opacity: 0; transition: opacity 0.15s; }
.conv-item:hover .conv-item__actions, .conv-item--active .conv-item__actions { opacity: 1; }
.btn-xs { padding: 1px 6px; font-size: 12px; line-height: 1.6; }
.ctx-viewer { display: flex; flex-direction: column; gap: var(--space-3); max-width: 560px; }
.ctx-block__title { font-weight: 600; font-size: 13px; margin-bottom: 4px; }
.ctx-item { font-size: 13px; padding: 4px 0; border-bottom: 1px solid var(--color-border); }
@media (max-width: 1200px) { .nong-nai-layout { grid-template-columns: 200px 1fr; } .nong-nai-overview { grid-column: 1 / -1; } }
.nong-nai-chat { display: flex; flex-direction: column; min-height: 70vh; }
.nong-nai-chat .card__title { margin-bottom: var(--space-3); }
.chat-history { flex: 1; min-height: 320px; max-height: 60vh; overflow-y: auto; padding: 8px; background: var(--color-surface-alt); border-radius: var(--radius-sm); border: 1px solid var(--color-border); margin-bottom: var(--space-2); }
.chat-msg { margin-bottom: var(--space-3); max-width: 92%; }
.chat-msg-user { margin-left: auto; }
.chat-msg-assistant { margin-right: auto; }
.chat-msg__author { font-size: 11px; color: var(--color-text-muted); margin-bottom: 2px; }
.chat-msg__body { padding: 8px 12px; border-radius: var(--radius-sm); background: var(--color-surface); border: 1px solid var(--color-border); white-space: pre-wrap; word-break: break-word; line-height: 1.5; }
.chat-msg-user .chat-msg__body { background: var(--color-primary-tint); border-color: var(--color-primary); color: var(--color-primary); }
.chat-msg__body--action { background: var(--color-info-tint); border-color: var(--color-info); color: var(--color-info); font-size: 13px; }
.chat-quick-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: var(--space-2); }
.chat-input-row { display: flex; gap: var(--space-2); align-items: flex-end; }
.chat-input-row textarea { flex: 1; resize: none; }
.nong-nai-overview { max-height: calc(100vh - 200px); overflow-y: auto; position: sticky; top: calc(var(--topbar-height) + var(--space-4)); }
.overview-case-header { padding-bottom: var(--space-3); margin-bottom: var(--space-3); border-bottom: 1px solid var(--color-border); }
.overview-case-header h3 { margin: 0 0 4px 0; font-size: var(--fs-lg); }
.overview-section { border: 1px solid var(--color-border); border-radius: var(--radius-sm); margin-bottom: var(--space-2); overflow: hidden; }
.overview-section__title { padding: 8px 12px; cursor: pointer; font-weight: 600; font-size: 13px; background: var(--color-surface-alt); user-select: none; }
.overview-section__title:hover { background: var(--color-surface); }
.overview-section__body { padding: 8px 12px; }
.overview-item { padding: 6px 0; border-bottom: 1px solid var(--color-border); }
.overview-item:last-child { border-bottom: none; }
@media (max-width: 900px) { .nong-nai-layout { grid-template-columns: 1fr; } .nong-nai-overview { position: static; max-height: none; } }

/* === Nong Nai: AI-edited field annotation === */
.form-control.ai-edited {
  border-color: #2563eb;
  border-width: 2px;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
  background: #f5f9ff;
}
.form-control.ai-edited:hover {
  cursor: help;
}
.field-annotation {
  margin-top: 6px;
  font-size: 12px;
}
.field-annotation__bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  border-radius: var(--radius-sm);
}
.field-annotation__label {
  color: #1e40af;
  font-weight: 600;
}

/* === Nong Nai: chat message additions === */
.chat-msg__time {
  font-size: 10px;
  color: var(--color-text-faint);
  margin-top: 2px;
  text-align: right;
}
.chat-msg--pending-edit .chat-msg__body--pending {
  background: #fffbeb !important;
  border-color: #f59e0b !important;
  color: #92400e !important;
}
.chat-msg--pending-edit code {
  background: rgba(0,0,0,0.06);
  padding: 1px 4px;
  border-radius: 3px;
  font-size: 12px;
}
.btn-doc {
  background: #f5f9ff;
  border-color: #2563eb;
  color: #1e40af;
}
.btn-doc:hover {
  background: #2563eb;
  color: #fff;
}

/* === Nong Nai: pending edits banner in overview === */
.overview-pending-alert {
  margin-bottom: var(--space-3);
}

/* === Document editor === */
.doc-editor-overlay {
  z-index: 150;
}
.doc-editor-modal {
  max-width: 1200px !important;
  width: 95vw !important;
  height: 92vh;
  display: flex;
  flex-direction: column;
}
.doc-editor__header {
  flex-shrink: 0;
}
.doc-editor__body {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 280px;
  grid-template-rows: 1fr;
  gap: var(--space-3);
  overflow: hidden;
  padding: var(--space-3) var(--space-5) !important;
}
.doc-editor__toolbar {
  grid-column: 1 / -1;
  display: flex;
  gap: var(--space-2);
}
.doc-editor__ai-box {
  grid-column: 1 / -1;
  background: var(--color-surface-alt);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: var(--space-3);
}
.doc-editor__pending-banner {
  grid-column: 1 / -1;
}
.doc-editor__editor-wrap {
  display: flex;
  position: relative;
  overflow: hidden;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  min-height: 0;
  height: 100%;
}
.doc-editor__line-numbers {
  flex-shrink: 0;
  width: 50px;
  padding: 10px 6px;
  text-align: right;
  background: var(--color-surface-alt);
  border-right: 1px solid var(--color-border);
  overflow: hidden;
  font-family: monospace;
  font-size: 13px;
  line-height: 1.5;
  color: var(--color-text-muted);
  user-select: none;
}
.doc-editor__line-num {
  height: 1.5em;
}
.doc-editor__textarea {
  flex: 1;
  border: none;
  border-radius: 0;
  font-family: 'Sarasa Mono SC', 'Noto Sans SC', monospace;
  font-size: 14px;
  line-height: 1.5;
  padding: 10px 14px;
  resize: none;
  white-space: pre-wrap;
  overflow-y: auto;
}
.doc-editor__textarea:focus {
  border: none;
  box-shadow: none;
  outline: none;
}
.doc-editor__sidebar {
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.doc-editor__sidebar-title {
  padding: 8px 12px;
  background: var(--color-surface-alt);
  font-weight: 600;
  font-size: 13px;
  border-bottom: 1px solid var(--color-border);
}
.doc-editor__versions-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px;
}
.doc-editor__version-row {
  padding: 8px;
  border-bottom: 1px solid var(--color-border);
  font-size: 13px;
}
.doc-editor__version-row.is-current {
  background: #f5f9ff;
}
.doc-editor__version-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 4px;
}
.doc-editor__version-meta {
  display: flex;
  align-items: center;
  margin-bottom: 4px;
}
.doc-editor__version-summary {
  font-size: 12px;
  color: var(--color-text-muted);
  margin-bottom: 6px;
}
.doc-editor__version-actions {
  display: flex;
  gap: 6px;
}

/* === Diff view === */
.diff-view {
  font-family: monospace;
  font-size: 13px;
  line-height: 1.5;
  background: var(--color-surface-alt);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 8px;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 320px;
  overflow-y: auto;
}
.diff-view--old {
  background: #fef2f2;
  border-color: #fecaca;
}
.diff-view--new {
  background: #f0fdf4;
  border-color: #bbf7d0;
}
.diff-row {
  display: flex;
  padding: 1px 8px;
  font-family: monospace;
  font-size: 13px;
}
.diff-row.diff-removed {
  background: #fee2e2;
  color: #991b1b;
}
.diff-row.diff-added {
  background: #dcfce7;
  color: #166534;
}
.diff-row.diff-unchanged {
  color: var(--color-text-muted);
}
.diff-line-num {
  width: 40px;
  text-align: right;
  margin-right: 8px;
  color: var(--color-text-faint);
  user-select: none;
}
.diff-sign {
  width: 16px;
  font-weight: bold;
}

@media (max-width: 900px) {
  .doc-editor__body {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr 200px;
  }
  .doc-editor__sidebar {
    max-height: 200px;
  }
}

/* === AI-sourced row indicators === */
.badge-ai {
  background: #dbeafe;
  color: #1e40af;
  border: 1px solid #93c5fd;
}
.ai-sourced-row {
  background: #f5f9ff !important;
}
.ai-sourced-row:hover {
  background: #eff6ff !important;
}
.data-table .ai-sourced-row td {
  border-left: 3px solid #2563eb;
}
.data-table .ai-sourced-row td:first-child {
  border-left: 3px solid #2563eb;
}

/* override: make doc editor near-fullscreen */
.doc-editor-modal {
  max-width: 100vw !important;
  width: 98vw !important;
  height: 95vh !important;
  max-height: 95vh !important;
  display: flex;
  flex-direction: column;
}

/* === AI Chat Widget (Facebook-style floating chat) === */
.ai-chat-widget {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 9999;
  font-family: inherit;
}
.ai-chat-fab {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: linear-gradient(135deg, #2563eb, #1e40af);
  border: none;
  color: #fff;
  cursor: pointer;
  box-shadow: 0 6px 16px rgba(37, 99, 235, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  transition: transform 0.2s, box-shadow 0.2s;
}
.ai-chat-fab:hover {
  transform: scale(1.08);
  box-shadow: 0 8px 24px rgba(37, 99, 235, 0.5);
}
.ai-chat-fab__icon {
  font-size: 24px;
  line-height: 1;
}
.ai-chat-fab__badge {
  position: absolute;
  top: -2px;
  right: -2px;
  background: #ef4444;
  color: #fff;
  border-radius: 999px;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  font-size: 11px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid #fff;
}
.ai-chat-panel {
  position: absolute;
  bottom: 70px;
  right: 0;
  width: 380px;
  max-width: calc(100vw - 40px);
  height: 560px;
  max-height: calc(100vh - 100px);
  background: var(--color-surface);
  border-radius: 12px;
  box-shadow: 0 10px 40px rgba(15, 23, 42, 0.25);
  border: 1px solid var(--color-border);
  display: none;
  flex-direction: column;
  overflow: hidden;
  animation: ai-chat-pop 0.18s ease-out;
}
.ai-chat-widget.is-open .ai-chat-panel {
  display: flex;
}
@keyframes ai-chat-pop {
  from { opacity: 0; transform: translateY(8px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
.ai-chat-panel__header {
  background: linear-gradient(135deg, #2563eb, #1e40af);
  color: #fff;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}
.ai-chat-panel__title {
  display: flex;
  align-items: center;
  gap: 10px;
}
.ai-chat-panel__avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(255,255,255,0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 16px;
}
.ai-chat-panel__name {
  font-weight: 600;
  font-size: 14px;
}
.ai-chat-panel__status {
  font-size: 11px;
  opacity: 0.85;
}
.ai-chat-panel__btn {
  background: rgba(255,255,255,0.15);
  border: none;
  color: #fff;
  width: 28px;
  height: 28px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.ai-chat-panel__btn:hover {
  background: rgba(255,255,255,0.25);
}
.ai-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  background: var(--color-surface-alt);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.ai-msg {
  max-width: 80%;
  display: flex;
}
.ai-msg--user {
  align-self: flex-end;
  justify-content: flex-end;
}
.ai-msg--assistant {
  align-self: flex-start;
}
.ai-msg__bubble {
  padding: 8px 12px;
  border-radius: 14px;
  font-size: 13px;
  line-height: 1.5;
  word-break: break-word;
  white-space: pre-wrap;
}
.ai-msg--user .ai-msg__bubble {
  background: #2563eb;
  color: #fff;
  border-bottom-right-radius: 4px;
}
.ai-msg--assistant .ai-msg__bubble {
  background: var(--color-surface);
  color: var(--color-text);
  border: 1px solid var(--color-border);
  border-bottom-left-radius: 4px;
}
.ai-msg__bubble--action {
  background: #eff6ff !important;
  color: #1e40af !important;
  border-color: #bfdbfe !important;
  font-size: 12px;
}
.ai-chat-quick {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 8px 12px;
  background: var(--color-surface);
  border-top: 1px solid var(--color-border);
  flex-shrink: 0;
}
.ai-chat-quick__btn {
  background: var(--color-surface-alt);
  border: 1px solid var(--color-border);
  color: var(--color-text);
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  cursor: pointer;
  font-weight: 500;
}
.ai-chat-quick__btn:hover {
  background: #eff6ff;
  border-color: #93c5fd;
  color: #1e40af;
}
.ai-chat-input-row {
  display: flex;
  gap: 8px;
  padding: 10px 12px;
  background: var(--color-surface);
  border-top: 1px solid var(--color-border);
  align-items: flex-end;
  flex-shrink: 0;
}
.ai-chat-input {
  flex: 1;
  resize: none;
  border: 1px solid var(--color-border);
  border-radius: 18px;
  padding: 8px 14px;
  font-size: 13px;
  font-family: inherit;
  max-height: 120px;
  outline: none;
  background: var(--color-surface);
  color: var(--color-text);
}
.ai-chat-input:focus {
  border-color: #2563eb;
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.15);
}
.ai-chat-send-btn {
  background: #2563eb;
  color: #fff;
  border: none;
  border-radius: 50%;
  width: 36px;
  height: 36px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
.ai-chat-send-btn:hover {
  background: #1e40af;
}
.ai-chat-send-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
@media (max-width: 480px) {
  .ai-chat-panel {
    width: calc(100vw - 32px);
    height: calc(100vh - 100px);
  }
}

/* === DocumentEditor: line number spinner + auto-save status === */
.doc-editor__line-num.is-loading {
  background: rgba(37, 99, 235, 0.08);
  position: relative;
}
.doc-editor__line-num.is-done {
  color: #16a34a;
  font-weight: 700;
}
.line-spinner {
  display: inline-block;
  width: 12px;
  height: 12px;
  border: 2px solid rgba(37, 99, 235, 0.2);
  border-top-color: #2563eb;
  border-radius: 50%;
  animation: line-spin 0.6s linear infinite;
  vertical-align: middle;
}
@keyframes line-spin {
  to { transform: rotate(360deg); }
}
.autosave-status {
  display: inline-block;
  font-size: 11px;
  font-weight: 500;
  min-width: 100px;
}
.doc-editor__textarea:disabled {
  background: #fafbff;
  cursor: not-allowed;
}

/* === Chat widget: pending edit chip === */
.ai-msg__bubble--pending-edit {
  background: #fffbeb !important;
  border: 1px solid #fbbf24 !important;
  color: #78350f !important;
  border-radius: 12px !important;
}
.ai-chat-confirm-btn {
  background: #2563eb;
  color: #fff;
  border: none;
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}
.ai-chat-confirm-btn:hover {
  background: #1e40af;
}
.ai-chat-revert-btn {
  background: transparent;
  color: #6b7280;
  border: 1px solid #d1d5db;
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 12px;
  cursor: pointer;
}
.ai-chat-revert-btn:hover {
  background: #f3f4f6;
  color: #1f2937;
}

/* === DocumentEditor: highlight mirror layer + search bar + context menu === */
.doc-editor__editor-wrap {
  position: relative;
}
.doc-editor__highlight-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  padding: 10px 14px;
  font-family: 'Sarasa Mono SC', 'Noto Sans SC', monospace;
  font-size: 14px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
  overflow: hidden;
  color: transparent;
  z-index: 1;
}
.doc-editor__highlight-layer mark.search-highlight {
  background: rgba(250, 204, 21, 0.55);
  color: transparent;
  border-radius: 2px;
}
.doc-editor__highlight-layer mark.search-highlight--current {
  background: rgba(249, 115, 22, 0.7);
}
.doc-editor__textarea {
  position: relative;
  z-index: 2;
  background: transparent;
}

/* === Right-click context menu === */
.doc-context-menu {
  position: fixed;
  z-index: 10000;
  background: var(--color-surface);
  border: 1px solid var(--color-border-strong);
  border-radius: 6px;
  box-shadow: 0 6px 24px rgba(15, 23, 42, 0.18);
  padding: 4px;
  min-width: 200px;
  font-size: 13px;
}
.doc-context-menu__item {
  padding: 8px 12px;
  cursor: pointer;
  border-radius: 4px;
  color: var(--color-text);
}
.doc-context-menu__item:hover {
  background: var(--color-primary-tint);
  color: var(--color-primary);
}
.doc-context-menu__item.is-disabled {
  opacity: 0.4;
  cursor: not-allowed;
}
.doc-context-menu__item.is-disabled:hover {
  background: transparent;
  color: var(--color-text);
}
.doc-context-menu__separator {
  height: 1px;
  background: var(--color-border);
  margin: 4px 0;
}

/* === VSCode-style search bar (absolutely positioned overlay top-right) === */
.doc-search-bar {
  position: absolute;
  top: 8px;
  right: 12px;
  width: 420px;
  max-width: calc(100% - 24px);
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 8px 12px;
  background: var(--color-surface);
  border: 1px solid var(--color-border-strong);
  border-radius: 6px;
  box-shadow: 0 4px 16px rgba(15, 23, 42, 0.12);
  z-index: 10;
}
.doc-search-row {
  display: flex;
  gap: 6px;
  align-items: center;
}
.doc-search-bar .doc-search__input,
.doc-search-bar .doc-search__replace {
  flex: 1;
  font-size: 13px;
  padding: 5px 10px;
  border-radius: 4px;
}
.doc-search__counter {
  font-size: 11px;
  color: var(--color-text-muted);
  font-family: monospace;
  min-width: 80px;
  text-align: right;
}

/* === Chat widget: retry chip === */
.ai-msg__bubble--retry {
  background: #fef2f2 !important;
  border: 1px solid #fca5a5 !important;
  color: #991b1b !important;
  border-radius: 12px !important;
}
/* --- Workflow status checklist (Phase 2: case overview) --- */
.workflow-checklist { display: flex; flex-direction: column; gap: 6px; }
.workflow-step { display: flex; align-items: center; gap: 8px; padding: 4px 0; font-size: 14px; }
.workflow-step .wf-icon { display: inline-flex; align-items: center; justify-content: center; width: 20px; height: 20px; border-radius: 50%; font-size: 12px; font-weight: bold; flex-shrink: 0; }
.workflow-step.wf-done .wf-icon { background: var(--color-success-tint, #e3f6e8); color: var(--color-success, #2e7d32); }
.workflow-step.wf-pending .wf-icon { background: #f1f1f4; color: #9a9aa5; }
.workflow-step.wf-warn .wf-icon { background: var(--color-warning-tint, #fdf1de); color: var(--color-warning, #b8860b); }
.workflow-step.wf-neutral .wf-icon { background: transparent; color: #c0c0c8; }
.workflow-step.wf-done span:last-child { color: var(--color-text, #222); }
.workflow-step.wf-pending span:last-child, .workflow-step.wf-neutral span:last-child { color: #9a9aa5; }
.next-action-box { background: #f6f7fb; border: 1px solid #e5e6ee; border-radius: 8px; padding: 12px 14px; }
.next-action-label { font-weight: 600; font-size: 13px; margin-bottom: 4px; color: #555; }

/* --- Agent explanation cards (Phase 3: analysis tab) --- */
.agent-explain-card { border: 1px solid #e5e6ee; border-radius: 8px; padding: 14px; margin-bottom: 12px; }
.agent-explain-header { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.agent-explain-name { font-weight: 700; font-size: 15px; }
.agent-explain-purpose { color: #555; font-size: 13px; margin: 6px 0; }
.agent-explain-meta { font-size: 12px; color: #888; display: flex; gap: 14px; flex-wrap: wrap; margin-top: 6px; }
.agent-explain-details { margin-top: 10px; font-size: 13px; color: #444; border-top: 1px dashed #e5e6ee; padding-top: 8px; }
.agent-explain-details summary { cursor: pointer; color: var(--color-primary, #3b5bdb); font-size: 13px; }
.workflow-pipeline { display: flex; align-items: center; flex-wrap: wrap; gap: 4px; font-size: 13px; margin: 10px 0 18px; }
.workflow-pipeline .wp-node { background: #eef0fa; border-radius: 6px; padding: 4px 10px; }
.workflow-pipeline .wp-arrow { color: #aaa; }

/* --- Notification bell (Phase 5: notifications) --- */
.notif-bell { position: relative; display: inline-flex; }
.notif-bell__btn { position: relative; display: inline-flex; align-items: center; justify-content: center; }
.notif-bell__badge {
  position: absolute; top: -4px; right: -4px;
  min-width: 16px; height: 16px; padding: 0 4px;
  border-radius: 999px; background: var(--color-danger); color: #fff;
  font-size: 10px; font-weight: 700; line-height: 16px; text-align: center;
  display: inline-flex; align-items: center; justify-content: center;
}
.notif-panel {
  position: absolute; top: calc(100% + 8px); right: 0; z-index: 50;
  width: 340px; max-width: calc(100vw - 32px);
  background: var(--color-surface); border: 1px solid var(--color-border);
  border-radius: var(--radius-md); box-shadow: var(--shadow-md);
  overflow: hidden;
}
.notif-panel__header {
  display: flex; align-items: center; justify-content: space-between;
  padding: var(--space-3) var(--space-4); border-bottom: 1px solid var(--color-border);
}
.notif-panel__list { max-height: 420px; overflow-y: auto; }
.notif-panel__empty { padding: var(--space-5); text-align: center; color: var(--color-text-faint); font-size: var(--fs-sm); }
.notif-item {
  display: flex; gap: var(--space-2); padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--color-border); cursor: pointer;
  transition: background var(--transition-fast);
}
.notif-item:last-child { border-bottom: none; }
.notif-item:hover { background: var(--color-surface-alt); }
.notif-item--unread { background: var(--color-primary-tint); }
.notif-item--unread:hover { background: var(--color-primary-tint); filter: brightness(0.98); }
.notif-item__icon { font-size: var(--fs-md); line-height: 1; flex-shrink: 0; }
.notif-item__body { min-width: 0; flex: 1; }
.notif-item__title { font-size: var(--fs-sm); font-weight: 600; color: var(--color-text); }
.notif-item__text { font-size: var(--fs-xs); color: var(--color-text-muted); margin-top: 2px; }
.notif-item__time { font-size: var(--fs-xs); color: var(--color-text-faint); margin-top: 4px; }

/* Phase 9: background job progress bar (topbar widget) */
.job-progress-bar { height: 6px; border-radius: 3px; background: var(--color-surface-alt); overflow: hidden; margin: 4px 0; }
.job-progress-bar__fill { height: 100%; background: var(--color-primary); transition: width 0.3s ease; }

/* Phase 11: citation chips + source modal */
.citation-chips { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 4px; }
.citation-chip {
  border: 1px solid var(--color-border-strong); background: var(--color-surface-alt);
  color: var(--color-primary); border-radius: var(--radius-sm); font-size: var(--fs-xs);
  padding: 1px 6px; cursor: pointer; line-height: 1.6; transition: background var(--transition-fast);
}
.citation-chip:hover { background: var(--color-primary-tint); }
.citation-modal__label { font-weight: 600; margin-bottom: var(--space-2); }
.citation-modal__page { font-size: var(--fs-xs); color: var(--color-text-muted); margin-bottom: var(--space-2); }
.citation-modal__excerpt {
  background: var(--color-surface-alt); border: 1px solid var(--color-border);
  border-radius: var(--radius-sm); padding: var(--space-3); font-size: var(--fs-sm);
  white-space: pre-wrap; line-height: 1.6;
}

/* Phase 12: AI feedback (up/down vote) row + downvote reason picker */
.feedback-row { display: flex; gap: 4px; margin-top: 4px; }
.feedback-btn {
  border: 1px solid var(--color-border); background: var(--color-surface);
  border-radius: var(--radius-sm); font-size: var(--fs-sm); line-height: 1;
  padding: 3px 8px; cursor: pointer; transition: background var(--transition-fast), border-color var(--transition-fast);
}
.feedback-btn:hover { background: var(--color-surface-alt); }
.feedback-btn--active { border-color: var(--color-primary); background: var(--color-primary-tint); }
.feedback-reason-list { display: flex; flex-direction: column; gap: var(--space-2); }
.feedback-reason-option {
  text-align: left; border: 1px solid var(--color-border); background: var(--color-surface);
  border-radius: var(--radius-sm); padding: var(--space-2) var(--space-3); cursor: pointer;
  font-size: var(--fs-sm); transition: background var(--transition-fast), border-color var(--transition-fast);
}
.feedback-reason-option:hover { background: var(--color-surface-alt); }
.feedback-reason-option--selected { border-color: var(--color-primary); background: var(--color-primary-tint); font-weight: 600; }
