/* Bizport chat: RTL, phone first, system fonts only (no CDN). */

:root {
  --ink: #17202b;
  --muted: #5d6b7a;
  --line: #dfe4ea;
  --bg: #eef1f5;
  --surface: #ffffff;
  --brand: #1b3a5c;
  --brand-hover: #244b75;
  --brand-soft: #e6edf5;
  --user: #1b3a5c;
  --user-ink: #ffffff;
  --agent: #ffffff;
  --error-bg: #fdecec;
  --error-ink: #a12222;
  --error-line: #f3c4c4;
  --radius: 16px;
  --app-height: 100vh;
  color-scheme: light;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", "Noto Sans Hebrew", "Arial Hebrew", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}

[hidden] { display: none !important; }

/* 100dvh follows the phone's address bar; --app-height (set from app.js)
   follows the keyboard, so the message box stays visible while typing. */
.app {
  height: 100vh;
  height: 100dvh;
  max-height: var(--app-height);
  display: flex;
  flex-direction: column;
}

/* ---------- login and name cards ---------- */
.screen-card {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
  overflow-y: auto;
}

.card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 28px 24px;
  box-shadow: 0 10px 30px rgba(23, 32, 43, 0.06);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 8px;
}
.brand h1 {
  margin: 0;
  font-size: 1.2rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}
.brand-mark {
  flex: none;
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: var(--brand);
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 1.15rem;
}
.brand-mark-small { width: 34px; height: 34px; border-radius: 10px; font-size: 1rem; }

.card-text { margin: 0; color: var(--muted); font-size: 0.95rem; }

.field-label { font-weight: 600; font-size: 0.95rem; }
.field-label-big { font-size: 1.1rem; }

.field {
  width: 100%;
  font: inherit;
  font-size: 16px; /* 16px stops phones from zooming in */
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fbfcfd;
  color: var(--ink);
}
.field:focus, .composer-input:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(27, 58, 92, 0.15);
  background: #fff;
}

.form-error {
  margin: 0;
  color: var(--error-ink);
  background: var(--error-bg);
  border: 1px solid var(--error-line);
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 0.92rem;
}

/* ---------- buttons ---------- */
.btn {
  font: inherit;
  font-size: 16px;
  font-weight: 600;
  border: 0;
  border-radius: 12px;
  padding: 12px 18px;
  cursor: pointer;
  touch-action: manipulation;
}
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn:focus-visible { outline: 3px solid rgba(27, 58, 92, 0.35); outline-offset: 2px; }
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--brand-hover); }
.btn-ghost {
  background: var(--brand-soft);
  color: var(--brand);
  padding: 8px 14px;
  font-size: 15px;
}
.btn-ghost:hover { background: #d9e4f0; }

/* ---------- chat ---------- */
.screen-chat {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 820px;
  margin: 0 auto;
  background: var(--bg);
}
@media (min-width: 821px) {
  .screen-chat { border-inline: 1px solid var(--line); }
}

.chat-header {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  padding-top: max(10px, env(safe-area-inset-top));
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.chat-title { display: flex; align-items: center; gap: 10px; min-width: 0; }
.chat-store { font-weight: 700; font-size: 0.98rem; }
.chat-user {
  color: var(--muted);
  font-size: 0.85rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 50vw;
}

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

.note {
  align-self: center;
  text-align: center;
  max-width: 520px;
  color: var(--muted);
  font-size: 0.9rem;
  background: rgba(255, 255, 255, 0.6);
  border-radius: 12px;
  padding: 8px 14px;
}

.row { display: flex; flex-direction: column; max-width: 85%; }
.row-agent { align-self: flex-start; align-items: flex-start; }  /* right side in RTL */
.row-user { align-self: flex-end; align-items: flex-end; }       /* left side in RTL */

.bubble {
  padding: 10px 14px;
  border-radius: var(--radius);
  white-space: pre-wrap;
  unicode-bidi: plaintext; /* each line follows its own language direction */
  text-align: start;
  overflow-wrap: anywhere;
  word-break: break-word;
}
.bubble-user {
  background: var(--user);
  color: var(--user-ink);
  border-end-end-radius: 6px;
}
.bubble-agent {
  background: var(--agent);
  border: 1px solid var(--line);
  border-end-start-radius: 6px;
}
.bubble-error {
  background: var(--error-bg);
  color: var(--error-ink);
  border: 1px solid var(--error-line);
  border-end-start-radius: 6px;
}

.row-failed .bubble-user { opacity: 0.6; }
.not-sent {
  margin-top: 4px;
  font-size: 0.8rem;
  color: var(--error-ink);
}

.agent-wrap { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; }
.meta { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding-inline-start: 4px; }

.tag {
  font-size: 0.78rem;
  font-weight: 600;
  padding: 2px 10px;
  border-radius: 999px;
  background: #eceff3;
  color: #44505d;
}
.cat-stock { background: #e3f4ea; color: #1d6b3d; }
.cat-shipping { background: #e2eefb; color: #1e5594; }
.cat-support { background: #fdf0dc; color: #8a5300; }

.handed { font-size: 0.8rem; color: var(--muted); }
.handed::before { content: "\2713\00a0"; color: #1d6b3d; }

.bubble-thinking { display: inline-flex; align-items: center; gap: 8px; color: var(--muted); }
.dots { display: inline-flex; gap: 4px; }
.dots i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--muted);
  opacity: 0.3;
  animation: blink 1.2s infinite ease-in-out;
}
.dots i:nth-child(2) { animation-delay: 0.2s; }
.dots i:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink { 0%, 80%, 100% { opacity: 0.25; } 40% { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .dots i { animation: none; opacity: 0.6; } }

/* ---------- sample messages (for testing) ---------- */
.samples {
  flex: none;
  background: var(--surface);
  border-top: 1px solid var(--line);
  padding: 6px 12px 0;
}
.samples-toggle {
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  color: var(--brand);
  background: transparent;
  border: 0;
  border-radius: 8px;
  padding: 4px 8px;
  cursor: pointer;
  touch-action: manipulation;
}
.samples-toggle::after { content: "\25BE"; margin-inline-start: 6px; display: inline-block; transition: transform 0.15s; }
.samples-toggle.is-open::after { transform: rotate(180deg); }
.samples-toggle:hover { background: var(--brand-soft); }
.samples-toggle:focus-visible, .chip:focus-visible { outline: 3px solid rgba(27, 58, 92, 0.35); outline-offset: 2px; }

.samples-panel {
  max-height: min(40vh, 320px);
  max-height: min(40dvh, 320px);
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 6px 2px 8px;
}
.samples-note {
  margin: 0 0 8px;
  font-size: 0.8rem;
  color: var(--muted);
}
.samples-group + .samples-group { margin-top: 10px; }
.samples-title {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--muted);
  margin-bottom: 6px;
}
.samples-list { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  font: inherit;
  font-size: 14px;
  line-height: 1.35;
  text-align: start;
  unicode-bidi: plaintext;
  color: var(--ink);
  background: var(--brand-soft);
  border: 1px solid #d3deea;
  border-radius: 999px;
  padding: 6px 12px;
  max-width: 100%;
  cursor: pointer;
  touch-action: manipulation;
}
.chip:hover { background: #d9e4f0; border-color: #c2d2e3; }
.samples + .composer { border-top: 0; padding-top: 6px; }

/* ---------- composer ---------- */
.composer {
  flex: none;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 12px;
  padding-bottom: max(10px, env(safe-area-inset-bottom));
  background: var(--surface);
  border-top: 1px solid var(--line);
}
.composer-input {
  flex: 1;
  min-width: 0;
  font: inherit;
  font-size: 16px;
  line-height: 1.4;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fbfcfd;
  color: var(--ink);
  resize: none;
  overflow-y: hidden;
  max-height: 140px;
}
.composer-send { flex: none; padding: 10px 18px; }
