/* =============================================================================
   Asszisztens widget — semleges, prémium alapdizájn, design tokenekkel.
   A márkaszínt a host oldal (vagy a szerveroldali brand_json) állítja:
     --a-accent, --a-accent-ink, --a-surface, --a-ink, --a-radius
   Minden más ezekből származik, ezért egy másik márkához 3-5 érték elég.
   ========================================================================== */

.a-root {
  --a-surface: #ffffff;
  --a-surface-2: #f6f5f2;
  --a-surface-3: #eeede8;
  --a-ink: #16181a;
  --a-ink-soft: #5b6167;
  --a-ink-faint: #6b7178;
  /* A beviteli mező placeholder-szövege: olvasható, nem „beolvadó” szürke. */
  --a-placeholder: #4f565d;
  --a-line: rgba(22, 24, 26, 0.10);
  --a-line-strong: rgba(22, 24, 26, 0.18);
  --a-accent: #0f5f5c;
  --a-accent-ink: #ffffff;
  --a-accent-soft: rgba(15, 95, 92, 0.08);
  --a-danger: #b3261e;
  --a-radius: 20px;
  --a-radius-sm: 12px;
  --a-shadow: 0 24px 60px -12px rgba(16, 20, 22, 0.28), 0 2px 8px rgba(16, 20, 22, 0.08);
  --a-font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --a-vh: 100dvh;

  font-family: var(--a-font);
  font-size: 15px;
  line-height: 1.5;
  color: var(--a-ink);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

@media (prefers-color-scheme: dark) {
  .a-root {
    --a-surface: #15181a;
    --a-surface-2: #1d2124;
    --a-surface-3: #262b2f;
    --a-ink: #f3f2ef;
    --a-ink-soft: #b4b9bd;
    --a-ink-faint: #9aa1a6;
    /* Sötét felületen a placeholder fehér — így nem olvad bele a háttérbe. */
    --a-placeholder: rgba(255, 255, 255, 0.95);
    --a-line: rgba(255, 255, 255, 0.10);
    --a-line-strong: rgba(255, 255, 255, 0.20);
    --a-accent: #4fc3b8;
    --a-accent-ink: #06201f;
    --a-accent-soft: rgba(79, 195, 184, 0.12);
    --a-danger: #ff8a80;
    --a-shadow: 0 24px 60px -12px rgba(0, 0, 0, 0.6), 0 2px 8px rgba(0, 0, 0, 0.4);
  }
}

.a-root *,
.a-root *::before,
.a-root *::after {
  box-sizing: border-box;
}

/* Mobilon a widget gombjai ne kapjanak téglalap alakú kijelölést/kiemelést. */
.a-root {
  -webkit-tap-highlight-color: transparent;
}

.a-root button,
.a-root .a-chip,
.a-root .a-launcher,
.a-root .a-send,
.a-root .a-close,
.a-root .a-persona {
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
}

.a-msg__debug {
  margin: 6px 0 0;
  color: var(--a-ink-faint);
  font: 400 11.5px/1.4 var(--a-font);
  letter-spacing: 0.02em;
}

.a-root ::selection {
  background: var(--a-accent-soft);
}

/* --------------------------------------------------------------- launcher */
/* Betöltés alatt a gomb rejtve: nincs „alap gomb → átvált” villanás. */
.a-root--booting .a-launcher {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.a-launcher {
  transition: opacity 0.18s ease;
  /* Mobilon a koppintás ne rajzoljon téglalapot a gömb/ovális gomb köré:
     nincs tap-highlight, nincs szövegkijelölés, nincs hosszú nyomás menü. */
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
  appearance: none;
  -webkit-appearance: none;
  position: fixed;
  right: max(20px, env(safe-area-inset-right));
  bottom: max(20px, env(safe-area-inset-bottom));
  z-index: 2147483000;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 52px;
  padding: 0 20px 0 16px;
  border: 1px solid var(--a-line-strong);
  border-radius: 999px;
  background: var(--a-surface);
  color: var(--a-ink);
  box-shadow: var(--a-shadow);
  font: 600 14px/1 var(--a-font);
  letter-spacing: 0.01em;
  cursor: pointer;
  transition: transform 0.18s ease, box-shadow 0.18s ease, background-color 0.18s ease;
}

/* Bal alsó sarok (admin → Márka és domainek → Gomb helye) */
.a-root--launcher-left .a-launcher {
  right: auto;
  left: max(20px, env(safe-area-inset-left));
}

/* Csak ikon (kör) — a felirat elrejtve */
.a-root--launcher-circle .a-launcher {
  justify-content: center;
  width: 56px;
  min-width: 56px;
  height: 56px;
  min-height: 0;
  padding: 0;
  border-radius: 50%;
}

.a-root--launcher-circle .a-launcher__label {
  display: none;
}

@media (max-width: 560px) {
  .a-root--launcher-left .a-launcher {
    left: 14px;
    right: auto;
  }

  .a-root--launcher-circle .a-launcher {
    width: 52px;
    min-width: 52px;
    height: 52px;
  }
}

.a-launcher:hover {
  transform: translateY(-1px);
  box-shadow: 0 28px 64px -14px rgba(16, 20, 22, 0.34), 0 2px 8px rgba(16, 20, 22, 0.10);
}

.a-launcher:active {
  transform: translateY(0);
}

.a-launcher__orb {
  position: relative;
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--a-accent);
  color: var(--a-accent-ink);
  font-size: 15px;
  font-weight: 700;
  line-height: 1;
}

.a-launcher__dot {
  position: absolute;
  right: -1px;
  bottom: -1px;
  width: 9px;
  height: 9px;
  border: 2px solid var(--a-surface);
  border-radius: 50%;
  background: #2e9e6b;
}

.a-launcher[aria-expanded="true"] .a-launcher__orb {
  transform: rotate(90deg);
  transition: transform 0.18s ease;
}

/* ------------------------------------------------------------------ panel */
.a-panel {
  position: fixed;
  right: max(20px, env(safe-area-inset-right));
  /* Ha megjelenik a billentyűzet (tableten/asztali nézetben is), a panel fölé emelkedik. */
  bottom: calc(max(84px, calc(env(safe-area-inset-bottom) + 76px)) + var(--a-kb, 0px));
  z-index: 2147483001;
  display: flex;
  flex-direction: column;
  width: min(392px, calc(100vw - 32px));
  max-height: min(660px, calc(var(--a-vh) - 120px));
  overflow: hidden;
  border: 1px solid var(--a-line);
  border-radius: var(--a-radius);
  background: var(--a-surface);
  box-shadow: var(--a-shadow);
  animation: a-in 0.2s cubic-bezier(0.22, 0.8, 0.3, 1);
}

.a-panel[hidden] {
  display: none !important;
}

@keyframes a-in {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.99);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

/* ----------------------------------------------------------------- header */
.a-header {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 14px 14px 18px;
  border-bottom: 1px solid var(--a-line);
  background: linear-gradient(180deg, var(--a-surface-2), var(--a-surface));
}

.a-header__text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  flex: 1;
}

.a-header__kicker {
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.10em;
  text-transform: uppercase;
  color: var(--a-ink-faint);
}

.a-header__title {
  font-size: 15.5px;
  font-weight: 650;
  letter-spacing: -0.01em;
  color: var(--a-ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.a-header__sub {
  font-size: 12px;
  color: var(--a-ink-soft);
}

.a-avatar {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: radial-gradient(circle at 30% 25%, color-mix(in srgb, var(--a-accent) 55%, #ffffff) 0%, var(--a-accent) 70%);
  color: var(--a-accent-ink);
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.a-iconbtn {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 38px;
  height: 38px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 10px;
  background: transparent;
  color: var(--a-ink-soft);
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.a-iconbtn:hover {
  background: var(--a-surface-3);
  color: var(--a-ink);
}

.a-iconbtn svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* --------------------------------------------------------------- personas */
.a-personas {
  display: flex;
  gap: 8px;
  padding: 12px 18px;
  overflow-x: auto;
  border-bottom: 1px solid var(--a-line);
  scrollbar-width: none;
}

.a-personas::-webkit-scrollbar {
  display: none;
}

.a-persona {
  flex: 0 0 auto;
  min-height: 32px;
  padding: 0 12px;
  border: 1px solid var(--a-line-strong);
  border-radius: 999px;
  background: transparent;
  color: var(--a-ink-soft);
  font: 500 12.5px/1 var(--a-font);
  cursor: pointer;
  white-space: nowrap;
}

.a-persona[aria-selected="true"] {
  border-color: var(--a-accent);
  background: var(--a-accent-soft);
  color: var(--a-accent);
  font-weight: 650;
}

/* --------------------------------------------------------------- messages */
.a-log {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
  /* 0: kis magasságnál (nyitott billentyűzet) a napló zsugorodik, nem a beviteli mező
     lóg ki a panel alján. */
  min-height: 0;
  padding: 18px;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
}

.a-msg {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-width: 88%;
}

.a-msg--user {
  align-self: flex-end;
  align-items: flex-end;
}

.a-msg__who {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--a-ink-faint);
}

.a-msg__body {
  padding: 11px 14px;
  border: 1px solid var(--a-line);
  border-radius: 16px 16px 16px 6px;
  background: var(--a-surface-2);
  font-size: 14.5px;
  line-height: 1.55;
  color: var(--a-ink);
  overflow-wrap: anywhere;
}

.a-msg--user .a-msg__body {
  border-color: transparent;
  border-radius: 16px 16px 6px 16px;
  background: var(--a-accent);
  color: var(--a-accent-ink);
}

.a-msg--blocked .a-msg__body {
  border-color: color-mix(in srgb, var(--a-danger) 40%, transparent);
  background: color-mix(in srgb, var(--a-danger) 8%, var(--a-surface));
  color: var(--a-ink);
}

.a-msg__body p {
  margin: 0;
}

.a-msg__body p + p {
  margin-top: 8px;
}

.a-msg__foot {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.a-tag {
  padding: 2px 7px;
  border-radius: 999px;
  background: var(--a-surface-3);
  color: var(--a-ink-faint);
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.02em;
}

/* ----------------------------------------------------------------- forrás */
.a-sources {
  width: 100%;
  border: 1px solid var(--a-line);
  border-radius: var(--a-radius-sm);
  background: var(--a-surface);
}

.a-sources > summary {
  padding: 8px 12px;
  font-size: 12px;
  font-weight: 600;
  color: var(--a-ink-soft);
  cursor: pointer;
  list-style: none;
}

.a-sources > summary::-webkit-details-marker {
  display: none;
}

.a-sources > summary::before {
  content: "▸";
  display: inline-block;
  margin-right: 6px;
  color: var(--a-ink-faint);
  transition: transform 0.15s ease;
}

.a-sources[open] > summary::before {
  transform: rotate(90deg);
}

.a-sources ul {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0 12px 12px;
  list-style: none;
}

.a-sources li {
  font-size: 12px;
  color: var(--a-ink-soft);
}

.a-sources li strong {
  display: block;
  color: var(--a-ink);
  font-weight: 600;
}

/* -------------------------------------------------------------- CTA-kártya */
.a-cta {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
  margin-top: 2px;
  padding: 14px;
  border: 1px solid color-mix(in srgb, var(--a-accent) 32%, var(--a-line));
  border-radius: var(--a-radius-sm);
  background: var(--a-accent-soft);
}

.a-cta__label {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--a-accent);
}

.a-cta__desc {
  margin: 0;
  font-size: 13px;
  color: var(--a-ink-soft);
}

.a-cta__btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 16px;
  border-radius: 10px;
  background: var(--a-accent);
  color: var(--a-accent-ink);
  font: 650 14px/1 var(--a-font);
  text-decoration: none;
  transition: filter 0.15s ease;
}

.a-cta__btn:hover {
  filter: brightness(1.06);
}

.a-cta__note {
  font-size: 11.5px;
  color: var(--a-ink-faint);
}

/* ------------------------------------------------------------ gépel, üres */
.a-typing {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 12px 14px;
  border: 1px solid var(--a-line);
  border-radius: 16px 16px 16px 6px;
  background: var(--a-surface-2);
  width: fit-content;
}

.a-typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--a-ink-faint);
  animation: a-blink 1.2s infinite ease-in-out;
}

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

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

@keyframes a-blink {
  0%, 80%, 100% {
    opacity: 0.25;
  }
  40% {
    opacity: 1;
  }
}

.a-empty {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.a-empty__text {
  font-size: 14.5px;
  color: var(--a-ink-soft);
}

.a-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.a-chip {
  min-height: 34px;
  max-width: 100%;
  padding: 6px 12px;
  border: 1px solid var(--a-line-strong);
  border-radius: 999px;
  background: var(--a-surface);
  color: var(--a-ink);
  font: 500 13px/1.35 var(--a-font);
  text-align: left;
  cursor: pointer;
}

.a-chip:hover {
  border-color: var(--a-accent);
  color: var(--a-accent);
}

/* ---------------------------------------------------------------- composer */
.a-composer {
  flex: 0 0 auto;
  padding: 10px 14px calc(10px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--a-line);
  background: var(--a-surface);
}

.a-field {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 6px 6px 6px 12px;
  border: 1px solid var(--a-line-strong);
  border-radius: 14px;
  background: var(--a-surface-2);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.a-field:focus-within {
  border-color: var(--a-accent);
  box-shadow: 0 0 0 3px var(--a-accent-soft);
}

.a-input {
  flex: 1;
  min-height: 36px;
  max-height: 132px;
  padding: 8px 0;
  border: 0;
  background: transparent;
  color: var(--a-ink);
  font: 400 14.5px/1.5 var(--a-font);
  resize: none;
  outline: none;
}

.a-input::placeholder {
  color: var(--a-placeholder);
  opacity: 1; /* Firefox enélkül áttetszővé teszi */
}

/* Sötét beviteli mező (admin → Márka és domainek → „Sötét beviteli mező”).
   A placeholder itt kifejezetten fehér, mert a háttér sötét. */
.a-root--input-dark .a-field {
  border-color: rgba(255, 255, 255, 0.22);
  background: #14161a;
}

.a-root--input-dark .a-input {
  color: #ffffff;
}

.a-root--input-dark .a-input::placeholder {
  color: #ffffff;
  opacity: 0.95;
}

.a-root--input-dark .a-field:focus-within {
  border-color: var(--a-accent);
  box-shadow: 0 0 0 3px var(--a-accent-soft);
}

.a-send {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 38px;
  height: 38px;
  padding: 0;
  border: 0;
  border-radius: 10px;
  background: var(--a-accent);
  color: var(--a-accent-ink);
  cursor: pointer;
  transition: opacity 0.15s ease, transform 0.15s ease;
}

.a-send:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.a-send:not(:disabled):active {
  transform: scale(0.96);
}

.a-send svg {
  width: 17px;
  height: 17px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.a-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 8px;
  font-size: 11.5px;
  color: var(--a-ink-faint);
}

.a-status {
  flex: 1;
  min-height: 16px;
}

.a-privacy {
  margin: 6px 0 0;
  font-size: 11.5px;
  line-height: 1.4;
  color: var(--a-ink-faint);
}

.a-privacy a {
  color: var(--a-ink-soft);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.a-counter {
  font-variant-numeric: tabular-nums;
}

.a-counter[data-over="true"] {
  color: var(--a-danger);
  font-weight: 650;
}

/* --------------------------------------------------------------- megerősítés */
/* A böngésző window.confirm() helyett: nem blokkolja a fókuszt, felolvasható,
   és a panelen belül marad (a fókuszcsapda is kezeli). */
.a-confirm {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 0 14px 10px;
  padding: 12px 14px;
  border: 1px solid var(--a-line-strong);
  border-radius: var(--a-radius-sm);
  background: var(--a-surface-2);
}

.a-confirm[hidden] {
  display: none;
}

.a-confirm__text {
  margin: 0;
  font-size: 13.5px;
  line-height: 1.45;
  color: var(--a-ink);
}

.a-confirm__actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

.a-btn {
  min-height: 36px;
  padding: 0 14px;
  border: 1px solid var(--a-line-strong);
  border-radius: 10px;
  background: var(--a-surface);
  color: var(--a-ink);
  font: 600 13px/1 var(--a-font);
  cursor: pointer;
}

.a-btn--danger {
  border-color: transparent;
  background: var(--a-danger);
  color: #ffffff;
}

@media (prefers-color-scheme: dark) {
  .a-btn--danger {
    color: #2a0703;
  }
}

/* ------------------------------------------------------------------- a11y */
.a-root :focus-visible,
.a-launcher:focus-visible {
  outline: 2px solid var(--a-accent);
  outline-offset: 2px;
  border-radius: 8px;
}

/* Koppintás (egér/ujj) ne hagyjon keretet a gombon — csak a billentyűs fókusz látszódjon. */
.a-root button:focus:not(:focus-visible),
.a-launcher:focus:not(:focus-visible) {
  outline: none;
}

/* A gömb/ovális gomb fókuszgyűrűje kövesse a forma ívét. */
.a-launcher:focus-visible {
  border-radius: 999px;
}

.a-sr {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

/* --------------------------------------------------------------- mobilnézet */
@media (max-width: 560px) {
  .a-launcher {
    right: 14px;
    bottom: max(14px, env(safe-area-inset-bottom));
    min-height: 48px;
    padding: 0 16px 0 13px;
    font-size: 13.5px;
  }

  .a-panel {
    right: 0;
    /* A billentyűzet magasságával megemeljük (a látható terület aljára igazítunk). */
    bottom: var(--a-kb, 0px);
    left: 0;
    width: 100%;
    max-height: var(--a-vh);
    height: var(--a-vh);
    border: 0;
    border-radius: 18px 18px 0 0;
    animation: a-up 0.22s cubic-bezier(0.22, 0.8, 0.3, 1);
  }

  .a-log {
    padding: 16px 14px;
  }

  .a-msg {
    max-width: 94%;
  }
}

@keyframes a-up {
  from {
    transform: translateY(16px);
    opacity: 0.6;
  }
  to {
    transform: none;
    opacity: 1;
  }
}

/* Mozgáscsökkentés: minden animáció ki. */
@media (prefers-reduced-motion: reduce) {
  .a-root *,
  .a-panel {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}

/* Kényszerített színek (Windows high contrast). */
@media (forced-colors: active) {
  .a-msg__body,
  .a-panel,
  .a-launcher,
  .a-cta__btn {
    border: 1px solid ButtonBorder;
  }
}
