/* ═══════════════════════════════════════════════════════════════════════
   KINETIC ISLAND — Awwwards-tier Chatbot Interface
   Design: Kinetic Pill trigger, high-fidelity glass, command-bar input
   ═══════════════════════════════════════════════════════════════════════ */

:root {
  --cw-glass: rgba(10, 10, 10, 0.75);
  --cw-border: rgba(255, 255, 255, 0.08);
  --cw-accent: #e8a045;
  --cw-accent-muted: rgba(232, 160, 69, 0.15);
  --cw-text: #f0ede8;
  --cw-text-muted: #8a8680;
  --cw-font-sans: 'Inter', system-ui, sans-serif;
  --cw-font-mono: 'JetBrains Mono', monospace;
  --cw-blur: blur(40px);
}

/* ── Kinetic Pill Trigger ───────────────── */
#chat-trigger {
  position: fixed;
  bottom: 32px;
  right: 32px;
  z-index: 9998;
  height: 42px;
  padding: 0 16px 0 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  background: #000;
  border: 1px solid var(--cw-border);
  border-radius: 100px;
  cursor: pointer;
  transition: all 0.4s var(--ease-out);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.4);
}

#chat-trigger:hover {
  transform: translateY(-2px);
  border-color: var(--cw-accent-muted);
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.6);
}

.trigger-status {
  position: relative;
  width: 18px;
  height: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.orbital-ring {
  position: absolute;
  inset: 0;
  border: 1px dashed var(--cw-accent-muted);
  border-radius: 50%;
  animation: cw-rotate 8s linear infinite;
  opacity: 0.6;
}

#chat-trigger.active .orbital-ring {
  animation-duration: 2s;
  border-color: var(--cw-accent);
}

@keyframes cw-rotate {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

.trigger-core {
  width: 5px;
  height: 5px;
  background: var(--cw-accent);
  border-radius: 50%;
  box-shadow: 0 0 10px var(--cw-accent);
}

.trigger-label {
  font-family: var(--cw-font-mono);
  font-size: 0.68rem;
  font-weight: 500;
  color: var(--cw-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.12em;
  transition: color 0.3s;
}

#chat-trigger:hover .trigger-label {
  color: var(--cw-text);
}

.trigger-close {
  display: none;
  font-size: 1.1rem;
  color: var(--cw-text);
  line-height: 1;
}

#chat-trigger.active .trigger-core,
#chat-trigger.active .trigger-label {
  display: none;
}

#chat-trigger.active .trigger-close {
  display: block;
}

/* ── Kinetic Modal (Refined) ────────── */
#chat-modal {
  position: fixed;
  bottom: 90px;
  right: 32px;
  z-index: 9999;
  width: 400px;
  height: 640px;
  max-height: calc(100vh - 140px);
  display: flex;
  flex-direction: column;
  border-radius: 20px;
  overflow: hidden;
  background: var(--cw-glass);
  backdrop-filter: var(--cw-blur);
  -webkit-backdrop-filter: var(--cw-blur);
  border: 1px solid var(--cw-border);
  box-shadow: 0 40px 100px rgba(0, 0, 0, 0.8);
  
  opacity: 0;
  visibility: hidden;
  transform: translateY(20px) scale(0.98);
  transition: all 0.5s cubic-bezier(0.16, 1, 0.3, 1);
  transform-origin: bottom right;
}

/* Texture Overlay */
#chat-modal::before {
  content: '';
  position: absolute;
  inset: 0;
  z-index: 0;
  opacity: 0.04;
  pointer-events: none;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.65' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)'/%3E%3C/svg%3E");
}

#chat-modal.open {
  opacity: 1;
  visibility: visible;
  transform: translateY(0) scale(1);
}

/* ── Split Header ──────────────────── */
.cw-header {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 24px 24px 16px;
  border-bottom: 1px solid var(--cw-border);
}

.cw-header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.cw-avatar {
  width: 32px;
  height: 32px;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--cw-border);
  background: #000;
}

.cw-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.cw-header-info h4 {
  font-family: var(--cw-font-sans);
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--cw-text);
  margin: 0;
  letter-spacing: -0.01em;
}

.cw-header-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
}

.cw-telemetry {
  font-family: var(--cw-font-mono);
  font-size: 0.6rem;
  color: var(--cw-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

.cw-status {
  display: flex;
  align-items: center;
  gap: 5px;
  font-family: var(--cw-font-mono);
  font-size: 0.55rem;
  color: var(--color-success);
}

.cw-status-dot {
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--color-success);
  box-shadow: 0 0 8px var(--color-success);
}

/* ── Messages Area ─────────────────── */
.cw-messages {
  position: relative;
  z-index: 1;
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  scrollbar-width: none;
}

.cw-messages::-webkit-scrollbar { display: none; }

.cw-welcome {
  margin-bottom: 24px;
}

.cw-welcome h2 {
  font-family: var(--cw-font-sans);
  font-size: 2rem;
  font-weight: 800;
  color: var(--cw-text);
  letter-spacing: -0.04em;
  line-height: 0.9;
  margin-bottom: 12px;
}

.cw-welcome p {
  font-family: var(--cw-font-sans);
  font-size: 0.9rem;
  color: var(--cw-text-muted);
  line-height: 1.5;
  max-width: 280px;
}

.cw-msg {
  max-width: 90%;
  font-family: var(--cw-font-sans);
  font-size: 0.9rem;
  line-height: 1.6;
  animation: cw-reveal 0.4s var(--ease-out) both;
}

@keyframes cw-reveal {
  from { 
    opacity: 0; 
    transform: translateY(10px);
    filter: blur(4px);
  }
  to { 
    opacity: 1; 
    transform: translateY(0);
    filter: blur(0);
  }
}

.cw-msg.assistant {
  align-self: flex-start;
  max-width: 92%;
  color: var(--cw-text);
  border-left: 1px solid var(--cw-accent-muted);
  padding: 4px 0 12px 20px;
  background: transparent;
  margin-bottom: 8px;
}

.cw-msg.user {
  align-self: flex-end;
  max-width: 80%;
  background: rgba(255, 255, 255, 0.03);
  color: var(--cw-text);
  padding: 10px 16px;
  border-radius: 12px 12px 2px 12px;
  font-size: 0.85rem;
  border: 1px solid var(--cw-border);
  margin-bottom: 12px;
}

.cw-msg.typing {
  font-family: var(--cw-font-mono);
  font-size: 0.65rem;
  color: var(--cw-accent);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  border: none;
  padding: 0 0 0 20px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.cw-msg.typing::after {
  content: '';
  width: 4px;
  height: 4px;
  background: var(--cw-accent);
  border-radius: 50%;
  animation: cw-pulse-typing 1s infinite;
}

@keyframes cw-pulse-typing {
  0% { opacity: 0.2; transform: scale(0.8); }
  50% { opacity: 1; transform: scale(1.1); }
  100% { opacity: 0.2; transform: scale(0.8); }
}

.cw-msg code {
  font-family: var(--cw-font-mono);
  font-size: 0.8em;
  background: rgba(255, 255, 255, 0.05);
  padding: 2px 6px;
  border-radius: 4px;
  color: var(--cw-accent);
}

/* ── Command Bar ───────────────────── */
.cw-input-area {
  position: relative;
  z-index: 1;
  padding: 16px 24px 24px;
}

.cw-command-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--cw-border);
  border-radius: 14px;
  padding: 4px 6px 4px 16px;
  transition: all 0.3s var(--ease-out);
}

.cw-command-bar:focus-within {
  background: rgba(255, 255, 255, 0.05);
  border-color: var(--cw-accent-muted);
  box-shadow: 0 0 20px rgba(0, 0, 0, 0.2);
}

.cw-prefix {
  font-family: var(--cw-font-mono);
  font-size: 0.75rem;
  color: var(--cw-accent);
  opacity: 0.6;
}

.cw-input-area textarea {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--cw-text);
  font-family: var(--cw-font-sans);
  font-size: 0.85rem;
  padding: 10px 0;
  resize: none;
  max-height: 100px;
}

.cw-input-area textarea::placeholder {
  color: var(--color-text-tertiary);
}

.cw-send-btn {
  width: 32px;
  height: 32px;
  border-radius: 10px;
  border: none;
  background: var(--cw-accent);
  color: #000;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s;
  opacity: 0.5;
}

.cw-send-btn:not(:disabled) {
  opacity: 1;
}

.cw-send-btn:not(:disabled):hover {
  transform: scale(1.05);
  box-shadow: 0 0 15px var(--cw-accent-muted);
}

.cw-send-btn svg {
  width: 16px;
  height: 16px;
  fill: currentColor;
}

/* ── Suggestions ───────────────────── */
.cw-suggestions {
  position: relative;
  z-index: 1;
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 0 24px 16px;
  scrollbar-width: none;
}

.cw-suggestions::-webkit-scrollbar { display: none; }

.cw-suggestion {
  flex-shrink: 0;
  padding: 6px 12px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--cw-border);
  color: var(--cw-text-muted);
  font-family: var(--cw-font-sans);
  font-size: 0.7rem;
  cursor: pointer;
  transition: all 0.2s;
}

.cw-suggestion:hover {
  background: var(--cw-accent-muted);
  border-color: var(--cw-accent-muted);
  color: var(--cw-accent);
}

/* ── Mobile ────────────────────────── */
@media (max-width: 500px) {
  #chat-modal {
    width: 100%;
    height: 100%;
    max-height: none;
    bottom: 0;
    right: 0;
    border-radius: 0;
    border: none;
  }
  
  #chat-trigger {
    bottom: 20px;
    right: 20px;
  }
}
