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

:root {
  --blue:        #2D9CDB;
  --blue-dark:   #1a7ab5;
  --navy:        #1a1a2e;
  --navy-mid:    #16213e;
  --surface:     #f4f6f9;
  --white:       #ffffff;
  --border:      #e2e8f0;
  --text:        #1e293b;
  --text-muted:  #64748b;
  --ai-bubble:   #ffffff;
  --user-bubble: #2D9CDB;
  --shadow:      0 2px 12px rgba(0,0,0,.10);
  --shadow-lg:   0 8px 32px rgba(0,0,0,.16);
  --radius:      14px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

html, body { height: 100%; overflow: hidden; background: var(--surface); color: var(--text); }


/* ── Login screen ─────────────────────────────────────────────────────────── */
#login-screen {
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--navy) 0%, var(--navy-mid) 60%, #0f3460 100%);
}

.login-card {
  background: var(--white);
  border-radius: 20px;
  padding: 44px 40px 40px;
  width: 380px;
  box-shadow: var(--shadow-lg);
}

.login-brand {
  text-align: center;
  margin-bottom: 32px;
}
.login-logo {
  width: 200px;
  height: 200px;
  object-fit: contain;
  margin-bottom: 12px;
  filter: drop-shadow(0 4px 8px rgba(45,156,219,.3));
}
.login-brand h1 {
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--navy);
  letter-spacing: -.5px;
}
.login-brand p {
  font-size: .85rem;
  color: var(--text-muted);
  margin-top: 4px;
}

.field { margin-bottom: 18px; }
.field label {
  display: block;
  font-size: .8rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .06em;
  margin-bottom: 6px;
}
.field input {
  width: 100%;
  padding: 11px 14px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  font-size: .95rem;
  color: var(--text);
  background: var(--surface);
  transition: border-color .15s, box-shadow .15s;
  outline: none;
}
.field input:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(45,156,219,.15);
}

.login-error {
  background: #fef2f2;
  color: #dc2626;
  font-size: .85rem;
  padding: 10px 14px;
  border-radius: 8px;
  border: 1px solid #fecaca;
  margin-bottom: 14px;
}

#login-btn {
  width: 100%;
  padding: 13px;
  background: var(--blue);
  color: var(--white);
  border: none;
  border-radius: 10px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  margin-top: 6px;
  transition: background .15s, transform .1s;
}
#login-btn:hover  { background: var(--blue-dark); }
#login-btn:active { transform: scale(.98); }
#login-btn:disabled { opacity: .65; cursor: not-allowed; }

/* Shared full-width button style for secondary login-card buttons */
#new-pw-btn, #forgot-send-btn, #forgot-confirm-btn, #signup-btn, #signup-confirm-btn {
  width: 100%;
  padding: 13px;
  background: var(--blue);
  color: var(--white);
  border: none;
  border-radius: 10px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  margin-top: 6px;
  transition: background .15s, transform .1s;
}
#new-pw-btn:hover, #forgot-send-btn:hover, #forgot-confirm-btn:hover,
#signup-btn:hover, #signup-confirm-btn:hover { background: var(--blue-dark); }
#new-pw-btn:disabled, #forgot-send-btn:disabled, #forgot-confirm-btn:disabled,
#signup-btn:disabled, #signup-confirm-btn:disabled { opacity: .65; cursor: not-allowed; }

.auth-links {
  text-align: center;
  margin-top: 14px;
}
.auth-links a {
  font-size: .82rem;
  color: var(--text-muted);
  text-decoration: none;
}
.auth-links a:hover { color: var(--blue); text-decoration: underline; }

.pw-hint {
  font-size: .74rem;
  color: var(--text-muted);
  text-align: center;
  margin: 4px 0 10px;
  line-height: 1.5;
}


/* ── App shell ────────────────────────────────────────────────────────────── */
#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

/* ── Header ───────────────────────────────────────────────────────────────── */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  height: 72px;
  background: var(--navy);
  color: var(--white);
  flex-shrink: 0;
  box-shadow: 0 2px 8px rgba(0,0,0,.25);
  z-index: 10;
}

.header-brand { display: flex; align-items: center; gap: 12px; }
.header-avatar {
  width: 56px;
  height: 56px;
  object-fit: contain;
}
.header-title { display: flex; flex-direction: column; }
.header-name { font-size: 1.05rem; font-weight: 700; line-height: 1.2; }
.header-sub  { font-size: .72rem; color: rgba(255,255,255,.55); }
.beta-badge {
  display: inline-block;
  font-size: .6rem;
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--navy);
  background: var(--blue);
  border-radius: 4px;
  padding: 1px 5px;
  vertical-align: middle;
  position: relative;
  top: -1px;
}

.header-right { display: flex; align-items: center; gap: 14px; }
#account-display {
  font-size: .85rem;
  color: rgba(255,255,255,.7);
  max-width: 200px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.logout-btn {
  background: rgba(255,255,255,.12);
  color: var(--white);
  border: 1px solid rgba(255,255,255,.2);
  border-radius: 8px;
  padding: 6px 14px;
  font-size: .82rem;
  cursor: pointer;
  transition: background .15s;
}
.logout-btn:hover { background: rgba(255,255,255,.22); }

#customer-selector select {
  background: rgba(255,255,255,.12);
  color: var(--white);
  border: 1px solid rgba(255,255,255,.25);
  border-radius: 8px;
  padding: 5px 10px;
  font-size: .82rem;
  cursor: pointer;
  max-width: 200px;
  outline: none;
}
#customer-selector select:hover  { background: rgba(255,255,255,.2); }
#customer-selector select option { background: var(--navy); color: var(--white); }


/* ── Chat main area ───────────────────────────────────────────────────────── */
#chat-main {
  flex: 1;
  overflow-y: auto;
  padding: 24px 0;
  scroll-behavior: smooth;
}

#messages {
  max-width: 820px;
  margin: 0 auto;
  padding: 0 20px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}


/* ── Messages ─────────────────────────────────────────────────────────────── */
.message {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  max-width: 82%;
  animation: msg-in .2s ease-out;
}

@keyframes msg-in {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* AI message — left aligned */
.message.ai { align-self: flex-start; }
.message.ai .avatar {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: #e8eaed;
  padding: 6px;
  object-fit: contain;
  flex-shrink: 0;
}
.message.ai .bubble {
  background: var(--ai-bubble);
  color: var(--text);
  border-radius: var(--radius) var(--radius) var(--radius) 4px;
  padding: 14px 18px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  line-height: 1.6;
}

/* User message — right aligned */
.message.user { align-self: flex-end; flex-direction: row-reverse; }
.message.user .bubble {
  background: var(--user-bubble);
  color: var(--white);
  border-radius: var(--radius) var(--radius) 4px var(--radius);
  padding: 12px 16px;
  line-height: 1.55;
}

/* Markdown inside AI bubbles */
.message.ai .bubble p  { margin-bottom: .6em; }
.message.ai .bubble p:last-child { margin-bottom: 0; }
.message.ai .bubble h1,
.message.ai .bubble h2,
.message.ai .bubble h3 { margin: .8em 0 .4em; font-size: 1em; }
.message.ai .bubble ul,
.message.ai .bubble ol { padding-left: 1.4em; margin: .4em 0; }
.message.ai .bubble li { margin-bottom: .25em; }
.message.ai .bubble strong { color: var(--navy); }
.message.ai .bubble code {
  font-family: "SF Mono", Consolas, monospace;
  font-size: .88em;
  background: #f1f5f9;
  padding: 2px 6px;
  border-radius: 4px;
}
.message.ai .bubble pre {
  background: #f1f5f9;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
  overflow-x: auto;
  margin: .6em 0;
}
.message.ai .bubble pre code { background: none; padding: 0; }
.message.ai .bubble blockquote {
  border-left: 3px solid var(--blue);
  margin: .6em 0;
  padding: 4px 12px;
  color: var(--text-muted);
  font-size: .9em;
}
.message.ai .bubble em { color: var(--text-muted); }


/* ── Links inside AI bubbles ──────────────────────────────────────────────── */
.message.ai .bubble a {
  color: var(--blue);
  text-decoration: underline;
}
.message.ai .bubble a:hover { color: var(--blue-dark); }
.message.ai .bubble a strong { color: inherit; }


/* ── Typing indicator ─────────────────────────────────────────────────────── */
.typing-bubble {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 14px 18px;
  min-width: 56px;
}
.dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: bounce .9s infinite ease-in-out;
}
.dot:nth-child(2) { animation-delay: .15s; }
.dot:nth-child(3) { animation-delay: .30s; }

@keyframes bounce {
  0%, 80%, 100% { transform: translateY(0);   opacity: .5; }
  40%           { transform: translateY(-7px); opacity: 1; }
}


/* ── Input area ───────────────────────────────────────────────────────────── */
.input-area {
  flex-shrink: 0;
  background: var(--white);
  border-top: 1px solid var(--border);
  padding: 14px 20px 12px;
  box-shadow: 0 -2px 12px rgba(0,0,0,.06);
}

.input-wrap {
  max-width: 820px;
  margin: 0 auto;
  display: flex;
  align-items: flex-end;
  gap: 10px;
}

#chat-input {
  flex: 1;
  resize: none;
  border: 1.5px solid var(--border);
  border-radius: 12px;
  padding: 11px 16px;
  font-size: .95rem;
  font-family: inherit;
  line-height: 1.5;
  max-height: 180px;
  overflow-y: auto;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
  color: var(--text);
  background: var(--surface);
}
#chat-input:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(45,156,219,.12);
  background: var(--white);
}
#chat-input::placeholder { color: var(--text-muted); }

#help-btn {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 0 13px;
  height: 44px;
  flex-shrink: 0;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: 22px;
  cursor: pointer;
  font-size: .82rem;
  font-family: inherit;
  color: var(--text-muted);
  transition: border-color .15s, color .15s, background .15s;
  white-space: nowrap;
}
#help-btn:hover {
  border-color: var(--blue);
  color: var(--blue);
  background: var(--white);
}
#help-btn img {
  width: 36px;
  height: 36px;
  transform: rotate(-12deg);
  transition: transform .25s ease;
  object-fit: contain;
}
#help-btn:hover img {
  transform: rotate(-28deg) scale(1.08);
}
#help-btn:disabled { opacity: .45; cursor: not-allowed; }

#send-btn {
  width: 44px;
  height: 44px;
  background: var(--blue);
  color: var(--white);
  border: none;
  border-radius: 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background .15s, transform .1s;
}
#send-btn:hover   { background: var(--blue-dark); }
#send-btn:active  { transform: scale(.93); }
#send-btn:disabled { opacity: .5; cursor: not-allowed; }

.input-hint {
  max-width: 820px;
  margin: 6px auto 0;
  font-size: .73rem;
  color: var(--text-muted);
  text-align: center;
}
.feedback-link {
  color: var(--blue);
  text-decoration: none;
  font-weight: 500;
}
.feedback-link:hover { text-decoration: underline; }


/* ── Help example chips ───────────────────────────────────────────────────── */
a.example-chip {
  display: inline-block;
  margin: 2px 0;
  padding: 2px 10px;
  border: 1px solid var(--blue);
  border-radius: 12px;
  background: transparent;
  color: var(--blue);
  font-size: .82rem;
  text-decoration: none;
  cursor: pointer;
  transition: background .12s, color .12s;
}
a.example-chip:hover {
  background: var(--blue);
  color: #fff;
}

/* ── Site footer ──────────────────────────────────────────────────────────── */
.site-footer {
  flex-shrink: 0;
  background: var(--navy);
  color: rgba(255,255,255,.45);
  font-size: .7rem;
  text-align: center;
  padding: 6px 16px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.site-footer a {
  color: rgba(255,255,255,.65);
  text-decoration: none;
}
.site-footer a:hover { color: #fff; text-decoration: underline; }

/* ── T&C modal ────────────────────────────────────────────────────────────── */
.tc-overlay {
  position: fixed; inset: 0; z-index: 9999;
  background: rgba(0,0,0,.55);
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
.tc-overlay.hidden { display: none !important; }
.tc-box {
  background: #fff; border-radius: 14px;
  box-shadow: 0 16px 48px rgba(0,0,0,.28);
  max-width: 640px; width: 100%;
  max-height: 80vh; display: flex; flex-direction: column;
  overflow: hidden;
}
.tc-header {
  background: var(--navy); color: #fff;
  padding: 16px 20px; font-size: .95rem; font-weight: 700;
  display: flex; align-items: center; justify-content: space-between;
  flex-shrink: 0;
}
.tc-close {
  background: none; border: none; color: rgba(255,255,255,.7);
  font-size: 1.3rem; cursor: pointer; line-height: 1; padding: 0 2px;
}
.tc-close:hover { color: #fff; }
.tc-body {
  padding: 20px 24px; overflow-y: auto; font-size: .83rem;
  line-height: 1.65; color: #334155;
}
.tc-body p + p { margin-top: 12px; }
.tc-footer-bar {
  padding: 12px 20px; border-top: 1px solid #e2e8f0;
  display: flex; justify-content: flex-end; flex-shrink: 0;
}
.tc-ok-btn {
  padding: 8px 24px; background: var(--blue); color: #fff;
  border: none; border-radius: 8px; font-size: .88rem; font-weight: 600;
  cursor: pointer; transition: background .15s;
}
.tc-ok-btn:hover { background: var(--blue-dark); }

/* ── Login-page footer ────────────────────────────────────────────────────── */
.login-footer {
  margin-top: 28px; text-align: center;
  font-size: .7rem; color: rgba(255,255,255,.35);
}
.login-footer a { color: rgba(255,255,255,.55); text-decoration: none; }
.login-footer a:hover { color: #fff; text-decoration: underline; }

/* ── Utility ──────────────────────────────────────────────────────────────── */
.hidden { display: none !important; }
