/* =========================================================
   TTK ERP Brain — Web Chat Widget Styles
   ========================================================= */

:root {
  --erp-primary: #2563eb;
  --erp-primary-hover: #1d4ed8;
  --erp-primary-light: #eff6ff;
  --erp-bg-white: #ffffff;
  --erp-bg-slate: #f8fafc;
  --erp-border: #e2e8f0;
  --erp-text-main: #0f172a;
  --erp-text-muted: #64748b;
  --erp-success: #10b981;
  --erp-warning: #f59e0b;
  --erp-danger: #ef4444;
  --erp-shadow-lg: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.1);
  --erp-shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --erp-radius: 16px;
  --erp-font: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
}

/* Floating Action Button (FAB) */
.erp-brain-fab {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 10px 25px rgba(37, 99, 235, 0.35);
  cursor: pointer;
  z-index: 999999;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  border: 2px solid rgba(255, 255, 255, 0.2);
  padding: 0;
}

.erp-brain-fab:hover {
  transform: scale(1.08) translateY(-2px);
  box-shadow: 0 15px 30px rgba(37, 99, 235, 0.42);
}

.erp-brain-fab svg {
  width: 28px;
  height: 28px;
  transition: transform 0.2s;
}

.erp-brain-fab .pulse-dot {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 14px;
  height: 14px;
  background-color: var(--erp-success);
  border: 2px solid #fff;
  border-radius: 50%;
}

/* Chat Window Modal / Popup */
.erp-brain-window {
  position: fixed;
  bottom: 96px;
  right: 24px;
  width: 440px;
  height: 680px;
  max-width: calc(100vw - 32px);
  max-height: calc(100vh - 120px);
  background: var(--erp-bg-white);
  border-radius: var(--erp-radius);
  box-shadow: var(--erp-shadow-lg);
  border: 1px solid var(--erp-border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 999999;
  font-family: var(--erp-font);
  opacity: 0;
  pointer-events: none;
  transform: translateY(20px) scale(0.95);
  transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

.erp-brain-fab:focus-visible,
.erp-btn-icon:focus-visible,
.erp-chip:focus-visible,
.erp-suggestion-chip:focus-visible,
.erp-btn-send:focus-visible,
.erp-copy-answer:focus-visible,
.erp-jump-latest:focus-visible {
  outline: 3px solid #93c5fd;
  outline-offset: 2px;
}

.erp-brain-window.active {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0) scale(1);
}

/* Header */
.erp-chat-header {
  background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
  color: #fff;
  padding: 16px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.erp-chat-title-group {
  display: flex;
  align-items: center;
  gap: 12px;
}

.erp-chat-avatar {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.12);
  flex-shrink: 0;
}

.erp-logo-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.erp-chat-title-text h3 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.2px;
}

.erp-chat-title-text p {
  margin: 2px 0 0 0;
  font-size: 11px;
  color: #94a3b8;
  display: flex;
  align-items: center;
  gap: 4px;
}

.erp-chat-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.erp-btn-icon {
  background: transparent;
  border: none;
  color: #94a3b8;
  cursor: pointer;
  padding: 6px;
  border-radius: 6px;
  transition: all 0.2s;
}

.erp-btn-icon:hover {
  color: #fff;
  background: rgba(255, 255, 255, 0.1);
}

/* Messages Area */
.erp-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 18px;
  background: var(--erp-bg-slate);
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.erp-message-row {
  display: flex;
  flex-direction: column;
  max-width: 90%;
  animation: fadeIn 0.25s ease-out;
}

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

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

.erp-bubble {
  padding: 12px 16px;
  border-radius: 14px;
  font-size: 14px;
  line-height: 1.55;
  box-shadow: var(--erp-shadow-sm);
  word-break: break-word;
}

.erp-message-row.user .erp-bubble {
  background: var(--erp-primary);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.erp-message-row.assistant .erp-bubble {
  background: #fff;
  color: var(--erp-text-main);
  border: 1px solid var(--erp-border);
  border-bottom-left-radius: 4px;
}

/* Thought Accordion */
.erp-thought-accordion {
  margin-bottom: 8px;
  background: #f1f5f9;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  overflow: hidden;
  font-size: 12px;
}

.erp-thought-header {
  padding: 8px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  background: #e2e8f0;
  font-weight: 500;
  color: #334155;
  width: 100%;
  border: 0;
  font-family: inherit;
  text-align: left;
}

.erp-thought-body {
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  color: #475569;
  max-height: 180px;
  overflow-y: auto;
}

.erp-thought-item {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  font-family: monospace;
  font-size: 11.5px;
}

/* Agent Active Badge */
.erp-agent-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 8px;
  border-radius: 9999px;
  font-size: 11px;
  font-weight: 600;
  background: #dbeafe;
  color: #1d4ed8;
  margin-bottom: 6px;
}

/* Quick Chips Container */
.erp-quick-chips {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 10px 18px 4px 18px;
  background: #fff;
  border-top: 1px solid var(--erp-border);
  scrollbar-width: none;
}
.erp-quick-chips::-webkit-scrollbar {
  display: none;
}

.erp-chip {
  white-space: nowrap;
  background: #f1f5f9;
  border: 1px solid #cbd5e1;
  padding: 6px 12px;
  border-radius: 9999px;
  font-size: 12px;
  color: #334155;
  cursor: pointer;
  transition: all 0.15s;
}

.erp-chip:hover {
  background: var(--erp-primary-light);
  color: var(--erp-primary);
  border-color: var(--erp-primary);
}

/* Footer / Input bar */
.erp-chat-input-bar {
  background: #fff;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  border-top: 1px solid var(--erp-border);
}

.erp-chat-input-bar textarea {
  flex: 1;
  resize: none;
  border: 1px solid var(--erp-border);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 13.5px;
  outline: none;
  font-family: inherit;
  max-height: 100px;
  min-height: 40px;
  transition: border-color 0.2s;
}

.erp-chat-input-bar textarea:focus {
  border-color: var(--erp-primary);
}

.erp-btn-send {
  background: var(--erp-primary);
  border: none;
  color: #fff;
  width: 40px;
  height: 40px;
  border-radius: 10px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
}

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

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

.erp-bubble .table-wrapper {
  width: 100%;
  margin: 10px 0;
  overflow-x: auto;
  border-radius: 8px;
  -webkit-overflow-scrolling: touch;
}

/* Markdown formatting inside bubble */
.erp-bubble table {
  width: 100%;
  min-width: 480px;
  border-collapse: collapse;
  margin: 10px 0;
  font-size: 12.5px;
}

.erp-error-message {
  color: #b91c1c !important;
  background: #fef2f2 !important;
  border-color: #fecaca !important;
}

.erp-copy-answer {
  align-self: flex-start;
  min-height: 32px;
  margin-top: 4px;
  padding: 4px 8px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: #64748b;
  font: 500 11px/1.2 var(--erp-font);
  cursor: pointer;
}

.erp-copy-answer:hover {
  color: var(--erp-primary);
  background: #fff;
}

.erp-suggestion-arrow {
  margin-left: auto;
  flex-shrink: 0;
  color: #94a3b8;
  font-size: 11px;
}

.erp-jump-latest {
  position: absolute;
  right: 16px;
  bottom: 112px;
  z-index: 3;
  min-height: 36px;
  padding: 7px 12px;
  border: 0;
  border-radius: 999px;
  background: #0f172a;
  color: #fff;
  box-shadow: 0 8px 22px rgba(15, 23, 42, 0.22);
  font: 600 12px/1 var(--erp-font);
  cursor: pointer;
  opacity: 0;
  pointer-events: none;
  transform: translateY(6px);
  transition: opacity 0.18s ease, transform 0.18s ease;
}

.erp-jump-latest.is-visible {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

.erp-btn-icon:disabled,
.erp-chip:disabled,
.erp-suggestion-chip:disabled,
.erp-btn-send:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.erp-bubble th, .erp-bubble td {
  border: 1px solid #e2e8f0;
  padding: 6px 10px;
  text-align: left;
}

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

.erp-bubble tr:nth-child(even) {
  background-color: #f9fafb;
}

.erp-bubble blockquote {
  margin: 10px 0;
  padding: 8px 12px;
  background: #eff6ff;
  border-left: 4px solid var(--erp-primary);
  border-radius: 4px;
  font-size: 13px;
}

.erp-bubble h1, .erp-bubble h2, .erp-bubble h3 {
  margin-top: 12px;
  margin-bottom: 6px;
  font-weight: 700;
}
.erp-bubble h1 { font-size: 16px; }
.erp-bubble h2 { font-size: 15px; }
.erp-bubble h3 { font-size: 14px; }

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

.typing-cursor {
  display: inline-block;
  color: var(--erp-primary);
  font-weight: bold;
  animation: cursorBlink 0.8s infinite;
  margin-left: 2px;
}

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

/* =========================================================
   Suggestions & Interactive Prompt Chips
   ========================================================= */

/* Suggestions Container under Assistant Message */
.erp-suggestions-box {
  margin-top: 10px;
  padding: 10px 12px;
  background: #f0f9ff;
  border: 1px solid #bae6fd;
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  animation: fadeIn 0.3s ease-out;
}

.erp-suggestions-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 11.5px;
  font-weight: 600;
  color: #1d4ed8;
}

.erp-time-tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 9999px;
  font-size: 11px;
  background: #dbeafe;
  color: #1d4ed8;
  font-weight: 600;
}

.erp-suggestions-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.erp-suggestion-chip {
  background: #ffffff;
  border: 1px solid #bfdbfe;
  color: #1d4ed8;
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  text-align: left;
  line-height: 1.35;
  transition: all 0.15s ease;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}

.erp-suggestion-chip:hover {
  background: #2563eb;
  color: #ffffff;
  border-color: #2563eb;
  transform: translateY(-1px);
  box-shadow: 0 3px 6px rgba(37, 99, 235, 0.22);
}

.erp-suggestion-chip:active {
  transform: translateY(0);
}

.erp-suggestion-chip .chip-period-tag {
  background: #dbeafe;
  color: #1d4ed8;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 10.5px;
  white-space: nowrap;
}

.erp-suggestion-chip:hover .chip-period-tag {
  background: rgba(255, 255, 255, 0.25);
  color: #ffffff;
}

/* Chat Suggestions Bar above Input in Full Page */
.chat-suggestions-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 10px;
  scrollbar-width: thin;
  scrollbar-color: #cbd5e1 transparent;
}

.chat-suggestions-bar::-webkit-scrollbar {
  height: 4px;
}
.chat-suggestions-bar::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 4px;
}

.suggestions-label {
  font-size: 12px;
  font-weight: 700;
  color: #64748b;
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 4px;
}

.chat-filter-chip {
  white-space: nowrap;
  background: #f1f5f9;
  border: 1px solid #cbd5e1;
  padding: 5px 12px;
  border-radius: 20px;
  font-size: 12px;
  color: #334155;
  cursor: pointer;
  transition: all 0.15s;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.chat-filter-chip:hover {
  background: #eff6ff;
  border-color: #2563eb;
  color: #1d4ed8;
}

/* Starter cards grid in initial greeting */
.starter-cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 12px;
  margin-top: 14px;
}

.starter-card {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  padding: 12px;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.starter-card:hover {
  background: #f0f9ff;
  border-color: #60a5fa;
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.1);
}

.starter-icon {
  font-size: 20px;
}

.starter-title {
  font-weight: 700;
  font-size: 13px;
  color: #0f172a;
}

.starter-desc {
  font-size: 11.5px;
  color: #64748b;
  line-height: 1.35;
}

/* =========================================================
   Responsive mobile experience
   ========================================================= */
@media (max-width: 600px) {
  .erp-brain-fab {
    right: 12px;
    bottom: max(12px, env(safe-area-inset-bottom));
    width: 56px;
    height: 56px;
    border-radius: 18px;
  }

  .erp-brain-window {
    inset: 0;
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    max-width: none;
    max-height: none;
    border: 0;
    border-radius: 0;
    transform: translateY(100%);
    transform-origin: bottom center;
    overscroll-behavior: contain;
  }

  .erp-brain-window.active {
    transform: translateY(0);
  }

  .erp-chat-header {
    flex-shrink: 0;
    min-height: 64px;
    padding: max(12px, env(safe-area-inset-top)) 14px 12px;
    gap: 10px;
  }

  .erp-chat-title-group {
    min-width: 0;
    gap: 10px;
  }

  .erp-chat-avatar {
    width: 40px;
    height: 40px;
    flex: 0 0 40px;
    border-radius: 12px;
  }

  .erp-chat-title-text {
    min-width: 0;
  }

  .erp-chat-title-text h3,
  .erp-chat-title-text p {
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
  }

  .erp-chat-header-actions {
    flex-shrink: 0;
    gap: 2px;
  }

  .erp-btn-icon {
    width: 42px;
    height: 42px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 12px;
  }

  .erp-chat-messages {
    min-height: 0;
    padding: 15px 12px 20px;
    gap: 14px;
    overscroll-behavior: contain;
  }

  .erp-message-row {
    max-width: 94%;
  }

  .erp-message-row.assistant {
    max-width: 100%;
    width: 100%;
  }

  .erp-bubble {
    padding: 12px 13px;
    border-radius: 16px;
    font-size: 14px;
    line-height: 1.6;
  }

  .erp-bubble table { min-width: 480px; }

  .erp-thought-header {
    min-height: 44px;
    padding: 10px 12px;
  }

  .erp-thought-body {
    max-height: 132px;
  }

  .erp-quick-chips {
    flex-shrink: 0;
    padding: 9px 12px 5px;
    gap: 7px;
    scroll-snap-type: x proximity;
    overscroll-behavior-x: contain;
  }

  .erp-chip {
    min-height: 36px;
    padding: 7px 12px;
    scroll-snap-align: start;
  }

  .erp-chat-input-bar {
    flex-shrink: 0;
    align-items: flex-end;
    padding: 10px 12px max(10px, env(safe-area-inset-bottom));
    gap: 8px;
    box-shadow: 0 -8px 24px rgba(15, 23, 42, 0.05);
  }

  .erp-jump-latest {
    right: 12px;
    bottom: calc(112px + env(safe-area-inset-bottom));
  }

  .erp-chat-input-bar textarea {
    min-width: 0;
    min-height: 46px;
    padding: 11px 13px;
    border-radius: 14px;
    font-size: 16px;
    line-height: 1.45;
    background: #f8fafc;
  }

  .erp-btn-send {
    width: 46px;
    height: 46px;
    flex: 0 0 46px;
    border-radius: 14px;
  }

  .erp-suggestions-box {
    padding: 11px;
  }

  .erp-suggestions-header {
    align-items: flex-start;
    gap: 8px;
  }

  .erp-suggestions-list {
    flex-direction: column;
    flex-wrap: nowrap;
  }

  .erp-suggestion-chip {
    width: 100%;
    min-height: 44px;
    padding: 10px 11px;
  }
}

@media (max-width: 600px) and (orientation: landscape) and (max-height: 520px) {
  .erp-chat-header {
    min-height: 52px;
    padding-top: 6px;
    padding-bottom: 6px;
  }

  .erp-chat-avatar {
    width: 36px;
    height: 36px;
    flex-basis: 36px;
  }

  .erp-quick-chips {
    display: none;
  }

  .erp-chat-messages {
    padding-top: 10px;
    padding-bottom: 10px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .erp-brain-window,
  .erp-brain-fab,
  .erp-message-row,
  .erp-suggestions-box {
    animation: none !important;
    transition-duration: 0.01ms !important;
  }
}
