/* /ai page — iLEKS assistant panel, full screen. Ported from ileks.vivotik.net/assets/style.css. */
:root {
  --ink: #131921;
  --ileks-orange: #ff7a1a;
  --ileks-orange-dark: #d4600a;
  --ileks-orange-light: #ffb347;
  --ileks-orange-pale: #fff1e0;
  --ileks-orange-pale-2: #ffe3bd;
  --bg: #f4f5f7;
  --border: #e2e5eb;
  --text: #17181c;
  --text-soft: #565c66;
  --success: #0f9d58;
  --shadow-lg: 0 12px 32px rgba(20, 20, 30, 0.18);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --keyboard-inset: 0px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body.ileks-ai-page {
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  overscroll-behavior: none;
  font-family: "Inter", "Open Sans", Roboto, "Segoe UI", -apple-system, BlinkMacSystemFont, Tahoma, Arial, sans-serif;
}
img { max-width: 100%; display: block; }
a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; }

/* ---------- Panel ---------- */
.side-panel {
  position: fixed;
  inset: 0;
  margin: 0 auto;
  width: min(860px, 100vw);
  background: #fff;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
}

.panel-header {
  padding: 16px 18px;
  padding-top: calc(16px + var(--safe-top));
  background: linear-gradient(135deg, var(--ileks-orange), var(--ileks-orange-light));
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-shrink: 0;
}
.panel-header .title { font-weight: 800; font-size: 17px; display: flex; align-items: center; gap: 8px; }
.panel-header .sub { font-size: 12.5px; opacity: 0.85; margin-top: 3px; }
.panel-header .close-btn {
  background: rgba(255,255,255,0.2); border: none; color: #fff;
  width: 44px; height: 44px; border-radius: 50%; font-size: 18px; flex-shrink: 0;
  display: inline-flex; align-items: center; justify-content: center;
}

.panel-tools { display: flex; align-items: center; gap: 6px; }
.panel-tools .tool-btn {
  background: rgba(255,255,255,.12); color: #fff; border: 0; border-radius: 8px;
  height: 32px; min-width: 32px; padding: 0 8px; font-size: 14px;
  display: inline-flex; align-items: center;
}
.panel-tools .tool-btn:hover { background: rgba(255,255,255,.22); }
.panel-tools .chat-cart-btn { gap: 5px; }
.chat-cart-count {
  min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px;
  background: #fff; color: var(--ileks-orange-dark); font-size: 11.5px; font-weight: 800;
  display: inline-flex; align-items: center; justify-content: center;
}
.chat-cart-count[hidden] { display: none; }

.chat-history { border-bottom: 1px solid var(--border); background: #f6f7f9; max-height: 40%; overflow: auto; flex-shrink: 0; }
.chat-history .h-title { font-size: 12px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: var(--text-soft); padding: 10px 14px 4px; }
.chat-history .h-item { display: flex; justify-content: space-between; gap: 10px; width: 100%; text-align: start; background: none; border: 0; border-top: 1px solid var(--border); padding: 9px 14px; font: inherit; color: inherit; }
.chat-history .h-item:hover { background: rgba(0,0,0,.04); }
.chat-history .h-item .q { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-history .h-item .d { color: var(--text-soft); font-size: 12px; white-space: nowrap; }
.chat-history .h-empty { padding: 12px 14px; color: var(--text-soft); font-size: 13px; }

/* ---------- Messages ---------- */
.chat-log {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: #fffaf5;
}
.msg { max-width: 88%; padding: 11px 14px; border-radius: 12px; font-size: 15.5px; line-height: 1.65; }
.msg.user { align-self: flex-end; background: var(--ileks-orange); color: #fff; border-end-end-radius: 3px; white-space: pre-wrap; }
.msg.assistant { align-self: flex-start; background: #fff; border: 1px solid var(--border); border-end-start-radius: 3px; }
.msg.system-note { align-self: center; font-size: 13px; color: var(--text-soft); background: none; white-space: pre-wrap; }

.msg.assistant p { margin: 0 0 8px; }
.msg.assistant p:last-child { margin-bottom: 0; }
.msg.assistant ul, .msg.assistant ol { margin: 0 0 8px; padding-inline-start: 1.3em; }
.msg.assistant ul:last-child, .msg.assistant ol:last-child { margin-bottom: 0; }
.msg.assistant li { margin: 2px 0; }
.msg.assistant code { background: #f2f2f2; border-radius: 4px; padding: 1px 5px; font-size: 0.92em; }
.msg.assistant a { color: var(--ileks-orange); text-decoration: underline; }
.md-table-wrap { overflow-x: auto; margin-bottom: 8px; }
.md-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.md-table th, .md-table td { text-align: start; padding: 6px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.md-table th { font-weight: 700; }

/* ---------- Product cards in chat ---------- */
.chat-products { display: flex; flex-direction: column; gap: 8px; align-self: stretch; }
.chat-product {
  display: flex; gap: 10px; background: #fff; border: 1px solid var(--border);
  border-radius: 10px; padding: 8px; align-items: center;
}
.chat-product .product-link { display: flex; gap: 10px; align-items: center; flex: 1; min-width: 0; }
.chat-product .thumb { width: 58px; height: 58px; flex-shrink: 0; background: #fafafa; border-radius: 6px; display: flex; align-items: center; justify-content: center; overflow: hidden; }
.chat-product .thumb img { width: 100%; height: 100%; object-fit: contain; }
.chat-product .info { flex: 1; min-width: 0; }
.chat-product .info .name { font-size: 14.5px; font-weight: 600; line-height: 1.35; }
.chat-product .product-link:hover .name { color: var(--ileks-orange-dark); }
.chat-product .info .price { font-size: 15px; font-weight: 800; color: var(--ileks-orange-dark); margin-top: 3px; }
.ref-tag {
  display: inline-block; margin-inline-end: 6px; padding: 0 6px; border-radius: 6px;
  background: var(--ileks-orange-pale); color: var(--ileks-orange-dark);
  font-size: 12px; font-weight: 700; line-height: 18px; vertical-align: 1px;
  font-variant-numeric: tabular-nums;
}
.chat-product .add-mini {
  background: var(--ink); color: #fff; border: none; border-radius: 6px; font-size: 12.5px; padding: 7px 11px; flex-shrink: 0;
}
.chat-product .add-mini.added { background: var(--success); }
.chat-product .compare-mini {
  background: #fff; color: var(--ink); border: 1px solid var(--border); border-radius: 6px; font-size: 12.5px; padding: 7px 11px; flex-shrink: 0;
}
.chat-product .chat-actions { display: flex; flex-direction: column; gap: 4px; flex-shrink: 0; }
.chat-products .compare-these {
  align-self: stretch;
  background: var(--ileks-orange-pale); color: var(--ileks-orange-dark); border: 1px solid var(--ileks-orange-pale-2);
  border-radius: 8px; padding: 9px; font-size: 13.5px; font-weight: 700;
}
.chat-products-compare { flex-direction: row; gap: 8px; flex-wrap: wrap; }
.chat-products-compare .compare-pic { flex-direction: column; align-items: stretch; flex: 1; min-width: 110px; text-align: center; }
.chat-products-compare .compare-pic .product-link { flex-direction: column; align-items: stretch; }
.chat-products-compare .compare-pic .thumb { width: 100%; height: 84px; }
.chat-products-compare .compare-pic .info .name {
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.chat-products-compare .compare-these { flex-basis: 100%; }

/* ---------- Suggestions + input ---------- */
.suggestions { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 16px 12px; flex-shrink: 0; background: #fffaf5; }
.suggestions button {
  background: var(--ileks-orange-pale); color: var(--ileks-orange-dark); border: 1px solid var(--ileks-orange-pale-2);
  border-radius: 20px; padding: 10px 14px; font-size: 13.5px; min-height: 44px;
}
.suggestions button:hover { background: #ffd9a3; }
html.keyboard-open .suggestions { display: none; }

.chat-input-row {
  display: flex; gap: 8px; align-items: center;
  padding: 12px 14px;
  padding-bottom: calc(12px + var(--safe-bottom));
  border-top: 1px solid var(--border); background: #fff;
  flex-shrink: 0;
}
html.keyboard-open .chat-input-row { padding-bottom: 12px; }
html.keyboard-open .panel-header { padding-top: 16px; }
/* Must stay >= 16px: iOS Safari zooms the page on focus otherwise. */
.chat-input-row input {
  flex: 1; border: 1px solid var(--border); border-radius: 20px; padding: 11px 16px; font-size: 16px; outline: none; font-family: inherit;
}
.chat-input-row input:focus { border-color: var(--ileks-orange); }
.chat-input-row button {
  background: var(--ileks-orange); color: #fff; border: none; border-radius: 50%;
  width: 44px; height: 44px; font-size: 16px; flex-shrink: 0;
}
[dir="rtl"] .chat-input-row button { transform: scaleX(-1); }
.chat-input-row button:disabled { opacity: 0.5; }

.typing-indicator { display: flex; align-items: center; gap: 8px; }
.typing-text { font-size: 13.5px; color: var(--text-soft); }
.typing-dots { display: inline-flex; gap: 3px; align-items: center; padding: 2px 4px; }
.typing-dots span { width: 6px; height: 6px; border-radius: 50%; background: var(--ileks-orange); opacity: 0.4; animation: ileks-bounce 1.2s infinite; }
.typing-dots span:nth-child(2) { animation-delay: .15s; }
.typing-dots span:nth-child(3) { animation-delay: .3s; }
@keyframes ileks-bounce { 0%, 60%, 100% { opacity: .35; transform: translateY(0); } 30% { opacity: 1; transform: translateY(-3px); } }

.empty-state { text-align: center; padding: 40px; color: var(--text-soft); font-size: 13px; }

/* ---------- Toast + compare modal ---------- */
.ileks-toast {
  position: fixed;
  left: 50%;
  bottom: calc(90px + var(--safe-bottom) + var(--keyboard-inset));
  transform: translateX(-50%) translateY(16px);
  background: var(--ink);
  color: #fff;
  padding: 10px 16px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  z-index: 120;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease, transform .2s ease;
  box-shadow: var(--shadow-lg);
}
.ileks-toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.compare-modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(15,15,20,0.45);
  display: none;
  place-items: center;
  padding: 18px;
}
.compare-modal.is-open { display: grid; }
.compare-sheet {
  width: min(920px, 100%);
  max-height: min(88vh, 900px);
  overflow: auto;
  background: #fff;
  border-radius: 14px;
  box-shadow: var(--shadow-lg);
  padding: 16px 18px 22px;
}
.compare-top {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  margin-bottom: 14px; position: sticky; top: 0; background: #fff; z-index: 2; padding-bottom: 8px;
}
.compare-top h2 { margin: 0; font-size: 18px; }
.compare-top .close-btn { background: #f3f4f6; border: none; width: 32px; height: 32px; border-radius: 50%; font-size: 16px; }
.compare-explain {
  background: var(--ileks-orange-pale); border: 1px solid var(--ileks-orange-pale-2); border-radius: 10px;
  padding: 12px 14px; margin-bottom: 14px; font-size: 15.5px; line-height: 1.65; color: var(--text);
}
.compare-explain p { margin: 0 0 8px; }
.compare-explain p:last-child { margin-bottom: 0; }
.compare-explain ul, .compare-explain ol { margin: 0 0 8px; padding-inline-start: 1.3em; }
.compare-explain li { margin: 2px 0; }
.compare-heads { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 14px; }
.compare-card { border: 1px solid var(--border); border-radius: 10px; padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.compare-card img { height: 120px; object-fit: contain; }
.compare-card .cname { font-size: 14.5px; font-weight: 700; line-height: 1.35; }
.compare-card .cprice { font-size: 17px; font-weight: 800; }
.compare-card .add-btn { background: var(--ink); color: #fff; border: none; border-radius: 6px; padding: 9px; font-size: 13.5px; font-weight: 600; }
.compare-card .add-btn.added { background: var(--success); }
.compare-table { width: 100%; border-collapse: collapse; font-size: 14px; font-variant-numeric: tabular-nums; }
.compare-table th, .compare-table td { text-align: start; padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
.compare-table th { color: var(--text-soft); font-weight: 600; width: 22%; }
.compare-table tr.diff td { background: #fff6ea; }

@media (max-width: 720px) {
  .side-panel { width: 100%; box-shadow: none; }
  .panel-header .sub { display: none; }

  .chat-product { flex-wrap: wrap; align-items: flex-start; }
  .chat-product .chat-actions { flex-direction: row; width: 100%; }
  .chat-product .add-mini, .chat-product .compare-mini { flex: 1; min-height: 44px; }

  .suggestions { flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; padding: 0 12px 8px; }
  .suggestions button { white-space: nowrap; }

  .compare-modal { padding: 0; align-items: stretch; }
  .compare-sheet { width: 100%; max-height: 100dvh; height: 100dvh; border-radius: 0; padding-bottom: calc(22px + var(--safe-bottom)); }
  .compare-heads { grid-template-columns: 1fr; }
  .compare-top .close-btn { width: 44px; height: 44px; }
}
