/* Chat history page only. Loaded last, unlayered, so these rules beat the
   layered legacy sheets (including @layer screens) without !important.
   Every selector is scoped to body.route-chats. Other routes are untouched.

   The per-row card border that layout-review.css forced with !important is
   removed from that shared rule. This sheet draws one outer border instead.

   Palette is the sidebar ramp. #2196F3 is the selected filter label only.
   Weights are Satoshi 400 / 500 / 700. 700 is the page title. */

html body.route-chats {
  --ch-canvas: #171818;
  --ch-page: #1A1B1B;
  --ch-card: #1F2121;
  --ch-raised: #252727;
  --ch-hover: #2B2D2D;
  --ch-border: #2F3232;
  --ch-border-strong: #3B3E3E;
  --ch-text: #ECEDEC;
  --ch-text-2: #A6ABAB;
  --ch-text-3: #7A7F7F;
  --ch-accent: #2196F3;
  background: var(--ch-page);
  overflow-x: hidden;
}

html body.route-chats #main,
html body.route-chats #main-content,
html body.route-chats .main-content {
  background: var(--ch-page);
  background-image: none;
  color: var(--ch-text);
  overflow-x: hidden;
  max-width: 100%;
  padding-top: 0;
  padding-left: 0;
  padding-right: 0;
}

html body.route-chats::before,
html body.route-chats::after,
html body.route-chats #perplexity-fade,
html body.route-chats #perplexity-fade-bottom,
html body.route-chats #mobile-topbar-veil {
  content: none;
  display: none;
  height: 0;
  background: none;
  background-image: none;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
  box-shadow: none;
  opacity: 0;
  pointer-events: none;
}

/* On this route the sidebar active row is a neutral fill, and the plan
   label is plain tertiary text. Other routes keep their own sidebar. */
html body.route-chats aside.sidebar#sidebar .sidebar-quick-item.active,
html body.route-chats aside.sidebar#sidebar .sidebar-quick-item--history,
html body.route-chats aside.sidebar#sidebar .sidebar-quick-item--history.is-open,
html body.route-chats aside.sidebar#sidebar .sidebar-quick-item--history.active,
html body.route-chats aside.sidebar#sidebar button.sidebar-quick-item#sqi-history {
  background: var(--ch-hover);
  background-image: none;
  color: var(--ch-text);
  border-color: transparent;
  box-shadow: none;
}

html body.route-chats aside.sidebar#sidebar .sidebar-quick-item--history .sqi-icon,
html body.route-chats aside.sidebar#sidebar .sidebar-quick-item--history .sqi-label,
html body.route-chats aside.sidebar#sidebar .sidebar-quick-item--history.active .sqi-icon,
html body.route-chats aside.sidebar#sidebar .sidebar-quick-item--history.active .sqi-label {
  background: transparent;
  background-image: none;
  color: var(--ch-text);
  stroke: currentColor;
  font-weight: 500;
}

html body.route-chats .footer-org-tier-badge {
  background: transparent;
  background-image: none;
  color: var(--ch-text-3);
  border: 0;
  border-radius: 0;
  box-shadow: none;
  height: auto;
  padding: 0;
  opacity: 1;
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0;
  text-transform: none;
}

html body.route-chats .chats-view {
  max-width: none;
  width: 100%;
  margin: 0;
  padding: 8px 24px 32px;
  gap: 0;
  color: var(--ch-text);
  font-family: "Satoshi", system-ui, sans-serif;
  font-size: 14px;
  font-weight: 400;
  background: transparent;
  background-image: none;
  box-shadow: none;
  min-width: 0;
  overflow-x: hidden;
}

html body.route-chats .chats-header,
html body.route-chats .chats-view > .chats-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 4px 0 16px;
  padding: 0;
  min-height: 0;
  height: auto;
  background: transparent;
  background-image: none;
  border: 0;
  border-radius: 0;
  box-shadow: none;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
}

html body.route-chats .chats-page-title {
  margin: 0;
  font-size: 20px;
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: 0;
  text-transform: none;
  color: var(--ch-text);
}

html body.route-chats .chats-new-btn {
  height: 32px;
  padding: 0 12px;
  border-radius: 6px;
  border: 1px solid var(--ch-border);
  background: var(--ch-card);
  background-image: none;
  color: var(--ch-text-2);
  font-family: "Satoshi", system-ui, sans-serif;
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0;
  text-transform: none;
  box-shadow: none;
  cursor: pointer;
}

html body.route-chats .chats-new-btn:hover {
  background: var(--ch-hover);
  background-image: none;
  border-color: var(--ch-border);
  color: var(--ch-text);
  transform: none;
}

html body.route-chats .chats-search {
  display: block;
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  height: 40px;
  margin: 0 0 12px;
  padding: 0 12px;
  border-radius: 6px;
  border: 1px solid var(--ch-border);
  background: var(--ch-raised);
  background-image: none;
  color: var(--ch-text);
  font-family: "Satoshi", system-ui, sans-serif;
  font-size: 14px;
  font-weight: 400;
  box-shadow: none;
  outline: none;
}

html body.route-chats .chats-search::placeholder {
  color: var(--ch-text-3);
  font-weight: 400;
}

html body.route-chats .chats-search:focus {
  border-color: var(--ch-border-strong);
  background: var(--ch-raised);
  background-image: none;
  box-shadow: none;
  outline: none;
}

html body.route-chats .chats-filters {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin: 0 0 12px;
  padding: 0;
  background: transparent;
  min-width: 0;
  max-width: 100%;
}

html body.route-chats .chats-chip {
  height: 32px;
  min-width: 0;
  padding: 0 12px;
  border-radius: 6px;
  border: 1px solid var(--ch-border);
  background: transparent;
  background-image: none;
  color: var(--ch-text-2);
  font-family: "Satoshi", system-ui, sans-serif;
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0;
  text-transform: none;
  box-shadow: none;
  cursor: pointer;
}

html body.route-chats .chats-chip:hover {
  background: var(--ch-hover);
  border-color: var(--ch-border);
  color: var(--ch-text);
}

html body.route-chats .chats-chip.is-active {
  background: var(--ch-hover);
  border-color: var(--ch-border);
  color: var(--ch-accent);
}

html body.route-chats .chats-list {
  display: flex;
  flex-direction: column;
  gap: 0;
  margin: 0;
  padding: 0;
  min-width: 0;
  max-width: 100%;
  height: auto;
  max-height: none;
  overflow: hidden;
  background: var(--ch-card);
  background-image: none;
  border: 1px solid var(--ch-border);
  border-radius: 10px;
  box-shadow: none;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
}

html body.route-chats .chats-group {
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: transparent;
  border: 0;
  box-shadow: none;
}

html body.route-chats .chats-group + .chats-group {
  border-top: 1px solid var(--ch-border);
}

html body.route-chats .chats-group-label {
  margin: 0;
  padding: 12px 16px 4px;
  background: transparent;
  border: 0;
  box-shadow: none;
  font-size: 12px;
  font-weight: 500;
  line-height: 1.3;
  letter-spacing: 0;
  text-transform: none;
  color: var(--ch-text-3);
}

html body.route-chats .chats-row {
  display: flex;
  align-items: stretch;
  position: relative;
  gap: 0;
  margin: 0;
  min-height: 56px;
  min-width: 0;
  max-width: 100%;
  padding: 0;
  background: transparent;
  background-image: none;
  border: 0;
  border-radius: 0;
  box-shadow: none;
  color: var(--ch-text);
  text-decoration: none;
  transform: none;
  transition: background 120ms ease;
}

html body.route-chats .chats-row + .chats-row {
  border-top: 1px solid var(--ch-border);
}

html body.route-chats .chats-row:hover,
html body.route-chats .chats-row:focus-within,
html body.route-chats .chats-row.is-active {
  background: var(--ch-hover);
  background-image: none;
  border-color: transparent;
  border-top-color: var(--ch-border);
  box-shadow: none;
  color: var(--ch-text);
  transform: none;
}

html body.route-chats .chats-row-open {
  display: flex;
  align-items: center;
  gap: 16px;
  flex: 1 1 auto;
  min-width: 0;
  min-height: 56px;
  padding: 8px 16px;
  color: inherit;
  text-decoration: none;
}

html body.route-chats .chats-row-open:focus-visible {
  outline: 1px solid var(--ch-border-strong);
  outline-offset: -1px;
}

html body.route-chats .chats-row-main {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 2px;
}

html body.route-chats .chats-row-title {
  display: block;
  margin: 0;
  font-size: 14px;
  font-weight: 500;
  line-height: 1.25;
  letter-spacing: 0;
  color: var(--ch-text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  -webkit-line-clamp: 1;
  -webkit-box-orient: unset;
}

html body.route-chats .chats-row-preview {
  display: block;
  margin: 0;
  font-size: 13px;
  font-weight: 400;
  line-height: 1.3;
  color: var(--ch-text-2);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  -webkit-line-clamp: 1;
  -webkit-box-orient: unset;
}

html body.route-chats .chats-row-meta {
  flex: 0 0 auto;
  margin: 0;
  padding: 0;
  font-size: 12px;
  font-weight: 400;
  line-height: 1.3;
  color: var(--ch-text-3);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  text-align: right;
}

html body.route-chats .chats-row-pin {
  margin-right: 8px;
  font-size: 12px;
  font-weight: 500;
  color: var(--ch-text-3);
}

html body.route-chats .chats-row-actions {
  position: absolute;
  top: 0;
  right: 8px;
  bottom: 0;
  display: flex;
  align-items: center;
  gap: 4px;
  opacity: 0;
  pointer-events: none;
  background: var(--ch-hover);
}

html body.route-chats .chats-row:hover .chats-row-actions,
html body.route-chats .chats-row:focus-within .chats-row-actions {
  opacity: 1;
  pointer-events: auto;
}

html body.route-chats .chats-row-action {
  height: 28px;
  padding: 0 8px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  background-image: none;
  color: var(--ch-text-2);
  font-family: "Satoshi", system-ui, sans-serif;
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0;
  box-shadow: none;
  cursor: pointer;
}

html body.route-chats .chats-row-action:hover,
html body.route-chats .chats-row-action:focus-visible {
  background: var(--ch-raised);
  color: var(--ch-text);
  outline: none;
}

html body.route-chats .chats-row-action--danger:hover,
html body.route-chats .chats-row-action--danger:focus-visible {
  color: var(--ch-text);
}

html body.route-chats .chats-row--skel {
  pointer-events: none;
}

html body.route-chats .chats-skel-bar {
  height: 12px;
  border-radius: 6px;
  background: var(--ch-hover);
  background-image: none;
}

html body.route-chats .chats-skel-bar--title { width: 42%; }
html body.route-chats .chats-skel-bar--preview { width: 68%; height: 10px; }
html body.route-chats .chats-skel-bar--time { width: 48px; height: 10px; }
html body.route-chats .chats-skel-label {
  width: 64px;
  height: 10px;
  margin: 14px 16px 6px;
  padding: 0;
}

html body.route-chats .chats-empty {
  margin: 0;
  padding: 28px 16px;
  text-align: left;
  background: transparent;
  background-image: none;
  border: 0;
  border-radius: 0;
  box-shadow: none;
  color: var(--ch-text-2);
  font-size: 13px;
  font-weight: 400;
}

html body.route-chats .chats-empty a {
  color: var(--ch-text);
  text-decoration: underline;
  text-underline-offset: 2px;
}

html body.route-chats .chats-more {
  display: block;
  margin: 12px 0 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--ch-text-2);
  font-family: "Satoshi", system-ui, sans-serif;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  box-shadow: none;
}

html body.route-chats .chats-more:hover {
  color: var(--ch-text);
}

@media (max-width: 820px) {
  html body.route-chats .chats-view {
    padding: calc(env(safe-area-inset-top, 0px) + 64px) 12px calc(24px + env(safe-area-inset-bottom, 0px));
  }

  html body.route-chats .chats-search {
    font-size: 16px;
    height: 44px;
  }

  html body.route-chats .chats-new-btn,
  html body.route-chats .chats-chip,
  html body.route-chats .chats-row-action {
    min-height: 44px;
    height: 44px;
  }

  html body.route-chats .chats-row,
  html body.route-chats .chats-row-open {
    min-height: 56px;
  }

  html body.route-chats .chats-row-title { font-size: 14px; }
  html body.route-chats .chats-row-preview { font-size: 13px; }
  html body.route-chats .chats-list {
    height: auto;
    max-height: none;
    overflow: hidden;
  }
}

@media (max-width: 390px) {
  html body.route-chats,
  html body.route-chats #main,
  html body.route-chats #main-content,
  html body.route-chats .chats-view,
  html body.route-chats .chats-list,
  html body.route-chats .chats-row,
  html body.route-chats .chats-row-open {
    max-width: 100%;
    overflow-x: hidden;
  }

  html body.route-chats .chats-row-open {
    gap: 8px;
    padding-left: 12px;
    padding-right: 12px;
  }
}
