:root {
  --chat-brown: #4b382e;
  --chat-muted: #8d776b;
  --chat-rose: #ad725e;
  --chat-rose-dark: #925a49;
  --chat-peach: #f5e4db;
  --chat-cream: #fffaf6;
  --chat-line: rgba(91, 62, 47, .12);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; }

.chat-page {
  min-height: 100svh; margin: 0; overflow: hidden; color: var(--chat-brown);
  background:
    radial-gradient(circle at 8% 10%, rgba(230, 181, 162, .28), transparent 26rem),
    radial-gradient(circle at 92% 86%, rgba(227, 202, 165, .22), transparent 24rem),
    #f8f0ea;
}

.chat-header {
  position: relative; z-index: 10; display: flex; align-items: center; gap: 12px;
  height: 70px; padding: 0 max(18px, calc((100% - 980px) / 2));
  border-bottom: 1px solid var(--chat-line); background: rgba(255, 253, 250, .93);
  box-shadow: 0 5px 24px rgba(87, 58, 43, .05); backdrop-filter: blur(16px);
}
.chat-back {
  display: grid; width: 42px; height: 42px; flex: 0 0 auto; place-items: center;
  border: 1px solid var(--chat-line); border-radius: 50%; color: var(--chat-brown);
  background: white; font-size: 24px; text-decoration: none;
}
.header-character { display: flex; min-width: 0; align-items: center; gap: 10px; margin-right: auto; }
.header-avatar { position: relative; width: 44px; height: 44px; flex: 0 0 auto; }
.header-avatar img { width: 100%; height: 100%; border-radius: 15px; object-fit: cover; }
.header-avatar i {
  position: absolute; right: -3px; bottom: -2px; width: 13px; height: 13px;
  border: 3px solid white; border-radius: 50%; background: #60bd78;
}
.header-character > div:last-child { display: grid; min-width: 0; gap: 1px; }
.header-character b { overflow: hidden; font-size: 14px; text-overflow: ellipsis; white-space: nowrap; }
.header-character span { color: #6fa47a; font-size: 10px; font-weight: 600; }
.message-limit {
  flex: 0 0 auto; padding: 7px 10px; border-radius: 999px; color: #895d4c;
  background: #fff0e8; font-size: 10px; font-weight: 700; white-space: nowrap;
}

.chat-main {
  display: grid; width: min(980px, calc(100% - 32px)); height: calc(100svh - 70px);
  grid-template-rows: auto minmax(0, 1fr); gap: 14px; margin: 0 auto; padding: 20px 0 24px;
}
.chat-intro {
  position: relative; display: flex; align-items: center; gap: 15px; min-height: 86px;
  padding: 2px 12px; overflow: hidden;
}
.chat-character { position: relative; width: 76px; height: 76px; flex: 0 0 auto; }
.chat-character img {
  width: 100%; height: 100%; border: 4px solid white; border-radius: 25px;
  object-fit: cover; object-position: 50% 22%; box-shadow: 0 10px 28px rgba(89, 62, 48, .15);
}
.chat-status {
  position: absolute; z-index: 2; right: -2px; bottom: 4px; width: 17px; height: 17px;
  border: 3px solid #f8f0ea; border-radius: 50%; background: #60bd78;
}
.chat-intro .section-kicker { margin: 0 0 2px; color: #9d715b; font-size: 10px; letter-spacing: 1.5px; }
.chat-intro h1 { margin: 0; font: 700 clamp(25px, 3vw, 36px)/1.15 "Mali", sans-serif; }
.chat-intro > div > p:last-child { margin: 3px 0 0; color: var(--chat-muted); font-size: 12px; }
.intro-paw { position: absolute; z-index: -1; color: #dba38d; opacity: .42; pointer-events: none; }
.paw-one { top: 3px; right: 60px; font-size: 26px; transform: rotate(18deg); }
.paw-two { right: 16px; bottom: 4px; font: 34px "Itim", sans-serif; transform: rotate(-12deg); }

.chat-card {
  display: grid; min-height: 0; grid-template-rows: minmax(0, 1fr) auto auto auto;
  overflow: hidden; border: 1px solid var(--chat-line); border-radius: 25px;
  background: rgba(255, 253, 250, .97); box-shadow: 0 20px 55px rgba(85, 60, 42, .11);
}
.chat-messages {
  min-height: 0; overflow-y: auto; padding: 18px 22px 10px; scroll-behavior: smooth;
  overscroll-behavior: contain; scrollbar-color: #ddc6bb transparent;
  background:
    linear-gradient(rgba(255,253,250,.93), rgba(255,253,250,.93)),
    radial-gradient(circle, #dbb5a5 1.2px, transparent 1.4px);
  background-size: auto, 27px 27px;
}
.chat-day { display: flex; align-items: center; gap: 10px; margin: 0 0 18px; color: #aa9387; font-size: 9px; }
.chat-day::before, .chat-day::after { height: 1px; flex: 1; background: #eee0d9; content: ""; }
.chat-day span { padding: 4px 9px; border-radius: 999px; background: #fff7f2; }
.message-row { display: flex; align-items: flex-end; gap: 9px; margin-bottom: 15px; }
.message-row img { width: 36px; height: 36px; flex: 0 0 auto; border: 2px solid white; border-radius: 13px; object-fit: cover; box-shadow: 0 3px 8px rgba(88,59,45,.1); }
.message-row > div { max-width: min(76%, 570px); }
.message-row span { display: block; margin: 0 0 4px 5px; color: #a08a7e; font-size: 9px; }
.message-row p {
  margin: 0; padding: 11px 14px; border-radius: 7px 18px 18px 18px;
  color: #4f3d33; background: var(--chat-peach); box-shadow: 0 3px 10px rgba(96,61,44,.05);
  font-size: 14px; line-height: 1.62; overflow-wrap: anywhere;
}
.message-row.user { justify-content: flex-end; }
.message-row.user > div { display: flex; flex-direction: column; align-items: flex-end; }
.message-row.user p { border-radius: 18px 7px 18px 18px; color: white; background: linear-gradient(145deg, #b77963, #a56652); }
.message-row.typing p { display: flex; min-width: 56px; height: 42px; align-items: center; gap: 4px; }
.message-row.typing i { width: 6px; height: 6px; border-radius: 50%; background: #96776a; animation: chat-bounce 1.2s infinite; }
.message-row.typing i:nth-child(2) { animation-delay: .15s; }
.message-row.typing i:nth-child(3) { animation-delay: .3s; }
@keyframes chat-bounce { 0%, 70%, 100% { transform: translateY(0); opacity: .45; } 35% { transform: translateY(-4px); opacity: 1; } }

.quick-replies { display: flex; gap: 8px; overflow-x: auto; padding: 9px 16px 10px; border-top: 1px solid rgba(91,62,47,.06); scrollbar-width: none; }
.quick-replies[hidden] { display: none; }
.quick-replies::-webkit-scrollbar { display: none; }
.quick-replies button {
  min-height: 37px; flex: 0 0 auto; padding: 8px 12px; border: 1px solid #e3c7ba;
  border-radius: 999px; color: #795546; background: #fff9f5;
  font: 600 11px "Mali", sans-serif; cursor: pointer;
}
.quick-replies button span { margin-right: 3px; color: #bd7962; }
.quick-replies button:hover { border-color: var(--chat-rose); background: #fff0e8; }

.chat-form {
  display: flex; align-items: flex-end; gap: 8px; padding: 10px 12px;
  border-top: 1px solid var(--chat-line); background: white;
}
.chat-form[hidden] { display: none; }
.pet-button {
  display: grid; width: 47px; height: 47px; flex: 0 0 auto; place-items: center;
  border: 1px solid #e4d2ca; border-radius: 16px; color: #a16652; background: #fff7f2;
  font-size: 17px; cursor: pointer;
}
.chat-form textarea {
  width: 100%; min-height: 47px; max-height: 108px; resize: none; padding: 12px 14px;
  border: 1px solid #dfd0c8; border-radius: 17px; outline: none; color: var(--chat-brown);
  background: #fdfaf8; font: 500 14px/1.5 "Mali", sans-serif;
}
.chat-form textarea:focus { border-color: #bd8a76; box-shadow: 0 0 0 3px rgba(189, 138, 118, .12); }
.chat-form button[type="submit"] {
  display: flex; min-width: 78px; min-height: 47px; align-items: center; justify-content: center; gap: 6px;
  border: 0; border-radius: 16px; color: white; background: linear-gradient(145deg, #b77963, #9c604d);
  box-shadow: 0 6px 15px rgba(151,91,70,.18); font: 700 12px "Mali", sans-serif; cursor: pointer;
}
.chat-form button[type="submit"] b { display: grid; width: 23px; height: 23px; place-items: center; border-radius: 50%; background: rgba(255,255,255,.2); }
.chat-form button:disabled { cursor: not-allowed; opacity: .45; }

.quota-end { overflow-y: auto; padding: 17px 20px 18px; border-top: 1px solid var(--chat-line); background: #fff9f5; text-align: center; }
.quota-end[hidden] { display: none; }
.quota-end p { margin: 0; color: #8b7569; font-size: 11px; }
.quota-end .quota-end-title { margin-bottom: 3px; color: #65493c; font-size: 14px; font-weight: 700; }
.paid-interest button {
  min-height: 40px; padding: 8px 12px; border: 1px solid #dfc5b8; border-radius: 999px;
  color: #735143; background: white; font: 600 11px "Mali", sans-serif; cursor: pointer;
}
.paid-interest { max-width: 520px; margin: 13px auto 0; }
.payment-scan-title { margin: 0 0 4px !important; color: #65493c !important; font-size: 13px !important; font-weight: 700; }
.paid-interest .payment-scan-note {
  display: block; margin: 0 0 11px; color: #927d72; font-size: 9px; line-height: 1.45;
}
.paid-interest p { color: #65493c; }
.paid-interest .package-options { display: flex; justify-content: center; flex-wrap: wrap; gap: 7px; }
.paid-interest button.selected { border-color: var(--chat-rose); color: white; background: var(--chat-rose); }
.paid-interest small { display: block; margin-top: 9px; color: #a18d82; font-size: 9px; }
.payment-status { min-height: 18px; margin-top: 9px !important; color: #9c604d !important; font-weight: 700; }
.payment-history { margin-top: 10px; border-top: 1px solid rgba(101, 73, 60, .12); color: #65493c; font-size: 10px; text-align: left; }
.payment-history summary { padding: 9px 2px 2px; cursor: pointer; font-weight: 700; text-align: center; }
.payment-history-list { display: grid; gap: 6px; padding-top: 6px; }
.payment-history-item { display: grid; gap: 2px; padding: 8px 10px; border: 1px solid #ead8cf; border-radius: 8px; background: white; }
.payment-history-item b { color: #65493c; font-size: 10px; }
.payment-history-item span { color: #927d72; font-size: 9px; }
.chat-note { margin: 0; padding: 1px 16px calc(8px + var(--safe-bottom)); color: #a18d82; background: white; font-size: 9px; text-align: center; }

.payment-modal {
  position: fixed !important; z-index: 1000 !important; inset: 0 !important;
  display: flex; width: 100vw; height: 100dvh; align-items: center; justify-content: center;
  overflow: hidden; padding: 14px; background: rgba(55, 38, 30, .55); backdrop-filter: blur(5px);
}
.payment-modal[hidden] { display: none; }
.payment-sheet {
  position: relative; width: min(100%, 430px); max-height: calc(100dvh - 28px); overflow-y: auto;
  padding: 24px 20px calc(22px + var(--safe-bottom)); border-radius: 26px;
  background: #fffdfb; box-shadow: 0 22px 60px rgba(57, 37, 28, .25); text-align: center;
  overscroll-behavior: contain;
}
.payment-close {
  position: absolute; top: 10px; right: 12px; width: 38px; height: 38px; border: 0;
  border-radius: 50%; color: #76584b; background: #f8eee8; font-size: 25px; cursor: pointer;
}
.payment-kicker { margin: 0; color: #2872a7; font-size: 11px; font-weight: 700; letter-spacing: .8px; }
.payment-sheet h2 { margin: 4px 34px 3px; color: #543d32; font-size: 20px; }
.payment-amount { margin: 0 0 12px; color: #9b6652; font-size: 14px; font-weight: 700; }
.payment-order { margin: -6px 0 10px; color: #a18d82; font-size: 9px; overflow-wrap: anywhere; }
.payment-qr-wrap {
  display: grid; width: min(72vw, 270px); aspect-ratio: 1; place-items: center; margin: 0 auto;
  padding: 10px; border: 1px solid #ead8cf; border-radius: 20px; background: white;
}
.payment-qr-wrap img { display: block; width: 100%; height: 100%; object-fit: contain; }
.payment-qr-wrap.expired img { opacity: .12; filter: grayscale(1); }
.payment-help { margin: 12px auto; color: #806b60; font-size: 11px; line-height: 1.6; }
.payment-primary, .payment-secondary {
  display: flex; min-height: 46px; align-items: center; justify-content: center; margin-top: 8px;
  border-radius: 999px; font-size: 12px; font-weight: 700; text-decoration: none;
}
.payment-primary { color: white; background: var(--chat-rose); }
.payment-primary[hidden] { display: none; }
.payment-secondary { border: 1px solid #ddc7bc; color: #75574a; background: white; }
.payment-secondary[hidden] { display: none; }
.payment-mode-note { margin: 7px 5px 0; color: #947d71; font-size: 9px; line-height: 1.5; }
.payment-mode-note[hidden] { display: none; }
.payment-return-note { margin: 10px 4px 0; color: #8b7569; font-size: 10px; line-height: 1.55; }
.qr-payment-status { min-height: 20px; margin: 13px 0 3px; color: #4e8b5d; font-size: 12px; font-weight: 700; }
.qr-expires { min-height: 16px; margin: 0 0 5px; color: #9b6652; font-size: 10px; }
.payment-sheet small { color: #a18d82; font-size: 9px; line-height: 1.5; }

.payment-result-page {
  display: grid; min-height: 100svh; place-items: center; padding: 24px;
  color: var(--chat-brown); background: linear-gradient(145deg, #fffaf7, #f5e5dc);
}
.payment-result {
  width: min(100%, 430px); padding: 30px 24px; border: 1px solid #ead7cd; border-radius: 28px;
  background: rgba(255,255,255,.94); box-shadow: 0 18px 45px rgba(102,69,53,.12); text-align: center;
}
.payment-result img { width: 96px; height: 96px; object-fit: cover; border: 5px solid white; border-radius: 30px; box-shadow: 0 8px 22px rgba(102,69,53,.14); }
.payment-result h1 { margin: 18px 0 8px; font-size: 25px; }
.payment-result p { margin: 0; color: #8b7569; font-size: 14px; line-height: 1.7; }
.payment-result a {
  display: inline-flex; min-height: 48px; align-items: center; justify-content: center; margin-top: 20px; padding: 10px 22px;
  border-radius: 999px; color: white; background: var(--chat-rose); font-weight: 700; text-decoration: none;
}

@media (max-width: 640px) {
  .payment-modal { padding: max(10px, env(safe-area-inset-top)) 10px max(10px, env(safe-area-inset-bottom)); }
  .payment-sheet { max-height: calc(100dvh - max(20px, env(safe-area-inset-top) + env(safe-area-inset-bottom))); padding: 20px 15px calc(18px + var(--safe-bottom)); border-radius: 22px; }
  .payment-sheet h2 { font-size: 18px; }
  .payment-qr-wrap { width: min(66vw, 250px); }
  .chat-header { height: 62px; padding: 0 10px; gap: 8px; }
  .chat-back { width: 40px; height: 40px; border-color: transparent; background: transparent; }
  .header-avatar { width: 40px; height: 40px; }
  .header-avatar img { border-radius: 13px; }
  .message-limit { max-width: 98px; overflow: hidden; padding: 7px 8px; text-overflow: ellipsis; }
  .chat-main { width: 100%; height: calc(100svh - 62px); grid-template-rows: auto minmax(0, 1fr); gap: 8px; padding: 8px 0 0; }
  .chat-intro { min-height: 62px; gap: 10px; padding: 0 14px; }
  .chat-character { width: 58px; height: 58px; }
  .chat-character img { border-width: 3px; border-radius: 19px; }
  .chat-status { width: 14px; height: 14px; }
  .chat-intro .section-kicker { font-size: 8px; }
  .chat-intro h1 { font-size: 21px; }
  .chat-intro > div > p:last-child { font-size: 9px; }
  .paw-one { right: 42px; font-size: 20px; }
  .paw-two { right: 10px; font-size: 27px; }
  .chat-card { border-right: 0; border-bottom: 0; border-left: 0; border-radius: 22px 22px 0 0; box-shadow: 0 -5px 22px rgba(85,60,42,.07); }
  .chat-messages { padding: 14px 12px 8px; }
  .chat-day { margin-bottom: 13px; }
  .message-row { gap: 7px; margin-bottom: 13px; }
  .message-row img { width: 32px; height: 32px; border-radius: 11px; }
  .message-row > div { max-width: 84%; }
  .message-row p { padding: 10px 12px; font-size: 13px; line-height: 1.55; }
  .quick-replies { padding: 7px 10px 8px; }
  .quick-replies button { min-height: 36px; }
  .chat-form { padding: 8px 9px; padding-bottom: max(8px, var(--safe-bottom)); }
  .pet-button { width: 45px; height: 45px; border-radius: 15px; }
  .chat-form textarea { min-height: 45px; padding: 11px 12px; font-size: 16px; }
  .chat-form button[type="submit"] { width: 45px; min-width: 45px; min-height: 45px; padding: 0; }
  .chat-form button[type="submit"] span { display: none; }
  .quota-end { padding: 14px 12px 15px; }
  .chat-note { display: none; }
}

@media (max-width: 350px) {
  .header-character span { display: none; }
  .message-limit { max-width: 88px; font-size: 9px; }
  .chat-intro > div > p:last-child { display: none; }
}

@media (max-height: 650px) and (max-width: 640px) {
  .chat-intro { display: none; }
  .chat-main { grid-template-rows: minmax(0, 1fr); padding-top: 0; }
  .chat-card { border-radius: 0; }
}
