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

/* ── Font ──────────────────────────────────────────────────────────────── */
@font-face {
  font-family: 'Satoshi';
  src: url('assets/Satoshi-Variable.ttf') format('truetype');
  font-weight: 300 900;
  font-display: swap;
}

/* ── Design Tokens (Dark Mode Default) ─────────────────────────────────── */
:root {
  /* Backgrounds */
  --bg: #161616;
  --bg-secondary: #212121;
  --bg-tertiary: #333333;

  /* Text */
  --text: #F5F5F5;
  --text-secondary: #949A9C;
  --text-tertiary: #798183;
  --placeholder: #798183;

  /* Brand */
  --primary: #FF9021;
  --primary-text: #FFFFFF;

  /* Bubbles */
  --bubble-outgoing: #FF9021;
  --bubble-outgoing-text: #FFFFFF;
  --bubble-incoming: #242424;
  --bubble-incoming-text: #F5F5F5;

  /* Glass */
  --glass: rgba(120, 120, 120, 0.14);
  --glass-border: rgba(255, 255, 255, 0.12);

  /* Status */
  --success: #10B981;
  --error: #EF4444;

  /* Border */
  --border: #404040;

  /* Spacing */
  --space-xs: 4px;
  --space-sm: 8px;
  --space-md: 12px;
  --space-lg: 16px;
  --space-xl: 20px;
  --space-xxl: 24px;
  --space-xxxl: 32px;

  /* Radii */
  --radii-xs: 4px;
  --radii-sm: 12px;
  --radii-md: 16px;
  --radii-lg: 20px;
  --radii-xl: 24px;
  --radii-pill: 999px;

  /* Font */
  --font: 'Satoshi', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;

  /* Timestamp on user bubble */
  --timestamp-user: rgba(255, 255, 255, 0.55);
  --timestamp-assistant: #636366;

  /* Page background (behind the frame on desktop) */
  --page-bg: #0D0D0D;
}

/* ── Light Mode ────────────────────────────────────────────────────────── */
[data-theme="light"] {
  --bg: #FFFFFF;
  --bg-secondary: #F9FAFB;
  --bg-tertiary: #EBEDF0;

  --text: #111827;
  --text-secondary: #5F6B6E;
  --text-tertiary: #737B7E;
  --placeholder: #737B7E;

  --primary: #FF9021;
  --primary-text: #FFFFFF;

  --bubble-outgoing: #FF9021;
  --bubble-outgoing-text: #FFFFFF;
  --bubble-incoming: #EBEDF0;
  --bubble-incoming-text: #111827;

  --glass: rgba(120, 120, 120, 0.10);
  --glass-border: rgba(0, 0, 0, 0.14);

  --success: #10B981;
  --error: #EF4444;

  --border: #C9CDCE;

  --timestamp-user: rgba(255, 255, 255, 0.55);
  --timestamp-assistant: #636366;

  --page-bg: #F0F0F0;
}

/* ── Base ──────────────────────────────────────────────────────────────── */
html, body {
  height: 100%;
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  background: var(--page-bg);
  color: var(--text);
  overflow: hidden;
}

/* ── Page Background ──────────────────────────────────────────────────── */
.page-bg {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100dvh;
  background: var(--page-bg);
}

/* ── Chat Frame ───────────────────────────────────────────────────────── */
.chat-frame {
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 420px;
  height: 90dvh;
  max-height: 844px;
  background: var(--bg);
  border-radius: var(--radii-xl);
  border: 1px solid var(--glass-border);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.3);
  overflow: hidden;
  position: relative;
}

@media (max-width: 480px) {
  .page-bg {
    align-items: stretch;
  }
  .chat-frame {
    max-width: 100%;
    max-height: none;
    height: 100dvh;
    border-radius: 0;
    border: none;
    box-shadow: none;
  }
}

/* ── Header ───────────────────────────────────────────────────────────── */
.header {
  display: flex;
  align-items: center;
  padding: var(--space-md) var(--space-xl);
  padding-top: var(--space-lg);
  gap: var(--space-sm);
  z-index: 10;
  flex-shrink: 0;
  background: var(--glass);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  border-bottom: 1px solid var(--glass-border);
}

@media (max-width: 480px) {
  .header {
    padding-top: max(var(--space-lg), env(safe-area-inset-top, var(--space-lg)));
  }
}

.profile-pill {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  border: 1px solid var(--glass-border);
  border-radius: var(--radii-pill);
  padding: 4px 20px 4px 4px;
  max-width: 70%;
  overflow: hidden;
  background: var(--glass);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
}

.header-avatar {
  width: 40px;
  height: 40px;
  border-radius: var(--radii-lg);
  border: 1px solid var(--glass-border);
  overflow: hidden;
  flex-shrink: 0;
}

.header-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.header-info {
  min-width: 0;
  overflow: hidden;
}

.contact-name {
  font-size: 16px;
  font-weight: 600;
  font-family: var(--font);
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.contact-status {
  font-size: 12px;
  font-weight: 500;
  font-family: var(--font);
  color: var(--text-secondary);
  margin-top: 1px;
}

.header-spacer {
  flex: 1;
}

.theme-toggle {
  width: 36px;
  height: 36px;
  border-radius: var(--radii-lg);
  border: 1px solid var(--glass-border);
  background: var(--glass);
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: color 0.2s, background 0.2s;
}

.theme-toggle:hover {
  color: var(--text);
  background: var(--bg-secondary);
}

.theme-toggle svg {
  width: 18px;
  height: 18px;
}

/* Sun icon shown in dark mode, moon in light mode */
.theme-icon-sun { display: block; }
.theme-icon-moon { display: none; }
[data-theme="light"] .theme-icon-sun { display: none; }
[data-theme="light"] .theme-icon-moon { display: block; }

/* ── Messages Container ───────────────────────────────────────────────── */
.messages-container {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: none;
  -webkit-overflow-scrolling: touch;
}

.messages-scroll {
  display: flex;
  flex-direction: column;
  min-height: 100%;
  justify-content: flex-end;
  padding: var(--space-lg) 0;
}

/* ── Message Bubble ───────────────────────────────────────────────────── */
.message {
  margin: 4px 0;
  padding: 0 14px;
  display: flex;
}

.message--user {
  justify-content: flex-end;
}

.message--assistant {
  justify-content: flex-start;
}

.bubble-wrap {
  max-width: 88%;
  display: flex;
  flex-direction: column;
}

.bubble {
  padding: var(--space-md);
  border-radius: var(--radii-lg);
  font-size: 16px;
  line-height: 22px;
  font-weight: 500;
  font-family: var(--font);
  word-break: break-word;
  white-space: pre-wrap;
}

.bubble--user {
  background: var(--bubble-outgoing);
  color: var(--bubble-outgoing-text);
  border-bottom-right-radius: var(--radii-xs);
}

.bubble--assistant {
  background: var(--bubble-incoming);
  color: var(--bubble-incoming-text);
  border-bottom-left-radius: var(--radii-xs);
}

/* ── Timestamp Row ────────────────────────────────────────────────────── */
.timestamp-row {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
  margin-top: 3px;
  padding: 0 2px;
}

.message--user .timestamp-row {
  justify-content: flex-end;
}

.timestamp-text {
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.25px;
  font-family: var(--font);
}

.message--user .timestamp-text {
  color: var(--timestamp-user);
}

.message--assistant .timestamp-text {
  color: var(--timestamp-assistant);
}

/* ── Typing Indicator ─────────────────────────────────────────────────── */
.typing-indicator {
  margin: 4px 0;
  padding: 0 14px;
  display: flex;
  justify-content: flex-start;
}

.typing-bubble {
  padding: var(--space-md) var(--space-lg);
  border-radius: var(--radii-lg);
  border-bottom-left-radius: var(--radii-xs);
  background: var(--bubble-incoming);
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ── Streaming Cursor ─────────────────────────────────────────────────── */
.streaming-cursor::after {
  content: '';
  display: inline-block;
  width: 2px;
  height: 16px;
  background: var(--bubble-incoming-text);
  margin-left: 2px;
  vertical-align: text-bottom;
  animation: cursor-blink 0.8s step-end infinite;
}

@keyframes cursor-blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}

/* ── Welcome Message ──────────────────────────────────────────────────── */
.welcome-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--space-xxxl) var(--space-xl);
  text-align: center;
  gap: var(--space-lg);
  flex: 1;
}

.welcome-loader {
  margin-bottom: var(--space-sm);
}

.welcome-title {
  font-size: 20px;
  font-weight: 600;
  font-family: var(--font);
  color: var(--text);
}

.welcome-subtitle {
  font-size: 14px;
  font-weight: 500;
  font-family: var(--font);
  color: var(--text-secondary);
  line-height: 20px;
  max-width: 280px;
}

/* ── Input Area ───────────────────────────────────────────────────────── */
.input-area {
  display: flex;
  align-items: flex-end;
  padding: var(--space-sm) var(--space-md);
  gap: var(--space-sm);
  flex-shrink: 0;
  background: var(--bg);
  border-top: 1px solid var(--glass-border);
}

@media (max-width: 480px) {
  .input-area {
    padding-bottom: max(var(--space-sm), env(safe-area-inset-bottom, var(--space-sm)));
  }
}

.input-wrapper {
  flex: 1;
  position: relative;
  border: 1px solid var(--glass-border);
  border-radius: var(--radii-xl);
  overflow: hidden;
  background: var(--glass);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
}

.input-field {
  width: 100%;
  min-height: 38px;
  max-height: 160px;
  border: none;
  border-radius: var(--radii-xl);
  padding: 9px 14px;
  font-size: 16px;
  line-height: 20px;
  font-weight: 500;
  font-family: var(--font);
  background: transparent;
  color: var(--text);
  resize: none;
  outline: none;
  overflow-y: auto;
}

.input-field::placeholder {
  color: var(--placeholder);
}

.send-btn {
  width: 38px;
  height: 38px;
  border-radius: var(--radii-lg);
  background: var(--primary);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: white;
  transition: opacity 0.15s;
}

.send-btn:disabled {
  background: var(--text-tertiary);
  cursor: not-allowed;
  opacity: 0.6;
}

.send-btn:not(:disabled):active {
  opacity: 0.85;
}

.send-btn svg {
  width: 18px;
  height: 18px;
}

/* ── Privacy Notice ───────────────────────────────────────────────────── */
.privacy-notice {
  text-align: center;
  padding: var(--space-xs) var(--space-md);
  font-size: 10px;
  font-weight: 500;
  font-family: var(--font);
  color: var(--text-tertiary);
  flex-shrink: 0;
}

/* ── AivenLoader Animation ────────────────────────────────────────────── */
.aiven-loader {
  animation: breathe 1.4s ease-in-out infinite;
  display: block;
}

@keyframes breathe {
  0%, 100% { transform: scale(0.92); }
  50% { transform: scale(1.08); }
}

.aiven-eyes {
  animation: gaze 4.81s ease-in-out infinite;
}

@keyframes gaze {
  0%    { transform: translateX(0); }
  6.2%  { transform: translateX(16px); }
  10%   { transform: translateX(16px); }
  17.3% { transform: translateX(-16px); }
  21%   { transform: translateX(-16px); }
  28.3% { transform: translateX(16px); }
  31.8% { transform: translateX(16px); }
  37%   { transform: translateX(0); }
  100%  { transform: translateX(0); }
}

.aiven-blink {
  animation: blink 4.81s linear infinite;
}

@keyframes blink {
  0%, 30%    { opacity: 1; }
  31%        { opacity: 0; }
  32.5%      { opacity: 1; }
  100%       { opacity: 1; }
}

/* ── Day Divider ──────────────────────────────────────────────────────── */
.day-divider {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-md) var(--space-xl);
}

.day-divider-text {
  font-size: 11px;
  font-weight: 600;
  font-family: var(--font);
  color: var(--text-tertiary);
  letter-spacing: 0.5px;
  text-transform: uppercase;
}

/* ── Error Banner ─────────────────────────────────────────────────────── */
.error-banner {
  padding: var(--space-sm) var(--space-lg);
  background: rgba(239, 68, 68, 0.12);
  border-bottom: 1px solid rgba(239, 68, 68, 0.2);
  text-align: center;
  font-size: 13px;
  font-weight: 500;
  font-family: var(--font);
  color: var(--error);
  display: none;
  flex-shrink: 0;
}

.error-banner.visible {
  display: block;
}

/* ── Connection Status Colors ─────────────────────────────────────────── */
.status--online { color: var(--success); }
.status--connecting { color: var(--text-tertiary); }
.status--error { color: var(--error); }

/* ── Scrollbar Styling ────────────────────────────────────────────────── */
.messages-container::-webkit-scrollbar {
  width: 4px;
}

.messages-container::-webkit-scrollbar-track {
  background: transparent;
}

.messages-container::-webkit-scrollbar-thumb {
  background: var(--glass-border);
  border-radius: 2px;
}

.messages-container::-webkit-scrollbar-thumb:hover {
  background: var(--text-tertiary);
}

/* ── Loading Skeleton ─────────────────────────────────────────────────── */
.loading-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  gap: var(--space-md);
}

.loading-text {
  font-size: 13px;
  font-weight: 500;
  font-family: var(--font);
  color: var(--text-tertiary);
}
