/* ========================================================
   MerMiko AI Chat Widget - Styles
   ======================================================== */

:root {
  --m-ai-primary: #ea001b;
  --m-ai-primary-glow: rgba(234, 0, 27, 0.4);
  --m-ai-bg: #0b0f19;
  --m-ai-card: rgba(17, 24, 39, 0.85);
  --m-ai-border: rgba(255, 255, 255, 0.1);
  --m-ai-text: #f3f4f6;
  --m-ai-text-dim: #9ca3af;
  --m-ai-user-bubble: linear-gradient(135deg, #2563eb, #1d4ed8);
  --m-ai-bot-bubble: rgba(30, 41, 59, 0.7);
}

/* Przycisk w górnym pasku nawigacji */
.nav-ai-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  background: linear-gradient(135deg, rgba(234, 0, 27, 0.15), rgba(99, 102, 241, 0.15));
  border: 1px solid rgba(234, 0, 27, 0.4);
  color: #fff !important;
  font-weight: 700;
  font-size: 0.86rem;
  padding: 6px 14px;
  border-radius: 999px;
  cursor: pointer;
  transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  box-shadow: 0 0 15px rgba(234, 0, 27, 0.2);
  text-decoration: none;
}
.nav-ai-btn:hover {
  background: linear-gradient(135deg, rgba(234, 0, 27, 0.3), rgba(99, 102, 241, 0.3));
  border-color: rgba(234, 0, 27, 0.7);
  box-shadow: 0 0 20px rgba(234, 0, 27, 0.4);
  transform: translateY(-1px);
}
.nav-ai-sparkle {
  display: inline-block;
  font-size: 0.95rem;
  animation: m-ai-spin 4s linear infinite;
}
@keyframes m-ai-spin {
  0% { transform: scale(1) rotate(0deg); }
  50% { transform: scale(1.15) rotate(180deg); }
  100% { transform: scale(1) rotate(360deg); }
}

/* Pływający przycisk w prawym dolnym rogu */
.m-ai-fab {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 58px;
  height: 58px;
  border-radius: 18px;
  background: linear-gradient(135deg, #ea001b, #990012);
  border: 1px solid rgba(255, 255, 255, 0.2);
  box-shadow: 0 8px 30px rgba(234, 0, 27, 0.4), 0 0 20px rgba(234, 0, 27, 0.25);
  cursor: pointer;
  z-index: 99998;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  user-select: none;
}
.m-ai-fab:hover {
  transform: translateY(-3px) scale(1.05);
  box-shadow: 0 12px 35px rgba(234, 0, 27, 0.55), 0 0 25px rgba(234, 0, 27, 0.4);
}
.m-ai-fab img {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  pointer-events: none;
}
.m-ai-fab .m-ai-badge-online {
  position: absolute;
  top: -2px;
  right: -2px;
  width: 14px;
  height: 14px;
  background: #22c55e;
  border: 2px solid #0b0f19;
  border-radius: 50%;
  box-shadow: 0 0 8px #22c55e;
}
.m-ai-fab-tooltip {
  position: absolute;
  right: 70px;
  background: rgba(15, 23, 42, 0.95);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.12);
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 0.8rem;
  font-weight: 600;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transform: translateX(8px);
  transition: all 0.2s ease;
  backdrop-filter: blur(8px);
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.4);
}
.m-ai-fab:hover .m-ai-fab-tooltip {
  opacity: 1;
  transform: translateX(0);
}

/* Okno czatu (Drawer / Modal) */
.m-ai-chat-window {
  position: fixed;
  bottom: 96px;
  right: 24px;
  width: 400px;
  max-width: calc(100vw - 32px);
  height: 600px;
  max-height: calc(100vh - 120px);
  background: var(--m-ai-card);
  border: 1px solid var(--m-ai-border);
  border-radius: 20px;
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.6), 0 0 30px rgba(234, 0, 27, 0.15);
  display: flex;
  flex-direction: column;
  z-index: 99999;
  overflow: hidden;
  opacity: 0;
  visibility: hidden;
  transform: translateY(20px) scale(0.96);
  transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}
.m-ai-chat-window.open {
  opacity: 1;
  visibility: visible;
  transform: translateY(0) scale(1);
}

/* Nagłówek czatu */
.m-ai-header {
  padding: 14px 16px;
  background: rgba(11, 15, 25, 0.8);
  border-bottom: 1px solid var(--m-ai-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.m-ai-header-left {
  display: flex;
  align-items: center;
  gap: 10px;
}
.m-ai-header-avatar {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.15);
}
.m-ai-header-title {
  font-weight: 700;
  font-size: 0.95rem;
  color: #fff;
  display: flex;
  align-items: center;
  gap: 6px;
}
.m-ai-header-badge {
  font-size: 0.65rem;
  background: rgba(234, 0, 27, 0.2);
  color: #ff4d64;
  border: 1px solid rgba(234, 0, 27, 0.4);
  padding: 2px 6px;
  border-radius: 6px;
  font-weight: 800;
  letter-spacing: 0.5px;
}
.m-ai-header-sub {
  font-size: 0.75rem;
  color: #4ade80;
  display: flex;
  align-items: center;
  gap: 5px;
}
.m-ai-header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}
.m-ai-btn-icon {
  background: transparent;
  border: none;
  color: var(--m-ai-text-dim);
  width: 32px;
  height: 32px;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  transition: all 0.15s;
}
.m-ai-btn-icon:hover {
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
}

/* High Load Warning Banner */
.m-ai-load-banner {
  background: rgba(245, 158, 11, 0.12);
  border-bottom: 1px solid rgba(245, 158, 11, 0.25);
  color: #fbbf24;
  font-size: 0.74rem;
  font-weight: 600;
  padding: 8px 14px;
  display: flex;
  align-items: center;
  gap: 8px;
  line-height: 1.35;
  animation: m-ai-fadeIn 0.2s ease-out;
}
.m-ai-load-banner svg {
  flex-shrink: 0;
}
@keyframes m-ai-fadeIn {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Obszar wiadomości */
.m-ai-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  scroll-behavior: smooth;
}
.m-ai-messages::-webkit-scrollbar {
  width: 6px;
}
.m-ai-messages::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.15);
  border-radius: 3px;
}

/* Dymki wiadomości */
.m-ai-msg {
  display: flex;
  gap: 10px;
  max-width: 88%;
  line-height: 1.5;
  font-size: 0.88rem;
}
.m-ai-msg-user {
  align-self: flex-end;
  flex-direction: row-reverse;
}
.m-ai-msg-bot {
  align-self: flex-start;
}
.m-ai-msg-avatar {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  flex-shrink: 0;
}
.m-ai-bubble {
  padding: 10px 14px;
  border-radius: 14px;
  word-break: break-word;
}
.m-ai-msg-user .m-ai-bubble {
  background: var(--m-ai-user-bubble);
  color: #fff;
  border-bottom-right-radius: 3px;
}
.m-ai-msg-bot .m-ai-bubble {
  background: var(--m-ai-bot-bubble);
  color: var(--m-ai-text);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-bottom-left-radius: 3px;
}

/* Formatowanie Markdown wewnątrz bota */
.m-ai-h1, .m-ai-h2, .m-ai-h3 {
  font-weight: 700;
  color: #fff;
  margin: 8px 0 4px 0;
  line-height: 1.35;
}
.m-ai-h1 { font-size: 1.05rem; }
.m-ai-h2 { font-size: 0.98rem; }
.m-ai-h3 { font-size: 0.92rem; color: #ff4d64; }

.m-ai-bubble p {
  margin: 0 0 8px 0;
}
.m-ai-bubble p:last-child {
  margin-bottom: 0;
}
.m-ai-bubble ul, .m-ai-bubble ol {
  margin: 4px 0 8px 18px;
  padding: 0;
}
.m-ai-bubble li {
  margin-bottom: 4px;
}
.m-ai-bubble strong {
  color: #fff;
  font-weight: 700;
}
.m-ai-bubble a {
  color: #38bdf8;
  text-decoration: underline;
  text-underline-offset: 2px;
}
.m-ai-bubble a:hover {
  color: #7dd3fc;
}
.m-ai-bubble code {
  background: rgba(0, 0, 0, 0.35);
  padding: 2px 5px;
  border-radius: 4px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.82rem;
  color: #f43f5e;
}
.m-ai-bubble pre {
  background: rgba(0, 0, 0, 0.45);
  border: 1px solid rgba(255, 255, 255, 0.1);
  padding: 10px;
  border-radius: 8px;
  overflow-x: auto;
  margin: 6px 0;
}
.m-ai-bubble pre code {
  background: transparent;
  padding: 0;
  color: #cbd5e1;
}

/* Szybkie pytania (Suggested Chips) */
.m-ai-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}
.m-ai-chip {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: #cbd5e1;
  padding: 6px 11px;
  border-radius: 999px;
  font-size: 0.78rem;
  cursor: pointer;
  transition: all 0.2s;
  text-align: left;
}
.m-ai-chip:hover {
  background: rgba(234, 0, 27, 0.18);
  border-color: rgba(234, 0, 27, 0.4);
  color: #fff;
  transform: translateY(-1px);
}

/* Dynamiczne Myślenie i Weryfikacja */
.m-ai-thinking-bubble {
  background: rgba(15, 23, 42, 0.75) !important;
  border: 1px solid rgba(234, 0, 27, 0.3) !important;
  padding: 10px 14px !important;
}
.m-ai-thought-step {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 0.8rem;
  color: #cbd5e1;
  font-weight: 500;
}
.m-ai-thought-spinner {
  width: 13px;
  height: 13px;
  border: 2px solid rgba(234, 0, 27, 0.25);
  border-top-color: #ff334b;
  border-radius: 50%;
  animation: m-ai-spin 0.8s linear infinite;
  flex-shrink: 0;
}

/* Kursor pisania (Typing cursor effect) */
.m-ai-cursor {
  display: inline-block;
  width: 2px;
  height: 1.15em;
  background: #ff334b;
  vertical-align: -2px;
  margin-left: 2px;
  border-radius: 1px;
  box-shadow: 0 0 6px #ff334b;
  animation: m-ai-blink 0.75s infinite;
}
@keyframes m-ai-blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}

/* Wskaźnik pisania (Typing dots) */
.m-ai-typing {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 10px 14px;
}
.m-ai-typing-dot {
  width: 6px;
  height: 6px;
  background: #cbd5e1;
  border-radius: 50%;
  animation: m-ai-bounce 1.4s infinite ease-in-out both;
}
.m-ai-typing-dot:nth-child(1) { animation-delay: -0.32s; }
.m-ai-typing-dot:nth-child(2) { animation-delay: -0.16s; }
@keyframes m-ai-bounce {
  0%, 80%, 100% { transform: scale(0); opacity: 0.4; }
  40% { transform: scale(1); opacity: 1; }
}

/* Pasek wpisywania (Footer) */
.m-ai-footer {
  padding: 12px 14px;
  background: rgba(11, 15, 25, 0.85);
  border-top: 1px solid var(--m-ai-border);
}
.m-ai-input-form {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 14px;
  padding: 4px 6px 4px 14px;
  transition: border-color 0.2s;
}
.m-ai-input-form:focus-within {
  border-color: rgba(234, 0, 27, 0.6);
  box-shadow: 0 0 10px rgba(234, 0, 27, 0.2);
}
.m-ai-input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: #fff;
  font-size: 0.9rem;
  font-family: inherit;
  resize: none;
  height: 24px;
  max-height: 80px;
  line-height: 24px;
}
.m-ai-input::placeholder {
  color: #64748b;
}
.m-ai-btn-send {
  background: #ea001b;
  border: none;
  color: #fff;
  width: 34px;
  height: 34px;
  border-radius: 10px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  flex-shrink: 0;
}
.m-ai-btn-send:hover:not(:disabled) {
  background: #ff1f38;
  transform: scale(1.05);
}
.m-ai-btn-send:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.m-ai-disclaimer {
  font-size: 0.68rem;
  color: #64748b;
  text-align: center;
  margin-top: 6px;
}

/* Mobile Responsive */
@media (max-width: 640px) {
  .m-ai-chat-window {
    bottom: 0;
    right: 0;
    width: 100vw;
    height: 100vh;
    max-width: 100vw;
    max-height: 100vh;
    border-radius: 0;
  }
  .m-ai-fab {
    bottom: 16px;
    right: 16px;
  }
}

/* ========================================================
   Action Cards (Interactive MerMiko Widgets)
   ======================================================== */
.m-ai-action-card {
  margin-top: 10px;
  background: rgba(15, 23, 42, 0.95);
  border: 1px solid rgba(56, 189, 248, 0.35);
  border-radius: 14px;
  padding: 12px 14px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}
.m-ai-action-header {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 0.85rem;
  color: #38bdf8;
  margin-bottom: 10px;
  padding-bottom: 6px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}
.m-ai-action-row {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-bottom: 8px;
  font-size: 0.78rem;
}
.m-ai-action-label {
  color: #94a3b8;
  font-size: 0.68rem;
  text-transform: uppercase;
}
.m-ai-action-val {
  color: #f1f5f9;
  word-break: break-all;
  font-weight: 600;
}
.m-ai-og-preview {
  margin: 8px 0;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 10px;
  overflow: hidden;
}
.m-ai-og-img {
  width: 100%;
  height: 120px;
  object-fit: cover;
  display: block;
}
.m-ai-og-info {
  padding: 8px 10px;
}
.m-ai-og-title {
  font-size: 0.82rem;
  font-weight: 700;
  color: #fff;
  margin-bottom: 2px;
}
.m-ai-og-desc {
  font-size: 0.72rem;
  color: #94a3b8;
  line-height: 1.3;
}
.m-ai-action-buttons {
  display: flex;
  gap: 8px;
  margin-top: 10px;
  flex-wrap: wrap;
}
.m-ai-btn-confirm {
  flex: 1.5;
  background: linear-gradient(135deg, #0284c7, #38bdf8);
  border: none;
  color: #fff;
  font-weight: 700;
  font-size: 0.78rem;
  padding: 8px 12px;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
.m-ai-btn-confirm:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 4px 14px rgba(56, 189, 248, 0.4);
}
.m-ai-btn-confirm:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}
.m-ai-btn-cancel {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: #94a3b8;
  font-weight: 600;
  font-size: 0.75rem;
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s;
}
.m-ai-btn-cancel:hover {
  color: #fff;
  background: rgba(255, 255, 255, 0.12);
}
.m-ai-telemetry-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin-top: 8px;
}
.m-ai-telemetry-pill {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  padding: 6px 8px;
}
.m-ai-telemetry-label {
  font-size: 0.65rem;
  color: #94a3b8;
  text-transform: uppercase;
}
.m-ai-telemetry-val {
  font-size: 0.76rem;
  font-weight: 700;
  color: #fff;
  font-family: 'JetBrains Mono', monospace;
}
.m-ai-qr-canvas-wrap {
  background: #fff;
  padding: 8px;
  border-radius: 10px;
  display: inline-block;
  margin: 6px 0;
}
.m-ai-qr-img {
  display: block;
  width: 175px;
  height: 175px;
  margin: 10px auto;
  border-radius: 12px;
  background: #ffffff;
  padding: 10px;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.55), 0 0 15px rgba(56, 189, 248, 0.2);
  border: 1px solid rgba(255, 255, 255, 0.15);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}
.m-ai-qr-img:hover {
  transform: scale(1.03);
  box-shadow: 0 12px 30px rgba(56, 189, 248, 0.4);
}
.m-ai-qr-preview-box {
  background: rgba(0, 0, 0, 0.3);
  border: 1px dashed rgba(255, 255, 255, 0.15);
  border-radius: 12px;
  padding: 12px;
  text-align: center;
  margin: 8px 0;
}

/* Interaktywne GUI Aliasu w karcie */
.m-ai-slug-section {
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 10px;
  padding: 10px;
  margin: 8px 0;
}
.m-ai-slug-input-wrap {
  display: flex;
  align-items: center;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  overflow: hidden;
  margin-top: 4px;
}
.m-ai-slug-prefix {
  font-size: 0.72rem;
  color: #64748b;
  font-family: 'JetBrains Mono', monospace;
  padding: 6px 0 6px 10px;
  user-select: none;
}
.m-ai-slug-input {
  flex: 1;
  background: transparent;
  border: none;
  color: #38bdf8;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.8rem;
  font-weight: 700;
  padding: 6px 8px;
  outline: none;
  min-width: 60px;
}
.m-ai-btn-check-slug {
  background: rgba(56, 189, 248, 0.15);
  border: none;
  border-left: 1px solid rgba(56, 189, 248, 0.3);
  color: #38bdf8;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 6px 10px;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}
.m-ai-btn-check-slug:hover {
  background: rgba(56, 189, 248, 0.3);
  color: #fff;
}
.m-ai-slug-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 5px;
}
.m-ai-slug-chip {
  background: rgba(56, 189, 248, 0.1);
  border: 1px dashed rgba(56, 189, 248, 0.4);
  color: #7dd3fc;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s;
}
.m-ai-slug-chip:hover {
  background: rgba(56, 189, 248, 0.25);
  border-color: #38bdf8;
  color: #fff;
  transform: translateY(-1px);
}


