/* TOPCARTECH assistant — Graphite theme tokens from style.css (brand guideline v2.2). */
.tct-chat {
  --chat-edge: max(16px, env(safe-area-inset-right));
  --chat-bottom: max(16px, env(safe-area-inset-bottom));
  position: fixed;
  left: max(16px, env(safe-area-inset-left));
  right: var(--chat-edge);
  bottom: var(--chat-bottom);
  z-index: 45;
  display: grid;
  justify-items: end;
  gap: 12px;
  pointer-events: none;
  color: var(--ink);
  font-family: 'Inter', Arial, sans-serif;
}
.tct-chat[hidden] { display: none; }
.tct-chat > * { pointer-events: auto; }
.tct-chat button { cursor: pointer; font: inherit; }
.tct-chat :is(button, a, input, [tabindex]):focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.tct-chat-sr {
  position: absolute;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* Launcher */
.tct-chat-launch {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 52px;
  padding: 12px 20px 12px 16px;
  border: 1px solid var(--deep-navy);
  border-radius: var(--r-pill, 999px);
  background: var(--accent);
  color: var(--deep-navy);
  font-weight: 600;
  font-size: 15px;
  transition: background-color .2s, color .2s, transform .2s;
}
.tct-chat-launch:hover { background: var(--deep-navy); color: var(--white); transform: translateY(-2px); box-shadow: 0 10px 24px rgb(0 0 0 / .35); }
.tct-chat-launch-close, .is-open .tct-chat-launch-open { display: none; }
.is-open .tct-chat-launch-close { display: block; }

/* One-time hint */
.tct-chat-teaser[hidden] { display: none; }
.tct-chat-teaser {
  display: flex;
  align-items: flex-start;
  max-width: min(300px, 100%);
  border: 1px solid var(--control);
  border-radius: var(--r-md, 16px) var(--r-md, 16px) 4px var(--r-md, 16px);
  background: var(--surface);
  box-shadow: 0 12px 30px rgb(0 0 0 / .35);
  animation: tct-chat-rise .35s ease-out;
}
.tct-chat-teaser-open {
  flex: 1;
  padding: 12px 4px 12px 14px;
  border: 0;
  background: none;
  color: var(--ink);
  text-align: left;
  font-size: 14px;
  line-height: 1.5;
}
.tct-chat-teaser-close {
  min-width: 40px; min-height: 40px;
  border: 0;
  background: none;
  color: var(--muted);
  font-size: 20px;
}

/* Panel */
.tct-chat-panel[hidden] { display: none; }
.tct-chat-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto auto;
  width: min(400px, 100%);
  height: min(620px, calc(100vh - var(--chat-bottom) - 80px));
  height: min(620px, calc(100dvh - var(--chat-bottom) - 80px));
  overflow: hidden;
  border: 1px solid var(--control);
  border-radius: var(--r-lg, 24px);
  background: var(--surface);
  box-shadow: 0 24px 60px rgb(0 0 0 / .45);
  transform-origin: bottom right;
  animation: tct-chat-open .28s cubic-bezier(.2, .8, .2, 1);
}
.tct-chat-heading {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 12px 14px 16px;
  background: var(--navy);
  color: var(--white);
}
.tct-chat-avatar {
  flex: none;
  width: 40px; height: 40px;
  border-radius: var(--r-sm, 10px);
  box-shadow: 0 0 0 1px rgb(255 255 255 / .25);
}
.tct-chat-heading-text { flex: 1; min-width: 0; }
.tct-chat-heading h2 {
  margin: 0;
  font: 600 22px/1.15 'Barlow Condensed', 'Inter', sans-serif;
  color: var(--white);
}
.tct-chat-status {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 2px 0 0;
  color: rgb(255 255 255 / .82);
  font-size: 12px;
  line-height: 1.4;
}
.tct-chat-status::before {
  content: '';
  flex: none;
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--accent);
}
.tct-chat-icon {
  display: grid;
  place-items: center;
  flex: none;
  width: 40px; height: 40px;
  border: 1px solid rgb(255 255 255 / .35);
  border-radius: var(--r-pill, 999px);
  background: transparent;
  color: var(--white);
  transition: background-color .2s;
}
.tct-chat-icon:hover { background: rgb(255 255 255 / .12); }

/* Conversation */
.tct-chat-log {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
  padding: 18px 14px 8px;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: var(--control) transparent;
}
.tct-chat-log:focus-visible { outline-offset: -3px; }
.tct-chat-row { display: grid; gap: 8px; justify-items: start; }
.tct-chat-row.is-user { justify-items: end; }
.tct-chat-row.is-new { animation: tct-chat-rise .3s ease-out; }
.tct-chat-message {
  max-width: 88%;
  padding: 10px 14px;
  overflow-wrap: anywhere;
  border: 1px solid var(--line);
  border-radius: var(--r-md, 16px) var(--r-md, 16px) var(--r-md, 16px) 4px;
  background: var(--paper);
  font-size: 15px;
  line-height: 1.6;
}
.tct-chat-message p { margin: 0; }
.tct-chat-user {
  border-color: var(--navy);
  border-radius: var(--r-md, 16px) var(--r-md, 16px) 4px var(--r-md, 16px);
  background: var(--navy);
  color: var(--white);
}
.tct-chat-divider {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 12px;
}
.tct-chat-divider::before, .tct-chat-divider::after { content: ''; flex: 1; height: 1px; background: var(--line); }

/* Typing indicator */
.tct-chat-typing .tct-chat-message { display: flex; gap: 5px; padding: 14px 16px; }
.tct-chat-typing span {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--muted);
  animation: tct-chat-dot 1.1s infinite ease-in-out;
}
.tct-chat-typing span:nth-child(2) { animation-delay: .15s; }
.tct-chat-typing span:nth-child(3) { animation-delay: .3s; }

/* Inline links */
.tct-chat-links { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-top: 8px; }
.tct-chat-links .tct-chat-action {
  color: var(--steel);
  font-size: 14px;
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 3px;
}
.tct-chat-links .tct-chat-action:hover { color: var(--white); }

/* Product results */
.tct-chat-products { display: grid; gap: 8px; width: 100%; }
.tct-chat-product {
  display: grid;
  grid-template-columns: 72px minmax(0, 1fr);
  gap: 12px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: var(--r-md, 16px);
  background: var(--bg);
  transition: border-color .2s, transform .2s;
}
.tct-chat-product:hover { border-color: var(--control); transform: translateY(-1px); }
.tct-chat-product-media {
  display: grid;
  place-items: center;
  width: 72px; height: 72px;
  overflow: hidden;
  border-radius: var(--r-sm, 10px);
  background: var(--photo);
}
.tct-chat-product-media img { width: 100%; height: 100%; object-fit: contain; }
.tct-chat-product-body { display: grid; align-content: center; gap: 2px; min-width: 0; }
.tct-chat-product-ref {
  margin: 0;
  color: var(--steel);
  font-size: 12px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  letter-spacing: .02em;
  user-select: text;
}
.tct-chat-product-name { margin: 0; font-size: 14px; font-weight: 600; line-height: 1.35; }
.tct-chat-product-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 12px; margin-top: 6px; }
.tct-chat-product-actions .tct-chat-action { color: var(--steel); font-size: 13px; font-weight: 600; text-decoration: underline; text-underline-offset: 3px; }
.tct-chat-mini {
  min-height: 30px;
  padding: 4px 12px;
  border: 1px solid var(--deep-navy);
  border-radius: var(--r-pill, 999px);
  background: var(--accent);
  color: var(--deep-navy);
  font-size: 13px;
  font-weight: 600;
}
.tct-chat-mini:hover { background: var(--deep-navy); color: var(--white); }

/* Request summary */
.tct-chat-summary {
  width: 100%;
  padding: 14px;
  border: 1px solid var(--control);
  border-radius: var(--r-md, 16px);
  background: var(--bg);
}
.tct-chat-summary-title { margin: 0 0 8px; font: 600 18px/1.2 'Barlow Condensed', 'Inter', sans-serif; }
.tct-chat-summary dl { display: grid; gap: 6px; margin: 0 0 12px; }
.tct-chat-summary dl div { display: grid; grid-template-columns: 76px minmax(0, 1fr); gap: 8px; font-size: 14px; line-height: 1.45; }
.tct-chat-summary dt { color: var(--muted); }
.tct-chat-summary dd { margin: 0; overflow-wrap: anywhere; user-select: text; }
.tct-chat-summary-actions { display: grid; gap: 8px; }
.tct-chat-summary-actions .tct-chat-action {
  display: flex;
  gap: 6px;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 8px 16px;
  border-radius: var(--r-pill, 999px);
  font-size: 14px;
  font-weight: 600;
  text-decoration: none;
  transition: background-color .2s, color .2s;
}
.tct-chat-primary { border: 1px solid var(--deep-navy); background: var(--accent); color: var(--deep-navy); }
.tct-chat-secondary { border: 1px solid rgb(255 255 255 / .3); background: var(--navy); color: var(--white); }
.tct-chat-summary-actions .tct-chat-action:hover { background: var(--deep-navy); color: var(--white); }

/* Quick replies */
/* Chips wrap onto extra lines so every option stays fully visible (no clipped edge). */
.tct-chat-topics {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 10px 14px 8px;
  border-top: 1px solid var(--line);
}
.tct-chat-topics:empty { display: none; }
.tct-chat-chip {
  flex: none;
  max-width: 100%;
  min-height: 34px;
  padding: 5px 12px;
  border: 1px solid var(--control);
  border-radius: var(--r-pill, 999px);
  background: var(--surface);
  color: var(--steel);
  font-size: 13px;
  font-weight: 600;
  line-height: 1.3;
  text-align: left;
  transition: background-color .2s, border-color .2s, color .2s;
}
.tct-chat-chip:hover { border-color: var(--steel); background: var(--paper); color: var(--ink); }
.tct-chat-chip.is-quiet { color: var(--muted); }

/* Composer */
.tct-chat-form { padding: 4px 14px 14px; }
.tct-chat-compose {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 4px 4px 16px;
  border: 1px solid var(--control);
  border-radius: var(--r-pill, 999px);
  background: var(--bg);
  transition: border-color .2s;
}
.tct-chat-compose:focus-within { border-color: var(--steel); }
.tct-chat-compose input {
  flex: 1;
  min-width: 0;
  min-height: 40px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--ink);
  font: 16px/1.4 'Inter', Arial, sans-serif;
}
.tct-chat-compose input::placeholder { color: var(--muted); }
.tct-chat-compose input:focus-visible { outline: none; }
.tct-chat-send {
  display: grid;
  place-items: center;
  flex: none;
  width: 40px; height: 40px;
  border: 1px solid var(--deep-navy);
  border-radius: 50%;
  background: var(--accent);
  color: var(--deep-navy);
  transition: background-color .2s, color .2s;
}
.tct-chat-send:hover { background: var(--deep-navy); color: var(--white); }

@keyframes tct-chat-open { from { opacity: 0; transform: translateY(12px) scale(.97); } }
@keyframes tct-chat-rise { from { opacity: 0; transform: translateY(8px); } }
@keyframes tct-chat-dot { 0%, 60%, 100% { opacity: .35; transform: none; } 30% { opacity: 1; transform: translateY(-3px); } }

/* Phones: the panel becomes a near full-height sheet. */
@media (max-width: 520px) {
  .tct-chat { --chat-edge: max(12px, env(safe-area-inset-right)); --chat-bottom: max(12px, env(safe-area-inset-bottom)); left: max(12px, env(safe-area-inset-left)); }
  .tct-chat-panel { width: 100%; height: calc(100vh - var(--chat-bottom) - 76px); height: calc(100dvh - var(--chat-bottom) - 76px); }
  .tct-chat.is-open .tct-chat-launch span { display: none; }
  .tct-chat.is-open .tct-chat-launch { padding: 12px 14px; }
}
@media (max-height: 420px) {
  .tct-chat-panel { grid-template-rows: auto minmax(80px, 1fr) auto auto; }
  .tct-chat-heading { padding-block: 8px; }
  .tct-chat-status { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  .tct-chat *, .tct-chat *::before { animation: none !important; transition: none !important; }
  .tct-chat-launch:hover, .tct-chat-product:hover { transform: none; }
}
