/*
 * This is a manifest file that'll be compiled into application.css.
 *
 * With Propshaft, assets are served efficiently without preprocessing steps. You can still include
 * application-wide styles in this file, but keep in mind that CSS precedence will follow the standard
 * cascading order, meaning styles declared later in the document or manifest will override earlier ones,
 * depending on specificity.
 *
 * Consider organizing styles into separate files for maintainability.
 */

/* Speech mode: hide streaming text until audio plays.
   Two classes on #messages work together:
   - .speech-mode-hiding   → instant hide (no transition), applied BEFORE
     the shell arrives so CSS hides it on first paint — zero flash.
   - .speech-mode-revealing → smooth expand + fade when audio starts. The
     ease-out curve front-loads visible expansion (~100 ms for typical
     content) even though max-height overshoots.  */
#messages.speech-mode-hiding [id^="message-"]:not([data-role]) {
  overflow: hidden;
  max-height: 0;
  opacity: 0;
}

#messages.speech-mode-revealing [id^="message-"]:not([data-role]) {
  max-height: 5000px;
  opacity: 1;
  transition: opacity 0.35s ease-out, max-height 0.5s ease-out;
}

/* Citation link styles - icon-based badges */
.citation-link {
  cursor: pointer;
  text-decoration: none !important;
  transition: all 0.15s ease;
  vertical-align: baseline;
}

.citation-link:hover {
  text-decoration: none !important;
  transform: translateY(-1px);
}

.citation-link svg {
  flex-shrink: 0;
}

/* Source highlight animation */
.source-card {
  transition: all 0.3s ease;
}

.source-highlight {
  border-color: #6366f1 !important;
  background-color: #eef2ff !important;
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.2);
  animation: highlight-pulse 0.5s ease-in-out 2;
}

.dark .source-highlight {
  background-color: rgba(99, 102, 241, 0.15) !important;
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.3);
}

@keyframes highlight-pulse {
  0%, 100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.02);
  }
}

/* Pagy pagination styles */
.pagy-nav-wrapper nav.series-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.25rem;
}

.pagy-nav-wrapper nav.series-nav a,
.pagy-nav-wrapper nav.series-nav a[role="link"] {
  padding: 0.375rem 0.75rem;
  font-size: 0.875rem;
  color: #4b5563;
  border-radius: 0.5rem;
  transition: background-color 0.15s ease;
  text-decoration: none;
}

.pagy-nav-wrapper nav.series-nav a:hover {
  background-color: #f3f4f6;
}

/* Current page */
.pagy-nav-wrapper nav.series-nav a[aria-current="page"] {
  font-weight: 500;
  color: white;
  background-color: var(--color-primary-600);
  pointer-events: none;
}

/* Disabled/gap elements */
.pagy-nav-wrapper nav.series-nav a[aria-disabled="true"] {
  color: #9ca3af;
  pointer-events: none;
}

.pagy-nav-wrapper nav.series-nav a[role="separator"] {
  padding: 0.375rem 0.5rem;
}

/* Dark mode */
.dark .pagy-nav-wrapper nav.series-nav a,
.dark .pagy-nav-wrapper nav.series-nav a[role="link"] {
  color: #9ca3af;
}

.dark .pagy-nav-wrapper nav.series-nav a:hover {
  background-color: #1f2937;
}

.dark .pagy-nav-wrapper nav.series-nav a[aria-current="page"] {
  color: white;
  background-color: var(--color-primary-600);
}

.dark .pagy-nav-wrapper nav.series-nav a[aria-disabled="true"] {
  color: #4b5563;
}

/* ========================================
   Keyword highlight mirror
   ======================================== */

/* Wrapper created by JS around the textarea */
.kw-wrapper {
  position: relative;
}

/* Mirror div — sits behind the transparent textarea */
.kw-mirror {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  white-space: pre-wrap;
  word-wrap: break-word;
  color: transparent;
  z-index: 0;
}

/* Highlighted keyword spans — soft background pill */
.kw-highlight {
  color: transparent;
  border-radius: 3px;
  padding: 1px 0;
}

/* Category background colours — soft tint */
.kw-route      { background: rgba(99, 102, 241, 0.15); }
.kw-excel      { background: rgba(16, 185, 129, 0.15); }
.kw-excel-op   { background: rgba(16, 185, 129, 0.15); }
.kw-research   { background: rgba(139, 92, 246, 0.15); }
.kw-chart      { background: rgba(245, 158, 11, 0.15); }
.kw-factset    { background: rgba(14, 165, 233, 0.15); }
.kw-dynamo     { background: rgba(59, 130, 246, 0.15); }
.kw-web        { background: rgba(249, 115, 22, 0.15); }
.kw-cpec       { background: rgba(47, 97, 101, 0.15); }
.kw-abs        { background: rgba(168, 85, 247, 0.15); }
.kw-abn        { background: rgba(236, 72, 153, 0.15); }
.kw-calculator { background: rgba(20, 184, 166, 0.15); }
.kw-imagegen   { background: rgba(225, 29, 72, 0.15); }
.kw-news       { background: rgba(234, 88, 12, 0.15); }
.kw-company    { background: rgba(5, 150, 105, 0.20); border-radius: 3px; }

/* Dark mode — slightly brighter tints */
.dark .kw-route      { background: rgba(129, 140, 248, 0.20); }
.dark .kw-excel      { background: rgba(52, 211, 153, 0.20); }
.dark .kw-excel-op   { background: rgba(52, 211, 153, 0.20); }
.dark .kw-research   { background: rgba(167, 139, 250, 0.20); }
.dark .kw-chart      { background: rgba(251, 191, 36, 0.20); }
.dark .kw-factset    { background: rgba(56, 189, 248, 0.20); }
.dark .kw-dynamo     { background: rgba(96, 165, 250, 0.20); }
.dark .kw-web        { background: rgba(251, 146, 60, 0.20); }
.dark .kw-cpec       { background: rgba(94, 234, 212, 0.20); }
.dark .kw-abs        { background: rgba(192, 132, 252, 0.20); }
.dark .kw-abn        { background: rgba(244, 114, 182, 0.20); }
.dark .kw-calculator { background: rgba(45, 212, 191, 0.20); }
.dark .kw-imagegen   { background: rgba(251, 113, 133, 0.20); }
.dark .kw-news       { background: rgba(251, 146, 60, 0.20); }
.dark .kw-company    { background: rgba(52, 211, 153, 0.25); border-radius: 3px; }

/* Floating tooltip */
.kw-tooltip {
  position: fixed;
  z-index: 9999;
  max-width: 280px;
  padding: 6px 10px;
  font-size: 12px;
  line-height: 1.4;
  color: white;
  background: #1e293b;
  border-radius: 6px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s ease;
}
.kw-tooltip.visible { opacity: 1; }

/* Keyword reference popover — fixed-positioned, appended to body */
.kw-reference {
  position: fixed;
  z-index: 9999;
  width: 320px;
  max-height: 400px;
  overflow-y: auto;
  margin-top: 4px;
  padding: 12px;
  background: white;
  border: 1px solid #e5e7eb;
  border-radius: 12px;
  box-shadow: 0 10px 25px rgba(0,0,0,0.1);
  font-size: 12px;
  line-height: 1.5;
}
.dark .kw-reference {
  background: #1f2937;
  border-color: #374151;
}
.kw-reference h4 {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #9ca3af;
  margin: 8px 0 4px;
}
.kw-reference h4:first-child { margin-top: 0; }
.kw-ref-item {
  display: flex;
  align-items: baseline;
  gap: 6px;
  padding: 3px 0;
  color: #374151;
}
.dark .kw-ref-item { color: #d1d5db; }
.kw-ref-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  flex-shrink: 0;
  margin-top: 5px;
}
.kw-ref-keyword { font-weight: 500; }
.kw-ref-desc { color: #6b7280; }
.dark .kw-ref-desc { color: #9ca3af; }

/* Clickable reference items */
.kw-ref-clickable {
  cursor: pointer;
  border-radius: 4px;
  padding: 4px 6px;
  margin: 0 -6px;
  transition: background-color 0.15s;
}
.kw-ref-clickable:hover { background: #f3f4f6; }
.dark .kw-ref-clickable:hover { background: #374151; }

/* @ mention autocomplete dropdown */
.kw-at-dropdown {
  position: fixed;
  z-index: 9999;
  min-width: 240px;
  max-width: 360px;
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0,0,0,.12);
  padding: 4px;
  font-size: 13px;
}
.dark .kw-at-dropdown {
  background: #1f2937;
  border-color: #374151;
  box-shadow: 0 8px 24px rgba(0,0,0,.4);
}
.kw-at-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  border-radius: 6px;
  cursor: pointer;
  color: #374151;
}
.dark .kw-at-item { color: #d1d5db; }
.kw-at-item:hover, .kw-at-item.kw-at-active {
  background: #f3f4f6;
}
.dark .kw-at-item:hover, .dark .kw-at-item.kw-at-active {
  background: #374151;
}
.kw-at-trigger {
  font-weight: 600;
  color: #2F6165;
  white-space: nowrap;
}
.dark .kw-at-trigger { color: #5eead4; }
.kw-at-desc {
  color: #6b7280;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ========================================
   Workspace view mode toggle (cards / list)
   ======================================== */

/* Card mode: grid layout, show card-view, hide list-view */
[data-view-mode="cards"] {
  display: grid;
  grid-template-columns: repeat(1, minmax(0, 1fr));
  gap: 0.75rem;
}
@media (min-width: 640px) {
  [data-view-mode="cards"] { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (min-width: 1024px) {
  [data-view-mode="cards"] { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
[data-view-mode="cards"] .workspace-chat-item .card-view,
[data-view-mode="cards"] .workspace-content-item .card-view { display: block; }
[data-view-mode="cards"] .workspace-chat-item .list-view,
[data-view-mode="cards"] .workspace-content-item .list-view { display: none; }

/* Documents card mode: 4 columns on xl */
.workspace-docs-container[data-view-mode="cards"] {
  grid-template-columns: repeat(1, minmax(0, 1fr));
}
@media (min-width: 768px) {
  .workspace-docs-container[data-view-mode="cards"] { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (min-width: 1024px) {
  .workspace-docs-container[data-view-mode="cards"] { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (min-width: 1280px) {
  .workspace-docs-container[data-view-mode="cards"] { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}
[data-view-mode="cards"] .workspace-doc-item .card-view { display: block; }
[data-view-mode="cards"] .workspace-doc-item .list-view { display: none; }

/* List mode: stacked rows, show list-view, hide card-view */
[data-view-mode="list"] {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
[data-view-mode="list"] .workspace-chat-item .card-view,
[data-view-mode="list"] .workspace-content-item .card-view,
[data-view-mode="list"] .workspace-doc-item .card-view { display: none; }
[data-view-mode="list"] .workspace-chat-item .list-view,
[data-view-mode="list"] .workspace-content-item .list-view,
[data-view-mode="list"] .workspace-doc-item .list-view { display: flex; }

/* Library docs: default (cards) — hide list-view, show card-view */
.library-doc-item .list-view { display: none; }
.library-doc-item .card-view { display: block; }
.library-docs-container {
  display: grid;
  grid-template-columns: repeat(1, minmax(0, 1fr));
  gap: 0.75rem;
}
@media (min-width: 768px) {
  .library-docs-container { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (min-width: 1024px) {
  .library-docs-container { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (min-width: 1280px) {
  .library-docs-container { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}

/* Library docs: list mode override */
.library-docs-container[data-view-mode="list"] {
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
}
.library-docs-container[data-view-mode="list"] .library-doc-item .card-view { display: none; }
.library-docs-container[data-view-mode="list"] .library-doc-item .list-view { display: flex; }

