.ai-view {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 0;
  height: 100%;
  overflow: hidden;
}

body[data-secondary-tab="ai"] .app-main {
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 0;
  overflow: hidden;
}

body[data-secondary-tab="ai"] .secondary-topbar {
  flex: 0 0 auto;
}

body[data-secondary-tab="ai"] .ai-view {
  flex: 1 1 auto;
}

.ai-hero-card {
  flex: 0 0 auto;
  padding: 16px 18px;
  border-radius: 0 0 24px 24px;
  background: linear-gradient(135deg, #111827 0%, #1f2937 60%, #334155 100%);
  color: #ffffff;
  box-shadow: 0 14px 34px rgba(17, 24, 39, 0.16);
}

.ai-pill {
  width: fit-content;
  padding: 6px 10px;
  display: inline-flex;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.14);
  color: #ffffff;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.ai-hero-card h2 {
  margin-top: 12px;
  font-size: 24px;
  line-height: 1.08;
  font-weight: 850;
}

.ai-hero-card p {
  margin-top: 7px;
  color: rgba(255, 255, 255, 0.78);
  font-size: 13px;
  line-height: 1.45;
}

.ai-quick-row {
  flex: 0 0 auto;
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 0 0 2px;
  scrollbar-width: none;
}

.ai-quick-row::-webkit-scrollbar {
  display: none;
}

.ai-quick-row button {
  flex: 0 0 auto;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: #ffffff;
  color: var(--ink);
  font-size: 12px;
  font-weight: 750;
  box-shadow: var(--shadow-sm);
}

.ai-chat-card {
  flex: 1 1 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 24px 24px 0 0;
  background: #ffffff;
  box-shadow: var(--shadow-sm);
}

.ai-messages {
  flex: 1 1 auto;
  min-height: 0;
  padding: 14px;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.ai-welcome-card {
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 5px;
  border-radius: 18px;
  background: var(--surface);
  color: var(--soft);
  font-size: 13px;
  line-height: 1.4;
}

.ai-welcome-card strong {
  color: var(--ink);
  font-size: 15px;
}

.ai-message {
  max-width: 84%;
  padding: 10px 12px;
  border-radius: 18px;
  font-size: 13px;
  line-height: 1.45;
  white-space: pre-wrap;
}

.ai-message.assistant {
  align-self: flex-start;
  background: var(--surface);
  color: var(--ink);
  border-bottom-left-radius: 6px;
}

.ai-message.user {
  align-self: flex-end;
  background: var(--primary);
  color: #ffffff;
  border-bottom-right-radius: 6px;
}

.ai-message.has-products {
  width: 100%;
  max-width: 100%;
  padding: 0;
  overflow: visible;
  background: transparent;
  white-space: normal;
}

.ai-message.has-products .ai-message-copy {
  width: fit-content;
  max-width: 84%;
  padding: 10px 12px;
  border-radius: 18px 18px 18px 6px;
  background: var(--surface);
  white-space: pre-wrap;
}

.ai-recommendations {
  width: 100%;
  margin-top: 10px;
  padding: 11px 0 4px;
  overflow: hidden;
  border: 1px solid rgba(28, 85, 55, .09);
  border-radius: 18px;
  background: linear-gradient(145deg, #f8fbf9, #eef7f1);
  box-shadow: 0 5px 16px rgba(24, 76, 49, .07);
}

.ai-recommendation-head {
  padding: 0 11px 9px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.ai-recommendation-head > span {
  width: 29px;
  height: 29px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  border-radius: 10px;
  background: #173d2b;
  color: #f8cb46;
}

.ai-recommendation-head svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
}

.ai-recommendation-head strong,
.ai-recommendation-head small {
  display: block;
}

.ai-recommendation-head strong {
  color: #173d2b;
  font-size: 11px;
  font-weight: 850;
}

.ai-recommendation-head small {
  margin-top: 1px;
  color: #738279;
  font-size: 8.5px;
}

.ai-product-row {
  padding: 0 10px 7px;
  display: flex;
  gap: 9px;
  overflow-x: auto;
  overscroll-behavior-inline: contain;
  scroll-snap-type: x proximity;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}

.ai-product-row::-webkit-scrollbar {
  display: none;
}

.ai-product-card {
  position: relative;
  flex: 0 0 154px;
  min-width: 0;
  overflow: hidden;
  scroll-snap-align: start;
  border: 1px solid rgba(22, 61, 43, .09);
  border-radius: 16px;
  background: #ffffff;
  box-shadow: 0 4px 12px rgba(22, 61, 43, .07);
}

.ai-product-image {
  position: relative;
  height: 92px;
  padding: 8px;
  overflow: hidden;
  background: linear-gradient(145deg, #f8faf9, #edf3ef);
}

.ai-product-image img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: contain;
  mix-blend-mode: multiply;
}

.ai-product-image > span {
  position: absolute;
  top: 7px;
  left: 7px;
  padding: 4px 6px;
  border-radius: 6px;
  background: rgba(23, 61, 43, .92);
  color: #f8cb46;
  font-size: 6.5px;
  font-weight: 900;
  letter-spacing: .45px;
}

.ai-product-info {
  padding: 9px;
}

.ai-product-info > small {
  display: block;
  overflow: hidden;
  color: #238052;
  font-size: 7px;
  font-weight: 850;
  letter-spacing: .18px;
  text-overflow: ellipsis;
  text-transform: uppercase;
  white-space: nowrap;
}

.ai-product-info > strong {
  min-height: 30px;
  margin-top: 4px;
  overflow: hidden;
  display: -webkit-box;
  color: #18281f;
  font-size: 11px;
  font-weight: 850;
  line-height: 1.32;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.ai-product-info > p {
  margin: 3px 0 0;
  overflow: hidden;
  color: #7c8981;
  font-size: 8px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ai-product-footer {
  min-height: 30px;
  margin-top: 9px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.ai-product-footer > b {
  color: #17261e;
  font-size: 12px;
  font-weight: 900;
}

.ai-product-add {
  min-width: 58px;
  height: 30px;
  padding: 0 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid #1f7a4d;
  border-radius: 9px;
  background: #eff9f2;
  color: #1f7a4d;
  font-size: 9px;
  font-weight: 900;
}

.ai-product-add b {
  font-size: 15px;
  font-weight: 700;
  line-height: 1;
}

.ai-product-add:active,
.ai-product-quantity button:active {
  transform: scale(.94);
}

.ai-product-quantity {
  height: 30px;
  min-width: 70px;
  display: grid;
  grid-template-columns: 25px minmax(20px, 1fr) 25px;
  align-items: center;
  overflow: hidden;
  border-radius: 9px;
  background: #1f7a4d;
  color: #ffffff;
}

.ai-product-quantity button {
  height: 100%;
  display: grid;
  place-items: center;
  color: #ffffff;
  font-size: 14px;
  font-weight: 800;
}

.ai-product-quantity strong {
  text-align: center;
  font-size: 10px;
  font-weight: 900;
}

.ai-form {
  flex: 0 0 auto;
  padding: 10px 10px calc(10px + env(safe-area-inset-bottom));
  display: flex;
  align-items: flex-end;
  gap: 8px;
  border-top: 1px solid var(--border);
  background: #ffffff;
}

.ai-form textarea {
  flex: 1;
  min-width: 0;
  width: 100%;
  min-height: 42px;
  height: 42px;
  max-height: 84px;
  padding: 10px 13px;
  overflow-y: auto;
  resize: none;
  border: 0;
  outline: 0;
  border-radius: 22px;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-size: 14px;
  line-height: 22px;
  -webkit-user-select: text;
  user-select: text;
  -webkit-appearance: none;
  appearance: none;
}

.ai-form textarea::placeholder {
  color: #7d817f;
}

.ai-form button {
  flex: 0 0 auto;
  height: 42px;
  padding: 0 15px;
  border-radius: 999px;
  background: var(--ink);
  color: #ffffff;
  font-size: 13px;
  font-weight: 800;
}

.ai-form button:disabled,
.ai-quick-row button:disabled {
  opacity: 0.55;
}

body.qk-ai-input-focused #bottomNav {
  display: none !important;
}

body[data-secondary-tab="ai"].qk-ai-input-focused {
  height: var(--qk-ai-layout-height, 100dvh);
  min-height: var(--qk-ai-layout-height, 100dvh);
  max-height: var(--qk-ai-layout-height, 100dvh);
}

body[data-secondary-tab="ai"].qk-ai-input-focused #app {
  height: var(--qk-ai-viewport-height, 100dvh);
  min-height: var(--qk-ai-viewport-height, 100dvh);
  max-height: var(--qk-ai-viewport-height, 100dvh);
  transform: translate3d(0, var(--qk-ai-viewport-offset-top, 0px), 0);
  transform-origin: top center;
}

body[data-secondary-tab="ai"].qk-ai-input-focused .app-main {
  padding-bottom: 0 !important;
}

body[data-secondary-tab="ai"].qk-ai-input-focused .ai-view {
  gap: 0;
}

body[data-secondary-tab="ai"].qk-ai-input-focused .ai-quick-row {
  display: none;
}

body[data-secondary-tab="ai"].qk-ai-input-focused .ai-chat-card {
  border-right: 0;
  border-left: 0;
  border-bottom: 0;
  border-radius: 0;
}

body[data-secondary-tab="ai"].qk-ai-input-focused .ai-form {
  padding-bottom: 8px;
}

body[data-secondary-tab="ai"].qk-ai-keyboard-open .secondary-topbar {
  padding-top: 8px;
  padding-bottom: 8px;
}

/* iOS zooms focused form controls below 16px, which also pans the chat page. */
@supports (-webkit-touch-callout: none) {
  .ai-form textarea {
    font-size: 16px;
  }
}

@media (max-height: 720px) {
  .ai-view {
    gap: 8px;
  }

  .ai-hero-card {
    padding: 13px 16px;
  }

  .ai-hero-card h2 {
    margin-top: 9px;
    font-size: 21px;
  }

  .ai-hero-card p {
    font-size: 12px;
    line-height: 1.35;
  }

  .ai-quick-row button {
    padding: 8px 11px;
    font-size: 11.5px;
  }
}

@media (max-width: 360px) {
  .ai-hero-card h2 {
    font-size: 20px;
  }

  .ai-message {
    max-width: 90%;
  }
}
