/* Mahi chat widget - uses Medico Sattva's own design tokens (style.css :root). */
/* Layering: .mahi is a direct child of <body> and creates its own stacking context here
   (position + z-index). Its layer comes from the shared scale in style.css (--z-chat),
   which is above the top bar, header and mobile menu. Do not "fix" overlap by raising numbers. */
.mahi {
  --mahi-offset: 1rem;
  --mahi-vvh: 100dvh;   /* visual viewport height, kept current by mahi.js (keyboard aware) */
  --mahi-kb: 0px;       /* space taken by an on-screen keyboard that overlays the page (iOS) */
  position: fixed;
  right: calc(var(--mahi-offset) + env(safe-area-inset-right, 0px));
  bottom: calc(var(--mahi-offset) + env(safe-area-inset-bottom, 0px) + var(--mahi-kb));
  z-index: var(--z-chat, 1100);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Helvetica Neue', Arial, sans-serif;
}

.mahi__toggle {
  display: inline-flex; align-items: center; gap: 0.5rem; min-height: 52px; padding: 0 1.1rem 0 0.95rem;
  background: var(--green-primary); color: var(--white); border: 0; border-radius: 999px; cursor: pointer;
  font: 600 0.92rem/1 'Inter', sans-serif; box-shadow: var(--shadow-lg); transition: background 0.2s, transform 0.2s;
}
.mahi__toggle:hover { background: var(--green-deep); transform: translateY(-2px); }
.mahi__toggle:focus-visible, .mahi__icon-btn:focus-visible, .mahi__send:focus-visible, .mahi__option:focus-visible { outline: 3px solid var(--navy-primary); outline-offset: 2px; }
.mahi__icon { width: 24px; height: 24px; flex: 0 0 24px; }
.mahi__icon--close { display: none; }
.mahi--open .mahi__icon--open { display: none; }
.mahi--open .mahi__icon--close { display: block; }
.mahi--open .mahi__toggle-label { display: none; }
.mahi--open .mahi__toggle { padding: 0 0.95rem; }

.mahi__panel {
  position: absolute; right: 0; bottom: calc(52px + 0.75rem);
  display: flex; flex-direction: column; width: min(380px, calc(100vw - 2rem));
  height: min(560px, calc(var(--mahi-vvh) - 11rem)); min-height: 320px; max-width: calc(100vw - 2rem);
  background: var(--white); border: 1px solid var(--border); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg); overflow: hidden; transform-origin: bottom right;
}
.mahi__panel:not([hidden]) { animation: mahiIn 0.2s ease-out both; }
@keyframes mahiIn { from { opacity: 0; transform: translateY(10px) scale(0.98); } to { opacity: 1; transform: none; } }
.mahi__panel[hidden] { display: none; }

.mahi__header { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; padding: 0.85rem 1rem; background: var(--navy-primary); color: var(--white); }
.mahi__title { margin: 0; font: 700 1.05rem/1.2 'Poppins', 'Inter', sans-serif; color: var(--white); letter-spacing: 0; }
.mahi__subtitle { margin: 0.1rem 0 0; font-size: 0.78rem; color: rgba(255, 255, 255, 0.82); }
.mahi__header-actions { display: flex; gap: 0.25rem; }
.mahi__icon-btn { display: inline-flex; align-items: center; justify-content: center; width: 44px; height: 44px; background: transparent; border: 0; border-radius: var(--radius-sm); color: var(--white); cursor: pointer; }
.mahi__icon-btn:hover { background: rgba(255, 255, 255, 0.14); }
.mahi__icon-btn svg { width: 20px; height: 20px; }

.mahi__messages { flex: 1 1 auto; min-height: 0; overflow-x: hidden; overflow-y: auto; overscroll-behavior: contain; padding: 1rem; display: flex; flex-direction: column; gap: 0.75rem; background: var(--surface); }
.mahi__row { display: flex; flex-direction: column; max-width: 88%; }
.mahi__row--user { align-self: flex-end; align-items: flex-end; }
.mahi__row--assistant { align-self: flex-start; align-items: flex-start; }
.mahi__bubble { max-width: 100%; margin: 0; padding: 0.65rem 0.9rem; border-radius: var(--radius-md); font-size: 0.93rem; line-height: 1.5; white-space: pre-wrap; overflow-wrap: anywhere; }
.mahi__row--assistant .mahi__bubble { background: var(--white); color: var(--ink); border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.mahi__row--user .mahi__bubble { background: var(--green-primary); color: var(--white); border-bottom-right-radius: 4px; }
.mahi__row--error .mahi__bubble { background: var(--error-bg); color: var(--error); border-color: transparent; }
.mahi__time { margin-top: 0.2rem; font-size: 0.7rem; color: var(--gray); }
.mahi__links, .mahi__options { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-top: 0.5rem; }
.mahi__link, .mahi__option { display: inline-flex; align-items: center; min-height: 36px; padding: 0.35rem 0.8rem; border-radius: 999px; font: 600 0.82rem/1.2 'Inter', sans-serif; text-decoration: none; cursor: pointer; }
.mahi__link { background: var(--green-tint); color: var(--green-deep); border: 1px solid transparent; }
.mahi__link:hover { background: var(--green-primary); color: var(--white); }
.mahi__option { background: var(--white); color: var(--navy-primary); border: 1.5px solid var(--navy-primary); }
.mahi__option:hover:not(:disabled) { background: var(--navy-primary); color: var(--white); }
.mahi__option:disabled { opacity: 0.5; cursor: default; }

.mahi__typing { display: flex; gap: 4px; padding: 0.4rem 1rem 0.6rem; background: var(--surface); }
.mahi__typing[hidden] { display: none; }
.mahi__typing span:not(.visually-hidden) { width: 7px; height: 7px; border-radius: 50%; background: var(--gray-light); animation: mahiBounce 1.1s infinite ease-in-out; }
.mahi__typing span:nth-child(3) { animation-delay: 0.15s; }
.mahi__typing span:nth-child(4) { animation-delay: 0.3s; }
@keyframes mahiBounce { 0%, 80%, 100% { transform: translateY(0); opacity: 0.5; } 40% { transform: translateY(-4px); opacity: 1; } }

.mahi__notice { margin: 0; padding: 0.3rem 1rem; font-size: 0.72rem; color: var(--gray); text-align: center; background: var(--surface); border-top: 1px solid var(--border); }
.mahi__form { display: flex; gap: 0.5rem; padding: 0.75rem; background: var(--white); border-top: 1px solid var(--border); }
.mahi__form input { flex: 1 1 auto; min-width: 0; min-height: 44px; padding: 0.6rem 0.9rem; font: inherit; font-size: 16px; color: var(--ink); background: var(--white); border: 1.5px solid var(--border); border-radius: var(--radius-sm); }
.mahi__form input:focus { outline: none; border-color: var(--green-primary); box-shadow: 0 0 0 3px var(--green-tint); }
.mahi__send { display: inline-flex; align-items: center; justify-content: center; flex: 0 0 44px; width: 44px; height: 44px; background: var(--green-primary); color: var(--white); border: 0; border-radius: var(--radius-sm); cursor: pointer; }
.mahi__send:hover:not(:disabled) { background: var(--green-deep); }
.mahi__send:disabled, .mahi__form input:disabled { opacity: 0.6; cursor: not-allowed; }
.mahi__send svg { width: 20px; height: 20px; }

/* Touch devices: every interactive element reaches 44px. */
@media (pointer: coarse) {
  .mahi__link, .mahi__option { min-height: 44px; padding-inline: 1rem; }
}

/* Phones: round launcher; the open panel is a bottom sheet inside the visual viewport,
   respecting screen edges, notches and the on-screen keyboard. */
@media (max-width: 600px) {
  .mahi { --mahi-offset: 0.75rem; }
  .mahi__toggle { width: 52px; padding: 0; justify-content: center; }
  .mahi__toggle-label { display: none; }
  .mahi--open .mahi__toggle { display: none; }   /* the panel header has its own close button */
  .mahi__panel {
    position: fixed; width: auto; max-width: none; min-height: 0;
    left: calc(0.5rem + env(safe-area-inset-left, 0px));
    right: calc(0.5rem + env(safe-area-inset-right, 0px));
    bottom: calc(0.5rem + env(safe-area-inset-bottom, 0px) + var(--mahi-kb));
    height: min(78dvh, calc(var(--mahi-vvh) - 1rem));
  }
}
/* Short desktop windows: the panel sits above the launcher (~5rem), so keep it fully on screen. */
@media (min-width: 601px) and (max-height: 600px) { .mahi__panel { height: calc(var(--mahi-vvh) - 6.5rem); min-height: 0; } }
@media (prefers-reduced-motion: reduce) {
  .mahi__toggle, .mahi__typing span { transition: none; animation: none; }
  .mahi__panel:not([hidden]) { animation: none; }
}

/* Catalogue request form rendered safely inside the Mahi transcript. */
.mahi__catalogue-row { width: 100%; max-width: 100%; }
.mahi__catalogue-card { width: 100%; box-sizing: border-box; padding: 1rem; background: var(--white); border: 1px solid var(--border); border-radius: var(--radius-md); color: var(--ink); }
.mahi__catalogue-card h3 { margin: 0 0 .4rem; font: 700 1rem/1.35 'Poppins', 'Inter', sans-serif; color: var(--navy-primary); }
.mahi__catalogue-card > p { margin: 0 0 .8rem; font-size: .82rem; line-height: 1.45; color: var(--gray); }
.mahi__catalogue-form { display: grid; gap: .65rem; }
.mahi__catalogue-field { display: grid; gap: .25rem; }
.mahi__catalogue-field label { font-size: .78rem; font-weight: 700; color: var(--navy-primary); }
.mahi__catalogue-field input, .mahi__catalogue-field textarea { box-sizing: border-box; width: 100%; min-width: 0; padding: .65rem .7rem; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--white); color: var(--ink); font: 400 16px/1.4 'Inter', sans-serif; }
.mahi__catalogue-field input:focus, .mahi__catalogue-field textarea:focus { outline: 2px solid var(--green-primary); outline-offset: 1px; }
.mahi__catalogue-submit { min-height: 44px; padding: .7rem 1rem; border: 0; border-radius: var(--radius-sm); background: var(--green-primary); color: var(--white); font: 700 .85rem/1.2 'Inter', sans-serif; cursor: pointer; }
.mahi__catalogue-submit:disabled { opacity: .65; cursor: wait; }
.mahi__catalogue-feedback { margin: 0; color: var(--error); font-size: .8rem; }
.mahi__catalogue-success { margin: .75rem 0; color: var(--green-deep); font-weight: 700; font-size: .9rem; }
.mahi__catalogue-link { display: block; margin-top: .5rem; padding: .7rem .8rem; border: 1px solid var(--border); border-radius: var(--radius-sm); color: var(--navy-primary); font-size: .82rem; font-weight: 700; text-decoration: none; overflow-wrap: anywhere; }
.mahi__catalogue-link--whatsapp { background: var(--green-tint); color: var(--green-deep); border-color: var(--green-tint); }
.mahi__catalogue-note { margin: .4rem 0 0 !important; font-size: .72rem !important; }
.mahi__honeypot { position: absolute !important; width: 1px !important; height: 1px !important; overflow: hidden !important; left: -10000px !important; opacity: 0 !important; }
