:root {
  --app-viewport-height: 100vh;
  --app-viewport-offset-top: 0px;
  --app-viewport-offset-left: 0px;
  --chat-green: #075e54;
  --chat-green-dark: #054c44;
  --chat-accent: #25d366;
  --chat-bg: #efeae2;
  --chat-text: #1f2c34;
  --chat-muted: #667781;
  --chat-border: #e1e6e8;
  --chat-white: #ffffff;
  --brand-wine: #8b0000;
  --shadow: 0 22px 60px rgba(31, 44, 52, 0.18);
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: #f5f1ec;
}

body.family-chat-page {
  min-height: 100vh;
  margin: 0;
  color: var(--chat-text);
  background:
    radial-gradient(circle at 12% 20%, rgba(139, 0, 0, 0.08), transparent 25rem),
    radial-gradient(circle at 88% 75%, rgba(7, 94, 84, 0.10), transparent 28rem),
    #f7f4f0;
  font-family: "Roboto", sans-serif;
}

button,
input {
  font: inherit;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.public-header {
  min-height: 76px;
  padding: 12px clamp(18px, 4vw, 64px);
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 24px;
  background: rgba(255, 255, 255, 0.94);
  border-bottom: 1px solid rgba(31, 44, 52, 0.08);
  backdrop-filter: blur(14px);
}

.public-header__back {
  width: fit-content;
  display: inline-flex;
  align-items: center;
  gap: 9px;
  color: #4b5960;
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 700;
}

.public-header__back:hover {
  color: var(--brand-wine);
}

.public-header__brands {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
}

.public-header__brands img {
  width: auto;
  height: 38px;
  max-width: 112px;
  object-fit: contain;
}

.public-header__divider {
  width: 1px;
  height: 28px;
  background: #d9dfe1;
}

.public-header__secure {
  justify-self: end;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--chat-green);
  font-size: 0.86rem;
  font-weight: 700;
}

.chat-page-main {
  width: min(1180px, calc(100% - 36px));
  min-height: calc(100vh - 132px);
  margin: 0 auto;
  padding: 34px 0;
  display: grid;
  grid-template-columns: minmax(260px, 0.8fr) minmax(420px, 1.2fr);
  align-items: center;
  gap: clamp(36px, 7vw, 96px);
}

.chat-intro {
  max-width: 470px;
}

.chat-intro__eyebrow {
  display: inline-block;
  margin-bottom: 14px;
  color: var(--brand-wine);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.13em;
  text-transform: uppercase;
}

.chat-intro h1 {
  margin: 0 0 16px;
  color: #19262d;
  font-size: clamp(2.25rem, 4.6vw, 4.25rem);
  line-height: 1.02;
  letter-spacing: -0.05em;
}

.chat-intro > p {
  margin: 0;
  color: #5e6a70;
  font-size: 1.05rem;
  line-height: 1.7;
}

.chat-intro__features {
  margin-top: 30px;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.chat-intro__features span {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 13px;
  color: #344249;
  background: rgba(255, 255, 255, 0.78);
  border: 1px solid rgba(31, 44, 52, 0.10);
  border-radius: 999px;
  box-shadow: 0 6px 18px rgba(31, 44, 52, 0.06);
  font-size: 0.83rem;
  font-weight: 700;
}

.chat-intro__features i {
  color: var(--chat-green);
}

.chat-shell {
  width: 100%;
  max-width: 660px;
  height: min(750px, calc(100vh - 130px));
  min-height: 590px;
  justify-self: end;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--chat-white);
  border: 1px solid rgba(31, 44, 52, 0.09);
  border-radius: 20px;
  box-shadow: var(--shadow);
}

.chat-header {
  min-height: 76px;
  padding: 12px 18px;
  display: flex;
  align-items: center;
  gap: 12px;
  color: #fff;
  background: linear-gradient(135deg, var(--chat-green), #0b766a);
}

.chat-avatar {
  position: relative;
  width: 48px;
  height: 48px;
  flex: 0 0 48px;
  display: grid;
  place-items: center;
  color: var(--chat-green);
  background: #fff;
  border-radius: 50%;
  font-size: 1.25rem;
}

.chat-avatar__status {
  position: absolute;
  right: 0;
  bottom: 1px;
  width: 12px;
  height: 12px;
  background: var(--chat-accent);
  border: 2px solid var(--chat-green);
  border-radius: 50%;
}

.chat-header__identity {
  min-width: 0;
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 3px;
}

.chat-header__identity strong {
  font-size: 1rem;
}

.chat-header__identity > span {
  display: flex;
  align-items: center;
  gap: 6px;
  color: rgba(255, 255, 255, 0.8);
  font-size: 0.77rem;
}

.online-dot {
  width: 6px;
  height: 6px;
  background: #8effad;
  border-radius: 50%;
}

.chat-header__restart {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  color: #fff;
  background: transparent;
  border: 0;
  border-radius: 50%;
  cursor: pointer;
  transition: background 0.2s ease;
}

.chat-header__restart:hover,
.chat-header__restart:focus-visible {
  background: rgba(255, 255, 255, 0.14);
}

.chat-messages {
  position: relative;
  flex: 1;
  min-height: 0;
  padding: 22px 20px 14px;
  overflow-y: auto;
  overscroll-behavior: contain;
  background-color: var(--chat-bg);
  background-image:
    radial-gradient(circle at 25px 25px, rgba(7, 94, 84, 0.035) 2px, transparent 2px),
    radial-gradient(circle at 8px 8px, rgba(139, 0, 0, 0.025) 1.5px, transparent 1.5px);
  background-size: 48px 48px, 31px 31px;
  scrollbar-width: thin;
  scrollbar-color: #bdc5c8 transparent;
}

.chat-day-label {
  width: fit-content;
  margin: 0 auto 18px;
  padding: 5px 12px;
  color: #54656f;
  background: rgba(255, 255, 255, 0.86);
  border-radius: 7px;
  box-shadow: 0 1px 2px rgba(31, 44, 52, 0.08);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.chat-message {
  display: flex;
  margin: 0 0 10px;
  animation: message-in 0.28s ease both;
}

.chat-message--user {
  justify-content: flex-end;
}

.chat-bubble {
  position: relative;
  max-width: min(84%, 500px);
  padding: 9px 12px 7px;
  color: #28363d;
  background: #fff;
  border-radius: 4px 12px 12px;
  box-shadow: 0 1px 2px rgba(31, 44, 52, 0.13);
  font-size: 0.92rem;
  line-height: 1.48;
}

.chat-message--user .chat-bubble {
  background: #d9fdd3;
  border-radius: 12px 4px 12px 12px;
}

.chat-bubble p {
  margin: 0;
}

.chat-bubble p + p {
  margin-top: 7px;
}

.chat-bubble strong {
  font-weight: 700;
}

.chat-bubble__time {
  margin-left: 10px;
  float: right;
  transform: translateY(3px);
  color: #7a8a92;
  font-size: 0.64rem;
  line-height: 1;
}

.chat-message--user .chat-bubble__time::after {
  margin-left: 3px;
  color: #2d91d7;
  content: "✓✓";
  letter-spacing: -0.17em;
}

.chat-result-card {
  min-width: min(410px, 70vw);
}

.chat-result-card__heading {
  margin-bottom: 9px;
  padding-bottom: 7px;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--chat-green);
  border-bottom: 1px solid #e9edef;
  font-weight: 700;
}

.chat-result-card__meta {
  margin-bottom: 9px;
  color: #667781;
  font-size: 0.76rem;
}

.chat-table-wrap {
  max-width: 100%;
  overflow-x: auto;
}

.chat-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.78rem;
}

.chat-table th,
.chat-table td {
  padding: 7px 6px;
  text-align: center;
  border-bottom: 1px solid #edf0f1;
  white-space: nowrap;
}

.chat-table th:first-child,
.chat-table td:first-child {
  text-align: left;
}

.chat-table th {
  color: #54656f;
  background: #f6f8f8;
  font-size: 0.7rem;
  text-transform: uppercase;
}

.chat-metric {
  margin-top: 10px;
  padding: 10px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  background: #f6f8f8;
  border-radius: 9px;
  text-align: center;
}

.chat-metric strong {
  display: block;
  color: var(--chat-green);
  font-size: 1.05rem;
}

.chat-metric span {
  color: #667781;
  font-size: 0.69rem;
}

.chat-notice {
  margin-top: 8px;
  padding: 9px 10px;
  background: #fff8df;
  border-left: 3px solid #e9a900;
  border-radius: 5px;
}

.chat-notice strong {
  display: block;
  margin-bottom: 3px;
  color: #5e4a00;
}

.chat-notice p {
  color: #554f3b;
  font-size: 0.83rem;
}

.chat-typing {
  width: fit-content;
  margin: -2px 20px 10px;
  padding: 10px 13px;
  display: flex;
  gap: 4px;
  background: var(--chat-bg);
  border-radius: 11px;
}

.chat-typing[hidden] {
  display: none;
}

.chat-typing span {
  width: 6px;
  height: 6px;
  background: #86969f;
  border-radius: 50%;
  animation: typing 1s infinite ease-in-out;
}

.chat-typing span:nth-child(2) {
  animation-delay: 0.15s;
}

.chat-typing span:nth-child(3) {
  animation-delay: 0.3s;
}

.chat-actions {
  max-height: 180px;
  padding: 0 14px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  overflow-y: auto;
  background: #f8fafb;
}

.chat-human-check {
  padding: 12px 16px 4px;
  text-align: center;
  background: #f7fbfa;
  border-top: 1px solid rgba(7, 94, 84, 0.12);
}

.chat-human-check[hidden] {
  display: none;
}

#chat-turnstile {
  display: flex;
  justify-content: center;
  min-height: 65px;
}

.chat-human-check p {
  margin: 6px 0 0;
  color: #52666a;
  font-size: 0.76rem;
}

.chat-actions:not(:empty) {
  padding-top: 12px;
  padding-bottom: 12px;
  border-top: 1px solid var(--chat-border);
}

.chat-action {
  min-height: 44px;
  padding: 9px 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: var(--chat-green);
  background: #fff;
  border: 1px solid #cfdadb;
  border-radius: 9px;
  cursor: pointer;
  font-size: 0.82rem;
  font-weight: 700;
  line-height: 1.2;
  text-align: center;
  transition: border-color 0.2s ease, background 0.2s ease, transform 0.2s ease;
}

.chat-action:hover,
.chat-action:focus-visible {
  background: #f0faf7;
  border-color: var(--chat-green);
  transform: translateY(-1px);
}

.chat-action--primary {
  color: #fff;
  background: var(--chat-green);
  border-color: var(--chat-green);
}

.chat-action--primary:hover,
.chat-action--primary:focus-visible {
  color: #fff;
  background: var(--chat-green-dark);
}

.chat-action--danger {
  color: #9c2929;
}

.chat-action--wide {
  grid-column: 1 / -1;
}

.chat-composer {
  padding: 10px 12px;
  display: flex;
  align-items: center;
  gap: 9px;
  background: #f0f2f5;
  border-top: 1px solid var(--chat-border);
  transition: background 0.2s ease, box-shadow 0.2s ease;
}

.chat-composer[hidden] {
  display: none;
}

.chat-composer:focus-within {
  position: relative;
  z-index: 3;
  background: #e9f1ef;
  box-shadow: 0 -8px 22px rgba(7, 94, 84, 0.12);
}

.chat-composer input {
  min-width: 0;
  height: 44px;
  flex: 1;
  padding: 0 15px;
  color: #2d3a40;
  background: #fff;
  border: 1px solid transparent;
  border-radius: 12px;
  outline: none;
  font-size: 0.92rem;
}

.chat-composer input:focus {
  border-color: #8dbbb5;
  box-shadow: 0 0 0 3px rgba(7, 94, 84, 0.09);
}

.chat-composer button {
  width: 44px;
  height: 44px;
  flex: 0 0 44px;
  display: grid;
  place-items: center;
  color: #fff;
  background: var(--chat-green);
  border: 0;
  border-radius: 50%;
  cursor: pointer;
  transition: background 0.2s ease, transform 0.2s ease;
}

.chat-composer button:hover {
  background: var(--chat-green-dark);
  transform: scale(1.03);
}

.chat-composer button:disabled,
.chat-composer input:disabled {
  cursor: wait;
  opacity: 0.65;
}

.chat-privacy {
  margin: 0;
  padding: 7px 12px 9px;
  color: #718087;
  background: #f0f2f5;
  font-size: 0.66rem;
  text-align: center;
}

.chat-privacy i {
  margin-right: 4px;
}

.public-footer {
  min-height: 56px;
  padding: 17px 20px;
  color: #6f797d;
  font-size: 0.76rem;
  text-align: center;
}

@keyframes message-in {
  from {
    opacity: 0;
    transform: translateY(5px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes typing {
  0%,
  60%,
  100% {
    opacity: 0.45;
    transform: translateY(0);
  }
  30% {
    opacity: 1;
    transform: translateY(-3px);
  }
}

@media (max-width: 860px) {
  .public-header {
    grid-template-columns: auto 1fr auto;
  }

  .public-header__brands {
    gap: 10px;
  }

  .public-header__brands img {
    height: 30px;
    max-width: 82px;
  }

  .public-header__divider {
    height: 22px;
  }

  .chat-page-main {
    padding: 26px 0;
    grid-template-columns: 1fr;
    gap: 24px;
  }

  .chat-intro {
    max-width: 640px;
    text-align: center;
    justify-self: center;
  }

  .chat-intro h1 {
    font-size: clamp(2rem, 9vw, 3.2rem);
  }

  .chat-intro__features {
    justify-content: center;
  }

  .chat-shell {
    height: 720px;
    max-height: calc(100vh - 36px);
    justify-self: center;
  }
}

@media (max-width: 560px), (max-height: 560px) and (pointer: coarse) {
  html {
    width: 100%;
    height: 100%;
    overflow: hidden;
  }

  body.family-chat-page {
    width: 100%;
    height: 100vh;
    height: 100svh;
    height: var(--app-viewport-height, 100dvh);
    min-height: 0;
    max-height: var(--app-viewport-height, 100dvh);
    position: fixed;
    top: 0;
    left: 0;
    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
    overflow: hidden;
    overscroll-behavior: none;
    transform: translate3d(
      var(--app-viewport-offset-left),
      var(--app-viewport-offset-top),
      0
    );
    background: var(--chat-bg);
  }

  .public-header {
    min-height: 60px;
    padding: max(9px, env(safe-area-inset-top))
      max(13px, env(safe-area-inset-right))
      9px
      max(13px, env(safe-area-inset-left));
    position: relative;
    z-index: 2;
  }

  .public-header__back span,
  .public-header__secure {
    display: none;
  }

  .public-header__brands {
    justify-self: center;
  }

  .public-header__brands img {
    height: 25px;
    max-width: 68px;
  }

  .chat-page-main {
    width: 100%;
    height: 100%;
    min-height: 0;
    padding: 0;
    display: block;
    overflow: hidden;
  }

  .chat-intro,
  .public-footer {
    display: none;
  }

  .chat-shell {
    width: 100%;
    max-width: none;
    height: 100%;
    max-height: none;
    min-height: 0;
    border: 0;
    border-radius: 0;
    box-shadow: none;
  }

  .chat-header {
    min-height: 66px;
    padding: 9px 13px;
    flex: 0 0 auto;
  }

  .chat-avatar {
    width: 43px;
    height: 43px;
    flex-basis: 43px;
  }

  .chat-messages {
    flex: 1 1 0;
    padding: 17px 11px 10px;
    -webkit-overflow-scrolling: touch;
  }

  .chat-bubble {
    max-width: 90%;
    font-size: 0.9rem;
  }

  .chat-result-card {
    min-width: min(330px, 77vw);
  }

  .chat-actions {
    max-height: none;
    padding-right: 10px;
    padding-left: 10px;
    grid-template-columns: 1fr;
    overflow: visible;
  }

  .chat-action--wide {
    grid-column: auto;
  }

  .chat-composer {
    flex: 0 0 auto;
    padding: 9px max(10px, env(safe-area-inset-right))
      9px max(10px, env(safe-area-inset-left));
  }

  .chat-composer input {
    font-size: 16px;
  }

  .chat-privacy {
    flex: 0 0 auto;
    padding: 7px max(10px, env(safe-area-inset-right))
      max(8px, env(safe-area-inset-bottom))
      max(10px, env(safe-area-inset-left));
  }

  body.family-chat-page.chat-keyboard-open {
    grid-template-rows: minmax(0, 1fr);
  }

  body.family-chat-page.chat-keyboard-open .public-header,
  body.family-chat-page.chat-keyboard-open .chat-privacy {
    display: none;
  }

  body.family-chat-page.chat-keyboard-open .chat-header {
    min-height: 56px;
    padding-top: 6px;
    padding-bottom: 6px;
  }

  body.family-chat-page.chat-keyboard-open .chat-avatar {
    width: 40px;
    height: 40px;
    flex-basis: 40px;
  }

  body.family-chat-page.chat-keyboard-open .chat-messages {
    padding-top: 10px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
