:root {
  /* Brand Palette Inference */
  --z1l-brand-orange: #fea500; /* Adjusted to a more golden/yellow orange based on typical "Zero1" branding */
  --z1l-brand-black: #050505;
  --z1l-dark-gray: #1a1a1a;
  
  /* Widget Vars */
  --z1l-bg-dark: var(--z1l-brand-black);
  --z1l-panel-bg: rgba(20, 20, 20, 0.85); /* Glassmorphism base */
  --z1l-panel-backdrop: blur(16px);
  --z1l-border: rgba(255, 255, 255, 0.1);
  --z1l-text-main: #ffffff;
  --z1l-text-dim: #999999;
  --z1l-accent: var(--z1l-brand-orange);
  --z1l-accent-glow: rgba(254, 165, 0, 0.3);
  
  --z1l-msg-user-bg: var(--z1l-accent);
  --z1l-msg-user-text: #000000; /* High contrast on orange */
  --z1l-msg-bot-bg: rgba(255, 255, 255, 0.08);
  
  --z1l-shadow: 0 12px 40px rgba(0, 0, 0, 0.6);
  --z1l-font: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --z1l-radius: 20px; /* More rounded, modern */
  --z1l-radius-sm: 12px;
}

#z1l-chat-wrapper * {
  box-sizing: border-box;
  font-family: var(--z1l-font);
}

/* Floating Button */
#z1l-chat-trigger {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 64px;
  height: 64px;
  background-color: var(--z1l-dark-gray);
  border: 1px solid var(--z1l-border);
  border-radius: 50%;
  box-shadow: 0 8px 24px rgba(0,0,0,0.5);
  cursor: pointer;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
  color: var(--z1l-accent);
  overflow: hidden;
}

/* Hover effect for button */
#z1l-chat-trigger::before {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at center, var(--z1l-accent-glow) 0%, transparent 70%);
  opacity: 0;
  transition: opacity 0.3s ease;
}

#z1l-chat-trigger:hover {
  transform: scale(1.05) translateY(-2px);
  border-color: var(--z1l-accent);
  box-shadow: 0 12px 32px rgba(254, 165, 0, 0.2);
}

#z1l-chat-trigger:hover::before {
  opacity: 1;
}

#z1l-chat-trigger svg {
  width: 28px;
  height: 28px;
  fill: currentColor;
  position: relative;
  z-index: 2;
}

/* Main Panel */
#z1l-chat-panel {
  position: fixed;
  bottom: 100px;
  right: 24px;
  width: 380px;
  max-width: 90vw;
  height: 600px;
  max-height: 80vh;
  
  background-color: var(--z1l-panel-bg);
  backdrop-filter: var(--z1l-panel-backdrop);
  -webkit-backdrop-filter: var(--z1l-panel-backdrop);
  
  border: 1px solid var(--z1l-border);
  border-radius: var(--z1l-radius);
  box-shadow: var(--z1l-shadow);
  
  display: flex;
  flex-direction: column;
  z-index: 9999;
  
  opacity: 0;
  transform: translateY(20px) scale(0.96);
  pointer-events: none;
  transform-origin: bottom right;
  transition: opacity 0.4s cubic-bezier(0.16, 1, 0.3, 1), transform 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

#z1l-chat-panel.z1l-open {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

/* Header */
.z1l-header {
  padding: 20px 24px;
  border-bottom: 1px solid var(--z1l-border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: rgba(255,255,255,0.02);
  border-top-left-radius: var(--z1l-radius);
  border-top-right-radius: var(--z1l-radius);
}

.z1l-titles h3 {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
  color: var(--z1l-text-main);
  letter-spacing: -0.02em;
}

.z1l-titles p {
  margin: 4px 0 0;
  font-size: 13px;
  color: var(--z1l-text-dim);
  font-weight: 400;
}

.z1l-close-btn {
  background: rgba(255,255,255,0.05);
  border: none;
  border-radius: 50%;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--z1l-text-dim);
  cursor: pointer;
  transition: all 0.2s;
}

.z1l-close-btn:hover {
  background: rgba(255,255,255,0.1);
  color: var(--z1l-text-main);
}

/* Messages Area */
.z1l-messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,0.1) transparent;
}

.z1l-messages::-webkit-scrollbar {
  width: 4px;
}
.z1l-messages::-webkit-scrollbar-thumb {
  background-color: rgba(255,255,255,0.2);
  border-radius: 4px;
}

.z1l-msg {
  max-width: 85%;
  padding: 12px 16px;
  border-radius: var(--z1l-radius-sm);
  font-size: 15px;
  line-height: 1.5;
  word-wrap: break-word;
  animation: bg-slide-up 0.4s cubic-bezier(0.16, 1, 0.3, 1);
  position: relative;
}

@keyframes bg-slide-up {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.z1l-msg.z1l-bot {
  align-self: flex-start;
  background-color: var(--z1l-msg-bot-bg);
  color: #eee;
  border-bottom-left-radius: 2px;
  border: 1px solid rgba(255,255,255,0.05);
}

.z1l-msg.z1l-user {
  align-self: flex-end;
  background-color: var(--z1l-msg-user-bg);
  color: var(--z1l-msg-user-text);
  border-bottom-right-radius: 2px;
  font-weight: 500;
  box-shadow: 0 2px 8px rgba(254, 165, 0, 0.2);
}

.z1l-msg-error {
  align-self: center;
  font-size: 12px;
  color: #ff5555;
  background: rgba(255, 85, 85, 0.1);
  padding: 4px 10px;
  border-radius: 12px;
  margin-top: 8px;
}

/* Typing Indicator */
.z1l-typing {
  align-self: flex-start;
  display: flex;
  gap: 4px;
  padding: 14px 16px;
  background-color: var(--z1l-msg-bot-bg);
  border-radius: var(--z1l-radius-sm);
  border-bottom-left-radius: 2px;
  width: fit-content;
  align-items: center;
}

.z1l-dot {
  width: 5px;
  height: 5px;
  background-color: #888;
  border-radius: 50%;
  animation: z1l-fade 1.2s infinite ease-in-out both;
}

.z1l-dot:nth-child(1) { animation-delay: -0.32s; }
.z1l-dot:nth-child(2) { animation-delay: -0.16s; }

@keyframes z1l-fade {
  0%, 100% { opacity: 0.3; }
  50% { opacity: 1; }
}

/* Footer & Input */
.z1l-footer {
  padding: 16px 24px 24px; /* More padding at bottom */
  border-top: 1px solid var(--z1l-border);
  display: flex;
  gap: 12px;
  background: transparent;
  align-items: flex-end;
}

.z1l-input-wrapper {
  flex: 1;
  background-color: rgba(0,0,0,0.3);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 24px;
  overflow: hidden; /* This effectively clips content, except scrollbars sometimes sit on top. Padding is safer. */
  padding: 12px 0; /* Vertical padding here creates space for textarea scrollbar to NOT hit the top/bottom radius */
  display: flex;
  transition: border-color 0.2s, box-shadow 0.2s;
  min-height: 48px;
}

.z1l-input-wrapper:focus-within {
  border-color: var(--z1l-accent);
  background-color: rgba(0,0,0,0.5);
  box-shadow: 0 0 0 1px var(--z1l-accent-glow);
}

.z1l-input {
  width: 100%;
  background-color: transparent;
  border: none;
  color: var(--z1l-text-main);
  padding: 0 16px; /* Horizontal padding only */
  font-size: 15px;
  line-height: 1.4;
  height: auto;
  min-height: 24px; /* Reduced min height as wrapper handles the visual height */
  max-height: 104px; /* Limit height */
  outline: none;
  resize: none;
  overflow-y: auto;
  display: block;
  margin: 0;
  
  /* Custom scrollbar */
  scrollbar-width: thin;
  scrollbar-color: rgba(255,165,0,0.3) transparent;
}

.z1l-input:focus {
  background-color: transparent; /* Override global textarea:focus styles */
  box-shadow: none; /* Override global styles if any */
}

/* Chrome/Safari Scrollbar for input */
.z1l-input::-webkit-scrollbar {
  width: 4px; /* Keep it thin */
}
.z1l-input::-webkit-scrollbar-thumb {
  background-color: rgba(255,255,255,0.15);
  border-radius: 4px;
}
.z1l-input::-webkit-scrollbar-thumb:hover {
  background-color: rgba(255,165,0,0.5);
}
.z1l-input::-webkit-scrollbar-track {
  background: transparent;
  margin: 0; /* No margin needed as wrapper padding handles offset */
}

.z1l-send-btn {
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: var(--z1l-accent);
  color: var(--z1l-brand-black);
  border: none;
  border-radius: 50%;
  cursor: pointer;
  transition: transform 0.2s, background-color 0.2s;
  flex-shrink: 0;
}

.z1l-send-btn:hover {
  background-color: #ffb833; /* Slightly lighter orange */
  transform: scale(1.05);
}

.z1l-send-btn:active {
  transform: scale(0.95);
}

.z1l-send-btn svg {
  width: 20px;
  height: 20px;
  fill: currentColor;
  transform: translateX(2px); /* Optically center the send icon */
}

/* Responsive */
/* Responsive */
@media (max-width: 768px) {
  /* Lock background scroll when chat is open */
  body.z1l-chat-open {
    overflow: hidden;
    touch-action: none; /* Helps prevent scroll chaining on some devices */
  }

  #z1l-chat-panel {
    bottom: 0;
    right: 0;
    width: 100%;
    max-width: 100%;
    height: 100%; /* Fallback */
    height: 100dvh; /* Modern dynamic viewport height */
    max-height: 100dvh;
    border-radius: 0;
    transform: translateY(100%); /* Start from bottom for mobile slide-up */
  }
  
  #z1l-chat-panel.z1l-open {
    transform: translateY(0);
  }
  
  .z1l-close-btn {
    display: flex; /* Ensure visible on mobile */
    background: rgba(255,255,255,0.1); /* Explicit bg for better visibility */
  }

  /* Prevent iOS zoom on focus by enforcing 16px font size */
  .z1l-input {
    font-size: 16px !important;
  }

  /* Make header slightly taller for touch targets */
  .z1l-header {
    padding: 16px 20px;
  }

  #z1l-chat-trigger {
    bottom: 20px;
    right: 20px;
    /* Optional: hide trigger when chat is open on mobile if desired, 
       but standard behavior is panel covers it anyway */
  }
}
