/* ============================================================
   GLOBAL RESET & BASE
   ============================================================ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --purple:      #6c63ff;
  --purple-dark: #5046e5;
  --purple-light:#ede9fe;
  --teal:        #38b2ac;
  --orange:      #ed8936;
  --yellow:      #f6e05e;
  --green:       #48bb78;
  --red:         #fc8181;
  --bg-grad:     linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  --chat-bg:     #f0f4ff;
  --white:       #ffffff;
  --text:        #2d3748;
  --text-light:  #718096;
  --radius-lg:   18px;
  --radius-md:   12px;
  --radius-sm:   8px;
  --shadow:      0 4px 20px rgba(0,0,0,.12);
  --shadow-sm:   0 2px 8px rgba(0,0,0,.08);
  --font:        'Nunito', 'Segoe UI', sans-serif;
}

html, body { height: 100%; }

body {
  font-family: var(--font);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

/* ============================================================
   LOGIN PAGE
   ============================================================ */
.login-page {
  background: var(--bg-grad);
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  overflow: hidden;
}

/* Floating decorations */
.deco {
  position: fixed;
  animation: float 4s ease-in-out infinite;
  pointer-events: none;
  opacity: .85;
  user-select: none;
}
@keyframes float {
  0%, 100% { transform: translateY(0) rotate(-5deg); }
  50%       { transform: translateY(-18px) rotate(5deg); }
}

.login-wrapper {
  width: 100%;
  max-width: 420px;
  padding: 1.5rem;
  z-index: 1;
}

.login-card {
  background: var(--white);
  border-radius: 28px;
  padding: 2.5rem 2rem;
  box-shadow: 0 20px 60px rgba(0,0,0,.25);
  text-align: center;
}

.mascot-ring {
  width: 90px;
  height: 90px;
  border-radius: 50%;
  background: linear-gradient(135deg, #f6d365 0%, #fda085 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 1rem;
  box-shadow: 0 8px 24px rgba(253,160,133,.4);
  animation: bounce 2.5s ease-in-out infinite;
}
@keyframes bounce {
  0%, 100% { transform: translateY(0); }
  50%       { transform: translateY(-8px); }
}
.mascot-emoji { font-size: 3rem; line-height: 1; }

.brand-title {
  font-size: 2rem;
  font-weight: 900;
  color: var(--purple);
  letter-spacing: -.5px;
}
.brand-sub {
  font-size: 1rem;
  color: var(--text-light);
  margin: .25rem 0 1.75rem;
  font-weight: 600;
}

/* Form */
.field-group { text-align: left; margin-bottom: 1rem; }
.field-group label {
  display: block;
  font-weight: 700;
  font-size: .9rem;
  color: var(--text);
  margin-bottom: .35rem;
}
.field-group input {
  width: 100%;
  padding: .75rem 1rem;
  border: 2.5px solid #e2e8f0;
  border-radius: var(--radius-md);
  font-family: var(--font);
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
  outline: none;
  transition: border-color .2s, box-shadow .2s;
}
.field-group input:focus {
  border-color: var(--purple);
  box-shadow: 0 0 0 3px rgba(108,99,255,.15);
}

.error-msg {
  background: #fff5f5;
  color: #c53030;
  border: 2px solid #fc8181;
  border-radius: var(--radius-sm);
  padding: .6rem 1rem;
  font-size: .9rem;
  font-weight: 700;
  text-align: left;
  margin-bottom: 1rem;
}

.login-btn {
  width: 100%;
  padding: .9rem 1rem;
  background: linear-gradient(135deg, var(--purple) 0%, #9f7aea 100%);
  color: var(--white);
  border: none;
  border-radius: var(--radius-lg);
  font-family: var(--font);
  font-size: 1.1rem;
  font-weight: 800;
  cursor: pointer;
  transition: transform .15s, box-shadow .15s;
  box-shadow: 0 6px 20px rgba(108,99,255,.4);
  margin-top: .25rem;
}
.login-btn:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 10px 28px rgba(108,99,255,.5);
}
.login-btn:active:not(:disabled) { transform: translateY(0); }
.login-btn:disabled { opacity: .7; cursor: not-allowed; }

/* ============================================================
   CHAT PAGE — LAYOUT
   ============================================================ */
.chat-page {
  background: var(--chat-bg);
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

/* --- Two-panel body --- */
.chat-body {
  display: flex;
  flex: 1;
  overflow: hidden;
  min-height: 0;
}

/* --- Left panel --- */
.left-panel {
  width: 300px;
  min-width: 260px;
  flex-shrink: 0;
  background: var(--white);
  border-right: 2px solid #e8edff;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.left-panel-content {
  flex: 1;
  overflow-y: auto;
  padding: 1.25rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.left-panel-footer {
  padding: 1rem;
  border-top: 2px solid #e8edff;
  background: var(--white);
  display: flex;
  flex-direction: column;
  gap: .5rem;
}

/* --- Start Chat button --- */
.chat-start-btn {
  width: 100%;
  padding: .85rem 1rem;
  background: linear-gradient(135deg, var(--purple) 0%, #9f7aea 100%);
  color: var(--white);
  border: none;
  border-radius: var(--radius-lg);
  font-family: var(--font);
  font-size: 1rem;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(108,99,255,.4);
  transition: transform .15s, box-shadow .15s;
}
.chat-start-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 20px rgba(108,99,255,.5);
}

/* --- Live chat button --- */
.live-btn {
  width: 100%;
  padding: .85rem 1rem;
  background: linear-gradient(135deg, var(--teal) 0%, #2c7a7b 100%);
  color: var(--white);
  border: none;
  border-radius: var(--radius-lg);
  font-family: var(--font);
  font-size: 1rem;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(56,178,172,.4);
  transition: transform .15s, box-shadow .15s;
}
.live-btn:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 8px 20px rgba(56,178,172,.5);
}
.live-btn:disabled { opacity: .55; cursor: not-allowed; }

.live-btn--stop {
  background: linear-gradient(135deg, var(--red) 0%, #c53030 100%);
  box-shadow: 0 4px 14px rgba(252,129,129,.4);
}
.live-btn--stop:hover:not(:disabled) {
  box-shadow: 0 8px 20px rgba(252,129,129,.5);
}
.live-btn--stop[hidden] { display: none; }

/* --- Live session status badge --- */
.live-status {
  display: flex;
  align-items: center;
  gap: .5rem;
  color: var(--teal);
  font-size: .85rem;
  font-weight: 700;
  padding: .5rem .75rem;
  background: rgba(56,178,172,.1);
  border-radius: var(--radius-md);
  border: 1.5px solid rgba(56,178,172,.3);
}
.live-status[hidden] { display: none !important; }

/* --- Right panel --- */
.right-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}

/* Collapse left panel on narrow screens */
@media (max-width: 680px) {
  .left-panel { display: none; }
}

/* --- Header --- */
.chat-header {
  background: var(--white);
  border-bottom: 2px solid #e8edff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .75rem 1.25rem;
  flex-shrink: 0;
  box-shadow: var(--shadow-sm);
  z-index: 10;
}
.header-left { display: flex; align-items: center; gap: .75rem; }
.header-mascot {
  font-size: 2rem;
  width: 46px;
  height: 46px;
  background: linear-gradient(135deg, #f6d365 0%, #fda085 100%);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.header-name {
  display: block;
  font-size: 1.15rem;
  font-weight: 900;
  color: var(--purple);
  line-height: 1.2;
}
.header-tagline {
  display: block;
  font-size: .75rem;
  color: var(--text-light);
  font-weight: 600;
}
.header-actions { display: flex; gap: .5rem; }
.hdr-btn {
  padding: .45rem .85rem;
  border: 2px solid #e2e8f0;
  border-radius: 50px;
  background: var(--white);
  font-family: var(--font);
  font-size: .8rem;
  font-weight: 700;
  cursor: pointer;
  color: var(--text);
  transition: background .15s, border-color .15s, color .15s;
}
.hdr-btn:hover { background: var(--purple-light); border-color: var(--purple); color: var(--purple); }
.hdr-btn--logout:hover { background: #fff5f5; border-color: var(--red); color: #c53030; }

/* --- Main chat area --- */
.chat-main {
  flex: 1;
  overflow-y: auto;
  padding: 1.25rem 1rem;
  scroll-behavior: smooth;
}
.messages { display: flex; flex-direction: column; gap: 1rem; max-width: 800px; margin: 0 auto; }

/* --- Footer --- */
.chat-footer {
  background: var(--white);
  border-top: 2px solid #e8edff;
  padding: .75rem 1rem;
  flex-shrink: 0;
  box-shadow: 0 -4px 16px rgba(0,0,0,.06);
}

/* Pending image */
.pending-image {
  position: relative;
  display: inline-flex;
  margin-bottom: .6rem;
}
.pending-image img {
  height: 64px;
  border-radius: var(--radius-sm);
  border: 3px solid var(--purple);
  object-fit: cover;
}
.remove-image-btn {
  position: absolute;
  top: -8px;
  right: -8px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--red);
  color: var(--white);
  border: none;
  font-size: .75rem;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

/* Mic status */
.mic-status {
  display: flex;
  align-items: center;
  gap: .5rem;
  color: #c53030;
  font-size: .85rem;
  font-weight: 700;
  margin-bottom: .5rem;
  padding-left: .25rem;
}
.mic-status[hidden] { display: none !important; }
.mic-pulse {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--red);
  animation: pulse-ring 1.2s cubic-bezier(0.215, 0.61, 0.355, 1) infinite;
}
@keyframes pulse-ring {
  0%   { transform: scale(.95); box-shadow: 0 0 0 0 rgba(252,129,129,.7); }
  70%  { transform: scale(1);   box-shadow: 0 0 0 8px rgba(252,129,129,0); }
  100% { transform: scale(.95); box-shadow: 0 0 0 0 rgba(252,129,129,0); }
}

/* Input row */
.input-row {
  display: flex;
  align-items: flex-end;
  gap: .5rem;
}
.tool-btn {
  flex-shrink: 0;
  min-width: 46px;
  height: 46px;
  padding: 0 .6rem;
  border-radius: 50px;
  border: 2.5px solid #e2e8f0;
  background: var(--white);
  font-size: 1rem;
  font-family: var(--font);
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .15s, border-color .15s, transform .1s;
}
.tool-btn:hover:not(:disabled) {
  background: var(--purple-light);
  border-color: var(--purple);
  transform: scale(1.08);
}
.tool-btn:disabled { opacity: .45; cursor: not-allowed; }
.tool-btn.listening {
  background: #fff5f5;
  border-color: var(--red);
  animation: mic-glow 1.2s ease-in-out infinite;
}
@keyframes mic-glow {
  0%, 100% { box-shadow: 0 0 0 0 rgba(252,129,129,.5); }
  50%       { box-shadow: 0 0 0 8px rgba(252,129,129,0); }
}

.input-wrap { flex: 1; }
.input-wrap textarea {
  width: 100%;
  padding: .7rem 1rem;
  border: 2.5px solid #e2e8f0;
  border-radius: var(--radius-lg);
  font-family: var(--font);
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
  resize: none;
  outline: none;
  line-height: 1.5;
  max-height: 120px;
  overflow-y: auto;
  transition: border-color .2s, box-shadow .2s;
}
.input-wrap textarea:focus {
  border-color: var(--purple);
  box-shadow: 0 0 0 3px rgba(108,99,255,.12);
}
.input-wrap textarea:disabled { background: #f7f8fc; }

.send-btn {
  flex-shrink: 0;
  padding: .7rem 1.1rem;
  background: linear-gradient(135deg, var(--purple) 0%, #9f7aea 100%);
  color: var(--white);
  border: none;
  border-radius: var(--radius-lg);
  font-family: var(--font);
  font-size: .95rem;
  font-weight: 800;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: .3rem;
  transition: transform .15s, box-shadow .15s;
  box-shadow: 0 4px 14px rgba(108,99,255,.35);
  white-space: nowrap;
  height: 46px;
}
.send-btn:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 8px 20px rgba(108,99,255,.45);
}
.send-btn:disabled { opacity: .55; cursor: not-allowed; }

/* ============================================================
   MESSAGE BUBBLES
   ============================================================ */
.msg-row {
  display: flex;
  align-items: flex-end;
  gap: .6rem;
  animation: msg-in .3s ease-out;
}
@keyframes msg-in {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

.msg-row.buddy { flex-direction: row; }
.msg-row.user  { flex-direction: row-reverse; }

.msg-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  flex-shrink: 0;
  align-self: flex-end;
}
.msg-row.buddy .msg-avatar {
  background: linear-gradient(135deg, #f6d365 0%, #fda085 100%);
}
.msg-row.user .msg-avatar {
  background: linear-gradient(135deg, var(--purple) 0%, #9f7aea 100%);
}

.msg-bubble {
  max-width: min(68%, 520px);
  padding: .85rem 1.1rem;
  border-radius: var(--radius-lg);
  line-height: 1.65;
  font-size: 1rem;
  font-weight: 600;
  word-break: break-word;
}

/* Buddy bubble */
.msg-row.buddy .msg-bubble {
  background: var(--white);
  color: var(--text);
  border-radius: 4px var(--radius-lg) var(--radius-lg) var(--radius-lg);
  box-shadow: var(--shadow-sm);
  border: 2px solid #e8edff;
}

/* User bubble */
.msg-row.user .msg-bubble {
  background: linear-gradient(135deg, var(--purple) 0%, #9f7aea 100%);
  color: var(--white);
  border-radius: var(--radius-lg) 4px var(--radius-lg) var(--radius-lg);
  box-shadow: 0 4px 14px rgba(108,99,255,.3);
}

/* Image inside bubble */
.msg-bubble img.msg-photo {
  display: block;
  max-width: 100%;
  max-height: 220px;
  border-radius: var(--radius-sm);
  margin-bottom: .4rem;
  object-fit: cover;
}

/* Markdown inside buddy bubble */
.msg-bubble p { margin: .35rem 0; }
.msg-bubble p:first-child { margin-top: 0; }
.msg-bubble p:last-child  { margin-bottom: 0; }
.msg-bubble ul, .msg-bubble ol {
  padding-left: 1.4rem;
  margin: .4rem 0;
}
.msg-bubble li { margin: .2rem 0; }
.msg-bubble strong { font-weight: 800; }
.msg-bubble em { font-style: italic; }
.msg-bubble code {
  background: #f0f4ff;
  border-radius: 4px;
  padding: .1em .35em;
  font-size: .9em;
  font-family: monospace;
}

/* Typing indicator */
.msg-bubble.typing-bubble {
  padding: .85rem 1.1rem;
  min-width: 70px;
}
.typing-dots {
  display: flex;
  gap: 5px;
  align-items: center;
  height: 22px;
}
.typing-dots span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #a0aec0;
  animation: dot-blink 1.4s infinite;
}
.typing-dots span:nth-child(2) { animation-delay: .2s; }
.typing-dots span:nth-child(3) { animation-delay: .4s; }
@keyframes dot-blink {
  0%, 80%, 100% { opacity: .25; transform: scale(.9); }
  40%           { opacity: 1;   transform: scale(1.1); }
}

/* Streaming cursor */
.stream-cursor {
  display: inline-block;
  width: 2px;
  height: 1em;
  background: var(--purple);
  margin-left: 2px;
  vertical-align: text-bottom;
  animation: cursor-blink .7s step-end infinite;
}
@keyframes cursor-blink {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0; }
}

/* ============================================================
   CAMERA MODAL
   ============================================================ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.6);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 1rem;
  animation: fade-in .2s ease;
}
/* Ensure [hidden] attribute works — CSS display:flex would otherwise override it */
.modal-overlay[hidden] { display: none !important; }
@keyframes fade-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.modal-box {
  background: var(--white);
  border-radius: 24px;
  padding: 1.5rem;
  width: 100%;
  max-width: 520px;
  box-shadow: 0 24px 64px rgba(0,0,0,.3);
  animation: slide-up .25s ease;
}
@keyframes slide-up {
  from { transform: translateY(30px); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}
.modal-header h3 { font-size: 1.15rem; font-weight: 800; color: var(--text); }
.modal-close {
  width: 32px; height: 32px;
  border-radius: 50%;
  border: none;
  background: #f0f4ff;
  font-size: 1rem;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  color: var(--text);
  font-weight: 700;
  transition: background .15s;
}
.modal-close:hover { background: var(--purple-light); }

.camera-viewport {
  width: 100%;
  aspect-ratio: 4/3;
  background: #1a202c;
  border-radius: var(--radius-md);
  overflow: hidden;
  position: relative;
  margin-bottom: 1rem;
}
.camera-viewport video,
.camera-viewport .capture-preview {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.capture-preview img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #1a202c;
}

.camera-actions {
  display: flex;
  gap: .6rem;
  flex-wrap: wrap;
}
.cam-btn {
  flex: 1;
  padding: .75rem 1rem;
  border: none;
  border-radius: var(--radius-md);
  font-family: var(--font);
  font-size: .95rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform .1s, box-shadow .1s;
  min-width: 130px;
}
.cam-btn--capture {
  background: linear-gradient(135deg, var(--purple) 0%, #9f7aea 100%);
  color: var(--white);
  box-shadow: 0 4px 14px rgba(108,99,255,.35);
}
.cam-btn--capture:hover { transform: translateY(-2px); }
.cam-btn--retake  { background: #f0f4ff; color: var(--text); }
.cam-btn--retake:hover { background: var(--purple-light); }
.cam-btn--use {
  background: linear-gradient(135deg, var(--green) 0%, #38a169 100%);
  color: var(--white);
  box-shadow: 0 4px 14px rgba(72,187,120,.35);
}
.cam-btn--use:hover { transform: translateY(-2px); }

/* ============================================================
   LIVE CHAT MODAL
   ============================================================ */
.live-modal {
  max-width: 360px;
}

.live-image-section {
  margin-bottom: 1.25rem;
}

.live-hint {
  text-align: center;
  font-size: .85rem;
  font-weight: 600;
  color: var(--text-light);
  margin-bottom: .75rem;
}

.live-pending-image {
  position: relative;
  display: flex;
  justify-content: center;
  margin-bottom: .75rem;
}
.live-pending-image img {
  height: 110px;
  max-width: 100%;
  border-radius: var(--radius-md);
  border: 3px solid var(--teal);
  object-fit: cover;
}
.live-pending-image .remove-image-btn {
  top: -8px;
  right: calc(50% - 55px - 8px);
}

.live-mic-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .75rem;
  padding: .5rem 0 .25rem;
}

.live-mic-btn {
  width: 110px;
  height: 110px;
  border-radius: 50%;
  border: none;
  background: linear-gradient(135deg, var(--teal) 0%, #2c7a7b 100%);
  color: var(--white);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: .25rem;
  font-family: var(--font);
  box-shadow: 0 6px 24px rgba(56,178,172,.45);
  transition: transform .15s, box-shadow .15s;
}
.live-mic-btn:hover:not(:disabled) {
  transform: scale(1.06);
  box-shadow: 0 10px 32px rgba(56,178,172,.55);
}
.live-mic-btn:disabled { opacity: .6; cursor: not-allowed; }

.live-mic-icon {
  font-size: 2.2rem;
  line-height: 1;
}
.live-mic-label {
  font-size: .7rem;
  font-weight: 800;
  letter-spacing: .05em;
  text-transform: uppercase;
}

.live-mic-btn.active {
  background: linear-gradient(135deg, var(--red) 0%, #c53030 100%);
  box-shadow: 0 6px 24px rgba(252,129,129,.55);
  animation: live-mic-pulse 1.5s ease-in-out infinite;
}
.live-mic-btn.active:hover:not(:disabled) {
  box-shadow: 0 10px 32px rgba(252,129,129,.65);
}
@keyframes live-mic-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(252,129,129,.7), 0 6px 24px rgba(252,129,129,.45); }
  60%       { box-shadow: 0 0 0 14px rgba(252,129,129,0), 0 6px 24px rgba(252,129,129,.45); }
}

.live-mic-hint {
  font-size: .82rem;
  font-weight: 600;
  color: var(--text-light);
  text-align: center;
}

/* ============================================================
   TOAST
   ============================================================ */
.toast {
  position: fixed;
  bottom: 90px;
  left: 50%;
  transform: translateX(-50%);
  background: #2d3748;
  color: var(--white);
  padding: .7rem 1.4rem;
  border-radius: 50px;
  font-size: .9rem;
  font-weight: 700;
  z-index: 200;
  box-shadow: var(--shadow);
  animation: toast-in .3s ease;
  white-space: nowrap;
}
@keyframes toast-in {
  from { opacity: 0; transform: translateX(-50%) translateY(10px); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* ============================================================
   SCROLLBAR
   ============================================================ */
.chat-main::-webkit-scrollbar { width: 6px; }
.chat-main::-webkit-scrollbar-track { background: transparent; }
.chat-main::-webkit-scrollbar-thumb { background: #cbd5e0; border-radius: 3px; }

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 520px) {
  .chat-header { padding: .6rem .75rem; }
  .header-tagline { display: none; }
  .hdr-btn { font-size: .75rem; padding: .4rem .65rem; }
  .chat-footer { padding: .6rem .75rem; }
  .send-btn span:first-child { display: none; }
  .msg-bubble { font-size: .95rem; }
  .chat-main { padding: 1rem .75rem; }
}
