/* ============================================
   Chat Widget – Modern Design
   ============================================ */

/* --- Edge Tab Trigger --- */
.chat-widget-fab {
  position: fixed;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 44px;
  padding: 12px 0;
  border: none;
  border-radius: 8px 0 0 8px;
  background-color: #008080;
  color: #fff;
  cursor: pointer;
  box-shadow: -2px 0 12px rgba(0, 128, 128, 0.25);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  z-index: 1092;
  font-size: 1.2rem;
  transition: right 0.3s cubic-bezier(0.4, 0, 0.2, 1),
              transform 0.3s cubic-bezier(0.4, 0, 0.2, 1),
              box-shadow 0.2s ease,
              background-color 0.2s ease;
}

.chat-widget-fab span {
  font-size: 0.6rem;
  font-weight: 600;
  letter-spacing: 0.5px;
  line-height: 1;
  opacity: 0.9;
}

.chat-widget-fab i {
  transition: transform 0.2s ease;
}

.chat-widget-fab-shortcut {
  font-family: inherit;
  font-size: 0.5rem;
  font-weight: 500;
  line-height: 1;
  padding: 2px 4px;
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.15);
  color: rgba(255, 255, 255, 0.7);
  border: none;
}

.chat-widget-fab:hover {
  transform: translateY(-50%) translateX(-2px);
  background-color: #006d6d;
  box-shadow: -4px 0 20px rgba(0, 128, 128, 0.35);
}

/* Slide tab with panel when open */
body.chat-panel-open .chat-widget-fab {
  right: 420px;
}

body.chat-panel-open .chat-widget-fab span,
body.chat-panel-open .chat-widget-fab kbd {
  display: none;
}

body.chat-panel-open .chat-widget-fab i::before {
  content: "\ea50"; /* bx-chevron-right */
}

/* Push page content when panel is open */
.layout-page {
  transition: margin-right 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

body.chat-panel-open .layout-page {
  margin-right: 420px;
}

.layout-navbar {
  transition: right 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

body.chat-panel-open .layout-navbar {
  right: 420px;
}

/* Detached navbar uses explicit width from core.css, so right alone won't shrink it */
.layout-navbar.navbar-detached {
  transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

body.chat-panel-open .layout-navbar.navbar-detached {
  width: calc(100% - 1.625rem * 2 - 16.25rem - 420px);
}

.layout-menu-collapsed body.chat-panel-open .layout-navbar.navbar-detached {
  width: calc(100% - 1.625rem * 2 - 5.25rem - 420px);
}

@media (max-width: 1199.98px) {
  body.chat-panel-open .layout-navbar.navbar-detached {
    width: calc(100% - 1.625rem * 2 - 420px) !important;
  }
}

@media (max-width: 991.98px) {
  body.chat-panel-open .layout-navbar.navbar-detached {
    width: calc(100% - 1rem * 2 - 420px) !important;
  }
}

/* --- Chat Panel --- */
.chat-widget-panel {
  position: fixed;
  top: 0;
  right: 0;
  width: 420px;
  height: 100vh;
  background: #fff;
  border-left: 1px solid #e5e5e5;
  box-shadow: -2px 0 20px rgba(0, 0, 0, 0.08);
  display: none;
  flex-direction: column;
  z-index: 1091;
  overflow: hidden;
  animation: chatSlideIn 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.chat-widget-panel.open {
  display: flex;
}

@keyframes chatSlideIn {
  from { transform: translateX(100%); }
  to { transform: translateX(0); }
}

/* --- Header --- */
.chat-widget-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: #fff;
  border-bottom: 1px solid #e5e5e5;
  flex-shrink: 0;
}

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

.chat-widget-header-actions {
  display: flex;
  gap: 2px;
}

.chat-widget-header-btn {
  background: transparent;
  border: none;
  color: #8e8ea0;
  cursor: pointer;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.15rem;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.chat-widget-header-btn:hover {
  background-color: #f0f0f0;
  color: #1a1a1a;
}

/* --- Kai Avatar (Header) --- */
.kai-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: #008080;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.kai-header-text {
  display: flex;
  flex-direction: column;
  line-height: 1;
}

.kai-name {
  font-weight: 600;
  font-size: 0.9rem;
  color: #1a1a1a;
}

/* --- Messages Area --- */
.chat-widget-messages {
  flex: 1;
  overflow-y: auto;
  padding: 0;
  display: flex;
  flex-direction: column;
  scrollbar-width: thin;
  scrollbar-color: transparent transparent;
}

.chat-widget-messages:hover {
  scrollbar-color: rgba(0, 128, 128, 0.3) transparent;
}

.chat-widget-messages::-webkit-scrollbar {
  width: 6px;
}

.chat-widget-messages::-webkit-scrollbar-track {
  background: transparent;
}

.chat-widget-messages::-webkit-scrollbar-thumb {
  background-color: transparent;
  border-radius: 3px;
}

.chat-widget-messages:hover::-webkit-scrollbar-thumb {
  background-color: rgba(0, 128, 128, 0.3);
}

/* --- Welcome Screen --- */
.chat-widget-welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 48px 24px 32px;
  flex: 1;
}

.kai-welcome-avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: #008080;
  color: #fff;
  font-weight: 700;
  font-size: 1.2rem;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 16px;
}

.chat-widget-welcome .chat-widget-welcome-greeting {
  margin: 0 0 6px 0;
  font-size: 1.15rem;
  font-weight: 600;
  color: #1a1a1a;
}

.chat-widget-welcome .chat-widget-welcome-subtitle {
  margin: 0;
  font-size: 0.82rem;
  line-height: 1.5;
  color: #8e8ea0;
  max-width: 320px;
}

/* --- Suggestion Chips --- */
.chat-widget-suggestions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 24px;
  width: 100%;
  padding: 0 4px;
}

.chat-widget-chip {
  background: #fff;
  border: 1px solid #e5e5e5;
  color: #1a1a1a;
  border-radius: 12px;
  padding: 12px;
  font-size: 0.78rem;
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
  white-space: normal;
  text-align: left;
  line-height: 1.4;
  display: flex;
  align-items: flex-start;
  gap: 8px;
}

.chat-widget-chip i {
  font-size: 1rem;
  color: #8e8ea0;
  flex-shrink: 0;
  margin-top: 1px;
}

.chat-widget-chip:hover {
  background-color: #f7f7f8;
  border-color: #d0d0d0;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
}

.chat-widget-chip:hover i {
  color: #008080;
}

/* --- Message Rows --- */
@keyframes chatMsgFadeIn {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.chat-widget-msg,
.chat-widget-typing,
.chat-widget-tool-card,
.chat-widget-tool-indicator {
  animation: chatMsgFadeIn 0.25s ease;
}

.chat-widget-msg {
  display: flex;
  flex-direction: column;
  padding: 12px 20px;
  max-width: 100%;
}

.chat-widget-msg.user {
  align-items: flex-end;
  background: transparent;
}

.chat-widget-msg.assistant {
  align-items: flex-start;
  background: #f7f7f8;
  position: relative;
}

.chat-widget-msg .bubble {
  font-size: 0.875rem;
  line-height: 1.65;
  word-wrap: break-word;
  color: #1a1a1a;
}

.chat-widget-msg.user .bubble {
  background-color: #f0f0f0;
  padding: 10px 16px;
  border-radius: 18px;
  max-width: 85%;
  color: #1a1a1a;
}

.chat-widget-msg.assistant .bubble {
  background: transparent;
  padding: 0;
  max-width: 100%;
}

/* --- Message Timestamps --- */
.chat-widget-msg-time {
  display: block;
  font-size: 0.65rem;
  color: #b0b0b0;
  margin-top: 4px;
}

.chat-widget-msg.user .chat-widget-msg-time {
  text-align: right;
}

.chat-widget-msg.assistant .chat-widget-msg-time {
  text-align: left;
}

/* --- Copy Button --- */
.chat-widget-copy-btn {
  position: absolute;
  top: 10px;
  right: 12px;
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: #b0b0b0;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
  opacity: 0;
  transition: opacity 0.15s ease, background-color 0.15s ease, color 0.15s ease;
}

.chat-widget-msg.assistant:hover .chat-widget-copy-btn {
  opacity: 1;
}

.chat-widget-copy-btn:hover {
  background: rgba(0, 0, 0, 0.06);
  color: #1a1a1a;
}

/* --- Tool Indicator --- */
.chat-widget-tool-indicator {
  display: flex;
  align-items: center;
  gap: 6px;
  color: #8e8ea0;
  font-size: 0.72rem;
  padding: 6px 20px;
  align-self: flex-start;
}

.chat-widget-tool-indicator i {
  font-size: 0.85rem;
  color: #008080;
}

/* --- Typing Indicator --- */
.chat-widget-typing {
  display: flex;
  align-items: center;
  align-self: flex-start;
  gap: 5px;
  padding: 14px 20px;
  background: #f7f7f8;
  width: 100%;
}

.chat-widget-typing .dot {
  width: 6px;
  height: 6px;
  background-color: #008080;
  border-radius: 50%;
  animation: chatTypingBounce 1.4s infinite ease-in-out;
}

.chat-widget-typing .dot:nth-child(2) {
  animation-delay: 0.2s;
}

.chat-widget-typing .dot:nth-child(3) {
  animation-delay: 0.4s;
}

.chat-widget-typing-label {
  font-size: 0.72rem;
  color: #8e8ea0;
  margin-left: 6px;
}

@keyframes chatTypingBounce {
  0%, 60%, 100% {
    transform: translateY(0);
    opacity: 0.3;
  }
  30% {
    transform: translateY(-4px);
    opacity: 1;
  }
}

/* --- Input Bar --- */
.chat-widget-input-bar {
  padding: 12px 16px 16px;
  flex-shrink: 0;
  background: #fff;
}

.chat-widget-file-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 0 0 8px 0;
}

.chat-widget-file-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px 4px 10px;
  background-color: #f7f7f8;
  border: 1px solid #e5e5e5;
  border-radius: 8px;
  font-size: 0.78rem;
  color: #1a1a1a;
  max-width: 100%;
}

.chat-widget-file-chip i.bx-file {
  color: #8e8ea0;
  font-size: 1rem;
  flex-shrink: 0;
}

.chat-widget-file-chip span {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
  min-width: 0;
}

.chat-widget-file-chip-remove {
  background: transparent;
  border: none;
  color: #b0b0b0;
  cursor: pointer;
  padding: 0;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 0.9rem;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.chat-widget-file-chip-remove:hover {
  background-color: #e5e5e5;
  color: #1a1a1a;
}

.chat-widget-input-wrapper {
  display: flex;
  align-items: flex-end;
  gap: 0;
  background: #f7f7f8;
  border: 1px solid #e5e5e5;
  border-radius: 16px;
  padding: 4px 6px 4px 4px;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.chat-widget-input-wrapper:focus-within {
  border-color: #008080;
  box-shadow: 0 0 0 2px rgba(0, 128, 128, 0.1);
}

.chat-widget-input {
  flex: 1;
  border: none;
  background: transparent;
  padding: 8px 8px;
  font-size: 0.875rem;
  font-family: inherit;
  line-height: 1.5;
  outline: none;
  resize: none;
  min-height: 24px;
  max-height: 150px;
  overflow-y: auto;
  color: #1a1a1a;
}

.chat-widget-input::placeholder {
  color: #b0b0b0;
}

.chat-widget-send-btn {
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 50%;
  background-color: #008080;
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 1.1rem;
  transition: background-color 0.15s ease, transform 0.1s ease;
}

.chat-widget-send-btn:hover {
  background-color: #006d6d;
}

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

.chat-widget-send-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.chat-widget-attach-btn {
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: #8e8ea0;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 1.2rem;
  transition: color 0.15s ease;
  padding: 0;
}

.chat-widget-attach-btn:hover {
  color: #008080;
}

.chat-widget-attach-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

/* File bubble in user message */
.bubble.file-bubble {
  display: flex;
  align-items: center;
  gap: 6px;
}

.bubble.file-bubble i {
  font-size: 1.1rem;
  color: #008080;
}

/* --- Drop Overlay --- */
.chat-widget-drop-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(255, 255, 255, 0.92);
  border: 2px dashed #c0c0c0;
  border-radius: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  z-index: 20;
  color: #1a1a1a;
  font-weight: 600;
  font-size: 0.9rem;
  pointer-events: none;
}

.chat-widget-drop-overlay i {
  font-size: 2.5rem;
  color: #8e8ea0;
}

.drop-overlay-hint {
  font-size: 0.75rem;
  font-weight: 400;
  color: #8e8ea0;
}

/* --- Character Counter --- */
.chat-widget-char-count {
  display: none;
  font-size: 0.65rem;
  color: #b0b0b0;
  text-align: right;
  padding: 3px 8px 0 0;
}

.chat-widget-char-count.visible {
  display: block;
}

.chat-widget-char-count.warning {
  color: #d97706;
}

/* Disabled state */
.chat-widget-input:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ============================================
   Markdown Styles inside Assistant Messages
   ============================================ */
.chat-widget-msg.assistant .bubble p {
  margin: 0 0 8px 0;
}

.chat-widget-msg.assistant .bubble p:last-child {
  margin-bottom: 0;
}

.chat-widget-msg.assistant .bubble ul,
.chat-widget-msg.assistant .bubble ol {
  margin: 4px 0 8px 0;
  padding-left: 20px;
}

.chat-widget-msg.assistant .bubble li {
  margin-bottom: 2px;
}

.chat-widget-msg.assistant .bubble code {
  background-color: rgba(0, 0, 0, 0.05);
  padding: 2px 5px;
  border-radius: 4px;
  font-size: 0.8rem;
  font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
}

.chat-widget-msg.assistant .bubble pre {
  background-color: #1e1e2e;
  color: #cdd6f4;
  padding: 12px 14px;
  border-radius: 8px;
  overflow-x: auto;
  margin: 8px 0;
  font-size: 0.78rem;
  line-height: 1.55;
}

.chat-widget-msg.assistant .bubble pre code {
  background: none;
  padding: 0;
  color: inherit;
  font-size: inherit;
}

.chat-widget-msg.assistant .bubble blockquote {
  border-left: 3px solid #008080;
  margin: 8px 0;
  padding: 4px 12px;
  color: #6e6e80;
  border-radius: 0;
}

.chat-widget-msg.assistant .bubble table {
  border-collapse: collapse;
  width: 100%;
  margin: 8px 0;
  font-size: 0.8rem;
}

.chat-widget-msg.assistant .bubble th,
.chat-widget-msg.assistant .bubble td {
  border: 1px solid #e5e5e5;
  padding: 5px 10px;
  text-align: left;
}

.chat-widget-msg.assistant .bubble th {
  background-color: #f7f7f8;
  font-weight: 600;
}

.chat-widget-msg.assistant .bubble h1,
.chat-widget-msg.assistant .bubble h2,
.chat-widget-msg.assistant .bubble h3,
.chat-widget-msg.assistant .bubble h4 {
  margin: 10px 0 4px 0;
  font-weight: 600;
  line-height: 1.3;
  color: #1a1a1a;
}

.chat-widget-msg.assistant .bubble h1 { font-size: 1.1rem; }
.chat-widget-msg.assistant .bubble h2 { font-size: 1rem; }
.chat-widget-msg.assistant .bubble h3 { font-size: 0.95rem; }
.chat-widget-msg.assistant .bubble h4 { font-size: 0.9rem; }

.chat-widget-msg.assistant .bubble a {
  color: #008080;
  text-decoration: underline;
}

.chat-widget-msg.assistant .bubble hr {
  border: none;
  border-top: 1px solid #e5e5e5;
  margin: 8px 0;
}

/* ============================================
   Rich Tool Display Cards
   ============================================ */
.chat-widget-tool-card {
  background-color: #fff;
  border: 1px solid #e5e5e5;
  border-left: 3px solid #008080;
  border-radius: 10px;
  padding: 12px 14px;
  margin: 4px 20px;
  align-self: flex-start;
  max-width: calc(100% - 40px);
}

.tool-card-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
}

.tool-card-stat {
  text-align: center;
  min-width: 60px;
}

.tool-card-stat-value {
  font-size: 1.15rem;
  font-weight: 700;
  color: #008080;
  line-height: 1.2;
}

.tool-card-stat-label {
  font-size: 0.65rem;
  color: #8e8ea0;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-top: 2px;
}

.tool-card-table-wrap {
  overflow-x: auto;
  overflow-y: auto;
  max-height: 200px;
}

.tool-card-table {
  border-collapse: collapse;
  width: 100%;
  font-size: 0.75rem;
}

.tool-card-table thead {
  position: sticky;
  top: 0;
  z-index: 1;
}

.tool-card-table th {
  background-color: #f7f7f8;
  color: #1a1a1a;
  padding: 6px 10px;
  text-align: left;
  font-weight: 600;
  white-space: nowrap;
  border-bottom: 1px solid #e5e5e5;
}

.tool-card-table td {
  padding: 5px 10px;
  border-bottom: 1px solid #f0f0f0;
  white-space: nowrap;
}

.tool-card-table tbody tr:hover {
  background-color: #f7f7f8;
}

.tool-card-footer {
  font-size: 0.7rem;
  color: #8e8ea0;
  text-align: right;
  margin-top: 6px;
}

/* ============================================
   Preview Actions
   ============================================ */
.chat-widget-preview-actions {
  display: flex;
  gap: 8px;
  align-self: flex-start;
  margin: 4px 20px;
}

.preview-btn-confirm {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 8px 18px;
  border: none;
  border-radius: 8px;
  background-color: #008080;
  color: #fff;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.15s ease;
}

.preview-btn-confirm:hover {
  background-color: #006d6d;
}

/* ============================================
   Student Preview Modal
   ============================================ */
#chatStudentPreviewModal {
  z-index: 1100;
}

body.chat-preview-open .modal-backdrop {
  z-index: 1095;
}

.chat-preview-modal-table thead th {
  background-color: #f7f7f8;
  color: #1a1a1a;
  font-weight: 600;
  white-space: nowrap;
  font-size: 0.85rem;
  border-bottom: 1px solid #e5e5e5;
}

.chat-preview-modal-table tbody td {
  font-size: 0.85rem;
  vertical-align: middle;
}

.chat-preview-modal-table tbody tr:hover {
  background-color: #f7f7f8;
}

/* ============================================
   Tabbed Preview (Students & Parents)
   ============================================ */
.chat-preview-tabs {
  display: flex;
  border-bottom: 1px solid #e5e5e5;
  background: #fff;
  padding: 0;
}

.chat-preview-tab {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.875rem 1.5rem;
  border: none;
  background: none;
  color: #8e8ea0;
  font-weight: 500;
  font-size: 0.875rem;
  cursor: pointer;
  position: relative;
  transition: all 0.2s ease;
}

.chat-preview-tab:hover {
  color: #1a1a1a;
  background: #f7f7f8;
}

.chat-preview-tab.active {
  color: #008080;
}

.chat-preview-tab.active::after {
  content: '';
  position: absolute;
  bottom: -1px;
  left: 0.75rem;
  right: 0.75rem;
  height: 2px;
  background: #008080;
  border-radius: 2px 2px 0 0;
}

.chat-preview-tab i {
  font-size: 1.125rem;
}

.chat-preview-tab-badge {
  padding: 0.15em 0.55em;
  font-size: 0.7rem;
  font-weight: 600;
  border-radius: 50px;
  background: rgba(0, 128, 128, 0.1);
  color: #008080;
}

.chat-preview-tab-pane {
  display: none;
}

.chat-preview-tab-pane.active {
  display: block;
}

/* Students tab */
.chat-preview-people-table {
  margin-bottom: 0;
}

.chat-preview-people-table thead th {
  background: #f7f7f8;
  border-bottom: 1px solid #e5e5e5;
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: #8e8ea0;
  padding: 0.75rem 1rem;
}

.chat-preview-people-table tbody td {
  padding: 0.75rem 1rem;
  vertical-align: middle;
  border-bottom: 1px solid #f0f0f0;
  font-size: 0.85rem;
}

.chat-preview-people-table tbody tr:hover {
  background: #f7f7f8;
}

.chat-preview-people-table tbody tr:last-child td {
  border-bottom: none;
}

/* Parents tab */
.chat-preview-parent-list {
  padding: 1rem;
}

.chat-preview-parent-card {
  border: 1px solid #e5e5e5;
  border-radius: 10px;
  margin-bottom: 0.75rem;
  transition: all 0.2s ease;
}

.chat-preview-parent-card:hover {
  border-color: #d0d0d0;
  box-shadow: 0 1px 6px rgba(0, 0, 0, 0.05);
}

.chat-preview-parent-header {
  padding: 0.875rem 1.125rem;
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.875rem;
  border-radius: 10px;
}

.chat-preview-parent-card.expanded .chat-preview-parent-header {
  border-radius: 10px 10px 0 0;
}

.chat-preview-parent-header:hover {
  background: #fafafa;
}

.chat-preview-parent-avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 0.9rem;
  background: #e5e5e5;
  color: #1a1a1a;
  flex-shrink: 0;
}

.chat-preview-parent-name {
  font-weight: 600;
  font-size: 0.9rem;
  color: #1a1a1a;
}

.chat-preview-parent-contact {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-top: 0.125rem;
}

.chat-preview-parent-contact span {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  font-size: 0.8rem;
  color: #8e8ea0;
}

.chat-preview-parent-contact i {
  font-size: 0.875rem;
  color: #b0b0b0;
}

.chat-preview-children-badge {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.25rem 0.75rem;
  background: rgba(0, 128, 128, 0.1);
  color: #008080;
  border-radius: 50px;
  font-size: 0.75rem;
  font-weight: 600;
  flex-shrink: 0;
}

.chat-preview-children-badge i {
  font-size: 0.8125rem;
}

.chat-preview-expand-btn {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #f0f0f0;
  color: #8e8ea0;
  border: none;
  cursor: pointer;
  transition: all 0.2s ease;
  flex-shrink: 0;
}

.chat-preview-expand-btn:hover {
  background: rgba(0, 128, 128, 0.1);
  color: #008080;
}

.chat-preview-expand-btn i {
  transition: transform 0.2s ease;
  font-size: 1.1rem;
}

.chat-preview-parent-card.expanded .chat-preview-expand-btn {
  background: #008080;
  color: #fff;
}

.chat-preview-parent-card.expanded .chat-preview-expand-btn i {
  transform: rotate(180deg);
}

.chat-preview-children-section {
  display: none;
  border-top: 1px solid #e5e5e5;
  background: #fafafa;
  border-radius: 0 0 10px 10px;
  overflow: hidden;
}

.chat-preview-parent-card.expanded .chat-preview-children-section {
  display: block;
}

.chat-preview-children-header {
  padding: 0.5rem 1.125rem;
  background: #f0f0f0;
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: #8e8ea0;
  display: flex;
  align-items: center;
  gap: 0.375rem;
}

.chat-preview-child-row {
  padding: 0.625rem 1.125rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-top: 1px solid #f0f0f0;
  background: #fff;
}

.chat-preview-child-row:last-child {
  border-radius: 0 0 10px 10px;
}

.chat-preview-child-row:hover {
  background: #fafafa;
}

.chat-preview-child-info {
  display: flex;
  align-items: center;
  gap: 0.625rem;
}

.chat-preview-child-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 0.65rem;
  background: rgba(0, 128, 128, 0.12);
  color: #008080;
  flex-shrink: 0;
}

.chat-preview-child-name {
  font-weight: 500;
  font-size: 0.8125rem;
  color: #1a1a1a;
}

.chat-preview-child-meta {
  font-size: 0.75rem;
  color: #b0b0b0;
}

.chat-preview-relationship-badge {
  padding: 0.1875rem 0.625rem;
  background: #f0f0f0;
  color: #6e6e80;
  border-radius: 50px;
  font-size: 0.6875rem;
  font-weight: 500;
  text-transform: capitalize;
}

.chat-preview-orphan-section {
  border: 1px solid #e5e5e5;
  border-radius: 10px;
  margin-bottom: 0.75rem;
  overflow: hidden;
}

.chat-preview-orphan-header {
  padding: 0.625rem 1.125rem;
  background: #f7f7f8;
  font-size: 0.75rem;
  font-weight: 600;
  color: #8e8ea0;
  display: flex;
  align-items: center;
  gap: 0.375rem;
  border-bottom: 1px solid #e5e5e5;
}

.chat-preview-orphan-header i {
  font-size: 0.9375rem;
  color: #b0b0b0;
}

/* ============================================
   Conversations History Overlay
   ============================================ */
.chat-widget-conversations {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: #fff;
  z-index: 10;
  display: flex;
  flex-direction: column;
}

.conversations-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: #fff;
  border-bottom: 1px solid #e5e5e5;
  flex-shrink: 0;
}

.conversations-title {
  font-weight: 600;
  font-size: 0.9rem;
  color: #1a1a1a;
}

.conversations-close-btn {
  background: transparent;
  border: none;
  color: #8e8ea0;
  cursor: pointer;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.conversations-close-btn:hover {
  background-color: #f0f0f0;
  color: #1a1a1a;
}

.conversations-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 8px;
}

.conversation-item {
  padding: 10px 12px;
  cursor: pointer;
  border-radius: 8px;
  border-left: none;
  margin: 2px 0;
  transition: background-color 0.15s ease;
}

.conversation-item:hover {
  background-color: #f7f7f8;
}

.conversation-item.active {
  background-color: rgba(0, 128, 128, 0.08);
}

.conversation-item-title {
  font-size: 0.85rem;
  font-weight: 500;
  color: #1a1a1a;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.conversation-item-icon {
  font-size: 0.9rem;
  color: #b0b0b0;
  flex-shrink: 0;
  margin-right: 4px;
}

.conversation-item.active .conversation-item-icon {
  color: #008080;
}

.conversation-item-meta {
  display: flex;
  gap: 8px;
  font-size: 0.7rem;
  color: #8e8ea0;
  margin-top: 2px;
}

.conversation-item-preview {
  font-size: 0.75rem;
  color: #b0b0b0;
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.conversations-loading,
.conversations-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100px;
  color: #8e8ea0;
  font-size: 0.85rem;
}

/* ============================================
   Responsive: Full-screen on mobile (<576px)
   ============================================ */
@media (max-width: 575.98px) {
  .chat-widget-fab {
    width: 38px;
    padding: 10px 0;
    font-size: 1.1rem;
  }

  .chat-widget-fab span {
    font-size: 0.55rem;
  }

  body.chat-panel-open .chat-widget-fab {
    display: none;
  }

  .chat-widget-panel {
    width: 100%;
    height: 100%;
    border-left: none;
  }

  body.chat-panel-open .layout-page {
    margin-right: 0;
  }

  body.chat-panel-open .layout-navbar {
    right: 0;
  }

  body.chat-panel-open .layout-navbar.navbar-detached {
    width: calc(100% - 1rem * 2) !important;
  }
}
