/* ============================================================
   JuliaChat — стили
   Две темы: «Вопрос» (розовая) и «Фото» (фиолетовая).
   Мобильный чат в духе ChatGPT/Claude.
   ============================================================ */

:root {
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --radius: 18px;
  --radius-sm: 12px;

  /* Розовая тема (Вопрос) — по умолчанию */
  --bg: #fdf2f6;
  --bg-deep: #ecd6e0;
  --bg-soft: #fbe8f0;
  --header: #f7d6e0;
  --accent: #e26d9a;
  --accent-soft: #f6c9db;
  --bubble-user: #f4a9c7;
  --bubble-user-text: #4a1f33;
  --bubble-ai: #ffffff;
  --bubble-ai-text: #3a2630;
  --text: #4a2b3a;
  --muted: #a97e90;
  --border: #f2d3df;
  --input-bg: #ffffff;
  --shadow: 0 2px 14px rgba(200, 100, 150, 0.12);
}

/* Фиолетовая тема (Фото) */
body.theme-photo {
  --bg: #f6f1fb;
  --bg-deep: #ddccef;
  --bg-soft: #efe6f8;
  --header: #e2d3f2;
  --accent: #9a6dd0;
  --accent-soft: #d9c9f0;
  --bubble-user: #c3a9ef;
  --bubble-user-text: #2f1f4a;
  --bubble-ai: #ffffff;
  --bubble-ai-text: #322640;
  --text: #3a2b4a;
  --muted: #907ea9;
  --border: #e0d3f2;
  --input-bg: #ffffff;
  --shadow: 0 2px 14px rgba(140, 100, 200, 0.12);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html {
  height: 100%;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  font-family: var(--font);
  color: var(--text);
  background: var(--bg-deep, #e8d0da);
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
  transition: background 0.4s ease;
}
body.theme-photo { background: var(--bg-deep, #d6c5ec); }

#root {
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  transition: background 0.4s ease;
  /* На широком экране — колонка по центру, как окно телефона */
  max-width: 480px;
  margin: 0 auto;
  position: relative;
  box-shadow: 0 0 40px rgba(0,0,0,0.08);
}

/* ============================================================ ЭКРАН ВХОДА */
.login-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  padding-top: calc(24px + env(safe-area-inset-top, 0px));
  padding-bottom: calc(24px + env(safe-area-inset-bottom, 0px));
}
.login-card {
  width: 100%;
  max-width: 360px;
  background: rgba(255, 255, 255, 0.86);
  backdrop-filter: blur(8px);
  border-radius: 24px;
  padding: 34px 26px;
  box-shadow: var(--shadow);
  text-align: center;
}
.login-emoji { font-size: 44px; margin-bottom: 8px; }
.login-title {
  font-size: 24px;
  font-weight: 700;
  margin: 0 0 4px;
  color: var(--text);
}
.login-sub {
  font-size: 14px;
  color: var(--muted);
  margin: 0 0 24px;
}
.field {
  margin-bottom: 14px;
  text-align: left;
}
.field label {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 5px;
  padding-left: 4px;
}
.field input {
  width: 100%;
  padding: 14px 16px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 16px;
  font-family: var(--font);
  background: #fff;
  color: var(--text);
  outline: none;
  transition: border-color 0.15s;
}
.field input:focus { border-color: var(--accent); }
.btn-primary {
  width: 100%;
  padding: 15px;
  margin-top: 8px;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: #fff;
  font-size: 16px;
  font-weight: 600;
  font-family: var(--font);
  cursor: pointer;
  transition: filter 0.15s;
}
.btn-primary:active { filter: brightness(0.94); }
.btn-primary:disabled { opacity: 0.6; }
.login-error {
  color: #d14343;
  font-size: 13px;
  margin-top: 12px;
  min-height: 18px;
}

/* ============================================================ ШАПКA */
.app-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  padding-top: calc(10px + env(safe-area-inset-top, 0px));
  background: var(--header);
  transition: background 0.4s ease;
  position: relative;
  z-index: 20;
}
.icon-btn {
  border: none;
  background: transparent;
  font-size: 22px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--text);
  flex-shrink: 0;
}
.icon-btn:active { background: rgba(0, 0, 0, 0.05); }
.header-title {
  flex: 1;
  font-size: 17px;
  font-weight: 600;
  text-align: center;
  color: var(--text);
}

/* ============================================================ ПЕРЕКЛЮЧАТЕЛЬ РЕЖИМОВ (две кнопки сверху) */
.mode-switch {
  display: flex;
  gap: 10px;
  padding: 12px;
  background: var(--header);
  transition: background 0.4s ease;
}
.mode-btn {
  flex: 1;
  padding: 16px 12px;
  border: none;
  border-radius: var(--radius);
  font-size: 16px;
  font-weight: 600;
  font-family: var(--font);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: transform 0.12s, box-shadow 0.2s, background 0.2s;
  background: rgba(255, 255, 255, 0.55);
  color: var(--text);
}
.mode-btn .mode-emoji { font-size: 20px; }
.mode-btn.active {
  background: #fff;
  box-shadow: var(--shadow);
  color: var(--accent);
}
.mode-btn:active { transform: scale(0.97); }

/* ============================================================ ОБЛАСТЬ СООБЩЕНИЙ */
.chat-area {
  flex: 1;
  overflow-y: auto;
  padding: 16px 12px 8px;
  -webkit-overflow-scrolling: touch;
}
.welcome {
  text-align: center;
  padding: 40px 24px;
  color: var(--muted);
}
.welcome-emoji { font-size: 52px; margin-bottom: 12px; }
.welcome-title {
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
  margin: 0 0 8px;
}
.welcome-text { font-size: 14px; line-height: 1.5; margin: 0; }

.msg {
  display: flex;
  margin-bottom: 14px;
  animation: fadein 0.25s ease;
}
@keyframes fadein {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}
.msg.user { justify-content: flex-end; }
.bubble {
  max-width: 82%;
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: 15.5px;
  line-height: 1.5;
  word-wrap: break-word;
  white-space: pre-wrap;
}
.msg.user .bubble {
  background: var(--bubble-user);
  color: var(--bubble-user-text);
  border-bottom-right-radius: 6px;
}
.msg.ai .bubble {
  background: var(--bubble-ai);
  color: var(--bubble-ai-text);
  border-bottom-left-radius: 6px;
  box-shadow: var(--shadow);
}
.bubble img {
  max-width: 100%;
  border-radius: var(--radius-sm);
  display: block;
}
.bubble img + .bubble-caption { margin-top: 6px; }
.bubble-caption { font-size: 13px; color: var(--muted); }

/* картинка, загруженная пользователем, в пузыре */
.user-photo {
  max-width: 200px;
  border-radius: var(--radius-sm);
  margin-bottom: 6px;
  display: block;
}

/* чип документа в пузыре */
.doc-chip {
  display: inline-block;
  background: rgba(255, 255, 255, 0.5);
  border-radius: 10px;
  padding: 6px 12px;
  font-size: 13px;
  margin-bottom: 6px;
  font-weight: 500;
}

/* выбор действия с документом: спросить / изменить */
.doc-actions {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
}
.doc-action {
  flex: 1;
  padding: 9px 12px;
  border: 1.5px solid var(--border);
  background: var(--input-bg);
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-family: var(--font);
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  transition: all 0.15s;
}
.doc-action.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

/* индикатор набора */
.typing {
  display: inline-flex;
  gap: 4px;
  align-items: center;
  padding: 4px 2px;
}
.typing span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  opacity: 0.6;
  animation: bounce 1.2s infinite;
}
.typing span:nth-child(2) { animation-delay: 0.2s; }
.typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
  30% { transform: translateY(-5px); opacity: 1; }
}

/* результат редактирования фото */
.result-img-wrap { position: relative; }
.download-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 8px;
  padding: 9px 14px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  font-family: var(--font);
  cursor: pointer;
  text-decoration: none;
}

/* ============================================================ ПОЛЕ ВВОДА */
.input-bar {
  padding: 10px 12px;
  padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px));
  background: var(--header);
  transition: background 0.4s ease;
}
.input-inner {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--input-bg);
  border-radius: 24px;
  padding: 6px 6px 6px 8px;
  box-shadow: var(--shadow);
}
.attach-btn {
  border: none;
  background: transparent;
  font-size: 22px;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  cursor: pointer;
  flex-shrink: 0;
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
}
.attach-btn:active { background: var(--bg-soft); }
.input-box {
  flex: 1;
  border: none;
  outline: none;
  resize: none;
  font-size: 16px;
  font-family: var(--font);
  line-height: 1.4;
  max-height: 120px;
  padding: 9px 4px;
  background: transparent;
  color: var(--text);
}
.mic-btn {
  border: none;
  background: transparent;
  font-size: 20px;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  cursor: pointer;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent);
  transition: background 0.15s;
}
.mic-btn:active { background: var(--bg-soft); }
.mic-btn:disabled { opacity: 0.5; }
.mic-btn.recording {
  background: var(--accent);
  color: #fff;
  animation: pulse 1.2s infinite;
}
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(226, 109, 154, 0.5); }
  50% { box-shadow: 0 0 0 8px rgba(226, 109, 154, 0); }
}

.send-btn {
  border: none;
  background: var(--accent);
  color: #fff;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  font-size: 18px;
  cursor: pointer;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: filter 0.15s;
}
.send-btn:active { filter: brightness(0.92); }
.send-btn:disabled { opacity: 0.4; }

/* превью прикреплённого фото над полем ввода */
.attach-preview {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  margin-bottom: 8px;
  background: var(--input-bg);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
}
.attach-preview img {
  width: 44px;
  height: 44px;
  object-fit: cover;
  border-radius: 8px;
}
.attach-preview .name {
  flex: 1;
  font-size: 13px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.attach-preview .remove {
  border: none;
  background: transparent;
  font-size: 18px;
  color: var(--muted);
  cursor: pointer;
}

/* подсказка для режима фото */
.photo-hint {
  font-size: 12.5px;
  color: var(--muted);
  text-align: center;
  padding: 0 20px 8px;
}

/* ============================================================ БОКОВОЕ МЕНЮ */
.drawer-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
  z-index: 40;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s;
}
.drawer-overlay.open { opacity: 1; pointer-events: auto; }
.drawer {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: 78%;
  max-width: 320px;
  background: var(--bg);
  z-index: 41;
  transform: translateX(-100%);
  transition: transform 0.28s ease;
  display: flex;
  flex-direction: column;
  padding-top: calc(env(safe-area-inset-top, 0px));
  box-shadow: 2px 0 24px rgba(0, 0, 0, 0.12);
}
.drawer.open { transform: translateX(0); }
.drawer-header {
  padding: 18px 16px 12px 20px;
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.drawer-close {
  border: none;
  background: transparent;
  font-size: 18px;
  color: var(--muted);
  width: 34px;
  height: 34px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.drawer-close:active { background: var(--bg-soft); }
.drawer-new {
  margin: 0 16px 8px;
  padding: 13px 16px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-weight: 600;
  font-family: var(--font);
  cursor: pointer;
  text-align: left;
}
.drawer-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px 12px;
}
.drawer-item {
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  color: var(--text);
  cursor: pointer;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-bottom: 2px;
}
.drawer-item:active { background: var(--bg-soft); }
.drawer-item.active { background: var(--accent-soft); font-weight: 600; }
.drawer-footer {
  padding: 10px 16px;
  padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
}
.drawer-logout {
  background: transparent;
  border: none;
  padding: 8px 6px;
  color: var(--muted);
  font-size: 12.5px;
  font-family: var(--font);
  cursor: pointer;
  opacity: 0.7;
}
.drawer-logout:active { opacity: 1; }

.hidden { display: none !important; }

/* ============================================================ SVG-иконки в кнопках */
.icon-btn svg, .mode-btn svg, .attach-btn svg, .mic-btn svg, .send-btn svg { display: block; }
.mode-btn svg { margin-right: 2px; }

/* Стоп-кнопка (во время вывода) */
.send-btn.stop { background: var(--text); }

/* ============================================================ Список чатов: удаление */
.drawer-item {
  display: flex;
  align-items: center;
  gap: 6px;
}
.drawer-item-title {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.drawer-item-del {
  border: none;
  background: transparent;
  color: var(--muted);
  width: 28px;
  height: 28px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  opacity: 0.55;
}
.drawer-item-del:active { background: rgba(0,0,0,0.06); opacity: 1; }
.drawer-empty {
  padding: 20px 14px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
}

/* Мик-кнопка в записи */
.mic-btn.recording {
  background: var(--accent);
  color: #fff;
  border-radius: 50%;
  animation: pulse 1.2s infinite;
}
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(226,109,154,0.5); }
  50% { box-shadow: 0 0 0 8px rgba(226,109,154,0); }
}
