/* ==== Речной сплав — стили ==== */
:root {
  --water-deep: #0a3d62;
  --water-mid: #1e5f8c;
  --water-light: #4a90a4;
  --water-foam: #c5dde6;
  --water-sky: #e8f1f5;
  --wood: #8b5a3c;
  --wood-dark: #5d3a20;
  --sand: #d4b896;
  --forest: #2d5016;
  --forest-mid: #4a7c2e;
  --coral: #e8826a;
  --danger: #c0392b;
  --text: #f4f8fa;
  --text-dim: #a8c2cf;
  --bubble-own: linear-gradient(135deg, #1e5f8c, #4a90a4);
  --bubble-other: linear-gradient(135deg, rgba(255,255,255,0.08), rgba(255,255,255,0.04));
  --glass: rgba(8, 30, 48, 0.72);
  --glass-strong: rgba(8, 30, 48, 0.92);
  --stroke: rgba(143, 211, 224, 0.18);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overscroll-behavior: none;
}
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  color: var(--text);
  background: linear-gradient(180deg, #072535 0%, #0a3d62 45%, #1e5f8c 100%);
  min-height: 100vh;
  min-height: 100dvh;
  line-height: 1.4;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

/* ---- Анимированная вода ---- */
.water-bg {
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 0;
}
.waves {
  position: absolute;
  left: -10%;
  right: -10%;
  bottom: -40px;
  height: 220px;
  background: radial-gradient(ellipse at center top, rgba(143,211,224,0.25), transparent 70%);
  filter: blur(6px);
  opacity: 0.35;
  animation: drift 18s linear infinite;
}
.waves::before, .waves::after {
  content: '';
  position: absolute;
  left: 0; right: 0;
  height: 80px;
  background-repeat: repeat-x;
  background-size: 220px 80px;
}
.waves::before {
  bottom: 80px;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 220 80'><path d='M0,40 Q55,10 110,40 T220,40 V80 H0 Z' fill='%238fd3e0' fill-opacity='0.18'/></svg>");
  animation: wave 10s linear infinite;
}
.waves::after {
  bottom: 40px;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 220 80'><path d='M0,50 Q55,20 110,50 T220,50 V80 H0 Z' fill='%234a90a4' fill-opacity='0.25'/></svg>");
  animation: wave 14s linear infinite reverse;
}
.waves-2 { opacity: 0.25; animation-duration: 24s; }
.waves-3 { opacity: 0.18; animation-duration: 32s; }
@keyframes wave { from { background-position-x: 0; } to { background-position-x: 220px; } }
@keyframes drift { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-8px); } }

/* ---- Приветствие ---- */
.welcome {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: env(safe-area-inset-top) 20px env(safe-area-inset-bottom);
  background: linear-gradient(180deg, #072535, #0a3d62 60%, #1e5f8c);
}
.welcome-card {
  background: var(--glass-strong);
  border: 1px solid var(--stroke);
  border-radius: 24px;
  padding: 28px 24px;
  max-width: 400px;
  width: 100%;
  box-shadow: 0 20px 60px rgba(0,0,0,0.4);
  text-align: center;
  backdrop-filter: blur(12px);
}
.welcome-logo { margin: 0 auto 8px; }
.welcome h1 { margin: 6px 0 2px; font-size: 26px; letter-spacing: 0.3px; }
.welcome-dates {
  display: inline-block;
  background: rgba(232,130,106,0.18);
  color: #ffb199;
  padding: 4px 12px;
  border-radius: 999px;
  font-size: 14px;
  margin: 0 0 16px;
}
.welcome-hint { color: var(--text-dim); font-size: 14px; margin: 0 0 20px; }
.welcome-foot { color: var(--text-dim); font-size: 12px; margin-top: 16px; }

.field {
  display: block;
  text-align: left;
  margin: 0 0 12px;
}
.field > span {
  display: block;
  font-size: 12px;
  color: var(--text-dim);
  margin-bottom: 6px;
  padding-left: 4px;
}
.field input, .field textarea {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--stroke);
  background: rgba(255,255,255,0.05);
  color: var(--text);
  border-radius: 14px;
  font-size: 16px;
  font-family: inherit;
  transition: border-color 0.15s;
}
.field input:focus, .field textarea:focus {
  outline: none;
  border-color: var(--water-light);
  background: rgba(255,255,255,0.08);
}

.primary-btn {
  background: linear-gradient(135deg, var(--coral), #d46653);
  color: white;
  border: none;
  padding: 14px 20px;
  border-radius: 14px;
  font-size: 16px;
  font-weight: 600;
  width: 100%;
  cursor: pointer;
  box-shadow: 0 6px 20px rgba(232,130,106,0.35);
  transition: transform 0.1s;
}
.primary-btn:active { transform: scale(0.97); }
.primary-btn.small { padding: 10px 14px; font-size: 14px; width: auto; }

/* ---- Главный экран ---- */
.app {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  max-width: 760px;
  margin: 0 auto;
}

/* ---- Верхняя панель ---- */
.topbar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: env(safe-area-inset-top) 10px 10px;
  padding-top: max(10px, env(safe-area-inset-top));
  background: var(--glass-strong);
  border-bottom: 1px solid var(--stroke);
  backdrop-filter: blur(14px);
  position: relative;
  z-index: 5;
}
.title-wrap { flex: 1; min-width: 0; padding: 0 4px; }
.title {
  font-weight: 700;
  font-size: 17px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.subtitle {
  font-size: 12px;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.icon-btn {
  background: transparent;
  border: none;
  color: var(--text);
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.15s;
}
.icon-btn:hover, .icon-btn:focus-visible {
  background: rgba(143,211,224,0.12);
  outline: none;
}
.icon-btn:active { background: rgba(143,211,224,0.2); }
.icon-btn.small { width: 32px; height: 32px; }

.ai-btn {
  background: linear-gradient(135deg, rgba(232,130,106,0.2), rgba(232,130,106,0.05));
  color: #ffb199;
}

/* ---- Закреплённое ---- */
.pinned-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: rgba(232,130,106,0.12);
  border-bottom: 1px solid rgba(232,130,106,0.22);
  cursor: pointer;
}
.pin-icon {
  color: var(--coral);
  flex-shrink: 0;
  display: flex;
}
.pin-content { flex: 1; min-width: 0; }
.pin-label { font-size: 11px; color: var(--coral); font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px; }
.pin-text {
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text);
}

/* ---- Список сообщений ---- */
.messages {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 16px 12px 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  scroll-behavior: smooth;
  scrollbar-width: thin;
  scrollbar-color: rgba(143,211,224,0.3) transparent;
}
.messages::-webkit-scrollbar { width: 6px; }
.messages::-webkit-scrollbar-thumb { background: rgba(143,211,224,0.3); border-radius: 3px; }

.msg-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  max-width: 85%;
  animation: floatIn 0.35s cubic-bezier(.2,.9,.3,1.2);
}
.msg-row.own { margin-left: auto; flex-direction: row-reverse; }
@keyframes floatIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 600;
  color: #fff;
  box-shadow: 0 2px 6px rgba(0,0,0,0.25);
  user-select: none;
}

.bubble {
  position: relative;
  background: var(--bubble-other);
  border: 1px solid var(--stroke);
  border-radius: 18px;
  padding: 8px 12px 6px;
  min-width: 60px;
  max-width: 100%;
  word-wrap: break-word;
  overflow-wrap: anywhere;
  backdrop-filter: blur(6px);
  cursor: pointer;
  transition: transform 0.1s;
}
.msg-row.own .bubble {
  background: var(--bubble-own);
  border-color: rgba(143,211,224,0.3);
  border-bottom-right-radius: 6px;
}
.msg-row:not(.own) .bubble { border-bottom-left-radius: 6px; }
.bubble:active { transform: scale(0.99); }
.bubble.deleted { opacity: 0.5; font-style: italic; }

.bubble.ai-bubble {
  background: linear-gradient(135deg, rgba(232,130,106,0.18), rgba(232,130,106,0.05));
  border-color: rgba(232,130,106,0.35);
}

.author {
  font-size: 12px;
  font-weight: 600;
  color: var(--water-foam);
  margin-bottom: 2px;
}
.msg-row.own .author { display: none; }

.msg-text {
  font-size: 15px;
  white-space: pre-wrap;
  word-break: break-word;
}
.msg-text a { color: #9fd8e8; }

.meta {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
  font-size: 11px;
  color: var(--text-dim);
  margin-top: 2px;
  margin-left: 12px;
  float: right;
}
.meta .edited { font-style: italic; opacity: 0.8; }
.meta .pinned-mark { color: var(--coral); }

/* Ответ внутри пузыря */
.reply-preview {
  border-left: 3px solid var(--coral);
  padding: 4px 8px;
  margin: 0 0 6px;
  background: rgba(143,211,224,0.08);
  border-radius: 6px;
  font-size: 13px;
}
.reply-preview .rp-author { font-weight: 600; font-size: 12px; color: var(--water-foam); }
.reply-preview .rp-text { color: var(--text-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Медиа в пузыре */
.media {
  margin: -2px -4px 4px;
  border-radius: 12px;
  overflow: hidden;
  max-width: 300px;
}
.media img, .media video {
  display: block;
  width: 100%;
  height: auto;
  max-height: 380px;
  object-fit: cover;
  cursor: zoom-in;
  background: #000;
}

/* Голосовое */
.voice {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 180px;
  padding: 2px 0;
}
.voice-play {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(255,255,255,0.15);
  color: white;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
}
.voice-play:hover { background: rgba(255,255,255,0.25); }
.voice-wave {
  flex: 1;
  height: 24px;
  display: flex;
  align-items: center;
  gap: 2px;
  min-width: 80px;
}
.voice-wave span {
  flex: 1;
  background: rgba(255,255,255,0.35);
  border-radius: 1px;
  min-height: 3px;
}
.voice-wave span.played { background: var(--coral); }
.voice-time {
  font-size: 12px;
  color: var(--text-dim);
  min-width: 36px;
  font-variant-numeric: tabular-nums;
}

/* Системное */
.msg-row.system {
  max-width: 100%;
  margin: 8px auto;
  justify-content: center;
}
.msg-row.system .bubble {
  background: rgba(143,211,224,0.1);
  border: 1px dashed rgba(143,211,224,0.3);
  font-size: 12px;
  color: var(--text-dim);
  text-align: center;
  padding: 6px 12px;
  cursor: default;
}

/* ---- Полоса ответа/редактирования ---- */
.reply-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  background: var(--glass-strong);
  border-top: 1px solid var(--stroke);
}
.reply-accent {
  width: 3px;
  align-self: stretch;
  background: var(--coral);
  border-radius: 3px;
}
.reply-content { flex: 1; min-width: 0; }
.reply-title { font-size: 12px; font-weight: 600; color: var(--coral); }
.reply-text {
  font-size: 13px;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ---- Предпросмотр вложения ---- */
.attach-preview {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  background: var(--glass-strong);
  border-top: 1px solid var(--stroke);
}
.attach-preview img, .attach-preview video {
  max-height: 80px;
  max-width: 120px;
  border-radius: 8px;
  object-fit: cover;
}
.attach-preview .info { flex: 1; font-size: 13px; color: var(--text-dim); }
.attach-preview button { flex-shrink: 0; }

/* ---- Композер ---- */
.composer {
  display: flex;
  align-items: flex-end;
  gap: 4px;
  padding: 8px 8px max(8px, env(safe-area-inset-bottom));
  background: var(--glass-strong);
  border-top: 1px solid var(--stroke);
  backdrop-filter: blur(14px);
  z-index: 5;
}
.composer-btn { flex-shrink: 0; }
.composer-btn.send { color: var(--coral); }

.input-wrap {
  flex: 1;
  background: rgba(255,255,255,0.06);
  border: 1px solid var(--stroke);
  border-radius: 22px;
  padding: 6px 12px;
  min-height: 40px;
  display: flex;
  align-items: center;
  transition: border-color 0.15s;
}
.input-wrap:focus-within { border-color: var(--water-light); }

#msgInput {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--text);
  font-size: 16px;
  font-family: inherit;
  line-height: 1.35;
  resize: none;
  outline: none;
  max-height: 140px;
  padding: 4px 0;
}
#msgInput::placeholder { color: var(--text-dim); }

/* ---- Плашка записи ---- */
.rec-bar {
  position: absolute;
  left: 10px;
  right: 10px;
  bottom: calc(70px + env(safe-area-inset-bottom));
  background: var(--glass-strong);
  border: 1px solid rgba(232,130,106,0.5);
  border-radius: 14px;
  padding: 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  z-index: 6;
  animation: floatIn 0.25s ease;
}
.rec-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--coral);
  animation: pulse 1s infinite;
  flex-shrink: 0;
}
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.3; } }
#recTime { font-variant-numeric: tabular-nums; font-weight: 600; }
.rec-btn {
  border: none;
  background: rgba(255,255,255,0.1);
  color: var(--text);
  padding: 8px 14px;
  border-radius: 10px;
  font-size: 14px;
  cursor: pointer;
}
.rec-btn.stop { background: var(--coral); color: white; font-weight: 600; }
.rec-bar > div:nth-child(2) { flex: 1; font-size: 14px; }

/* ---- Модалки ---- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(5, 20, 32, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  backdrop-filter: blur(4px);
  animation: fadeIn 0.2s ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.modal-card {
  background: linear-gradient(180deg, #10405f, #072535);
  border: 1px solid var(--stroke);
  border-radius: 20px;
  padding: 24px 20px;
  max-width: 440px;
  width: 100%;
  max-height: 85vh;
  overflow-y: auto;
  position: relative;
  box-shadow: 0 30px 80px rgba(0,0,0,0.5);
  animation: floatIn 0.25s cubic-bezier(.2,.9,.3,1.2);
}
.modal-close {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: rgba(255,255,255,0.08);
  color: var(--text);
  font-size: 16px;
  cursor: pointer;
}
.modal-card h2 { margin: 0 0 10px; font-size: 22px; }
.modal-card h3 { margin: 18px 0 6px; font-size: 15px; color: var(--water-foam); }
.modal-card p { margin: 6px 0; }
.muted { color: var(--text-dim); font-size: 14px; }
.muted.small { font-size: 12px; }
.modal-card code {
  background: rgba(255,255,255,0.08);
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 13px;
}

.info-chip {
  display: inline-block;
  background: rgba(143,211,224,0.12);
  border: 1px solid var(--stroke);
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 13px;
  margin-right: 6px;
  margin-bottom: 8px;
}
.checklist {
  list-style: none;
  padding: 0;
  margin: 6px 0;
}
.checklist li {
  padding: 6px 0 6px 26px;
  position: relative;
  font-size: 14px;
  border-bottom: 1px solid rgba(143,211,224,0.08);
}
.checklist li::before {
  content: '';
  position: absolute;
  left: 2px;
  top: 9px;
  width: 14px;
  height: 14px;
  border: 2px solid var(--water-light);
  border-radius: 4px;
}
.checklist li.done::before {
  background: var(--water-light);
  box-shadow: inset 0 0 0 2px #072535;
}
.checklist li.done { color: var(--text-dim); text-decoration: line-through; }

.room-row {
  display: flex;
  gap: 6px;
  align-items: stretch;
  margin-top: 6px;
}
.room-row input {
  flex: 1;
  padding: 10px;
  border: 1px solid var(--stroke);
  background: rgba(255,255,255,0.06);
  color: var(--text);
  border-radius: 10px;
  font-size: 13px;
  font-family: ui-monospace, monospace;
}

/* ---- Контекстное меню сообщения (bottom sheet) ---- */
.modal-card.sheet {
  align-self: flex-end;
  border-radius: 20px 20px 0 0;
  max-width: 440px;
  margin: 0;
  padding: 10px 8px max(14px, env(safe-area-inset-bottom));
  animation: slideUp 0.25s cubic-bezier(.2,.9,.3,1.2);
}
@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}
#msgMenu { align-items: flex-end; padding: 0; }
.sheet-item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 16px;
  background: transparent;
  border: none;
  color: var(--text);
  font-size: 16px;
  text-align: left;
  cursor: pointer;
  border-radius: 12px;
  transition: background 0.1s;
}
.sheet-item:hover, .sheet-item:focus-visible {
  background: rgba(143,211,224,0.08);
  outline: none;
}
.sheet-item.danger { color: #ff9c87; }
.sheet-item.cancel {
  margin-top: 6px;
  border-top: 1px solid var(--stroke);
  padding-top: 14px;
  justify-content: center;
  color: var(--text-dim);
}

/* ---- Помощник ---- */
.ai-presets {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 10px 0;
}
.ai-presets button {
  background: rgba(143,211,224,0.08);
  border: 1px solid var(--stroke);
  color: var(--text);
  padding: 8px 12px;
  border-radius: 10px;
  font-size: 13px;
  cursor: pointer;
}
.ai-presets button:hover { background: rgba(143,211,224,0.15); }
.check {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 8px 0 12px;
  font-size: 14px;
  color: var(--text-dim);
}
.ai-result {
  background: rgba(232,130,106,0.1);
  border: 1px solid rgba(232,130,106,0.3);
  padding: 12px 14px;
  border-radius: 12px;
  font-size: 14px;
  margin-top: 10px;
  white-space: pre-wrap;
  line-height: 1.5;
}
.ai-result.loading { color: var(--text-dim); font-style: italic; }

/* ---- Просмотрщик медиа ---- */
.viewer {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(0,0,0,0.95);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.viewer img, .viewer video {
  max-width: 100%;
  max-height: 100%;
  border-radius: 8px;
}
.viewer-close {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: none;
  background: rgba(255,255,255,0.12);
  color: white;
  font-size: 20px;
  cursor: pointer;
}

/* ---- Тост ---- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 90px;
  transform: translateX(-50%);
  background: var(--glass-strong);
  border: 1px solid var(--stroke);
  color: var(--text);
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 14px;
  z-index: 70;
  animation: floatIn 0.2s ease;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}

/* ---- Мелочи ---- */
.own-only { display: flex; }
.msg-menu-foreign .own-only { display: none; }

@media (max-width: 480px) {
  .title { font-size: 15px; }
  .subtitle { font-size: 11px; }
  .msg-row { max-width: 92%; }
  .media { max-width: 240px; }
}
