/* ==========================================================================
   NessLek Deluxe — AI Agent widget
   Floating bubble (stacks above the WhatsApp button), chat panel, and the
   inline launcher card above the contact form. Uses the theme's brand tokens.
   ========================================================================== */

.nai {
  --nai-gap: 2rem;
  --nai-size: 60px;
  --nai-bottom: var(--nai-gap);
  position: fixed;
  right: var(--nai-gap);
  bottom: var(--nai-bottom);
  z-index: 1000;
  font-family: var(--font-body);
}
/* WhatsApp button occupies the corner — sit directly above it */
.nai--stacked { --nai-bottom: calc(var(--nai-gap) + 60px + 14px); }

.nai .screen-reader-text {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

/* ---- Bubble ---- */
.nai-bubble {
  display: flex;
  flex-direction: row-reverse;
  align-items: center;
  gap: 0;
  height: var(--nai-size);
  min-width: var(--nai-size);
  padding: 0;
  margin-left: auto;
  border: 0;
  border-radius: 999px;
  background: var(--gold-gradient);
  color: var(--navy);
  box-shadow: var(--shadow-gold);
  cursor: pointer;
  transition: transform 0.3s var(--ease-luxe), box-shadow 0.3s var(--ease), gap 0.35s var(--ease-luxe), padding 0.35s var(--ease-luxe);
}
[dir="rtl"] .nai-bubble { flex-direction: row; margin-left: 0; margin-right: auto; }

.nai-bubble-icon {
  flex: 0 0 var(--nai-size);
  height: var(--nai-size);
  display: grid;
  place-items: center;
  position: relative;
}
/* Soft attention ring on first load */
.nai-bubble-icon::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 2px solid var(--gold);
  animation: nai-ring 2.4s var(--ease-out) 1.2s 3;
  opacity: 0;
  pointer-events: none;
}
@keyframes nai-ring {
  0%   { transform: scale(1);   opacity: 0.7; }
  100% { transform: scale(1.7); opacity: 0; }
}

.nai-bubble-label {
  max-width: 0;
  overflow: hidden;
  white-space: nowrap;
  font-family: var(--font-head);
  font-size: 0.85rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  opacity: 0;
  transition: max-width 0.4s var(--ease-luxe), opacity 0.25s var(--ease);
}

/* Hover (pointer devices) and keyboard focus reveal the label */
@media (hover: hover) {
  .nai[data-state="closed"] .nai-bubble:hover { padding-inline-start: 1.25rem; transform: translateY(-3px); }
  .nai[data-state="closed"] .nai-bubble:hover .nai-bubble-label { max-width: 240px; opacity: 1; }
}
.nai[data-state="closed"] .nai-bubble:focus-visible { padding-inline-start: 1.25rem; outline: 2px solid var(--navy); outline-offset: 3px; }
.nai[data-state="closed"] .nai-bubble:focus-visible .nai-bubble-label { max-width: 240px; opacity: 1; }

.nai[data-state="open"] .nai-bubble { background: var(--navy); color: var(--gold-bright); box-shadow: var(--shadow-md); }
.nai[data-state="open"] .nai-bubble-icon::after { display: none; }

/* ---- Panel ---- */
.nai-panel {
  position: fixed;
  right: var(--nai-gap);
  bottom: calc(var(--nai-bottom) + var(--nai-size) + 14px);
  width: 390px;
  height: min(620px, calc(100vh - var(--nai-bottom) - var(--nai-size) - 110px));
  min-height: 360px;
  display: flex;
  flex-direction: column;
  background: var(--white);
  border-radius: 14px;
  box-shadow: var(--shadow-lg), 0 0 0 1px rgba(2, 19, 62, 0.06);
  overflow: hidden;
  transform-origin: bottom right;
  animation: nai-in 0.35s var(--ease-luxe);
}
.nai-panel[hidden] { display: none; }
[dir="rtl"] .nai-panel { transform-origin: bottom right; }
@keyframes nai-in {
  from { opacity: 0; transform: translateY(12px) scale(0.97); }
  to   { opacity: 1; transform: none; }
}

.nai-head {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 1rem 1rem 1rem 1.25rem;
  background: var(--navy-gradient);
  color: var(--white);
  border-bottom: 1px solid rgba(230, 168, 23, 0.35);
}
.nai-avatar {
  flex: 0 0 38px;
  height: 38px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: rgba(230, 168, 23, 0.14);
  border: 1px solid rgba(230, 168, 23, 0.45);
  color: var(--gold-bright);
}
.nai-head-text { flex: 1; min-width: 0; line-height: 1.3; }
.nai-head-text strong { display: block; font-family: var(--font-display); font-size: 1.25rem; font-weight: 600; letter-spacing: 0.01em; }
.nai-head-text span { font-size: 0.72rem; color: rgba(255, 255, 255, 0.65); }

.nai-icon-btn {
  flex: 0 0 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: rgba(255, 255, 255, 0.75);
  cursor: pointer;
  transition: background 0.2s var(--ease), color 0.2s var(--ease);
}
.nai-icon-btn:hover, .nai-icon-btn:focus-visible { background: rgba(255, 255, 255, 0.1); color: var(--gold-bright); outline: none; }

/* ---- Messages ---- */
.nai-log {
  flex: 1;
  overflow-y: auto;
  padding: 1.25rem 1rem 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  background: var(--grey-50);
  overscroll-behavior: contain;
}
.nai-msg {
  max-width: 86%;
  padding: 0.7rem 0.95rem;
  border-radius: 14px;
  font-size: 0.88rem;
  line-height: 1.6;
  word-wrap: break-word;
  overflow-wrap: anywhere;
}
.nai-msg p { margin: 0 0 0.5rem; }
.nai-msg p:last-child { margin-bottom: 0; }
.nai-msg ul, .nai-msg ol { margin: 0.25rem 0 0.5rem; padding-inline-start: 1.15rem; }
.nai-msg ul { list-style: disc; }
.nai-msg ol { list-style: decimal; }
.nai-msg li::marker { color: var(--gold-deep); }
.nai-msg ul:last-child, .nai-msg ol:last-child { margin-bottom: 0; }
.nai-msg li { margin-bottom: 0.2rem; }
.nai-msg a { color: var(--gold-deep); text-decoration: underline; text-underline-offset: 2px; font-weight: 500; }

.nai-msg--assistant {
  align-self: flex-start;
  background: var(--white);
  color: var(--grey-900);
  border: 1px solid var(--grey-100);
  border-end-start-radius: 4px;
}
.nai-msg--user {
  align-self: flex-end;
  background: var(--navy);
  color: var(--white);
  border-end-end-radius: 4px;
  white-space: pre-wrap;
}
.nai-msg--note  { background: #fff8e6; border-color: rgba(230, 168, 23, 0.4); font-size: 0.8rem; }
.nai-msg--error { background: rgba(153, 10, 9, 0.06); border-color: rgba(153, 10, 9, 0.2); color: var(--red); }

.nai-msg--typing { display: flex; gap: 5px; padding: 0.9rem 1rem; }
.nai-msg--typing span {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--gold);
  animation: nai-dot 1.2s infinite ease-in-out;
}
.nai-msg--typing span:nth-child(2) { animation-delay: 0.15s; }
.nai-msg--typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes nai-dot {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.35; }
  40%           { transform: translateY(-5px); opacity: 1; }
}

/* ---- Suggested questions ---- */
.nai-suggest {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  padding: 0.5rem 1rem 0.75rem;
  background: var(--grey-50);
}
.nai-suggest[hidden] { display: none; }
.nai-chip {
  padding: 0.4rem 0.8rem;
  border: 1px solid rgba(230, 168, 23, 0.5);
  border-radius: 999px;
  background: var(--white);
  color: var(--navy);
  font-family: var(--font-body);
  font-size: 0.76rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s var(--ease), border-color 0.2s var(--ease);
}
.nai-chip:hover, .nai-chip:focus-visible { background: #fff8e6; border-color: var(--gold); outline: none; }

/* ---- Composer ---- */
.nai-form {
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
  padding: 0.75rem;
  border-top: 1px solid var(--grey-100);
  background: var(--white);
}
.nai-form textarea {
  flex: 1;
  resize: none;
  max-height: 120px;
  overflow-y: hidden;
  padding: 0.65rem 0.85rem;
  border: 1px solid var(--grey-200);
  border-radius: 10px;
  font-family: var(--font-body);
  font-size: 0.88rem;
  line-height: 1.45;
  color: var(--grey-900);
  background: var(--white);
  transition: border-color 0.2s var(--ease), box-shadow 0.2s var(--ease);
}
.nai-form textarea:focus { outline: none; border-color: var(--gold); box-shadow: 0 0 0 3px rgba(230, 168, 23, 0.18); }
.nai-send {
  flex: 0 0 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 10px;
  background: var(--gold-gradient);
  color: var(--navy);
  cursor: pointer;
  transition: transform 0.2s var(--ease), opacity 0.2s var(--ease);
}
[dir="rtl"] .nai-send svg { transform: scaleX(-1); }
.nai-send:hover { transform: translateY(-1px); }
.nai-send:disabled { opacity: 0.5; cursor: wait; transform: none; }
.nai-send:focus-visible { outline: 2px solid var(--navy); outline-offset: 2px; }

.nai-foot {
  margin: 0;
  padding: 0 0.9rem 0.65rem;
  font-size: 0.66rem;
  line-height: 1.4;
  color: var(--grey-400);
  text-align: center;
  background: var(--white);
}

/* ---- Inline launcher above the contact form ---- */
.nai-inline {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1.5rem;
  padding: 1.15rem 1.35rem;
  border-radius: var(--radius-lg);
  background: var(--navy-gradient);
  color: var(--white);
  box-shadow: var(--shadow-md);
  border: 1px solid rgba(230, 168, 23, 0.3);
  transition: transform 0.3s var(--ease-luxe), box-shadow 0.3s var(--ease);
}
.nai-inline:hover { transform: translateY(-3px); box-shadow: var(--shadow-lg); }
.nai-inline-icon {
  flex: 0 0 46px;
  height: 46px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: rgba(230, 168, 23, 0.14);
  border: 1px solid rgba(230, 168, 23, 0.45);
  color: var(--gold-bright);
}
.nai-inline-text { flex: 1; min-width: 0; line-height: 1.45; }
.nai-inline-text strong { display: block; font-family: var(--font-display); font-size: 1.25rem; font-weight: 600; }
.nai-inline-text span { font-size: 0.82rem; color: rgba(255, 255, 255, 0.72); }
.nai-inline-btn { flex-shrink: 0; white-space: nowrap; }

/* ---- Small screens ---- */
@media (max-width: 600px) {
  .nai-panel {
    inset: 0;
    width: auto;
    height: auto;
    min-height: 0;
    border-radius: 0;
    animation-name: nai-in-mobile;
  }
  body.nai-locked { overflow: hidden; }
  /* Full-screen sheet: the close button in the header replaces the bubble */
  .nai[data-state="open"] .nai-bubble { display: none; }
  .nai-inline { flex-wrap: wrap; }
  .nai-inline-btn { width: 100%; justify-content: center; }
}
@keyframes nai-in-mobile {
  from { opacity: 0; transform: translateY(24px); }
  to   { opacity: 1; transform: none; }
}

@media (prefers-reduced-motion: reduce) {
  .nai-bubble, .nai-bubble-label, .nai-inline { transition: none; }
  .nai-bubble-icon::after, .nai-panel, .nai-msg--typing span { animation: none; }
}

@media print {
  .nai, .nai-inline { display: none !important; }
}
