/* chat.css: the assistant panel and the memory page, in the look of shadcn AI Elements.
   Tokens and ui-* primitives come from ui.css; everything here is prefixed ai- (or the legacy asst- hooks).
   No inline styles anywhere: state lives in classes and data-* attributes. */

.ai-icon {
  width: 16px;
  height: 16px;
  flex: none;
  display: inline-block;
  vertical-align: middle;
}
.ai-chat,
.ai-chat *,
.ai-page,
.ai-page * {
  box-sizing: border-box;
}

/* ---------- panel frame ---------- */

.asst {
  position: relative;
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--radius-xl, 14px);
  background: var(--card, var(--background));
  color: var(--card-foreground, var(--foreground));
  box-shadow: var(--shadow-xs, 0 1px 2px 0 rgb(0 0 0 / 0.05));
  font-size: 14px;
  line-height: 20px;
}
.asst-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 12px 12px 16px;
  border-bottom: 1px solid var(--border);
}
.asst-avatar,
.ai-message__avatar {
  display: inline-flex;
  flex: none;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: 1px solid var(--border);
  border-radius: 9999px;
  background: var(--background);
  color: var(--foreground);
}
.asst-title {
  flex: 1;
  min-width: 0;
}
.asst-head h2 {
  margin: 0;
  font-size: 14px;
  line-height: 20px;
  font-weight: 600;
  letter-spacing: normal;
}
.asst-sub {
  margin: 0;
  color: var(--muted-foreground);
  font-size: 12px;
  line-height: 16px;
}
.asst-back {
  flex: none;
}

/* ---------- memory peek (collapsible) ---------- */

.ai-memory {
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.ai-memory__trigger {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  color: var(--muted-foreground);
  font-weight: 500;
  cursor: pointer;
  list-style: none;
  outline: none;
  transition: color 0.15s, background-color 0.15s;
}
.ai-memory__trigger::-webkit-details-marker {
  display: none;
}
.ai-memory__trigger:hover {
  color: var(--foreground);
  background: color-mix(in oklab, var(--muted) 50%, transparent);
}
.ai-memory__trigger:focus-visible {
  box-shadow: inset 0 0 0 3px color-mix(in oklab, var(--ring) 50%, transparent);
}
.ai-memory__count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 9999px;
  background: var(--secondary);
  color: var(--secondary-foreground);
  font-size: 12px;
  line-height: 16px;
  font-variant-numeric: tabular-nums;
}
.ai-memory__chev {
  margin-left: auto;
  transition: transform 0.2s;
}
.ai-memory[open] .ai-memory__chev {
  transform: rotate(180deg);
}
.ai-memory__content {
  display: grid;
  gap: 8px;
  padding: 0 16px 12px;
}
.ai-memory[open] .ai-memory__content {
  animation: ai-slide-in 0.2s ease-out;
}
.ai-memory__list {
  display: grid;
  gap: 6px;
  max-height: 11rem;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  list-style: none;
}
.ai-memory__list li {
  display: flex;
  align-items: baseline;
  gap: 8px;
  min-width: 0;
}
.ai-memory__none {
  margin: 0;
  color: var(--muted-foreground);
}
.ai-memory__link {
  width: fit-content;
  color: var(--foreground);
  font-weight: 500;
  text-decoration: underline;
  text-underline-offset: 4px;
}

/* Rule kind badge: Only / Never / Prefer */
.ai-kind {
  display: inline-flex;
  flex: none;
  align-items: center;
  height: 20px;
  padding: 0 8px;
  border: 1px solid transparent;
  border-radius: 9999px;
  font-size: 12px;
  line-height: 16px;
  font-weight: 500;
  white-space: nowrap;
  background: var(--secondary);
  color: var(--secondary-foreground);
}
.ai-kind[data-kind="require"] {
  background: color-mix(in oklab, var(--ai-green, #16a34a) 12%, transparent);
  color: var(--ai-green, #16a34a);
}
.ai-kind[data-kind="exclude"] {
  background: color-mix(in oklab, var(--destructive) 10%, transparent);
  color: var(--destructive);
}
.ai-kind[data-kind="prefer"] {
  background: color-mix(in oklab, var(--ai-blue, #2563eb) 12%, transparent);
  color: var(--ai-blue, #2563eb);
}

/* ---------- transcript ---------- */

.ai-scroller {
  position: relative;
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  min-height: 0;
}
.ai-viewport {
  min-height: 9rem;
  max-height: 60vh;
  max-height: 60dvh;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-gutter: stable;
  outline: none;
  -webkit-mask-image: linear-gradient(to bottom, #000 calc(100% - 24px), transparent 100%);
  mask-image: linear-gradient(to bottom, #000 calc(100% - 24px), transparent 100%);
}
.ai-viewport:focus-visible {
  box-shadow: inset 0 0 0 3px color-mix(in oklab, var(--ring) 50%, transparent);
}
.ai-content {
  display: flex;
  flex-direction: column;
  gap: 24px;
  min-height: 100%;
  padding: 16px 16px 24px;
}
.ai-log {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

/* Scroll-to-latest: round outline icon button floating above the composer. */
.ai-scroll-btn {
  position: absolute;
  left: 50%;
  bottom: 12px;
  z-index: 2;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 9999px;
  background: var(--background);
  color: var(--foreground);
  box-shadow: var(--shadow-sm, 0 1px 3px 0 rgb(0 0 0 / 0.1));
  cursor: pointer;
  translate: -50% 0;
  transition: translate 0.2s, scale 0.2s, opacity 0.2s, background-color 0.15s;
}
.ai-scroll-btn:hover {
  background: var(--accent);
}
.ai-scroll-btn:focus-visible {
  outline: none;
  border-color: var(--ring);
  box-shadow: 0 0 0 3px color-mix(in oklab, var(--ring) 50%, transparent);
}
.ai-scroll-btn[data-active="false"] {
  opacity: 0;
  scale: 0.95;
  translate: -50% 50%;
  pointer-events: none;
}

/* ---------- empty state ---------- */

.ai-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 24px 8px;
  text-align: center;
}
.ai-log:has(.ai-message) .ai-empty {
  display: none;
}
.ai-empty__icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: var(--radius-lg, 10px);
  background: var(--muted);
  color: var(--foreground);
}
.ai-empty__icon .ai-icon {
  width: 20px;
  height: 20px;
}
.ai-empty__title {
  margin: 0;
  font-size: 14px;
  line-height: 20px;
  font-weight: 500;
}
.ai-empty__desc {
  margin: 4px 0 0;
  color: var(--muted-foreground);
  font-size: 14px;
  line-height: 20px;
  text-wrap: pretty;
}

/* ---------- messages ---------- */

.ai-message {
  display: flex;
  gap: 10px;
  width: 100%;
  min-width: 0;
  font-size: 14px;
}
.ai-message[data-role="user"] {
  justify-content: flex-end;
}
.ai-bubble {
  width: fit-content;
  max-width: 85%;
  min-width: 0;
  padding: 8px 12px;
  border-radius: var(--radius-xl, 14px);
  background: var(--secondary);
  color: var(--secondary-foreground);
  line-height: 1.625;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.ai-message[data-pending] .ai-bubble {
  opacity: 0.7;
}
.ai-message__avatar {
  width: 28px;
  height: 28px;
}
.ai-message__avatar .ai-icon {
  width: 14px;
  height: 14px;
}
.ai-message__content {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 12px;
  min-width: 0;
  padding-top: 4px;
  overflow-wrap: break-word;
}

/* Markdown body (ghost bubble: plain text, no background) */
.ai-prose {
  width: 100%;
  font-size: 14px;
  line-height: 1.625;
}
.ai-prose > :first-child {
  margin-top: 0;
}
.ai-prose > :last-child {
  margin-bottom: 0;
}
.ai-prose p {
  margin: 0 0 0.75em;
}
.ai-prose strong {
  font-weight: 600;
}
.ai-prose a {
  color: var(--primary);
  text-decoration: underline;
  text-underline-offset: 3px;
}
.ai-prose code {
  padding: 0.1em 0.35em;
  border-radius: 6px;
  background: var(--muted);
  font: 12.5px/1.4 var(--font-mono, ui-monospace, SFMono-Regular, Menlo, monospace);
}
.ai-table-wrap {
  max-width: 100%;
  margin: 0 0 0.75em;
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-md, 8px);
}
.ai-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  line-height: 18px;
  font-variant-numeric: tabular-nums;
}
.ai-table th,
.ai-table td {
  padding: 6px 10px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}
.ai-table th {
  background: color-mix(in oklab, var(--muted) 50%, transparent);
  color: var(--muted-foreground);
  font-weight: 500;
  white-space: nowrap;
}
.ai-table tbody tr:last-child td {
  border-bottom: 0;
}
.ai-table tbody tr:hover {
  background: color-mix(in oklab, var(--muted) 50%, transparent);
}

.ai-error {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 10px 12px;
  border: 1px solid color-mix(in oklab, var(--destructive) 30%, var(--border));
  border-radius: var(--radius-lg, 10px);
  background: color-mix(in oklab, var(--destructive) 6%, var(--background));
  color: var(--destructive);
}
.ai-error .ai-icon {
  margin-top: 2px;
}
.ai-error p {
  margin: 0;
}

/* ---------- thinking marker (htmx indicator) ---------- */

.ai-marker {
  display: none;
  align-items: center;
  gap: 8px;
  color: var(--muted-foreground);
  font-size: 14px;
  line-height: 20px;
}
.ai-marker.htmx-request,
.htmx-request .ai-marker {
  display: flex;
}
.ai-marker__note {
  color: color-mix(in oklab, var(--muted-foreground) 70%, transparent);
  font-size: 12px;
}
.ai-chat .ai-marker {
  padding-left: 38px; /* line up with message text, past the avatar */
}
.ai-spin {
  animation: ai-spin 1s linear infinite;
}
@property --ai-shimmer-angle {
  syntax: "<angle>";
  inherits: true;
  initial-value: 20deg;
}
.ai-shimmer {
  --_spread: calc(3ch + 40px);
  --_base: var(--muted-foreground);
  --_hl: var(--foreground);
  background-image: linear-gradient(
    calc(90deg + var(--ai-shimmer-angle)),
    var(--_base) calc(50% - var(--_spread)),
    color-mix(in oklab, var(--_hl), var(--_base) 50%) calc(50% - var(--_spread) * 0.5),
    var(--_hl) 50%,
    color-mix(in oklab, var(--_hl), var(--_base) 50%) calc(50% + var(--_spread) * 0.5),
    var(--_base) calc(50% + var(--_spread))
  );
  background-repeat: no-repeat;
  background-size: calc(200% + var(--_spread) * 2) 100%;
  background-position: 0 0;
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  color: var(--muted-foreground);
  animation: ai-shimmer 2s linear infinite;
}
@keyframes ai-shimmer {
  from {
    background-position: 100% 0;
  }
  to {
    background-position: 0 0;
  }
}
@keyframes ai-spin {
  to {
    transform: rotate(360deg);
  }
}
@keyframes ai-slide-in {
  from {
    opacity: 0;
    transform: translateY(-6px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

/* ---------- suggestion chips ---------- */

.ai-suggestions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 8px;
  width: 100%;
  padding: 2px;
}
.ai-suggestions--wrap {
  justify-content: center;
}
.ai-suggestions--bar {
  padding: 10px 16px 2px;
}
/* While the conversation is empty, the chips sit in the empty state instead. */
.asst:has(.ai-empty):not(:has(.ai-log .ai-message)) .ai-suggestions--bar {
  display: none;
}
.ai-suggestion-form {
  display: contents;
}
.ai-suggestion {
  display: inline-flex;
  flex: none;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 32px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: 9999px;
  background: var(--background);
  color: var(--foreground);
  box-shadow: var(--shadow-xs, 0 1px 2px 0 rgb(0 0 0 / 0.05));
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  line-height: 20px;
  cursor: pointer;
  outline: none;
  transition: background-color 0.15s, color 0.15s, border-color 0.15s, box-shadow 0.15s;
}
.ai-suggestion:hover {
  background: var(--accent);
  color: var(--accent-foreground);
}
.ai-suggestion:focus-visible {
  border-color: var(--ring);
  box-shadow: 0 0 0 3px color-mix(in oklab, var(--ring) 50%, transparent);
}
.ai-suggestion:disabled {
  opacity: 0.5;
  pointer-events: none;
}
.ai-suggestion__icon {
  width: 14px;
  height: 14px;
  color: var(--muted-foreground);
}
@media (pointer: coarse) {
  .ai-suggestion {
    height: 40px;
  }
}
.asst[data-busy] .ai-suggestion {
  opacity: 0.5;
  pointer-events: none;
}

/* ---------- prompt input ---------- */

.ai-prompt {
  margin: 0;
  padding: 10px 12px 12px;
}
.ai-prompt__group {
  display: flex;
  flex-direction: column;
  width: 100%;
  min-width: 0;
  overflow: hidden;
  border: 1px solid var(--input, var(--border));
  border-radius: var(--radius-lg, 10px);
  background: var(--field-bg, transparent);
  background-color: var(--background);
  box-shadow: var(--shadow-xs, 0 1px 2px 0 rgb(0 0 0 / 0.05));
  transition: border-color 0.15s, box-shadow 0.15s;
}
.ai-prompt__group:has(.ai-prompt__textarea:focus-visible),
.ai-prompt__group:has(.ai-prompt__textarea:focus) {
  border-color: var(--ring);
  box-shadow: 0 0 0 3px color-mix(in oklab, var(--ring) 50%, transparent);
}
.ai-prompt__textarea {
  display: block;
  width: 100%;
  min-height: 52px;
  max-height: 192px;
  margin: 0;
  padding: 12px 12px 4px;
  border: 0;
  border-radius: 0;
  outline: 0;
  box-shadow: none;
  resize: none;
  background: transparent;
  color: inherit;
  font: inherit;
  font-size: 14px;
  line-height: 20px;
  field-sizing: content;
  overflow-y: auto;
}
.ai-prompt__textarea:focus,
.ai-prompt__textarea:focus-visible {
  outline: 0;
  box-shadow: none;
  border: 0;
}
.ai-prompt__textarea::placeholder {
  color: var(--muted-foreground);
}
.ai-prompt__footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 4px 8px 8px 12px;
}
.ai-prompt__hint {
  min-width: 0;
  overflow: hidden;
  color: var(--muted-foreground);
  font-size: 12px;
  line-height: 16px;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.ai-prompt__hint .ui-kbd {
  height: 18px;
  font-size: 11px;
}
@media (pointer: coarse) {
  .ai-prompt__hint {
    visibility: hidden;
  }
}
.ai-send {
  display: inline-flex;
  flex: none;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 0;
  border-radius: 9999px;
  background: var(--primary);
  color: var(--primary-foreground);
  cursor: pointer;
  outline: none;
  transition: background-color 0.15s, opacity 0.15s, box-shadow 0.15s;
}
.ai-send:hover {
  background: color-mix(in oklab, var(--primary) 90%, transparent);
}
.ai-send:focus-visible {
  box-shadow: 0 0 0 3px color-mix(in oklab, var(--ring) 50%, transparent);
}
.ai-send:disabled {
  opacity: 0.5;
  cursor: default;
}
.ai-send__spin {
  display: none;
}
.ai-prompt.htmx-request .ai-send__icon,
.asst[data-busy] .ai-send__icon {
  display: none;
}
.ai-prompt.htmx-request .ai-send__spin,
.asst[data-busy] .ai-send__spin {
  display: inline-block;
  animation: ai-spin 1s linear infinite;
}
.ai-prompt.htmx-request .ai-prompt__textarea {
  opacity: 0.7;
}

/* ---------- trace: "What I did" as a task with chain-of-thought tool rows ---------- */

.ai-task {
  width: 100%;
  font-size: 13px;
}
.ai-task__trigger {
  display: flex;
  align-items: center;
  gap: 8px;
  width: fit-content;
  max-width: 100%;
  border-radius: var(--radius-sm, 6px);
  color: var(--muted-foreground);
  font-size: 13px;
  line-height: 20px;
  cursor: pointer;
  list-style: none;
  outline: none;
  transition: color 0.15s;
}
.ai-task__trigger::-webkit-details-marker {
  display: none;
}
.ai-task__trigger:hover {
  color: var(--foreground);
}
.ai-task__trigger:focus-visible {
  box-shadow: 0 0 0 3px color-mix(in oklab, var(--ring) 50%, transparent);
}
.ai-task__count {
  color: color-mix(in oklab, var(--muted-foreground) 75%, transparent);
  font-variant-numeric: tabular-nums;
}
.ai-task__count::before {
  content: "· ";
}
.ai-task__chev {
  transition: transform 0.2s;
}
.ai-task[open] .ai-task__chev {
  transform: rotate(180deg);
}

.ai-cot {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin: 8px 0 0;
  padding: 0;
  list-style: none;
}
.ai-task[open] .ai-cot {
  animation: ai-slide-in 0.2s ease-out;
}
.ai-cot__step {
  position: relative;
  display: flex;
  gap: 8px;
  min-width: 0;
}
.ai-cot__rail {
  position: relative;
  display: flex;
  flex: none;
  justify-content: center;
  width: 16px;
}
.ai-cot__dot {
  position: relative;
  z-index: 1;
  width: 8px;
  height: 8px;
  margin-top: 12px;
  border-radius: 9999px;
  background: var(--ai-green, #16a34a);
  box-shadow: 0 0 0 3px var(--card, var(--background));
}
.ai-cot__step[data-status="error"] .ai-cot__dot {
  background: var(--ai-red, #dc2626);
}
.ai-cot__step[data-status="running"] .ai-cot__dot {
  background: var(--muted-foreground);
  animation: ai-pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}
.ai-cot__line {
  position: absolute;
  top: 20px;
  bottom: -14px;
  left: 50%;
  width: 1px;
  background: var(--border);
}
.ai-cot__step:last-child .ai-cot__line {
  display: none;
}
@keyframes ai-pulse {
  50% {
    opacity: 0.5;
  }
}

/* One tool call: a quiet collapsible row, bordered card once opened. */
.ai-tool {
  flex: 1;
  min-width: 0;
  border: 1px solid transparent;
  border-radius: var(--radius-md, 8px);
  transition: border-color 0.15s, background-color 0.15s;
}
.ai-tool[open] {
  border-color: var(--border);
  background: var(--background);
}
.ai-tool__header {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 32px;
  padding: 4px 8px;
  border-radius: inherit;
  cursor: pointer;
  list-style: none;
  outline: none;
}
.ai-tool__header::-webkit-details-marker {
  display: none;
}
.ai-tool__header:hover {
  background: color-mix(in oklab, var(--muted) 60%, transparent);
}
.ai-tool__header:focus-visible {
  box-shadow: 0 0 0 3px color-mix(in oklab, var(--ring) 50%, transparent);
}
.ai-tool__name {
  display: flex;
  flex: 1;
  align-items: baseline;
  gap: 6px;
  min-width: 0;
  overflow: hidden;
}
.ai-tool__title {
  flex: none;
  color: var(--foreground);
  font-weight: 500;
}
.ai-tool__hint {
  min-width: 0;
  overflow: hidden;
  color: var(--muted-foreground);
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ai-tool__badge {
  display: inline-flex;
  flex: none;
  align-items: center;
  gap: 4px;
  height: 20px;
  padding: 0 8px 0 6px;
  border-radius: 9999px;
  background: var(--secondary);
  color: var(--secondary-foreground);
  font-size: 12px;
  line-height: 16px;
  font-weight: 500;
}
.ai-tool__status {
  width: 12px;
  height: 12px;
  color: var(--ai-green, #16a34a);
}
.ai-cot__step[data-status="error"] .ai-tool__status {
  color: var(--ai-red, #dc2626);
}
.ai-tool__chevron {
  color: var(--muted-foreground);
  transition: transform 0.2s;
}
.ai-tool[open] .ai-tool__chevron {
  transform: rotate(180deg);
}
.ai-tool__content {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 8px 10px 12px;
  border-top: 1px solid var(--border);
}
.ai-tool[open] .ai-tool__content {
  animation: ai-slide-in 0.2s ease-out;
}
.ai-tool__fn {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 0;
  color: var(--muted-foreground);
  font-size: 12px;
}
.ai-tool__fn .ai-icon {
  width: 12px;
  height: 12px;
}
.ai-tool__fn code,
.ai-code {
  font-family: var(--font-mono, ui-monospace, SFMono-Regular, Menlo, monospace);
}
.ai-tool__section {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}
.ai-tool__h {
  margin: 0;
  color: var(--muted-foreground);
  font-size: 11px;
  line-height: 16px;
  font-weight: 500;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.ai-tool__none {
  margin: 0;
  color: var(--muted-foreground);
}
.ai-code {
  max-height: 10rem;
  margin: 0;
  padding: 8px 10px;
  overflow: auto;
  border-radius: var(--radius-sm, 6px);
  background: color-mix(in oklab, var(--muted) 60%, transparent);
  color: var(--foreground);
  font-size: 12px;
  line-height: 1.5;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.ai-code--error {
  background: color-mix(in oklab, var(--destructive) 10%, transparent);
  color: var(--destructive);
}
.ai-kv {
  display: grid;
  gap: 2px;
  margin: 0;
  padding: 6px 10px;
  border-radius: var(--radius-sm, 6px);
  background: color-mix(in oklab, var(--muted) 60%, transparent);
  font-size: 12px;
  line-height: 18px;
}
.ai-kv__row {
  display: grid;
  grid-template-columns: minmax(5rem, auto) minmax(0, 1fr);
  gap: 10px;
}
.ai-kv dt {
  color: var(--muted-foreground);
}
.ai-kv dd {
  margin: 0;
  min-width: 0;
  overflow-wrap: anywhere;
  font-variant-numeric: tabular-nums;
}
.ai-kv-list {
  display: grid;
  gap: 2px;
  margin: 0;
  padding: 6px 10px 6px 26px;
  border-radius: var(--radius-sm, 6px);
  background: color-mix(in oklab, var(--muted) 60%, transparent);
  font-size: 12px;
  line-height: 18px;
}
.ai-kv-list li::marker {
  color: var(--muted-foreground);
}

/* ---------- cart changes of a turn ---------- */

.ai-changes {
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg, 10px);
  background: var(--background);
}
.ai-changes__head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  background: color-mix(in oklab, var(--muted) 50%, transparent);
  font-size: 13px;
  font-weight: 500;
}
.ai-changes__head .ai-icon {
  color: var(--ai-green, #16a34a);
}
.ai-changes__count {
  margin-left: auto;
  color: var(--muted-foreground);
  font-size: 12px;
  font-weight: 400;
}
.ai-changes__list {
  margin: 0;
  padding: 0;
  list-style: none;
}
.ai-change {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  padding: 8px 12px;
  border-left: 3px solid var(--cat, transparent);
  font-size: 13px;
}
.ai-change + .ai-change {
  border-top: 1px solid var(--border);
}
.ai-change__img {
  flex: none;
  width: 40px;
  height: 40px;
  border-radius: var(--radius-sm, 6px);
  background: #fff;
  object-fit: contain;
}
.ai-change__img--none {
  background: var(--muted);
}
.ai-change__main {
  display: grid;
  flex: 1;
  gap: 1px;
  min-width: 0;
}
.ai-change__title {
  overflow: hidden;
  color: var(--foreground);
  font-weight: 500;
  text-decoration: none;
  text-overflow: ellipsis;
  white-space: nowrap;
}
a.ai-change__title:hover {
  text-decoration: underline;
  text-underline-offset: 3px;
}
.ai-change__meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 2px 8px;
  color: var(--muted-foreground);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}
.ai-change__meta b {
  color: var(--foreground);
  font-weight: 600;
}
.ai-change__kind {
  flex: none;
  padding: 0 8px;
  border-radius: 9999px;
  background: var(--secondary);
  color: var(--secondary-foreground);
  font-size: 11px;
  line-height: 20px;
  font-weight: 500;
}
.ai-change--gone {
  border-left-color: var(--destructive);
}
.ai-change--gone .ai-change__title {
  color: var(--muted-foreground);
  text-decoration: line-through;
}

/* ---------- product cards (tool result) ---------- */

.ai-products {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 17rem), 1fr));
  gap: 10px;
  width: 100%;
  margin: 0;
  padding: 0;
  list-style: none;
}
.ai-product {
  display: grid;
  grid-template-columns: 76px minmax(0, 1fr);
  grid-template-areas:
    "media body"
    "act act"
    "note note";
  gap: 10px 12px;
  min-width: 0;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg, 10px);
  background: var(--card, var(--background));
  box-shadow: var(--shadow-xs, 0 1px 2px 0 rgb(0 0 0 / 0.05));
  transition: border-color 0.15s, box-shadow 0.15s;
}
.ai-product:hover {
  border-color: color-mix(in oklab, var(--foreground) 20%, var(--border));
}
.ai-product[data-in-cart="true"] {
  border-color: color-mix(in oklab, var(--ai-green, #16a34a) 45%, var(--border));
}
.ai-product__media {
  position: relative;
  grid-area: media;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 76px;
  height: 76px;
  overflow: hidden;
  border-radius: var(--radius-md, 8px);
  background: #fff;
  box-shadow: inset 0 0 0 1px var(--border);
}
.ai-product__img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}
.ai-product__noimg {
  width: 24px;
  height: 24px;
  color: var(--muted-foreground);
}
.ai-product__shop {
  position: absolute;
  left: 4px;
  bottom: 4px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  max-width: calc(100% - 8px);
  height: 18px;
  padding: 0 6px;
  border: 1px solid var(--border);
  border-radius: 9999px;
  background: var(--background);
  color: var(--foreground);
  font-size: 10px;
  line-height: 16px;
  font-weight: 500;
}
.ai-product__dot {
  width: 6px;
  height: 6px;
  flex: none;
  border-radius: 9999px;
  background: var(--muted-foreground);
}
.ai-product[data-shop="barbora"] .ai-product__dot {
  background: var(--shop-barbora, #cf4a2a);
}
.ai-product[data-shop="rimi"] .ai-product__dot {
  background: var(--shop-rimi, #2b5ca6);
}
.ai-product__body {
  grid-area: body;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.ai-product__body p {
  margin: 0;
}
.ai-product__why {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  width: fit-content;
  max-width: 100%;
  margin-bottom: 2px !important;
  padding: 1px 8px 1px 6px;
  border-radius: 9999px;
  background: color-mix(in oklab, var(--muted) 80%, transparent);
  color: var(--muted-foreground);
  font-size: 11px;
  line-height: 16px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ai-product__why .ai-icon {
  width: 11px;
  height: 11px;
}
.ai-product__title {
  display: -webkit-box;
  margin: 0;
  overflow: hidden;
  font-size: 13px;
  line-height: 18px;
  font-weight: 500;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
}
.ai-product__meta {
  color: var(--muted-foreground);
  font-size: 12px;
  line-height: 16px;
  font-variant-numeric: tabular-nums;
}
.ai-product__price {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 2px !important;
}
.ai-product__now {
  font-size: 15px;
  line-height: 22px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.ai-product__deal {
  display: inline-flex;
  align-items: center;
  height: 18px;
  padding: 0 6px;
  border-radius: 9999px;
  background: color-mix(in oklab, var(--ai-green, #16a34a) 14%, transparent);
  color: var(--ai-green, #16a34a);
  font-size: 11px;
  line-height: 16px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.ai-product__actions {
  grid-area: act;
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
}
.ai-product__add {
  flex: 1;
  min-width: 0;
}
.ai-product__add .ai-icon {
  width: 14px;
  height: 14px;
}
.ai-product__note {
  grid-area: note;
  display: flex;
  align-items: center;
  gap: 6px;
  margin: -2px 0 0;
  color: var(--muted-foreground);
  font-size: 12px;
  line-height: 16px;
}
.ai-product__note--error {
  color: var(--destructive);
}
.ai-product__note--error .ai-icon {
  width: 14px;
  height: 14px;
}
.ai-product.htmx-request,
.ai-product:has(form.htmx-request) {
  opacity: 0.7;
}

/* Quantity stepper: one outline group, 32px tall */
.ai-qty {
  display: inline-flex;
  flex: none;
  align-items: center;
  height: 32px;
  overflow: hidden;
  border: 1px solid var(--input, var(--border));
  border-radius: var(--radius-md, 8px);
  background: var(--background);
  box-shadow: var(--shadow-xs, 0 1px 2px 0 rgb(0 0 0 / 0.05));
}
.ai-qty:focus-within {
  border-color: var(--ring);
  box-shadow: 0 0 0 3px color-mix(in oklab, var(--ring) 50%, transparent);
}
.ai-qty__btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 100%;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--foreground);
  cursor: pointer;
  outline: none;
}
.ai-qty__btn .ai-icon {
  width: 14px;
  height: 14px;
}
.ai-qty__btn:hover {
  background: var(--accent);
}
.ai-qty__btn:focus-visible {
  background: var(--accent);
}
.ai-qty__btn:disabled {
  opacity: 0.4;
  cursor: default;
  background: transparent;
}
.ai-qty__input {
  width: 30px;
  height: 100%;
  padding: 0;
  border: 0;
  border-radius: 0;
  outline: 0;
  box-shadow: none;
  background: transparent;
  color: var(--foreground);
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  text-align: center;
  font-variant-numeric: tabular-nums;
  appearance: textfield;
  -moz-appearance: textfield;
}
.ai-qty__input:focus {
  outline: 0;
  box-shadow: none;
}
.ai-qty__input::-webkit-outer-spin-button,
.ai-qty__input::-webkit-inner-spin-button {
  margin: 0;
  -webkit-appearance: none;
}

/* ---------- phone: the assistant sits under the cart, one tap away ---------- */

.asst-jump {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 3;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 40px;
  padding: 0 18px;
  border-radius: 9999px;
  background: var(--primary);
  color: var(--primary-foreground);
  font-size: 14px;
  font-weight: 500;
  text-decoration: none;
  box-shadow: var(--shadow-lg, 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1));
}
.asst-jump:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px color-mix(in oklab, var(--ring) 50%, transparent);
}
main:has(#assistant:target) .asst-jump,
main:has(.asst:focus-within) .asst-jump {
  display: none;
}

@media (min-width: 64rem) {
  .asst {
    position: sticky;
    top: 72px;
    height: calc(100vh - 88px);
    height: calc(100dvh - 88px);
  }
  .ai-viewport {
    flex: 1 1 0;
    max-height: none;
    min-height: 0;
  }
  .asst-jump,
  .asst-back {
    display: none;
  }
}

/* ---------- memory page ---------- */

.ai-page {
  display: grid;
  gap: 24px;
  max-width: 48rem;
  margin: 0 auto;
  padding: 24px 0 32px;
  font-size: 14px;
  line-height: 20px;
}
.ai-page h1 {
  margin: 0;
  font-size: 24px;
  line-height: 32px;
  font-weight: 600;
  letter-spacing: -0.01em;
}
.ai-page h2 {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  font-size: 16px;
  line-height: 24px;
  font-weight: 600;
}
.ai-page__head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px 16px;
}
.ai-page__desc {
  max-width: 40rem;
  margin: 4px 0 0;
  color: var(--muted-foreground);
}
.ai-page__result {
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-xl, 14px);
  background: var(--card, var(--background));
}
.ai-page__result > .ai-error {
  margin: -16px;
  border: 0;
}
.ai-rules {
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--radius-xl, 14px);
  background: var(--card, var(--background));
  box-shadow: var(--shadow-xs, 0 1px 2px 0 rgb(0 0 0 / 0.05));
}
.ai-rules__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}
.ai-rules__count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 22px;
  height: 22px;
  padding: 0 7px;
  border-radius: 9999px;
  background: var(--secondary);
  color: var(--secondary-foreground);
  font-size: 12px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}
.ai-rules > :not(.ai-rules__head):not(.ai-rules__list) {
  margin: 16px;
}
.ai-rules__list {
  margin: 0;
  padding: 0;
  list-style: none;
}
.ai-rule {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 16px;
  transition: background-color 0.15s;
}
.ai-rule + .ai-rule {
  border-top: 1px solid var(--border);
}
.ai-rule:hover {
  background: color-mix(in oklab, var(--muted) 50%, transparent);
}
.ai-rule .ai-kind {
  margin-top: 1px;
}
.ai-rule__main {
  display: grid;
  flex: 1;
  gap: 2px;
  min-width: 0;
}
.ai-rule__main p {
  margin: 0;
}
.ai-rule__note {
  font-weight: 500;
  overflow-wrap: anywhere;
}
.ai-rule__detail {
  color: var(--muted-foreground);
  font-size: 12px;
  line-height: 16px;
  overflow-wrap: anywhere;
}
.ai-rule__act {
  flex: none;
  margin: -4px 0;
}
.ai-rule.htmx-request,
.ai-rule:has(.htmx-request) {
  opacity: 0.6;
}
.ai-rules-add {
  display: grid;
  gap: 4px;
}
.ai-rules-add .ai-prompt {
  padding: 8px 0 0;
}
.ai-rules-add .ai-marker {
  margin-top: 8px;
}

/* ---------- reduced motion ---------- */

@media (prefers-reduced-motion: reduce) {
  .ai-chat *,
  .ai-page * {
    animation: none !important;
    transition: none !important;
  }
  .ai-shimmer {
    background-image: none;
    -webkit-text-fill-color: currentColor;
  }
}
