/* Step188-A UI layer (loaded after style.179u2.*.css) */
/* ============================================================
   Step188-A : UI refinement layer (presentation only)
   - no backend / RAG / auth / security change
   - additive rules only; no existing rule was deleted
   ============================================================ */

/* --- 1. horizontal overflow hardening (320-430px) ------------ */
.layout, .content, .ai-workspace, .hero-ask, .ai-answer-card,
.doc-dir, .bottom-grid, .panel, .messages, .message, .dynamic-list,
.doc-item, .doc-body, .vid-item, .vid-body, .dd-doc, .dd-doc-body,
.faq-rank-item, .side-account, .history-item { min-width: 0; }
.doc-title, .doc-desc, .doc-meta, .vid-title, .vid-desc,
.dd-doc-title, .dd-doc-desc, .panel-title, .rank-q, .h-title,
.side-account-email, .vd-card-title, .vd-card-summary, .vd-chapter-t,
.doc-note, .empty-note, .bubble {
  overflow-wrap: anywhere; word-break: break-word;
}
.messages, .doc-dir-panel, .dynamic-list, .qa-chips { max-width: 100%; }
.ai-workspace img, .panel img, .bubble img, video { max-width: 100%; height: auto; }
.bubble table { display: block; max-width: 100%; overflow-x: auto; }

/* --- 2. answer readability (CSS only; answer text untouched) -- */
.ai-answer-card .bubble { max-width: 74ch; letter-spacing: .01em; }
.ai-answer-card { scroll-margin-top: 72px; }
.messages .message + .message { margin-top: 10px; }

/* --- 3-4. (deferred: needs a DOM hook in the CSP-hashed inline script) --- */

/* --- 5. document vs video separation -------------------------- */
.doc-item.dyn { border-left: 3px solid #94a3b8; }
.vid-item.dyn { border-left: 3px solid var(--red, #fa8802); }
.doc-item.dyn, .vid-item.dyn { border-radius: 8px; }

/* --- 6. disabled / coming-soon, unified ----------------------- */
button[disabled], .is-disabled, [aria-disabled="true"] {
  opacity: .55; cursor: not-allowed; pointer-events: none;
}
.doc-note.doc-unavailable {
  display: inline-block; background: #f1f3f7; color: #6b7280;
  border-radius: 999px; padding: 4px 10px; font-size: 12.5px;
}

/* --- 7. empty state stays quiet ------------------------------- */
.panel-empty, .empty-note { color: var(--muted, #6b7280); font-size: 13px; }

/* --- 8. focus visibility (keyboard) --------------------------- */
a:focus-visible, button:focus-visible, input:focus-visible,
textarea:focus-visible, select:focus-visible,
[tabindex]:focus-visible {
  outline: 2px solid #1f2433; outline-offset: 2px; border-radius: 6px;
}

/* --- 9. touch targets (>=44px) -------------------------------- */
@media (max-width: 860px) {
  .qa-chip { min-height: 44px; font-size: 14px; padding: 11px 14px; }
  .ask-bar .clear-btn { min-width: 44px; min-height: 44px; }
  .doc-link, .doc-btn, .vid-link, .vd-play-btn, .vd-size-btn,
  .fb-btn, .print-btn, .panel-link, .nav-item, .guide-q-btn,
  #dd-search-btn, #dd-search-input, .dd-open, .dd-close {
    min-height: 44px;
  }
  .fb-btn, .print-btn { padding: 10px 14px; }
  .ai-actions { gap: 10px; }
}

/* --- 10. iOS safe area ---------------------------------------- */
.mobile-topbar { padding-top: env(safe-area-inset-top, 0px); }
@media (max-width: 860px) {
  .content { padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px)); }
  .sidebar { padding-bottom: calc(20px + env(safe-area-inset-bottom, 0px)); }
}

/* --- 11. legible type on small screens ------------------------ */
@media (max-width: 430px) {
  .bubble { font-size: 15px; }
  .ai-answer-card .bubble { font-size: 15.5px; line-height: 1.85; }
  .doc-title, .vid-title, .dd-doc-title { font-size: 14.5px; }
  .doc-desc, .vid-desc, .dd-doc-desc, .doc-meta { font-size: 13px; }
  .pii-note { font-size: 12.5px; }
  .hero-text h1 { line-height: 1.35; }
}

/* --- 12. reduced motion --------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
    scroll-behavior: auto !important;
  }
}

/* --- 13. HQ / video confirmation notice: stronger contrast, wording unchanged --- */
.video-answer-notice {
  background: var(--red-soft, #fff3e6);
  border-left: 4px solid var(--red, #fa8802);
  border-radius: 10px;
  padding: 10px 12px;
  color: #7a4a00;
  font-weight: 600;
  overflow-wrap: anywhere;
}
/* --- 14. AI disclaimer stays readable but secondary --- */
.ai-disclaimer { line-height: 1.6; }

/* ============================================================
   Step188-A2 : owner UI feedback polish (CSS only, additive)
   1) PC: centre the app shell and use a little more width
   2) mobile / tablet: no nested scroll inside the answer card
   3) question label: keep it in flow, wrap long questions
   No !important, no inline style, no JS, no backend change.
   ============================================================ */

/* --- 1. wide screens: centre the whole shell (sidebar + content) --- */
@media (min-width: 1500px) {
  .layout  { max-width: 1760px; margin-left: auto; margin-right: auto; }
  .content { max-width: 1512px; }
}
/* answer line length is deliberately NOT widened: .ai-answer-card .bubble
   keeps the 74ch cap from the Step188-A layer. */

/* --- 2. mobile & tablet: the answer flows, the page scrolls --- */
@media (max-width: 1024px) {
  .ai-answer-card .messages { max-height: none; overflow-y: visible; }
}

/* --- 3. question label stays in flow and wraps --- */
@media (max-width: 1024px) {
  .ai-answer-card .message.user { margin-bottom: 12px; }
  .ai-answer-card .message.user .bubble {
    max-width: 100%;
    overflow-wrap: anywhere;
    word-break: break-word;
  }
  .ai-answer-card .message.user + .message.bot { margin-top: 4px; }
}

/* ============================================================
   Step188-A3 : related documents / videos sit with the answer
   The two panels were moved in the template (IDs unchanged);
   this block only styles the new wrapper and re-balances the
   bottom grid, which now holds the FAQ ranking alone.
   ============================================================ */

.related-answer { margin: 16px 0 28px; }
.related-answer-title {
  font-size: 15.5px; font-weight: 700; color: var(--text, #1f2430);
  margin: 0 0 10px; letter-spacing: .01em; overflow-wrap: anywhere;
}
.related-answer-grid {
  display: grid; grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px; align-items: start;
}
.related-answer-grid > .panel { min-width: 0; }

/* the FAQ ranking is now the only bottom panel */
.bottom-grid { grid-template-columns: minmax(0, 1fr); }

/* nothing related yet: keep the existing guidance, but compact */
.related-answer-grid:not(:has(.has-dynamic)) { grid-template-columns: 1fr; gap: 8px; }
.related-answer-grid:not(:has(.has-dynamic)) > .panel { padding: 12px 14px; }

/* single column and tighter rhythm on tablet / mobile */
@media (max-width: 1024px) {
  .related-answer-grid { grid-template-columns: 1fr; gap: 14px; }
}
@media (max-width: 860px) {
  .related-answer { margin: 8px 0 20px; }
  .related-answer-title { font-size: 15px; margin-bottom: 8px; }
  .related-answer-grid { gap: 12px; }
}

/* ============================================================
   Step188-A4 : document navigation lives in the sidebar
   - #doc-dir is now the click-delegation scope around .layout
     (search + categories in the sidebar, results in main)
   - the JS-rendered .dd-card is restyled as a compact 44px row;
     the existing .dd-btn keeps the click, stretched over the row
   ============================================================ */

.doc-dir-scope { display: flex; flex-direction: column; flex: 1; min-height: 0; }

/* --- desktop sidebar: a little wider, scrolls on short screens --- */
@media (min-width: 861px) {
  .sidebar { width: 292px; max-height: 100vh; overflow-y: auto; overscroll-behavior: contain; }
}
@media (min-width: 1500px) {
  .content { max-width: 1468px; }   /* 1760 shell - 292 sidebar */
}

/* --- primary / guide navigation --- */
.side-nav-primary { margin-bottom: 4px; }
.side-nav-guides { margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--border, #e7e9ee); }
.side-nav-label { font-size: 11px; font-weight: 700; color: #8a919e; letter-spacing: .04em; margin: 0 0 4px 6px; }
.side-nav-guides .nav-item { padding: 8px 12px; font-size: 13px; min-height: 40px; }

/* --- document search block (Step188-A5: search input + button only) --- */
.side-docs { margin: 14px 0 0; padding-top: 12px; border-top: 1px solid var(--border, #e7e9ee); }
.side-docs-title { font-size: 13px; font-weight: 800; color: var(--text, #1f2430); margin: 0 0 10px; letter-spacing: .02em; }
.side-docs .dd-search-row {
  display: flex; flex-wrap: nowrap; align-items: stretch; gap: 8px; margin: 0 0 10px;
}
.side-docs #dd-search-input { flex: 1 1 auto; min-width: 0; }
.side-docs #dd-search-input, .side-docs #dd-search-btn {
  min-width: 0; width: 100%; min-height: 44px; font-size: 13px; box-sizing: border-box;
}
.side-docs #dd-search-btn { flex: 0 0 auto; width: auto; padding: 0 14px; white-space: nowrap; }

/* --- category rows (JS keeps rendering .dd-card; CSS makes it a row) --- */
.side-docs .doc-dir-grid { display: flex; flex-direction: column; gap: 2px; }
.side-docs .dd-card {
  position: relative; display: flex; flex-direction: row; align-items: center; gap: 8px;
  height: auto; min-height: 44px; padding: 6px 8px; margin: 0;
  border: 0; border-radius: 8px; background: transparent; box-shadow: none;
  transition: background .15s ease;
}
/* exactly one hit-testable box per row: the button. The number, the title and
   the count are display only, so they can never become the pointer target. */
.side-docs .dd-card { pointer-events: none; }
.side-docs .dd-card .dd-btn { pointer-events: auto; }
.side-docs .dd-card:hover { background: #f3f4f7; }
/* Step188-A5: the chosen category stays marked while it holds focus. A persistent
   .is-active class would require inline JS, so this is the CSS-only equivalent. */
.side-docs .dd-card:focus-within {
  background: var(--red-soft, #fff3e6);
  box-shadow: inset 3px 0 0 0 var(--red, #fa8802);
}
.side-docs .dd-card-soon:focus-within { background: transparent; box-shadow: none; }
.side-docs .dd-card:has(.dd-btn:focus-visible) { box-shadow: inset 0 0 0 2px #1f2433; }
.side-docs .dd-card-top { display: contents; }
.side-docs .dd-badge { order: 0; flex: 0 0 auto; font-size: 11px; min-width: 26px; text-align: center; padding: 2px 4px; }
.side-docs .dd-card-title {
  order: 1; flex: 1 1 auto; min-width: 0; margin: 0; min-height: 0;
  display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow: hidden;
  font-size: 13.5px; font-weight: 600; line-height: 1.3; overflow-wrap: anywhere;
}
.side-docs .dd-card-desc { display: none; }
.side-docs .dd-card-foot { display: contents; }
.side-docs .dd-count { order: 2; font-size: 11px; color: #8a919e; white-space: nowrap; }
/* Step188-A6: the real button IS the row. Until A5 the button was a 1x1px flex
   item whose ::after overlay covered the row, so the overlay and .dd-card-title
   competed for the same pixels: with a stationary cursor the hit target
   oscillated between them (~10 pointerover/pointerout per second, no DOM
   mutation, no layout shift), the cursor flickered between pointer and auto,
   and mousedown/mouseup landed on different elements -- so the browser
   dispatched click on .dd-card, which carries no data-dd-cat, and the frozen
   delegated handler ignored it. That is why the first click only focused the
   row and a second click was needed. */
.side-docs .dd-btn {
  order: 3; position: absolute; inset: 0; width: auto; height: auto;
  min-height: 0; padding: 0; margin: 0;
  border: 0; overflow: hidden; opacity: 0; font-size: 1px; line-height: 1px;
  background: transparent; color: transparent; cursor: pointer; z-index: 1;
}
.side-docs .dd-btn::after { content: none; }
/* nothing to open yet: quiet, not clickable (button is disabled by ui_enhance) */
.side-docs .dd-card-soon { opacity: .6; cursor: default; }
.side-docs .dd-card-soon:hover { background: transparent; }
.side-docs .dd-card-soon .dd-btn { display: none; }
.side-docs .dd-card-soon .dd-count { color: #b0b6c2; }

/* --- recent history / utility link --- */
.side-history { margin-top: 14px; padding-top: 10px; border-top: 1px solid var(--border, #e7e9ee); }
.side-util { margin-top: 12px; padding-top: 8px; border-top: 1px solid var(--border, #e7e9ee); }
.side-util .side-card-btn {
  display: block; width: 100%; text-align: left; background: transparent; border: 0;
  color: #4a5160; font-size: 13px; font-weight: 600; padding: 8px 10px; min-height: 44px;
  border-radius: 8px; cursor: pointer; box-shadow: none;
}
.side-util .side-card-btn:hover { background: #f3f4f7; color: var(--text, #1f2430); }

/* --- results now render in main, below the related content --- */
.doc-results { margin: 0; }
.doc-results > .doc-dir-panel { margin: 0 0 24px; }

/* --- drawer (mobile): full 44px targets, nothing wider than the drawer --- */
@media (max-width: 860px) {
  /* the base stylesheet stacks this row on mobile; the sidebar keeps it inline */
  .side-docs .dd-search-row { flex-direction: row; flex-wrap: nowrap; }
  .side-docs #dd-search-input { flex: 1 1 auto; width: auto; min-width: 0; }
  .side-docs #dd-search-btn { flex: 0 0 auto; width: auto; }
  .side-docs #dd-search-input, .side-docs #dd-search-btn { min-height: 44px; }
  .side-docs .dd-card { min-height: 46px; }
  .side-nav-guides .nav-item, .side-util .side-card-btn { min-height: 44px; }
}
