/* =====================================================================
   chat-polish.css  —  Chat UI polish + bug fixes (loaded LAST)
   ---------------------------------------------------------------------
   Scope: the dashboard chat view (#chatView) and its composer (#composer).
   Loads after every other stylesheet so it wins the cascade for the chat
   without editing the fragile 36k-line dashboard-new.css monolith.
   Keeps the Matrixe identity (purple #8b5cf6 / magenta #cb11ab, glass,
   rounded cards) and refines it: tighter rhythm, consistent buttons,
   modern shadows, subtle motion. To fully revert: remove the <link> to
   this file from dashboard.html. Created 2026-06-23.

   Sections:
     1. Bug fixes (table overflow, code wrapping, contrast, focus, safe-area)
     2. Message bubbles & typography refresh
     3. Code / preformatted blocks
     4. Composer refinement (brand-consistent send button, focus rings)
     5. Empty / hero state (action cards & pills)
     6. Micro-interactions, scrollbars, reduced-motion
   ===================================================================== */

/* =====================================================================
   1. BUG FIXES
   ===================================================================== */

/* 1a. Wide markdown tables: the wrapper JS injects (.table-scroll) was only
   styled under the mobile (max-width:900px) query, so wide tables overflowed
   the bubble on desktop. Give it horizontal scrolling everywhere. */
html[data-page="dashboard"] #chatView .bubble .table-scroll,
html[data-page="dashboard"] #chatView .message-content .table-scroll {
  display: block;
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 14px 0;
  border-radius: 12px;
  overscroll-behavior-x: contain;
}
html[data-page="dashboard"] #chatView .bubble .table-scroll > table {
  width: auto;
  min-width: 100%;
  margin: 0;
}

/* 1b. Long inline code / URLs used to overflow the bubble: .bubble code was
   defined 7× with no wrapping. Allow it to break. */
html[data-page="dashboard"] #chatView .bubble code {
  word-break: break-word;
  overflow-wrap: anywhere;
}
/* …but never break inside a real code block (those scroll horizontally). */
html[data-page="dashboard"] #chatView .bubble pre code {
  word-break: normal;
  overflow-wrap: normal;
}
html[data-page="dashboard"] #chatView .bubble pre {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* 1c. Composer icon buttons had #9ca3af (gray-400) on light backgrounds —
   below WCAG AA. Darken for readable contrast. */
[data-theme="light"] #composer.composer-v2 .c-attach,
[data-theme="light"] #composer.composer-v2 .c-model,
[data-theme="light"] #chatView .btn-attach-simple {
  color: #6b7280 !important; /* gray-500, ≥4.5:1 on white */
}
[data-theme="light"] #composer.composer-v2 .c-attach:hover,
[data-theme="light"] #composer.composer-v2 .c-model:hover {
  color: #4b5563 !important;
}

/* 1d. Keyboard focus was invisible on the icon buttons. Add a clear brand ring. */
html[data-page="dashboard"] #composer .c-btn:focus-visible,
html[data-page="dashboard"] #chatView .btn-attach-simple:focus-visible,
html[data-page="dashboard"] #chatView .input-submit-btn-grey:focus-visible,
html[data-page="dashboard"] #chatView .model-toggle-btn:focus-visible {
  outline: 2px solid var(--primary, #8b5cf6) !important;
  outline-offset: 2px !important;
  border-radius: 12px;
}
html[data-page="dashboard"] #composer.composer-v2 .c-send:focus-visible {
  outline: 2px solid #ffffff !important;
  outline-offset: 2px !important;
  box-shadow: 0 0 0 4px rgba(124, 58, 237, 0.45) !important;
}

/* 1e. Notched phones: keep the last message clear of the home indicator. */
@media (max-width: 900px) {
  html[data-page="dashboard"] #chatView {
    padding-bottom: calc(140px + env(safe-area-inset-bottom, 0px)) !important;
  }
}

/* =====================================================================
   2. MESSAGE BUBBLES & TYPOGRAPHY (refine, keep brand)
   ===================================================================== */

/* Comfortable, consistent rhythm between messages. */
html[data-page="dashboard"] #chatView .msg {
  margin-bottom: 18px;
}
html[data-page="dashboard"] #chatView .msg:last-child {
  margin-bottom: 6px;
}

/* Readable measure for assistant answers on wide screens. */
@media (min-width: 901px) {
  html[data-page="dashboard"] #chatView .msg.assistant .bubble {
    max-width: 760px !important;
  }
}

/* Slightly softer, more even bubble hover (was inconsistent across rules). */
html[data-page="dashboard"] #chatView .bubble {
  transition: border-color 0.18s ease, box-shadow 0.18s ease, transform 0.18s ease !important;
}

/* Headings inside answers: tighter, clearer hierarchy. */
html[data-page="dashboard"] #chatView .bubble h1,
html[data-page="dashboard"] #chatView .bubble h2,
html[data-page="dashboard"] #chatView .bubble h3 {
  line-height: 1.3 !important;
  font-weight: 650 !important;
  letter-spacing: -0.01em !important;
  margin: 16px 0 8px !important;
}
html[data-page="dashboard"] #chatView .bubble h1 { font-size: 1.34em !important; }
html[data-page="dashboard"] #chatView .bubble h2 { font-size: 1.2em !important; }
html[data-page="dashboard"] #chatView .bubble h3 { font-size: 1.07em !important; }
html[data-page="dashboard"] #chatView .bubble > *:first-child { margin-top: 0 !important; }

/* Links pick up the brand accent. */
html[data-page="dashboard"] #chatView .msg.assistant .bubble a {
  color: var(--primary-dark, #7c3aed);
  text-underline-offset: 2px;
}
html[data-page="dashboard"][data-theme="dark"] #chatView .msg.assistant .bubble a {
  color: var(--primary-light, #a78bfa);
}

/* =====================================================================
   3. CODE / PRE BLOCKS
   ===================================================================== */

html[data-page="dashboard"] #chatView .bubble pre {
  border-radius: 12px !important;
  padding: 14px 16px !important;
  margin: 12px 0 !important;
  font-size: 13px !important;
  line-height: 1.55 !important;
}
html[data-page="dashboard"] #chatView .bubble code {
  font-size: 0.88em !important;
  padding: 2px 6px !important;
  border-radius: 6px !important;
}
[data-theme="light"] html[data-page="dashboard"] #chatView .bubble code {
  background: rgba(124, 58, 237, 0.08) !important;
  color: #6d28d9 !important;
}

/* =====================================================================
   4. COMPOSER REFINEMENT
   ===================================================================== */

/* Unify the send button to the brand purple gradient on EVERY breakpoint.
   (Mobile CSS flattened it to a dark #1f2937 circle, losing the identity.) */
html[data-page="dashboard"] #composer.composer-v2 .c-send {
  background: linear-gradient(135deg, #a855f7 0%, #7c3aed 100%) !important;
  color: #ffffff !important;
  box-shadow: 0 2px 10px rgba(124, 58, 237, 0.28) !important;
  transition: transform 0.15s ease, box-shadow 0.18s ease, filter 0.18s ease !important;
}
html[data-page="dashboard"] #composer.composer-v2 .c-send:hover {
  background: linear-gradient(135deg, #b366f9 0%, #8b46ee 100%) !important;
  box-shadow: 0 5px 16px rgba(124, 58, 237, 0.38) !important;
  transform: scale(1.06) !important;
}
html[data-page="dashboard"] #composer.composer-v2 .c-send:active {
  transform: scale(0.94) !important;
}
html[data-page="dashboard"] #composer.composer-v2 .c-send svg {
  stroke: #ffffff !important;
}

/* A touch more lift on the input card when focused (within brand). */
html[data-page="dashboard"] #chatView .hero-input-card:focus-within {
  border-color: rgba(139, 92, 246, 0.45) !important;
  box-shadow: 0 8px 30px -8px rgba(124, 58, 237, 0.22) !important;
}

/* Brand-tinted copy button hover. */
html[data-page="dashboard"] #chatView .bubble .copy-btn-unified:hover {
  border-color: rgba(124, 58, 237, 0.35) !important;
  color: var(--primary-dark, #7c3aed) !important;
  background: rgba(124, 58, 237, 0.06) !important;
}

/* =====================================================================
   5. EMPTY / HERO STATE — action cards & pills
   ===================================================================== */

/* Modernise the Tilda-era offset shadow into a soft, centred one and add a
   gentle hover lift — keeps the white rounded-pill identity. */
html[data-page="dashboard"] #chatView .action-card {
  box-shadow: 0 4px 16px rgba(17, 24, 39, 0.08) !important;
  border: 1px solid rgba(17, 24, 39, 0.05) !important;
  transition: transform 0.18s ease, box-shadow 0.2s ease, color 0.2s ease, border-color 0.2s ease !important;
}
html[data-page="dashboard"] #chatView .action-card:hover {
  transform: translateY(-2px) !important;
  box-shadow: 0 10px 26px -8px rgba(124, 58, 237, 0.22) !important;
  border-color: rgba(124, 58, 237, 0.18) !important;
}
html[data-page="dashboard"][data-theme="dark"] #chatView .action-card {
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.35) !important;
  border-color: rgba(255, 255, 255, 0.06) !important;
}

/* Action pills: consistent hover lift (kept subtle, reduced-motion aware). */
html[data-page="dashboard"] #chatView .action-pill {
  transition: transform 0.16s ease, box-shadow 0.18s ease, background 0.18s ease !important;
}

/* =====================================================================
   6. MICRO-INTERACTIONS / SCROLLBARS
   ===================================================================== */

/* Gentle entrance for messages. */
@keyframes chatMsgIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}
html[data-page="dashboard"] #chatView .msg {
  animation: chatMsgIn 0.22s ease-out both;
}

/* Smooth programmatic scrolling of the message list. */
html[data-page="dashboard"] #chatView #messages,
html[data-page="dashboard"] #chatView .messages,
html[data-page="dashboard"] #chatView .chat-scroll {
  scroll-behavior: smooth;
}

/* Thin, unobtrusive, brand-tinted scrollbars inside the chat. */
html[data-page="dashboard"] #chatView *::-webkit-scrollbar {
  width: 9px;
  height: 9px;
}
html[data-page="dashboard"] #chatView *::-webkit-scrollbar-thumb {
  background: rgba(124, 58, 237, 0.28);
  border-radius: 10px;
}
html[data-page="dashboard"] #chatView *::-webkit-scrollbar-thumb:hover {
  background: rgba(124, 58, 237, 0.45);
}
html[data-page="dashboard"] #chatView *::-webkit-scrollbar-track {
  background: transparent;
}

/* Respect users who prefer less motion: kill the lift/animation, keep state. */
@media (prefers-reduced-motion: reduce) {
  html[data-page="dashboard"] #chatView .msg { animation: none !important; }
  html[data-page="dashboard"] #chatView .action-card:hover,
  html[data-page="dashboard"] #composer.composer-v2 .c-send:hover { transform: none !important; }
  html[data-page="dashboard"] #chatView #messages,
  html[data-page="dashboard"] #chatView .messages,
  html[data-page="dashboard"] #chatView .chat-scroll { scroll-behavior: auto; }
}

/* =====================================================================
   7. ASSISTANT FAMILY SWITCH — Стандартный / Профи (premium segmented)
   + harmonised speed toggle, so the whole model-picker reads as one cluster.
   Provider behind each family (Gemini / GPT) is never shown to the user.
   ===================================================================== */
html[data-page="dashboard"] .family-switch {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 3px;
  border-radius: 999px;
  background: rgba(124, 58, 237, 0.06);
  border: 1px solid rgba(124, 58, 237, 0.12);
  box-shadow: inset 0 1px 2px rgba(17, 24, 39, 0.05);
  vertical-align: middle;
}
html[data-page="dashboard"] .family-opt {
  -webkit-appearance: none;
  appearance: none;
  border: 0;
  background: transparent;
  cursor: pointer;
  font-weight: 600;
  font-size: 12.5px;
  letter-spacing: 0.1px;
  line-height: 1;
  color: #6b7280;
  padding: 7px 15px;
  border-radius: 999px;
  white-space: nowrap;
  transition: color .2s cubic-bezier(.4,0,.2,1), background .2s cubic-bezier(.4,0,.2,1),
              box-shadow .2s ease, transform .12s ease;
}
html[data-page="dashboard"] .family-opt:hover { color: #4b5563; }
html[data-page="dashboard"] .family-opt:active { transform: scale(.96); }
html[data-page="dashboard"] .family-opt.is-active {
  color: #ffffff;
  background: linear-gradient(135deg, #a855f7 0%, #7c3aed 100%);
  box-shadow: 0 3px 10px -1px rgba(124, 58, 237, 0.40), 0 1px 2px rgba(124, 58, 237, 0.25);
}
html[data-page="dashboard"] .family-opt:focus-visible {
  outline: 2px solid var(--primary, #8b5cf6);
  outline-offset: 2px;
}
/* Compact variant for the (tighter) composer row */
html[data-page="dashboard"] .family-switch--compact { padding: 2px; gap: 2px; }
html[data-page="dashboard"] .family-switch--compact .family-opt { padding: 6px 12px; font-size: 12px; }

html[data-page="dashboard"][data-theme="dark"] .family-switch {
  background: rgba(255, 255, 255, 0.04);
  border-color: rgba(255, 255, 255, 0.09);
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.22);
}
html[data-page="dashboard"][data-theme="dark"] .family-opt { color: #9ca3af; }
html[data-page="dashboard"][data-theme="dark"] .family-opt:hover { color: #e5e7eb; }
html[data-page="dashboard"][data-theme="dark"] .family-opt.is-active { color: #ffffff; }

/* Speed toggle (Быстрый/Вдумчивый) -> matching pill so the cluster is cohesive */
html[data-page="dashboard"] #composer.composer-v2 .c-model,
html[data-page="dashboard"] #chatView .model-toggle-btn {
  border-radius: 999px !important;
  padding: 7px 13px !important;
  gap: 6px !important;
  font-weight: 600 !important;
  font-size: 12.5px !important;
  width: auto !important;
  background: rgba(124, 58, 237, 0.06) !important;
  border: 1px solid rgba(124, 58, 237, 0.12) !important;
  color: #6b7280 !important;
  transition: background .18s ease, color .18s ease, border-color .18s ease !important;
}
html[data-page="dashboard"] #composer.composer-v2 .c-model:hover,
html[data-page="dashboard"] #chatView .model-toggle-btn:hover {
  background: rgba(124, 58, 237, 0.12) !important;
  color: #4b5563 !important;
}
html[data-page="dashboard"] #composer.composer-v2 .c-model .model-name,
html[data-page="dashboard"] #chatView .model-toggle-btn .model-name { font-weight: 600 !important; }
html[data-page="dashboard"][data-theme="dark"] #composer.composer-v2 .c-model,
html[data-page="dashboard"][data-theme="dark"] #chatView .model-toggle-btn {
  background: rgba(255, 255, 255, 0.04) !important;
  border-color: rgba(255, 255, 255, 0.09) !important;
  color: #9ca3af !important;
}

@media (prefers-reduced-motion: reduce) {
  html[data-page="dashboard"] .family-opt { transition: none !important; }
  html[data-page="dashboard"] .family-opt:active { transform: none !important; }
}

/* =====================================================================
   7b. MODE EXPLAINER — ⓘ button + popover ("чем отличаются режимы")
   ===================================================================== */
html[data-page="dashboard"] .mode-info { position: relative; display: inline-flex; align-items: center; }
html[data-page="dashboard"] .mode-info-btn {
  -webkit-appearance: none; appearance: none; border: 0; cursor: pointer; padding: 0;
  width: 26px; height: 26px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  background: transparent; color: #9ca3af;
  transition: color .15s ease, background .15s ease;
}
html[data-page="dashboard"] .mode-info-btn:hover { color: var(--primary, #7c3aed); background: rgba(124, 58, 237, .08); }
html[data-page="dashboard"] .mode-info-btn:focus-visible { outline: 2px solid var(--primary, #8b5cf6); outline-offset: 2px; }

html[data-page="dashboard"] .mode-info-pop {
  position: absolute; bottom: calc(100% + 11px); left: 50%;
  transform: translateX(-50%) translateY(6px);
  width: 312px; max-width: 80vw;
  background: #ffffff; color: #1f2430; text-align: left;
  border: 1px solid rgba(17, 24, 39, .08); border-radius: 14px;
  box-shadow: 0 18px 44px -14px rgba(17, 24, 39, .32), 0 2px 8px rgba(17, 24, 39, .10);
  padding: 14px 16px; z-index: 1200;
  opacity: 0; visibility: hidden; pointer-events: none;
  transition: opacity .16s ease, transform .16s ease, visibility .16s;
}
html[data-page="dashboard"] .mode-info.open .mode-info-pop {
  opacity: 1; visibility: visible; pointer-events: auto;
  transform: translateX(-50%) translateY(0);
}
html[data-page="dashboard"] .mode-info-pop::after {
  content: ""; position: absolute; top: 100%; left: 50%; transform: translateX(-50%);
  border: 7px solid transparent; border-top-color: #ffffff;
}
html[data-page="dashboard"] .mip-group + .mip-group {
  margin-top: 12px; padding-top: 12px; border-top: 1px solid rgba(17, 24, 39, .07);
}
html[data-page="dashboard"] .mip-title {
  font-size: 11px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase;
  color: #8a8fa3; margin-bottom: 6px;
}
html[data-page="dashboard"] .mip-row { font-size: 12.5px; line-height: 1.5; color: #4b5563; margin: 3px 0; }
html[data-page="dashboard"] .mip-row b { color: #1f2430; font-weight: 650; }

html[data-page="dashboard"][data-theme="dark"] .mode-info-pop {
  background: #15151f; color: #e5e7eb; border-color: rgba(255, 255, 255, .10);
  box-shadow: 0 18px 44px -14px rgba(0, 0, 0, .62);
}
html[data-page="dashboard"][data-theme="dark"] .mode-info-pop::after { border-top-color: #15151f; }
html[data-page="dashboard"][data-theme="dark"] .mip-row { color: #b9bfce; }
html[data-page="dashboard"][data-theme="dark"] .mip-row b { color: #f3f4f6; }
html[data-page="dashboard"][data-theme="dark"] .mode-info-btn:hover { color: #c4b5fd; background: rgba(255, 255, 255, .06); }

/* =====================================================================
   8. "THINKING" / LOADING INDICATOR — premium
   Gradient wave dots + shimmering status text + soft breathing bubble.
   ===================================================================== */
html[data-page="dashboard"] #chatView .thinking-indicator { gap: 9px; min-width: 0; }

/* Dots — brand gradient, soft glow, smooth upward wave (vs the old pop-in) */
html[data-page="dashboard"] #chatView .thinking-dots { gap: 6px; height: auto; margin-bottom: 0; }
html[data-page="dashboard"] #chatView .thinking-dot {
  width: 9px; height: 9px;
  background: linear-gradient(135deg, #a855f7 0%, #cb11ab 100%) !important;
  background-color: transparent !important;
  box-shadow: 0 2px 7px rgba(168, 85, 247, 0.40);
  animation: chatThinkWave 1.15s ease-in-out infinite both !important;
}
html[data-page="dashboard"] #chatView .thinking-dot:nth-child(1) { animation-delay: -0.24s !important; }
html[data-page="dashboard"] #chatView .thinking-dot:nth-child(2) { animation-delay: -0.12s !important; }
html[data-page="dashboard"] #chatView .thinking-dot:nth-child(3) { animation-delay: 0s !important; }
@keyframes chatThinkWave {
  0%, 65%, 100% { transform: translateY(0); opacity: .5; }
  32%          { transform: translateY(-5px); opacity: 1; }
}

/* Status text — shimmering sweep across the label */
html[data-page="dashboard"] #chatView .thinking-text {
  font-size: 13.5px !important;
  font-weight: 600 !important;
  letter-spacing: .1px;
  background: linear-gradient(90deg, #8a90a0 0%, #8a90a0 30%, #7c3aed 50%, #8a90a0 70%, #8a90a0 100%);
  background-size: 220% 100%;
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent;
  animation: chatTextSweep 2.4s linear infinite;
}
html[data-page="dashboard"] #chatView .thinking-text .thinking-ellipsis { -webkit-text-fill-color: #8a90a0; }
@keyframes chatTextSweep { 0% { background-position: 120% 0; } 100% { background-position: -120% 0; } }
html[data-page="dashboard"][data-theme="dark"] #chatView .thinking-text {
  background: linear-gradient(90deg, #868c9b 0%, #868c9b 30%, #c4b5fd 50%, #868c9b 70%, #868c9b 100%);
  background-size: 220% 100%;
  -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent;
}
html[data-page="dashboard"][data-theme="dark"] #chatView .thinking-text .thinking-ellipsis { -webkit-text-fill-color: #868c9b; }

/* Secondary status line ("Выполняю инструменты…" / time estimate) */
html[data-page="dashboard"] #chatView .thinking-time {
  font-size: 11.5px; opacity: .95; color: #9499a8; height: auto;
}
html[data-page="dashboard"][data-theme="dark"] #chatView .thinking-time { color: #868c9b; }

/* Loading bubble — gentle brand breathing (own !important so it wins) */
html[data-page="dashboard"] #chatView .msg[data-loading="true"] .bubble {
  border-color: rgba(168, 85, 247, 0.28) !important;
  box-shadow: 0 4px 18px -6px rgba(168, 85, 247, 0.22) !important;
  animation: chatLoadBreathe 2.6s ease-in-out infinite;
}
@keyframes chatLoadBreathe {
  0%, 100% { box-shadow: 0 2px 10px -4px rgba(168, 85, 247, 0.16); }
  50%      { box-shadow: 0 6px 22px -6px rgba(168, 85, 247, 0.30); }
}

@media (prefers-reduced-motion: reduce) {
  html[data-page="dashboard"] #chatView .thinking-text { animation: none !important; }
  html[data-page="dashboard"] #chatView .msg[data-loading="true"] .bubble { animation: none !important; }
}

/* =====================================================================
   9. UNREAD DOT — a chat received a reply while you were in another chat
   ===================================================================== */
html[data-page="dashboard"] .chat-item-title .chat-bg-dot {
  display: inline-block;
  width: 8px; height: 8px;
  margin-left: 7px;
  border-radius: 50%;
  background: linear-gradient(135deg, #a855f7, #cb11ab);
  box-shadow: 0 0 0 3px rgba(168, 85, 247, 0.16);
  vertical-align: middle;
  animation: chatBgDotPulse 1.6s ease-in-out infinite;
}
@keyframes chatBgDotPulse { 0%, 100% { opacity: 1; } 50% { opacity: .45; } }
@media (prefers-reduced-motion: reduce) {
  html[data-page="dashboard"] .chat-item-title .chat-bg-dot { animation: none !important; }
}

/* =====================================================================
   PRODUCT TABLES — prettier layout + photo hover preview & lightbox
   (added 2026-06-24). Scoped to product tables (JS adds .thumbnails-added).
   ===================================================================== */

/* --- table shell --- */
html[data-page="dashboard"] #chatView .bubble table.thumbnails-added,
html[data-page="dashboard"] #chatView .message-content table.thumbnails-added {
  border-collapse: separate !important;
  border-spacing: 0 !important;
  width: 100%;
  font-size: 13.5px;
  background: var(--surface, #fff);
  border: 1px solid var(--border, #ececf1);
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 2px 10px rgba(17, 12, 40, 0.05);
}

/* --- header --- */
html[data-page="dashboard"] #chatView .bubble table.thumbnails-added thead th {
  background: linear-gradient(180deg, rgba(139, 92, 246, 0.09), rgba(139, 92, 246, 0.03)) !important;
  color: var(--text-muted, #6b7280) !important;
  font-weight: 700 !important;
  font-size: 11px !important;
  letter-spacing: 0.045em;
  text-transform: uppercase;
  padding: 13px 14px !important;
  border: none !important;
  border-bottom: 1px solid var(--border, #ececf1) !important;
  white-space: nowrap;
  text-align: right;
}
html[data-page="dashboard"] #chatView .bubble table.thumbnails-added thead th:nth-child(-n+2) {
  text-align: left;
}

/* --- body cells --- */
html[data-page="dashboard"] #chatView .bubble table.thumbnails-added tbody td {
  padding: 11px 14px !important;
  border: none !important;
  border-bottom: 1px solid rgba(0, 0, 0, 0.045) !important;
  vertical-align: middle !important;
  text-align: right;
  font-variant-numeric: tabular-nums;
  color: var(--text, #1f2330);
}
html[data-page="dashboard"] #chatView .bubble table.thumbnails-added tbody td:nth-child(-n+2) {
  text-align: left;
}
html[data-page="dashboard"] #chatView .bubble table.thumbnails-added tbody tr:last-child td {
  border-bottom: none !important;
}
/* article column (2nd, after the photo) emphasised */
html[data-page="dashboard"] #chatView .bubble table.thumbnails-added tbody td:nth-child(2) {
  font-weight: 600;
  color: var(--text, #111827);
  letter-spacing: 0.01em;
}
/* row hover */
html[data-page="dashboard"] #chatView .bubble table.thumbnails-added tbody tr {
  transition: background 0.15s ease;
}
html[data-page="dashboard"] #chatView .bubble table.thumbnails-added tbody tr:hover {
  background: rgba(139, 92, 246, 0.05);
}

/* --- photo cell + thumbnail --- */
html[data-page="dashboard"] #chatView .product-thumb-header {
  width: 86px !important;
  min-width: 86px !important;
}
html[data-page="dashboard"] #chatView .product-thumb-cell {
  width: 86px !important;
  min-width: 86px !important;
  padding: 8px 10px !important;
}
html[data-page="dashboard"] #chatView .product-thumb {
  width: 58px !important;
  height: 77px !important;
  object-fit: cover;
  border-radius: 11px !important;
  border: 1px solid var(--border, #ececf1) !important;
  background: #f4f4f7;
  box-shadow: 0 1px 5px rgba(17, 12, 40, 0.10);
  cursor: zoom-in;
  transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease;
}
html[data-page="dashboard"] #chatView .product-thumb:hover {
  transform: translateY(-1px) scale(1.05) !important;
  width: 58px !important;
  height: 77px !important;
  border-color: rgba(139, 92, 246, 0.55) !important;
  box-shadow: 0 8px 22px rgba(139, 92, 246, 0.30) !important;
  filter: none !important;
}

/* --- floating hover preview (fixed, escapes .table-scroll clipping) --- */
.product-hover-preview {
  position: fixed;
  z-index: 10050;
  width: 260px;
  padding: 10px;
  background: #fff;
  border: 1px solid rgba(0, 0, 0, 0.06);
  border-radius: 16px;
  box-shadow: 0 18px 50px rgba(17, 12, 40, 0.28);
  pointer-events: none;
  animation: wbPreviewIn 0.14s ease;
}
.product-hover-preview img {
  display: block;
  width: 100%;
  height: 300px;
  object-fit: contain;
  border-radius: 10px;
  background: #f4f4f7;
}
.product-hover-preview .php-cap {
  margin-top: 8px;
  text-align: center;
  font-size: 12px;
  font-weight: 600;
  color: #6b7280;
}
@keyframes wbPreviewIn {
  from { opacity: 0; transform: translateY(4px) scale(0.98); }
  to { opacity: 1; transform: none; }
}
[data-theme="dark"] .product-hover-preview {
  background: #1c1c24;
  border-color: rgba(255, 255, 255, 0.08);
}
[data-theme="dark"] .product-hover-preview img { background: #26262f; }
[data-theme="dark"] .product-hover-preview .php-cap { color: #a8a8b3; }

/* --- richer lightbox --- */
.product-lightbox { backdrop-filter: blur(6px); }
.product-lightbox .plb-figure {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  max-width: 92vw;
  animation: wbLbIn 0.2s ease;
}
.product-lightbox .plb-figure img {
  max-width: 88vw;
  max-height: 82vh;
  object-fit: contain;
  border-radius: 14px;
  background: #fff;
  box-shadow: 0 14px 50px rgba(0, 0, 0, 0.5);
}
.product-lightbox .plb-cap {
  display: flex;
  align-items: center;
  gap: 18px;
  color: #fff;
  font-size: 14px;
  font-weight: 600;
}
.product-lightbox .plb-cap a {
  color: #c79bff;
  text-decoration: none;
  font-weight: 600;
}
.product-lightbox .plb-cap a:hover { text-decoration: underline; }
.product-lightbox .plb-close {
  position: absolute;
  top: -16px;
  right: -16px;
  width: 38px;
  height: 38px;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  background: rgba(255, 255, 255, 0.95);
  color: #111;
  font-size: 24px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
  transition: transform 0.15s ease, background 0.15s ease;
}
.product-lightbox .plb-close:hover { background: #fff; transform: scale(1.06); }
@keyframes wbLbIn {
  from { opacity: 0; transform: scale(0.96); }
  to { opacity: 1; transform: none; }
}

/* =====================================================================
   GENERIC CHAT TABLES — modern look for ordinary markdown tables
   (e.g. «Данные»: ПОКАЗАТЕЛЬ / ЗНАЧЕНИЕ / ОЦЕНКА). Added 2026-06-24.
   Scoped with :not(.thumbnails-added) so product tables stay untouched.
   ===================================================================== */
html[data-page="dashboard"] #chatView .table-scroll > table:not(.thumbnails-added) {
  border-collapse: separate !important;
  border-spacing: 0 !important;
  width: 100%;
  font-size: 13.5px;
  background: var(--surface, #fff);
  border: 1px solid var(--border, #ececf1);
  border-radius: 14px;
  overflow: hidden;
  box-shadow: 0 2px 10px rgba(17, 12, 40, 0.05);
}

/* header */
html[data-page="dashboard"] #chatView .table-scroll > table:not(.thumbnails-added) thead th {
  background: linear-gradient(180deg, rgba(139, 92, 246, 0.09), rgba(139, 92, 246, 0.03)) !important;
  color: var(--text-muted, #6b7280) !important;
  font-weight: 700 !important;
  font-size: 11px !important;
  letter-spacing: 0.045em !important;
  text-transform: uppercase !important;
  text-align: left !important;
  padding: 12px 16px !important;
  border: none !important;
  border-bottom: 1px solid var(--border, #ececf1) !important;
  white-space: nowrap;
}

/* body cells */
html[data-page="dashboard"] #chatView .table-scroll > table:not(.thumbnails-added) tbody td {
  padding: 11px 16px !important;
  text-align: left !important;
  border: none !important;
  border-bottom: 1px solid rgba(0, 0, 0, 0.05) !important;
  vertical-align: middle !important;
  color: var(--text, #1f2330) !important;
  background: transparent !important;
  font-variant-numeric: tabular-nums;
}
html[data-page="dashboard"] #chatView .table-scroll > table:not(.thumbnails-added) tbody tr:last-child td {
  border-bottom: none !important;
}
/* first column emphasised */
html[data-page="dashboard"] #chatView .table-scroll > table:not(.thumbnails-added) tbody td:first-child {
  font-weight: 600;
  color: var(--text, #111827);
}
/* zebra + hover */
html[data-page="dashboard"] #chatView .table-scroll > table:not(.thumbnails-added) tbody tr {
  transition: background 0.15s ease;
}
html[data-page="dashboard"] #chatView .table-scroll > table:not(.thumbnails-added) tbody tr:hover td {
  background: rgba(139, 92, 246, 0.05) !important;
}

/* dark theme */
[data-theme="dark"] html[data-page="dashboard"] #chatView .table-scroll > table:not(.thumbnails-added),
html[data-page="dashboard"][data-theme="dark"] #chatView .table-scroll > table:not(.thumbnails-added) {
  background: rgba(28, 28, 36, 0.6);
  border-color: rgba(255, 255, 255, 0.08);
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.3);
}
[data-theme="dark"] html[data-page="dashboard"] #chatView .table-scroll > table:not(.thumbnails-added) thead th,
html[data-page="dashboard"][data-theme="dark"] #chatView .table-scroll > table:not(.thumbnails-added) thead th {
  color: #a8a8b3 !important;
  border-bottom-color: rgba(255, 255, 255, 0.08) !important;
}
[data-theme="dark"] html[data-page="dashboard"] #chatView .table-scroll > table:not(.thumbnails-added) tbody td,
html[data-page="dashboard"][data-theme="dark"] #chatView .table-scroll > table:not(.thumbnails-added) tbody td {
  color: #d7d7df !important;
  border-bottom-color: rgba(255, 255, 255, 0.06) !important;
}
[data-theme="dark"] html[data-page="dashboard"] #chatView .table-scroll > table:not(.thumbnails-added) tbody td:first-child,
html[data-page="dashboard"][data-theme="dark"] #chatView .table-scroll > table:not(.thumbnails-added) tbody td:first-child {
  color: #fff;
}
