/* ─── Reset & base ─────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --clr-primary:    #1a5f8a;
  --clr-primary-dk: #134e73;
  --clr-accent:     #27ae60;
  --clr-accent-dk:  #1e8a4a;
  --clr-danger:     #c0392b;
  --clr-warning:    #e67e22;
  --clr-bg:         #f0f4f8;
  --clr-surface:    #ffffff;
  --clr-border:     #d0d9e3;
  --clr-text:       #1c2b3a;
  --clr-text-muted: #5a7089;
  --clr-bubble-user:#1a5f8a;
  --clr-bubble-ai:  #eef3f8;
  --radius-card:    16px;
  --radius-bubble:  18px;
  --shadow-card:    0 4px 24px rgba(0, 0, 0, 0.10);
  --font:           'Segoe UI', system-ui, -apple-system, sans-serif;
  --transition:     0.18s ease;
}

html { font-size: 16px; }

body {
  font-family: var(--font);
  background: var(--clr-bg);
  color: var(--clr-text);
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

/* ─── Layout ────────────────────────────────────────────────────────────────── */
#app {
  width: 100%;
  max-width: 440px;
}

.hidden { display: none !important; }

/* ─── Card (auth steps) ─────────────────────────────────────────────────────── */
.card {
  background: var(--clr-surface);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  padding: 2rem 2rem 1.75rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.card-header { text-align: center; }

.brand {
  display: inline-block;
  font-weight: 700;
  font-size: 0.85rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--clr-primary);
  margin-bottom: 0.75rem;
}
.brand.small { font-size: 0.78rem; }

.step-title {
  font-size: 1.45rem;
  font-weight: 700;
  color: var(--clr-text);
  margin-bottom: 0.35rem;
}

.step-subtitle {
  font-size: 0.93rem;
  color: var(--clr-text-muted);
  line-height: 1.5;
}

/* ─── Form ──────────────────────────────────────────────────────────────────── */
.form-group { display: flex; flex-direction: column; gap: 0.4rem; }

.form-label {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--clr-text);
}

.form-input {
  width: 100%;
  padding: 0.7rem 0.9rem;
  border: 1.5px solid var(--clr-border);
  border-radius: 10px;
  font-size: 1rem;
  font-family: var(--font);
  color: var(--clr-text);
  background: #fff;
  transition: border-color var(--transition), box-shadow var(--transition);
  outline: none;
}
.form-input:focus {
  border-color: var(--clr-primary);
  box-shadow: 0 0 0 3px rgba(26, 95, 138, 0.15);
}

.otp-input {
  letter-spacing: 0.3em;
  font-size: 1.5rem;
  text-align: center;
  font-weight: 700;
}

.field-error {
  font-size: 0.83rem;
  color: var(--clr-danger);
  line-height: 1.4;
}

.demo-note {
  font-size: 0.88rem;
  color: var(--clr-accent-dk);
  background: rgba(39, 174, 96, 0.12);
  border: 1px solid rgba(39, 174, 96, 0.25);
  border-radius: 10px;
  padding: 0.55rem 0.7rem;
  line-height: 1.45;
}

/* ─── Buttons ───────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.72rem 1.25rem;
  border-radius: 10px;
  font-size: 0.95rem;
  font-family: var(--font);
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: background var(--transition), opacity var(--transition), transform var(--transition);
  text-decoration: none;
}
.btn:active:not(:disabled) { transform: scale(0.98); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary {
  background: var(--clr-primary);
  color: #fff;
  width: 100%;
}
.btn-primary:hover:not(:disabled) { background: var(--clr-primary-dk); }

.btn-secondary {
  background: transparent;
  color: var(--clr-primary);
  border: 1.5px solid var(--clr-primary);
  width: 100%;
}
.btn-secondary:hover:not(:disabled) { background: rgba(26, 95, 138, 0.06); }

.btn-link {
  background: none;
  border: none;
  color: var(--clr-text-muted);
  font-size: 0.88rem;
  font-weight: 500;
  padding: 0.25rem 0;
  cursor: pointer;
  text-decoration: underline;
  align-self: center;
}
.btn-link:hover { color: var(--clr-primary); }
.btn-link.small { font-size: 0.82rem; }

/* ─── Privacy note ──────────────────────────────────────────────────────────── */
.privacy-note {
  font-size: 0.78rem;
  color: var(--clr-text-muted);
  text-align: center;
  line-height: 1.5;
}

/* ─── Chat wrapper ──────────────────────────────────────────────────────────── */
.chat-wrapper {
  background: var(--clr-surface);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  display: flex;
  flex-direction: column;
  height: calc(100dvh - 2rem);
  max-height: 680px;
  overflow: hidden;
}

/* For full-width chat on desktop, widen #app */
#app:has(.chat-wrapper:not(.hidden)) {
  max-width: 560px;
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.85rem 1.1rem;
  border-bottom: 1px solid var(--clr-border);
  background: var(--clr-surface);
  flex-shrink: 0;
}
.chat-header > div { display: flex; flex-direction: column; }
.chat-status { font-size: 0.78rem; color: var(--clr-text-muted); margin-top: 0.1rem; }

.usage-wrap {
  margin-top: 0.5rem;
  width: min(100%, 320px);
}

.usage-bar {
  width: 100%;
  height: 8px;
  border-radius: 999px;
  background: #dbe5ef;
  overflow: hidden;
}

.usage-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #1a5f8a 0%, #2e86c1 100%);
  transition: width 0.25s ease, background 0.2s ease;
}

.usage-fill.warning {
  background: linear-gradient(90deg, #e67e22 0%, #c0392b 100%);
}

.usage-text {
  margin-top: 0.25rem;
  font-size: 0.76rem;
  color: var(--clr-text-muted);
}

/* ─── Messages ──────────────────────────────────────────────────────────────── */
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  scroll-behavior: smooth;
}

.message {
  display: flex;
  flex-direction: column;
  max-width: 82%;
}
.message.user { align-self: flex-end; align-items: flex-end; }
.message.assistant { align-self: flex-start; align-items: flex-start; }

.bubble {
  padding: 0.65rem 0.95rem;
  border-radius: var(--radius-bubble);
  font-size: 0.93rem;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
}
.message.user .bubble {
  background: var(--clr-bubble-user);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.message.assistant .bubble {
  background: var(--clr-bubble-ai);
  color: var(--clr-text);
  border-bottom-left-radius: 4px;
}

.message.assistant .bubble.rich-html {
  white-space: normal;
}

.message.assistant .bubble.rich-html h3,
.message.assistant .bubble.rich-html h4 {
  margin: 0.15rem 0 0.45rem;
  font-size: 0.98rem;
}

.message.assistant .bubble.rich-html p {
  margin: 0.2rem 0;
}

.message.assistant .bubble.rich-html ul,
.message.assistant .bubble.rich-html ol {
  margin: 0.35rem 0 0.3rem 1.1rem;
}

.message.assistant .bubble.rich-html li {
  margin: 0.2rem 0;
}

.message.assistant .bubble.rich-html hr {
  border: 0;
  border-top: 1px solid var(--clr-border);
  margin: 0.55rem 0;
}

.message.assistant .bubble.rich-html table {
  border-collapse: collapse;
  width: 100%;
  margin: 0.45rem 0;
  font-size: 0.86rem;
}

.message.assistant .bubble.rich-html th,
.message.assistant .bubble.rich-html td {
  border: 1px solid var(--clr-border);
  padding: 0.3rem 0.35rem;
  text-align: left;
  vertical-align: top;
}

.message.assistant .bubble.rich-html th {
  background: rgba(26, 95, 138, 0.08);
  font-weight: 700;
}

/* ─── Booking CTA ───────────────────────────────────────────────────────────── */
.booking-cta {
  display: inline-block;
  margin-top: 0.5rem;
  padding: 0.5rem 1.1rem;
  background: var(--clr-accent);
  color: #fff;
  border-radius: 8px;
  font-size: 0.88rem;
  font-weight: 700;
  text-decoration: none;
  transition: background var(--transition);
}
.booking-cta:hover { background: var(--clr-accent-dk); }

/* ─── Typing indicator ──────────────────────────────────────────────────────── */
.typing-indicator {
  display: flex;
  gap: 5px;
  align-items: center;
  padding: 0.55rem 0.85rem;
}
.typing-indicator span {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--clr-text-muted);
  animation: blink 1.2s infinite;
}
.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink {
  0%, 80%, 100% { opacity: 0.25; transform: scale(0.9); }
  40%           { opacity: 1;    transform: scale(1.1); }
}

/* ─── Chat input bar ────────────────────────────────────────────────────────── */
.chat-input-bar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.65rem 0.75rem;
  border-top: 1px solid var(--clr-border);
  background: var(--clr-surface);
  flex-shrink: 0;
}

.chat-input {
  flex: 1;
  padding: 0.62rem 0.9rem;
  border: 1.5px solid var(--clr-border);
  border-radius: 22px;
  font-size: 0.93rem;
  font-family: var(--font);
  color: var(--clr-text);
  background: #fff;
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
}
.chat-input:focus {
  border-color: var(--clr-primary);
  box-shadow: 0 0 0 3px rgba(26, 95, 138, 0.12);
}

.send-btn {
  width: 40px; height: 40px;
  border-radius: 50%;
  border: none;
  background: var(--clr-primary);
  color: #fff;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  transition: background var(--transition), transform var(--transition);
}
.send-btn:hover:not(:disabled) { background: var(--clr-primary-dk); }
.send-btn:active:not(:disabled) { transform: scale(0.93); }
.send-btn:disabled { opacity: 0.45; cursor: not-allowed; }
.send-btn svg { width: 16px; height: 16px; }

/* ─── Responsive ────────────────────────────────────────────────────────────── */
@media (max-width: 480px) {
  body { padding: 0; align-items: flex-start; }
  .card { border-radius: 0; box-shadow: none; min-height: 100dvh; padding: 1.5rem 1.25rem; }
  .chat-wrapper { border-radius: 0; height: 100dvh; max-height: none; }
  #app { max-width: 100%; }
  #app:has(.chat-wrapper:not(.hidden)) { max-width: 100%; }
}
