:root {
  --codex-primary: #4f46e5;
  --codex-gradient: linear-gradient(135deg, #6366f1, #8b5cf6);
  --codex-font-size: 14px;
  --codex-text: #0f172a;
  --codex-panel: #ffffff;
  --codex-border: #e5e7eb;
  --codex-muted: #6b7280;
  --codex-surface: #f8fafc;
}

:root.codex-dark {
  --codex-panel: #0f172a;
  --codex-text: #e5e7f0;
  --codex-border: #1f2937;
  --codex-muted: #9ca3af;
  --codex-surface: #0b1220;
}

#codex-ai-panel, #codex-ai-panel * {
  box-sizing: border-box;
  font-family: "Inter", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

#codex-ai-launcher {
  position: fixed;
  bottom: 18px;
  right: 18px;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  background-image: var(--codex-gradient);
  color: #fff;
  border: none;
  padding: 14px 18px;
  border-radius: 999px;
  box-shadow: 0 12px 26px rgba(0,0,0,0.2);
  cursor: pointer;
  font-size: var(--codex-font-size);
  z-index: 9999;
}
#codex-ai-launcher .codex-launcher__icon {
  background: rgba(255,255,255,0.18);
  width: 28px; height: 28px;
  border-radius: 50%;
  display: grid; place-items: center;
}
#codex-ai-launcher.codex-left { left: 18px; right: auto; }

#codex-ai-panel {
  position: fixed;
  bottom: 76px;
  right: 18px;
  width: min(420px, calc(100vw - 36px));
  max-height: 82vh;
  background: var(--codex-panel);
  color: var(--codex-text);
  border-radius: 18px;
  box-shadow: 0 18px 44px rgba(0,0,0,0.22);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  pointer-events: none;
  transform: translateY(12px);
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 9999;
}
#codex-ai-panel.codex-open {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}
#codex-ai-panel.codex-left { left: 18px; right: auto; }

.codex-ai-header {
  background: var(--codex-gradient);
  color: #fff;
  padding: 12px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.codex-ai-identity { display: flex; align-items: center; gap: 10px; }
.codex-avatar { width: 38px; height: 38px; border-radius: 12px; background: rgba(255,255,255,0.25); background-size: cover; background-position: center; }
.codex-status { font-size: 12px; opacity: 0.9; }
.codex-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: #22c55e; margin-right: 4px; }
.codex-ai-header button {
  width: 32px; height: 32px;
  border-radius: 10px;
  border: none;
  background: rgba(255,255,255,0.18);
  color: #fff;
  cursor: pointer;
  font-size: 18px;
}

.codex-ai-welcome { padding: 12px 16px 8px; }
.codex-eyebrow { text-transform: uppercase; letter-spacing: 0.1em; font-size: 11px; color: var(--codex-muted); }
.codex-lead { font-weight: 700; margin: 4px 0; font-size: 18px; }
.codex-pill { display: inline-flex; align-items: center; gap: 6px; padding: 6px 10px; background: rgba(99,102,241,0.12); color: var(--codex-primary); border-radius: 999px; font-size: 12px; }

.codex-prechat {
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: var(--codex-surface);
}
.codex-prechat__title { font-weight: 700; margin-bottom: 2px; }
.codex-grid-2 { display: grid; grid-template-columns: repeat(auto-fit,minmax(150px,1fr)); gap: 10px; }
.codex-prechat input,
.codex-prechat select,
.codex-prechat textarea {
  width: 100%;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--codex-border);
  background: #fff;
  font-size: 14px;
}
:root.codex-dark .codex-prechat input,
:root.codex-dark .codex-prechat select,
:root.codex-dark .codex-prechat textarea { background: #111827; color: var(--codex-text); }
.codex-prechat select {
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, #4b5563 50%), linear-gradient(135deg, #4b5563 50%, transparent 50%);
  background-position: calc(100% - 18px) 50%, calc(100% - 12px) 50%;
  background-size: 6px 6px, 6px 6px;
  background-repeat: no-repeat;
}
.codex-file {
  display: flex;
  align-items: center;
  gap: 10px;
  background: #fff;
  border: 1px dashed var(--codex-border);
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 13px;
}
.codex-file input { width: auto; }
.codex-meta { font-size: 12px; color: var(--codex-muted); }
.codex-prechat .solid.full {
  width: 100%;
  padding: 12px;
  border-radius: 12px;
  border: none;
  font-weight: 700;
  background: var(--codex-gradient);
  color: #fff;
  cursor: pointer;
  font-size: 15px;
  box-shadow: 0 8px 20px rgba(79,70,229,0.25);
}

#codex-ai-messages {
  flex: 1;
  padding: 10px 16px 12px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: #fff;
}
.codex-ai-bubble {
  padding: 12px 14px;
  border-radius: 14px;
  background: rgba(0,0,0,0.04);
  box-shadow: 0 10px 24px rgba(0,0,0,0.06);
  max-width: 85%;
  line-height: 1.5;
  word-break: break-word;
}
.codex-user { align-self: flex-end; background: var(--codex-gradient); color: #fff; }
.codex-assistant { align-self: flex-start; background: rgba(0,0,0,0.04); color: var(--codex-text); }
:root.codex-dark .codex-assistant { background: rgba(255,255,255,0.05); }
.codex-ai-bubble.codex-thinking { display: inline-flex; gap: 6px; }
.codex-ai-bubble.codex-thinking .dot { width: 6px; height: 6px; background: var(--codex-primary); border-radius: 50%; animation: codex-pulse 1s infinite ease-in-out; }
.codex-ai-bubble.codex-thinking .dot:nth-child(2) { animation-delay: 0.15s; }
.codex-ai-bubble.codex-thinking .dot:nth-child(3) { animation-delay: 0.3s; }
@keyframes codex-pulse { 0%,80%,100%{transform:scale(0);}40%{transform:scale(1);} }

.codex-chat-meta {
  padding: 10px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
  color: var(--codex-muted);
  border-top: 1px solid var(--codex-border);
}

#codex-ai-form {
  padding: 14px 16px 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  border-top: 1px solid var(--codex-border);
  background: var(--codex-surface);
}
#codex-ai-form textarea {
  min-height: 90px;
  padding: 12px 14px;
  border-radius: 14px;
  border: 1px solid var(--codex-border);
  font-family: inherit;
  resize: none;
}
.codex-form-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }
.codex-form-actions button { padding: 11px 18px; border-radius: 12px; border: none; cursor: pointer; font-weight: 700; }
.codex-form-actions .solid { background: var(--codex-gradient); color: #fff; }
.codex-form-actions .ghost { background: transparent; border: 1px solid var(--codex-border); color: var(--codex-text); }
.codex-form-actions .ghost.small { padding: 7px 10px; }
.codex-upload input[type="file"] { width: 150px; font-size: 12px; padding: 8px; border: 1px solid var(--codex-border); border-radius: 10px; }

.codex-quick { display: flex; gap: 8px; padding: 8px 16px; overflow-x: auto; }
.codex-chip { border: none; padding: 9px 12px; background: rgba(0,0,0,0.05); border-radius: 12px; cursor: pointer; font-size: 12px; }

#codex-feedback { display: none; padding: 12px 16px 16px; border-top: 1px solid var(--codex-border); background: rgba(0,0,0,0.02); }
#codex-feedback select, #codex-feedback textarea {
  width: 100%; padding: 10px 12px; border-radius: 12px; border: 1px solid var(--codex-border); margin-bottom: 8px;
}

#codex-ai-booking { max-height: 0; overflow: hidden; transition: max-height 0.25s ease; background: rgba(0,0,0,0.02); }
#codex-ai-booking.open { max-height: 420px; }
.codex-booking { padding: 0 16px 14px; }
.codex-booking__title { font-weight: 700; margin: 10px 0 6px; }
#codex-ai-booking form { display: flex; flex-direction: column; gap: 8px; }
#codex-ai-booking input, #codex-ai-booking textarea { padding: 10px 12px; border-radius: 12px; border: 1px solid var(--codex-border); }

/* Admin styling */
.codex-tabs { display: inline-flex; gap: 8px; padding: 6px; background: #f4f5f7; border-radius: 12px; margin-bottom: 14px; }
.codex-tab-btn { border: 1px solid transparent; padding: 10px 14px; border-radius: 10px; cursor: pointer; background: transparent; font-weight: 600; color: #4b5563; }
.codex-tab-btn.active { background: linear-gradient(135deg, #6366f1, #8b5cf6); color: #fff; box-shadow: 0 6px 16px rgba(99,102,241,0.25); }
.codex-admin input[type="text"], .codex-admin textarea, .codex-admin select { width: 100%; max-width: 460px; padding: 10px 12px; border-radius: 10px; border: 1px solid #e5e7eb; }
.badge { padding: 4px 8px; border-radius: 8px; font-weight: 700; text-transform: capitalize; }
.badge.new { background: #dbeafe; color: #1d4ed8; }
.badge.active { background: #ecfdf3; color: #16a34a; }
.badge.closed { background: #f3f4f6; color: #6b7280; }

@media (max-width: 520px) {
  #codex-ai-panel { left: 12px; right: 12px; width: calc(100vw - 24px); }
  #codex-ai-launcher { right: 12px; left: auto; }
  .codex-grid-2 { grid-template-columns: 1fr; }
}
