:root {
  --wa-header: #075e54;
  --wa-header-deep: #054c44;
  --wa-teal: #128c7e;
  --wa-send: #25d366;
  --wa-chat-bg: #e5ddd5;
  --wa-mine: #dcf8c6;
  --wa-theirs: #ffffff;
  --wa-ink: #111b21;
  --wa-muted: #667781;
  --wa-composer: #f0f2f5;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
  --font: "Segoe UI", system-ui, -apple-system, sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  font-family: var(--font);
  color: var(--wa-ink);
  background: #0b141a;
}

body {
  min-height: 100dvh;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.app {
  max-width: 720px;
  margin: 0 auto;
  min-height: 100dvh;
  height: 100dvh;
  display: grid;
  grid-template-rows: auto 1fr auto;
  background: var(--wa-chat-bg);
  position: relative;
  overflow: hidden;
}

/* Patrón sutil tipo WhatsApp */
.app::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0.06;
  background-image:
    radial-gradient(circle at 20% 20%, #000 1px, transparent 1px),
    radial-gradient(circle at 80% 40%, #000 1px, transparent 1px);
  background-size: 28px 28px;
  z-index: 0;
}

.header,
.chat,
.composer {
  position: relative;
  z-index: 1;
}

/* ---- Header ---- */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: calc(0.65rem + var(--safe-top)) 0.9rem 0.65rem;
  background: linear-gradient(180deg, var(--wa-header), var(--wa-header-deep));
  color: #fff;
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.12);
}

.header__left {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 0;
}

.header__avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: #fff;
  object-fit: cover;
  flex-shrink: 0;
}

.header__name {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 600;
  line-height: 1.2;
}

.header__sub {
  margin: 0.15rem 0 0;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.78rem;
  color: rgba(255, 255, 255, 0.85);
}

.status__dot {
  width: 0.45rem;
  height: 0.45rem;
  border-radius: 50%;
  background: #9aa8a4;
  flex-shrink: 0;
}

#api-status.status--ok .status__dot { background: #25d366; }
#api-status.status--warn .status__dot { background: #ffc107; }
#api-status.status--err .status__dot { background: #ff6b6b; }

/* ---- Chat area ---- */
.chat {
  overflow-y: auto;
  overflow-x: hidden;
  padding: 0.75rem 0.7rem 0.5rem;
  -webkit-overflow-scrolling: touch;
}

.welcome {
  margin: 1.5rem auto 1rem;
  max-width: 280px;
  text-align: center;
  background: rgba(255, 255, 255, 0.92);
  border-radius: 12px;
  padding: 1.1rem 1rem;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
}

.welcome img {
  margin-bottom: 0.5rem;
  border-radius: 50%;
}

.welcome h2 {
  margin: 0 0 0.35rem;
  font-size: 1.15rem;
}

.welcome p {
  margin: 0;
  color: var(--wa-muted);
  font-size: 0.9rem;
  line-height: 1.4;
}

.welcome__caregiver {
  margin-top: 0.65rem !important;
  padding-top: 0.55rem;
  border-top: 1px solid rgba(0, 0, 0, 0.06);
  color: var(--wa-header) !important;
  font-size: 0.82rem !important;
  font-weight: 500;
}

.header__report {
  margin-left: auto;
  flex-shrink: 0;
  border: 0;
  border-radius: 999px;
  padding: 0.4rem 0.85rem;
  font: inherit;
  font-size: 0.78rem;
  cursor: pointer;
  color: #fff;
  background: rgba(255, 255, 255, 0.18);
}

.header__report:hover {
  background: rgba(255, 255, 255, 0.28);
}

.header__report:disabled {
  opacity: 0.65;
  cursor: wait;
}

.report-dialog {
  border: 0;
  border-radius: 14px;
  padding: 0;
  width: min(92vw, 420px);
  max-height: min(80vh, 640px);
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.35);
  background: #fff;
  color: var(--wa-ink);
  z-index: 1000;
}

.report-dialog[open] {
  display: grid;
}

.report-dialog::backdrop {
  background: rgba(11, 20, 26, 0.55);
}

.report-dialog__panel {
  margin: 0;
  display: grid;
  gap: 0.65rem;
  padding: 0.9rem 1rem 1rem;
}

.report-dialog__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.report-dialog__head h2 {
  margin: 0;
  font-size: 1.05rem;
  color: var(--wa-header);
}

.report-dialog__close {
  border: 0;
  background: transparent;
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  color: var(--wa-muted);
  padding: 0.1rem 0.35rem;
}

.report-dialog__note {
  margin: 0;
  font-size: 0.82rem;
  color: var(--wa-header);
  background: rgba(7, 94, 84, 0.08);
  border-radius: 8px;
  padding: 0.55rem 0.65rem;
  line-height: 1.35;
}

.report-dialog__summary {
  margin: 0;
  font-size: 0.9rem;
  line-height: 1.4;
}

.report-dialog__days {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.4rem;
  max-height: 40vh;
  overflow-y: auto;
}

.report-day {
  display: grid;
  gap: 0.15rem;
  padding: 0.5rem 0.55rem;
  border-radius: 8px;
  background: #f4f6f7;
  font-size: 0.8rem;
  color: var(--wa-muted);
}

.report-day--active {
  background: rgba(37, 211, 102, 0.12);
  color: var(--wa-ink);
}

.report-day__words {
  font-size: 0.75rem;
  color: var(--wa-muted);
}

.report-dialog__meta {
  margin: 0;
  font-size: 0.78rem;
  color: var(--wa-muted);
  line-height: 1.35;
}

.messages {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  padding-bottom: 0.5rem;
}

.msg {
  display: flex;
  width: 100%;
  animation: pop 0.22s ease;
}

.msg--user {
  justify-content: flex-end;
}

.msg--assistant {
  justify-content: flex-start;
}

.bubble {
  max-width: min(82%, 420px);
  padding: 0.45rem 0.55rem 0.3rem 0.7rem;
  border-radius: 8px;
  box-shadow: 0 1px 1px rgba(0, 0, 0, 0.08);
  position: relative;
}

.msg--user .bubble {
  background: var(--wa-mine);
  border-top-right-radius: 2px;
}

.msg--assistant .bubble {
  background: var(--wa-theirs);
  border-top-left-radius: 2px;
}

.bubble__text {
  margin: 0;
  white-space: pre-wrap;
  word-wrap: break-word;
  font-size: 0.95rem;
  line-height: 1.35;
}

.bubble__meta {
  display: block;
  text-align: right;
  font-size: 0.68rem;
  color: var(--wa-muted);
  margin-top: 0.15rem;
  line-height: 1;
}

/* Thinking */
.bubble--thinking {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.65rem 0.9rem;
  color: var(--wa-muted);
  font-size: 0.88rem;
}

.thinking-dots {
  display: inline-flex;
  gap: 0.2rem;
}

.thinking-dots i {
  width: 0.4rem;
  height: 0.4rem;
  border-radius: 50%;
  background: var(--wa-teal);
  display: block;
  animation: bounce 1.2s infinite ease-in-out;
}

.thinking-dots i:nth-child(2) { animation-delay: 0.15s; }
.thinking-dots i:nth-child(3) { animation-delay: 0.3s; }

/* ---- Composer ---- */
.composer {
  background: var(--wa-composer);
  padding: 0.45rem 0.55rem calc(0.55rem + var(--safe-bottom));
  border-top: 1px solid rgba(0, 0, 0, 0.06);
}

.composer__form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.45rem;
  align-items: center;
}

.composer__form input {
  width: 100%;
  border: 0;
  outline: none;
  border-radius: 24px;
  padding: 0.7rem 1rem;
  font: inherit;
  font-size: 1rem;
  background: #fff;
  color: var(--wa-ink);
  box-shadow: 0 1px 1px rgba(0, 0, 0, 0.06);
}

.composer__form input:disabled {
  opacity: 0.7;
}

.composer__form button {
  width: 48px;
  height: 48px;
  border: 0;
  border-radius: 50%;
  background: var(--wa-teal);
  color: #fff;
  display: grid;
  place-items: center;
  cursor: pointer;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.18);
  transition: background 0.15s ease, transform 0.1s ease;
}

.composer__form button:hover:not(:disabled) {
  background: var(--wa-send);
}

.composer__form button:active:not(:disabled) {
  transform: scale(0.96);
}

.composer__form button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

@keyframes pop {
  from {
    opacity: 0;
    transform: translateY(6px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

@keyframes bounce {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.45; }
  40% { transform: translateY(-3px); opacity: 1; }
}

/* Desktop */
@media (min-width: 721px) {
  body {
    display: grid;
    place-items: center;
    padding: 1rem;
    background:
      radial-gradient(800px 400px at 50% -10%, #128c7e55, transparent),
      #0b141a;
  }

  .app {
    height: min(900px, calc(100dvh - 2rem));
    min-height: 0;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.35);
  }
}

/* Móvil: teclado / viewport */
@supports (height: 100svh) {
  .app {
    height: 100svh;
    min-height: 100svh;
  }

  @media (min-width: 721px) {
    .app {
      height: min(900px, calc(100svh - 2rem));
      min-height: 0;
    }
  }
}

