/* contract-artifact-panel.css — Phase 19 (2026-05-10) Modern claude-like preview
 * Right-rail sticky panel cho preview hợp đồng .docx.
 * Slide-in từ phải, header gradient, paper-like body, smooth transitions.
 */

:root {
  --cap-bg: #f5f5f4;
  --cap-card-bg: #ffffff;
  --cap-text: #1c1917;
  --cap-text-muted: #78716c;
  --cap-border: #e7e5e4;
  --cap-border-strong: #d6d3d1;
  --cap-accent: #c2410c;     /* warm orange — claude-style */
  --cap-accent-soft: #fff7ed;
  --cap-success: #15803d;
  --cap-success-soft: #f0fdf4;
  --cap-radius: 12px;
}

.cap-root {
  position: fixed;
  top: 0;
  right: 0;
  width: min(720px, 50vw);
  height: 100vh;
  background: var(--cap-bg);
  border-left: 1px solid var(--cap-border);
  box-shadow: -8px 0 32px rgba(28, 25, 23, 0.08), -2px 0 6px rgba(28, 25, 23, 0.04);
  z-index: 9000;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  /* Phase 19.2 fix: dùng transform translateX thay width transition (GPU-accel,
   * không bị stuck mid-flight, smooth hơn). */
  transform: translateX(100%);
  transition: transform 0.32s cubic-bezier(0.4, 0, 0.2, 1);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "SF Pro Display", Roboto, Helvetica, Arial, sans-serif;
  color: var(--cap-text);
  pointer-events: none;
}

.cap-root.cap-open {
  transform: translateX(0);
  pointer-events: auto;
}

.cap-root[hidden] {
  display: none;
}

@media (max-width: 1024px) {
  .cap-root { width: min(640px, 56vw); }
}

@media (max-width: 768px) {
  .cap-root { width: 100vw; }
}

/* ══════════════════ HEADER (flat) ══════════════════ */
.cap-header {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 14px 18px 12px;
  border-bottom: 1px solid var(--cap-border);
  background: var(--cap-card-bg);
  flex-shrink: 0;
}

.cap-header__meta {
  flex: 1;
  min-width: 0;
}

.cap-header__title {
  font-size: 14.5px;
  font-weight: 600;
  color: var(--cap-text);
  letter-spacing: -0.005em;
  line-height: 1.4;
  /* Phase 21.1: cho phép tiêu đề wrap 2 dòng nếu dài, hiện đầy đủ */
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  text-overflow: ellipsis;
  word-break: break-word;
}

.cap-header__close {
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 6px;
  background: transparent;
  cursor: pointer;
  color: var(--cap-text-muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background-color 0.12s ease, color 0.12s ease;
}

.cap-header__close:hover {
  background: rgba(28, 25, 23, 0.06);
  color: var(--cap-text);
}

.cap-header__close:focus-visible {
  outline: 2px solid var(--cap-accent);
  outline-offset: 1px;
}

/* ══════════════════ TOOLBAR (flat) ══════════════════ */
.cap-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 20px;
  border-bottom: 1px solid var(--cap-border);
  background: var(--cap-card-bg);
  flex-shrink: 0;
  flex-wrap: wrap;
}

.cap-toolbar__group {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 30px;
}

.cap-toolbar__label {
  font-size: 11.5px;
  color: var(--cap-text-muted);
  font-weight: 500;
  letter-spacing: 0.01em;
}

.cap-version-select {
  font-size: 12.5px;
  padding: 4px 8px;
  border: 1px solid var(--cap-border);
  border-radius: 6px;
  background: var(--cap-card-bg);
  color: var(--cap-text);
  cursor: pointer;
  min-width: 90px;
  font-weight: 500;
  font-family: inherit;
  transition: border-color 0.12s ease, background-color 0.12s ease;
}

.cap-version-select:hover {
  border-color: var(--cap-border-strong);
  background: #fafaf9;
}

.cap-version-select:focus-visible {
  outline: 2px solid var(--cap-accent);
  outline-offset: 1px;
  border-color: var(--cap-accent);
}

/* Mode switcher: 3 button group, segmented-control style (flat) */
.cap-mode {
  border: 1px solid var(--cap-border);
  border-radius: 7px;
  padding: 2px;
  background: #fafaf9;
}

.cap-mode__btn {
  font-size: 12px;
  font-weight: 500;
  padding: 4px 10px;
  border: none;
  border-radius: 5px;
  background: transparent;
  color: var(--cap-text-muted);
  cursor: pointer;
  font-family: inherit;
  transition: background-color 0.12s ease, color 0.12s ease;
  letter-spacing: 0.01em;
}

.cap-mode__btn:hover:not(:disabled) {
  color: var(--cap-text);
}

.cap-mode__btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.cap-mode__btn.is-active {
  background: var(--cap-card-bg);
  color: var(--cap-text);
  font-weight: 600;
  box-shadow: 0 1px 2px rgba(28, 25, 23, 0.06);
}

.cap-btn {
  font-size: 12.5px;
  padding: 6px 14px;
  border: 1px solid var(--cap-border);
  border-radius: 6px;
  background: var(--cap-card-bg);
  color: var(--cap-text);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-weight: 500;
  font-family: inherit;
  height: 30px;
  transition: background-color 0.12s ease, border-color 0.12s ease;
}

.cap-btn:hover {
  background: #fafaf9;
  border-color: var(--cap-border-strong);
}

.cap-btn:focus-visible {
  outline: 2px solid var(--cap-accent);
  outline-offset: 1px;
}

.cap-btn--primary {
  background: var(--cap-accent);
  border-color: var(--cap-accent);
  color: #ffffff;
}

.cap-btn--primary:hover {
  background: #9a3412;
  border-color: #9a3412;
}

.cap-spacer {
  flex: 1;
}

/* ══════════════════ SUMMARY BAR (Phase 21.9 — collapsible) ══════════════════ */
.cap-summary {
  border-bottom: 1px solid var(--cap-border);
  background: #fffbeb;
  flex-shrink: 0;
}

/* Header — always visible, click to toggle */
.cap-summary__header {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 10px 20px;
  background: transparent;
  border: 0;
  cursor: pointer;
  font-family: inherit;
  text-align: left;
  color: #78350f;
  transition: background-color 0.12s ease;
}

.cap-summary__header:hover {
  background: rgba(245, 158, 11, 0.06);
}

.cap-summary__header:focus-visible {
  outline: 2px solid var(--cap-accent);
  outline-offset: -2px;
}

.cap-summary__chevron {
  flex-shrink: 0;
  color: #b45309;
  transition: transform 0.18s ease;
}

.cap-summary[data-expanded="true"] .cap-summary__chevron {
  transform: rotate(90deg);
}

.cap-summary__count {
  font-size: 12px;
  font-weight: 600;
  color: #78350f;
  letter-spacing: 0.005em;
  white-space: nowrap;
}

.cap-summary__stats {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
  margin-right: 8px;
}

.cap-summary__stat {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 4px;
  font-variant-numeric: tabular-nums;
}

.cap-summary__stat--modified {
  background: #fef3c7;
  color: #78350f;
}

.cap-summary__stat--added {
  background: #d1fae5;
  color: #065f46;
}

.cap-summary__stat--removed {
  background: #fee2e2;
  color: #991b1b;
}

.cap-summary__stat-icon {
  font-weight: 700;
  font-size: 11px;
  line-height: 1;
}

.cap-summary__toggle-text {
  font-size: 11px;
  font-weight: 500;
  color: #b45309;
  white-space: nowrap;
  flex-shrink: 0;
}

/* Chips wrap — CSS grid trick cho smooth height transition */
.cap-summary__chips-wrap {
  display: grid;
  grid-template-rows: 0fr;
  transition: grid-template-rows 0.22s ease;
}

.cap-summary[data-expanded="true"] .cap-summary__chips-wrap {
  grid-template-rows: 1fr;
}

.cap-summary__chips-wrap > .cap-summary__chips {
  overflow: hidden;
  min-height: 0;
}

.cap-summary[data-expanded="true"] .cap-summary__chips-wrap > .cap-summary__chips {
  /* Khi expanded: cho phép scroll nếu quá nhiều pill */
  overflow-y: auto;
  max-height: 200px;
  padding: 0 20px 12px;
}

.cap-summary__chips {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.cap-summary__chips::-webkit-scrollbar {
  width: 6px;
}
.cap-summary__chips::-webkit-scrollbar-track {
  background: transparent;
}
.cap-summary__chips::-webkit-scrollbar-thumb {
  background: rgba(180, 83, 9, 0.25);
  border-radius: 3px;
}
.cap-summary__chips::-webkit-scrollbar-thumb:hover {
  background: rgba(180, 83, 9, 0.45);
}

.cap-summary__chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11.5px;
  font-family: inherit;
  padding: 3px 9px 3px 4px;
  border-radius: 5px;
  border: 1px solid rgba(0, 0, 0, 0.06);
  background: var(--cap-card-bg);
  cursor: pointer;
  color: var(--cap-text);
  transition: background-color 0.12s ease, border-color 0.12s ease, transform 0.12s ease;
  max-width: 260px;
}

.cap-summary__chip:hover {
  border-color: var(--cap-border-strong);
  transform: translateY(-1px);
}

.cap-summary__chip:focus-visible {
  outline: 2px solid var(--cap-accent);
  outline-offset: 1px;
}

.cap-summary__verb {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 11px;
  width: 18px;
  height: 18px;
  border-radius: 4px;
  letter-spacing: 0;
  line-height: 1;
}

.cap-summary__chip--modified .cap-summary__verb {
  background: #fef3c7;
  color: #78350f;
}

.cap-summary__chip--added .cap-summary__verb {
  background: #d1fae5;
  color: #065f46;
}

.cap-summary__chip--removed .cap-summary__verb {
  background: #fee2e2;
  color: #991b1b;
}

.cap-summary__label {
  color: var(--cap-text);
  font-weight: 500;
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ══════════════════ BODY (paper-like) ══════════════════ */
.cap-body {
  flex: 1;
  overflow: auto;
  padding: 24px 28px 60px;
  background: var(--cap-bg);
  scroll-behavior: smooth;
}

.cap-body::-webkit-scrollbar {
  width: 10px;
}

.cap-body::-webkit-scrollbar-track {
  background: transparent;
}

.cap-body::-webkit-scrollbar-thumb {
  background: rgba(28, 25, 23, 0.15);
  border-radius: 6px;
  border: 2px solid var(--cap-bg);
}

.cap-body::-webkit-scrollbar-thumb:hover {
  background: rgba(28, 25, 23, 0.3);
}

.cap-doc {
  background: var(--cap-card-bg);
  border: 1px solid var(--cap-border);
  border-radius: var(--cap-radius);
  padding: 36px 44px;
  font-family: "Charter", "Iowan Old Style", "Source Serif Pro", "Times New Roman", Georgia, serif;
  font-size: 14.5px;
  line-height: 1.7;
  color: var(--cap-text);
  word-wrap: break-word;
  box-shadow:
    0 1px 2px rgba(28, 25, 23, 0.04),
    0 4px 12px rgba(28, 25, 23, 0.04);
  position: relative;
  font-feature-settings: "kern" 1, "liga" 1, "calt" 1;
}

@media (max-width: 768px) {
  .cap-doc {
    padding: 24px 20px;
    font-size: 14px;
  }
}

/* Phase 21.1 — block-level rendering matching docx output. */
.cap-doc .cap-p {
  margin: 0 0 12px;
  text-align: justify;
}

.cap-doc .cap-p:last-child {
  margin-bottom: 0;
}

.cap-doc .cap-hr {
  border: none;
  border-top: 1px solid var(--cap-border);
  margin: 20px 0;
}

.cap-doc .cap-doc__h {
  font-family: -apple-system, "Inter", "Segoe UI", Roboto, sans-serif;
  font-weight: 700;
  margin: 22px 0 10px;
  color: var(--cap-text);
  letter-spacing: -0.005em;
  line-height: 1.32;
}

.cap-doc .cap-doc__h--1 {
  font-size: 17.5px;
  text-align: center;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  margin: 4px 0 18px;
  padding-bottom: 12px;
  border-bottom: 2px solid var(--cap-border-strong);
}

.cap-doc .cap-doc__h--2 { font-size: 15.5px; }
.cap-doc .cap-doc__h--3 { font-size: 14.5px; font-style: italic; color: var(--cap-text-muted); }

.cap-doc__article-heading {
  font-family: -apple-system, "Inter", "Segoe UI", Roboto, sans-serif;
  font-weight: 700;
  font-size: 15px;
  color: var(--cap-accent);
  margin: 22px 0 8px;
  letter-spacing: -0.005em;
}

.cap-doc__appendix-heading {
  font-family: -apple-system, "Inter", "Segoe UI", Roboto, sans-serif;
  font-weight: 700;
  font-size: 14.5px;
  color: var(--cap-success);
  margin: 28px 0 10px;
  padding: 8px 12px;
  border-left: 3px solid var(--cap-success);
  background: var(--cap-success-soft);
  border-radius: 0 6px 6px 0;
}

/* Lists */
.cap-doc .cap-list {
  margin: 0 0 12px;
  padding-left: 26px;
}

.cap-doc .cap-list li {
  margin-bottom: 4px;
  text-align: justify;
}

.cap-doc .cap-list--bullets {
  list-style: disc;
}

.cap-doc .cap-list--numbered {
  list-style: decimal;
}

/* Tables — match docx default appearance */
.cap-doc .cap-table {
  width: 100%;
  border-collapse: collapse;
  margin: 14px 0 16px;
  font-size: 13.5px;
  font-family: -apple-system, "Inter", "Segoe UI", Roboto, sans-serif;
  border: 1px solid var(--cap-border-strong);
}

.cap-doc .cap-table th,
.cap-doc .cap-table td {
  padding: 8px 12px;
  border: 1px solid var(--cap-border);
  text-align: left;
  vertical-align: top;
  line-height: 1.55;
}

.cap-doc .cap-table thead th {
  background: #fafaf9;
  font-weight: 600;
  color: var(--cap-text);
  letter-spacing: 0.005em;
}

.cap-doc .cap-table tbody tr:nth-child(even) td {
  background: #fbfbfa;
}

.cap-doc .cap-table--kv th[scope="row"] {
  background: #fafaf9;
  font-weight: 600;
  width: 32%;
}

.cap-doc .cap-table__no-header {
  display: none;
}

/* Inline elements */
.cap-doc strong { font-weight: 700; color: var(--cap-text); }
.cap-doc em { font-style: italic; }
.cap-doc code {
  font-family: "SF Mono", Monaco, Consolas, monospace;
  font-size: 0.9em;
  padding: 1px 5px;
  background: #f5f5f4;
  border-radius: 3px;
  border: 1px solid var(--cap-border);
}

/* Note callout */
.cap-doc .cap-note {
  margin: 12px 0;
  padding: 10px 14px;
  background: #fffbeb;
  border-left: 3px solid #d97706;
  border-radius: 0 6px 6px 0;
  display: flex;
  gap: 10px;
  font-size: 13.5px;
  font-family: -apple-system, "Inter", "Segoe UI", Roboto, sans-serif;
}

.cap-doc .cap-note__label {
  font-weight: 700;
  color: #78350f;
  flex-shrink: 0;
}

.cap-doc .cap-note__text {
  color: var(--cap-text);
  line-height: 1.55;
}

.cap-empty {
  padding: 60px 24px;
  text-align: center;
  color: var(--cap-text-muted);
}

.cap-empty__title {
  font-size: 14px;
  font-weight: 600;
  color: var(--cap-text);
  margin-bottom: 6px;
}

.cap-empty__desc {
  font-size: 12.5px;
  color: var(--cap-text-muted);
  line-height: 1.5;
  max-width: 360px;
  margin: 0 auto;
}

/* ══════════════════ SECTION (Phase 21) ══════════════════ */
/* Mỗi Điều / Phụ lục là 1 section. Trong mode "doc" và "inline" có
   background tint nhẹ phân biệt status. */
.cap-section {
  position: relative;
  scroll-margin-top: 16px;
  border-radius: 6px;
  padding: 2px 6px;
  margin: 4px -6px;
  transition: background-color 0.18s ease;
}

.cap-section--unchanged { /* default — no tint */ }

.cap-section--modified {
  background: #fffbeb;
}

.cap-section--added {
  background: #ecfdf5;
}

.cap-section--removed {
  background: #fef2f2;
  opacity: 0.85;
}

.cap-section--flash {
  animation: capSectionFlash 1.4s ease;
}

@keyframes capSectionFlash {
  0%   { background-color: #fde68a; }
  60%  { background-color: #fef3c7; }
  100% { background-color: var(--cap-section-bg, transparent); }
}

.cap-section__badge {
  position: absolute;
  top: 6px;
  right: 8px;
  font-family: -apple-system, "Inter", "Segoe UI", Roboto, sans-serif;
  font-size: 10.5px;
  font-weight: 600;
  padding: 1px 7px;
  border-radius: 3px;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.cap-section__badge--modified { background: #fef3c7; color: #78350f; }
.cap-section__badge--added    { background: #d1fae5; color: #065f46; }
.cap-section__badge--removed  { background: #fee2e2; color: #991b1b; }

.cap-section__removed {
  opacity: 0.7;
  text-decoration: line-through;
  text-decoration-color: rgba(127, 29, 29, 0.4);
  text-decoration-thickness: 1px;
}

/* Inline word-level diff (trong mode "inline") */
.cap-doc--inline-diff .cap-ins,
.cap-ins {
  background: #d1fae5;
  color: #065f46;
  text-decoration: none;
  border-radius: 2px;
  padding: 0 2px;
  font-weight: 500;
}

.cap-doc--inline-diff .cap-del,
.cap-del {
  background: #fee2e2;
  color: #991b1b;
  text-decoration: line-through;
  text-decoration-color: rgba(153, 27, 27, 0.45);
  border-radius: 2px;
  padding: 0 2px;
  font-weight: 400;
}

/* Block xuất hiện bên trong section khi modified (chỉ word-diff text mode).
   Giữ pre-wrap để newlines từ raw text hiển thị đúng. */
.cap-section__inline-diff {
  white-space: pre-wrap;
  word-wrap: break-word;
}

@media (prefers-color-scheme: dark) {
  .cap-section--modified { background: rgba(217, 119, 6, 0.10); }
  .cap-section--added    { background: rgba(16, 185, 129, 0.10); }
  .cap-section--removed  { background: rgba(220, 38, 38, 0.10); }
  .cap-summary { background: rgba(180, 83, 9, 0.10); }
}

/* ──────────────────────────────────────────────────────────────────────
 * Diff view — Phase 17 (2026-05-10) Smart compare
 * LCS-based + collapse unchanged hunks + word-level inline diff
 * ────────────────────────────────────────────────────────────────────── */

.cap-diff {
  background: #ffffff;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  padding: 0;
  font-family: "SF Mono", Monaco, Consolas, monospace;
  font-size: 12px;
  line-height: 1.55;
  overflow: hidden;
}

.cap-diff__summary {
  background: linear-gradient(180deg, #fafafa 0%, #f3f4f6 100%);
  padding: 10px 16px;
  border-bottom: 1px solid #e5e7eb;
  font-size: 11.5px;
  font-family: -apple-system, "Segoe UI", Roboto, sans-serif;
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  align-items: center;
}

.cap-diff__stat {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 4px;
}

.cap-diff__stat--add {
  background: #d1fae5;
  color: #065f46;
}

.cap-diff__stat--del {
  background: #fee2e2;
  color: #991b1b;
}

.cap-diff__stat--ctx {
  background: #f3f4f6;
  color: #6b7280;
  font-weight: 500;
}

.cap-diff__hunk-block {
  border-bottom: 1px solid #f3f4f6;
}

.cap-diff__hunk-block:last-child {
  border-bottom: none;
}

.cap-diff__line {
  padding: 2px 12px 2px 6px;
  white-space: pre-wrap;
  word-wrap: break-word;
  display: flex;
  align-items: flex-start;
  gap: 6px;
  border-left: 3px solid transparent;
  transition: background-color 0.12s ease;
}

.cap-diff__sign {
  flex-shrink: 0;
  width: 14px;
  text-align: center;
  font-weight: 700;
  user-select: none;
  color: #9ca3af;
}

.cap-diff__line--add {
  background: #ecfdf5;
  color: #065f46;
  border-left-color: #10b981;
}

.cap-diff__line--add .cap-diff__sign {
  color: #10b981;
}

.cap-diff__line--del {
  background: #fef2f2;
  color: #991b1b;
  border-left-color: #ef4444;
}

.cap-diff__line--del .cap-diff__sign {
  color: #ef4444;
}

.cap-diff__line--ctx {
  background: #ffffff;
  color: #6b7280;
}

.cap-diff__line:hover {
  filter: brightness(0.97);
}

/* Word-level highlighting cho cặp del+add cùng dòng */
.cap-word--add {
  background: #6ee7b7;
  color: #064e3b;
  border-radius: 3px;
  padding: 0 2px;
  font-weight: 600;
}

.cap-word--del {
  background: #fca5a5;
  color: #7f1d1d;
  border-radius: 3px;
  padding: 0 2px;
  text-decoration: line-through;
  text-decoration-color: rgba(127, 29, 29, 0.5);
  font-weight: 500;
}

.cap-diff__line--word {
  border-left-width: 4px;
}

/* Collapsed hunk (nhóm dòng giữ nguyên > 4 dòng) — clickable expand */
.cap-diff__collapsed {
  background: linear-gradient(90deg, #f9fafb 0%, #ffffff 50%, #f9fafb 100%);
  color: #6b7280;
  font-size: 11px;
  padding: 8px 12px;
  text-align: center;
  cursor: pointer;
  border-top: 1px dashed #e5e7eb;
  border-bottom: 1px dashed #e5e7eb;
  font-family: -apple-system, "Segoe UI", Roboto, sans-serif;
  user-select: none;
  transition: background 0.15s ease, color 0.15s ease;
}

.cap-diff__collapsed:hover {
  background: linear-gradient(90deg, #eef2ff 0%, #f5f3ff 50%, #eef2ff 100%);
  color: #4f46e5;
}

.cap-diff__collapsed-icon {
  font-size: 13px;
  font-weight: 700;
  margin-right: 6px;
  letter-spacing: 1px;
}

.cap-diff__collapsed-text {
  font-style: italic;
}

.cap-diff__empty {
  padding: 30px 20px;
  text-align: center;
  color: #9ca3af;
  font-family: -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 13px;
}

/* Backdrop on mobile */
@media (max-width: 768px) {
  .cap-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.3);
    z-index: 8999;
    display: none;
  }
  .cap-root.cap-open ~ .cap-backdrop {
    display: block;
  }
}

/* ──────────────────────────────────────────────────────────────────────
 * Phase 19.2 (2026-05-10): UNIFIED CARD DESIGN — claude-style
 * Card .msg-file--contract = button mở panel (toàn card click → preview).
 * Icon "Tải" nhỏ overlay góc phải = download direct.
 * Hint badge "Mở trong khung xem" mờ phía dưới + arrow icon.
 * KHÔNG còn separate button → đồng bộ UI thành 1 entity claude-like.
 * ────────────────────────────────────────────────────────────────────── */

.msg-file--contract {
  position: relative;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 16px;
  width: 100%;
  max-width: min(640px, 100%);
  text-decoration: none;
  border-radius: 14px;
  background: linear-gradient(135deg, #ffffff 0%, #fafaf9 100%);
  border: 1.5px solid rgba(194, 65, 12, 0.18);
  box-shadow:
    0 1px 2px rgba(28, 25, 23, 0.04),
    0 4px 12px rgba(194, 65, 12, 0.05);
  cursor: pointer !important;
  user-select: none;
  transition:
    background 0.18s ease,
    border-color 0.18s ease,
    box-shadow 0.22s ease,
    transform 0.15s ease;
  animation: capUnifiedAppear 0.4s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

.msg-file--contract::before {
  /* Subtle glow trên hover — claude-style */
  content: "";
  position: absolute;
  inset: -2px;
  border-radius: 16px;
  background: linear-gradient(135deg, rgba(194, 65, 12, 0) 0%, rgba(234, 88, 12, 0.18) 100%);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.22s ease;
  z-index: -1;
}

.msg-file--contract:hover {
  background: linear-gradient(135deg, #fffbf5 0%, #fff7ed 100%);
  border-color: rgba(194, 65, 12, 0.42);
  box-shadow:
    0 2px 4px rgba(28, 25, 23, 0.06),
    0 12px 28px rgba(194, 65, 12, 0.18);
  transform: translateY(-2px);
}

.msg-file--contract:hover::before {
  opacity: 1;
}

.msg-file--contract:active {
  transform: translateY(0);
  box-shadow:
    0 1px 2px rgba(28, 25, 23, 0.06),
    0 4px 10px rgba(194, 65, 12, 0.12);
}

.msg-file--contract:focus-visible {
  outline: 2.5px solid rgba(194, 65, 12, 0.5);
  outline-offset: 2px;
}

.msg-file--contract .msg-file__ic {
  flex: 0 0 auto;
  width: 42px;
  height: 42px;
  border-radius: 11px;
  background: linear-gradient(135deg, #c2410c 0%, #ea580c 100%);
  color: #ffffff;
  box-shadow:
    0 2px 6px rgba(194, 65, 12, 0.3),
    0 0 0 1px rgba(255, 255, 255, 0.12) inset;
  transition: transform 0.2s ease, box-shadow 0.22s ease;
}

.msg-file--contract:hover .msg-file__ic {
  transform: scale(1.04);
  box-shadow:
    0 4px 12px rgba(194, 65, 12, 0.4),
    0 0 0 1px rgba(255, 255, 255, 0.18) inset;
}

.msg-file--contract .msg-file__ic svg {
  width: 20px;
  height: 20px;
  stroke-width: 1.8;
}

.msg-file--contract .msg-file__meta {
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.msg-file--contract .msg-file__name {
  font-size: 14px;
  font-weight: 600;
  color: #1c1917;
  letter-spacing: -0.01em;
  line-height: 1.35;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.msg-file--contract .msg-file__size {
  font-size: 11.5px;
  color: #78716c;
  opacity: 1;
  font-feature-settings: "tnum" 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Icon "Tải" overlay góc phải — small action button */
.msg-file__dl {
  flex: 0 0 auto;
  width: 32px;
  height: 32px;
  border: 1px solid rgba(28, 25, 23, 0.12);
  border-radius: 8px;
  background: #ffffff;
  color: #57534e;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: inherit;
  transition: all 0.15s ease;
  box-shadow: 0 1px 2px rgba(28, 25, 23, 0.04);
}

.msg-file__dl:hover {
  background: #fff7ed;
  border-color: #c2410c;
  color: #c2410c;
  transform: scale(1.06);
}

.msg-file__dl:active {
  transform: scale(0.94);
}

.msg-file__dl:focus-visible {
  outline: 2px solid rgba(194, 65, 12, 0.5);
  outline-offset: 2px;
}

.msg-file__dl svg {
  flex-shrink: 0;
}

/* Hint badge "Mở trong khung xem" — bottom-right corner */
.msg-file__open-hint {
  position: absolute;
  bottom: -8px;
  right: 16px;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 9px;
  background: linear-gradient(135deg, #c2410c 0%, #ea580c 100%);
  color: #ffffff;
  font-size: 10.5px;
  font-weight: 600;
  border-radius: 6px;
  letter-spacing: 0.01em;
  white-space: nowrap;
  pointer-events: none;
  box-shadow: 0 2px 6px rgba(194, 65, 12, 0.35);
  opacity: 0.92;
  transition: opacity 0.18s, transform 0.18s;
}

.msg-file--contract:hover .msg-file__open-hint {
  opacity: 1;
  transform: translateY(-1px);
}

.msg-file__open-hint svg {
  flex-shrink: 0;
  opacity: 0.95;
}

@keyframes capUnifiedAppear {
  0% {
    opacity: 0;
    transform: translateY(8px) scale(0.96);
  }
  100% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* Mobile */
@media (max-width: 640px) {
  .msg-file--contract { padding: 12px 14px; gap: 12px; }
  .msg-file--contract .msg-file__ic { width: 38px; height: 38px; }
  .msg-file--contract .msg-file__name { font-size: 13.5px; }
  .msg-file__open-hint span { display: none; }
  .msg-file__open-hint { padding: 4px; }
}

/* Dark theme */
@media (prefers-color-scheme: dark) {
  .msg-file--contract {
    background: linear-gradient(135deg, #1c1917 0%, #292524 100%);
    border-color: rgba(194, 65, 12, 0.3);
  }
  .msg-file--contract:hover {
    background: linear-gradient(135deg, #292524 0%, #44403c 100%);
    border-color: rgba(194, 65, 12, 0.5);
  }
  .msg-file--contract .msg-file__name { color: #fafaf9; }
  .msg-file--contract .msg-file__size { color: #a8a29e; }
  .msg-file__dl {
    background: rgba(255, 255, 255, 0.05);
    border-color: rgba(255, 255, 255, 0.12);
    color: #d6d3d1;
  }
  .msg-file__dl:hover {
    background: rgba(194, 65, 12, 0.2);
    border-color: #ea580c;
    color: #fed7aa;
  }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  .msg-file--contract,
  .msg-file__dl,
  .msg-file__open-hint {
    animation: none;
    transition: none;
  }
  .msg-file--contract:hover,
  .msg-file__dl:hover { transform: none; }
}

/* ──────────────────────────────────────────────────────────────────────
 * LEGACY: Phase 16 nút "Mở trong khung xem" ở tail action — Phase 19 đã
 * chuyển vào card. Giữ class cũ ở dạng off để tương thích nếu gọi lại.
 * ────────────────────────────────────────────────────────────────────── */

.asst-cta-btn--open-panel {
  margin-left: 8px;
  position: relative;
  background: linear-gradient(135deg, #10b981 0%, #06b6d4 50%, #0ea5e9 100%);
  background-size: 200% 200%;
  background-position: 0% 50%;
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.18) inset,
    0 6px 18px rgba(16, 185, 129, 0.32),
    0 2px 6px rgba(6, 182, 212, 0.18);
  border: 1px solid rgba(255, 255, 255, 0.12);
  transition:
    transform 0.18s cubic-bezier(0.4, 0, 0.2, 1),
    box-shadow 0.22s ease,
    background-position 0.45s ease,
    filter 0.18s ease;
  animation: capPanelButtonAppear 0.45s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

.asst-cta-btn--open-panel:hover {
  background-position: 100% 50%;
  transform: translateY(-2px) scale(1.02);
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.25) inset,
    0 12px 28px rgba(16, 185, 129, 0.44),
    0 4px 10px rgba(6, 182, 212, 0.32);
  filter: brightness(1.04);
}

.asst-cta-btn--open-panel:active {
  transform: translateY(0) scale(0.98);
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.12) inset,
    0 4px 10px rgba(16, 185, 129, 0.28);
  filter: brightness(0.98);
}

.asst-cta-btn--open-panel:focus-visible {
  outline: 2px solid rgba(6, 182, 212, 0.7);
  outline-offset: 3px;
}

/* Subtle "shimmer" line ở mép phải để mời mắt người dùng — chỉ hiện khi hover */
.asst-cta-btn--open-panel::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: linear-gradient(
    115deg,
    transparent 0%,
    transparent 35%,
    rgba(255, 255, 255, 0.22) 50%,
    transparent 65%,
    transparent 100%
  );
  background-size: 220% 100%;
  background-position: 100% 0;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.25s ease, background-position 0.85s ease;
}

.asst-cta-btn--open-panel:hover::after {
  opacity: 1;
  background-position: -20% 0;
}

/* Icon container: thay emoji 📑 bằng SVG inline (panel-open) */
.asst-cta-btn--open-panel .asst-cta-btn__ic {
  background: rgba(255, 255, 255, 0.22);
  backdrop-filter: blur(2px);
  position: relative;
}

.asst-cta-btn--open-panel .asst-cta-btn__ic::before {
  content: "";
  width: 14px;
  height: 14px;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23ffffff' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'><rect x='3' y='4' width='18' height='16' rx='2'/><line x1='14' y1='4' x2='14' y2='20'/><polyline points='17 9 19 12 17 15'/></svg>");
  background-repeat: no-repeat;
  background-position: center;
  background-size: 14px 14px;
  display: block;
  transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.asst-cta-btn--open-panel:hover .asst-cta-btn__ic::before {
  transform: translateX(1.5px);
}

.asst-cta-btn--open-panel .asst-cta-btn__label {
  font-weight: 600;
  letter-spacing: 0.1px;
}

/* Tiny "NEW" badge hint — pulsing dot to draw attention first time */
.asst-cta-btn--open-panel::before {
  content: "";
  position: absolute;
  top: -2px;
  right: -2px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #ec4899;
  box-shadow: 0 0 0 2px #ffffff, 0 0 8px rgba(236, 72, 153, 0.6);
  animation: capPanelPulseDot 1.6s ease-in-out infinite;
  pointer-events: none;
}

@keyframes capPanelButtonAppear {
  0% {
    opacity: 0;
    transform: translateY(6px) scale(0.92);
  }
  100% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes capPanelPulseDot {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.35); opacity: 0.65; }
}

/* Tôn trọng prefers-reduced-motion */
@media (prefers-reduced-motion: reduce) {
  .asst-cta-btn--open-panel {
    animation: none;
    transition: background-color 0.15s ease, box-shadow 0.15s ease;
  }
  .asst-cta-btn--open-panel:hover {
    transform: none;
  }
  .asst-cta-btn--open-panel::after,
  .asst-cta-btn--open-panel::before {
    animation: none;
  }
}

/* Light theme adjustments — nhẹ shadow hơn */
@media (prefers-color-scheme: light) {
  .asst-cta-btn--open-panel {
    box-shadow:
      0 1px 0 rgba(255, 255, 255, 0.5) inset,
      0 4px 14px rgba(16, 185, 129, 0.22),
      0 1px 4px rgba(6, 182, 212, 0.12);
  }
  .asst-cta-btn--open-panel:hover {
    box-shadow:
      0 1px 0 rgba(255, 255, 255, 0.6) inset,
      0 10px 24px rgba(16, 185, 129, 0.32),
      0 3px 8px rgba(6, 182, 212, 0.2);
  }
}

/* Mobile: smaller margin */
@media (max-width: 640px) {
  .asst-cta-btn--open-panel {
    margin-left: 4px;
  }
  .asst-cta-btn--open-panel::before {
    width: 7px;
    height: 7px;
    top: -1px;
    right: -1px;
  }
}

/* ── Phase 20: process flow diagram inline preview ──────────────────────── */
.cap-diagram {
  display: block;
  margin: 28px auto;
  padding: 16px;
  background: #fafaf9;
  border: 1px solid var(--cap-border);
  border-radius: 8px;
  text-align: center;
  max-width: 100%;
  overflow-x: auto;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
}

.cap-diagram svg {
  max-width: 100%;
  height: auto;
  display: block;
  margin: 0 auto;
}

.cap-diagram__caption {
  margin-top: 10px;
  font-family: -apple-system, "Inter", "Segoe UI", Roboto, sans-serif;
  font-size: 12.5px;
  font-style: italic;
  color: var(--cap-muted, #6b7280);
  letter-spacing: 0.01em;
}

.cap-diagram__loading {
  padding: 36px 12px;
  font-family: -apple-system, "Inter", "Segoe UI", Roboto, sans-serif;
  font-size: 13px;
  color: var(--cap-muted, #78716c);
  font-style: italic;
}

.cap-diagram__loading::before {
  content: "⏳";
  margin-right: 8px;
  font-style: normal;
}

.cap-diagram__error {
  padding: 18px 12px;
  font-family: -apple-system, "Inter", "Segoe UI", Roboto, sans-serif;
  font-size: 13px;
  color: #b91c1c;
  background: #fef2f2;
  border-radius: 6px;
}

.cap-diagram__error::before {
  content: "⚠️";
  margin-right: 8px;
}

@media (prefers-color-scheme: dark) {
  .cap-diagram {
    background: #1c1917;
    border-color: rgba(255, 255, 255, 0.08);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
  }
  .cap-diagram__caption {
    color: #a8a29e;
  }
  .cap-diagram__error {
    background: rgba(185, 28, 28, 0.18);
    color: #fca5a5;
  }
}
