/* PDFbat AI chat view (shared by /ai.html and the editor AI panel) */
.cx { position: relative; display: flex; flex-direction: column; min-height: 0; height: 100%; background: var(--surface); }
.cx-scroll { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; scrollbar-gutter: stable; }
.cx-thread { max-width: 768px; margin: 0 auto; padding: 28px 20px 24px; display: flex; flex-direction: column; gap: 22px; min-height: 100%; }
.cx.drop::after { content: 'Drop the file to attach it'; position: absolute; inset: 10px; display: grid; place-items: center; border: 2px dashed var(--accent); border-radius: 18px; background: color-mix(in srgb, var(--accent-soft) 85%, transparent); color: var(--accent-text); font-weight: 700; font-size: 17px; z-index: 20; pointer-events: none; }
.cx-loading { margin: auto; }

/* Empty state */
.cx-empty { margin: auto 0; display: grid; gap: 22px; padding: 4vh 0 8px; }
.cx-hello { text-align: center; display: grid; justify-items: center; gap: 8px; }
.cx-hello h1 { margin: 0; font-size: clamp(24px, 3.2vw, 32px); letter-spacing: -.02em; font-weight: 650; }
.cx-hello p { margin: 0; color: var(--muted); max-width: 540px; line-height: 1.5; }
.cx-spark { width: 44px; height: 44px; border-radius: 14px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent-text); margin-bottom: 4px; }
.cx-spark .i { width: 22px; height: 22px; }
.cx-suggest { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.cx-chip { border: 1px solid var(--border); background: var(--surface); border-radius: 999px; padding: 8px 14px; font: inherit; font-size: 13.5px; color: var(--text-2); cursor: pointer; min-height: 36px; line-height: 1.3; text-align: left; }
.cx-chip:hover { border-color: var(--border-strong); background: var(--surface-2); color: var(--text); }
.cx-cards { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.cx-card { display: grid; grid-template-columns: auto 1fr; grid-template-rows: auto auto; column-gap: 10px; row-gap: 2px; align-items: center; text-align: left; padding: 12px 14px; border: 1px solid var(--border); border-radius: 14px; background: var(--surface); font: inherit; color: var(--text); cursor: pointer; transition: border-color .12s, background .12s; }
.cx-card:hover { border-color: var(--border-strong); background: var(--surface-2); }
.cx-card-ic { grid-row: 1 / 3; width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent-text); }
.cx-card b { font-size: 14px; font-weight: 600; }
.cx-card > span:last-child { font-size: 12.5px; color: var(--muted); line-height: 1.35; }

/* Messages */
.cx-msg { display: flex; gap: 14px; min-width: 0; }
.cx-msg.user { justify-content: flex-end; }
.cx-bubble { max-width: min(80%, 620px); background: var(--surface-2); border: 1px solid var(--border); border-radius: 20px; padding: 10px 16px; line-height: 1.55; overflow-wrap: anywhere; }
.cx-utext { white-space: pre-wrap; }
.cx-tag { display: inline-flex; align-items: center; gap: 5px; font-size: 11.5px; font-weight: 700; color: var(--accent-text); text-transform: uppercase; letter-spacing: .04em; margin-bottom: 2px; }
.cx-tag .i { width: 13px; height: 13px; }
.cx-avatar { flex: none; width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; background: var(--accent); color: var(--on-accent); margin-top: 1px; }
.cx-avatar .i { width: 15px; height: 15px; }
.cx-main { flex: 1; min-width: 0; }
.cx-body { line-height: 1.65; overflow-wrap: anywhere; color: var(--text); font-size: 15.5px; }
.cx-msg.note { justify-content: center; }
.cx-notecard { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-2); background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px; padding: 6px 14px; max-width: 100%; }
.cx-notecard span { overflow: hidden; text-overflow: ellipsis; }
.cx-thinking { display: inline-flex; align-items: center; gap: 10px; color: var(--muted); font-size: 14.5px; padding-top: 3px; }
.cx-dots { display: inline-flex; gap: 4px; }
.cx-dots i { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); opacity: .3; animation: cx-dot 1.2s infinite ease-in-out; }
.cx-dots i:nth-child(2) { animation-delay: .15s; } .cx-dots i:nth-child(3) { animation-delay: .3s; }
@keyframes cx-dot { 0%, 80%, 100% { opacity: .25; transform: none; } 40% { opacity: 1; transform: translateY(-3px); } }
.cx-caret { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: var(--text); margin-left: 4px; vertical-align: 1px; animation: cx-pulse 1s infinite; }
@keyframes cx-pulse { 50% { opacity: .2; } }
.cx-error { display: flex; gap: 8px; align-items: flex-start; color: var(--danger); background: var(--danger-soft); border-radius: 10px; padding: 9px 12px; font-size: 14px; margin-top: 6px; }
.cx-error .i { margin-top: 3px; }
.cx-stopped { font-size: 12.5px; color: var(--muted); margin-top: 4px; }
.cx-sources { margin-top: 10px; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; font-size: 12.5px; color: var(--muted); }
.cx-actions { display: flex; gap: 2px; margin: 6px 0 0 -6px; opacity: .0; transition: opacity .15s; }
.cx-msg:hover .cx-actions, .cx-msg:last-child .cx-actions, .cx-actions.show, .cx-actions:focus-within { opacity: 1; }
@media (hover: none) { .cx-actions { opacity: 1; } }
.cx-act { display: inline-flex; align-items: center; gap: 6px; height: 30px; min-width: 30px; justify-content: center; padding: 0 7px; border: 0; background: none; border-radius: 8px; color: var(--muted); cursor: pointer; font: inherit; font-size: 13px; font-weight: 600; }
.cx-act:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }

/* Markdown */
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md p { margin: 0 0 12px; }
.md h2, .md h3, .md h4 { margin: 18px 0 8px; font-size: 16.5px; line-height: 1.35; font-weight: 650; }
.md h2 { font-size: 18px; }
.md ul, .md ol { margin: 6px 0 12px; padding-left: 22px; }
.md li { margin: 4px 0; }
.md li::marker { color: var(--muted); }
.md code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .88em; background: var(--surface-2); border: 1px solid var(--border); padding: 1px 5px; border-radius: 5px; }
.md pre { background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; overflow-x: auto; margin: 10px 0; }
.md pre code { border: 0; padding: 0; background: none; }
.md blockquote { margin: 8px 0; padding: 2px 0 2px 14px; border-left: 3px solid var(--border-strong); color: var(--text-2); }
.md hr { border: 0; border-top: 1px solid var(--border); margin: 16px 0; }
.md a { color: var(--accent-text); }
.md-table { overflow-x: auto; margin: 10px 0; border: 1px solid var(--border); border-radius: 10px; }
.md-table table { border-collapse: collapse; width: 100%; font-size: 14px; }
.md-table th, .md-table td { padding: 8px 10px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
.md-table th { background: var(--surface-2); font-weight: 600; }
.md-table tr:last-child td { border-bottom: 0; }
.cite { display: inline-flex; align-items: center; font-size: 11.5px; font-weight: 650; line-height: 1; padding: 3px 7px; border-radius: 999px; background: var(--accent-soft); color: var(--accent-text); vertical-align: 1px; white-space: nowrap; margin: 0 1px; }

/* Results */
.cx-result-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.cx-result-title { display: inline-flex; align-items: center; gap: 8px; font-weight: 650; }
.cx-result-btns { display: flex; gap: 6px; }
.btn.sm { height: 32px; padding: 0 11px; font-size: 13px; gap: 6px; }
.cx-tablewrap { overflow-x: auto; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); }
.cx-kv, .cx-grid { width: 100%; border-collapse: collapse; font-size: 14px; }
.cx-kv th, .cx-kv td, .cx-grid th, .cx-grid td { text-align: left; padding: 8px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
.cx-kv tr:last-child > *, .cx-grid tr:last-child > * { border-bottom: 0; }
.cx-kv th { width: 38%; color: var(--muted); font-weight: 500; }
.cx-grid th { background: var(--surface-2); font-weight: 600; white-space: nowrap; }
.cx-subtable { margin-top: 14px; }
.cx-subtable h4 { margin: 0 0 6px; font-size: 13.5px; }
.cx-review { display: grid; gap: 14px; }
.cx-risks { display: grid; gap: 8px; }
.cx-risks h4 { margin: 0; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.cx-risk { border: 1px solid var(--border); border-left: 4px solid var(--border-strong); border-radius: 12px; padding: 11px 14px; background: var(--surface); }
.cx-risk.high { border-left-color: var(--danger); }
.cx-risk.medium { border-left-color: #e8a317; }
.cx-risk.low { border-left-color: var(--success); }
.cx-risk-head { display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap; }
.cx-risk p { margin: 6px 0 0; font-size: 14.5px; line-height: 1.55; color: var(--text-2); }
.cx-sev { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--text-2); }
.cx-risk.high .cx-sev { background: var(--danger-soft); color: var(--danger); }
.cx-risk.medium .cx-sev { background: var(--warning-soft); color: var(--warning); }
.cx-risk.low .cx-sev { background: var(--success-soft); color: var(--success); }
.cx-suggestion b { color: var(--text); }
.cx-facts { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 8px; }
.cx-facts > div { border: 1px solid var(--border); border-radius: 10px; padding: 9px 12px; display: grid; gap: 2px; font-size: 14px; }
.cx-facts span { font-size: 12px; color: var(--muted); }
.cx-rv { border: 1px solid var(--border); border-radius: 12px; padding: 0 14px; }
.cx-rv summary { cursor: pointer; padding: 10px 0; font-weight: 600; display: flex; align-items: center; gap: 8px; list-style: none; }
.cx-rv summary::-webkit-details-marker { display: none; }
.cx-rv summary::after { content: ''; margin-left: auto; width: 16px; height: 16px; background: currentColor; -webkit-mask: url(/vendor/icons/chevron-down.svg) center / contain no-repeat; mask: url(/vendor/icons/chevron-down.svg) center / contain no-repeat; opacity: .6; transition: transform .15s; }
.cx-rv[open] summary::after { transform: rotate(180deg); }
.cx-rv ul { margin: 0 0 12px; padding-left: 20px; line-height: 1.6; }
.cx-count { font-size: 11.5px; padding: 1px 7px; border-radius: 999px; background: var(--surface-2); color: var(--muted); font-weight: 600; }
.cx-disclaimer { font-size: 12.5px; color: var(--muted); margin: 0; }
.cx-file { border: 1px solid var(--border); border-radius: 14px; padding: 14px; background: var(--surface); display: grid; gap: 12px; max-width: 520px; box-shadow: var(--shadow-sm); }
.cx-file-top { display: flex; gap: 12px; align-items: center; min-width: 0; }
.cx-file-ic { flex: none; width: 42px; height: 42px; border-radius: 10px; display: grid; place-items: center; background: var(--accent); color: var(--on-accent); }
.cx-file-text { display: grid; min-width: 0; }
.cx-file-text b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cx-file-text small { color: var(--muted); font-size: 12.5px; }
.cx-file-btns { display: flex; gap: 8px; flex-wrap: wrap; }
.cx-file-tags { display: flex; gap: 6px; flex-wrap: wrap; }
.cx-tagchip { font-size: 12px; padding: 3px 9px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border); color: var(--text-2); }
.cx-file-note { margin: 0; font-size: 13px; color: var(--muted); }

/* Composer */
.cx-bottom { flex: none; padding: 0 16px max(10px, env(safe-area-inset-bottom)); background: var(--surface); }
.cx-bottom-inner { max-width: 768px; margin: 0 auto; position: relative; }
.cx-composer { border: 1px solid var(--border-strong); border-radius: 26px; background: var(--surface); box-shadow: 0 2px 6px rgba(16, 24, 40, .06), 0 10px 28px -12px rgba(16, 24, 40, .16); padding: 10px 10px 8px 12px; transition: border-color .12s, box-shadow .12s; }
.cx-composer:focus-within { border-color: var(--text-2); }
.cx-composer.over { border-color: var(--accent); box-shadow: 0 0 0 3px var(--ring); }
.cx-input { display: block; width: 100%; border: 0 !important; box-shadow: none !important; background: transparent; resize: none; min-height: 28px; max-height: 220px; padding: 6px 6px 4px; font: inherit; font-size: 16px; line-height: 1.5; color: var(--text); outline: none; }
.cx-row { display: flex; align-items: center; gap: 6px; padding-top: 4px; }
.cx-grow { flex: 1; }
.cx-round, .cx-send { flex: none; width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; cursor: pointer; padding: 0; }
.cx-round { border: 1px solid var(--border-strong); background: var(--surface); color: var(--text-2); box-shadow: var(--shadow-sm); }
.cx-round:hover { background: var(--surface-2); color: var(--text); }
.cx-pill { display: inline-flex; align-items: center; gap: 6px; height: 36px; padding: 0 12px; border-radius: 999px; border: 1px solid transparent; background: none; color: var(--text-2); font: inherit; font-size: 13.5px; font-weight: 600; cursor: pointer; }
.cx-pill:hover { background: var(--surface-2); color: var(--text); }
.cx-send { border: 1px solid var(--accent); background: var(--accent); color: var(--on-accent); box-shadow: 0 1px 0 rgba(0, 0, 0, .12), inset 0 -2px 0 rgba(0, 0, 0, .12); }
.cx-send:hover:not(:disabled) { background: var(--accent-hover); }
.cx-send:disabled { background: var(--surface-3); border-color: var(--surface-3); color: var(--muted); box-shadow: none; cursor: default; }
.cx-send.stop { background: var(--text); border-color: var(--text); color: var(--surface); }
.cx-send.stop .i { width: 14px; height: 14px; background: currentColor; }
.cx-note { text-align: center; font-size: 12px; color: var(--muted); margin: 8px 0 0; }
.cx-tobottom { position: absolute; left: 50%; top: -48px; transform: translate(-50%, 6px); width: 36px; height: 36px; border-radius: 50%; border: 1px solid var(--border-strong); background: var(--surface); color: var(--text-2); display: grid; place-items: center; cursor: pointer; box-shadow: var(--shadow); opacity: 0; pointer-events: none; transition: opacity .15s, transform .15s; z-index: 3; }
.cx-tobottom.show { opacity: 1; pointer-events: auto; transform: translate(-50%, 0); }
.cx.is-empty .cx-tobottom { display: none; }

/* Attached document chip */
.cx-chips { display: flex; gap: 8px; flex-wrap: wrap; padding: 0 0 8px; }
.cx-chips[hidden] { display: none; }
.cx-doc { display: inline-flex; align-items: center; gap: 10px; max-width: min(100%, 340px); border: 1px solid var(--border); border-radius: 14px; padding: 7px 8px 7px 7px; background: var(--surface-2); }
.cx-doc-ic { flex: none; width: 34px; height: 34px; border-radius: 9px; display: grid; place-items: center; background: var(--accent); color: var(--on-accent); }
.cx-doc.busy .cx-doc-ic { background: var(--surface); }
.cx-doc-text { display: grid; min-width: 0; line-height: 1.3; }
.cx-doc-text b { font-size: 13.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cx-doc-text small { font-size: 12px; color: var(--muted); }
.cx-doc-x { flex: none; width: 28px; height: 28px; border-radius: 8px; border: 0; background: none; color: var(--muted); cursor: pointer; display: grid; place-items: center; }
.cx-doc-x:hover { background: var(--surface-3); color: var(--text); }

/* Slash commands */
.cx-slash { position: absolute; left: 0; right: 0; bottom: calc(100% + 8px); background: var(--surface); border: 1px solid var(--border); border-radius: 16px; box-shadow: var(--shadow-lg); padding: 6px; z-index: 10; display: grid; max-height: 320px; overflow-y: auto; }
.cx-slash[hidden] { display: none; }
.cx-slash-item { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border: 0; background: none; border-radius: 10px; text-align: left; font: inherit; font-size: 14px; color: var(--text-2); cursor: pointer; min-width: 0; }
.cx-slash-item b { color: var(--text); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13.5px; }
.cx-slash-item span { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cx-slash-item.on, .cx-slash-item:hover { background: var(--surface-2); }

/* Popover menus */
.cx-menu { position: fixed; z-index: 200; width: 280px; max-width: calc(100vw - 16px); background: var(--surface); border: 1px solid var(--border); border-radius: 16px; box-shadow: var(--shadow-lg); padding: 6px; display: grid; gap: 2px; }
.cx-mi { display: flex; gap: 12px; align-items: center; padding: 9px 10px; border: 0; background: none; border-radius: 10px; text-align: left; font: inherit; color: var(--text); cursor: pointer; }
.cx-mi:hover, .cx-mi:focus-visible { background: var(--surface-2); outline: none; }
.cx-mi > span { display: grid; min-width: 0; }
.cx-mi b { font-size: 14px; font-weight: 600; }
.cx-mi small { font-size: 12px; color: var(--muted); }
.cx-mi > .i { color: var(--text-2); }
.cx-mi-lang { display: grid; gap: 4px; padding: 8px 10px 6px; border-top: 1px solid var(--border); margin-top: 4px; font-size: 12px; color: var(--muted); }
.cx-mi-lang select { height: 34px; }

/* Upgrade card (Free plan) */
.cx-upgrade { display: flex; align-items: center; gap: 14px; border: 1px solid var(--border-strong); border-radius: 22px; padding: 14px 14px 14px 16px; background: var(--surface); box-shadow: 0 10px 28px -12px rgba(16, 24, 40, .18); margin-bottom: 8px; flex-wrap: wrap; }
.cx-upgrade > div { flex: 1 1 220px; display: grid; gap: 2px; min-width: 0; }
.cx-upgrade > div span { color: var(--muted); font-size: 13.5px; line-height: 1.45; }
.cx-upgrade-ic { flex: none; width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent-text); }

.spinner.sm { width: 14px; height: 14px; border-width: 2px; }

/* Compact (editor panel) */
.cx.compact .cx-thread { padding: 16px 14px 14px; gap: 16px; }
.cx.compact .cx-body { font-size: 14.5px; line-height: 1.6; }
.cx.compact .cx-msg { gap: 10px; }
.cx.compact .cx-avatar { width: 24px; height: 24px; }
.cx.compact .cx-avatar .i { width: 13px; height: 13px; }
.cx.compact .cx-bubble { max-width: 90%; padding: 8px 13px; border-radius: 16px; font-size: 14.5px; }
.cx.compact .cx-empty { padding: 8px 0 0; gap: 16px; margin: 0; }
.cx.compact .cx-hello { text-align: left; justify-items: start; }
.cx.compact .cx-hello h1 { font-size: 19px; }
.cx.compact .cx-hello p { font-size: 13.5px; }
.cx.compact .cx-suggest { justify-content: flex-start; }
.cx.compact .cx-cards { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; }
.cx.compact .cx-card { padding: 8px 10px; border-radius: 12px; grid-template-rows: auto; column-gap: 8px; }
.cx.compact .cx-card-ic { width: 28px; height: 28px; border-radius: 8px; grid-row: auto; }
.cx.compact .cx-card b { font-size: 13px; }
.cx.compact .cx-card > span:last-child { display: none; }
.cx.compact .cx-bottom { padding: 0 10px max(8px, env(safe-area-inset-bottom)); }
.cx.compact .cx-composer { border-radius: 20px; padding: 8px 8px 6px 10px; }
.cx.compact .cx-input { font-size: 15px; }
.cx.compact .cx-note { font-size: 11px; margin-top: 6px; }
.cx.compact .cx-facts { grid-template-columns: minmax(0, 1fr); }
.cx.compact .cx-upgrade { border-radius: 16px; }

@media (max-width: 760px) {
  .cx-thread { padding: 18px 14px 18px; gap: 18px; }
  .cx-cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .cx-card { grid-template-rows: auto; padding: 9px 10px; column-gap: 8px; border-radius: 12px; }
  .cx-card-ic { grid-row: auto; width: 28px; height: 28px; border-radius: 8px; }
  .cx-card b { font-size: 13.5px; }
  .cx-card > span:last-child { display: none; }
  .cx-hello h1 { font-size: 25px; }
  .cx-hello p { font-size: 14.5px; }
  .cx-spark { width: 38px; height: 38px; }
  .cx-chip { font-size: 13px; padding: 7px 12px; }
  .cx-avatar { display: none; }
  .cx-msg { gap: 0; }
  .cx-bubble { max-width: 88%; }
  .cx-bottom { padding: 0 10px max(8px, env(safe-area-inset-bottom)); }
  .cx-pill > span:not(.i) { display: none; }
  .cx-pill { width: 36px; padding: 0; justify-content: center; }
  .cx-empty { padding-top: 2vh; gap: 18px; }
  .cx-body { font-size: 15.5px; }
  .cx-actions { opacity: 1; }
}
.cx.compact .cx-doc { padding: 5px 8px 5px 5px; border-radius: 12px; gap: 8px; }
.cx.compact .cx-doc-ic { width: 28px; height: 28px; border-radius: 8px; }
.cx.compact .cx-doc-text b { font-size: 13px; }
.cx.compact .cx-doc-text small { font-size: 11.5px; }
.cx.compact .cx-chips { padding-bottom: 4px; }
