/* Preis-King Modern Chat v4.0 – mobile first, lazy frontend */

.pk-chat {
  --pk-chat-accent: #2f8f3a;
  --pk-chat-accent-hover: #267832;
  --pk-chat-bg: #fff;
  --pk-chat-surface: #f5f7f6;
  --pk-chat-surface-2: #eef2ef;
  --pk-chat-text: #1f2a24;
  --pk-chat-muted: #6d766f;
  --pk-chat-border: #e2e8e3;
  --pk-chat-danger: #b42318;
  --pk-chat-shadow: 0 18px 50px rgba(20, 35, 26, .18);
  --pk-chat-radius: 22px;
  --pk-chat-bottom-offset: 0px;
  position: relative;
  z-index: 2147483000;
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--pk-chat-text);
}

.pk-chat,
.pk-chat * {
  box-sizing: border-box;
}

.pk-chat > summary {
  list-style: none;
}

.pk-chat > summary::-webkit-details-marker {
  display: none;
}

.pk-chat__launcher {
  position: fixed;
  right: max(18px, env(safe-area-inset-right));
  bottom: calc(18px + env(safe-area-inset-bottom) + var(--pk-chat-bottom-offset));
  width: 56px;
  height: 56px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: var(--pk-chat-accent);
  color: #fff;
  cursor: pointer;
  box-shadow: 0 10px 28px rgba(47, 143, 58, .28);
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  transition: transform .18s ease, box-shadow .18s ease, background-color .18s ease;
}

.pk-chat__launcher:hover {
  background: var(--pk-chat-accent-hover);
  box-shadow: 0 14px 34px rgba(47, 143, 58, .34);
}

.pk-chat__launcher:active {
  transform: scale(.96);
}

.pk-chat__launcher:focus-visible,
.pk-chat__close:focus-visible,
.pk-chat button:focus-visible,
.pk-chat input:focus-visible,
.pk-chat textarea:focus-visible {
  outline: 3px solid rgba(47, 143, 58, .26);
  outline-offset: 2px;
}

.pk-chat__launcher svg {
  width: 27px;
  height: 27px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.pk-chat__badge {
  position: absolute;
  top: -3px;
  right: -3px;
  min-width: 20px;
  height: 20px;
  padding: 0 5px;
  display: inline-grid;
  place-items: center;
  border: 2px solid #fff;
  border-radius: 999px;
  background: #d92d20;
  color: #fff;
  font-size: 11px;
  font-weight: 800;
  line-height: 1;
}

.pk-chat[open] > .pk-chat__launcher {
  display: none;
}

.pk-chat__panel {
  position: fixed;
  right: max(18px, env(safe-area-inset-right));
  bottom: calc(18px + env(safe-area-inset-bottom));
  width: min(390px, calc(100vw - 36px));
  height: min(640px, calc(100dvh - 110px));
  display: none;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--pk-chat-border);
  border-radius: var(--pk-chat-radius);
  background: var(--pk-chat-bg);
  box-shadow: var(--pk-chat-shadow);
  isolation: isolate;
}

.pk-chat[open] > .pk-chat__panel {
  display: flex;
  animation: pk-chat-in .18s ease-out both;
}

.pk-chat__header {
  flex: 0 0 auto;
  min-height: 64px;
  padding: 12px 12px 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--pk-chat-border);
  background: rgba(255,255,255,.96);
  backdrop-filter: blur(12px);
}

.pk-chat__header > div {
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.pk-chat__header strong {
  font-size: 15px;
  line-height: 1.2;
}

.pk-chat__header span {
  margin-top: 2px;
  color: var(--pk-chat-muted);
  font-size: 12px;
}

.pk-chat__close {
  flex: 0 0 42px;
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: var(--pk-chat-surface);
  color: var(--pk-chat-text);
  cursor: pointer;
  font-size: 27px;
  line-height: 1;
  transition: background-color .16s ease, transform .16s ease;
}

.pk-chat__close:hover {
  background: var(--pk-chat-surface-2);
}

.pk-chat__close:active {
  transform: scale(.96);
}

.pk-chat__mount {
  min-height: 0;
  flex: 1 1 auto;
  display: flex;
  overflow: hidden;
}

.pk-chat__boot {
  width: 100%;
  min-height: 220px;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 12px;
  color: var(--pk-chat-muted);
  font-size: 14px;
}

.pk-chat__boot--error {
  padding: 28px;
  color: var(--pk-chat-danger);
  text-align: center;
}

.pk-chat__spinner {
  width: 28px;
  height: 28px;
  border: 3px solid var(--pk-chat-border);
  border-top-color: var(--pk-chat-accent);
  border-radius: 50%;
  animation: pk-chat-spin .7s linear infinite;
}

.modern-chat-container {
  width: 100%;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--pk-chat-bg);
}

.modern-chat-messages {
  min-height: 0;
  flex: 1 1 auto;
  margin: 0;
  padding: 16px 14px 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow-y: auto;
  overflow-x: hidden;
  list-style: none;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: #cbd5cc transparent;
  scroll-behavior: smooth;
}

.modern-chat-messages::-webkit-scrollbar {
  width: 6px;
}

.modern-chat-messages::-webkit-scrollbar-thumb {
  border-radius: 999px;
  background: #cbd5cc;
}

.pk-chat-empty {
  margin: auto;
  padding: 30px 16px;
  color: var(--pk-chat-muted);
  font-size: 14px;
  line-height: 1.5;
  text-align: center;
}

.modern-chat-message {
  width: 100%;
  display: flex;
  align-items: flex-end;
  gap: 8px;
}

.modern-chat-message.own-message {
  flex-direction: row-reverse;
}

.modern-chat-message[hidden] {
  display: none !important;
}

.modern-chat-avatar {
  flex: 0 0 30px;
  width: 30px;
  height: 30px;
  margin-bottom: 23px;
}

.modern-chat-avatar img {
  width: 100%;
  height: 100%;
  display: block;
  border-radius: 50%;
  object-fit: cover;
  background: var(--pk-chat-surface-2);
}

.message-content {
  min-width: 0;
  max-width: min(82%, 290px);
  display: flex;
  flex-direction: column;
  align-items: flex-start;
}

.own-message .message-content {
  align-items: flex-end;
}

.modern-chat-username {
  max-width: 100%;
  margin: 0 8px 4px;
  overflow: hidden;
  color: var(--pk-chat-muted);
  font-size: 11px;
  font-weight: 700;
  line-height: 1.2;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.online-indicator {
  width: 7px;
  height: 7px;
  display: inline-block;
  margin-left: 5px;
  border-radius: 50%;
  background: #22c55e;
  box-shadow: 0 0 0 2px #fff;
}

.modern-chat-text {
  max-width: 100%;
  padding: 9px 12px;
  border-radius: 16px 16px 16px 5px;
  background: var(--pk-chat-surface);
  color: var(--pk-chat-text);
  font-size: 14px;
  line-height: 1.45;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.own-message .modern-chat-text {
  border-radius: 16px 16px 5px 16px;
  background: var(--pk-chat-accent);
  color: #fff;
}

.modern-chat-text a {
  color: inherit;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.modern-chat-time {
  margin: 4px 8px 0;
  color: #8a958d;
  font-size: 10px;
  line-height: 1.2;
}

.message-controls {
  min-height: 25px;
  margin-top: 2px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 2px;
}

.own-message .message-controls {
  justify-content: flex-end;
}

.pk-chat-action {
  min-width: 28px;
  min-height: 28px;
  padding: 4px 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--pk-chat-muted);
  cursor: pointer;
  font: inherit;
  font-size: 11px;
  line-height: 1;
}

.pk-chat-action:hover {
  background: var(--pk-chat-surface);
  color: var(--pk-chat-text);
}

.pk-chat-action > span:first-child {
  font-size: 14px;
}

.modern-chat-form {
  flex: 0 0 auto;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--pk-chat-border);
  background: #fff;
}

.pk-chat-field {
  margin-bottom: 8px;
  display: block;
}

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

.modern-chat-guest-name {
  width: 100%;
  height: 40px;
  padding: 0 12px;
  border: 1px solid var(--pk-chat-border);
  border-radius: 12px;
  background: #fff;
  color: var(--pk-chat-text);
  font: inherit;
  font-size: 14px;
}

.modern-chat-input-group {
  display: grid;
  grid-template-columns: 42px minmax(0,1fr) 44px;
  align-items: end;
  gap: 7px;
}

.emoji-btn,
.modern-chat-submit-btn {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 12px;
  cursor: pointer;
}

.emoji-btn {
  background: var(--pk-chat-surface);
  color: var(--pk-chat-text);
  font-size: 20px;
}

.modern-chat-submit-btn {
  width: 44px;
  background: var(--pk-chat-accent);
  color: #fff;
}

.modern-chat-submit-btn:hover {
  background: var(--pk-chat-accent-hover);
}

.modern-chat-submit-btn:disabled {
  cursor: wait;
  opacity: .55;
}

.modern-chat-submit-btn svg {
  width: 21px;
  height: 21px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.modern-chat-message-input {
  width: 100%;
  min-height: 42px;
  max-height: 120px;
  padding: 10px 12px;
  resize: none;
  overflow-y: auto;
  border: 1px solid var(--pk-chat-border);
  border-radius: 12px;
  background: #fff;
  color: var(--pk-chat-text);
  font: inherit;
  font-size: 16px;
  line-height: 1.35;
}

.modern-chat-message-input::placeholder,
.modern-chat-guest-name::placeholder {
  color: #98a19b;
}

.pk-chat-emoji-panel {
  margin-top: 8px;
  padding: 8px;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 4px;
  border: 1px solid var(--pk-chat-border);
  border-radius: 12px;
  background: var(--pk-chat-surface);
}

.pk-chat-emoji-panel[hidden] {
  display: none !important;
}

.pk-chat-emoji {
  width: 100%;
  min-height: 34px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 8px;
  background: transparent;
  cursor: pointer;
  font-size: 19px;
}

.pk-chat-emoji:hover {
  background: #fff;
}

.pk-chat-status {
  min-height: 16px;
  margin-top: 6px;
  color: var(--pk-chat-muted);
  font-size: 11px;
  line-height: 1.3;
  text-align: center;
}

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

.pk-chat-status[data-type="error"] {
  color: var(--pk-chat-danger);
}

.pk-chat-status[data-type="success"] {
  color: var(--pk-chat-accent);
}

.pk-chat-edit {
  width: min(290px, 100%);
  margin-top: 4px;
}

.pk-chat-edit textarea {
  width: 100%;
  min-height: 76px;
  padding: 8px 10px;
  resize: vertical;
  border: 1px solid var(--pk-chat-border);
  border-radius: 10px;
  color: var(--pk-chat-text);
  font: inherit;
  font-size: 14px;
}

.pk-chat-edit__actions {
  margin-top: 6px;
  display: flex;
  justify-content: flex-end;
  gap: 6px;
}

.pk-chat-edit__save,
.pk-chat-edit__cancel {
  min-height: 34px;
  padding: 0 11px;
  border: 0;
  border-radius: 9px;
  cursor: pointer;
  font-weight: 700;
}

.pk-chat-edit__save {
  background: var(--pk-chat-accent);
  color: #fff;
}

.pk-chat-edit__cancel {
  background: var(--pk-chat-surface);
  color: var(--pk-chat-text);
}

@keyframes pk-chat-spin {
  to { transform: rotate(360deg); }
}

@keyframes pk-chat-in {
  from {
    opacity: 0;
    transform: translateY(8px) scale(.985);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

@media (hover: hover) and (pointer: fine) {
  .message-controls {
    opacity: .4;
    transition: opacity .14s ease;
  }

  .modern-chat-message:hover .message-controls,
  .message-controls:focus-within {
    opacity: 1;
  }
}

@media (max-width: 640px) {
  html.pk-chat-open,
  html.pk-chat-open body {
    overflow: hidden !important;
    overscroll-behavior: none;
  }

  .pk-chat__panel {
    inset: 0;
    width: 100%;
    height: 100dvh;
    max-width: none;
    max-height: none;
    border: 0;
    border-radius: 0;
    box-shadow: none;
  }

  .pk-chat__header {
    min-height: calc(58px + env(safe-area-inset-top));
    padding-top: calc(8px + env(safe-area-inset-top));
  }

  .modern-chat-messages {
    padding: 14px 12px 10px;
  }

  .message-content {
    max-width: 84%;
  }

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

  .modern-chat-text {
    font-size: 14px;
  }

  .pk-chat-action > span:last-child {
    display: none;
  }

  .pk-chat-action {
    min-width: 30px;
    min-height: 30px;
  }

  .pk-chat-emoji-panel {
    grid-template-columns: repeat(8, 1fr);
  }
}

@media (max-width: 380px) {
  .pk-chat__launcher {
    width: 54px;
    height: 54px;
    right: max(14px, env(safe-area-inset-right));
    bottom: calc(14px + env(safe-area-inset-bottom) + var(--pk-chat-bottom-offset));
  }

  .pk-chat-emoji-panel {
    grid-template-columns: repeat(4, 1fr);
  }

  .modern-chat-input-group {
    grid-template-columns: 40px minmax(0,1fr) 42px;
    gap: 6px;
  }

  .emoji-btn {
    width: 40px;
    height: 40px;
  }

  .modern-chat-submit-btn {
    width: 42px;
    height: 42px;
  }
}

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