/* ============================================
   MADI ENGINE — chat widget
   v1.0 — Marcin Wenz / Madimo
   Vanilla CSS, brand: carryhandle.store orange
   ============================================ */

:root {
  --madi-orange: #FF6B35;
  --madi-orange-dark: #E55A2B;
  --madi-bg: #ffffff;
  --madi-text: #1a1a1a;
  --madi-text-soft: #6b6b6b;
  --madi-border: #e8e8e8;
  --madi-bot-bg: #f5f5f7;
  --madi-user-bg: #FF6B35;
  --madi-user-text: #ffffff;
  --madi-shadow: 0 8px 32px rgba(0,0,0,0.12);
  --madi-shadow-lg: 0 16px 48px rgba(0,0,0,0.18);
  --madi-radius: 16px;
  --madi-font: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
}

/* === FLOATING BUTTON === */
.madi-fab {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: var(--madi-orange);
  color: white;
  border: none;
  cursor: pointer;
  box-shadow: var(--madi-shadow);
  z-index: 9998;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--madi-font);
  font-weight: 700;
  font-size: 22px;
  transition: transform 0.25s ease, box-shadow 0.25s ease;
  animation: madiPulse 2.4s ease-in-out 1.2s 3;
}

.madi-fab:hover {
  transform: scale(1.08);
  box-shadow: var(--madi-shadow-lg);
  background: var(--madi-orange-dark);
}

.madi-fab:active {
  transform: scale(0.95);
}

.madi-fab.is-open {
  transform: rotate(45deg);
  background: var(--madi-text);
}

.madi-fab-icon {
  display: block;
  line-height: 1;
}

.madi-fab-pulse-ring {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 2px solid var(--madi-orange);
  opacity: 0;
  animation: madiRing 2.4s ease-out 1.2s 3;
}

@keyframes madiPulse {
  0%, 100% { box-shadow: 0 8px 32px rgba(255,107,53,0.4); }
  50% { box-shadow: 0 8px 48px rgba(255,107,53,0.7); }
}

@keyframes madiRing {
  0% { opacity: 1; transform: scale(1); }
  100% { opacity: 0; transform: scale(1.6); }
}

/* === LABEL OBOK FAB === */
.madi-fab-label {
  position: fixed;
  bottom: 38px;
  right: 96px;
  background: var(--madi-text);
  color: white;
  padding: 8px 14px;
  border-radius: 20px;
  font-family: var(--madi-font);
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  z-index: 9997;
  box-shadow: var(--madi-shadow);
  opacity: 0;
  transform: translateX(8px);
  transition: opacity 0.3s ease, transform 0.3s ease;
  pointer-events: none;
}

.madi-fab-label.show {
  opacity: 1;
  transform: translateX(0);
}

body.has-cookie-banner .madi-fab {
  display: none;
}

body.has-cookie-banner .madi-fab-label {
  display: none;
}

.madi-fab-label::after {
  content: '';
  position: absolute;
  right: -6px;
  top: 50%;
  transform: translateY(-50%);
  width: 0;
  height: 0;
  border-top: 6px solid transparent;
  border-bottom: 6px solid transparent;
  border-left: 6px solid var(--madi-text);
}

/* === CHAT WINDOW === */
.madi-window {
  position: fixed;
  bottom: 100px;
  right: 24px;
  width: 380px;
  max-width: calc(100vw - 32px);
  height: 600px;
  max-height: calc(100vh - 140px);
  background: var(--madi-bg);
  border-radius: var(--madi-radius);
  box-shadow: var(--madi-shadow-lg);
  z-index: 9999;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  font-family: var(--madi-font);
  opacity: 0;
  transform: translateY(20px) scale(0.96);
  transition: opacity 0.28s ease, transform 0.28s ease;
  pointer-events: none;
}

.madi-window.is-open {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

/* === HEADER === */
.madi-header {
  background: linear-gradient(135deg, var(--madi-orange) 0%, var(--madi-orange-dark) 100%);
  color: white;
  padding: 20px 22px 18px;
  display: flex;
  align-items: center;
  gap: 14px;
  flex-shrink: 0;
}

.madi-avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: white;
  color: var(--madi-orange);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 20px;
  flex-shrink: 0;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  position: relative;
}

.madi-avatar::after {
  content: '';
  position: absolute;
  bottom: 0;
  right: 0;
  width: 12px;
  height: 12px;
  background: #4ade80;
  border: 2px solid white;
  border-radius: 50%;
}

.madi-header-text { flex: 1; min-width: 0; }
.madi-header-name { font-weight: 700; font-size: 16px; margin: 0 0 2px; }
.madi-header-status { font-size: 12px; opacity: 0.95; margin: 0; }

.madi-close {
  background: rgba(255,255,255,0.2);
  border: none;
  color: white;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
  flex-shrink: 0;
}
.madi-close:hover { background: rgba(255,255,255,0.32); }

/* === MESSAGES === */
.madi-messages {
  flex: 1;
  overflow-y: auto;
  padding: 18px 18px 8px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: #fafafa;
  scroll-behavior: smooth;
}

.madi-msg {
  max-width: 86%;
  padding: 11px 15px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.5;
  word-wrap: break-word;
  animation: madiMsgIn 0.3s ease;
}

@keyframes madiMsgIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.madi-msg.bot {
  background: var(--madi-bot-bg);
  color: var(--madi-text);
  align-self: flex-start;
  border-bottom-left-radius: 4px;
}

.madi-msg.user {
  background: var(--madi-user-bg);
  color: var(--madi-user-text);
  align-self: flex-end;
  border-bottom-right-radius: 4px;
}

/* === TYPING DOTS === */
.madi-typing {
  align-self: flex-start;
  background: var(--madi-bot-bg);
  padding: 14px 18px;
  border-radius: 16px;
  border-bottom-left-radius: 4px;
  display: flex;
  gap: 5px;
}

.madi-typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--madi-text-soft);
  animation: madiTyping 1.2s infinite ease-in-out;
}
.madi-typing span:nth-child(2) { animation-delay: 0.15s; }
.madi-typing span:nth-child(3) { animation-delay: 0.3s; }

@keyframes madiTyping {
  0%, 60%, 100% { opacity: 0.3; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-4px); }
}

/* === PRICE BADGE (when tool call hits) === */
.madi-price-badge {
  background: linear-gradient(135deg, #FFF3ED 0%, #FFE0CC 100%);
  border: 1px solid var(--madi-orange);
  border-radius: 12px;
  padding: 12px 14px;
  margin-top: 6px;
  align-self: flex-start;
  max-width: 86%;
  font-size: 13px;
}
.madi-price-badge .label { color: var(--madi-text-soft); font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 4px; }
.madi-price-badge .value { font-size: 18px; font-weight: 800; color: var(--madi-orange-dark); }
.madi-price-badge .meta { font-size: 11px; color: var(--madi-text-soft); margin-top: 4px; }

/* === INPUT === */
.madi-input-area {
  border-top: 1px solid var(--madi-border);
  background: white;
  padding: 12px 14px 14px;
  flex-shrink: 0;
}

.madi-input-row {
  display: flex;
  gap: 8px;
  align-items: flex-end;
}

.madi-input {
  flex: 1;
  border: 1px solid var(--madi-border);
  border-radius: 22px;
  padding: 10px 16px;
  font-size: 14px;
  font-family: var(--madi-font);
  outline: none;
  resize: none;
  max-height: 100px;
  min-height: 40px;
  transition: border-color 0.2s;
  line-height: 1.4;
}

.madi-input:focus {
  border-color: var(--madi-orange);
}

.madi-send {
  background: var(--madi-orange);
  color: white;
  border: none;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
  transition: background 0.2s, transform 0.2s;
}

.madi-send:hover { background: var(--madi-orange-dark); }
.madi-send:active { transform: scale(0.92); }
.madi-send:disabled { background: #cccccc; cursor: not-allowed; }

.madi-footer {
  text-align: center;
  font-size: 10px;
  color: var(--madi-text-soft);
  margin-top: 8px;
  letter-spacing: 0.3px;
}

.madi-footer strong { color: var(--madi-orange); font-weight: 700; }

/* === MOBILE === */
@media (max-width: 480px) {
  .madi-window {
    bottom: 0;
    right: 0;
    left: 0;
    width: 100%;
    max-width: 100%;
    height: 100%;
    max-height: 100%;
    border-radius: 0;
  }
  .madi-fab {
    bottom: 16px;
    right: 16px;
    width: 48px;
    height: 48px;
  }
  .madi-fab-icon svg {
    width: 22px;
    height: 22px;
  }
  .madi-fab-label {
    bottom: 30px;
    right: 88px;
    font-size: 12px;
  }
  body.has-cookie-banner .madi-fab {
    display: none;
  }
  body.has-cookie-banner .madi-fab-label {
    display: none;
  }
}
