/**
 * AgyChatbot - Modern Floating Chat Assistant Styles
 * Clean, executive UI with History Modal, Quota Bar, Model & Effort Selectors
 */

:root {
  --agy-primary: #831843;
  --agy-primary-hover: #9d174d;
  --agy-primary-gradient: linear-gradient(135deg, #9d174d 0%, #831843 100%);
  --agy-bg: #ffffff;
  --agy-card-bg: #f8fafc;
  --agy-border: #e2e8f0;
  --agy-text: #1e293b;
  --agy-text-muted: #64748b;
  --agy-user-bubble: #9d174d;
  --agy-user-text: #ffffff;
  --agy-assistant-bubble: #f8fafc;
  --agy-assistant-text: #0f172a;
  --agy-shadow: 0 14px 40px -5px rgba(15, 23, 42, 0.22), 0 8px 20px -6px rgba(15, 23, 42, 0.12);
  --agy-radius: 16px;
  --agy-zindex: 999999;
}

/* Floating Launcher Button */
.agy-launcher-btn {
  position: fixed !important;
  bottom: 24px !important;
  right: 24px !important;
  width: 58px !important;
  height: 58px !important;
  border-radius: 50% !important;
  background: var(--agy-primary-gradient) !important;
  color: #ffffff !important;
  border: 2px solid #ffffff !important;
  box-shadow: 0 6px 20px rgba(157, 23, 77, 0.4) !important;
  cursor: pointer !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  z-index: var(--agy-zindex) !important;
  transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1) !important;
}

.agy-launcher-btn:hover {
  transform: scale(1.08) translateY(-2px) !important;
  box-shadow: 0 8px 25px rgba(157, 23, 77, 0.55) !important;
}

.agy-launcher-btn svg {
  width: 28px;
  height: 28px;
  fill: currentColor;
}

.agy-launcher-badge {
  position: absolute;
  top: -2px;
  right: -2px;
  width: 14px;
  height: 14px;
  background: #10b981;
  border: 2px solid #ffffff;
  border-radius: 50%;
}

/* Main Chat Container / Window */
.agy-chat-window {
  position: fixed !important;
  bottom: 92px !important;
  right: 24px !important;
  width: 460px !important;
  max-width: calc(100vw - 32px) !important;
  height: 660px !important;
  max-height: calc(100vh - 120px) !important;
  background: var(--agy-bg) !important;
  border-radius: var(--agy-radius) !important;
  box-shadow: var(--agy-shadow) !important;
  border: 1px solid var(--agy-border) !important;
  display: flex !important;
  flex-direction: column !important;
  z-index: var(--agy-zindex) !important;
  overflow: hidden !important;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif !important;
  opacity: 0 !important;
  transform: translateY(20px) scale(0.97) !important;
  pointer-events: none !important;
  transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1) !important;
}

.agy-chat-window.agy-active {
  opacity: 1 !important;
  transform: translateY(0) scale(1) !important;
  pointer-events: auto !important;
}

.agy-chat-window.agy-expanded {
  width: 760px !important;
  height: 840px !important;
}

.agy-chat-window.agy-dragover {
  border: 2px dashed var(--agy-primary) !important;
  box-shadow: 0 0 0 4px rgba(157, 23, 77, 0.2) !important;
}

/* Chat Header */
.agy-header {
  padding: 12px 18px;
  background: #ffffff;
  border-bottom: 1px solid var(--agy-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.agy-header-info {
  display: flex;
  align-items: center;
  gap: 10px;
}

.agy-avatar {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: var(--agy-primary-gradient);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 18px;
}

.agy-header-titles {
  display: flex;
  flex-direction: column;
}

.agy-title {
  font-size: 14.5px;
  font-weight: 700;
  color: var(--agy-text);
  margin: 0;
  line-height: 1.2;
}

.agy-subtitle {
  font-size: 11px;
  color: var(--agy-text-muted);
  display: flex;
  align-items: center;
  gap: 4px;
  margin-top: 2px;
}

.agy-status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #10b981;
}

.agy-header-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

.agy-btn-icon {
  background: transparent;
  border: none;
  color: var(--agy-text-muted);
  width: 30px;
  height: 30px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.15s ease;
}

.agy-btn-icon:hover {
  background: #f1f5f9;
  color: var(--agy-text);
}

/* Top Quota & Config Control Bar */
.agy-top-control-bar {
  padding: 6px 14px;
  background: #f8fafc;
  border-bottom: 1px solid var(--agy-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 11px;
}

.agy-quota-group {
  display: flex;
  align-items: center;
  gap: 10px;
}

.agy-quota-item {
  display: flex;
  align-items: center;
  gap: 4px;
}

.agy-quota-label {
  font-weight: 600;
  color: var(--agy-text-muted);
  font-size: 10.5px;
}

.agy-quota-track {
  width: 44px;
  height: 6px;
  background: #e2e8f0;
  border-radius: 6px;
  overflow: hidden;
}

.agy-quota-fill {
  height: 100%;
  background: #10b981;
  border-radius: 6px;
  transition: width 0.3s ease;
}

.agy-quota-weekly-fill {
  background: #3b82f6;
}

.agy-quota-val {
  font-size: 10px;
  font-weight: 600;
  color: var(--agy-text);
}

.agy-select-group {
  display: flex;
  align-items: center;
  gap: 6px;
}

.agy-select-control {
  background: #ffffff;
  border: 1px solid var(--agy-border);
  border-radius: 6px;
  font-size: 10.5px;
  color: var(--agy-text);
  padding: 3px 6px;
  outline: none;
  cursor: pointer;
}

.agy-select-control:focus {
  border-color: var(--agy-primary);
}

/* Messages Area */
.agy-messages-body {
  flex: 1;
  padding: 18px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
  background: #fafbfc;
}

.agy-messages-body::-webkit-scrollbar {
  width: 5px;
}

.agy-messages-body::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 10px;
}

/* Message Rows */
.agy-message-row {
  display: flex;
  flex-direction: column;
  max-width: 88%;
  animation: agyFadeIn 0.2s ease;
}

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

.agy-message-row.agy-user {
  align-self: flex-end;
}

.agy-message-row.agy-assistant {
  align-self: flex-start;
  max-width: 95%;
}

.agy-bubble {
  padding: 12px 16px;
  border-radius: 14px;
  font-size: 13.5px;
  line-height: 1.55;
  word-break: break-word;
}

.agy-user .agy-bubble {
  background: var(--agy-user-bubble);
  color: var(--agy-user-text);
  border-bottom-right-radius: 3px;
}

.agy-assistant .agy-bubble {
  background: #ffffff;
  color: var(--agy-assistant-text);
  border: 1px solid var(--agy-border);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
  border-bottom-left-radius: 3px;
}

/* Multimodal Image Bubbles */
.agy-bubble-images {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 8px;
}

.agy-bubble-img-preview {
  max-width: 180px;
  max-height: 140px;
  border-radius: 8px;
  object-fit: cover;
  border: 1px solid rgba(255, 255, 255, 0.3);
  cursor: pointer;
  transition: transform 0.15s ease;
}

.agy-bubble-img-preview:hover {
  transform: scale(1.04);
}

/* Attached Images Preview in Input Footer */
.agy-attachments-preview {
  padding: 8px 14px;
  display: flex;
  gap: 8px;
  overflow-x: auto;
  background: #f1f5f9;
  border-top: 1px solid var(--agy-border);
}

.agy-attachment-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  background: #ffffff;
  border: 1px solid var(--agy-border);
  padding: 3px 8px 3px 4px;
  border-radius: 8px;
  font-size: 11.5px;
  color: var(--agy-text);
}

.agy-attachment-chip img {
  width: 26px;
  height: 26px;
  border-radius: 4px;
  object-fit: cover;
}

.agy-attachment-name {
  max-width: 100px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.agy-attachment-remove {
  background: transparent;
  border: none;
  color: #ef4444;
  font-weight: bold;
  font-size: 14px;
  cursor: pointer;
  padding: 0 2px;
  line-height: 1;
}

/* Markdown formatting inside assistant bubble */
.agy-bubble p {
  margin: 0 0 10px 0;
}

.agy-bubble p:last-child {
  margin-bottom: 0;
}

.agy-bubble table {
  width: 100%;
  border-collapse: collapse;
  margin: 10px 0;
  font-size: 12.5px;
}

.agy-bubble th,
.agy-bubble td {
  padding: 6px 10px;
  border: 1px solid var(--agy-border);
  text-align: left;
}

.agy-bubble th {
  background: #f8fafc;
  font-weight: 600;
}

.agy-bubble pre {
  background: #0f172a;
  color: #f8fafc;
  padding: 12px;
  border-radius: 8px;
  overflow-x: auto;
  font-size: 12px;
  margin: 10px 0;
  position: relative;
}

.agy-bubble code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

.agy-bubble :not(pre) > code {
  background: #f1f5f9;
  color: #0f172a;
  padding: 2px 5px;
  border-radius: 4px;
  font-size: 12px;
}

/* Tool Execution Chips / Accordions */
.agy-tool-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: #f0fdf4;
  border: 1px solid #bbf7d0;
  color: #166534;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 11.5px;
  font-weight: 500;
  margin-bottom: 8px;
}

.agy-tool-chip.agy-tool-running {
  background: #eff6ff;
  border-color: #bfdbfe;
  color: #1e40af;
}

.agy-tool-spinner {
  width: 10px;
  height: 10px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: agySpin 0.7s linear infinite;
}

@keyframes agySpin {
  to { transform: rotate(360deg); }
}

/* Typing / Streaming Cursor */
.agy-cursor {
  display: inline-block;
  width: 6px;
  height: 14px;
  background: var(--agy-primary);
  margin-left: 3px;
  vertical-align: middle;
  animation: agyBlink 0.9s infinite;
}

@keyframes agyBlink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}

/* Quick Prompts Suggestions */
.agy-quick-prompts {
  padding: 8px 14px;
  display: flex;
  gap: 6px;
  overflow-x: auto;
  background: #ffffff;
  border-top: 1px solid #f1f5f9;
}

.agy-quick-prompts::-webkit-scrollbar {
  display: none;
}

.agy-prompt-pill {
  flex-shrink: 0;
  background: #f1f5f9;
  border: 1px solid var(--agy-border);
  color: var(--agy-text);
  font-size: 11.5px;
  padding: 4px 10px;
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.agy-prompt-pill:hover {
  background: #e2e8f0;
  border-color: #cbd5e1;
}

/* Input Footer */
.agy-footer {
  padding: 12px 16px;
  background: #ffffff;
  border-top: 1px solid var(--agy-border);
}

.agy-input-wrapper {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: #f8fafc;
  border: 1px solid var(--agy-border);
  border-radius: 12px;
  padding: 6px 8px 6px 8px;
  transition: border-color 0.2s;
}

.agy-btn-attach {
  width: 32px;
  height: 32px;
  color: var(--agy-text-muted);
  cursor: pointer;
  flex-shrink: 0;
}

.agy-btn-attach:hover {
  color: var(--agy-primary);
}

.agy-input-wrapper:focus-within {
  border-color: var(--agy-primary);
  box-shadow: 0 0 0 2px rgba(157, 23, 77, 0.15);
}

.agy-textarea {
  flex: 1;
  border: none;
  background: transparent;
  resize: none;
  outline: none;
  max-height: 100px;
  font-size: 13px;
  line-height: 1.4;
  color: var(--agy-text);
  font-family: inherit;
  padding: 6px 0;
}

.agy-btn-send {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: var(--agy-primary);
  color: #fff;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.15s;
}

.agy-btn-send:hover {
  background: var(--agy-primary-hover);
}

.agy-btn-send:disabled {
  background: #cbd5e1;
  cursor: not-allowed;
}

/* Conversation History Modal */
.agy-modal-overlay {
  position: fixed !important;
  top: 0 !important;
  left: 0 !important;
  right: 0 !important;
  bottom: 0 !important;
  width: 100vw !important;
  height: 100vh !important;
  background: rgba(15, 23, 42, 0.55) !important;
  backdrop-filter: blur(4px) !important;
  z-index: 1000000 !important;
  display: none !important;
  align-items: center !important;
  justify-content: center !important;
  padding: 16px !important;
}

.agy-modal-overlay.agy-modal-open {
  display: flex !important;
  animation: agyFadeIn 0.2s ease;
}

.agy-modal-card {
  width: 540px !important;
  max-width: calc(100vw - 32px) !important;
  max-height: 80vh !important;
  background: #ffffff !important;
  border-radius: 14px !important;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.35) !important;
  display: flex !important;
  flex-direction: column !important;
  overflow: hidden !important;
  border: 1px solid var(--agy-border) !important;
}

.agy-modal-header {
  padding: 12px 16px;
  border-bottom: 1px solid var(--agy-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.agy-modal-title {
  font-size: 13.5px;
  font-weight: 700;
  color: var(--agy-text);
  display: flex;
  align-items: center;
  gap: 6px;
}

.agy-modal-search-box {
  padding: 10px 14px;
  border-bottom: 1px solid var(--agy-border);
  background: #f8fafc;
  display: flex;
  gap: 8px;
}

.agy-modal-search-input {
  flex: 1;
  border: 1px solid var(--agy-border);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 12px;
  outline: none;
}

.agy-modal-search-input:focus {
  border-color: var(--agy-primary);
}

.agy-btn-modal-new {
  background: var(--agy-primary);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 0 12px;
  font-size: 11.5px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}

.agy-btn-modal-new:hover {
  background: var(--agy-primary-hover);
}

.agy-modal-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 380px;
}

.agy-history-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  border-radius: 8px;
  border: 1px solid transparent;
  background: #fafbfc;
  cursor: pointer;
  transition: all 0.15s ease;
}

.agy-history-item:hover {
  background: #f1f5f9;
  border-color: var(--agy-border);
}

.agy-history-item.agy-history-current {
  background: #fdf2f8;
  border-color: #fbcfe8;
}

.agy-history-content {
  flex: 1;
  min-width: 0;
}

.agy-history-title {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--agy-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.agy-history-meta {
  font-size: 10px;
  color: var(--agy-text-muted);
  display: flex;
  gap: 8px;
  margin-top: 3px;
}

.agy-history-delete {
  background: transparent;
  border: none;
  color: var(--agy-text-muted);
  font-size: 16px;
  padding: 4px 6px;
  cursor: pointer;
  border-radius: 4px;
  line-height: 1;
}

.agy-history-delete:hover {
  color: #ef4444;
  background: #fee2e2;
}

.agy-modal-loading,
.agy-modal-empty {
  padding: 24px;
  text-align: center;
  color: var(--agy-text-muted);
  font-size: 12px;
}
