/* Chat page — isolated from storefront (no search-header padding) */
:root {
  --page-bg: #f2eff6;
  --surface: #ffffff;
  --text-dark: #111111;
  --text-light: #666666;
  --text-hint: #888888;
  --border-hairline: #eeeeee;
  --primary-color: #330072;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --page-bg: #15151d;
    --surface: #1e1e28;
    --text-dark: #ebe9f2;
    --text-light: #b5b2c6;
    --text-hint: #9a97ae;
    --border-hairline: #3a3a48;
  }
}

:root[data-theme="dark"] {
  --page-bg: #15151d;
  --surface: #1e1e28;
  --text-dark: #ebe9f2;
  --text-light: #b5b2c6;
  --text-hint: #9a97ae;
  --border-hairline: #3a3a48;
}

:root[data-theme="light"] {
  --page-bg: #f2eff6;
  --surface: #ffffff;
  --text-dark: #111111;
  --text-light: #666666;
  --text-hint: #888888;
  --border-hairline: #eeeeee;
}

html.page-chat {
  margin: 0;
  padding: 0;
  height: 100%;
  height: 100vh;
  height: -webkit-fill-available;
  overflow: hidden;
  background: var(--page-bg);
}

html.page-chat body,
body.page-chat {
  margin: 0;
  padding: 0 !important;
  padding-top: 0 !important;
  width: 100%;
  height: 100%;
  height: 100vh;
  height: -webkit-fill-available;
  min-height: 100%;
  min-height: 100vh;
  min-height: -webkit-fill-available;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--page-bg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: var(--text-dark);
  -webkit-text-size-adjust: 100%;
  touch-action: manipulation;
}

body.page-chat-thread-open {
  overflow: hidden;
  position: fixed;
  width: 100%;
  left: 0;
  right: 0;
}

/* Fixed shell — надёжнее 100dvh в iOS/Android PWA */
.chat-app {
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  width: 100%;
  max-width: 500px;
  margin-left: auto;
  margin-right: auto;
  display: flex;
  flex-direction: column;
  background: var(--page-bg, #f2eff6);
  color: var(--text-dark);
  overflow: hidden;
  z-index: 1;
}

/* Unified top bar — shop brand gradient, back + tabs in one block */
.chat-topbar {
  flex-shrink: 0;
  position: sticky;
  top: 0;
  z-index: 10;
  background: linear-gradient(135deg, #330072 0%, #6d4aad 100%);
  padding-top: env(safe-area-inset-top, 0px);
  box-shadow: 0 2px 10px rgba(51, 0, 114, 0.18);
}

.chat-topbar-inner {
  display: flex;
  align-items: stretch;
  min-height: 52px;
  gap: 0;
}

.chat-topbar-back {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 52px;
  min-height: 52px;
  color: #fff;
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
}

.chat-topbar-back:active {
  opacity: 0.7;
}

.chat-topbar-back-icon {
  font-size: 32px;
  font-weight: 800;
  line-height: 1;
  letter-spacing: -2px;
}

.chat-topbar-title {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0;
  padding: 0 12px;
  min-height: 52px;
  font-size: 17px;
  font-weight: 700;
  line-height: 1.2;
  color: #fff;
  border: none;
}

/* Tabs in the purple header — Chisto + Support */
.chat-tabs {
  flex: 1;
  display: flex;
  align-items: stretch;
  min-width: 0;
  margin: 0;
  padding: 0;
  background: transparent;
  border: none;
}

.chat-tab {
  position: relative;
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  padding: 6px 10px 4px;
  min-height: 52px;
  border: none;
  background: transparent;
  font-size: 13px;
  font-weight: 700;
  color: rgba(255, 255, 255, 0.72);
  cursor: pointer;
  border-bottom: 3px solid transparent;
  transition: color 0.15s ease, border-color 0.15s ease, background 0.15s ease;
  -webkit-tap-highlight-color: transparent;
}

.chat-tab:active {
  background: rgba(255, 255, 255, 0.08);
}

.chat-tab.active {
  color: #fff;
  border-bottom-color: #fff;
}

.chat-tab-icon {
  width: 22px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  font-size: 18px;
}

.chat-tab-icon--support img,
.chat-tab-icon--support svg {
  width: 18px;
  height: 18px;
  display: block;
  filter: brightness(0) invert(1);
  opacity: 0.82;
}

.chat-tab.active .chat-tab-icon--support img,
.chat-tab.active .chat-tab-icon--support svg {
  opacity: 1;
}

.chat-tab-label {
  line-height: 1.1;
  letter-spacing: 0.01em;
}

.chat-tab-badge {
  position: absolute;
  top: 6px;
  right: 10px;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  background: #ff3b30;
  color: #fff;
  font-size: 11px;
  font-weight: 800;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.25);
}

.chat-tab-badge.hidden {
  display: none !important;
}

.chat-hub-view {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 20px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.chat-hub-view.hidden {
  display: none !important;
}

.chat-hub-card {
  max-width: 320px;
  padding: 22px 20px;
  border-radius: 18px;
  background: var(--surface, #fff);
  border: 1px solid var(--border-hairline, #eee);
  box-shadow: 0 8px 28px rgba(51, 0, 114, 0.08);
  text-align: center;
}

.chat-hub-title {
  margin: 0 0 10px;
  font-size: 17px;
  font-weight: 700;
  color: var(--text-dark);
}

.chat-hub-text {
  margin: 0;
  font-size: 14px;
  line-height: 1.55;
  color: var(--text-light, #666);
}

.chat-list {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--surface, #fff);
}

/* List view — fills space directly under unified header */
.chat-list-view {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.chat-list-view.hidden {
  display: none !important;
}

.chat-list-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border-hairline, #eee);
  cursor: pointer;
}

.chat-list-item:active {
  background: var(--chat-list-item-active, rgba(51, 0, 114, 0.06));
}

.chat-avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: linear-gradient(135deg, #330072, #6d4aad);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 18px;
  flex-shrink: 0;
}

.chat-list-body {
  flex: 1;
  min-width: 0;
}

.chat-list-top {
  display: flex;
  justify-content: space-between;
  gap: 8px;
}

.chat-list-name {
  font-weight: 600;
  font-size: 16px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-list-time {
  font-size: 12px;
  color: var(--text-light, #666);
  flex-shrink: 0;
}

.chat-list-preview {
  font-size: 14px;
  color: var(--text-light, #666);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
}

.chat-badge {
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 10px;
  background: #330072;
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.chat-thread {
  display: none;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

.chat-thread.open {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  background: var(--page-bg, #f5f3f8);
  --chat-wallpaper-tint: rgba(245, 243, 248, 0.58);
  --chat-wallpaper-color: #e8e4ef;
  --chat-wallpaper-image: linear-gradient(var(--chat-wallpaper-tint), var(--chat-wallpaper-tint)), url('../img/chat-bg.webp?v=2');
}

.chat-thread-head {
  display: none;
}

.chat-thread-back {
  border: none;
  background: none;
  font-size: 28px;
  font-weight: 800;
  cursor: pointer;
  color: #fff;
  padding: 4px 8px;
  line-height: 1;
}

.chat-thread-info {
  flex: 1;
  min-width: 0;
}

.chat-thread-name {
  font-weight: 700;
  font-size: 16px;
  color: #fff;
}

.chat-thread-phone {
  font-size: 12px;
  color: rgba(255, 255, 255, 0.82);
}

.chat-thread-actions {
  display: flex;
  gap: 6px;
}

.chat-thread-actions a {
  text-decoration: none;
  font-size: 20px;
  padding: 6px;
}

.chat-messages-pane {
  flex: 1;
  min-height: 0;
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.chat-messages-bg {
  position: absolute;
  inset: 0;
  z-index: 0;
  background-color: var(--chat-wallpaper-color, #e8e4ef);
  background-image: var(--chat-wallpaper-image);
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  pointer-events: none;
}

.chat-messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 12px 14px;
  position: relative;
  z-index: 1;
  background: transparent;
}

.chat-date-sep {
  text-align: center;
  font-size: 12px;
  color: var(--text-light, #666);
  margin: 12px 0;
}

.chat-bubble {
  max-width: 82%;
  margin-bottom: 8px;
  padding: 10px 12px;
  border-radius: 16px;
  font-size: 15px;
  line-height: 1.4;
  word-break: break-word;
  position: relative;
}

.chat-bubble.mine {
  margin-left: auto;
  background: var(--chat-bubble-mine-bg, #dcf8c6);
  border-bottom-right-radius: 4px;
  color: var(--chat-bubble-mine-fg, #111);
}

.chat-bubble.theirs {
  margin-right: auto;
  background: var(--chat-bubble-theirs-bg, var(--surface, #fff));
  border-bottom-left-radius: 4px;
  color: var(--text-dark, #111);
}

.chat-bubble-time {
  font-size: 11px;
  color: var(--chat-bubble-time-theirs, rgba(0, 0, 0, 0.45));
  margin-top: 4px;
  text-align: right;
}

.chat-bubble.mine .chat-bubble-time {
  color: var(--chat-bubble-time-mine, rgba(0, 0, 0, 0.45));
}

.chat-bubble-voice audio {
  width: 100%;
  max-width: 220px;
}

.chat-compose {
  flex-shrink: 0;
  position: relative;
  bottom: 0;
  z-index: 2;
  flex-shrink: 0;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 8px 12px calc(8px + env(safe-area-inset-bottom, 0));
  background-color: var(--chat-wallpaper-color, #e8e4ef);
  background-image: var(--chat-wallpaper-image);
  background-size: cover;
  background-position: center bottom;
  background-repeat: no-repeat;
  border-top: none;
}

.chat-compose-field {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: flex-end;
  border: 1px solid var(--chat-compose-field-border, rgba(255, 255, 255, 0.65));
  border-radius: 24px;
  background: var(--chat-compose-field-bg, rgba(255, 255, 255, 0.92));
  padding: 4px 4px 4px 14px;
  box-shadow: var(--chat-compose-field-shadow, 0 1px 3px rgba(15, 23, 42, 0.08));
}

.chat-compose-input {
  flex: 1;
  min-width: 0;
  border: none;
  background: transparent;
  padding: 8px 6px 8px 0;
  font-size: 16px;
  line-height: 1.35;
  resize: none;
  max-height: 120px;
  color: var(--text-dark, #111);
  outline: none;
  font-family: inherit;
}

.chat-compose-input::placeholder {
  color: var(--text-light, #9ca3af);
}

.chat-compose-attach {
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  min-width: 44px;
  min-height: 44px;
  border: none;
  background: transparent;
  color: var(--chat-compose-attach-color, #8696a0);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

.chat-compose-attach:active {
  opacity: 0.65;
}

.chat-compose-action {
  flex-shrink: 0;
  width: 48px;
  height: 48px;
  min-width: 48px;
  min-height: 48px;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: #fff;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  box-shadow: none;
  -webkit-tap-highlight-color: transparent;
}

.chat-compose-action.is-send {
  background: #25d366;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.12);
}

.chat-compose-action.is-send:active {
  background: #20bd5a;
}

.chat-compose-action.recording.is-send {
  background: #dc2626;
  box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.25);
}

.chat-compose-action.recording.is-send:active {
  background: #b91c1c;
}

.chat-compose-action:not(.is-send):active .chat-compose-mic-svg {
  transform: scale(0.96);
}

.chat-compose-action.recording:not(.is-send) .chat-compose-mic-svg {
  filter: hue-rotate(-128deg) saturate(1.2);
}

.chat-compose-action-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

.chat-compose-action-mic svg {
  display: block;
  width: 48px;
  height: 48px;
}

.chat-compose-mic-svg {
  transition: transform 0.12s ease, filter 0.15s ease;
}

.chat-compose-action-send {
  font-size: 20px;
  font-weight: 700;
  transform: translateX(1px);
}

.chat-empty {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-light, #666);
  font-size: 15px;
}

.chat-modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 100;
}

.chat-modal-backdrop.hidden {
  display: none !important;
}

.chat-modal {
  width: 100%;
  max-width: 500px;
  background: var(--surface, #fff);
  border-radius: 20px 20px 0 0;
  padding: 20px;
}

.chat-modal h3 {
  margin: 0 0 16px;
  font-size: 18px;
}

.chat-modal .form-input {
  width: 100%;
  padding: 12px;
  border: 2px solid var(--border-strong, #e0e0e0);
  border-radius: 12px;
  margin-bottom: 12px;
  font-size: 16px;
  box-sizing: border-box;
}

.chat-contact-actions {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}

.chat-contact-actions button {
  flex: 1;
  padding: 8px;
  border-radius: 12px;
  border: 1px solid var(--border-soft, #e5e7eb);
  background: var(--surface, #fff);
  cursor: pointer;
  font-size: 13px;
}

.hidden {
  display: none !important;
}

.chat-bubble.call-event {
  align-self: center;
  max-width: 92%;
  background: var(--surface-muted, #f8f9fa);
  color: var(--text-muted, #666);
  border: 1px dashed var(--border-soft, #e5e7eb);
  font-size: 13px;
  text-align: center;
}

.chat-bubble.order-event {
  align-self: center;
  max-width: 92%;
  background: var(--surface, #fff);
  color: var(--text-dark, #111);
  border: 1px solid var(--border-soft, #e5e7eb);
  padding: 0;
  overflow: hidden;
}

.chat-order-card {
  padding: 12px 14px;
  text-align: left;
}

.chat-order-card__title {
  font-weight: 700;
  font-size: 15px;
  margin-bottom: 4px;
  color: var(--chat-order-card-title, #330072);
}

.chat-order-card__status {
  font-size: 13px;
  color: var(--text-light, #666);
  margin-bottom: 6px;
}

.chat-order-card__total {
  font-size: 16px;
  font-weight: 700;
  margin-bottom: 8px;
}

.chat-order-card__items {
  margin: 0;
  padding-left: 18px;
  font-size: 13px;
  color: var(--text-dark, #111);
}

.chat-list-item--pinned {
  background: var(--chat-pinned-bg, rgba(51, 0, 114, 0.04));
}

.chat-avatar--chisto {
  background: linear-gradient(135deg, #25d366, #128c7e);
  font-size: 22px;
}

.chat-call-event {
  padding: 2px 0;
}

/* Тёмная тема — контраст WCAG AA, приглушённые оттенки без резкого белого */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --chat-wallpaper-tint: rgba(21, 21, 29, 0.78);
    --chat-wallpaper-color: #15151d;
    --chat-bubble-mine-bg: #2a4034;
    --chat-bubble-mine-fg: #e6f4ea;
    --chat-bubble-theirs-bg: #272733;
    --chat-bubble-time-mine: rgba(230, 244, 234, 0.62);
    --chat-bubble-time-theirs: rgba(235, 233, 242, 0.55);
    --chat-compose-field-bg: #2a2a36;
    --chat-compose-field-border: rgba(255, 255, 255, 0.12);
    --chat-compose-field-shadow: 0 1px 4px rgba(0, 0, 0, 0.28);
    --chat-compose-attach-color: #9a97ae;
    --chat-order-card-title: #c4afff;
    --chat-list-item-active: rgba(155, 95, 255, 0.14);
    --chat-pinned-bg: rgba(155, 95, 255, 0.1);
  }
}

:root[data-theme="dark"] {
  --chat-wallpaper-tint: rgba(21, 21, 29, 0.78);
  --chat-wallpaper-color: #15151d;
  --chat-bubble-mine-bg: #2a4034;
  --chat-bubble-mine-fg: #e6f4ea;
  --chat-bubble-theirs-bg: #272733;
  --chat-bubble-time-mine: rgba(230, 244, 234, 0.62);
  --chat-bubble-time-theirs: rgba(235, 233, 242, 0.55);
  --chat-compose-field-bg: #2a2a36;
  --chat-compose-field-border: rgba(255, 255, 255, 0.12);
  --chat-compose-field-shadow: 0 1px 4px rgba(0, 0, 0, 0.28);
  --chat-compose-attach-color: #9a97ae;
  --chat-order-card-title: #c4afff;
  --chat-list-item-active: rgba(155, 95, 255, 0.14);
  --chat-pinned-bg: rgba(155, 95, 255, 0.1);
}

/* Телефоны: на всю ширину, без смещения fixed-блока */
@media (max-width: 520px) {
  .chat-app,
  .chat-thread.open {
    max-width: none;
    margin-left: 0;
    margin-right: 0;
  }
}

