/* ============================================================
   The AI Assistant page (/get-matched): a full-page chat layout, in the style of modern chat apps.
   Markup: app/Views/match/assistant_page.php. Behaviour: js/assistant_chat.js.
   Loaded after css/assistant_chat.css, whose message styles (kda-*) it restyles for the page.
   Everything is scoped under .kdc so nothing here touches the rest of the site.

   Two states, switched by the script with the class kdc--chat on .kdc:
     start screen   (no class)   a heading, one big input, the visitor's city, a card per profession
     conversation   (kdc--chat)  the thread fills the page; the input stays at the bottom of the window
   The page itself scrolls (no box inside the page), so it behaves the same with a phone's keyboard open.
   ============================================================ */

.kdc {
  --kda-blue: var(--kd-blue, #1e5baa);
  --kda-orange: var(--kd-orange, #f47b20);
  --kda-ink: #111827;
  --kda-text: #374151;
  --kda-muted: #6b7280;
  --kda-line: #e5e7eb;
  --kda-soft: #f5f7fa;
  --kdc-col: 780px;

  display: flex;
  flex-direction: column;
  min-height: calc(100vh - 120px);            /* the site's top strip + sticky header */
  min-height: calc(100svh - 120px);
  background: #ffffff;
  font-family: 'Poppins', system-ui, -apple-system, 'Segoe UI', sans-serif;
  color: var(--kda-text);
}

/* the site's floating "Need help" and back-to-top buttons would sit on top of the input */
body.kdc-page .kd-sticky-help,
body.kdc-page .back-to-top { display: none !important; }

.kdc__stage {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: var(--kdc-col);
  margin: 0 auto;
  padding: 0 16px;
  box-sizing: border-box;
}

/* ---------- start screen ---------- */

.kdc__hero { text-align: center; padding-top: 8px; }

.kdc__badge {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 5px 13px;
  border-radius: 999px;
  background: #eaf1fb;
  color: var(--kda-blue);
  font-size: 13px;
  font-weight: 600;
}
.kdc__badge svg { width: 15px; height: 15px; }

.kdc__title {
  margin: 16px 0 10px;
  font-size: clamp(28px, 4.4vw, 42px);
  font-weight: 600;
  line-height: 1.2;
  letter-spacing: -0.01em;
  color: var(--kda-ink);
}

.kdc__sub {
  margin: 0 auto 26px;
  max-width: 560px;
  font-size: 15.5px;
  line-height: 1.65;
  color: var(--kda-muted);
}

.kdc:not(.kdc--chat) .kdc__stage { justify-content: center; padding-top: 28px; padding-bottom: 36px; }
.kdc:not(.kdc--chat) .kdc__thread { display: none; }

/* ---------- the input ---------- */

.kdc__composer {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 10px 10px 10px 22px;
  border: 1px solid #d3dae4;
  border-radius: 28px;
  background: #ffffff;
  box-shadow: 0 6px 26px rgba(17, 24, 39, 0.08);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.kdc__composer:focus-within { border-color: var(--kda-blue); box-shadow: 0 6px 26px rgba(30, 91, 170, 0.16); }
.kdc:not(.kdc--chat) .kdc__composer { padding-top: 15px; padding-bottom: 15px; }

.kdc__input {
  flex: 1 1 auto;
  min-width: 0;
  max-height: 160px;
  margin: 0;
  padding: 7px 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--kda-ink);
  font: inherit;
  font-size: 16px;                              /* 16px: phones do not zoom the page on focus */
  line-height: 1.5;
  resize: none;
  overflow-y: hidden;
  box-shadow: none;
}
.kdc__input::placeholder { color: #9ca3af; }

.kdc__send {
  flex: 0 0 auto;
  width: 42px;
  height: 42px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--kda-blue);
  color: #ffffff;
  cursor: pointer;
  transition: filter 0.15s ease;
}
.kdc__send:hover { filter: brightness(0.9); }
.kdc__send:disabled { background: #c3cad4; cursor: not-allowed; }
.kdc__send svg { width: 20px; height: 20px; }

.kdc button:focus-visible, .kdc a:focus-visible { outline: 3px solid var(--kda-orange); outline-offset: 2px; }

/* ---------- where, and what to start with ---------- */

.kdc__start { margin-top: 18px; }
.kdc--chat .kdc__start { display: none; }

.kdc__where { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 8px; font-size: 13.5px; color: var(--kda-muted); }

.kdc__citybtn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border: 1px solid #d3dae4;
  border-radius: 999px;
  background: #ffffff;
  color: var(--kda-ink);
  font: inherit;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
}
.kdc__citybtn:hover { border-color: var(--kda-blue); color: var(--kda-blue); }
.kdc__citybtn svg { width: 15px; height: 15px; flex: 0 0 auto; }
.kdc__citybtn .kdc__chev { width: 13px; height: 13px; opacity: 0.7; }

.kdc__citylist { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin: 12px auto 0; max-width: 640px; }
.kdc__citylist[hidden] { display: none; }
.kdc-citychip {
  padding: 6px 13px;
  border: 1px solid var(--kda-line);
  border-radius: 999px;
  background: #ffffff;
  color: var(--kda-text);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}
.kdc-citychip:hover { border-color: var(--kda-blue); color: var(--kda-blue); }
.kdc-citychip.is-on { background: var(--kda-blue); border-color: var(--kda-blue); color: #ffffff; }

.kdc__cards { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-top: 20px; }

.kdc-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 12px;
  padding: 16px 14px 15px;
  border: 1px solid var(--kda-line);
  border-radius: 16px;
  background: #ffffff;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, transform 0.15s ease;
}
.kdc-card:hover { border-color: var(--kda-blue); box-shadow: 0 8px 22px rgba(30, 91, 170, 0.12); transform: translateY(-2px); }

.kdc-ico {
  flex: 0 0 auto;
  width: 38px;
  height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 12px;
  background: #eaf1fb;
  color: var(--kda-blue);
}
.kdc-ico svg { width: 20px; height: 20px; }
.kdc-card:nth-child(4n+2) .kdc-ico { background: #fff1e6; color: #d4630f; }
.kdc-card:nth-child(4n+3) .kdc-ico { background: #e9f7ef; color: #15803d; }
.kdc-card:nth-child(4n+4) .kdc-ico { background: #f2ecfb; color: #6d3fc0; }

.kdc-card__text { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.kdc-card__title { font-size: 14.5px; font-weight: 600; line-height: 1.3; color: var(--kda-ink); }
.kdc-card__blurb { font-size: 12.2px; line-height: 1.45; color: var(--kda-muted); }

/* ---------- the bottom of the stage: the note, and starting over ---------- */

.kdc__foot { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-top: 12px; }
.kdc__note { flex: 1 1 auto; margin: 0; font-size: 11.5px; line-height: 1.5; color: #9ca3af; text-align: center; }
.kdc--chat .kdc__note { text-align: left; }

.kdc__new {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 13px;
  border: 1px solid var(--kda-line);
  border-radius: 999px;
  background: #ffffff;
  color: var(--kda-text);
  font: inherit;
  font-size: 12.5px;
  font-weight: 500;
  cursor: pointer;
}
.kdc__new[hidden] { display: none; }
.kdc__new:hover { border-color: var(--kda-blue); color: var(--kda-blue); }
.kdc__new svg { width: 13px; height: 13px; }

.kdc__browse { margin: 0; padding: 4px 16px 36px; text-align: center; font-size: 13.5px; line-height: 1.9; color: var(--kda-muted); }
.kdc__browse a { margin: 0 2px; color: var(--kda-blue); text-decoration: none; }
.kdc__browse a:hover { text-decoration: underline; }
.kdc--chat .kdc__browse { display: none; }

/* ---------- the conversation ---------- */

.kdc--chat .kdc__thread { flex: 1 1 auto; padding: 26px 0 10px; }

.kdc--chat .kdc__dock {
  position: sticky;
  bottom: 0;
  z-index: 20;
  padding: 22px 0 max(12px, env(safe-area-inset-bottom));
  background: linear-gradient(to top, #ffffff 74%, rgba(255, 255, 255, 0));
}

.kdc .kda-msg { margin: 0 0 28px; scroll-margin-top: 96px; }       /* clear of the sticky site header when scrolled to */
.kdc .kda-msg--user { align-items: flex-end; }

/* what the visitor said: a soft bubble on the right */
.kdc .kda-msg--user .kda-bubble {
  max-width: min(82%, 560px);
  padding: 11px 18px;
  border-radius: 22px;
  background: #eaf1fb;
  color: var(--kda-ink);
  font-size: 15.5px;
}

/* what the assistant says: plain text on the page, with a small mark in the margin */
.kdc .kda-msg--bot { position: relative; padding-left: 46px; }
.kdc .kda-msg--bot::before {
  content: "";
  position: absolute;
  left: 0;
  top: 1px;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--kda-blue) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m12 3-1.9 5.8a2 2 0 0 1-1.3 1.3L3 12l5.8 1.9a2 2 0 0 1 1.3 1.3L12 21l1.9-5.8a2 2 0 0 1 1.3-1.3L21 12l-5.8-1.9a2 2 0 0 1-1.3-1.3L12 3Z'/%3E%3C/svg%3E") center / 17px no-repeat;
}
.kdc .kda-msg--bot .kda-bubble {
  max-width: 100%;
  padding: 4px 0;
  border-radius: 0;
  background: transparent;
  color: var(--kda-ink);
  font-size: 16px;
  line-height: 1.7;
}
.kdc .kda-msg--bot .kda-bubble + .kda-bubble { margin-top: 10px; }
.kdc .kda-bubble--error { padding: 10px 14px !important; border-radius: 12px !important; }
.kdc .kda-ok { padding: 10px 14px !important; border-radius: 12px !important; }

.kdc .kda-typing { padding: 10px 0; background: transparent; }

/* the quick replies: pills under the question they answer */
.kdc .kda-chips { margin-top: 14px; gap: 9px; }
.kdc .kda-chip { padding: 9px 16px; border-color: #cfd8e6; font-size: 14px; }

/* the list of professionals: a card each */
.kdc .kda-criteria { margin: 14px 0 4px; }
.kdc .kda-list { margin: 10px 0 0; width: 100%; border-top: 0; display: grid; gap: 12px; }

.kdc .kda-item {
  grid-template-columns: 30px 60px minmax(0, 1fr) auto;
  gap: 4px 14px;
  align-items: start;
  padding: 16px 16px 15px 12px;
  border: 1px solid var(--kda-line);
  border-radius: 18px;
  background: #ffffff;
  box-shadow: 0 2px 10px rgba(17, 24, 39, 0.04);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.kdc .kda-item:hover { border-color: #b9cbe6; box-shadow: 0 8px 22px rgba(30, 91, 170, 0.1); }

.kdc .kda-item__rank {
  width: 24px;
  height: 24px;
  margin-top: 2px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--kda-soft);
  color: var(--kda-text);
  font-size: 12px;
}
.kdc .kda-item__avatar { width: 60px; height: 60px; }
.kdc .kda-item__avatar--initials { font-size: 18px; }
.kdc .kda-item__name { font-size: 16px; }
.kdc .kda-item__line { font-size: 13.5px; }
.kdc .kda-item__facts { margin-top: 3px; font-size: 14px; }
.kdc .kda-item__actions { min-width: 118px; }
.kdc .kda-btn { padding: 8px 16px; }

.kdc .kda-list-note { margin: 12px 0 0; }

.kdc .kda-inquiry { width: min(100%, 480px); margin-top: 14px; padding: 18px; border-radius: 16px; box-shadow: 0 2px 10px rgba(17, 24, 39, 0.05); }

/* ---------- smaller screens ---------- */

@media (max-width: 860px) {
  .kdc__cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 600px) {
  .kdc__stage { padding: 0 14px; }
  .kdc:not(.kdc--chat) .kdc__stage { justify-content: flex-start; padding-top: 22px; }
  .kdc__sub { font-size: 14.5px; margin-bottom: 20px; }
  .kdc:not(.kdc--chat) .kdc__composer { padding-top: 11px; padding-bottom: 11px; }
  .kdc-card { flex-direction: row; align-items: center; gap: 10px; padding: 12px; }
  .kdc-ico { width: 34px; height: 34px; border-radius: 10px; }
  .kdc-ico svg { width: 18px; height: 18px; }
  .kdc-card__title { font-size: 13.5px; }
  .kdc-card__blurb { font-size: 11.5px; }
  .kdc__cards { gap: 10px; }

  .kdc .kda-msg--bot { padding-left: 0; }
  .kdc .kda-msg--bot::before { position: static; display: block; margin-bottom: 8px; width: 26px; height: 26px; background-size: 14px; }
  .kdc .kda-msg--user .kda-bubble { max-width: 90%; }
  .kdc .kda-bubble { font-size: 15.5px; }

  .kdc .kda-item { grid-template-columns: 26px 48px minmax(0, 1fr); padding: 14px 12px; }
  .kdc .kda-item__avatar { width: 48px; height: 48px; }
  .kdc .kda-item__actions { grid-column: 1 / -1; flex-direction: row; margin-top: 8px; min-width: 0; }
  .kdc .kda-item__actions .kda-btn { flex: 1 1 0; }

  .kdc__foot { flex-direction: column-reverse; align-items: stretch; gap: 8px; }
  .kdc--chat .kdc__foot { flex-direction: row; align-items: center; }
  .kdc--chat .kdc__note { display: none; }
  .kdc--chat .kdc__new { margin-left: auto; }
}

@media (prefers-reduced-motion: reduce) {
  .kdc-card, .kdc .kda-item { transition: none; }
  .kdc-card:hover { transform: none; }
}

/* while a conversation is going the page is the chat: the site footer waits below the start screen */
body.kdc-chatting .kd-footer { display: none; }
.kdc--chat .kdc__hero { display: none; }
