:root {
  --bg:          #f3f5f8;
  --surface:     #ffffff;
  --surface-2:   #fafbfc;
  --accent:      #1a4d6b;
  --accent-2:    #133a52;
  --accent-dim:  rgba(26, 77, 107, 0.12);
  --text:        #1a1d24;
  --muted:       #5a6070;
  --border:      #dde1e8;
  --bubble-in:   #ffffff;
  --bubble-out:  #1a4d6b;
  --bubble-out-text: #ffffff;
  --shadow-sm:   0 1px 2px rgba(0,0,0,0.04);
  --shadow:      0 4px 12px rgba(0,0,0,0.06);
  --shadow-accent: 0 4px 14px rgba(26,77,107,0.28);
  --radius:      14px;
}

/* Typing-Indicator-Dots */
.dots { display: inline-flex; gap: 4px; align-items: center; padding: 4px 0; }
.dots span {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--muted); opacity: 0.5;
  animation: dot-bounce 1.2s infinite;
}
.dots span:nth-child(2) { animation-delay: 0.15s; }
.dots span:nth-child(3) { animation-delay: 0.3s; }
@keyframes dot-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30%           { transform: translateY(-4px); opacity: 1; }
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body {
  height: 100%;
  font-family: "Lexend", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  font-size: 15px;
  overscroll-behavior: none;
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
}

/* ===== Header ===== */
.chat-header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  padding-top: calc(env(safe-area-inset-top) + 10px);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}
.chat-header .title { display: flex; align-items: center; gap: 10px; }
.chat-header .avatar {
  width: 38px; height: 38px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: grid; place-items: center;
  font-weight: 700;
  box-shadow: var(--shadow-accent);
}
.chat-header strong { font-size: 16px; font-weight: 600; line-height: 1.1; display: block; }
.chat-header .sub { display: block; font-size: 12px; color: var(--muted); margin-top: 2px; }
.chat-header .header-link {
  color: var(--muted);
  font-size: 18px;
  text-decoration: none;
  padding: 8px 12px;
  border-radius: 10px;
}
.chat-header .header-link:active { background: var(--accent-dim); }

/* ===== Messages ===== */
.chat {
  flex: 1 1 auto;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 14px 12px 8px;
  -webkit-overflow-scrolling: touch;
}
.messages {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 100%;
}
.messages > .empty {
  margin: auto;
  text-align: center;
  color: var(--muted);
  font-size: 14px;
  padding: 40px 24px;
  line-height: 1.5;
}

.msg {
  display: flex;
  max-width: 84%;
  flex-direction: column;
  gap: 2px;
}
.msg.out { align-self: flex-end; align-items: flex-end; }
.msg.in  { align-self: flex-start; align-items: flex-start; }

.bubble {
  padding: 10px 14px;
  border-radius: 18px;
  font-size: 15px;
  line-height: 1.45;
  word-wrap: break-word;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
  box-shadow: var(--shadow-sm);
}
.msg.in .bubble {
  background: var(--bubble-in);
  color: var(--text);
  border: 1px solid var(--border);
  border-bottom-left-radius: 6px;
}
.msg.out .bubble {
  background: var(--bubble-out);
  color: var(--bubble-out-text);
  border-bottom-right-radius: 6px;
}
.msg.pending .bubble { opacity: 0.7; }
.msg.error   .bubble { background: #8a2a2d; color: #fff; }

.bubble audio {
  display: block;
  width: 220px;
  max-width: 100%;
  height: 36px;
  margin-top: 4px;
}

.msg .meta {
  font-size: 11px;
  color: var(--muted);
  padding: 0 8px;
}

/* ===== Composer ===== */
.composer {
  position: sticky;
  bottom: 0;
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 10px 12px;
  padding-bottom: calc(env(safe-area-inset-bottom) + 10px);
  background: var(--surface);
  border-top: 1px solid var(--border);
  box-shadow: 0 -4px 12px rgba(0,0,0,0.04);
}
.msg-input {
  flex: 1;
  height: 44px;
  padding: 0 18px;
  border: 1px solid var(--border);
  border-radius: 22px;
  font-family: inherit;
  font-size: 16px;
  background: var(--surface-2);
  color: var(--text);
  outline: none;
  transition: border-color .15s, background .15s;
}
.msg-input:focus {
  border-color: var(--accent);
  background: var(--surface);
}

.btn-mic, .btn-send {
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: #fff;
  display: grid; place-items: center;
  font-family: inherit;
  cursor: pointer;
  box-shadow: var(--shadow-accent);
  transition: transform .1s, background .15s;
  -webkit-user-select: none; user-select: none;
  touch-action: manipulation;
}
.btn-mic:active, .btn-send:active { transform: scale(0.94); }
.btn-mic.recording {
  background: var(--accent-2);
  animation: pulse 1.1s infinite;
}
@keyframes pulse {
  0%, 100% { box-shadow: var(--shadow-accent), 0 0 0 0 rgba(229,72,77,0.55); }
  50%      { box-shadow: var(--shadow-accent), 0 0 0 12px rgba(229,72,77,0); }
}

/* ===== Recording overlay ===== */
.rec-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.72);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  z-index: 100;
  color: #fff;
  padding: 24px;
  text-align: center;
  backdrop-filter: blur(4px);
}
.rec-dot {
  width: 96px; height: 96px;
  border-radius: 50%;
  background: var(--accent);
  display: grid; place-items: center;
  animation: pulse 1.1s infinite;
  cursor: pointer;
  border: none;
  padding: 0;
}
.rec-dot:active { transform: scale(0.94); }
.rec-dot::before {
  content: "";
  width: 22px; height: 22px;
  background: #fff;
  border-radius: 4px;
}
.rec-time { font-size: 38px; font-weight: 700; font-variant-numeric: tabular-nums; }
.rec-hint { font-size: 14px; opacity: 0.85; max-width: 280px; line-height: 1.4; }
.btn-rec-cancel {
  background: transparent;
  color: #fff;
  border: 1px solid rgba(255,255,255,0.3);
  padding: 10px 22px;
  border-radius: 22px;
  font-family: inherit;
  font-size: 14px;
  cursor: pointer;
  margin-top: 8px;
}

/* ===== Toast ===== */
.toast {
  position: fixed;
  bottom: calc(env(safe-area-inset-bottom) + 80px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: #fff;
  padding: 10px 18px;
  border-radius: 20px;
  font-size: 14px;
  box-shadow: 0 6px 20px rgba(0,0,0,0.25);
  z-index: 50;
  max-width: calc(100% - 40px);
  text-align: center;
}

.hidden { display: none !important; }

.day-sep {
  align-self: center;
  font-size: 11px;
  color: var(--muted);
  padding: 4px 12px;
  margin: 8px 0;
  background: var(--surface);
  border-radius: 12px;
  border: 1px solid var(--border);
}
