/* ═══════════════════════════════════════════════════════════════════
   Tailwind Fallback Styles — for JS-dynamic elements
   These cover classes created at runtime by sse-client.js, toc.js, etc.
   ═══════════════════════════════════════════════════════════════════ */

/* ── Shared utilities (JS toggles these) ── */
.hidden { display: none; }
.visible { opacity: 1; }

/* ── HTMX indicator (skeleton loading state) ── */
/* !important needed because HTMX 2.x injects `visibility: hidden` via JS-
   injected <style>, which keeps the element in layout flow and causes
   large blank areas. `display: none` removes the element from layout. */
.htmx-indicator { display: none !important; }
.htmx-request .htmx-indicator { display: block !important; }
.htmx-request.htmx-indicator { display: block !important; }

/* ── Step Stepper (app.html progress) ── */
.step-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.step-item .step-dot {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.75rem;
  height: 1.75rem;
  border-radius: 0.5rem;
  background: #e2e8f0;
  color: #64748b;
  font-size: 0.75rem;
  font-weight: 600;
  flex-shrink: 0;
  transition: background-color 0.2s, color 0.2s;
}
.step-item.done .step-dot {
  background: #4f46e5;
  color: #fff;
}
.step-item.running .step-dot {
  background: #eef2ff;
  color: #4f46e5;
  animation: step-pulse 1.5s ease-in-out infinite;
}
.step-connector {
  width: 1.5rem;
  height: 2px;
  background: #e2e8f0;
  flex-shrink: 0;
}
.step-connector.done {
  background: #4f46e5;
}
@keyframes step-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(99, 102, 241, 0.3); }
  50% { box-shadow: 0 0 0 4px rgba(99, 102, 241, 0); }
}
.progress-meta {
  font-size: 0.75rem;
  color: #94a3b8;
  margin-left: auto;
}

/* ── Toast (sse-client.js showToast) ── */
.toast {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 100;
  padding: 0.75rem 1.25rem;
  border-radius: 0.5rem;
  font-size: 0.875rem;
  font-weight: 500;
  opacity: 0;
  transform: translateY(-0.5rem);
  transition: opacity 0.2s, transform 0.2s;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast-success { background: #f0fdf4; color: #15803d; }
.toast-error { background: #fef2f2; color: #b91c1c; }
.toast-info { background: #eef2ff; color: #4338ca; }

/* ── Compact Input (sse-client.js compactInput) ── */
.compact-input-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
}
.compact-input-text {
  font-size: 0.875rem;
  color: #475569;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.compact-input-reload {
  flex-shrink: 0;
}

/* ── Bottom Sheet (detail.html mobile TOC) ── */
.bottom-sheet-toggle { display: none; }
.bottom-sheet-mask {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(15, 23, 42, 0.3);
  backdrop-filter: blur(4px);
}
.bottom-sheet-toggle:checked ~ .bottom-sheet-mask { display: block; }
.bottom-sheet-toggle:checked ~ .bottom-sheet {
  transform: translateY(0);
}
.bottom-sheet {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 50;
  max-height: 70vh;
  overflow-y: auto;
  background: #fff;
  border-radius: 0.75rem 0.75rem 0 0;
  transform: translateY(100%);
  transition: transform 0.3s ease;
}
.bottom-sheet-handle {
  width: 2rem;
  height: 4px;
  background: #cbd5e1;
  border-radius: 2px;
  margin: 0.5rem auto 0;
}
.bottom-sheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid #e2e8f0;
}
.bottom-sheet-close {
  cursor: pointer;
  padding: 0.25rem 0.5rem;
  border-radius: 0.375rem;
  font-size: 0.875rem;
  color: #64748b;
}

/* ── TOC Drawer (desktop right-side panel) ── */
.toc-drawer-toggle { display: none; }

.toc-drawer-fab {
  position: fixed;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  z-index: 45;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
  border-radius: 0.375rem 0 0 0.375rem;
  background: #fff;
  border: 1px solid #e2e8f0;
  border-right: 0;
  padding: 0.75rem 0.375rem;
  font-size: 0.75rem;
  color: #64748b;
  box-shadow: -2px 0 12px rgba(15, 23, 42, 0.06);
  cursor: pointer;
  transition: color 0.15s, background-color 0.15s, opacity 0.2s;
}
.toc-drawer-fab:hover {
  color: #374151;
  background: #f9fafb;
}

.toc-drawer-mask {
  position: fixed;
  inset: 0;
  z-index: 45;
  background: rgba(15, 23, 42, 0.3);
  backdrop-filter: blur(2px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}
.toc-drawer-toggle:checked ~ .toc-drawer-mask {
  opacity: 1;
  pointer-events: auto;
}
.toc-drawer-toggle:checked ~ .toc-drawer-fab {
  opacity: 0;
  pointer-events: none;
}

.toc-drawer {
  position: fixed;
  top: 0;
  right: 0;
  width: 320px;
  height: 100vh;
  height: 100dvh;
  z-index: 50;
  background: #fff;
  box-shadow: -4px 0 24px rgba(15, 23, 42, 0.12);
  transform: translateX(100%);
  transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}
.toc-drawer-toggle:checked ~ .toc-drawer {
  transform: translateX(0);
}

.toc-drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid #e2e8f0;
  flex-shrink: 0;
}
.toc-drawer-body {
  flex: 1;
  overflow-y: auto;
  padding: 0.5rem 0;
}
.toc-drawer-footer {
  padding: 0.75rem 1rem;
  border-top: 1px solid #e2e8f0;
  flex-shrink: 0;
}

/* ── Settings Toast (qr-login.js) ── */
.settings-toast {
  font-size: 0.875rem;
  margin-top: 0.5rem;
  opacity: 0;
  transition: opacity 0.2s;
}
.settings-toast.show { opacity: 1; }
.settings-toast.toast-ok { color: #15803d; }
.settings-toast.toast-err { color: #b91c1c; }

/* ── Drag & Drop (settings.html) ── */
.drag-over {
  outline: 2px solid #6366f1;
  outline-offset: -2px;
  background: #eef2ff !important;
}

/* ── Filter Chip Active States ── */
/* Static classes replacing dynamic Tailwind color utilities
   (Tailwind CDN can't compile Jinja2-dynamic class names like
   bg-blue-600 that only appear after HTMX swaps). */
.filter-chip-on {
  color: #fff !important;
  --fc-ring-color: rgb(0 0 0 / 0.08);
  box-shadow: inset 0 0 0 1px var(--fc-ring-color);
}
.filter-chip-on-indigo { background-color: #4f46e5; }
.filter-chip-on-blue   { background-color: #2563eb; }
.filter-chip-on-amber  { background-color: #d97706; }
.filter-chip-on-red    { background-color: #dc2626; }

.dark .filter-chip-on {
  --fc-ring-color: rgb(255 255 255 / 0.12);
}
.dark .filter-chip-on-indigo { background-color: #6366f1; }
.dark .filter-chip-on-blue   { background-color: #3b82f6; }
.dark .filter-chip-on-amber  { background-color: #f59e0b; }
.dark .filter-chip-on-red    { background-color: #ef4444; }

/* ── Shake animation (login error) ── */
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-4px); }
  40% { transform: translateX(4px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(4px); }
}
.animate-shake { animation: shake 0.4s ease; }

/* ── Prose — Markdown content styling ── */
/* Matches design-system.md §3.5 with Tailwind values */
.prose {
  color: #374151;
  max-width: none;
  line-height: 1.75;
  font-size: 1rem;
}
.prose > :first-child { margin-top: 0; }
.prose > :last-child  { margin-bottom: 0; }

.prose h1 { font-size: 2.25rem; font-weight: 600; letter-spacing: -0.025em; line-height: 1.2;    margin: 0 0 0.8888889em; color: #111827; }
/* h2: left accent stripe per §3.5 */
.prose h2 { font-size: 1.5rem;  font-weight: 600; line-height: 1.3333; margin: 2em 0 1em;          color: #111827; border-left: 4px solid #4f46e5; padding-left: 1rem; scroll-margin-top: 4rem; }
.prose h3 { font-size: 1.25rem; font-weight: 600; line-height: 1.6;    margin: 1.6em 0 0.6em;       color: #111827; scroll-margin-top: 4rem; }
.prose h4 { font-size: 1.125rem;font-weight: 600; line-height: 1.5;    margin: 1.5em 0 0.5em;       color: #111827; }
.prose h5 { font-size: 1rem;    font-weight: 600; line-height: 1.4;    margin: 1.4em 0 0.4em;       color: #111827; }
.prose h6 { font-size: 0.875rem;font-weight: 600; line-height: 1.4;    margin: 1.4em 0 0.4em;       color: #6b7280; }

.prose p          { margin: 1.25em 0; }
.prose ul, .prose ol { margin: 1.25em 0; padding-left: 1.625em; }
.prose ul { list-style-type: disc; }
.prose ol { list-style-type: decimal; }
.prose li         { margin: 0.5em 0; }
.prose li > ul, .prose li > ol { margin: 0.5em 0; }
/* blockquote: accent left border + light bg per §3.5
   DS v0.1.2: italic → not-italic — 三家文档站共识，大段斜体降低可读性 */
.prose blockquote {
  border-left: 4px solid #4f46e5;
  background: #eef2ff;
  padding: 0.75em 1em;
  margin: 1.6em 0;
  color: #374151;
  border-radius: 0 0.375rem 0.375rem 0;
}
.prose blockquote p:first-of-type::before { content: ""; }
.prose blockquote p:last-of-type::after   { content: ""; }

.prose a {
  color: #4f46e5;
  text-decoration: underline;
  font-weight: 500;
}
.prose a:hover { color: #4338ca; }

.prose strong { font-weight: 600; color: #111827; }
.prose em     { font-style: italic; }

/* inline code: amber text per §3.5 */
.prose code {
  font-size: 0.875em;
  font-weight: 500;
  background: #f1f5f9;
  color: #b45309;
  padding: 0.125em 0.375em;
  border-radius: 0.25rem;
  font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}
.prose code::before, .prose code::after { content: ""; }

.prose pre {
  background: #1e293b;
  color: #e2e8f0;
  padding: 1em 1.25em;
  border-radius: 0.5rem;
  overflow-x: auto;
  font-size: 0.875em;
  line-height: 1.7142857;
  margin: 1.7142857em 0;
}
.prose pre code {
  background: transparent;
  color: inherit;
  padding: 0;
  font-size: inherit;
  font-weight: 400;
  border-radius: 0;
}

.prose table {
  width: 100%;
  table-layout: auto;
  text-align: left;
  margin: 2em 0;
  font-size: 0.875em;
  line-height: 1.7142857;
  border-collapse: collapse;
}
.prose thead { border-bottom: 2px solid #d1d5db; }
.prose thead th {
  font-weight: 600;
  vertical-align: bottom;
  padding: 0.5714286em;
  color: #111827;
  background: linear-gradient(180deg, #f1f5f9, #e2e8f0);
}
.prose tbody tr { border-bottom: 1px solid #e5e7eb; }
.prose tbody tr:nth-child(even) { background: #f8fafc; }
.prose tbody tr:last-child { border-bottom: none; }
.prose tbody td { padding: 0.5714286em; vertical-align: top; }

.prose img { max-width: 100%; height: auto; border-radius: 0.5rem; margin: 2em 0; }
/* hr: gradient per §3.5 */
.prose hr  { border: 0; height: 1px; background: linear-gradient(90deg, #e2e8f0, transparent); margin: 3em 0; }

.prose .table-wrapper { margin: 2em 0; }
.prose .table-wrapper table { margin: 0; }

/* ── TOC List ── */
/* DS TOC spec: text-xs, rounded, active: font-semibold + border-l-2, h3: pl-4 text-gray-400 */
.toc-list { list-style: none; padding: 0; margin: 0; }
.toc-list li { margin-top: 0.25rem; }
.toc-list a {
  display: block;
  padding: 0.25rem 0.5rem;
  border-radius: 0.25rem;
  font-size: 0.75rem;
  color: #6b7280;
  text-decoration: none;
  line-height: 1.4;
  transition: color 0.15s, background-color 0.15s;
  border-left: 2px solid transparent;
}
.toc-list a:hover { color: #1f2937; background: #f3f4f6; }
.toc-list a:focus-visible {
  outline: 2px solid #111827;
  outline-offset: 2px;
}
.toc-list a.active {
  color: #4f46e5;
  background: #eef2ff;
  border-left-color: #4f46e5;
  font-weight: 600;
}
.toc-h3 a { padding-left: 1rem; font-size: 0.75rem; color: #9ca3af; }
.toc-h3 a:hover { color: #1f2937; }

/* ── Dark mode overrides for dynamic elements ── */
.dark .prose            { color: #d1d5db; }
.dark .prose h1,
.dark .prose h2,
.dark .prose h3,
.dark .prose h4,
.dark .prose h5        { color: #f9fafb; }
.dark .prose h2        { border-left-color: #818cf8; }
.dark .prose h6        { color: #9ca3af; }
.dark .prose strong    { color: #f9fafb; }
.dark .prose blockquote { border-left-color: #818cf8; background: #1e1b4b; color: #c7d2fe; }
.dark .prose a          { color: #818cf8; }
.dark .prose a:hover    { color: #a5b4fc; }
.dark .prose code       { background: #1e293b; color: #fbbf24; }
.dark .prose pre        { background: #0f172a; color: #e2e8f0; }
.dark .prose thead      { border-bottom-color: #4b5563; }
.dark .prose thead th   { color: #f9fafb; background: linear-gradient(180deg, #1e293b, #334155); }
.dark .prose tbody tr   { border-bottom-color: #374151; }
.dark .prose tbody tr:nth-child(even) { background: #0f172a; }
.dark .prose hr         { background: linear-gradient(90deg, #374151, transparent); }

.dark .toc-list a            { color: #9ca3af; }
.dark .toc-list a:hover      { color: #e5e7eb; background: #1f2937; }
.dark .toc-list a:focus-visible { outline-color: #f9fafb; }
.dark .toc-list a.active     { color: #a5b4fc; background: #1e1b4b; border-left-color: #818cf8; }
.dark .step-item .step-dot { background: #475569; color: #94a3b8; }
.dark .step-item.done .step-dot { background: #6366f1; }
.dark .step-item.running .step-dot { background: #312e81; color: #a5b4fc; }
.dark .step-connector { background: #475569; }
.dark .step-connector.done { background: #6366f1; }
.dark .toast-success { background: #052e16; color: #86efac; }
.dark .toast-error { background: #450a0a; color: #fecaca; }
.dark .toast-info { background: #1e1b4b; color: #c7d2fe; }
.dark .bottom-sheet { background: #1e293b; }
.dark .bottom-sheet-header { border-color: #334155; }
.dark .bottom-sheet-close { color: #94a3b8; }
.dark .toc-drawer-fab { background: #1e293b; border-color: #334155; color: #94a3b8; }
.dark .toc-drawer-fab:hover { color: #e5e7eb; background: #334155; }
.dark .toc-drawer { background: #1e293b; }
.dark .toc-drawer-header { border-color: #334155; }
.dark .toc-drawer-footer { border-color: #334155; }
.dark .drag-over { background: #1e1b4b !important; outline-color: #818cf8; }

/* ── Reduced Motion — respect OS-level accessibility preference ── */
@media (prefers-reduced-motion: reduce) {
  .step-item .step-dot { transition: none; }
  .step-item.running .step-dot { animation: none; }
  .toast { transition: none; }
  .bottom-sheet { transition: none; }
  .settings-toast { transition: none; }
  .toc-list a { transition: none; }
  .toc-drawer-mask { transition: none; }
  .toc-drawer { transition: none; }
  .toc-drawer-fab { transition: none; }
}
