:root {
  color-scheme: light;
  --font-ui: Bahnschrift, "Segoe UI", Tahoma, sans-serif;
  --font-display: Bahnschrift, "Segoe UI Semibold", Tahoma, sans-serif;
  font-family: var(--font-ui);
  font-synthesis: none;
  color: #29342f;
  background: transparent;
}
* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; margin: 0; overflow: hidden; font-family: var(--font-ui); font-size: 12px; font-synthesis: none; }
button, input { font-family: inherit; letter-spacing: 0; }
[hidden] { display: none !important; }
button { cursor: pointer; }
.chat-shell {
  height: 100%;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  overflow: hidden;
  border: 1px solid #bfc5bb;
  border-radius: 8px;
  background: #fffdf7;
  box-shadow: 0 22px 58px rgba(31, 52, 44, .22);
}
.chat-header {
  grid-row: 1;
  min-height: 68px;
  display: grid;
  grid-template-columns: 40px minmax(0, 1fr) 34px;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-bottom: 1px solid #d9d7cd;
  background: #f3f0e6;
}
.chat-avatar {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: 7px;
  color: #fff;
  background: #d96c35;
  font-size: 12px;
  font-weight: 900;
}
.chat-header b, .chat-header small { display: block; }
.chat-header b { font-family: var(--font-display); font-size: 14px; font-weight: 800; }
.chat-header small { margin-top: 3px; color: #68726c; font-size: 10px; }
.chat-header button {
  width: 34px;
  height: 34px;
  border: 1px solid #cfcdc2;
  border-radius: 7px;
  color: #526059;
  background: #fffdf7;
  font-size: 22px;
}
.chat-status {
  grid-row: 2;
  min-height: 30px;
  display: grid;
  place-items: center;
  padding: 6px 12px;
  border-bottom: 1px solid #e5e2d8;
  color: #66736c;
  background: #faf8f1;
  font-size: 10px;
  font-weight: 700;
}
.chat-status.error { color: #a33b22; background: #fff0e9; }
.message-list {
  grid-row: 3;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow-y: auto;
  padding: 14px 12px;
  background: linear-gradient(rgba(255, 253, 247, .93), rgba(248, 246, 238, .94));
  scrollbar-width: thin;
}
.message-empty { margin: auto; max-width: 240px; color: #7a827d; text-align: center; font-size: 11px; line-height: 1.55; }
.message-row { max-width: 82%; display: grid; gap: 3px; align-self: flex-start; }
.message-row.user { align-self: flex-end; }
.message-bubble {
  padding: 9px 11px;
  border: 1px solid #d8d6cc;
  border-radius: 8px 8px 8px 2px;
  color: #34433c;
  background: #fff;
  font-size: 12px;
  line-height: 1.45;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}
.message-image {
  display: block;
  width: auto;
  max-width: min(250px, 100%);
  max-height: 280px;
  margin: 0 0 7px;
  border-radius: 6px;
  object-fit: contain;
  background: #ece9df;
}
.message-bubble .message-text:empty { display: none; }
.message-row.user .message-bubble {
  border-color: #bd592a;
  border-radius: 8px 8px 2px 8px;
  color: #fff;
  background: #d96c35;
}
.message-time { color: #858c87; font-size: 8px; }
.message-row.user .message-time { text-align: right; }
.message-form {
  grid-row: 4;
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr) 42px;
  align-items: center;
  gap: 6px;
  padding: 8px 10px;
  border-top: 1px solid #d9d7cd;
  background: #fffdf7;
}
.message-form > label[for="messageInput"] { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); }
.attach-image {
  width: 48px;
  height: 42px;
  display: grid;
  place-items: center;
  border: 1px solid #c8c8bd;
  border-radius: 8px;
  color: #58655f;
  background: #f8f6ef;
  cursor: pointer;
}
.attach-image span { font-size: 12px; font-weight: 800; line-height: 1; }
.attach-image input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.attach-image:has(input:disabled) { cursor: not-allowed; opacity: .55; }
.attach-image:hover { border-color: #b6582d; color: #a64b25; background: #fff8f1; }
.message-form .message-input {
  width: 100%;
  min-width: 0;
  height: 42px;
  padding: 0 12px;
  border: 1px solid #c8c8bd;
  border-radius: 8px;
  color: #29342f;
  background: #fff;
  font-family: var(--font-ui);
  font-size: 12px;
  font-weight: 650;
  line-height: 1;
  letter-spacing: 0;
  outline: none;
}
.message-form .message-input::placeholder { color: #77817c; opacity: 1; font-family: var(--font-ui); font-size: 12px; font-weight: 600; }
.image-preview {
  grid-column: 1 / -1;
  position: relative;
  width: fit-content;
  max-width: 100%;
}
.image-preview img { display: block; width: auto; max-width: 160px; height: 76px; border: 1px solid #cac7bc; border-radius: 7px; object-fit: cover; }
.message-form .image-preview button { position: absolute; top: 4px; right: 4px; width: 24px; height: 24px; display: grid; place-items: center; padding: 0; border: 1px solid rgba(255,255,255,.9); border-radius: 50%; color: #fff; background: rgba(172,63,28,.92); box-shadow: 0 2px 7px rgba(51,31,23,.25); font-family: Arial, sans-serif; font-size: 17px; font-weight: 400; line-height: 1; }
.message-form .message-input:focus { border-color: #b6582d; box-shadow: 0 0 0 2px rgba(217,108,53,.14); }
.message-form #sendMessage {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border: 1px solid #b64c1d;
  border-radius: 8px;
  color: #fff;
  background: #d96c35;
}
.message-form #sendMessage:hover { background: #c85e2c; }
.message-form #sendMessage:disabled, .message-form .message-input:disabled { cursor: not-allowed; opacity: .55; }
.message-form svg { width: 20px; height: 20px; fill: currentColor; }
@media (max-width: 520px) {
  .chat-shell { border-radius: 0; box-shadow: none; }
  .chat-header { padding-top: max(10px, env(safe-area-inset-top)); }
  .message-form { padding-bottom: max(14px, calc(env(safe-area-inset-bottom) + 8px)); }
}
