/* Chat pages (Search assistant + Operational advisor). Colours only through tokens.css. */
.ch { position: relative; display: grid; grid-template-columns: 280px minmax(0, 1fr); height: 100%; min-height: 0; }
.ch-rail { background: var(--bg); border-inline-end: 1px solid var(--line); padding: 16px 14px 14px; display: flex; flex-direction: column; min-height: 0; overflow: hidden; }
.ch-rail-h { display: flex; align-items: center; justify-content: space-between; padding: 0 6px 12px; }
.ch-rail-h h2 { font: 500 20px/1.2 var(--f-latin); font-variation-settings: "opsz" 72; }
[dir="rtl"] .ch-rail-h h2 { font-family: var(--f-kufi); }
.ch-rail-x { display: none; }
.ch-new { display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%; min-height: 46px; border: 1px dashed var(--primary); border-radius: 12px; background: transparent; color: var(--primary); font-weight: 500; transition: background var(--dur), border-style var(--dur); }
.ch-new:hover { background: var(--primary-soft); border-style: solid; }
.ch-hist { flex: 1; overflow-y: auto; margin: 6px -6px 0; padding: 0 6px; }
.ch-hist h3 { font: 500 12.5px/1 var(--f-body); color: var(--ink-2); margin: 20px 8px 8px; }
.ch-nohist { color: var(--ink-2); font-size: 13.5px; padding: 18px 8px; }
.ch-list { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: minmax(0, 1fr); gap: 2px; }
.ch-list li { min-width: 0; position: relative; display: flex; align-items: center; border-radius: 10px; transition: background var(--dur); }
.ch-list li:hover, .ch-list li:focus-within { background: var(--bg-2); }
.ch-list li.on { background: var(--surface); box-shadow: var(--sh-1); }
.ch-list li.on::before { content: ""; position: absolute; inset-inline-start: 0; top: 10px; bottom: 10px; width: 3px; border-radius: 3px; background: var(--accent); }
.ch-open { flex: 1; min-width: 0; text-align: start; border: 0; background: none; padding: 9px 10px; min-height: 48px; color: var(--ink); }
.ch-open span { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 14px; }
.ch-open small { color: var(--ink-2); font-size: 12px; }
.ch-del, .ch-x { border: 0; background: none; color: var(--ink-2); width: 38px; height: 38px; border-radius: 8px; display: grid; place-items: center; flex: none; opacity: 0; transition: opacity var(--dur), background var(--dur), color var(--dur); }
.ch-del .ico, .ch-x .ico { width: 17px; height: 17px; }
.ch-list li:hover .ch-del, .ch-list li.on .ch-del, .ch-del:focus-visible { opacity: 1; }
.ch-del:hover, .ch-x:hover { color: var(--danger); background: var(--danger-bg); }
.ch-rail-f { border-top: 1px solid var(--line); padding-top: 12px; margin-top: 8px; display: grid; gap: 8px; }
.ch-rail-f p { font-size: 12.5px; color: var(--ink-2); padding: 0 4px; }
.ch-rail-f .btn { justify-content: flex-start; }
.ch-scrim { display: none; }

.ch-main { position: relative; display: grid; grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr) auto; min-height: 0; min-width: 0; background: var(--surface); isolation: isolate; }
.ch-tabs { display: flex; align-items: flex-end; gap: 8px; padding: 12px 28px 0; border-bottom: 1px solid var(--line); background: var(--surface-2); }
.ch-tablist { display: flex; gap: 4px; min-width: 0; flex: 1; overflow-x: auto; scrollbar-width: none; }
.ch-tab { position: relative; display: flex; align-items: center; gap: 9px; border: 0; background: none; min-height: 46px; padding: 0 16px; color: var(--ink-2); font-weight: 500; border-radius: 12px 12px 0 0; white-space: nowrap; transition: color var(--dur), background var(--dur); }
.ch-tab:hover { color: var(--primary); background: var(--primary-soft); }
.ch-tab[aria-selected="true"] { color: var(--primary); background: var(--surface); }
.ch-tab[aria-selected="true"]::after { content: ""; position: absolute; inset-inline: 10px; bottom: -1px; height: 3px; border-radius: 3px 3px 0 0; background: var(--primary); }
.ch-chip { font-style: normal; font-size: 11.5px; font-weight: 500; color: var(--accent-ink); background: var(--accent-soft); border: 1px solid var(--accent-line); padding: 1px 8px; border-radius: 999px; }
.ch-hist-btn { display: none; margin-inline-start: auto; margin-bottom: 6px; }

.ch-thread { overflow-y: auto; overflow-x: hidden; padding: 28px 28px 12px; outline: none; }
.ch-thread-in { max-width: 800px; margin: 0 auto; display: flex; flex-direction: column; gap: 26px; }
.ch-pair { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.msg { min-width: 0; }
.msg.new { animation: ch-rise .4s var(--ease) both; }
.msg.user { align-self: flex-end; max-width: min(560px, 88%); }
.msg.user .bubble { background: var(--primary); color: var(--on-primary); padding: 12px 16px; border-radius: 18px 18px 4px 18px; overflow-wrap: anywhere; white-space: pre-wrap; box-shadow: var(--sh-1); }
[dir="rtl"] .msg.user .bubble { border-radius: 18px 18px 18px 4px; }
.when { display: flex; align-items: center; justify-content: flex-end; gap: 2px; font-size: 12px; color: var(--ink-2); margin-top: 2px; }
.msg.user:hover .ch-x, .msg.user:focus-within .ch-x { opacity: 1; }
.agent-head { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; font-size: 13px; color: var(--ink-2); margin-bottom: 10px; }
.agent-head b { color: var(--ink); font-weight: 500; }
.seal { width: 30px; height: 30px; display: grid; place-items: center; border-radius: 9px; background: var(--primary-soft); border: 1px solid var(--primary-soft-2); color: var(--primary); rotate: 45deg; }
.seal .ico { width: 16px; height: 16px; rotate: -45deg; }
.msg.agent { display: grid; gap: 12px; }
.msg.agent > .agent-head { margin-bottom: -2px; }
.answer { font-size: 16px; line-height: 1.75; max-width: 68ch; overflow-wrap: anywhere; }
.answer[lang="ar"] { font-size: 17px; line-height: 1.95; }
.fn { display: inline-grid; place-items: center; min-width: 22px; height: 22px; margin-inline: 3px; vertical-align: 2px; font: 600 11px/1 var(--f-mono); color: var(--accent-ink); background: var(--accent-soft); border: 1px solid var(--accent-line); border-radius: 6px; text-decoration: none; transition: background var(--dur), color var(--dur); }
.fn:hover, .fn:focus-visible { background: var(--accent-ink); color: var(--surface); }
.ch-sub { font: 500 13px/1.3 var(--f-body); color: var(--ink-2); margin-top: 6px; display: flex; align-items: center; gap: 10px; }
.ch-sub::after { content: ""; flex: 1; height: 1px; background: var(--line-soft); }
.quote:focus { outline: none; }
.ch-m8 { margin-top: 2px; }
.msg.agent .conflict { margin: 0; }
.msg.agent .msgbox { color: var(--ink); }
.ch-total { font-size: 14px; color: var(--ink-2); }
.ch-total b { font: 500 18px/1.3 var(--f-latin); color: var(--ink); }
[dir="rtl"] .ch-total b { font-family: var(--f-kufi); }
.ch-pager { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.ch-pager span { margin-inline-end: auto; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--primary-soft-2); background: var(--primary-soft); color: var(--primary); border-radius: 999px; min-height: 44px; padding: 6px 16px; font-size: 13.5px; text-align: start; line-height: 1.4; max-width: 100%; overflow-wrap: anywhere; transition: background var(--dur), border-color var(--dur), transform var(--dur); }
.chip:hover { border-color: var(--primary); background: var(--primary-soft-2); }
.chip:active { transform: translateY(1px); }
.chip.own { background: transparent; border-style: dashed; border-color: var(--line); color: var(--ink-2); }
.chip.own .ico { width: 15px; height: 15px; }
.ch-qlist { margin: 0; padding-inline-start: 22px; display: grid; gap: 8px; font-size: 15px; max-width: 68ch; }
.ch-qlist li::marker { color: var(--accent); }
.ch-foot { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; padding-top: 4px; }
.ch-fb { display: inline-flex; gap: 2px; }
.ch-fb .iconbtn { width: 38px; height: 38px; color: var(--ink-3); }
.ch-fb .iconbtn .ico { width: 18px; height: 18px; }
.ch-fb [aria-pressed="true"] { color: var(--primary); background: var(--primary-soft); }
.ch-typing { display: flex; align-items: center; gap: 12px; color: var(--ink-2); font-size: 14px; }
.dots { display: inline-flex; gap: 6px; }
.dots i { width: 7px; height: 7px; background: var(--primary); rotate: 45deg; animation: ch-pulse 1s ease-in-out infinite; }
.dots i:nth-child(2) { animation-delay: .15s; } .dots i:nth-child(3) { animation-delay: .3s; }

/* empty state */
.ch-empty { text-align: center; padding: 6vh 8px 20px; display: grid; justify-items: center; gap: 10px; color: var(--ink-2); }
.ch-empty svg { width: 96px; height: 96px; animation: ch-turn 40s linear infinite; }
.ch-empty h3 { font: 500 38px/1.35 var(--f-kufi); color: var(--primary); margin-top: 6px; }
.ch-empty p { max-width: 52ch; }
.ch-empty .ch-try { font-size: 12.5px; margin-top: 10px; color: var(--ink-3); }
.ch-empty .chips { justify-content: center; max-width: 640px; }

/* advisor ledger card */
.ledger { display: grid; grid-template-columns: minmax(0, .8fr) minmax(0, 1.2fr); border: 1px solid var(--line); border-radius: var(--r-l) var(--r-xs) var(--r-l) var(--r-l); overflow: hidden; background: var(--surface); box-shadow: var(--sh-1); }
[dir="rtl"] .ledger { border-radius: var(--r-xs) var(--r-l) var(--r-l) var(--r-l); }
.ld-big { position: relative; isolation: isolate; overflow: hidden; background: var(--chrome); color: var(--on-chrome); padding: 22px; display: flex; flex-direction: column; justify-content: space-between; gap: 16px; }
.ld-mash { position: absolute; inset: 0; z-index: -1; width: 100%; height: 100%; opacity: .16; pointer-events: none; }
.ld-big > small { color: var(--on-chrome-2); font-size: 13px; }
.ld-num { display: block; font: 500 78px/.95 var(--f-latin); font-variation-settings: "opsz" 144; letter-spacing: -.03em; overflow-wrap: anywhere; }
.ld-unit { display: block; font: 400 20px/1.3 var(--f-kufi); color: var(--chrome-accent-ink); margin-top: 6px; }
.ld-exact { display: block; font: 400 12.5px/1.4 var(--f-mono); color: var(--on-chrome-2); margin-top: 6px; }
.ld-tags { display: flex; flex-wrap: wrap; gap: 6px; }
.ld-tags span { font-size: 12px; border: 1px solid var(--chrome-accent); color: var(--chrome-accent-ink); padding: 3px 10px; border-radius: 999px; }
.ld-f { padding: 20px 22px; display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.ld-f h5 { margin: 0 0 8px; font: 500 12.5px/1.3 var(--f-body); color: var(--ink-2); display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.ld-as { font-size: 15px; padding: 10px 12px; background: var(--surface-2); border-radius: 8px; border: 1px solid var(--line-soft); overflow-wrap: anywhere; }
.ld-sub { font: 500 16px/1.6 var(--f-mono); color: var(--primary); overflow-wrap: anywhere; text-align: start; }
[dir="rtl"] .ld-sub { text-align: right; }
.ld-sub b { color: var(--accent-ink); }
.ld-mem { display: flex; gap: 8px; align-items: flex-start; font-size: 13px; color: var(--ink-2); }
.ld-mem .ico { width: 16px; height: 16px; margin-top: 2px; color: var(--accent); }
.ch-inputs { min-width: 560px; }
.ch-inputs td.n { font-family: var(--f-mono); font-weight: 500; }
.ch-ovr { display: block; font-family: var(--f-body); font-weight: 400; color: var(--accent-ink) !important; }
.ch-inputs .link { padding: 4px 0; text-align: start; }

/* upload card */
.msg.user.up { max-width: min(470px, 100%); }
.upl { background: var(--surface); border: 1px solid var(--line); border-radius: 18px 18px 4px 18px; padding: 14px 16px; box-shadow: var(--sh-1); }
[dir="rtl"] .upl { border-radius: 18px 18px 18px 4px; }
.upl-top { display: flex; gap: 12px; align-items: center; }
.upl-top > div { min-width: 0; }
.upl-top .nm { display: block; font-weight: 500; overflow-wrap: anywhere; line-height: 1.35; }
.upl-top small { display: block; color: var(--ink-2); font-size: 12.5px; }
.track { height: 6px; border-radius: 6px; background: var(--bg-2); overflow: hidden; margin: 14px 0 10px; }
.track i { display: block; height: 100%; width: calc(var(--p) * 100%); background: repeating-linear-gradient(90deg, var(--primary) 0 14px, var(--primary-hover) 14px 20px); background-size: 40px 100%; animation: ch-stripe 1s linear infinite; transition: width .4s var(--ease); }
.upl[data-state="up"] .track i { width: 100%; }
.upl[data-state="ok"] .track i { width: 100%; animation: none; }
.upl[data-state="bad"] .track i { width: 100%; animation: none; background: var(--danger); }
.who { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; margin-top: 12px; padding-top: 12px; border-top: 1px dashed var(--line); font-size: 13px; color: var(--ink-2); }
.who select { min-height: 44px; border: 1px solid var(--line); border-radius: 9px; background: var(--surface-2); padding: 0 10px; color: var(--primary); font-weight: 500; max-width: 100%; }
.who select:disabled { color: var(--ink-2); opacity: 1; }

/* composer */
.ch-comp { padding: 10px 28px 16px; background: linear-gradient(to bottom, transparent, var(--surface) 30%); }
.ch-alert { max-width: 800px; margin: 0 auto; display: none; align-items: flex-start; gap: 8px; padding: 10px 12px; border-radius: 10px; background: var(--warn-bg); color: var(--warn-ink); border: 1px solid var(--warn-line); font-size: 14px; margin-bottom: 8px; }
.ch-alert.on { display: flex; }
.ch-alert .ico { width: 18px; height: 18px; margin-top: 2px; }
.ch-comp-in { max-width: 800px; margin: 0 auto; display: flex; align-items: flex-end; gap: 6px; background: var(--surface); border: 1px solid var(--line); border-radius: 18px; padding: 7px; box-shadow: var(--sh-2); transition: border-color var(--dur), box-shadow var(--dur); }
.ch-comp-in:focus-within { border-color: var(--primary); }
.ch-comp-in .iconbtn { width: 44px; height: 44px; }
.ch-comp-in textarea { flex: 1; min-width: 0; border: 0; resize: none; background: transparent; min-height: 44px; max-height: 168px; padding: 11px 6px; line-height: 1.5; color: var(--ink); }
.ch-comp-in textarea:focus { outline: none; }
.ch-comp-in textarea::placeholder { color: var(--ink-3); }
.ch-send { width: 44px; height: 44px; border: 0; border-radius: 12px; background: var(--primary); color: var(--on-primary); display: grid; place-items: center; flex: none; transition: background var(--dur), transform var(--dur); }
.ch-send:hover:not(:disabled) { background: var(--primary-hover); }
.ch-send:active:not(:disabled) { transform: scale(.95); }
.ch-send:disabled { background: var(--bg-2); color: var(--ink-3); cursor: not-allowed; }
.ch-meta { max-width: 800px; margin: 6px auto 0; display: flex; justify-content: space-between; gap: 12px; font-size: 12px; color: var(--ink-2); padding-inline: 8px; }
.ch-meta .count { font-family: var(--f-mono); margin-inline-start: auto; }
.ch-meta .count.over { color: var(--danger); font-weight: 600; }

/* drop overlay */
.ch-drop { position: absolute; inset: 10px; z-index: 5; border: 2px dashed var(--primary); border-radius: 22px; background: color-mix(in srgb, var(--primary-soft) 98%, transparent); backdrop-filter: blur(3px); display: grid; place-items: center; text-align: center; padding: 20px; opacity: 0; pointer-events: none; transition: opacity var(--dur); }
.ch-drop.on { opacity: 1; pointer-events: auto; }
.ch-drop .d-star { width: 120px; height: 120px; transition: transform .5s var(--ease); }
.ch-drop.on .d-star { transform: rotate(22.5deg) scale(1.06); }
.ch-drop b { display: block; font: 500 24px/1.3 var(--f-kufi); color: var(--primary); margin-top: 14px; }
.ch-drop span { color: var(--ink-2); }
.ch-fb-set { border: 0; margin: 0; padding: 0; display: grid; }

@keyframes ch-rise { from { opacity: 0; transform: translateY(8px); } }
@keyframes ch-pulse { 50% { opacity: .3; } }
@keyframes ch-turn { to { transform: rotate(360deg); } }
@keyframes ch-stripe { to { background-position: 40px 0; } }

/* ---------- responsive ---------- */
@media (max-width: 1180px) {
  .ch { grid-template-columns: minmax(0, 1fr); }
  .ch-hist-btn { display: inline-grid; }
  .ch-rail-x { display: inline-grid; }
  .ch-rail { position: absolute; z-index: 30; inset-block: 0; inset-inline-start: 0; width: min(310px, 88%); box-shadow: var(--sh-2); transform: translateX(-105%); visibility: hidden; transition: transform .28s var(--ease), visibility .28s; }
  [dir="rtl"] .ch-rail { transform: translateX(105%); }
  .ch.rail-open .ch-rail { transform: none; visibility: visible; }
  .ch.rail-open .ch-scrim { display: block; position: absolute; inset: 0; z-index: 25; background: var(--scrim); }
}
@media (max-width: 900px) {
  .ch-tabs { padding: 8px 12px 0; }
  .ch-tab { padding: 0 10px; gap: 7px; min-height: 46px; }
  .ch-thread { padding: 18px 14px 8px; }
  .ch-comp { padding: 6px 10px 10px; }
  .ch-meta .hint { display: none; }
  .ledger { grid-template-columns: minmax(0, 1fr); }
  .ld-num { font-size: 60px; }
  .ch-del, .ch-x { opacity: 1; width: 44px; height: 44px; }
  .ch-fb .iconbtn { width: 44px; height: 44px; }
  .ch-empty h3 { font-size: 30px; }
  .ch-open { min-height: 50px; }
}
@media (max-width: 520px) {
  .ch-tab > .ico { display: none; }
  .ch-tab span { font-size: 14px; }
  .ch-tab { padding: 0 8px; gap: 6px; }
  .ch-chip { font-size: 10.5px; padding: 0 6px; }
  .msg.user { max-width: 92%; }
  .answer { font-size: 15.5px; }
  .ch-pager span { flex-basis: 100%; }
  .ch-pager .btn { flex: 1; }
}
@media (prefers-reduced-motion: reduce) { .ch-empty svg, .track i, .dots i { animation: none; } }

/* Evidence additions: file name under document titles and in quote sources (SRS 1.8.2.6, 1.9.1, 1.9.4) */
.ev-file { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; margin: 2px 0 4px; font: 400 12.5px/1.4 var(--f-mono); color: var(--ink-2); overflow-wrap: anywhere; }
.ev-loc { unicode-bidi: isolate; font-family: var(--f-body); background: var(--accent-soft); color: var(--accent-ink); border-radius: var(--r-xs); padding: 1px 7px; }
.src-file { font: 400 12px/1.4 var(--f-mono); color: var(--ink-2); overflow-wrap: anywhere; }

/* Spreadsheet viewer (SRS 1.9.7, 1.9.8): sheet tab, column letters, row numbers, only the quoted cells lit */
.xl { display: grid; gap: 0; }
.xl-tabs { display: flex; gap: 2px; border-bottom: 2px solid var(--sheet-line); }
.xl-tab { font: 500 13px/1 var(--f-body); padding: 8px 14px; background: var(--paper); color: var(--paper-head); border: 1px solid var(--sheet-line); border-bottom: 0; border-radius: var(--r-xs) var(--r-xs) 0 0; margin-bottom: -2px; box-shadow: inset 0 3px 0 var(--paper-head); }
.xl-grid { overflow-x: auto; }
.xl-t { font-size: 13.5px; }
.xl-t thead th, .xl-t th.rn { background: var(--sheet-head); font: 500 11.5px/1 var(--f-mono); color: var(--paper-foot); text-align: center; padding: 6px 8px; }
.xl-t th.corner { width: 36px; }
.xl-t td[data-h] { font-weight: 600; }
.xl-t tr.hit-row th.rn { color: var(--paper-ink); }
.xl-t td.hit { background: var(--sheet-hit); font-weight: 600; outline: 2px solid var(--paper-head); outline-offset: -2px; }
.xl-t td.hit mark { background: none; padding: 0; }

/* Upload status in chat is a system note, not an answer (SRS 1.7.1) */
.ch-sys { align-self: center; justify-self: center; max-width: min(560px, 100%); display: grid; gap: 10px; justify-items: center; text-align: center; padding: 10px 16px; border: 1px dashed var(--line); border-radius: var(--r-m); background: var(--surface-2); color: var(--ink-2); font-size: 14px; margin-top: 10px; }
.ch-sys p { display: flex; gap: 8px; align-items: center; }
.ch-sys .chips { justify-content: center; }

/* Inline "Write my own" inside an Output C message (SRS 1.8.3.4) */
.ch-own { display: grid; gap: 8px; margin-top: 10px; }
.ch-own textarea { width: 100%; min-height: 72px; resize: vertical; font: inherit; padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--r-s); background: var(--surface); color: var(--ink); }
.ch-own textarea:focus-visible { outline: 2px solid var(--primary); outline-offset: 1px; }
.ch-own-row { display: flex; gap: 8px; align-items: center; justify-content: flex-end; }
.ch-own-row .count.over, .ch-own .err { color: var(--danger); }
@media (max-width: 900px) { .ch-own-row .btn { min-height: 44px; } }

/* document viewer: page markers, sheet tabs as buttons */
.paper .ev-pg { font: 500 11px/1 var(--f-mono); color: var(--paper-foot); letter-spacing: .08em; text-align: center; margin: 6px 0 -4px; }
button.xl-tab { cursor: pointer; }
.xl-tab[aria-selected="false"] { background: transparent; box-shadow: none; color: var(--ink-2); }
.ld-expr { display: block; margin-top: 4px; font: 400 13px/1.5 var(--f-mono); color: var(--ink-2); overflow-wrap: anywhere; text-align: start; }
.dc-readers .pill { margin-block: 2px; }
