* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body.chat-page {
  background: #ece5dd;
  color: #1f2933;
  font-family: Arial, sans-serif;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  height: 100dvh;
}
@media (max-width: 768px) {
  body.chat-page .header-area,
  body.chat-page .mobile-header-active {
    display: none !important;
  }
}
.chat-container {
  width: 100%;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: #ece5dd;
}
.chat-top-bar { flex: 0 0 62px; display: flex; align-items: center; gap: 9px; padding: 10px 12px; color: #fff; background: #075e54; box-shadow: 0 1px 3px rgba(0,0,0,.22); z-index: 3; }
.chat-back { color: #fff; text-decoration: none; font-size: 28px; line-height: 1; padding: 4px 8px 5px 0; }
.chat-status-dot { width: 9px; height: 9px; flex: 0 0 9px; border-radius: 50%; background: #47d16c; box-shadow: 0 0 0 2px rgba(255,255,255,.18); }
.chat-title { flex: 1; font-size: 15px; font-weight: 700; line-height: 1.2; }
.chat-title small { display: block; margin-top: 3px; color: rgba(255,255,255,.78); font-size: 11px; font-weight: 400; }
.chat-category-badge { max-width: 110px; padding: 5px 9px; overflow: hidden; border-radius: 14px; background: rgba(255,255,255,.18); font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.chat-messages {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 14px 10px 18px;
  background-color: #ece5dd;
  background-image: radial-gradient(rgba(117,99,83,.12) 1px, transparent 1px);
  background-size: 22px 22px;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}
.chat-footer { flex: 0 0 auto; }
.message-row { display: flex; width: 100%; margin: 0 0 8px; }
.message-row.is-bot { justify-content: flex-start; }
.message-row.is-user { justify-content: flex-end; }
.message-bubble { position: relative; max-width: min(86%, 420px); padding: 9px 10px 6px; border-radius: 9px; background: #fff; box-shadow: 0 1px 1px rgba(0,0,0,.12); font-size: 14px; line-height: 1.42; overflow: hidden; }
.is-bot .message-bubble { border-top-left-radius: 2px; }
.is-user .message-bubble { background: #dcf8c6; border-top-right-radius: 2px; }
.message-content { display: block; white-space: normal; }
.message-bubble time { display: block; margin-top: 4px; color: #8696a0; font-size: 10px; line-height: 1; text-align: right; }
.audio-bubble { min-width: 245px; padding: 8px 9px 6px; }
.audio-player { --audio-progress: 0%; position: relative; display: flex; align-items: center; gap: 8px; min-height: 42px; max-width: 300px; }
.audio-player::after { content: ''; position: absolute; left: 48px; top: 7px; bottom: 7px; width: var(--audio-progress); max-width: calc(100% - 82px); border-radius: 5px; background: rgba(37, 151, 104, .16); pointer-events: none; }
.audio-player audio { display: none; }
.audio-play { position: relative; z-index: 1; display: grid; width: 36px; height: 36px; flex: 0 0 36px; place-items: center; padding: 0; border: 0; border-radius: 50%; background: #075e54; color: #fff; font-size: 15px; cursor: pointer; }
.waveform { position: relative; z-index: 1; display: flex; align-items: center; justify-content: space-between; width: 100%; height: 30px; gap: 2px; overflow: hidden; }
.waveform i { display: block; width: 3px; min-height: 6px; border-radius: 3px; background: #9aa5a5; transition: background .12s; }
.audio-player.is-playing .waveform i { background: #1d9b6c; }
.audio-duration { position: relative; z-index: 1; min-width: 32px; color: #677575; font-size: 11px; text-align: right; }
.audio-speed { position: relative; z-index: 1; min-width: 32px; padding: 2px 6px; border: 0; border-radius: 10px; background: rgba(0,0,0,.06); color: #075e54; font: 700 11px/1.4 Arial, sans-serif; cursor: pointer; }
.audio-speed:hover { background: rgba(7,94,84,.15); }
.audio-speed:active { transform: scale(.95); }
.youtube-bubble { width: min(86vw, 360px); padding: 8px; }
.youtube-bubble strong { display: block; margin: 1px 2px 7px; font-size: 12px; font-weight: 600; }
.youtube-frame { position: relative; width: 100%; aspect-ratio: 16 / 16; overflow: hidden; border-radius: 7px; background: #000; }
.youtube-frame iframe { width: 100%; height: 100%; border: 0; }
.chat-choices { position: relative; z-index: 2; flex: 0 0 auto; padding: 8px 10px; border-top: 1px solid rgba(0,0,0,.08); background: rgba(240,242,245,.97); }
.choices-container { display: flex; justify-content: center; gap: 8px; flex-wrap: wrap; }
.choice-btn { padding: 9px 14px; border: 1px solid #075e54; border-radius: 22px; background: #fff; color: #075e54; font-size: 13px; font-weight: 600; cursor: pointer; }
.choice-btn:active, .choice-btn:focus { background: #075e54; color: #fff; outline: none; }
.chat-input-bar { display: flex; align-items: center; gap: 8px; flex: 0 0 auto; padding: 8px 10px calc(8px + env(safe-area-inset-bottom)); background: #f0f2f5; }
.chat-input-field { width: 100%; min-width: 0; height: 43px; padding: 0 15px; border: 0; border-radius: 22px; outline: none; background: #fff; color: #1f2933; font-size: 15px; box-shadow: 0 1px 2px rgba(0,0,0,.08); }
.chat-input-field:disabled { background: #e1e5e7; color: #7d878a; }
.send-btn { display: grid; width: 43px; height: 43px; flex: 0 0 43px; place-items: center; padding: 0 0 2px 2px; border: 0; border-radius: 50%; background: #075e54; color: #fff; font-size: 22px; cursor: pointer; }
.send-btn:disabled { background: #9ab5af; cursor: not-allowed; }
@media (min-width: 700px) { .chat-container { max-width: 620px; margin: 0 auto; box-shadow: 0 0 20px rgba(0,0,0,.14); } }

.measure-bubble-inner {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 4px;
}
.measure-value-bubble .message-content {
  flex: 1 1 auto;
  min-width: 0;
}
.edit-measure {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  min-width: 44px;
  min-height: 44px;
  padding: 0 4px;
  margin: -6px -4px -6px 0;
  border: 0;
  background: transparent;
  color: #2D7A5A;
  cursor: pointer;
}
.edit-measure svg {
  width: 16px;
  height: 16px;
  fill: currentColor;
}
@media (hover: hover) {
  .edit-measure:hover { color: #1f5c42; }
}
.edit-measure:active { transform: scale(0.94); }

.measure-modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(26, 42, 58, 0.4);
  z-index: 9999;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.measure-modal-backdrop[hidden] { display: none !important; }
.measure-modal {
  position: relative;
  width: 100%;
  max-width: 480px;
  background: #FAF6EE;
  border-radius: 18px 18px 0 0;
  padding: 20px;
  padding-bottom: calc(20px + env(safe-area-inset-bottom));
  box-shadow: 0 -8px 32px rgba(26, 42, 58, 0.12);
  z-index: 10000;
}
@media (min-width: 768px) {
  .measure-modal-backdrop { align-items: center; }
  .measure-modal {
    border-radius: 18px;
    max-width: 440px;
  }
}
.measure-modal-title {
  margin: 0 0 8px;
  font-family: "Playfair Display", Georgia, serif;
  font-size: 18px;
  font-weight: 700;
  color: #1A2A3A;
}
.measure-modal-helper {
  margin: 0 0 12px;
  font-size: 13px;
  color: #4a5568;
}
.measure-modal-input {
  width: 100%;
  height: 52px;
  border: 1.5px solid #E7E1D4;
  border-radius: 12px;
  padding: 0 14px;
  font-size: 18px;
  color: #1A2A3A;
  background: #fff;
  box-sizing: border-box;
}
.measure-modal-input:focus {
  outline: 2px solid #2D7A5A;
  outline-offset: 1px;
}
.measure-modal-error {
  margin: 10px 0 0;
  font-size: 13px;
  color: #b42318;
}
.measure-modal-actions {
  display: flex;
  gap: 12px;
  margin-top: 16px;
}
.measure-modal-btn {
  flex: 1 1 0;
  height: 52px;
  border-radius: 12px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
}
.measure-modal-cancel {
  border: 1.5px solid #9ca3af;
  background: #fff;
  color: #1A2A3A;
}
.measure-modal-save {
  border: 0;
  background: #2D7A5A;
  color: #fff;
}
.measure-modal-save:disabled,
.measure-modal-cancel:disabled {
  opacity: 0.65;
  cursor: not-allowed;
}
.measure-system-notice .message-bubble {
  background: #e8f5ef;
  font-size: 13px;
}
.measure-edit-toast {
  position: fixed;
  left: 50%;
  bottom: calc(88px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  padding: 10px 18px;
  background: #1A2A3A;
  color: #FAF6EE;
  border-radius: 22px;
  font-size: 14px;
  z-index: 10001;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.18);
}
.measure-edit-toast[hidden] { display: none !important; }

@media (prefers-reduced-motion: reduce) {
  .edit-measure:active { transform: none; }
  .measure-system-notice { transition: none !important; }
}
