/* ============================================================
   Mahmoud AI — chatbot panel
   Lazy-loaded on first click. The launcher button itself is
   styled in layout.css so it exists before this file arrives.
   Shares the site's tokens — the CV page mirrors them too.
   ============================================================ */

.bot {
  position: fixed;
  inset-block-end: 24px;
  inset-inline-end: 24px;
  z-index: var(--z-chat);
  width: min(400px, calc(100vw - 32px));
  height: min(620px, calc(100dvh - 104px));
  display: flex;
  flex-direction: column;
  border-radius: var(--r);
  border: 1px solid var(--rule-2);
  background: var(--paper);
  color: var(--ink);
  box-shadow: var(--shadow-over);
  overflow: hidden;
  opacity: 0;
  transform: translateY(12px);
  transition: opacity 0.24s var(--ease), transform 0.24s var(--ease);
}
.bot.is-open { opacity: 1; transform: none; }

/* ── Title bar ────────────────────────────────────────────── */
.bot__bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 12px 12px 14px;
  border-bottom: 1px solid var(--rule);
  background: var(--paper-3);
  flex-shrink: 0;
}
/* The whole mascot, as on the launcher — transparent, never cropped. */
.bot__avatar {
  position: relative;
  width: 32px; height: 48px;
  flex-shrink: 0;
}
.bot__avatar img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
.bot__id { display: grid; line-height: 1.25; min-width: 0; }
.bot__id b { font-family: var(--font-display); font-size: 1.12rem; font-weight: 400; }
.bot__id small { font-size: 0.72rem; color: var(--ink-3); }
.bot__x {
  margin-inline-start: auto;
  width: 34px; height: 34px;
  display: grid;
  place-items: center;
  border-radius: var(--r);
  border: 1px solid transparent;
  color: var(--ink-2);
  transition: color var(--t-fast), border-color var(--t-fast);
}
.bot__x:hover { color: var(--ink); border-color: var(--rule-2); }

/* ── Setup screen ─────────────────────────────────────────── */
.bot__setup { padding: 20px 18px 22px; overflow-y: auto; flex: 1; }
.bot__setup-h { font-family: var(--font-display); font-size: 1.34rem; font-weight: 400; line-height: 1.2; margin-bottom: 6px; }
.bot__setup-lead { font-size: 0.82rem; color: var(--ink-2); line-height: 1.65; margin-bottom: 14px; }

.bot__label {
  display: block;
  margin: 14px 0 6px;
  font-family: var(--font-mono);
  font-size: 0.68rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-3);
}
.bot__input {
  width: 100%;
  padding: 10px 12px;
  border-radius: var(--r);
  border: 1px solid var(--control);
  background: var(--paper-3);
  color: var(--ink);
  font-size: 0.88rem;
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
.bot__input:focus { outline: none; border-color: var(--ink); box-shadow: 0 0 0 1px var(--ink); }
select.bot__input {
  appearance: none;
  cursor: pointer;
  padding-inline-end: 36px;
  background-image: var(--select-arrow);
  background-repeat: no-repeat;
  background-position: right 13px center;
}
html[dir='rtl'] select.bot__input { background-position: left 13px center; }
.bot__input--custom { margin-top: 8px; font-family: var(--font-mono); font-size: 0.8rem; }

.bot__note { font-size: 0.72rem; color: var(--ink-3); margin-top: 6px; line-height: 1.5; }

.bot__key-row { display: flex; gap: 8px; }
.bot__key-row .bot__input { font-family: var(--font-mono); letter-spacing: 0.04em; }
.bot__peek {
  flex-shrink: 0;
  padding: 0 13px;
  border-radius: var(--r);
  border: 1px solid var(--control);
  font-size: 0.74rem;
  color: var(--ink-2);
  transition: color var(--t-fast), border-color var(--t-fast);
}
.bot__peek:hover { color: var(--ink); border-color: var(--ink); }

.bot__getkey {
  display: inline-block;
  margin-top: 8px;
  font-size: 0.75rem;
  color: var(--ink);
  text-decoration: underline;
  text-decoration-color: var(--rule-2);
  text-underline-offset: 0.22em;
  transition: text-decoration-color var(--t-fast);
}
.bot__getkey:hover { text-decoration-color: var(--gold); }

.bot__err { font-size: 0.76rem; color: var(--danger); min-height: 1.1em; margin-top: 10px; }

.bot__start {
  width: 100%;
  margin-top: 8px;
  padding: 12px;
  border-radius: var(--r);
  background: var(--btn-bg);
  color: var(--btn-fg);
  font-size: 0.9rem;
  font-weight: 600;
  transition: background-color var(--t-fast);
}
.bot__start:hover { background: var(--btn-hover); }

.bot__privacy {
  margin-top: 16px;
  padding: 11px 13px;
  border-radius: var(--r);
  border: 1px solid var(--rule);
  background: var(--paper-2);
  font-size: 0.72rem;
  line-height: 1.65;
  color: var(--ink-2);
}
/* The padlock pictogram, set in ink like every other glyph on the site. */
.bot__privacy > span[aria-hidden] { filter: grayscale(1); opacity: 0.75; }

/* ── Chat screen ──────────────────────────────────────────── */
.bot__chat { display: flex; flex-direction: column; flex: 1; min-height: 0; }

.bot__log {
  flex: 1;
  overflow-y: auto;
  padding: 16px 16px 6px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scrollbar-width: thin;
}
.bot__log::-webkit-scrollbar { width: 6px; }
.bot__log::-webkit-scrollbar-thumb { background: var(--rule-2); border-radius: 3px; border: none; }

.msg { display: flex; }
.msg--user { justify-content: flex-end; }

.msg__bubble {
  max-width: 88%;
  padding: 10px 13px;
  border-radius: var(--r);
  font-size: 0.85rem;
  line-height: 1.66;
  word-wrap: break-word;
  overflow-wrap: anywhere;
}
.msg--bot .msg__bubble {
  background: var(--paper-3);
  border: 1px solid var(--rule);
  color: var(--ink);
}
.msg--user .msg__bubble { background: var(--ink); color: var(--paper); }
.msg--error .msg__bubble {
  max-width: 100%;
  background: color-mix(in srgb, var(--danger) 8%, transparent);
  border: 1px solid color-mix(in srgb, var(--danger) 40%, transparent);
  color: var(--danger);
  font-size: 0.8rem;
}

/* Rendered markdown inside a bot bubble */
.msg--bot .msg__bubble > *:first-child { margin-top: 0; }
.msg--bot .msg__bubble > *:last-child { margin-bottom: 0; }
.msg--bot .msg__bubble p { margin: 0 0 8px; }
.msg--bot .msg__bubble h3,
.msg--bot .msg__bubble h4,
.msg--bot .msg__bubble h5,
.msg--bot .msg__bubble h6 {
  margin: 10px 0 5px;
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 500;
  color: var(--ink);
}
.msg--bot .msg__bubble ul,
.msg--bot .msg__bubble ol { margin: 0 0 8px; padding-inline-start: 18px; }
.msg--bot .msg__bubble li { margin-bottom: 4px; list-style: disc; }
.msg--bot .msg__bubble ol li { list-style: decimal; }
.msg--bot .msg__bubble li::marker { color: var(--ink-3); }
.msg--bot .msg__bubble strong { font-weight: 600; }
.msg--bot .msg__bubble a {
  color: var(--ink);
  text-decoration: underline;
  text-decoration-color: var(--gold);
  text-underline-offset: 0.2em;
}
.msg--bot .msg__bubble code {
  font-family: var(--font-mono);
  font-size: 0.8em;
  padding: 1px 5px;
  border-radius: 2px;
  background: var(--paper-2);
  border: 1px solid var(--rule);
}
.msg--bot .msg__bubble pre {
  margin: 8px 0;
  padding: 10px 12px;
  border-radius: var(--r);
  background: var(--paper-2);
  border: 1px solid var(--rule);
  overflow-x: auto;
}
.msg--bot .msg__bubble pre code { padding: 0; border: none; background: none; font-size: 0.76rem; line-height: 1.6; }

/* Typing dots */
.msg--typing .msg__bubble { display: flex; gap: 5px; padding: 14px; }
.msg--typing .dot {
  width: 5px; height: 5px;
  border-radius: 50%;
  background: var(--ink-3);
  animation: bot-dot 1.3s var(--ease-soft) infinite;
}
.msg--typing .dot:nth-child(2) { animation-delay: 0.16s; }
.msg--typing .dot:nth-child(3) { animation-delay: 0.32s; }
@keyframes bot-dot {
  0%, 60%, 100% { opacity: 0.3; transform: translateY(0); }
  30%           { opacity: 1;   transform: translateY(-3px); }
}

/* Suggestions */
.bot__suggest { display: flex; flex-wrap: wrap; gap: 6px; padding: 6px 16px 10px; }
.bot__suggest button {
  padding: 6px 10px;
  border-radius: var(--r);
  border: 1px solid var(--rule-2);
  font-size: 0.74rem;
  color: var(--ink-2);
  text-align: start;
  transition: color var(--t-fast), border-color var(--t-fast);
}
.bot__suggest button:hover { color: var(--ink); border-color: var(--ink); }

/* Composer */
.bot__compose {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid var(--rule);
  flex-shrink: 0;
}
.bot__field {
  flex: 1;
  resize: none;
  max-height: 128px;
  padding: 10px 12px;
  border-radius: var(--r);
  border: 1px solid var(--control);
  background: var(--paper-3);
  color: var(--ink);
  font-size: 0.86rem;
  line-height: 1.5;
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
.bot__field:focus { outline: none; border-color: var(--ink); box-shadow: 0 0 0 1px var(--ink); }
.bot__field:disabled { opacity: 0.55; }

.bot__send {
  flex-shrink: 0;
  width: 40px; height: 40px;
  display: grid;
  place-items: center;
  border-radius: var(--r);
  background: var(--ink);
  color: var(--paper);
  transition: background-color var(--t-fast), opacity var(--t-fast);
}
.bot__send:hover:not(:disabled) { background: var(--btn-hover); }
.bot__send:disabled { opacity: 0.4; cursor: not-allowed; }
html[dir='rtl'] .bot__send svg { transform: scaleX(-1); }

/* Footer */
.bot__foot {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  padding: 0 14px 12px;
  flex-shrink: 0;
}
.bot__ghost {
  font-size: 0.7rem;
  color: var(--ink-3);
  text-decoration: underline;
  text-decoration-color: transparent;
  text-underline-offset: 0.2em;
  transition: color var(--t-fast), text-decoration-color var(--t-fast);
}
.bot__ghost:hover { color: var(--ink); text-decoration-color: var(--gold); }
.bot__mini { margin-inline-start: auto; font-size: 0.66rem; color: var(--ink-3); }

/* ── Mobile: full-screen sheet ────────────────────────────── */
@media (max-width: 620px) {
  .bot {
    inset: 0;
    width: 100%;
    height: 100dvh;
    max-height: none;
    border-radius: 0;
    border: none;
    transform: translateY(24px);
  }
  .bot.is-open { transform: none; }
  .bot__bar { padding-top: max(12px, env(safe-area-inset-top)); }
  .bot__compose { padding-bottom: max(10px, env(safe-area-inset-bottom)); }
  .msg__bubble { max-width: 92%; font-size: 0.9rem; }
}

@media (prefers-reduced-motion: reduce) {
  .bot { transition: opacity 0.01ms; transform: none; }
  .msg--typing .dot { animation: none; opacity: 0.6; }
}
