/* ==========================================================
   AI SPEECH THERAPY ASSISTANT CHATBOT STYLE
   Coordinates with tokens.css to provide an integrated design
   ========================================================== */

/* --- Floating Launcher Button --- */
.cb-launcher {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 60px;
  height: 60px;
  border-radius: var(--radius-full);
  background: var(--accent);
  color: var(--white);
  border: none;
  box-shadow: var(--shadow-lg);
  cursor: pointer;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform var(--t-fast) var(--ease), background var(--t-fast) var(--ease), box-shadow var(--t-fast) var(--ease);
}

.cb-launcher:hover {
  transform: scale(1.08) rotate(5deg);
  background: var(--accent-hover);
  box-shadow: var(--shadow-xl);
}

.cb-launcher svg {
  width: 28px;
  height: 28px;
  fill: currentColor;
  transition: transform var(--t-base) var(--ease);
}

.cb-launcher.cb-active svg {
  transform: rotate(90deg);
}

/* --- Main Chat Window Container --- */
.cb-window {
  position: fixed;
  bottom: 96px;
  right: 24px;
  width: 380px;
  height: 600px;
  max-height: calc(100vh - 120px);
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid rgba(255, 255, 255, 0.5);
  box-shadow: var(--shadow-xl);
  border-radius: var(--radius-lg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 9998;
  opacity: 0;
  transform: translateY(20px) scale(0.95);
  pointer-events: none;
  transition: opacity var(--t-base) var(--ease), transform var(--t-base) var(--ease);
}

.cb-window.cb-open {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: all;
}

/* --- Header Section --- */
.cb-header {
  background: linear-gradient(135deg, var(--peach) 0%, var(--blush) 100%);
  padding: var(--space-4);
  color: var(--text-primary);
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border-light);
}

.cb-header-profile {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.cb-avatar {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-full);
  background: var(--white);
  border: 2px solid var(--white);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: var(--fw-bold);
  color: var(--accent);
}

.cb-header-title {
  font-family: var(--font-heading);
  font-size: var(--fs-base);
  font-weight: var(--fw-bold);
  line-height: var(--lh-tight);
}

.cb-header-subtitle {
  font-size: var(--fs-xs);
  color: var(--text-secondary);
}

.cb-header-actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.cb-lang-select {
  background: rgba(255, 255, 255, 0.7);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 2px var(--space-1);
  font-size: var(--fs-xs);
  font-family: var(--font-body);
  color: var(--text-primary);
  cursor: pointer;
  outline: none;
  transition: background var(--t-fast);
}

.cb-lang-select:hover {
  background: var(--white);
}

.cb-close-btn {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-size: 20px;
  cursor: pointer;
  padding: 4px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.cb-close-btn:hover {
  color: var(--text-primary);
}

/* --- Disclaimer Bar --- */
.cb-disclaimer {
  background: var(--cream-warm);
  color: var(--text-secondary);
  font-size: calc(var(--fs-xs) - 1px);
  padding: var(--space-2) var(--space-4);
  line-height: var(--lh-tight);
  border-bottom: 1px solid var(--border-light);
  text-align: center;
  font-style: italic;
}

/* --- Chat Message Area --- */
.cb-messages {
  flex: 1;
  padding: var(--space-4);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  scroll-behavior: smooth;
}

/* --- Message Bubble Formatting --- */
.cb-message {
  max-width: 85%;
  display: flex;
  flex-direction: column;
  animation: cb-fade-in var(--t-base) var(--ease-out) forwards;
}

.cb-message-text {
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  font-size: var(--fs-sm);
  line-height: var(--lh-snug);
  word-wrap: break-word;
}

.cb-message-text p {
  margin: 0 0 var(--space-2) 0;
}
.cb-message-text p:last-child {
  margin-bottom: 0;
}

.cb-message-text ul, .cb-message-text ol {
  margin: var(--space-2) 0;
  padding-left: var(--space-5);
}

.cb-message-time {
  font-size: calc(var(--fs-xs) - 1px);
  color: var(--text-muted);
  margin-top: 4px;
  align-self: flex-start;
}

/* --- Bot vs User Bubbles --- */
.cb-msg-bot {
  align-self: flex-start;
}

.cb-msg-bot .cb-message-text {
  background: var(--white);
  color: var(--text-primary);
  border-bottom-left-radius: 4px;
  box-shadow: var(--shadow-sm);
  border: 1px solid rgba(92, 74, 60, 0.04);
}

.cb-msg-user {
  align-self: flex-end;
}

.cb-msg-user .cb-message-text {
  background: var(--accent);
  color: var(--white);
  border-bottom-right-radius: 4px;
  box-shadow: var(--shadow-sm);
}

.cb-msg-user .cb-message-time {
  align-self: flex-end;
}

/* --- Quick Suggestions Pills --- */
.cb-suggestions {
  padding: 0 var(--space-4) var(--space-2) var(--space-4);
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  max-height: 120px;
  overflow-y: auto;
}

.cb-suggest-pill {
  background: rgba(255, 255, 255, 0.7);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  padding: 6px 12px;
  border-radius: var(--radius-full);
  font-size: var(--fs-xs);
  cursor: pointer;
  transition: all var(--t-fast) var(--ease);
  font-family: var(--font-body);
}

.cb-suggest-pill:hover {
  background: var(--accent);
  color: var(--white);
  border-color: var(--accent);
  transform: translateY(-1px);
}

/* --- Input Bar --- */
.cb-input-area {
  padding: var(--space-3) var(--space-4);
  background: var(--white);
  border-top: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.cb-input {
  flex: 1;
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  padding: 10px var(--space-4);
  font-size: var(--fs-sm);
  font-family: var(--font-body);
  color: var(--text-primary);
  outline: none;
  background: var(--cream);
  transition: all var(--t-fast);
}

.cb-input:focus {
  border-color: var(--accent);
  background: var(--white);
  box-shadow: 0 0 0 3px rgba(244, 160, 122, 0.2);
}

.cb-send-btn {
  background: var(--accent);
  color: var(--white);
  border: none;
  width: 38px;
  height: 38px;
  border-radius: var(--radius-full);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--t-fast), transform var(--t-fast);
}

.cb-send-btn:hover {
  background: var(--accent-hover);
  transform: scale(1.05);
}

.cb-send-btn svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
}

/* --- Flow Action Buttons inside chat --- */
.cb-action-row {
  display: flex;
  gap: var(--space-2);
  margin-top: var(--space-2);
  flex-wrap: wrap;
}

.cb-action-btn {
  flex: 1;
  min-width: 120px;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  font-size: var(--fs-xs);
  font-family: var(--font-heading);
  font-weight: var(--fw-bold);
  cursor: pointer;
  border: none;
  text-align: center;
  transition: all var(--t-fast);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
}

.cb-btn-primary {
  background: var(--accent);
  color: var(--white);
}
.cb-btn-primary:hover {
  background: var(--accent-hover);
}

.cb-btn-secondary {
  background: var(--peach-light);
  color: var(--text-primary);
  border: 1px solid var(--border);
}
.cb-btn-secondary:hover {
  background: var(--peach);
}

/* --- Form Interfaces (Scheduling/Escalation/Feedback) --- */
.cb-form-panel {
  background: var(--cream);
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  padding: var(--space-4);
  margin-top: var(--space-2);
  width: 100%;
}

.cb-form-title {
  font-family: var(--font-heading);
  font-size: var(--fs-sm);
  font-weight: var(--fw-bold);
  margin-bottom: var(--space-3);
  color: var(--text-primary);
  border-bottom: 1px solid var(--border-light);
  padding-bottom: var(--space-2);
}

.cb-form-group {
  margin-bottom: var(--space-3);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.cb-form-group label {
  font-size: var(--fs-xs);
  font-weight: var(--fw-medium);
  color: var(--text-secondary);
}

.cb-form-control {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  font-size: var(--fs-xs);
  font-family: var(--font-body);
  outline: none;
  background: var(--white);
}

.cb-form-control:focus {
  border-color: var(--accent);
}

/* --- Scheduling Grid --- */
.cb-grid-select {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
  max-height: 120px;
  overflow-y: auto;
  padding: 2px;
}

.cb-grid-item {
  background: var(--white);
  border: 1px solid var(--border);
  padding: 6px;
  border-radius: var(--radius-sm);
  font-size: calc(var(--fs-xs) - 1px);
  text-align: center;
  cursor: pointer;
  transition: all var(--t-fast);
}

.cb-grid-item:hover {
  background: var(--peach-light);
}

.cb-grid-item.cb-selected {
  background: var(--accent);
  color: var(--white);
  border-color: var(--accent);
  font-weight: var(--fw-semi);
}

/* --- Rating Component --- */
.cb-stars {
  display: flex;
  gap: var(--space-2);
  justify-content: center;
  margin: var(--space-3) 0;
}

.cb-star-svg {
  width: 32px;
  height: 32px;
  cursor: pointer;
  fill: #E2E8F0;
  transition: fill var(--t-fast);
}

.cb-star-svg.cb-active, .cb-star-svg:hover, .cb-star-svg:hover ~ .cb-star-svg {
  fill: #FBBF24;
}

/* --- Typing Indicator --- */
.cb-typing {
  align-self: flex-start;
  background: var(--white);
  border-radius: var(--radius-md);
  border-bottom-left-radius: 4px;
  border: 1px solid rgba(92, 74, 60, 0.04);
  box-shadow: var(--shadow-sm);
  padding: var(--space-3) var(--space-4);
  display: flex;
  align-items: center;
  gap: 4px;
}

.cb-typing-dot {
  width: 6px;
  height: 6px;
  border-radius: var(--radius-full);
  background: var(--text-muted);
  animation: cb-bounce 1.4s infinite ease-in-out both;
}

.cb-typing-dot:nth-child(1) { animation-delay: -0.32s; }
.cb-typing-dot:nth-child(2) { animation-delay: -0.16s; }

/* --- Dynamic Right-to-Left Direction support (Arabic) --- */
.cb-rtl {
  direction: rtl;
  text-align: right;
}

.cb-rtl .cb-header-profile {
  flex-direction: row-reverse;
}

.cb-rtl .cb-msg-bot {
  align-self: flex-start;
}

.cb-rtl .cb-msg-bot .cb-message-text {
  border-bottom-left-radius: var(--radius-md);
  border-bottom-right-radius: 4px;
}

.cb-rtl .cb-msg-user {
  align-self: flex-end;
}

.cb-rtl .cb-msg-user .cb-message-text {
  border-bottom-right-radius: var(--radius-md);
  border-bottom-left-radius: 4px;
}

.cb-rtl .cb-message-time {
  align-self: flex-end;
}

.cb-rtl .cb-msg-user .cb-message-time {
  align-self: flex-start;
}

.cb-rtl .cb-input-area {
  flex-direction: row-reverse;
}

.cb-rtl .cb-send-btn svg {
  transform: scaleX(-1);
}

.cb-rtl .cb-form-group label {
  text-align: right;
}

/* --- Animations --- */
@keyframes cb-fade-in {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes cb-bounce {
  0%, 80%, 100% { transform: scale(0); }
  40% { transform: scale(1.0); }
}

/* --- Responsive Adjustments --- */
@media (max-width: 500px) {
  .cb-launcher {
    bottom: 16px;
    right: 16px;
  }
}

/* ==========================================================
   STANDALONE WEB APPLICATION DASHBOARD LAYOUT
   ========================================================== */
.app-container {
  display: flex;
  min-height: 100vh;
  background: var(--cream);
  font-family: var(--font-body);
}

.app-sidebar {
  width: 280px;
  background: var(--cream-warm);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: var(--space-6);
  flex-shrink: 0;
  box-shadow: var(--shadow-sm);
}

.app-brand {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin-bottom: var(--space-8);
  text-decoration: none;
}

.app-brand img {
  width: 32px;
  height: 32px;
}

.app-brand-text {
  display: flex;
  flex-direction: column;
}

.app-brand-name {
  font-family: var(--font-heading);
  font-size: var(--fs-md);
  font-weight: var(--fw-bold);
  color: var(--text-primary);
  line-height: var(--lh-tight);
}

.app-brand-tagline {
  font-size: var(--fs-xs);
  color: var(--text-secondary);
}

.app-menu {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  flex: 1;
}

.app-menu-btn {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: 12px var(--space-4);
  border-radius: var(--radius-md);
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-size: var(--fs-sm);
  font-weight: var(--fw-medium);
  cursor: pointer;
  text-align: left;
  transition: all var(--t-fast);
  width: 100%;
}

.app-menu-btn svg {
  width: 20px;
  height: 20px;
  fill: currentColor;
}

.app-menu-btn:hover, .app-menu-btn.active {
  background: var(--peach-light);
  color: var(--text-primary);
}

.app-menu-btn.active {
  font-weight: var(--fw-bold);
  border-left: 4px solid var(--accent);
  border-radius: 0 var(--radius-md) var(--radius-md) 0;
  padding-left: calc(var(--space-4) - 4px);
}

.app-sidebar-footer {
  border-top: 1px solid var(--border-light);
  padding-top: var(--space-4);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.app-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.app-bar {
  height: var(--nav-h);
  background: var(--white);
  border-bottom: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--space-6);
  box-shadow: var(--shadow-sm);
}

.app-bar-title {
  font-family: var(--font-heading);
  font-size: var(--fs-lg);
  font-weight: var(--fw-bold);
  color: var(--text-primary);
}

.app-content {
  flex: 1;
  padding: var(--space-6);
  overflow-y: auto;
}

.app-panel {
  display: none;
  animation: cb-fade-in var(--t-base) var(--ease-out) forwards;
  height: 100%;
}

.app-panel.active {
  display: block;
}

/* --- App Chat Module Layout --- */
.app-chat-layout {
  display: flex;
  height: calc(100vh - var(--nav-h) - var(--space-12));
  background: var(--white);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  overflow: hidden;
  border: 1px solid var(--border-light);
}

.app-chat-window {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100%;
}

.app-chat-sidebar {
  width: 320px;
  border-left: 1px solid var(--border-light);
  background: var(--cream-warm);
  display: flex;
  flex-direction: column;
  padding: var(--space-5);
  overflow-y: auto;
}

/* --- Metrics Grid --- */
.metrics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: var(--space-4);
  margin-bottom: var(--space-6);
}

.metric-card {
  background: var(--white);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  padding: var(--space-5);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  box-shadow: var(--shadow-sm);
}

.metric-label {
  font-size: var(--fs-xs);
  color: var(--text-muted);
  font-weight: var(--fw-bold);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.metric-value {
  font-family: var(--font-heading);
  font-size: var(--fs-xl);
  font-weight: var(--fw-xbold);
  color: var(--text-primary);
}

.metric-sub {
  font-size: calc(var(--fs-xs) - 1px);
  color: var(--text-secondary);
}

/* --- Analytics Visualization Charts --- */
.charts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(360px, 1fr));
  gap: var(--space-6);
  margin-bottom: var(--space-6);
}

.chart-card {
  background: var(--white);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  padding: var(--space-5);
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.chart-title {
  font-family: var(--font-heading);
  font-size: var(--fs-sm);
  font-weight: var(--fw-bold);
  color: var(--text-primary);
  border-bottom: 1px solid var(--border-light);
  padding-bottom: var(--space-2);
}

.chart-body {
  height: 220px;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

/* --- Database Lists & Tables --- */
.table-card {
  background: var(--white);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  padding: var(--space-5);
  box-shadow: var(--shadow-sm);
  margin-bottom: var(--space-6);
}

.table-wrapper {
  overflow-x: auto;
  margin-top: var(--space-3);
  max-height: 400px;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: var(--fs-xs);
}

.data-table th, .data-table td {
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border-light);
}

.data-table th {
  background: var(--cream-warm);
  color: var(--text-primary);
  font-weight: var(--fw-bold);
  position: sticky;
  top: 0;
  z-index: 10;
}

.data-table tr:hover {
  background: var(--cream);
}

.sentiment-badge {
  display: inline-block;
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  font-weight: var(--fw-semi);
}

.badge-positive { background: #D1FAE5; color: #065F46; }
.badge-neutral { background: #F3F4F6; color: #374151; }
.badge-negative { background: #FEE2E2; color: #991B1B; }

/* Custom Progress Bar for topic stats */
.topic-progress-row {
  display: flex;
  flex-direction: column;
  gap: 4px;
  width: 100%;
  margin-bottom: var(--space-3);
}

.topic-progress-labels {
  display: flex;
  justify-content: space-between;
  font-size: var(--fs-xs);
  color: var(--text-secondary);
}

.topic-progress-bar-bg {
  height: 8px;
  background: var(--border-light);
  border-radius: var(--radius-full);
  overflow: hidden;
}

.topic-progress-bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: var(--radius-full);
}

/* --- Responsive Layout Rules --- */
@media (max-width: 992px) {
  .app-sidebar {
    width: 80px;
    padding: var(--space-4) var(--space-2);
    align-items: center;
  }
  
  .app-brand-text, .app-brand-tagline, .app-menu-btn span, .app-sidebar-footer span {
    display: none;
  }
  
  .app-brand {
    margin-bottom: var(--space-6);
  }
  
  .app-menu-btn {
    justify-content: center;
    padding: var(--space-3);
  }
  
  .app-chat-layout {
    flex-direction: column;
    height: auto;
  }
  
  .app-chat-sidebar {
    width: 100%;
    border-left: none;
    border-top: 1px solid var(--border-light);
    height: 300px;
  }
}

