/* ==========================================================================
   DasTool Application Styles
   Uses design tokens from theme.css
   ========================================================================== */

/* --------------------------------------------------------------------------
   Auth Pages
   -------------------------------------------------------------------------- */
.card.card-auth {
  border: none;
  box-shadow: var(--shadow-md);
}

/* --------------------------------------------------------------------------
   HTMX Loading Indicators
   -------------------------------------------------------------------------- */
.htmx-indicator {
  display: none;
}

.htmx-request .htmx-indicator {
  display: inline-block;
}

.htmx-request.htmx-indicator {
  display: inline-block;
}

/* --------------------------------------------------------------------------
   Typography Utilities
   -------------------------------------------------------------------------- */
p:last-child {
  margin-bottom: 0;
}

/* --------------------------------------------------------------------------
   Dashboard Widget Styles
   -------------------------------------------------------------------------- */
.card.card-widget {
  transition: all var(--transition-slow);
  margin-bottom: 1.5rem;
}

.card.card-widget:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg) !important;
}

/* Widget Card Body Spacing */
@media (max-width: 768px) {
  .card.card-widget .card-body {
    padding: 1rem;
  }
}

/* Single Metric Display */
.display-3 {
  font-size: 3rem;
  font-weight: 700;
  font-family: var(--font-mono);
  color: var(--color-accent);
}

@media (max-width: 768px) {
  .display-3 {
    font-size: 2rem;
  }
}

/* --------------------------------------------------------------------------
   Metric Cards
   -------------------------------------------------------------------------- */
.metric-card {
  background: var(--color-bg-card);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  transition: all var(--transition-base);
}

.metric-card:hover {
  transform: translateY(-2px);
  border-color: var(--color-border-hover);
  box-shadow: var(--shadow-md);
}

.metric-card .h3,
.metric-card .metric-value {
  font-family: var(--font-mono);
  color: var(--color-accent);
}

/* Auto-scaling metric values to fit container */
.metric-card .metric-value {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  /* Responsive font: min 1rem, preferred 1.5rem, but scales down with container */
  font-size: clamp(0.9rem, 2.5cqw, 1.75rem);
}

/* Container query fallback for browsers without cqw support */
@supports not (font-size: 1cqw) {
  .metric-card .metric-value {
    font-size: 1.25rem;
  }
}

/* Make metric cards container query contexts */
.metric-card {
  container-type: inline-size;
}

.metric-card .metric-label {
  font-size: 0.75rem;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.metric-card .metric-change {
  font-size: 0.875rem;
}

.metric-card .metric-change.positive,
.metric-card .metric-change.up {
  color: var(--color-accent);
}

.metric-card .metric-change.negative,
.metric-card .metric-change.down {
  color: #dc3545;
}

@media (max-width: 576px) {
  .metric-card {
    margin-bottom: 0.75rem;
  }
  
  .metric-card .h3 {
    font-size: 1.5rem;
  }
  
  .metric-card .metric-value {
    font-size: 1.25rem;
  }
}

/* --------------------------------------------------------------------------
   Table Styles
   -------------------------------------------------------------------------- */
.table-responsive {
  border-radius: var(--radius-md);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.table {
  margin-bottom: 0;
}

.table thead th {
  border-bottom: 2px solid var(--color-border);
  font-weight: 600;
  text-transform: uppercase;
  font-size: 0.85rem;
  letter-spacing: 0.5px;
  white-space: nowrap;
  padding: 0.75rem 1rem;
  color: var(--color-text-muted);
  background: var(--color-bg-elevated);
}

.table tbody td {
  padding: 0.75rem 1rem;
  vertical-align: middle;
  color: var(--color-text);
}

.table tbody tr:hover {
  background-color: rgba(0, 184, 148, 0.05);
}

.table tbody tr:last-child td {
  border-bottom: none;
}

@media (max-width: 768px) {
  .table thead th,
  .table tbody td {
    padding: 0.5rem 0.75rem;
    font-size: 0.875rem;
  }
  
  .table thead th {
    font-size: 0.75rem;
  }
}

@media (max-width: 576px) {
  .table-responsive {
    font-size: 0.875rem;
  }
  
  .table-responsive table {
    min-width: 600px;
  }
}

/* --------------------------------------------------------------------------
   Chart Container
   -------------------------------------------------------------------------- */
.chart-container {
  position: relative;
  width: 100%;
  min-height: 300px;
}

canvas {
  max-width: 100%;
  height: auto !important;
}

@media (max-width: 768px) {
  .chart-container {
    min-height: 250px;
    height: 250px !important;
  }
}

@media (max-width: 576px) {
  .chart-container {
    min-height: 200px;
    height: 200px !important;
  }
}

/* --------------------------------------------------------------------------
   Widget Title
   -------------------------------------------------------------------------- */
.card-subtitle {
  font-weight: 600;
  font-size: 0.9rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--color-text-muted);
  margin-bottom: 1rem;
}

@media (max-width: 768px) {
  .card-subtitle {
    font-size: 0.8rem;
    margin-bottom: 0.75rem;
  }
}

/* --------------------------------------------------------------------------
   Empty State Styles
   -------------------------------------------------------------------------- */
.empty-state {
  text-align: center;
  padding: 3rem 2rem;
}

.empty-state-icon {
  width: 64px;
  height: 64px;
  background: rgba(0, 184, 148, 0.1);
  border-radius: var(--radius-lg);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.75rem;
  color: var(--color-accent);
  margin: 0 auto 1.5rem;
}

.empty-state h5 {
  color: var(--color-text);
  margin-bottom: 0.5rem;
}

.empty-state p {
  color: var(--color-text-muted);
}

/* Legacy empty state styles */
.text-muted.text-center.py-4 {
  padding: 2rem 1rem;
  color: var(--color-text-muted);
  font-style: italic;
}

/* --------------------------------------------------------------------------
   Chat Page — Full-viewport Layout
   -------------------------------------------------------------------------- */

/* The chat page is a flex column that fills the remaining viewport
   below the navbar. The parent <main> needs to cooperate. */
.chat-page {
  display: flex;
  flex-direction: column;
  height: calc(100dvh - var(--chat-offset, 72px));
  overflow: hidden;
}

/* --- Header bar --- */
.chat-header {
  flex-shrink: 0;
  border-bottom: 1px solid var(--color-border);
  background: var(--color-bg);
  padding: 0.75rem 1.5rem;
}

.chat-header-inner {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  max-width: 960px;
  margin: 0 auto;
}

.chat-back-link {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  color: var(--color-text-muted);
  text-decoration: none;
  transition: all var(--transition-fast);
  flex-shrink: 0;
}

.chat-back-link:hover {
  background: var(--color-bg-elevated);
  color: var(--color-text);
}

.chat-title {
  font-size: 1rem;
  font-weight: 600;
  margin: 0;
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-subtitle {
  font-size: 0.75rem;
  color: var(--color-text-muted);
}

/* --- Messages area --- */
.chat-messages {
  flex: 1 1 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 1.5rem 1rem;
  scroll-behavior: smooth;
}

.chat-messages-inner {
  max-width: 960px;
  margin: 0 auto;
}

/* --- Individual message --- */
.chat-msg {
  display: flex;
  gap: 0.75rem;
  margin-bottom: 1.75rem;
  align-items: flex-start;
}

.chat-msg--user {
  flex-direction: row-reverse;
}

/* Avatar */
.chat-msg-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 0.8rem;
  margin-top: 0.125rem;
}

.chat-msg-avatar--user {
  background: var(--color-bg-elevated);
  border: 1px solid var(--color-border);
  color: var(--color-text-muted);
}

.chat-msg-avatar--ai {
  background: var(--gradient-accent);
  color: var(--color-on-accent);
}

/* Message body */
.chat-msg-body {
  min-width: 0;
  max-width: 85%;
}

.chat-msg--user .chat-msg-body {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
}

/* Sender + timestamp row */
.chat-msg-meta {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  margin-bottom: 0.25rem;
}

.chat-msg--user .chat-msg-meta {
  flex-direction: row-reverse;
}

.chat-msg-sender {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--color-text);
}

.chat-msg-time {
  font-size: 0.7rem;
  color: var(--color-text-secondary);
}

/* Message content bubble */
.chat-msg-content {
  font-size: 0.925rem;
  line-height: 1.65;
  color: var(--color-text);
}

.chat-msg-content--user {
  background: var(--gradient-accent);
  color: var(--color-on-accent);
  border-radius: var(--radius-md) var(--radius-md) 4px var(--radius-md);
  padding: 0.75rem 1rem;
}

.chat-msg-content--user p {
  color: inherit;
}

/* Markdown tables inside chat messages */
.chat-msg-content table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  margin: 0.75rem 0;
  font-size: 0.85rem;
  line-height: 1.5;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.chat-msg-content thead th {
  background: var(--color-bg-elevated);
  color: var(--color-text-muted);
  font-weight: 600;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  padding: 0.6rem 0.875rem;
  border-bottom: 2px solid var(--color-border);
  white-space: nowrap;
  text-align: left;
}

.chat-msg-content thead th:not(:last-child) {
  border-right: 1px solid var(--color-border);
}

.chat-msg-content tbody td {
  padding: 0.5rem 0.875rem;
  color: var(--color-text);
  border-bottom: 1px solid var(--color-border);
  vertical-align: middle;
}

.chat-msg-content tbody td:not(:last-child) {
  border-right: 1px solid var(--color-border);
}

.chat-msg-content tbody tr:last-child td {
  border-bottom: none;
}

.chat-msg-content tbody tr:hover {
  background: rgba(0, 184, 148, 0.04);
}

/* Bold rows (e.g. "Total") get a subtle accent */
.chat-msg-content tbody tr td:first-child strong,
.chat-msg-content tbody tr th:first-child strong {
  color: var(--color-text);
}

.chat-msg-content tbody tr:has(strong) {
  background: var(--color-bg-elevated);
  font-weight: 500;
}

/* Numeric alignment — right-align columns that look numeric */
.chat-msg-content thead th + th,
.chat-msg-content tbody td + td {
  text-align: right;
}

/* Keep first column left-aligned (labels) */
.chat-msg-content thead th:first-child,
.chat-msg-content tbody td:first-child {
  text-align: left;
}

/* Responsive: horizontal scroll wrapper for wide tables */
.chat-msg-content > div:has(> table),
.chat-msg-content > table {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

@media (max-width: 576px) {
  .chat-msg-content table {
    font-size: 0.8rem;
  }

  .chat-msg-content thead th,
  .chat-msg-content tbody td {
    padding: 0.4rem 0.625rem;
  }
}

/* --- Tool call / Thinking steps — compact chips --- */
.chat-msg-steps {
  display: flex;
  flex-wrap: wrap;
  gap: 0.375rem;
  margin-bottom: 0.75rem;
}

/* Steps collapse to full-width only when expanded */
.chat-step {
  flex-shrink: 0;
}

.chat-step:has(.collapse.show),
.chat-step:has(.collapsing) {
  flex-basis: 100%;
}

.chat-step-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  background: var(--color-bg-elevated);
  border: 1px solid var(--color-border);
  border-radius: 100px;
  padding: 0.25rem 0.75rem;
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--color-text-muted);
  cursor: pointer;
  transition: all var(--transition-fast);
  line-height: 1.4;
}

.chat-step-toggle:hover {
  border-color: var(--color-border-hover);
  color: var(--color-text);
  background: var(--color-bg-card);
}

.chat-step-toggle i:first-child {
  font-size: 0.85rem;
}

.chat-step-chevron {
  font-size: 0.6rem !important;
  opacity: 0.5;
  transition: transform var(--transition-fast);
}

.chat-step-toggle[aria-expanded="true"] .chat-step-chevron {
  transform: rotate(180deg);
}

.chat-step-detail {
  background: var(--color-bg-elevated);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 0.75rem;
  margin-top: 0.375rem;
  font-size: 0.8rem;
  color: var(--color-text);
}

.chat-step-label {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--color-text-muted);
  margin-bottom: 0.25rem;
}

.chat-step-code {
  font-size: 0.78rem !important;
  padding: 0.5rem !important;
  max-height: 200px;
  overflow-y: auto;
}

.chat-spin {
  animation: spin 1s linear infinite;
}

/* --- Processing state --- */
.chat-msg-processing {
  display: inline-flex;
  align-items: center;
  gap: 0.625rem;
  background: var(--color-bg-elevated);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 0.625rem 1rem;
  animation: processingPulse 2s ease-in-out infinite;
}

.chat-msg-failed {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  color: #dc3545;
  font-size: 0.875rem;
  font-weight: 500;
}

/* --- Dashboard widgets inside messages --- */
.chat-msg-widget {
  margin-top: 0.5rem;
  max-width: 100%;
}

/* --- Feedback buttons --- */
.chat-msg-feedback {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  margin-top: 0.75rem;
  flex-wrap: wrap;
}

.chat-feedback-btn {
  background: none;
  border: none;
  padding: 0.25rem 0.35rem;
  color: var(--color-text-muted);
  font-size: 0.95rem;
  cursor: pointer;
  transition: color var(--transition-fast);
  line-height: 1;
}

.chat-feedback-btn:hover {
  color: var(--color-text);
}

.chat-feedback-form {
  flex-basis: 100%;
  max-width: 400px;
}

.chat-feedback-form textarea {
  background: var(--color-bg-elevated);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  font-size: 0.85rem;
  padding: 0.5rem 0.75rem;
  resize: vertical;
  transition: border-color var(--transition-fast);
}

.chat-feedback-form textarea:focus {
  border-color: var(--color-accent);
  box-shadow: 0 0 0 2px rgba(var(--color-accent-rgb, 79, 70, 229), 0.15);
  outline: none;
}

.chat-feedback-form .btn-primary {
  font-size: 0.8rem;
  padding: 0.3rem 0.85rem;
  border-radius: 100px;
}

.chat-feedback-form .btn-outline-secondary {
  font-size: 0.8rem;
  padding: 0.3rem 0.85rem;
  border-radius: 100px;
  border-color: var(--color-border);
  color: var(--color-text-secondary);
}

.chat-feedback-form .btn-outline-secondary:hover {
  background: var(--color-bg-elevated);
  color: var(--color-text);
}

/* --- Composer (input area) --- */
.chat-composer {
  flex-shrink: 0;
  border-top: 1px solid var(--color-border);
  background: var(--color-bg);
  padding: 0.75rem 1rem;
}

.chat-composer-readonly {
  text-align: center;
  padding: 0.875rem 1rem;
  font-size: 0.85rem;
}

.chat-composer-form {
  max-width: 960px;
  margin: 0 auto;
}

.chat-composer-input-wrap {
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
  background: var(--color-bg-card);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 0.5rem 0.5rem 0.5rem 1rem;
  transition: border-color var(--transition-base), box-shadow var(--transition-base);
}

.chat-composer-input-wrap:focus-within {
  border-color: var(--color-accent);
  box-shadow: 0 0 0 3px rgba(0, 184, 148, 0.12);
}

.chat-composer-input {
  flex: 1;
  border: none;
  outline: none;
  background: transparent;
  font-family: var(--font-display);
  font-size: 0.925rem;
  line-height: 1.5;
  color: var(--color-text);
  resize: none;
  padding: 0.25rem 0;
  min-height: 24px;
  max-height: 160px;
}

.chat-composer-input::placeholder {
  color: var(--color-text-secondary);
}

.chat-send-btn {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: none;
  background: var(--color-accent);
  color: var(--color-on-accent);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: all var(--transition-fast);
  font-size: 1rem;
}

.chat-send-btn:hover:not(:disabled) {
  background: var(--color-accent-hover);
  transform: scale(1.05);
}

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

.chat-send-btn.is-processing {
  background: var(--color-bg-elevated);
  border: 1px solid var(--color-border);
}

.chat-send-btn.is-processing .ai-thinking-icon {
  width: 16px;
  height: 16px;
}

.chat-composer-hint {
  text-align: center;
  font-size: 0.7rem;
  color: var(--color-text-secondary);
  margin-top: 0.375rem;
}

.chat-composer-hint kbd {
  font-family: var(--font-display);
  font-size: 0.65rem;
  background: var(--color-bg-elevated);
  border: 1px solid var(--color-border);
  border-radius: 3px;
  padding: 0.05em 0.35em;
  color: var(--color-text-muted);
}

/* --- Chat starters --- */
.chat-starter-btn {
  border-radius: var(--radius-sm);
  transition: all var(--transition-fast);
}

.chat-starter-btn:hover {
  border-color: var(--color-accent) !important;
  background: rgba(0, 184, 148, 0.1) !important;
}

/* --- Responsive adjustments --- */
@media (max-width: 768px) {
  .chat-page {
    height: calc(100dvh - var(--chat-offset, 60px));
  }

  .chat-header {
    padding: 0.625rem 1rem;
  }

  .chat-messages {
    padding: 1rem 0.75rem;
  }

  .chat-msg-body {
    max-width: 90%;
  }

  .chat-msg-avatar {
    width: 26px;
    height: 26px;
    font-size: 0.7rem;
  }

  .chat-composer {
    padding: 0.5rem 0.75rem;
  }
}

@media (max-width: 576px) {
  .chat-msg-body {
    max-width: 95%;
  }

  .chat-msg {
    gap: 0.5rem;
  }
}

/* --------------------------------------------------------------------------
   Data Source Cards
   -------------------------------------------------------------------------- */
.data-source-card {
  background: var(--color-bg-card);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  transition: all var(--transition-slow);
}

.data-source-card:hover {
  border-color: var(--color-border-hover);
  box-shadow: var(--shadow-md);
}

.data-source-icon {
  width: 48px;
  height: 48px;
  background: rgba(0, 184, 148, 0.1);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  color: var(--color-accent);
}

/* --------------------------------------------------------------------------
   Status Indicators
   -------------------------------------------------------------------------- */
.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
}

.status-dot.active,
.status-dot.success {
  background: var(--color-accent);
}

.status-dot.pending,
.status-dot.warning {
  background: #ffc107;
}

.status-dot.error,
.status-dot.danger {
  background: #dc3545;
}

.status-dot.inactive {
  background: var(--color-text-secondary);
}

/* Pulse animation for active status */
.status-dot.pulse {
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0%, 100% { 
    opacity: 1; 
    transform: scale(1); 
  }
  50% { 
    opacity: 0.5; 
    transform: scale(1.2); 
  }
}

/* --------------------------------------------------------------------------
   Loading States
   -------------------------------------------------------------------------- */
.skeleton {
  background: linear-gradient(
    90deg,
    var(--color-bg-elevated) 25%,
    rgba(0, 0, 0, 0.05) 50%,
    var(--color-bg-elevated) 75%
  );
  background-size: 200% 100%;
  animation: skeleton-loading 1.5s infinite;
  border-radius: var(--radius-sm);
}

@keyframes skeleton-loading {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* --------------------------------------------------------------------------
   Code / SQL Display
   -------------------------------------------------------------------------- */
pre {
  font-family: var(--font-mono);
  font-size: 0.875rem;
  background: var(--color-bg-elevated);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 1rem;
  overflow-x: auto;
  margin: 0;
  white-space: pre-wrap;
  word-wrap: break-word;
}

pre code {
  font-family: inherit;
  font-size: inherit;
  background: transparent;
  border: none;
  border-radius: 0;
  padding: 0;
  color: var(--color-text);
  display: block;
  white-space: pre-wrap;
  word-wrap: break-word;
}

code {
  font-family: var(--font-mono);
  font-size: 0.875em;
  color: var(--color-accent);
  background: rgba(0, 184, 148, 0.1);
  padding: 0.125rem 0.375rem;
  border-radius: var(--radius-sm);
}

pre code {
  color: var(--color-text);
  background: transparent;
  padding: 0;
}

.code-block {
  font-family: var(--font-mono);
  font-size: 0.875rem;
  background: var(--color-bg-elevated);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 1rem;
  overflow-x: auto;
}

.sql-display {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--color-text-muted);
  background: var(--color-bg-elevated);
  border-radius: var(--radius-sm);
  padding: 0.75rem 1rem;
}

/* --------------------------------------------------------------------------
   Tool Call Display
   -------------------------------------------------------------------------- */
.tool-call {
  background: var(--color-bg-elevated);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 1rem;
  margin: 0.5rem 0;
}

.tool-call-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.875rem;
  color: var(--color-text-muted);
  margin-bottom: 0.5rem;
}

.tool-call-header i {
  color: var(--color-accent);
}

/* --------------------------------------------------------------------------
   Breadcrumb Customization
   -------------------------------------------------------------------------- */
.breadcrumb {
  background: transparent;
  padding: 0;
  margin-bottom: 1rem;
}

.breadcrumb-item a {
  color: var(--color-text-muted);
  text-decoration: none;
  transition: color var(--transition-base);
}

.breadcrumb-item a:hover {
  color: var(--color-accent);
}

.breadcrumb-item.active {
  color: var(--color-text);
}

/* --------------------------------------------------------------------------
   Dashboard Grid
   -------------------------------------------------------------------------- */
.dashboard-grid {
  display: grid;
  gap: 1.5rem;
}

.dashboard-grid.cols-2 {
  grid-template-columns: repeat(2, 1fr);
}

.dashboard-grid.cols-3 {
  grid-template-columns: repeat(3, 1fr);
}

.dashboard-grid.cols-4 {
  grid-template-columns: repeat(4, 1fr);
}

@media (max-width: 991px) {
  .dashboard-grid.cols-3,
  .dashboard-grid.cols-4 {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 576px) {
  .dashboard-grid.cols-2,
  .dashboard-grid.cols-3,
  .dashboard-grid.cols-4 {
    grid-template-columns: 1fr;
  }
}

/* --------------------------------------------------------------------------
   Prevent Horizontal Scroll
   -------------------------------------------------------------------------- */
@media (max-width: 768px) {
  body {
    overflow-x: hidden;
  }
  
  .container {
    padding-left: 1rem;
    padding-right: 1rem;
  }
}

/* --------------------------------------------------------------------------
   Provenance Badges
   -------------------------------------------------------------------------- */
.provenance-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  font-size: 0.7rem;
  font-weight: 500;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  transition: opacity var(--transition-fast);
  line-height: 1.4;
}

.provenance-badge:hover {
  opacity: 0.8;
}

.provenance-badge--source {
  background: rgba(0, 184, 148, 0.12);
  color: #00876a;
  border: 1px solid rgba(0, 184, 148, 0.25);
}

.provenance-badge--override {
  background: rgba(111, 66, 193, 0.1);
  color: #6f42c1;
  border: 1px solid rgba(111, 66, 193, 0.25);
}

/* --------------------------------------------------------------------------
   Entity References — Inline Pills & Cards
   -------------------------------------------------------------------------- */

/* --- Design tokens per entity type --- */
.entity-pill,
.entity-card {
  --entity-hue: 210;
  --entity-color: hsl(var(--entity-hue) 55% 50%);
  cursor: pointer;
  transition:
    background var(--transition-fast),
    border-color var(--transition-fast),
    box-shadow var(--transition-fast);
}

/* Non-clickable chips (entity_id is not a valid UUID) */
.entity-pill:not([hx-get]),
.entity-card:not([hx-get]) {
  cursor: default;
}

.entity-pill:not([hx-get]):hover,
.entity-card:not([hx-get]):hover {
  background: inherit;
  border-color: inherit;
  box-shadow: none;
}

/* --- Inline pill --- */
.entity-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.25em;
  background: hsl(var(--entity-hue) 70% 96%);
  color: var(--entity-color);
  border: 1px solid hsl(var(--entity-hue) 50% 88%);
  border-radius: 100px;
  padding: 0.1em 0.6em 0.1em 0.45em;
  font-size: 0.9em;
  font-weight: 500;
  max-width: 28ch;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  vertical-align: baseline;
}

.entity-pill-icon {
  font-size: 0.85em;
  flex-shrink: 0;
  line-height: 1;
}

.entity-pill:hover {
  background: hsl(var(--entity-hue) 65% 92%);
  border-color: hsl(var(--entity-hue) 55% 78%);
  box-shadow: 0 1px 4px hsl(var(--entity-hue) 50% 50% / 0.15);
}

/* --- Entity card --- */
.entity-card {
  display: flex;
  flex-direction: column;
  gap: 0.125rem;
  background: var(--color-bg-card);
  border: 1px solid hsl(var(--entity-hue) 50% 88%);
  border-left: 3px solid var(--entity-color);
  border-radius: var(--radius-sm);
  padding: 0.625rem 0.875rem 0.625rem 0.75rem;
  margin: 0.375rem 0;
  max-width: 340px;
}

.entity-card:hover {
  background: hsl(var(--entity-hue) 70% 97%);
  border-color: hsl(var(--entity-hue) 55% 78%);
  box-shadow: 0 2px 8px hsl(var(--entity-hue) 50% 50% / 0.1);
}

.entity-card-name {
  display: flex;
  align-items: center;
  gap: 0.35em;
  font-weight: 600;
  font-size: 0.95em;
  color: var(--color-text);
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.entity-card-icon {
  font-size: 0.9em;
  flex-shrink: 0;
  line-height: 1;
}

.entity-card-summary {
  font-size: 0.8em;
  color: var(--color-text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Indent summary to align with name text when icon is present */
.entity-card-name:has(.entity-card-icon) ~ .entity-card-summary {
  padding-left: 1.1em;
}

/* Adjacent cards stack tighter */
.entity-card + .entity-card {
  margin-top: -0.25rem;
}

/* --- Responsive --- */
@media (max-width: 576px) {
  .entity-pill {
    font-size: 0.85em;
    max-width: 22ch;
  }

  .entity-card {
    max-width: 100%;
  }
}

/* --------------------------------------------------------------------------
   Entity Side Panel (Offcanvas)
   -------------------------------------------------------------------------- */
.entity-panel-offcanvas {
  --bs-offcanvas-width: 520px;
  max-width: 90vw;
  border-left: 1px solid var(--color-border);
  box-shadow: -4px 0 24px rgba(0, 0, 0, 0.08);
}

.entity-panel-offcanvas .offcanvas-header {
  border-bottom: 1px solid var(--color-border);
  padding: 1rem 1.25rem;
}

.entity-panel-offcanvas .offcanvas-title {
  font-size: 0.875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--color-text-muted);
}

.entity-panel-offcanvas .offcanvas-body {
  padding: 1.25rem;
}

.entity-panel-header {
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--color-border);
  margin-bottom: 0.75rem;
}

.entity-panel-icon {
  font-size: 1.5rem;
  line-height: 1;
}

.entity-panel-name {
  font-size: 1rem;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.entity-panel-section {
  padding: 0.75rem 0;
  border-bottom: 1px solid var(--color-border);
}

.entity-panel-section:last-child {
  border-bottom: none;
}

/* --------------------------------------------------------------------------
   Duplicate Pairs
   -------------------------------------------------------------------------- */

/* --- Pair card --- */
.dup-pair {
  background: var(--color-bg-card);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 0;
  margin-bottom: 1rem;
  transition:
    box-shadow var(--transition-slow),
    opacity 0.4s ease,
    transform 0.4s ease;
  overflow: hidden;
}

.dup-pair:hover {
  box-shadow: var(--shadow-md);
}

/* Dismiss animation */
.dup-pair.dup-dismissing {
  opacity: 0;
  transform: scale(0.96) translateY(-8px);
  pointer-events: none;
}

.dup-pair-inner {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 0;
  align-items: stretch;
  min-height: 0;
}

/* --- Entity column --- */
.dup-entity {
  padding: 1.25rem 1.5rem;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.dup-entity-name {
  font-weight: 600;
  font-size: 1rem;
  color: var(--color-text);
  text-decoration: none;
  transition: color var(--transition-fast);
  line-height: 1.3;
}

.dup-entity-name:hover {
  color: var(--color-accent);
}

.dup-entity-id {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--color-text-secondary);
  margin-top: 0.25rem;
  letter-spacing: 0.02em;
}

.dup-entity--right {
  text-align: right;
}

/* --- Center bridge column --- */
.dup-bridge {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 1.25rem 1.5rem;
  position: relative;
  min-width: 200px;
}

.dup-bridge::before,
.dup-bridge::after {
  content: '';
  position: absolute;
  top: 50%;
  width: 24px;
  height: 1px;
  background: var(--color-border);
}

.dup-bridge::before {
  left: 0;
}

.dup-bridge::after {
  right: 0;
}

/* --- Confidence ring --- */
.dup-confidence {
  position: relative;
  width: 56px;
  height: 56px;
  flex-shrink: 0;
  margin-bottom: 0.625rem;
}

.dup-confidence svg {
  width: 56px;
  height: 56px;
  transform: rotate(-90deg);
}

.dup-confidence-track {
  fill: none;
  stroke: var(--color-bg-elevated);
  stroke-width: 4;
}

.dup-confidence-fill {
  fill: none;
  stroke-width: 4;
  stroke-linecap: round;
  stroke-dasharray: 150.8;
  stroke-dashoffset: calc(150.8 * (1 - var(--conf, 0)));
  transition: stroke-dashoffset 0.8s ease;
}

.dup-confidence-fill--high {
  stroke: #e74c3c;
}

.dup-confidence-fill--medium {
  stroke: #f39c12;
}

.dup-confidence-fill--low {
  stroke: var(--color-text-secondary);
}

.dup-confidence-label {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--color-text);
}

/* --- Evidence pills --- */
.dup-evidence {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
}

.dup-evidence-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.7rem;
  font-weight: 500;
  padding: 0.15rem 0.5rem;
  border-radius: 100px;
  white-space: nowrap;
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.dup-evidence-pill--exact {
  background: rgba(0, 184, 148, 0.1);
  color: #00876a;
  border: 1px solid rgba(0, 184, 148, 0.2);
}

.dup-evidence-pill--similar {
  background: rgba(52, 152, 219, 0.1);
  color: #2471a3;
  border: 1px solid rgba(52, 152, 219, 0.2);
}

.dup-evidence-field {
  opacity: 0.7;
}

/* --- Actions footer --- */
.dup-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.5rem;
  padding: 0.75rem 1.5rem;
  border-top: 1px solid var(--color-border);
  background: var(--color-bg-elevated);
}

.dup-actions .btn {
  font-size: 0.85rem;
}

/* --- Staggered entrance animation --- */
.dup-pair {
  opacity: 0;
  animation: dupSlideIn 0.35s ease forwards;
}

@keyframes dupSlideIn {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Stagger each pair */
.dup-pair:nth-child(1) { animation-delay: 0.03s; }
.dup-pair:nth-child(2) { animation-delay: 0.06s; }
.dup-pair:nth-child(3) { animation-delay: 0.09s; }
.dup-pair:nth-child(4) { animation-delay: 0.12s; }
.dup-pair:nth-child(5) { animation-delay: 0.15s; }
.dup-pair:nth-child(6) { animation-delay: 0.18s; }
.dup-pair:nth-child(7) { animation-delay: 0.21s; }
.dup-pair:nth-child(8) { animation-delay: 0.24s; }
.dup-pair:nth-child(9) { animation-delay: 0.27s; }
.dup-pair:nth-child(10) { animation-delay: 0.30s; }

/* --- Responsive --- */
@media (max-width: 768px) {
  .dup-pair-inner {
    grid-template-columns: 1fr;
  }

  .dup-entity {
    padding: 1rem 1.25rem 0.5rem;
  }

  .dup-entity--right {
    text-align: left;
    padding-top: 0;
    padding-bottom: 1rem;
  }

  .dup-bridge {
    flex-direction: row;
    padding: 0.75rem 1.25rem;
    min-width: 0;
    gap: 0.75rem;
    border-top: 1px solid var(--color-border);
    border-bottom: 1px solid var(--color-border);
  }

  .dup-bridge::before,
  .dup-bridge::after {
    display: none;
  }

  .dup-confidence {
    margin-bottom: 0;
  }

  .dup-evidence {
    flex-direction: row;
    flex-wrap: wrap;
  }
}

/* --- Empty / all-resolved state --- */
.dup-done {
  text-align: center;
  padding: 3rem 2rem;
}

.dup-done-icon {
  width: 56px;
  height: 56px;
  background: rgba(0, 184, 148, 0.1);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 1rem;
  font-size: 1.5rem;
  color: var(--color-accent);
}

/* --------------------------------------------------------------------------
   Merge Page
   -------------------------------------------------------------------------- */
.merge-page { --merge-accent: var(--color-accent); --merge-danger: #e74c3c; }

/* Survivor cards */
.survivor-option {
  position: relative;
  border: 2px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 1.25rem;
  cursor: pointer;
  transition: border-color 0.2s, box-shadow 0.2s, background 0.2s;
  background: var(--color-bg-card);
}
.survivor-option:hover { border-color: rgba(0,0,0,0.15); }
.survivor-option.is-selected {
  border-color: var(--merge-accent);
  background: rgba(0, 184, 148, 0.04);
  box-shadow: 0 0 0 3px rgba(0, 184, 148, 0.12);
}
.survivor-option input[type="radio"] {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
  pointer-events: none;
}
.survivor-name {
  font-weight: 600;
  font-size: 1.05rem;
  color: var(--color-text);
  line-height: 1.3;
}
.survivor-meta {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.375rem;
  flex-wrap: wrap;
  align-items: center;
}
.survivor-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.2em 0.6em;
  border-radius: 100px;
  font-size: 0.75rem;
  font-weight: 500;
  background: var(--color-bg-elevated);
  color: var(--color-text-muted);
  border: 1px solid var(--color-border);
}
.survivor-label {
  display: none;
  padding: 0.2em 0.6em;
  border-radius: 100px;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  background: var(--merge-accent);
  color: #fff;
}
.survivor-option.is-selected .survivor-label { display: inline-block; }

/* Comparison table */
.merge-table { border-collapse: separate; border-spacing: 0; width: 100%; }
.merge-table th {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--color-text-muted);
  padding: 0.75rem 1rem;
  background: var(--color-bg-elevated);
  border-bottom: 2px solid var(--color-border);
  white-space: nowrap;
}
.merge-table td {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--color-border);
  vertical-align: middle;
  font-size: 0.925rem;
  color: var(--color-text);
  transition: background 0.15s;
}
.merge-table tbody tr:last-child td { border-bottom: none; }

/* Field name column */
.field-label {
  font-weight: 500;
  color: var(--color-text-muted);
  display: flex;
  align-items: center;
  gap: 0.375rem;
}

/* Diff indicator */
.diff-dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #f0ad4e;
  flex-shrink: 0;
}

/* Value cells with radio */
.value-cell {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.value-cell input[type="radio"] {
  accent-color: var(--merge-accent);
  width: 13px;
  height: 13px;
  flex-shrink: 0;
  cursor: pointer;
}
.value-cell .val-text { word-break: break-word; }

/* Same-value row styling */
tr.row-same td { color: var(--color-text-muted); }
tr.row-same td:first-child .diff-dot { display: none; }

/* Status chip in chosen column */
.chosen-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.2em 0.65em;
  border-radius: 100px;
  font-size: 0.75rem;
  font-weight: 600;
}
.chosen-chip.is-same {
  background: var(--color-bg-elevated);
  color: var(--color-text-secondary);
}
.chosen-chip.needs-pick {
  background: rgba(240, 173, 78, 0.12);
  color: #b8860b;
  border: 1px solid rgba(240, 173, 78, 0.3);
}

/* Survivor column header tag */
.th-survivor-tag {
  display: inline-block;
  padding: 0.15em 0.5em;
  border-radius: 100px;
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  background: var(--merge-accent);
  color: #fff;
  vertical-align: middle;
  margin-left: 0.375rem;
}

/* Absorbed column header tag */
.th-absorbed-tag {
  display: inline-block;
  padding: 0.15em 0.5em;
  border-radius: 100px;
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  background: rgba(0,0,0,0.06);
  color: var(--color-text-muted);
  vertical-align: middle;
  margin-left: 0.375rem;
}

/* Footer action bar */
.merge-action-bar {
  position: sticky;
  bottom: 0;
  background: rgba(255,255,255,0.92);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--color-border);
  padding: 1rem 0;
  margin: 0 -0.75rem;
  padding-left: 0.75rem;
  padding-right: 0.75rem;
  z-index: 10;
}

/* Confirmation modal */
.merge-confirm-body {
  text-align: center;
  padding: 1.5rem 1rem;
}
.merge-confirm-icon {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: rgba(231, 76, 60, 0.08);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 1rem;
}
.merge-confirm-icon i { font-size: 1.5rem; color: var(--merge-danger); }
.merge-summary-list {
  list-style: none;
  padding: 0;
  margin: 1rem 0 0;
  text-align: left;
  background: var(--color-bg-elevated);
  border-radius: var(--radius-sm);
  padding: 0.75rem 1rem;
}
.merge-summary-list li {
  padding: 0.25rem 0;
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.merge-summary-list li i { font-size: 0.8rem; }

/* --------------------------------------------------------------------------
   Entity Tags
   -------------------------------------------------------------------------- */
.entity-tag-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.2em 0.6em;
  border-radius: 100px;
  font-size: 0.85rem;
  font-weight: 500;
  background: var(--color-bg-elevated);
  color: var(--color-text);
  border: 1px solid var(--color-border);
  white-space: nowrap;
}

.entity-tag-pill .entity-tag-remove {
  display: none;
  background: none;
  border: none;
  padding: 0 0.15em;
  font-size: 1rem;
  line-height: 1;
  color: var(--color-text-muted);
  cursor: pointer;
}

.entity-tag-pill .entity-tag-remove:hover {
  color: var(--color-text);
}

.entity-tag-pill:hover .entity-tag-remove {
  display: inline;
}

.entity-tag-add {
  display: inline-flex;
  align-items: center;
  padding: 0.2em 0.6em;
  border-radius: 100px;
  font-size: 0.85rem;
  font-weight: 500;
  background: transparent;
  color: var(--color-text-muted);
  border: 1px dashed var(--color-border);
  cursor: pointer;
  transition: border-color var(--transition-fast), color var(--transition-fast);
}

.entity-tag-add:hover {
  border-color: var(--color-text-secondary);
  color: var(--color-text-secondary);
}

.entity-tag-input {
  font-size: 0.85rem;
  padding: 0.2em 0.6em;
  border: 1px solid #0d6efd;
  border-radius: 100px;
  outline: none;
  min-width: 140px;
}

.entity-tag-input:focus {
  box-shadow: 0 0 0 2px rgba(13, 110, 253, 0.25);
}

.entity-tag-dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  z-index: 100;
  min-width: 180px;
  max-height: 200px;
  overflow-y: auto;
  background: var(--color-bg-card);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-md);
  margin-top: 0.25rem;
}

.entity-tag-suggestion {
  padding: 0.4em 0.75em;
  font-size: 0.85rem;
  cursor: pointer;
  transition: background var(--transition-fast);
}

.entity-tag-suggestion:hover {
  background: var(--color-bg-elevated);
}

/* --------------------------------------------------------------------------
   Entity Notes
   -------------------------------------------------------------------------- */
.entity-note-content p {
  margin-bottom: 0.25rem;
}

.entity-note-content p:last-child {
  margin-bottom: 0;
}
.entity-note-actions {
  opacity: 0;
  transition: opacity 0.15s;
  display: flex;
  gap: 4px;
}
.entity-note:hover .entity-note-actions,
.entity-note-actions:focus-within {
  opacity: 1;
}
.entity-note-action {
  background: none;
  border: none;
  cursor: pointer;
  padding: 2px 4px;
  font-size: 0.75rem;
  color: var(--bs-secondary-color, #6c757d);
  border-radius: 4px;
  transition: color 0.15s, background 0.15s;
}
.entity-note-action:hover {
  color: var(--bs-body-color);
  background: rgba(0,0,0,0.05);
}

/* --------------------------------------------------------------------------
   Print Styles
   -------------------------------------------------------------------------- */
@media print {
  .navbar,
  .app-footer,
  .btn,
  form {
    display: none !important;
  }
  
  .card {
    break-inside: avoid;
    box-shadow: none !important;
    border: 1px solid #ddd !important;
  }
  
  body {
    font-size: 12pt;
  }
}

/* --------------------------------------------------------------------------
   Entity List — status badges (orphans, duplicates, conflicts)
   -------------------------------------------------------------------------- */
.entity-status-badge {
  display: inline-flex;
  align-items: center;
  font-size: 0.8rem;
  line-height: 1;
  padding: 0.2em 0.5em;
  border: 1px solid var(--bs-warning);
  border-radius: var(--bs-border-radius-sm);
  color: var(--bs-warning-text-emphasis);
  text-decoration: none;
  white-space: nowrap;
}

.entity-status-badge:hover {
  background-color: var(--bs-warning-bg-subtle);
  color: var(--bs-warning-text-emphasis);
}

/* --------------------------------------------------------------------------
   Entity List Filter Bar — responsive
   -------------------------------------------------------------------------- */
.entity-filter-input {
  max-width: 220px;
}

.entity-filter-select {
  max-width: 180px;
}

@media (max-width: 575.98px) {
  .entity-filter-bar {
    flex-direction: column;
    align-items: stretch !important;
  }

  .entity-filter-input,
  .entity-filter-select {
    max-width: 100%;
    width: 100%;
  }
}

/* --------------------------------------------------------------------------
   Field History Offcanvas
   -------------------------------------------------------------------------- */

/* --- Panel shell --- */
.fh-offcanvas {
  --bs-offcanvas-width: 420px;
  max-width: 90vw;
  border-left: 1px solid var(--color-border);
  box-shadow: -4px 0 24px rgba(0, 0, 0, 0.08);
}

.fh-offcanvas .offcanvas-header {
  border-bottom: 1px solid var(--color-border);
  padding: 0.875rem 1.25rem;
}

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

.fh-offcanvas .offcanvas-title i {
  font-size: 0.75rem;
  opacity: 0.7;
}

.fh-offcanvas .offcanvas-body {
  padding: 1.25rem;
  background: var(--color-bg);
}

/* --- Content sections --- */
.fh-content {
  animation: fhFadeIn 0.25s ease both;
}

@keyframes fhFadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.fh-field-label {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-text-secondary);
  margin-bottom: 0.75rem;
}

/* --- Current value card --- */
.fh-value-card {
  background: var(--color-bg-elevated);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 0.75rem 1rem;
  margin-bottom: 1rem;
}

.fh-value-label {
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-text-secondary);
  margin-bottom: 0.25rem;
}

.fh-value-display {
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--color-text);
  line-height: 1.35;
  word-break: break-word;
}

/* --- Provenance --- */
.fh-provenance {
  margin-bottom: 1.25rem;
  padding-bottom: 1.25rem;
  border-bottom: 1px solid var(--color-border);
}

.fh-prov-row {
  display: flex;
  align-items: flex-start;
  gap: 0.6rem;
}

.fh-prov-icon {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.5rem;
  height: 1.5rem;
  border-radius: 6px;
  font-size: 0.7rem;
  margin-top: 0.05rem;
  background: var(--color-bg-elevated);
  color: var(--color-text-muted);
  border: 1px solid var(--color-border);
}

.fh-prov-icon--source {
  background: rgba(0, 184, 148, 0.1);
  color: #00876a;
  border-color: rgba(0, 184, 148, 0.2);
}

.fh-prov-icon--override {
  background: rgba(111, 66, 193, 0.08);
  color: #6f42c1;
  border-color: rgba(111, 66, 193, 0.18);
}

.fh-prov-icon--custom {
  background: rgba(0, 168, 204, 0.08);
  color: #0088a8;
  border-color: rgba(0, 168, 204, 0.18);
}

.fh-prov-details {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.fh-prov-text {
  font-size: 0.82rem;
  color: var(--color-text);
  line-height: 1.5;
}

.fh-prov-text--muted {
  color: var(--color-text-muted);
}

.fh-prov-reason {
  font-size: 0.75rem;
  color: var(--color-text-muted);
  font-style: italic;
}

.fh-prov-original {
  font-size: 0.75rem;
  color: var(--color-text-secondary);
}

.fh-prov-row--source-sub {
  margin-top: 0.5rem;
  padding-top: 0.5rem;
  border-top: 1px dashed var(--color-border);
}

/* --- Timeline section --- */
.fh-section-label {
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-text-secondary);
  margin-bottom: 0.75rem;
}

/* --- Timeline --- */
.fh-timeline {
  position: relative;
  padding-left: 1.25rem;
}

/* Vertical line */
.fh-timeline::before {
  content: '';
  position: absolute;
  left: 0.375rem;
  top: 0.5rem;
  bottom: 0.5rem;
  width: 1px;
  background: var(--color-border);
}

/* --- Timeline entry --- */
.fh-tl-entry {
  position: relative;
  padding-bottom: 0.875rem;
  animation: fhEntryIn 0.3s ease both;
}

.fh-tl-entry:last-child {
  padding-bottom: 0;
}

@keyframes fhEntryIn {
  from { opacity: 0; transform: translateX(-4px); }
  to   { opacity: 1; transform: translateX(0); }
}

/* Timeline dot */
.fh-tl-dot {
  position: absolute;
  left: -1.25rem;
  top: 0.45rem;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--color-border);
  border: 2px solid var(--color-bg);
  box-shadow: 0 0 0 1px var(--color-border);
  z-index: 1;
  transform: translateX(0.375rem) translateX(-4.5px);
}

/* First entry: slightly larger dot */
.fh-tl-entry:first-child .fh-tl-dot {
  width: 11px;
  height: 11px;
  transform: translateX(0.375rem) translateX(-5.5px);
  top: 0.375rem;
}

/* Action-based dot colors */
.fh-tl-entry[data-action^="override"] .fh-tl-dot {
  background: #6f42c1;
  box-shadow: 0 0 0 1px rgba(111, 66, 193, 0.3);
}

.fh-tl-entry[data-action="custom_field_set"] .fh-tl-dot,
.fh-tl-entry[data-action="custom_field_clear"] .fh-tl-dot {
  background: #0088a8;
  box-shadow: 0 0 0 1px rgba(0, 168, 204, 0.3);
}

.fh-tl-entry[data-action="conflict_resolve"] .fh-tl-dot {
  background: var(--color-accent);
  box-shadow: 0 0 0 1px rgba(0, 184, 148, 0.3);
}

.fh-tl-entry[data-action="merge"] .fh-tl-dot,
.fh-tl-entry[data-action="link"] .fh-tl-dot {
  background: var(--color-accent);
  box-shadow: 0 0 0 1px rgba(0, 184, 148, 0.3);
}

.fh-tl-entry[data-action="delete"] .fh-tl-dot,
.fh-tl-entry[data-action="split"] .fh-tl-dot,
.fh-tl-entry[data-action="unlink"] .fh-tl-dot {
  background: #d96544;
  box-shadow: 0 0 0 1px rgba(217, 101, 68, 0.3);
}

.fh-tl-entry[data-action^="tag"] .fh-tl-dot,
.fh-tl-entry[data-action^="note"] .fh-tl-dot {
  background: #6c757d;
  box-shadow: 0 0 0 1px rgba(108, 117, 125, 0.25);
}

/* --- Entry card --- */
.fh-tl-card {
  background: var(--color-bg-elevated);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.65rem;
  transition: border-color var(--transition-fast);
}

.fh-tl-entry:first-child .fh-tl-card {
  border-color: rgba(0, 0, 0, 0.12);
}

.fh-tl-card:hover {
  border-color: rgba(0, 0, 0, 0.14);
}

.fh-tl-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.5rem;
  margin-bottom: 0.15rem;
}

.fh-tl-action {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--color-text);
  line-height: 1.3;
}

.fh-tl-time {
  font-size: 0.68rem;
  color: var(--color-text-secondary);
  white-space: nowrap;
  flex-shrink: 0;
}

/* --- Value transition --- */
.fh-tl-values {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  margin: 0.25rem 0;
  font-size: 0.78rem;
  line-height: 1.3;
  flex-wrap: wrap;
}

.fh-tl-old {
  color: var(--color-text-muted);
  text-decoration: line-through;
  text-decoration-color: rgba(0, 0, 0, 0.2);
}

.fh-tl-arrow {
  font-size: 0.6rem;
  color: var(--color-text-secondary);
  flex-shrink: 0;
}

.fh-tl-new {
  font-weight: 600;
  color: var(--color-text);
}

/* --- Meta line (user + reason) --- */
.fh-tl-meta {
  display: flex;
  align-items: baseline;
  gap: 0.4rem;
  font-size: 0.7rem;
  color: var(--color-text-secondary);
  line-height: 1.4;
}

.fh-tl-reason {
  color: var(--color-text-muted);
  font-style: italic;
}

.fh-tl-reason::before {
  content: '·';
  margin-right: 0.4rem;
  font-style: normal;
}

/* --- Empty state --- */
.fh-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  padding: 2rem 1rem;
  color: var(--color-text-secondary);
  font-size: 0.82rem;
}

.fh-empty i {
  font-size: 1.5rem;
  opacity: 0.4;
}
