/* หน่วยงานทดสอบ AI - Matrix Mode (ตารางวิเคราะห์หลายเอกสาร) */

.matrix-page { padding: 24px 40px 60px; max-width: 1600px; margin: 0 auto; }
.matrix-page [hidden], .reference-preview[hidden], .drawer-backdrop[hidden] { display: none !important; }

/* =========================================================
   MODE SWITCH - segmented tab (สนทนาถาม-ตอบ | ตารางวิเคราะห์)
   Shared visual pattern - same rules duplicated in css/chat.css so both
   pages render pixel-identical (index.html and matrix.html load separate
   stylesheets; only tokens.css is common between them and it is orchestrator-owned).
   ========================================================= */
.mode-switch {
  display: inline-flex; align-items: center; gap: 2px;
  padding: 3px; margin-bottom: 14px;
  background: var(--bg-chip); border: 1px solid var(--border); border-radius: 10px;
  width: fit-content;
}
.mode-tab {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 7px 16px; border-radius: 8px;
  font-size: 12.5px; font-weight: 600; line-height: 1.45; color: var(--text-500);
  transition: background .15s ease, color .15s ease;
}
.mode-tab:hover { color: var(--color-01); }
.mode-tab.is-active { background: var(--color-01); color: #fff; }
.mode-tab.is-active:hover { color: #fff; }

/* ===== Page head ===== */
.matrix-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; flex-wrap: wrap; margin-bottom: 16px; }
.matrix-head h1 { font-size: 17px; font-weight: 700; color: var(--text-900); }
.matrix-head .sub { font-size: 13px; color: var(--text-500); margin-top: 4px; }
.matrix-actions { display: flex; gap: 10px; flex-wrap: wrap; }

/* ===== Progress line ===== */
.matrix-progress { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.progress-track { flex: 1; max-width: 320px; height: 6px; border-radius: 4px; background: var(--bg-chip); overflow: hidden; }
.progress-fill { height: 100%; width: 0%; background: var(--color-02); border-radius: 4px; }
.progress-label { font-size: 12px; font-weight: 600; color: var(--text-600); white-space: nowrap; font-variant-numeric: tabular-nums; }

/* ===== Grid card ===== */
.matrix-card { position: relative; min-height: 220px; background: var(--bg-white); border: 1px solid var(--border); border-radius: 16px; overflow: hidden; }
.matrix-scroll { overflow: auto; max-width: 100%; }

.matrix-table { border-collapse: separate; border-spacing: 0; min-width: 100%; table-layout: fixed; }
.matrix-table col.col-doc { width: 300px; }
.matrix-table col.col-q { width: 240px; }

.matrix-table thead th {
  position: sticky; top: 0; z-index: 3;
  background: #f8fafc; border-bottom: 1px solid var(--border);
  text-align: left; padding: 12px 14px; vertical-align: top;
}
.matrix-table thead th.th-doc { left: 0; z-index: 4; }

.th-doc-label { font-size: 11px; font-weight: 700; color: var(--text-450); letter-spacing: .3px; }

.th-q { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.th-q-text { font-size: 13px; font-weight: 700; color: var(--text-900); line-height: 1.4; }
.th-q-cond { display: inline-flex; align-items: center; gap: 4px; margin-top: 6px; font-size: 10px; font-weight: 600; color: var(--color-01); background: var(--bg-active); border: 1px solid var(--border-active); border-radius: 6px; padding: 2px 7px; }
.th-menu-btn { flex: 0 0 auto; padding: 4px; border-radius: 6px; color: var(--text-450); }
.th-menu-btn:hover { background: var(--bg-chip); color: var(--text-700); }

.matrix-table tbody td {
  border-bottom: 1px solid var(--border); vertical-align: top; padding: 12px 14px;
  font-size: 13px; color: var(--text-700);
}
.matrix-table tbody tr:last-child td { border-bottom: none; }
.matrix-table tbody tr.row-doc { cursor: pointer; }
.matrix-table tbody tr.row-doc:hover td { background: #f8fafc; }
.matrix-table tbody td.td-doc {
  position: sticky; left: 0; z-index: 2; background: var(--bg-white);
  border-right: 1px solid var(--border);
}
.matrix-table tbody tr.row-doc:hover td.td-doc { background: #f8fafc; }

/* ===== Doc cell ===== */
.doc-cell { display: flex; gap: 10px; align-items: flex-start; }
.doc-badge {
  flex: 0 0 auto; width: 30px; height: 30px; border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-size: 9px; font-weight: 700; letter-spacing: .2px; text-transform: uppercase;
}
.doc-badge.pdf { background: #fef2f2; color: #b91c1c; }
.doc-badge.docx { background: #eff6ff; color: #1d4ed8; }
.doc-badge.xlsx { background: var(--success-bg); color: var(--success-700); }
.doc-info { min-width: 0; }
.doc-remove { flex: 0 0 auto; width: 24px; height: 24px; border-radius: 6px; color: var(--text-450); font-size: 18px; line-height: 1; }
.doc-remove:hover { background: #fef2f2; color: var(--danger-600); }
.doc-name {
  font-size: 13px; font-weight: 600; color: var(--text-900); line-height: 1.4;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.doc-id { font-size: 11px; color: var(--text-500); margin-top: 3px; font-variant-numeric: tabular-nums; }
.doc-cat { display: inline-block; margin-top: 6px; font-size: 10px; font-weight: 600; color: var(--text-600); background: var(--bg-chip); border-radius: 6px; padding: 2px 8px; }
.doc-relevance { display: inline-block; margin: 6px 0 0 5px; font-size: 10px; font-weight: 600; color: var(--success-700); }

/* ===== Answer cell ===== */
.cell-inner { display: flex; flex-direction: column; gap: 6px; min-height: 20px; }
.cell-answer { font-size: 13px; color: var(--text-900); line-height: 1.5; }
.cell-answer.numeric { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
.cell-row-flags { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }

.cite-chip {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 11px; font-weight: 600; color: var(--color-01);
  background: var(--bg-active); border: 1px solid var(--border-active);
  border-radius: 999px; padding: 2px 9px;
}
.cite-chip:hover { background: var(--border-active); }

.lowconf-flag { display: inline-flex; position: relative; color: var(--warn-600); cursor: help; }
.lowconf-flag .tt {
  position: absolute; bottom: calc(100% + 6px); left: 50%; transform: translateX(-50%);
  background: var(--text-900); color: #fff; font-size: 11px; font-weight: 500;
  padding: 6px 10px; border-radius: 8px; white-space: nowrap;
  opacity: 0; pointer-events: none; transition: opacity .12s ease; z-index: 20;
}
.lowconf-flag:hover .tt, .lowconf-flag:focus .tt { opacity: 1; }

.cell-abstain { font-size: 12px; font-style: italic; color: var(--text-450); }
.cell-error { font-size: 12px; color: var(--danger-600); }
.cell-idle { font-size: 12px; color: var(--text-400); }
.cell-skip { display: inline-flex; align-items: center; gap: 4px; position: relative; color: var(--text-400); font-weight: 600; cursor: help; }
.cell-skip .tt {
  position: absolute; bottom: calc(100% + 6px); left: 0;
  background: var(--text-900); color: #fff; font-size: 11px; font-weight: 500;
  padding: 6px 10px; border-radius: 8px; white-space: nowrap;
  opacity: 0; pointer-events: none; transition: opacity .12s ease; z-index: 20;
}
.cell-skip:hover .tt { opacity: 1; }

/* ===== Skeleton / pending / pulsing ===== */
.skel-bar { height: 12px; border-radius: 4px; background: linear-gradient(90deg, var(--bg-chip) 25%, #e9eef5 37%, var(--bg-chip) 63%); background-size: 400% 100%; animation: skel-shimmer 1.6s ease infinite; }
.skel-bar.w-70 { width: 70%; }
.skel-bar.w-45 { width: 45%; }
@keyframes skel-shimmer { 0% { background-position: 100% 0; } 100% { background-position: 0 0; } }

.cell-pulse { display: inline-flex; align-items: center; gap: 7px; font-size: 12px; color: var(--text-500); }
.cell-pulse .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--color-02); animation: cell-pulse 1s ease-in-out infinite; }
@keyframes cell-pulse { 0%, 100% { opacity: .35; transform: scale(.85); } 50% { opacity: 1; transform: scale(1.05); } }

/* ===== Empty state ===== */
.matrix-empty {
  position: absolute; inset: 0; top: 45px;
  display: none; flex-direction: column; align-items: center; justify-content: center; gap: 10px;
  background: rgba(255, 255, 255, .82); backdrop-filter: blur(1px);
  text-align: center;
}
.matrix-empty.show { display: flex; }
.matrix-empty p { font-size: 14px; font-weight: 600; color: var(--text-700); }

/* ===== Citation evidence preview ===== */
.reference-preview { position: fixed; inset: 0; z-index: 300; display: grid; place-items: center; padding: 24px; }
.reference-preview__backdrop { position: absolute; inset: 0; background: rgba(15, 28, 58, .55); backdrop-filter: blur(2px); }
.reference-preview__dialog { position: relative; width: min(1240px, 100%); max-height: min(820px, calc(100vh - 48px)); display: flex; flex-direction: column; overflow: hidden; border-radius: 16px; background: #f4f7fb; box-shadow: 0 28px 80px rgba(15, 23, 42, .38); }
.reference-preview__head { min-height: 76px; display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 15px 24px; background: #193574; color: #fff; }.reference-preview__heading { display: flex; align-items: center; gap: 12px; min-width: 0; }.reference-preview__icon { display: grid; place-items: center; width: 38px; height: 38px; border-radius: 9px; background: rgba(255,255,255,.14); font-size: 20px; }.reference-preview__heading h2 { margin: 0; font-size: 19px; line-height: 1.25; font-weight: 700; }.reference-preview__heading p { margin: 3px 0 0; font-size: 11.5px; color: rgba(255,255,255,.8); }.reference-preview__close { width: 36px; height: 36px; border-radius: 8px; color: #fff; font-size: 28px; line-height: 1; }.reference-preview__close:hover { background: rgba(255,255,255,.14); }
.reference-preview__tools { display: flex; align-items: center; gap: 14px; min-height: 62px; padding: 12px 24px; background: #fff; border-bottom: 1px solid #dbe4f1; }.reference-preview__tabs { display: flex; align-items: center; gap: 8px; flex: 1 1 auto; min-width: 0; }.reference-preview__tab { padding: 8px 12px; border-radius: 8px; background: #193574; color: #fff; font-size: 12px; font-weight: 700; }.reference-preview__tab-note { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding: 8px 10px; border: 1px solid #dbe4f1; border-radius: 8px; color: #49617f; font-size: 12px; }.reference-preview__search { flex: 0 1 230px; }.reference-preview__search input { width: 100%; padding: 9px 12px 9px 32px; border: 1px solid #d7e0ed; border-radius: 8px; color: var(--text-900); font: inherit; font-size: 12px; background: #fff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none' stroke='%236b83a0' stroke-width='1.8'%3E%3Ccircle cx='7' cy='7' r='4.5'/%3E%3Cpath d='m10.5 10.5 3.5 3.5'/%3E%3C/svg%3E") 10px center / 16px no-repeat; }.reference-preview__search input:focus { outline: 2px solid #b5ccff; border-color: #7198df; }.reference-preview__location { flex: 0 0 auto; font-size: 12px; font-weight: 700; color: #49617f; white-space: nowrap; }
.reference-preview__body { min-height: 0; display: grid; grid-template-columns: 244px minmax(0, 1fr); overflow: auto; }.reference-preview__aside { padding: 22px 16px; background: #fff; border-right: 1px solid #dbe4f1; }.reference-preview__eyebrow { margin: 0 0 8px; color: #5b7395; font-size: 11px; font-weight: 700; letter-spacing: .025em; }.reference-preview__evidence { width: 100%; display: flex; align-items: flex-start; gap: 9px; padding: 11px; border-radius: 9px; text-align: left; background: #eaf1ff; color: #17366f; }.reference-preview__evidence-number { flex: 0 0 auto; display: grid; place-items: center; width: 22px; height: 22px; border-radius: 6px; background: #193574; color: #fff; font-size: 11px; font-weight: 800; }.reference-preview__evidence strong, .reference-preview__evidence small { display: block; overflow: hidden; text-overflow: ellipsis; }.reference-preview__evidence strong { font-size: 12px; line-height: 1.35; }.reference-preview__evidence small { margin-top: 4px; font-size: 11px; color: #5b7395; }.reference-preview__meta { margin: 22px 0 0; padding-top: 16px; border-top: 1px solid #dbe4f1; }.reference-preview__meta div { display: grid; grid-template-columns: 75px minmax(0, 1fr); gap: 8px; padding: 6px 0; font-size: 11px; }.reference-preview__meta dt { color: #72849f; }.reference-preview__meta dd { margin: 0; color: #253a58; font-weight: 600; overflow-wrap: anywhere; }
.reference-preview__content { margin: 24px; padding: 32px; border: 1px solid #dbe4f1; border-radius: 16px; background: #fff; }.reference-preview__document-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; padding-bottom: 20px; border-bottom: 1px solid #e5ebf3; }.reference-preview__document-head h3 { margin: 0; color: #1e2c43; font-size: 21px; line-height: 1.4; }.reference-preview__document-head p:last-child { margin: 6px 0 0; color: #71829b; font-size: 12px; }.reference-preview__source { flex: 0 0 auto; padding: 9px 12px; border: 1px solid #d2ddea; border-radius: 8px; color: #193574; font-size: 12px; font-weight: 700; white-space: nowrap; }.reference-preview__source:hover { background: #eef4ff; }.reference-preview__source[hidden] { display: none; }.reference-preview__quote { margin-top: 24px; padding: 23px; border: 1px solid #dbe4f1; border-radius: 10px; background: #fbfdff; }.reference-preview__quote-label { margin: 0 0 12px; color: #263b5b; font-size: 13px; font-weight: 700; }.reference-preview__quote blockquote { margin: 0; color: #34455f; font-size: 15px; line-height: 1.82; white-space: pre-wrap; }.reference-preview__quote mark { padding: 0 2px; border-radius: 2px; background: #fff0ba; color: inherit; }.reference-preview__quote-empty { margin: 12px 0 0; color: #b45309; font-size: 12px; }.reference-preview__quote-empty[hidden] { display: none; }.reference-preview__integrity { margin: 15px 0 0; color: #74859e; font-size: 11.5px; line-height: 1.55; }
.reference-preview__foot { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 14px 24px; border-top: 1px solid #dbe4f1; background: #fff; color: #61748f; font-size: 11.5px; }.reference-preview__foot code { padding: 4px 6px; border-radius: 5px; background: #eef3f9; color: #34455f; font-family: inherit; overflow-wrap: anywhere; }.reference-preview__foot > div { display: flex; gap: 8px; flex: 0 0 auto; }.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

/* Matrix reuses the source-viewer hierarchy already established in the chat surface. */
.reference-preview__head { min-height: 90px; padding: 20px 24px; }.reference-preview__icon { font-size: 0; }.reference-preview__icon img { width: 20px; height: 20px; filter: brightness(0) invert(1); }.reference-preview__close { display: grid; place-items: center; font-size: 0; }.reference-preview__close img { width: 20px; height: 20px; filter: brightness(0) invert(1); }
.reference-preview__tab, .reference-preview__tab-note { display: inline-flex; align-items: center; gap: 7px; }.reference-preview__tab img, .reference-preview__tab-note img { width: 14px; height: 14px; }.reference-preview__tab img { filter: brightness(0) invert(1); }
.reference-preview__search { display: flex; align-items: center; gap: 7px; padding: 8px 10px; border: 1px solid #d7e0ed; border-radius: 8px; }.reference-preview__search > img { width: 14px; height: 14px; }.reference-preview__search input { padding: 0; border: 0; background: none; outline: 0; }.reference-preview__pager { display: flex; align-items: center; gap: 7px; color: #667b98; font-size: 11px; white-space: nowrap; }.reference-preview__pager button { display: grid; place-items: center; width: 27px; height: 27px; border: 1px solid #dbe4f1; border-radius: 6px; background: #fff; }.reference-preview__pager button:disabled { opacity: .48; }.reference-preview__pager img { width: 12px; height: 12px; }.reference-preview__pager strong { min-width: 20px; text-align: center; color: #193574; font-size: 12px; }
.reference-preview__source { display: inline-flex; align-items: center; gap: 6px; }.reference-preview__source img { width: 14px; height: 14px; }
.reference-preview__canvas { margin-top: 20px; min-height: 160px; border: 1px solid #dbe4f1; border-radius: 10px; overflow: auto; background: #eef2f8; }.reference-preview__pdf { display: flex; justify-content: center; padding: 16px; min-height: 220px; }.reference-preview__pdf img { display: block; max-width: 100%; height: auto; background: #fff; box-shadow: 0 8px 24px rgba(20,49,112,.18); }.reference-preview__canvas-note { margin: 0; padding: 28px; color: #61748f; text-align: center; }.reference-preview__canvas-note.is-error { color: #b42318; }
.reference-preview__sheet-tabs { display: flex; gap: 6px; padding: 10px 12px; border-bottom: 1px solid #dbe4f1; background: #f8faff; }.reference-preview__sheet-tab { padding: 7px 10px; border: 1px solid #d7e0ed; border-radius: 6px; background: #fff; color: #49617f; font: inherit; font-size: 12px; font-weight: 600; }.reference-preview__sheet-tab:hover, .reference-preview__sheet-tab.is-active { border-color: #193574; background: #193574; color: #fff; }.reference-preview__table-wrap { overflow: auto; max-height: 480px; background: #fff; }.reference-preview__table { width: max-content; min-width: 100%; border-collapse: collapse; color: #2d3f5a; font-size: 12px; line-height: 1.45; }.reference-preview__table th, .reference-preview__table td { max-width: 360px; min-width: 110px; padding: 9px 11px; border-right: 1px solid #e1e8f1; border-bottom: 1px solid #e1e8f1; vertical-align: top; text-align: left; white-space: pre-wrap; overflow-wrap: anywhere; }.reference-preview__table tr:nth-child(-n+2) > :not(.reference-preview__row-number) { background: #eaf1ff; color: #193574; font-weight: 700; }.reference-preview__table .reference-preview__row-number { position: sticky; left: 0; z-index: 1; min-width: 42px; padding: 9px 8px; background: #f4f7fb; color: #6a7f9f; text-align: center; font-size: 11px; font-weight: 700; }

/* A cited PDF is the primary task: reserve the viewport for reading it, not the extracted quote. */
@media (min-width: 769px) {
  .reference-preview.is-pdf-preview .reference-preview__dialog { width: min(1440px, calc(100vw - 40px)); height: calc(100vh - 24px); max-height: none; }
  .reference-preview.is-pdf-preview .reference-preview__body { flex: 1 1 auto; overflow: hidden; }
  .reference-preview.is-pdf-preview .reference-preview__content { display: flex; flex-direction: column; min-height: 0; overflow: auto; }
  .reference-preview.is-pdf-preview .reference-preview__canvas { flex: 1 1 auto; min-height: 520px; }
  .reference-preview.is-pdf-preview .reference-preview__pdf { min-height: 100%; align-items: flex-start; }
  .reference-preview.is-pdf-preview .reference-preview__pdf img { width: auto; max-width: 100%; max-height: calc(100vh - 350px); object-fit: contain; }
  .reference-preview.is-pdf-preview .reference-preview__quote { flex: 0 0 auto; max-height: 130px; overflow: auto; }
  .reference-preview.is-pdf-preview .reference-preview__integrity { flex: 0 0 auto; }
}

/* ===== Column menu ===== */
.col-menu {
  position: fixed; z-index: 220; background: var(--bg-white); border: 1px solid var(--border);
  border-radius: 10px; box-shadow: 0 12px 32px rgba(15, 23, 42, .14); overflow: hidden; min-width: 170px;
}
.col-menu button { display: block; width: 100%; text-align: left; padding: 10px 14px; font-size: 12.5px; font-weight: 500; color: var(--text-700); }
.col-menu button:hover { background: var(--bg-chip); }
.col-menu button.danger { color: var(--danger-600); }

/* ===== Add-column / add-doc modal extras ===== */
.modal--matrix { max-width: 520px; }
.preset-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.preset-chip { font-size: 12px; font-weight: 600; color: var(--text-700); background: var(--bg-chip); border: 1px solid var(--border); border-radius: 999px; padding: 6px 12px; }
.preset-chip:hover { border-color: var(--color-01); color: var(--color-01); }
.cond-toggle-row { display: flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 600; color: var(--text-700); margin-bottom: 8px; cursor: pointer; }
.cond-toggle-row input { width: 16px; height: 16px; }
.field-hint { font-size: 11.5px; color: var(--text-500); margin-top: 6px; }
#condInput:disabled { background: var(--bg-chip); color: var(--text-400); }

.doc-pick-list { display: flex; flex-direction: column; gap: 8px; max-height: 320px; overflow-y: auto; }
.doc-search-row { display: flex; gap: 8px; margin: 12px 0 6px; }
.doc-search-row .input { flex: 1; min-width: 0; }
.doc-search-feedback { min-height: 18px; margin-bottom: 8px; font-size: 11.5px; color: var(--text-500); }
.doc-pick-row { display: flex; align-items: flex-start; gap: 10px; border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; }
.doc-pick-row.is-disabled { opacity: .6; background: var(--bg-chip); }
.doc-pick-row input { margin-top: 4px; width: 16px; height: 16px; flex: 0 0 auto; }
.doc-pick-name { font-size: 13px; font-weight: 600; color: var(--text-900); line-height: 1.4; }
.doc-pick-meta { font-size: 11px; color: var(--text-500); margin-top: 3px; }
.doc-pick-name, .doc-pick-meta, .doc-pick-source { display: block; }
.doc-pick-source { width: fit-content; margin-top: 4px; font-size: 11px; font-weight: 600; color: var(--color-01); }

/* ===== Row drawer ===== */
.row-drawer {
  position: fixed; top: 0; right: 0; height: 100vh; width: 420px; max-width: 92vw;
  background: var(--bg-white); box-shadow: -12px 0 40px rgba(15, 23, 42, .16);
  z-index: 210; transform: translateX(100%); transition: transform .22s ease;
  display: flex; flex-direction: column; overflow: hidden;
}
.row-drawer.open { transform: translateX(0); }
.rd-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; padding: 20px 20px 14px; border-bottom: 1px solid var(--border); }
.rd-doc-id { font-size: 11px; font-weight: 700; color: var(--text-450); font-variant-numeric: tabular-nums; }
.rd-head h3 { font-size: 15px; font-weight: 700; color: var(--text-900); margin-top: 4px; line-height: 1.4; }
.rd-head .close { color: var(--text-450); padding: 4px; flex: 0 0 auto; }
.rd-head .close:hover { color: var(--text-700); }
.rd-meta { display: flex; gap: 8px; padding: 14px 20px 0; }
.rd-summary { padding: 14px 20px; border-bottom: 1px solid var(--border); }
.rd-label { font-size: 11px; font-weight: 700; color: var(--text-450); letter-spacing: .3px; margin-bottom: 6px; }
.rd-summary p { font-size: 13px; line-height: 1.6; color: var(--text-700); }
.rd-qa { flex: 1; overflow-y: auto; padding: 6px 20px 24px; }
.rd-qa-item { padding: 14px 0; border-bottom: 1px solid var(--border); }
.rd-qa-item:last-child { border-bottom: none; }
.rd-qa-q { font-size: 12px; font-weight: 700; color: var(--text-600); margin-bottom: 6px; }
.rd-qa-a { font-size: 13.5px; font-weight: 600; color: var(--text-900); line-height: 1.5; }
.rd-qa-cite { display: flex; align-items: center; gap: 8px; margin-top: 8px; }

/* ===== Backdrop (shared shape with chat drawer, defined locally) ===== */
.drawer-backdrop { position: fixed; inset: 0; background: rgba(15, 23, 42, .38); z-index: 205; }

@media (max-width: 900px) {
  .matrix-page { padding: 20px 16px 48px; }
  .matrix-actions { width: 100%; }
  .matrix-actions .btn { flex: 1 1 auto; justify-content: center; }
  .matrix-table col.col-doc { width: 250px; }
  .matrix-table col.col-q { width: 220px; }
  .doc-search-row { align-items: stretch; }
  .reference-preview { padding: 12px; }.reference-preview__dialog { max-height: calc(100vh - 24px); }.reference-preview__body { grid-template-columns: 1fr; }.reference-preview__aside { padding: 16px 20px; border-right: 0; border-bottom: 1px solid #dbe4f1; }.reference-preview__meta { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 4px 14px; margin-top: 14px; }.reference-preview__meta div { display: block; }.reference-preview__meta dt { margin-bottom: 3px; }.reference-preview__content { margin: 16px; padding: 22px; }
}

@media (max-width: 520px) {
  .matrix-head h1 { font-size: 16px; }
  .matrix-actions { gap: 7px; }
  .matrix-actions .btn { flex-basis: calc(50% - 7px); }
  .doc-search-row { flex-direction: column; }
  .progress-track { min-width: 80px; }
  .reference-preview__head { min-height: 64px; padding: 12px 16px; }.reference-preview__heading h2 { font-size: 16px; }.reference-preview__tools { align-items: stretch; flex-wrap: wrap; gap: 8px; padding: 10px 16px; }.reference-preview__tabs { flex-basis: 100%; }.reference-preview__tab-note { display: none; }.reference-preview__search { flex: 1; }.reference-preview__pager { align-self: center; }.reference-preview__content { margin: 10px; padding: 16px; }.reference-preview__document-head { display: block; }.reference-preview__document-head h3 { font-size: 17px; }.reference-preview__source { display: inline-flex; margin-top: 12px; }.reference-preview__quote { padding: 16px; }.reference-preview__quote blockquote { font-size: 13.5px; }.reference-preview__foot { align-items: flex-start; flex-direction: column; padding: 12px 16px; }.reference-preview__foot > div { width: 100%; }.reference-preview__foot .btn { flex: 1; justify-content: center; }
}
