/* Umran survey — chat-style survey UI (mobile-first, RTL). */

:root {
  --navy: #0A2F6B;
  --navy-dark: #071f47;
  --violet: #6A3FBF;
  --violet-deep: #4f2d96;
  --violet-tint: #f0ebfa;
  --violet-wash: #f3f0fa;
  --lavender: #b9a3ec;
  --ink: #1a2b42;
  --muted: #5c6b7a;
  --muted-2: #7a8797;
  --line: #d8e0ec;
  --surface: #f4f6fb;
  --surface-2: #e8edf5;
  --on-navy-muted: #dbe3f2;
  --disabled: #c3cddc;
  --white: #ffffff;
  --danger: #b42318;
  --danger-wash: #fdf1f0;
  --danger-line: #f3c9c4;

  --font: Almarai, Tajawal, 'Segoe UI', Tahoma, sans-serif;
  --ease: cubic-bezier(.2, 0, 0, 1);
  --focus-ring: 0 0 0 3px rgba(106, 63, 191, .22);
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { margin: 0; height: 100%; }

.survey-body {
  background: var(--surface);
  font-family: var(--font);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}

a { color: var(--navy); }
a:hover { color: var(--navy-dark); }

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

[dir=rtl] .flip-rtl { transform: scaleX(-1); }

/* ---------- Shell ---------- */

.chat {
  position: relative;
  width: 100%;
  height: 100vh;
  height: 100dvh;
  min-height: 560px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--surface);
}

/* ---------- Header ---------- */

.chat-header {
  flex: none;
  background: var(--navy);
  color: var(--white);
  padding: 10px 12px 0;
  padding-top: calc(10px + env(safe-area-inset-top));
}

.chat-header__bar {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 48px;
}

.chat-header__avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(255, 255, 255, .12);
  display: flex;
  align-items: center;
  justify-content: center;
  flex: none;
}

.chat-header__meta {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.chat-header__title {
  margin: 0;
  font-size: 16px;
  font-weight: 800;
  line-height: 1.3;
}

.chat-header__status {
  margin: 0;
  font-size: 12px;
  color: var(--on-navy-muted);
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}

.chat-header__dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--lavender);
  display: inline-block;
}

/* Install app button (shown by pwa.js) */
.chat-header__install {
  flex: none;
  min-height: 44px;
  min-width: 44px;
  padding: 0 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 0;
  border-radius: 999px;
  background: rgba(255, 255, 255, .12);
  color: var(--white);
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
}
.chat-header__install:hover { background: rgba(255, 255, 255, .18); }

@media (max-width: 359px) {
  .chat-header__install { padding: 0; width: 44px; }
  .chat-header__install-text {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
  }
}

/* ---------- Progress ---------- */

.chat-progress {
  display: flex;
  align-items: center;
  gap: 10px;
}

.chat-progress__track {
  flex: 1;
  border-radius: 999px;
  overflow: hidden;
}

.chat-progress__fill {
  width: 0;
  border-radius: 999px;
  transition: width 180ms var(--ease);
}

.chat-progress__label {
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

/* Mobile: inside the navy header */
.chat-progress--header { padding: 10px 2px 12px; }
.chat-progress--header .chat-progress__track { height: 4px; background: rgba(255, 255, 255, .18); }
.chat-progress--header .chat-progress__fill { height: 4px; background: var(--white); }
.chat-progress--header .chat-progress__label { color: var(--on-navy-muted); }

/* Desktop: its own row (hidden on mobile) */
.chat-progress--bar {
  display: none;
  gap: 12px;
  padding: 10px 20px;
  background: var(--white);
  border-bottom: 1px solid var(--line);
}
.chat-progress--bar .chat-progress__track { height: 6px; background: var(--surface-2); }
.chat-progress--bar .chat-progress__fill { height: 6px; background: var(--violet); }
.chat-progress--bar .chat-progress__label { font-size: 13px; color: var(--muted); }

/* ---------- Message list ---------- */

.chat-list {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 20px 16px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scrollbar-width: none;
  -ms-overflow-style: none;
}
.chat-list::-webkit-scrollbar { display: none; width: 0; height: 0; }

.chat-day {
  margin: 0 0 6px;
  align-self: center;
  padding: 4px 12px;
  border-radius: 999px;
  background: var(--surface-2);
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
}

.msg-bot {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  max-width: 86%;
  align-self: flex-start;
}

.msg-avatar {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--navy);
  display: flex;
  align-items: center;
  justify-content: center;
  flex: none;
}

/* Only the last bot message in a run shows the avatar
   (and not while the typing indicator follows it). */
.msg-bot:has(+ .msg-bot) .msg-avatar,
.msg-bot:has(+ .chat-typing) .msg-avatar { visibility: hidden; }

.msg-bubble {
  margin: 0;
  padding: 11px 14px;
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: 16px;
  border-end-start-radius: 4px;
  font-size: 15px;
  line-height: 1.6;
  color: var(--ink);
  box-shadow: 0 1px 2px rgba(10, 47, 107, .06);
  white-space: pre-line;
}

.msg-bubble--error {
  background: var(--danger-wash);
  border-color: var(--danger-line);
}

.msg-user {
  margin: 2px 0;
  align-self: flex-end;
  max-width: 78%;
  padding: 11px 14px;
  background: var(--navy);
  color: var(--white);
  border-radius: 16px;
  border-end-end-radius: 4px;
  font-size: 15px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
}

/* Typing indicator */
.chat-typing {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  align-self: flex-start;
}

.chat-typing__dots {
  padding: 14px 16px;
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: 16px;
  border-end-start-radius: 4px;
  display: flex;
  gap: 5px;
}

.chat-typing__dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--muted);
  display: inline-block;
  animation: chat-dot 1.1s infinite var(--ease);
}
.chat-typing__dot:nth-child(2) { animation-delay: .15s; }
.chat-typing__dot:nth-child(3) { animation-delay: .3s; }

@keyframes chat-dot {
  0%, 80%, 100% { opacity: .25; transform: translateY(0); }
  40% { opacity: 1; transform: translateY(-3px); }
}

/* ---------- Buttons ---------- */

.chat-btn {
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  font-family: inherit;
  transition: background-color 150ms var(--ease), transform 120ms var(--ease), box-shadow 150ms, border-color 150ms;
}
.chat-btn:active { transform: scale(.98); }
.chat-btn:focus-visible,
.chat-input:focus {
  outline: none;
  box-shadow: var(--focus-ring);
  border-color: var(--violet);
}

.chat-btn--primary {
  min-height: 52px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 0;
  border-radius: 12px;
  background: var(--navy);
  color: var(--white);
  font-size: 16px;
  font-weight: 700;
}
.chat-btn--primary:hover { background: var(--navy-dark); }

.chat-btn--ghost {
  min-height: 56px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1.5px solid var(--navy);
  border-radius: 12px;
  background: var(--white);
  color: var(--navy);
  font-size: 16px;
  font-weight: 700;
}
.chat-btn--ghost:hover { background: var(--surface-2); }

.chat-btn--block { width: 100%; }

/* ---------- Answer tray ---------- */

.chat-tray {
  flex: none;
  background: var(--white);
  border-radius: 20px 20px 0 0;
  box-shadow: 0 -6px 24px rgba(10, 47, 107, .09);
  padding: 10px 16px calc(16px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 12px;
  animation: tray-up 180ms var(--ease);
}

@keyframes tray-up {
  from { opacity: 0; transform: translateY(24px); }
  to { opacity: 1; transform: translateY(0); }
}

.chat-tray__grabber {
  align-self: center;
  width: 36px;
  height: 4px;
  border-radius: 999px;
  background: var(--line);
}

.chat-tray__label {
  margin: 0;
  font-size: 13px;
  font-weight: 700;
  color: var(--muted);
}

/* Choice */
.tray-options {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.tray-option {
  min-height: 52px;
  padding: 0 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--white);
  color: var(--ink);
  font-size: 15px;
  font-weight: 700;
  text-align: start;
}
.tray-option:hover,
.tray-option:active { background: var(--violet-wash); border-color: var(--violet); }

.tray-option__radio {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 2px solid var(--muted-2);
  flex: none;
}

.tray-option__label { flex: 1; }

/* Yes / no */
.tray-yesno {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}
.tray-yesno .chat-btn--primary { min-height: 56px; }

/* Rating */
.tray-rating {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding-bottom: 4px;
}

.tray-stars {
  display: flex;
  gap: 6px;
}

.tray-star {
  width: 56px;
  height: 56px;
  border: 0;
  border-radius: 14px;
  background: transparent;
  display: flex;
  align-items: center;
  justify-content: center;
}
.tray-star:active { background: var(--violet-tint); }
.tray-star svg { fill: none; stroke: var(--muted-2); }
.tray-star.is-filled svg { fill: var(--violet); stroke: var(--violet); }

.tray-rating__hint {
  margin: 0;
  min-height: 20px;
  font-size: 14px;
  font-weight: 700;
  color: var(--violet);
}

/* Text */
.tray-composer {
  display: flex;
  gap: 8px;
  align-items: center;
  margin: 0;
}

.chat-input {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 48px;
  padding: 0 16px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--ink);
  font-family: inherit;
  font-size: 16px; /* 16px stops iOS from zooming on focus */
}

.chat-send {
  width: 48px;
  height: 48px;
  min-height: 0;
  border-radius: 50%;
  flex: none;
}
.chat-send:disabled { background: var(--disabled); cursor: not-allowed; }

/* Skip / pause / stop row, and the inline stop confirmation */
.tray-actions,
.tray-confirm {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.tray-confirm__text {
  font-size: 13px;
  font-weight: 700;
  color: var(--ink);
}

.chat-btn--link {
  min-height: 44px;
  padding: 0 12px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}
.chat-btn--link:hover { background: var(--surface-2); }

.chat-btn--danger { color: var(--danger); }
.chat-btn--danger:hover { background: var(--danger-wash); }

/* ---------- Welcome dialog ---------- */

.welcome {
  position: absolute;
  inset: 0;
  z-index: 10;
  background: rgba(7, 31, 71, .45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  animation: fade-in 180ms var(--ease);
}

.welcome__dialog {
  width: 100%;
  max-width: 360px;
  max-height: 100%;
  overflow-y: auto;
  background: var(--white);
  border-radius: 20px;
  box-shadow: 0 20px 48px rgba(10, 47, 107, .22);
  display: flex;
  flex-direction: column;
  animation: pop-in 180ms var(--ease);
}

.welcome__hero {
  background: var(--navy);
  padding: 20px 20px 22px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.welcome__badge {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: rgba(255, 255, 255, .12);
  display: flex;
  align-items: center;
  justify-content: center;
}

.welcome__title {
  margin: 0;
  font-size: 22px;
  font-weight: 800;
  line-height: 1.35;
  color: var(--white);
}

.welcome__lead {
  margin: 0;
  font-size: 15px;
  line-height: 1.6;
  color: var(--on-navy-muted);
}

.welcome__body {
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.welcome__why {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.welcome__why-title {
  margin: 0;
  font-size: 15px;
  font-weight: 800;
  color: var(--navy);
}

.welcome__why-text {
  margin: 0;
  font-size: 14px;
  line-height: 1.65;
  color: var(--ink);
}

/* iOS install guide (reuses the welcome dialog shell) */
.welcome__dialog:focus { outline: none; }

.install-steps {
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.install-steps li {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 14px;
  line-height: 1.6;
  color: var(--ink);
}

.install-steps__num {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--violet-tint);
  color: var(--violet-deep);
  font-size: 14px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex: none;
}

.install-steps__icon {
  color: var(--navy);
  vertical-align: -3px;
}

.install-guide__note {
  margin: 0;
  font-size: 13px;
  line-height: 1.6;
  color: var(--muted);
}

.install-guide__actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.install-guide__actions .chat-btn--ghost { min-height: 52px; }

/* Error page (Pages/Error.cshtml) */
.error-page {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: var(--surface);
}

a.chat-btn { text-decoration: none; }

.error-page__ref {
  margin: 0;
  font-size: 12px;
  color: var(--muted);
  text-align: center;
  overflow-wrap: anywhere;
}

@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop-in {
  from { opacity: 0; transform: translateY(16px) scale(.98); }
  to { opacity: 1; transform: none; }
}

/* ---------- Desktop: centred chat column ---------- */

@media (min-width: 768px) {
  .chat {
    max-width: 760px;
    margin: 0 auto;
    background: var(--white);
    border-inline: 1px solid var(--line);
    box-shadow: 0 8px 24px rgba(10, 47, 107, .07);
    min-height: 520px;
  }

  .chat-header { padding: 12px 16px; }
  .chat-header__avatar { width: 44px; height: 44px; }
  .chat-header__title { font-size: 17px; }
  .chat-header__status { font-size: 13px; }
  .chat-header__dot { width: 8px; height: 8px; }

  .chat-progress--header { display: none; }
  .chat-progress--bar { display: flex; }

  .chat-list { padding: 24px 20px; gap: 12px; background: var(--surface); }
  .msg-bot { max-width: 85%; }
  .msg-avatar { width: 28px; height: 28px; }
  .msg-bubble { padding: 12px 16px; border-radius: 14px; border-end-start-radius: 4px; line-height: 1.65; }
  .msg-user { margin: 0; max-width: 80%; padding: 12px 16px; border-radius: 14px; border-end-end-radius: 4px; line-height: 1.65; }
  .chat-typing__dots { border-radius: 14px; border-end-start-radius: 4px; }

  .chat-tray {
    border-radius: 0;
    box-shadow: none;
    border-top: 1px solid var(--line);
    padding: 16px 20px 20px;
    gap: 14px;
  }
  .chat-tray__grabber,
  .chat-tray__label { display: none; }

  /* Choices become wrapping pill chips */
  .tray-options { flex-direction: row; flex-wrap: wrap; }
  .tray-option {
    min-height: 44px;
    padding: 0 18px;
    border: 1.5px solid var(--navy);
    border-radius: 999px;
    color: var(--navy);
    font-size: 14px;
  }
  .tray-option:hover,
  .tray-option:active { background: var(--surface-2); border-color: var(--navy); }
  .tray-option__radio,
  .tray-option__chevron { display: none; }

  .tray-yesno { display: flex; gap: 10px; }
  .tray-yesno .chat-btn { flex: 1 1 0; max-width: 220px; min-height: 48px; font-size: 15px; }

  .tray-star { width: 52px; height: 52px; border-radius: 12px; }
  .tray-star:hover { background: var(--violet-tint); }
  .tray-star svg { width: 34px; height: 34px; }
  .tray-rating__hint { font-size: 13px; color: var(--muted); }

  .chat-input { border-radius: 12px; background: var(--white); font-size: 15px; }

  .tray-restart { align-self: center; min-height: 48px; padding: 0 24px; font-size: 15px; }
}

@media (prefers-reduced-motion: reduce) {
  .chat-typing__dot { animation: none; opacity: .6; }
  .chat-tray, .welcome, .welcome__dialog { animation: none; }
  .chat-btn, .chat-progress__fill { transition: none; }
}
