/* ==========================================================================
   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
   -------------------------------------------------------------------------- */
.generated-dashboard-runtime {
  display: block;
  width: 100%;
  height: 760px;
  min-height: 480px;
  border: 0;
  background: #fff;
  overflow: hidden;
}

body.interface-shell {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
}

body.interface-shell .app-footer {
  display: none;
}

body.interface-shell > main.interface-main {
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  max-width: none;
  margin: 0 !important;
  padding: 0;
}

body.interface-shell .generated-dashboard-runtime {
  flex: 1 1 auto;
  height: 100%;
  min-height: 0;
  overflow: auto;
}

.interface-page {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
  background: var(--color-bg);
}

.interface-page__header {
  flex: 0 0 auto;
  padding-top: 1rem;
  padding-bottom: 1rem;
}

.interface-page > .generated-dashboard-runtime {
  width: 100%;
}

.card.card-widget {
  transition: transform var(--transition-slow), box-shadow 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: transform var(--transition-base), border-color var(--transition-base), box-shadow 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);
}

.entity-table-cell {
  max-width: 320px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.entity-row {
  position: relative;
}

.entity-row-checkbox-cell {
  position: relative;
  z-index: 2;
}

.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;
}

.chat-workspace {
  --artifact-pane-width: min(380px, 34vw);
  --artifact-pane-min-chat-width: 320px;
  --artifact-pane-max-width: calc(100vw - var(--artifact-pane-min-chat-width));
  display: flex;
  flex: 1 1 0;
  min-height: 0;
}

.chat-workspace.is-resizing-artifacts,
.chat-workspace.is-resizing-artifacts * {
  cursor: col-resize !important;
  user-select: none;
}

/* --- 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: 40px;
  height: 40px;
  border-radius: var(--radius-sm);
  color: var(--color-text-muted);
  text-decoration: none;
  transition: background-color var(--transition-fast), color 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;
  text-wrap: balance;
}

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

/* --- Messages area --- */
.chat-messages {
  flex: 1 1 0;
  min-width: 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);
  font-variant-numeric: tabular-nums;
}

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

.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: border-color var(--transition-fast), color var(--transition-fast), background-color 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-msg-artifact-references {
  display: grid;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

.chat-msg-artifact-references:empty {
  display: none;
}

.chat-artifact-reference {
  min-height: 40px;
  max-width: min(100%, 560px);
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  background: rgba(0, 184, 148, 0.08);
  border: 1px solid rgba(0, 184, 148, 0.22);
  border-radius: var(--radius-sm);
  padding: 0.375rem 0.5rem;
  color: var(--color-text);
  cursor: pointer;
  text-align: left;
  transition: background-color var(--transition-fast), border-color var(--transition-fast), transform var(--transition-fast);
}

.chat-artifact-reference:hover {
  background: rgba(0, 184, 148, 0.12);
  border-color: rgba(0, 184, 148, 0.38);
}

.chat-artifact-reference:active {
  transform: scale(0.96);
}

.chat-artifact-reference-icon {
  width: 28px;
  height: 28px;
  flex: 0 0 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  background: var(--color-bg);
  color: var(--color-accent);
}

.chat-artifact-reference-copy {
  min-width: 0;
  display: grid;
  gap: 0.0625rem;
}

.chat-artifact-reference-label {
  color: var(--color-text-secondary);
  font-size: 0.68rem;
  line-height: 1.1;
}

.chat-artifact-reference-title {
  overflow: hidden;
  color: var(--color-text);
  font-size: 0.8rem;
  font-weight: 600;
  line-height: 1.2;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-artifact-reference-meta {
  flex: 0 0 auto;
  color: var(--color-text-secondary);
  font-size: 0.72rem;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.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;
  min-width: 40px;
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--color-text-muted);
  font-size: 0.95rem;
  cursor: pointer;
  transition: color var(--transition-fast), transform var(--transition-fast);
  line-height: 1;
}

.chat-feedback-btn:active {
  transform: scale(0.96);
}

.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: center;
  gap: 0.5rem;
  background: var(--color-bg-card);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 0.375rem 0.375rem 0.375rem 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: 38px;
  height: 38px;
  border-radius: 50%;
  border: 1px solid transparent;
  box-sizing: border-box;
  background: var(--color-accent);
  color: var(--color-on-accent);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: background-color var(--transition-fast), transform var(--transition-fast), opacity var(--transition-fast), border-color var(--transition-fast);
  font-size: 1rem;
}

.chat-send-icon,
.chat-send-spinner {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

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

.chat-send-btn:active:not(:disabled) {
  transform: scale(0.96);
}

.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: border-color var(--transition-fast), background-color var(--transition-fast);
}

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

/* --- Artifacts side panel --- */
.chat-artifacts-panel {
  position: relative;
  display: flex;
  flex-direction: column;
  width: var(--artifact-pane-width);
  flex: 0 0 var(--artifact-pane-width);
  min-width: 300px;
  max-width: var(--artifact-pane-max-width);
  border-left: 1px solid var(--color-border);
  background: var(--color-bg);
  padding: 1rem;
  overflow: visible;
}

.chat-artifacts-panel--dashboard {
  min-width: min(640px, 58vw);
  max-width: var(--artifact-pane-max-width);
}

.chat-artifacts-resizer {
  position: absolute;
  inset: 0 auto 0 -20px;
  z-index: 2;
  width: 40px;
  min-width: 40px;
  min-height: 40px;
  border: 0;
  border-radius: 0;
  background: transparent;
  cursor: col-resize;
  touch-action: none;
}

.chat-artifacts-resizer::before {
  content: "";
  position: absolute;
  top: 1rem;
  bottom: 1rem;
  left: 19px;
  width: 2px;
  border-radius: 100px;
  background: transparent;
  transition: background-color var(--transition-fast), box-shadow var(--transition-fast);
}

.chat-artifacts-resizer:hover::before,
.chat-artifacts-resizer:focus-visible::before,
.chat-workspace.is-resizing-artifacts .chat-artifacts-resizer::before {
  background: var(--color-accent);
  box-shadow: 0 0 0 3px rgba(0, 184, 148, 0.12);
}

.chat-artifacts-resizer:focus-visible {
  outline: none;
}

.chat-artifact-focus {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  gap: 0.875rem;
  min-height: 0;
  overflow-y: auto;
}

.chat-artifacts-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
}

.chat-artifacts-kicker {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  color: var(--color-text-secondary);
  font-size: 0.7rem;
  font-weight: 600;
  line-height: 1.2;
}

.chat-artifacts-kicker i {
  color: var(--color-accent);
  font-size: 0.9rem;
}

.chat-artifacts-count {
  min-width: 1.25rem;
  height: 1.25rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 100px;
  background: var(--color-bg-elevated);
  color: var(--color-text-muted);
  font-size: 0.68rem;
  font-variant-numeric: tabular-nums;
}

.chat-artifacts-title {
  font-size: 1rem;
  font-weight: 600;
  line-height: 1.3;
  margin: 0.25rem 0 0;
  overflow-wrap: anywhere;
  text-wrap: balance;
}

.chat-artifacts-subtitle {
  font-size: 0.72rem;
  color: var(--color-text-secondary);
  margin: 0.125rem 0 0;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.3rem;
}

.chat-artifact-version-nav {
  display: inline-flex;
  align-items: center;
  gap: 0;
  padding: 1px;
  border-radius: 999px;
  background: var(--color-bg-elevated);
}

.chat-artifact-version-nav .chat-artifact-page-button {
  width: 18px;
  height: 18px;
  font-size: 0.65rem;
  color: var(--color-text-secondary);
  border-radius: 999px;
}

.chat-artifact-version-nav .chat-artifact-page-button::before {
  inset: 1px;
  border-radius: 999px;
}

.chat-artifact-version-nav .chat-artifact-page-button:hover:not(:disabled) {
  color: var(--color-text);
}

.chat-artifact-version-nav .chat-artifact-page-button:disabled {
  opacity: 0.3;
}

.chat-artifact-version-label {
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  padding: 0 0.35rem;
}

.chat-artifacts-list {
  display: grid;
  gap: 0.75rem;
}

.chat-artifact-card {
  background: var(--color-bg-card);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 0.75rem;
}

.chat-artifact-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.625rem;
}

.chat-artifact-name {
  font-size: 0.86rem;
  font-weight: 600;
  line-height: 1.35;
  margin: 0;
  overflow-wrap: anywhere;
}

.chat-artifact-meta {
  color: var(--color-text-secondary);
  font-size: 0.72rem;
  margin-top: 0.125rem;
  font-variant-numeric: tabular-nums;
}

.chat-artifact-download {
  width: 40px;
  height: 40px;
  flex: 0 0 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  color: var(--color-text-muted);
  text-decoration: none;
  transition: border-color var(--transition-fast), color var(--transition-fast), background-color var(--transition-fast), transform var(--transition-fast);
}

.chat-artifact-download:hover {
  background: var(--color-bg-elevated);
  border-color: var(--color-border-hover);
  color: var(--color-text);
}

.chat-artifact-download:active {
  transform: scale(0.96);
}

.chat-artifact-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
}

.chat-artifact-table-frame {
  display: flex;
  flex-direction: column;
  gap: 0.625rem;
  min-height: 0;
}

.chat-artifact-table {
  width: max-content;
  min-width: max(100%, 340px);
  border-collapse: collapse;
  font-size: 0.72rem;
  line-height: 1.35;
}

.chat-artifact-table th,
.chat-artifact-table td {
  padding: 0.4rem 0.5rem;
  border-bottom: 1px solid var(--color-border);
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: left;
}

.chat-artifact-table th {
  background: var(--color-bg-elevated);
  color: var(--color-text-muted);
  font-weight: 600;
}

.chat-artifact-table tr:last-child td {
  border-bottom: 0;
}

.chat-dashboard-artifact-frame-wrap {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-bg);
}

.chat-dashboard-artifact-frame {
  display: block;
  width: 100%;
  min-height: 620px;
  border: 0;
  background: var(--color-bg);
}

.chat-dashboard-artifact-state {
  min-height: 260px;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 0.75rem;
  border: 1px dashed var(--color-border);
  border-radius: var(--radius-sm);
  color: var(--color-text-secondary);
  text-align: center;
}

.chat-dashboard-artifact-state p {
  max-width: 38rem;
  margin: 0;
  padding: 0 1rem;
  overflow-wrap: anywhere;
}

.chat-dashboard-artifact-state--failed {
  color: var(--bs-danger);
  border-color: rgba(var(--bs-danger-rgb), 0.35);
  background: rgba(var(--bs-danger-rgb), 0.05);
}

.chat-artifact-empty-table,
.chat-artifacts-empty {
  border: 1px dashed var(--color-border);
  border-radius: var(--radius-sm);
  color: var(--color-text-secondary);
  font-size: 0.8rem;
  padding: 1rem;
  text-align: center;
}

.chat-artifacts-empty i {
  display: block;
  font-size: 1.4rem;
  margin-bottom: 0.4rem;
}

.chat-artifacts-empty p {
  margin: 0;
}

.chat-artifact-pagination {
  position: sticky;
  bottom: 0;
  z-index: 1;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.4rem 0.75rem;
  padding-top: 0.25rem;
  background: var(--color-bg);
}

.chat-artifact-page-meta,
.chat-artifact-page-current {
  color: var(--color-text-secondary);
  font-size: 0.72rem;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.chat-artifact-page-controls {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
}

.chat-artifact-page-button {
  width: 24px;
  height: 24px;
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--color-text-muted);
  font-size: 0.78rem;
  line-height: 1;
  transition: color var(--transition-fast), transform var(--transition-fast);
}

.chat-artifact-page-button::before {
  content: "";
  position: absolute;
  inset: 2px;
  border-radius: var(--radius-sm);
  background: transparent;
  transition: background-color var(--transition-fast);
}

.chat-artifact-page-button i {
  position: relative;
  z-index: 1;
}

.chat-artifact-page-button:hover:not(:disabled)::before {
  background: var(--color-bg-elevated);
}

.chat-artifact-page-button:hover:not(:disabled) {
  color: var(--color-text);
}

.chat-artifact-page-button:active:not(:disabled) {
  transform: scale(0.96);
}

.chat-artifact-page-button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

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

  .chat-workspace {
    flex-direction: column;
  }

  .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;
  }

  .chat-artifacts-panel {
    position: fixed;
    inset: 0;
    width: 100%;
    min-width: 0;
    max-width: none;
    max-height: none;
    height: 100dvh;
    z-index: 1050;
    border: 0;
    background: var(--color-bg);
    transform: translateY(100%);
    transition: transform 0.25s ease;
    overflow-y: auto;
  }

  .chat-artifacts-panel--dashboard {
    min-width: 0;
    max-width: none;
  }

  .chat-dashboard-artifact-frame {
    min-height: 100dvh;
  }

  .chat-page[data-artifact-drawer="open"] .chat-artifacts-panel {
    transform: translateY(0);
  }

  .chat-artifacts-resizer {
    display: none;
  }

  .chat-page:has(.chat-artifacts-panel) .chat-artifacts-launcher {
    display: inline-flex;
  }

  .chat-page[data-artifact-drawer="open"] .chat-artifacts-launcher {
    display: none;
  }

  .chat-artifacts-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 1045;
    background: rgba(0, 0, 0, 0.4);
  }

  .chat-page[data-artifact-drawer="open"] .chat-artifacts-backdrop {
    display: block;
  }

  .chat-artifacts-close {
    display: inline-flex;
  }

}

.chat-artifacts-launcher {
  display: none;
  align-items: center;
  gap: 0.35rem;
  margin-left: auto;
  padding: 0.35rem 0.7rem;
  border: 1px solid var(--color-border);
  border-radius: 999px;
  background: var(--color-bg-card);
  color: var(--color-text);
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  transition: color var(--transition-fast), border-color var(--transition-fast), background-color var(--transition-fast);
}

.chat-artifacts-launcher:hover {
  border-color: var(--color-border-hover);
  background: var(--color-bg-elevated);
}

.chat-artifacts-launcher i {
  color: var(--color-accent);
  font-size: 0.95rem;
}

.chat-artifacts-actions {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}

.chat-artifacts-close {
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: 1px solid var(--color-border);
  border-radius: 999px;
  background: var(--color-bg-card);
  color: var(--color-text-muted);
  cursor: pointer;
  transition: color var(--transition-fast), border-color var(--transition-fast);
}

.chat-artifacts-close:hover {
  color: var(--color-text);
  border-color: var(--color-border-hover);
}

@media (min-width: 769px) {
  .chat-artifacts-launcher,
  .chat-artifacts-backdrop,
  .chat-artifacts-close {
    display: none !important;
  }
}

@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: border-color var(--transition-slow), box-shadow 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 Rendering — Generative Layouts
   -------------------------------------------------------------------------- */

.dashboard-chart-wrap {
  position: relative;
  height: 300px;
}

@media (max-width: 768px) {
  .dashboard-chart-wrap { height: 250px; }
}

@media (max-width: 576px) {
  .dashboard-chart-wrap { height: 200px; }
}

.dashboard-text {
  text-wrap: pretty;
}

/* Tabular numbers prevent layout shift on data values */
.dashboard-content .card-body {
  font-variant-numeric: tabular-nums;
}

/* Staggered entrance animation for top-level dashboard items */
.dashboard-content > .row > .col,
.dashboard-content > .d-flex.flex-column > * {
  opacity: 0;
  animation: dashCardIn 0.38s ease forwards;
}

.dashboard-content > .row > .col:nth-child(1),
.dashboard-content > .d-flex.flex-column > :nth-child(1) { animation-delay: 0.06s; }
.dashboard-content > .row > .col:nth-child(2),
.dashboard-content > .d-flex.flex-column > :nth-child(2) { animation-delay: 0.12s; }
.dashboard-content > .row > .col:nth-child(3),
.dashboard-content > .d-flex.flex-column > :nth-child(3) { animation-delay: 0.18s; }
.dashboard-content > .row > .col:nth-child(4),
.dashboard-content > .d-flex.flex-column > :nth-child(4) { animation-delay: 0.24s; }
.dashboard-content > .row > .col:nth-child(5),
.dashboard-content > .d-flex.flex-column > :nth-child(5) { animation-delay: 0.30s; }
.dashboard-content > .row > .col:nth-child(6),
.dashboard-content > .d-flex.flex-column > :nth-child(6) { animation-delay: 0.36s; }

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

@media (prefers-reduced-motion: reduce) {
  .dashboard-content > .row > .col,
  .dashboard-content > .d-flex.flex-column > * {
    animation: none;
    opacity: 1;
  }
}

/* --------------------------------------------------------------------------
   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);
}

.provenance-badge--dastool {
  background: rgba(13, 110, 253, 0.08);
  color: #0b5ed7;
  border: 1px solid rgba(13, 110, 253, 0.2);
}

/* --------------------------------------------------------------------------
   Entity Detail Edit Card
   -------------------------------------------------------------------------- */
.entity-edit-card {
  overflow: visible;
}

.entity-edit-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.entity-edit-summary {
  margin-top: 0.15rem;
  color: var(--color-text-muted);
  font-size: 0.78rem;
}

.entity-dominant-source {
  cursor: default;
}

.entity-card-edit-button,
.entity-icon-button {
  min-width: 40px;
  transition-property: transform, background-color, border-color, color;
  transition-duration: var(--transition-fast);
}

.entity-card-edit-button:active,
.entity-icon-button:active,
.entity-edit-actions .btn:active {
  transform: scale(0.96);
}

.entity-fields-table td {
  padding: 0.8rem 1rem;
  vertical-align: top;
}

.entity-field-display-row + .entity-field-display-row td {
  border-top: 1px solid rgba(15, 23, 42, 0.06);
}

.entity-field-label {
  width: 32%;
  color: var(--color-text-muted);
  font-weight: 600;
}

.entity-field-value-line {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.45rem;
  min-width: 0;
}

.entity-field-value {
  min-width: 0;
  overflow-wrap: anywhere;
}

.entity-original-value {
  color: var(--color-text-muted);
  font-size: 0.78rem;
}

.entity-edit-form {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.entity-edit-section {
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
}

.entity-edit-section-title {
  color: var(--color-text-muted);
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

.entity-edit-field {
  display: grid;
  grid-template-columns: minmax(10rem, 32%) minmax(0, 1fr);
  gap: 1rem;
  padding-bottom: 0.9rem;
  border-bottom: 1px solid rgba(15, 23, 42, 0.06);
}

.entity-edit-field:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

.entity-edit-field-label label {
  display: block;
  margin-bottom: 0.35rem;
  font-weight: 600;
}

.entity-edit-field-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.entity-edit-field-control .form-control,
.entity-edit-field-control .form-select {
  min-height: 40px;
}

.entity-edit-field-help {
  margin-top: 0.35rem;
  color: var(--color-text-muted);
  font-size: 0.76rem;
  text-wrap: pretty;
}

.entity-edit-fk {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.entity-edit-fk-current {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  min-height: 40px;
  padding: 0.35rem 0.45rem 0.35rem 0.75rem;
  background: rgba(15, 23, 42, 0.035);
  border-radius: calc(var(--bs-border-radius) + 2px);
  box-shadow: inset 0 0 0 1px rgba(15, 23, 42, 0.08);
}

.entity-edit-fk-results {
  position: absolute;
  top: calc(100% + 0.25rem);
  left: 0;
  right: 0;
  z-index: 1050;
  max-height: 14rem;
  overflow-y: auto;
  background: #fff;
  border-radius: var(--bs-border-radius);
  box-shadow:
    0 12px 28px rgba(15, 23, 42, 0.14),
    0 0 0 1px rgba(15, 23, 42, 0.08);
}

.entity-edit-fk-result {
  display: block;
  width: 100%;
  min-height: 40px;
  padding: 0.55rem 0.75rem;
  color: var(--color-text);
  text-align: left;
  background: transparent;
  border: 0;
  transition-property: background-color;
  transition-duration: var(--transition-fast);
}

.entity-edit-fk-result:hover,
.entity-edit-fk-result:focus {
  background: rgba(13, 110, 253, 0.08);
}

.entity-edit-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.6rem;
}

@media (max-width: 768px) {
  .entity-edit-card-header,
  .entity-edit-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .entity-edit-field {
    grid-template-columns: 1fr;
  }

  .entity-field-label {
    width: 40%;
  }
}

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

.entity-pill {
  --entity-hue: 210;
  --entity-color: hsl(var(--entity-hue) 55% 50%);
  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;
  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]) {
  cursor: default;
}

.entity-pill:not([hx-get]):hover {
  background: hsl(var(--entity-hue) 70% 96%);
  border-color: hsl(var(--entity-hue) 50% 88%);
  box-shadow: none;
}

.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);
}

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

/* --------------------------------------------------------------------------
   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;
}

/* --------------------------------------------------------------------------
   Sync Progress Panel (Data Sources)
   -------------------------------------------------------------------------- */
.sync-progress-panel {
  display: flex;
  align-items: flex-start;
  gap: 1.5rem;
  padding: 0.75rem 0.5rem;
}

.sync-progress-visual {
  flex-shrink: 0;
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Orbital animation — ring + dot */
.sync-orbit {
  position: relative;
  width: 48px;
  height: 48px;
}

.sync-orbit-ring {
  position: absolute;
  inset: 0;
  border: 2.5px solid rgba(0, 184, 148, 0.15);
  border-top-color: var(--color-accent);
  border-radius: 50%;
  animation: syncOrbitSpin 1.8s cubic-bezier(0.4, 0, 0.2, 1) infinite;
}

.sync-orbit-dot {
  position: absolute;
  width: 8px;
  height: 8px;
  background: var(--color-accent);
  border-radius: 50%;
  top: -4px;
  left: 50%;
  margin-left: -4px;
  box-shadow: 0 0 8px rgba(0, 184, 148, 0.5);
  animation: syncOrbitSpin 1.8s cubic-bezier(0.4, 0, 0.2, 1) infinite;
  transform-origin: 4px 28px; /* center of the 48px container */
}

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

.sync-progress-content {
  flex: 1;
  min-width: 0;
}

.sync-progress-title {
  font-weight: 600;
  font-size: 1rem;
  color: var(--color-text);
  margin-bottom: 0.25rem;
}

.sync-progress-desc {
  color: var(--color-text-muted);
  font-size: 0.9rem;
  line-height: 1.5;
  margin-bottom: 0.75rem;
}

.sync-progress-reassurance {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  background: rgba(0, 184, 148, 0.06);
  border: 1px solid rgba(0, 184, 148, 0.15);
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.75rem;
  font-size: 0.82rem;
  color: var(--color-text-muted);
  line-height: 1.4;
}

.sync-progress-reassurance svg {
  flex-shrink: 0;
  color: var(--color-accent);
}

@media (max-width: 576px) {
  .sync-progress-panel {
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 1rem;
  }

  .sync-progress-reassurance {
    justify-content: center;
  }
}

/* --------------------------------------------------------------------------
   Stale / Deleted Entity Indicators
   -------------------------------------------------------------------------- */

/* Banner shown at top of entity detail page when entity is stale or deleted */
.entity-stale-banner {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  margin-bottom: 1rem;
  border-radius: var(--bs-border-radius);
  font-size: 0.875rem;
  line-height: 1.4;
}

.entity-stale-banner--stale {
  background: repeating-linear-gradient(
    -45deg,
    hsl(45 90% 96%),
    hsl(45 90% 96%) 8px,
    hsl(45 80% 92%) 8px,
    hsl(45 80% 92%) 16px
  );
  border: 1px solid hsl(45 70% 75%);
  color: hsl(35 80% 28%);
}

.entity-stale-banner--deleted {
  background: repeating-linear-gradient(
    -45deg,
    hsl(0 60% 97%),
    hsl(0 60% 97%) 8px,
    hsl(0 50% 93%) 8px,
    hsl(0 50% 93%) 16px
  );
  border: 1px solid hsl(0 50% 78%);
  color: hsl(0 60% 32%);
}

.entity-stale-banner i {
  font-size: 1.1em;
  flex-shrink: 0;
}

/* Dim the main content area when entity is stale/deleted */
.entity-stale-content {
  opacity: 0.55;
  pointer-events: auto;
}

.entity-stale-content .card {
  border-style: dashed;
}

/* FK link pointing to a stale/deleted entity */
.entity-fk-stale {
  text-decoration: line-through;
  opacity: 0.6;
}

.entity-fk-stale-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.2em;
  font-size: 0.7rem;
  padding: 0.1em 0.4em;
  border-radius: 100px;
  background: hsl(45 80% 92%);
  color: hsl(35 70% 35%);
  border: 1px solid hsl(45 60% 80%);
  vertical-align: middle;
  font-weight: 500;
}

.entity-fk-deleted-badge {
  background: hsl(0 50% 94%);
  color: hsl(0 55% 38%);
  border-color: hsl(0 40% 82%);
}

/* Panel stale banner — more compact for side panel */
.entity-panel-stale-banner {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.625rem;
  margin-bottom: 0.5rem;
  border-radius: var(--bs-border-radius-sm);
  font-size: 0.78rem;
  line-height: 1.3;
}

.entity-panel-stale-banner--stale {
  background: hsl(45 80% 93%);
  border: 1px solid hsl(45 60% 80%);
  color: hsl(35 70% 32%);
}

.entity-panel-stale-banner--deleted {
  background: hsl(0 50% 95%);
  border: 1px solid hsl(0 40% 82%);
  color: hsl(0 55% 35%);
}

/* Entity list stale count badge */
.entity-status-badge--stale {
  border-color: var(--bs-secondary-border-subtle);
  color: var(--bs-secondary-text-emphasis);
}

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