/* TDC AI widget - theme-agnostic, mobile-first. Inherits publication fonts. */

/* The browser's native [hidden] rule is user-agent-origin CSS, so any
   author rule below that also sets `display` on the same element (e.g.
   .tdc-ai-loading, .tdc-ai-askrow) wins at equal specificity regardless of
   source order - toggling the `hidden` property in JS then has no visual
   effect. This makes [hidden] always win, permanently, for every element
   in this plugin - fixes the "Thinking..." spinner and the Ask row staying
   visible after JS sets element.hidden = true. */
[hidden] { display: none !important; }

.tdc-ai { margin: 1rem 0; font-family: inherit; }

.tdc-ai-toolbar { display: flex; flex-wrap: wrap; gap: .5rem; }
.tdc-ai-btn {
  padding: .5rem .9rem; border: 1px solid #d0d4dc; border-radius: 999px;
  background: #fff; cursor: pointer; font-size: .875rem; line-height: 1;
}
.tdc-ai-btn:hover { background: #f4f6f9; }
.tdc-ai-btn-primary { background: #111827; color: #fff; border-color: #111827; }
.tdc-ai-btn-primary:hover { background: #1f2937; }
.tdc-ai-iconbtn { background: none; border: 0; cursor: pointer; font-size: 1rem; padding: .25rem; }
.tdc-ai-chip { padding: .35rem .75rem; border: 1px solid #d0d4dc; border-radius: 999px; background: #f9fafb; font-size: .8rem; cursor: pointer; }

.tdc-ai-drawer {
  margin-top: .75rem; border: 1px solid #e2e5ea; border-radius: 12px;
  padding: 1rem; background: #fafbfc; box-shadow: 0 2px 8px rgba(0,0,0,.04);
}
.tdc-ai-drawer-head { display: flex; align-items: center; gap: .5rem; margin-bottom: .5rem; }
.tdc-ai-drawer-title { font-weight: 600; margin-inline-end: auto; }

.tdc-ai-askrow, .tdc-ai-searchbar { display: flex; gap: .5rem; margin: .5rem 0; }
.tdc-ai-input { flex: 1; padding: .55rem .75rem; border: 1px solid #d0d4dc; border-radius: 8px; font-size: .9rem; min-width: 0; }

.tdc-ai-loading { display: flex; align-items: center; gap: .5rem; color: #556; font-size: .875rem; padding: .5rem 0; }
.tdc-ai-spinner { width: 14px; height: 14px; border: 2px solid #cbd2dc; border-top-color: #111827; border-radius: 50%; animation: tdcspin .8s linear infinite; }
@keyframes tdcspin { to { transform: rotate(360deg); } }

.tdc-ai-error { color: #b42318; background: #fef3f2; border: 1px solid #fecdca; border-radius: 8px; padding: .5rem .75rem; font-size: .875rem; }
.tdc-ai-panel-body p { margin: .35rem 0; }
.tdc-ai-sources { margin-top: .5rem; display: flex; flex-direction: column; gap: .25rem; }
.tdc-ai-source { font-size: .8rem; color: #445; }
.tdc-ai-empty { color: #778; font-size: .875rem; padding: .5rem 0; }

.tdc-ai-related, .tdc-ai-assets, .tdc-ai-results { display: grid; gap: .6rem; grid-template-columns: 1fr; margin-top: .75rem; }
.tdc-ai-card { display: block; border: 1px solid #e2e5ea; border-radius: 10px; padding: .75rem .9rem; background: #fff; text-decoration: none; color: inherit; }
.tdc-ai-card:hover { border-color: #b9c1cd; }
.tdc-ai-card-title { font-weight: 600; font-size: .9rem; }
.tdc-ai-card-kind { font-size: .7rem; text-transform: uppercase; letter-spacing: .05em; color: #889; margin-top: .2rem; }

/* PDF / asset layout */
.tdc-ai-asset-layout { display: grid; gap: 1rem; grid-template-columns: 1fr; }
.tdc-ai-viewer iframe { width: 100%; min-height: 420px; border: 1px solid #e2e5ea; border-radius: 10px; }
.tdc-ai-sidepanel { border: 1px solid #e2e5ea; border-radius: 12px; padding: 1rem; background: #fafbfc; }

/* Tablet / desktop */
@media (min-width: 768px) {
  .tdc-ai-related, .tdc-ai-assets, .tdc-ai-results { grid-template-columns: repeat(3, 1fr); }
  .tdc-ai-asset-layout { grid-template-columns: 2fr 1fr; }
  .tdc-ai-viewer iframe { min-height: 640px; }
}

/* Formatted answers in the article panel (tdc-ai-format.js) */
.tdc-ai-panel-body .tdc-ai-fmt-p,
.tdc-ai-panel-body .tdc-ai-fmt-text { margin: .35rem 0; line-height: 1.55; }
.tdc-ai-panel-body .tdc-ai-fmt-item { display: grid; grid-template-columns: 24px 1fr; gap: 10px; margin: .6rem 0; }
.tdc-ai-panel-body .tdc-ai-fmt-num {
  width: 24px; height: 24px; border-radius: 50%;
  background: #fde2e2; color: #c62828; font-size: 12px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
}
.tdc-ai-panel-body .tdc-ai-fmt-title { margin: 2px 0 2px; font-weight: 700; line-height: 1.4; }
.tdc-ai-panel-body .tdc-ai-fmt-item .tdc-ai-fmt-text { margin: 0; color: #4b5563; font-size: .95em; }
.tdc-ai-panel-body .tdc-ai-fmt-bullet { margin: .35rem 0; padding-left: 14px; text-indent: -14px; line-height: 1.55; }
.tdc-ai-panel-body .tdc-ai-fmt-cite { color: #6b7280; font-size: .9em; white-space: nowrap; }
