/* ================================================================
   CARD FEED & BASE CARD STYLES
   ================================================================ */
.feed {
  max-width: 960px;
  margin: 0 auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  flex: 1;
  width: 100%;
}

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  color: var(--text-muted);
  gap: 8px;
  padding: 80px 0;
}

.empty-state code {
  font-family: var(--mono);
  background: var(--bg-card);
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 13px;
}

/* Cards */
.card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  box-shadow: var(--shadow);
  overflow: hidden;
  animation: fadeIn 0.2s ease;
  transition: border-color 0.15s, box-shadow 0.15s, background 0.2s;
  scroll-margin-top: 60px;
}

.card.hidden-by-filter { display: none; }
.card.hidden-by-dismiss { display: none; }
.card.hidden-by-delete { display: none; }
.card.dismissed { opacity: 0.5; }
.card.dismissed .card-header { background: var(--bg-card); }

/* Card delete animation — slide right + fade */
@keyframes cardSlideOut {
  from { opacity: 1; transform: translateX(0); }
  to { opacity: 0; transform: translateX(30px); }
}

.card.card-deleting {
  animation: cardSlideOut 0.3s ease forwards;
  pointer-events: none;
}

/* Card restore animation — slide in from right */
@keyframes cardSlideIn {
  from { opacity: 0; transform: translateX(30px); }
  to { opacity: 1; transform: translateX(0); }
}

.card.card-restoring {
  animation: cardSlideIn 0.3s ease;
}

/* Card dismiss animation — fade out */
@keyframes cardDismissOut {
  from { opacity: 1; transform: scale(1); }
  to { opacity: 0; transform: scale(0.97); }
}

.card.card-dismissing {
  animation: cardDismissOut 0.25s ease forwards;
  pointer-events: none;
}

/* Card undismiss animation — fade in */
@keyframes cardDismissIn {
  from { opacity: 0; transform: scale(0.97); }
  to { opacity: 1; transform: scale(1); }
}

.card.card-undismissing {
  animation: cardDismissIn 0.25s ease;
}
#dismiss-toggle.active { color: var(--accent); }

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

.card-header {
  display: flex;
  align-items: center;
  padding: 8px 12px;
  background: var(--bg-header);
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  gap: 8px;
  user-select: none;
  transition: background 0.2s, border-color 0.2s;
}

.card-collapse-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 10px;
  padding: 2px;
  line-height: 1;
  transition: transform 0.15s, color 0.15s;
  flex-shrink: 0;
}

.card-collapse-btn:hover { color: var(--text); }
.card-collapse-btn.collapsed { transform: rotate(-90deg); }

.card-title {
  font-weight: 600;
  font-size: 13px;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.card-actions {
  display: flex;
  gap: 2px;
  align-items: center;
  flex-shrink: 0;
}

.card-action-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 13px;
  padding: 3px 5px;
  border-radius: 3px;
  line-height: 1;
  transition: color 0.15s, background 0.15s;
}

.card-action-btn:hover {
  color: var(--text);
  background: var(--bg-card);
}

.copy-prompt-btn svg {
  display: block;
}

.card-meta {
  color: var(--text-muted);
  font-size: 11px;
  white-space: nowrap;
  flex-shrink: 0;
}

.card-description {
  font-size: 12px;
  color: var(--text-muted);
  padding: 6px 14px 0;
}

.card-body {
  padding: 16px;
  transition: background 0.2s;
}

.card-collapsed > :not(.card-header) {
  display: none !important;
}

.card-provenance {
  padding: 6px 12px;
  border-top: 1px solid var(--border);
  font-size: 11px;
  color: var(--text-muted);
  font-family: var(--mono);
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  transition: border-color 0.2s;
}

/* ================================================================
   CARD TYPE STYLES — table, markdown, key-value, plotly, image
   ================================================================ */

/* Table cards */
.table-wrapper {
  overflow-x: auto;
  overflow-y: auto;
  max-height: 360px;
  font-size: 13px;
}

.table-wrapper table {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--mono);
  font-size: 12px;
}

.table-wrapper th {
  text-align: left;
  padding: 7px 12px;
  border-bottom: 2px solid var(--border);
  font-weight: 600;
  white-space: nowrap;
  background: var(--bg-card);
  position: sticky;
  top: 0;
  z-index: 1;
  cursor: pointer;
  user-select: none;
  transition: background 0.15s;
}

.table-wrapper th:hover {
  background: var(--bg-header);
}

.table-wrapper th .sort-indicator {
  display: inline-block;
  margin-left: 4px;
  font-size: 10px;
  color: var(--text-muted);
  opacity: 0;
  transition: opacity 0.15s;
}

.table-wrapper th:hover .sort-indicator { opacity: 0.5; }
.table-wrapper th .sort-indicator.active { opacity: 1; color: var(--accent); }

.table-wrapper td {
  padding: 5px 12px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  max-width: 300px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.table-wrapper tr:hover td {
  background: var(--bg-card);
}

.table-info {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  font-size: 12px;
  color: var(--text-muted);
}

.table-pager {
  display: flex;
  gap: 4px;
  align-items: center;
}

.table-pager button {
  padding: 3px 10px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg);
  color: var(--text);
  cursor: pointer;
  font-size: 12px;
  font-family: var(--font);
  transition: background 0.15s;
}

.table-pager button:hover { background: var(--bg-header); }
.table-pager button:disabled { opacity: 0.4; cursor: default; }

/* Markdown cards */
.markdown-body {
  font-size: 14px;
  line-height: 1.7;
}

.markdown-body h1, .markdown-body h2, .markdown-body h3 {
  margin: 16px 0 8px;
  font-weight: 600;
}

.markdown-body h1 { font-size: 20px; }
.markdown-body h2 { font-size: 17px; }
.markdown-body h3 { font-size: 15px; }
.markdown-body p { margin: 8px 0; }
.markdown-body strong { font-weight: 600; }

.markdown-body code {
  font-family: var(--mono);
  background: var(--bg-card);
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 13px;
}

.markdown-body pre {
  background: var(--bg-card);
  padding: 12px 16px;
  border-radius: 6px;
  overflow-x: auto;
  margin: 8px 0;
}

.markdown-body pre code {
  background: none;
  padding: 0;
}

.markdown-body ul, .markdown-body ol {
  padding-left: 24px;
  margin: 8px 0;
}

.markdown-body table {
  width: 100%;
  border-collapse: collapse;
  margin: 12px 0;
  font-size: 13px;
}

.markdown-body th,
.markdown-body td {
  padding: 6px 12px;
  border: 1px solid var(--border);
  text-align: left;
}

.markdown-body th {
  font-weight: 600;
  background: var(--bg-card);
}

.markdown-body tr:hover td {
  background: var(--bg-card);
}

/* Key-value cards */
.kv-list {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px 16px;
  font-size: 13px;
}

.kv-key {
  font-weight: 600;
  color: var(--text-muted);
  text-align: right;
  font-family: var(--mono);
}

.kv-value {
  font-family: var(--mono);
}

/* Section dividers */
.section-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 0;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  cursor: pointer;
  scroll-margin-top: 60px;
  user-select: none;
}

.section-divider:hover { color: var(--text); }

.section-chevron {
  font-size: 9px;
  transition: transform 0.15s;
  flex-shrink: 0;
  line-height: 1;
}

.section-collapsed .section-chevron {
  transform: rotate(-90deg);
}

.section-divider.hidden-by-filter { display: none; }
.hidden-by-section { display: none; }

.section-divider::before,
.section-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

/* Footer */
.footer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 100;
  background: var(--bg);
  border-top: 1px solid var(--border);
  padding: 6px 0;
  font-size: 11px;
  color: var(--text-muted);
  transition: background 0.2s, border-color 0.2s;
}

.footer-inner {
  max-width: 960px;
  margin: 0 auto;
  padding: 0 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.status-dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  margin-right: 5px;
}

.status-connected { background: var(--success); }
.status-disconnected { background: var(--error); }
.status-connecting { background: var(--warning); }

/* Plotly chart cards */
.card-body:has(.plotly-container) {
  min-width: 0;
  overflow: hidden;
}

.plotly-container {
  width: 100%;
  min-width: 0;
  min-height: 300px;
  position: relative;
  overflow: hidden;
}

.plotly-container .js-plotly-plot,
.plotly-container .js-plotly-plot .plotly,
.plotly-container .svg-container {
  width: 100% !important;
  max-width: 100% !important;
}

.chart-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 200px;
  color: var(--text-muted);
  font-size: 13px;
  gap: 8px;
}

.chart-loading::before {
  content: '';
  width: 16px;
  height: 16px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* Image cards (matplotlib SVG) */
.image-container {
  text-align: center;
}

.image-container img {
  max-width: 100%;
  height: auto;
  border-radius: 4px;
}

/* Copy toast */
.copy-toast {
  position: fixed;
  bottom: 48px;
  left: 50%;
  transform: translateX(-50%) translateY(8px);
  background: var(--text);
  color: var(--bg);
  padding: 6px 16px;
  border-radius: 6px;
  font-size: 12px;
  opacity: 0;
  transition: opacity 0.2s, transform 0.2s;
  pointer-events: none;
  z-index: 200;
}

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

.copy-toast.toast-error {
  background: var(--error);
  color: #fff;
}
/* Select-all banner */
.select-all-banner {
  padding: 6px 14px;
  font-size: 12px;
  background: color-mix(in srgb, var(--accent) 10%, var(--card-bg));
  border-bottom: 1px solid var(--border);
  text-align: center;
}

.select-all-banner a {
  color: var(--accent);
  font-weight: 600;
  text-decoration: underline;
  cursor: pointer;
}

/* Card flash animation on update */
@keyframes flashHighlight {
  0% { background: color-mix(in srgb, var(--accent) 15%, var(--bg)); }
  100% { background: var(--bg); }
}

.card.flash { animation: flashHighlight 0.6s ease; }

/* Deep-link highlight animation */
@keyframes cardHighlight {
  0% { box-shadow: 0 0 0 3px var(--accent); }
  100% { box-shadow: none; }
}

.card.card-highlight { animation: cardHighlight 2s ease-out; }


/* Card updating overlay */
.card-updating-overlay {
  position: absolute;
  inset: 0;
  background: color-mix(in srgb, var(--bg) 60%, transparent);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2;
  border-radius: var(--radius);
}

.card-updating-overlay::before {
  content: '';
  width: 20px;
  height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.card { position: relative; }

/* Action badge (Confirmed/Skipped) */
.sent-badge {
  display: inline-block;
  font-size: 11px;
  color: var(--success);
  font-weight: 500;
  padding: 2px 6px;
}

/* Selection badge */
.selection-badge {
  display: inline-block;
  font-size: 10px;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: 9px;
  background: var(--accent);
  color: white;
  margin-left: 4px;
}

/* Quick action buttons (secondary) */
.response-btn-action {
  background: var(--bg-header);
  color: var(--text);
  border-color: var(--border);
}

.response-btn-action:hover {
  background: var(--bg-card);
  border-color: var(--accent);
  color: var(--accent);
}

/* ================================================================
   TABLE OF CONTENTS OVERLAY
   ================================================================ */
.toc-dropdown {
  position: relative;
}

.toc-panel {
  position: absolute;
  right: 0;
  top: calc(100% + 4px);
  z-index: 110;
  max-height: 60vh;
  overflow-y: auto;
  min-width: 280px;
  max-width: min(380px, calc(100vw - 24px));
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  padding: 4px 0;
}

.toc-section-header {
  padding: 8px 12px 4px;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  cursor: pointer;
}

.toc-section-header:hover {
  color: var(--text);
}

.toc-entry {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 12px;
  font-size: 12px;
  color: var(--text);
  text-decoration: none;
  cursor: pointer;
  transition: background 0.1s;
}

.toc-entry:hover {
  background: var(--bg-card);
}

.toc-entry.toc-active {
  background: color-mix(in srgb, var(--accent) 10%, var(--bg));
  border-left: 3px solid var(--accent);
  padding-left: 9px;
}

.toc-type-badge {
  width: 20px;
  height: 20px;
  border-radius: 3px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
  line-height: 1;
}

.toc-entry-title {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.toc-entry-status {
  font-size: 10px;
  font-weight: 600;
  flex-shrink: 0;
}

.toc-status-waiting {
  color: var(--warning);
}

.toc-status-done {
  color: var(--success);
}

.toc-jump-latest {
  display: block;
  padding: 8px 12px;
  font-size: 11px;
  color: var(--accent);
  text-decoration: none;
  text-align: center;
  border-top: 1px solid var(--border);
  margin-top: 4px;
  cursor: pointer;
}

.toc-jump-latest:hover {
  background: var(--bg-card);
}

.toc-empty {
  padding: 16px;
  text-align: center;
  font-size: 12px;
  color: var(--text-muted);
}

.toc-trash-header {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  font-size: 11px;
  color: var(--text-muted);
  cursor: pointer;
  border-top: 1px solid color-mix(in srgb, var(--border) 30%, transparent);
  user-select: none;
}

.toc-trash-header:hover {
  color: var(--text);
}

.toc-trash-header.toc-trash-open {
  color: var(--text);
}

.toc-trash-entry {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px 4px 20px;
  font-size: 11px;
  color: var(--text-muted);
}

.toc-trash-title {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.toc-trash-restore {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 2px;
  opacity: 0;
  transition: opacity 0.1s;
}

.toc-trash-entry:hover .toc-trash-restore {
  opacity: 1;
}

.toc-trash-restore:hover {
  color: var(--text);
}

.delete-btn:hover {
  color: var(--decision-color, #ef4444);
}

@media (max-width: 600px) {
  .toc-panel {
    position: fixed;
    right: 12px;
    top: 48px;
    min-width: 0;
    width: calc(100vw - 24px);
    max-width: 380px;
  }
}

/* ================================================================
   ANNOTATIONS
   ================================================================ */
.card-annotations {
  border-top: 1px solid var(--border);
}

.card-annotation {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
}

.card-annotation:last-child {
  border-bottom: none;
}

.annotation-text {
  font-size: 13px;
  color: var(--text);
  line-height: 1.5;
  white-space: pre-wrap;
}

.annotation-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 4px;
  font-size: 11px;
  color: var(--text-muted);
  font-family: var(--mono);
}

.annotation-action-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 11px;
  padding: 0 2px;
  text-decoration: underline;
  font-family: var(--font);
  transition: color 0.15s;
}

.annotation-action-btn:hover {
  color: var(--text);
}

.annotation-form {
  padding: 8px 12px;
  border-top: 1px solid var(--border);
}

.annotation-textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  font-size: 12px;
  font-family: var(--font);
  resize: vertical;
  min-height: 36px;
  max-height: 120px;
  line-height: 1.5;
  outline: none;
  transition: border-color 0.15s;
}

.annotation-textarea:focus {
  outline: none;
  border-color: var(--accent);
}

.annotation-form-buttons {
  display: flex;
  gap: 8px;
  margin-top: 8px;
  justify-content: flex-end;
}

/* ================================================================
   UNDO SNACKBAR
   ================================================================ */
.undo-snackbar {
  position: fixed;
  bottom: 52px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  padding: 10px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 13px;
  z-index: 300;
  opacity: 0;
  transition: opacity 0.25s ease, transform 0.25s ease;
  pointer-events: none;
  white-space: nowrap;
  background: var(--text);
  color: var(--bg);
}

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

.undo-snackbar-text {
  font-weight: 500;
}

.undo-snackbar-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 13px;
  font-weight: 700;
  color: inherit;
  padding: 0;
}
