/* ============================================================
   Bloom Platform - Component Styles
   Reusable UI component overrides and specific modules
   ============================================================ */

/* ── Rich Text Editor ──────────────────────────────────────────────────────── */
.rte-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
  padding: var(--space-2) var(--space-3);
  background: var(--cream);
  border: 1px solid var(--border);
  border-bottom: none;
  border-radius: var(--radius) var(--radius) 0 0;
}
.rte-btn {
  padding: 3px 8px;
  font-size: 0.8rem;
  background: white;
  border: 1px solid var(--border);
  border-radius: 3px;
  cursor: pointer;
  color: var(--ink);
  line-height: 1.4;
  font-family: var(--font-body);
}
.rte-btn:hover { background: var(--sage-pale); border-color: var(--sage); }
.rte-sep { width: 1px; background: var(--border); margin: 2px 4px; align-self: stretch; }
.rte-area {
  min-height: 420px;
  padding: var(--space-5) var(--space-6);
  border: 1px solid var(--border);
  border-radius: 0 0 var(--radius) var(--radius);
  outline: none;
  font-family: var(--font-body);
  font-size: 0.9375rem;
  line-height: 1.75;
  color: var(--ink);
  background: white;
  overflow-y: auto;
}
.rte-area:focus { border-color: var(--sage); box-shadow: 0 0 0 3px rgba(107,158,114,0.15); }
.rte-area h2 { font-family: var(--font-heading); font-size: 1.25rem; color: var(--ink); margin: 1.4em 0 0.5em; font-weight: 600; }
.rte-area h3 { font-family: var(--font-heading); font-size: 1.05rem; color: var(--sage-d); margin: 1.2em 0 0.4em; font-weight: 600; }
.rte-area p  { margin: 0 0 0.75em; }
.rte-area ul { padding-left: 1.5em; margin: 0 0 0.75em; }
.rte-area li { margin-bottom: 0.25em; }

/* ── Report Score Tables (inside rte-area) ─────────────────────────────────── */
.rte-area table,
.report-view table {
  width: 100%;
  border-collapse: collapse;
  margin: 1.25em 0;
  font-size: 0.875rem;
}
.rte-area table th,
.rte-area table td,
.report-view table th,
.report-view table td {
  border: 1px solid #ccc;
  padding: 7px 10px;
  text-align: left;
  vertical-align: middle;
}
.rte-area table th,
.report-view table th {
  background: var(--sage-pale);
  font-weight: 600;
  color: var(--ink);
}
/* Domain header row */
.rte-area .rpt-domain-header,
.report-view .rpt-domain-header {
  background: var(--sage);
  color: white;
  font-weight: 700;
  font-size: 0.9rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
/* Score column headers & legend cells */
.rte-area .rpt-below,
.report-view .rpt-below { background: #fde8e8; color: #9b2020; font-weight: 600; }
.rte-area .rpt-border,
.report-view .rpt-border { background: #fef9e7; color: #7a5c00; font-weight: 600; }
.rte-area .rpt-on,
.report-view .rpt-on    { background: #e8f5e9; color: #256029; font-weight: 600; }
/* Legend table cells */
.rte-area .rpt-legend td,
.report-view .rpt-legend td { font-size: 0.82rem; padding: 6px 12px; }
/* Score mark */
.rte-area .rpt-scores tbody td,
.report-view .rpt-scores tbody td { text-align: center; font-size: 1rem; }
/* Domain explainer box */
.rte-area .rpt-explainer,
.report-view .rpt-explainer {
  background: var(--sage-pale);
  border-left: 3px solid var(--sage);
  border-radius: 0 6px 6px 0;
  padding: 10px 14px;
  margin: 1.4em 0 0.6em;
  font-size: 0.875rem;
  color: var(--ink-l);
  line-height: 1.55;
}
/* Legend table full width */
.rte-area .rpt-legend,
.report-view .rpt-legend { max-width: 100%; margin-bottom: 1.5em; }
.rte-area .rpt-legend th,
.report-view .rpt-legend th { background: var(--sage-pale); font-weight: 600; font-size: 0.82rem; padding: 6px 12px; }

/* ── Patient Card (compact list item) ────────────────────── */
.patient-card {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius);
  cursor: pointer;
  transition: background var(--transition);
  border: 1px solid transparent;
}
.patient-card:hover {
  background: var(--sage-pale);
  border-color: var(--sage-l);
}
.patient-card.selected {
  background: var(--sage-pale);
  border-color: var(--sage);
}

.patient-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--sage-l), var(--sage));
  color: var(--white);
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.875rem;
  flex-shrink: 0;
}

.patient-name {
  font-weight: 500;
  font-size: 0.9375rem;
  color: var(--ink);
}

.patient-meta {
  font-size: 0.8125rem;
  color: var(--ink-l);
}

/* ── Timeline ─────────────────────────────────────────────── */
.timeline {
  position: relative;
  padding-left: var(--space-6);
}

.timeline::before {
  content: '';
  position: absolute;
  left: 12px;
  top: 0;
  bottom: 0;
  width: 2px;
  background: var(--sage-l);
  border-radius: 2px;
}

.timeline-item {
  position: relative;
  margin-bottom: var(--space-4);
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-3) var(--space-4);
  box-shadow: var(--shadow-sm);
}

.timeline-item::before {
  content: '';
  position: absolute;
  left: calc(-1 * var(--space-6) + 8px);
  top: 14px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--sage);
  border: 2px solid var(--white);
  box-shadow: 0 0 0 2px var(--sage-l);
}

.timeline-date {
  font-size: 0.75rem;
  color: var(--ink-l);
  margin-bottom: var(--space-1);
  font-weight: 500;
  letter-spacing: 0.04em;
}

.timeline-title {
  font-size: 0.9375rem;
  color: var(--ink);
  font-weight: 500;
}

/* ── Session Feedback Card ────────────────────────────────── */
.feedback-card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

.feedback-collage {
  width: 100%;
  max-height: 280px;
  object-fit: cover;
}

.feedback-body {
  padding: var(--space-4) var(--space-5);
}

.feedback-message {
  font-family: var(--font-display);
  font-size: 1rem;
  line-height: 1.7;
  color: var(--ink-m);
  white-space: pre-wrap;
}

/* ── Invoice Table ────────────────────────────────────────── */
.invoice-total-row {
  font-weight: 600;
  font-size: 1rem;
  color: var(--sage-d);
  background: var(--sage-pale) !important;
}

/* ── Appointment Slot ─────────────────────────────────────── */
.appointment-slot {
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius);
  border-left: 4px solid var(--sage);
  background: var(--sage-pale);
  margin-bottom: var(--space-2);
}

.appointment-slot.cancelled {
  border-left-color: var(--ink-l);
  background: #f5f5f5;
  opacity: 0.7;
}

.appointment-slot.no-show {
  border-left-color: var(--rust);
  background: var(--rust-l);
}

.appointment-slot.completed {
  border-left-color: var(--sage-d);
}

/* ── Collage Upload ───────────────────────────────────────── */
.upload-zone {
  border: 2px dashed var(--sage-l);
  border-radius: var(--radius-lg);
  padding: var(--space-7) var(--space-5);
  text-align: center;
  cursor: pointer;
  transition: all var(--transition);
  background: var(--sage-pale);
}
.upload-zone:hover, .upload-zone.drag-over {
  border-color: var(--sage);
  background: var(--sage-pale);
}
.upload-zone input[type=file] { display: none; }

.upload-icon {
  width: 48px;
  height: 48px;
  margin: 0 auto var(--space-3);
  color: var(--sage-l);
}

/* ── Report Form Wizard ───────────────────────────────────── */
.wizard-steps {
  display: flex;
  gap: 0;
  margin-bottom: var(--space-6);
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.wizard-step {
  flex: 1;
  padding: var(--space-3) var(--space-2);
  text-align: center;
  font-size: 0.8125rem;
  color: var(--ink-l);
  border-right: 1px solid var(--border);
  background: var(--white);
  cursor: pointer;
  transition: all var(--transition);
}
.wizard-step:last-child { border-right: none; }
.wizard-step:hover { background: var(--sage-pale); }
.wizard-step.active {
  background: var(--sage);
  color: var(--white);
  font-weight: 500;
}
.wizard-step.done {
  background: var(--sage-pale);
  color: var(--sage-d);
}

.wizard-step-num {
  display: block;
  font-size: 1.125rem;
  font-family: var(--font-display);
  margin-bottom: 2px;
}

/* ── EASI Score Grid ──────────────────────────────────────── */
.easi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: var(--space-3);
}

.easi-area {
  background: var(--sage-pale);
  border: 1px solid var(--sage-l);
  border-radius: var(--radius);
  padding: var(--space-3);
}

.easi-area-name {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--sage-d);
  margin-bottom: var(--space-2);
}

.easi-score-display {
  font-family: var(--font-display);
  font-size: 2rem;
  color: var(--sage-d);
}

/* ── Notification Dropdown ────────────────────────────────── */
.notif-dropdown {
  position: absolute;
  right: var(--space-4);
  top: 52px;
  width: 360px;
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  z-index: 500;
  overflow: hidden;
  animation: slide-up 150ms ease;
}

.notif-dropdown-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border);
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--ink-m);
}

.notif-item {
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background var(--transition);
}
.notif-item:last-child { border-bottom: none; }
.notif-item:hover { background: var(--sage-pale); }
.notif-item.unread { background: #f4faf5; }

.notif-item-title {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--ink);
}
.notif-item-body {
  font-size: 0.8125rem;
  color: var(--ink-l);
  margin-top: 2px;
}
.notif-item-time {
  font-size: 0.75rem;
  color: var(--ink-l);
  margin-top: var(--space-1);
}

/* ── Store Product Grid ───────────────────────────────────── */
.product-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: var(--space-4);
}

.product-card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  transition: box-shadow var(--transition), transform var(--transition);
  cursor: pointer;
}
.product-card:hover {
  box-shadow: var(--shadow);
  transform: translateY(-2px);
}

.product-thumb {
  aspect-ratio: 16/10;
  background: var(--sage-pale);
  object-fit: cover;
  width: 100%;
}

.product-info {
  padding: var(--space-3) var(--space-4);
}

.product-name {
  font-weight: 500;
  font-size: 0.9375rem;
  color: var(--ink);
  margin-bottom: var(--space-1);
}

.product-price {
  font-family: var(--font-display);
  font-size: 1.25rem;
  color: var(--sage-d);
}

/* ── Topbar User Menu ─────────────────────────────────────── */
.user-menu-trigger {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  cursor: pointer;
  padding: var(--space-1) var(--space-2);
  border-radius: var(--radius);
  transition: background var(--transition);
  background: none;
  border: none;
}
.user-menu-trigger:hover { background: var(--sage-pale); }

.user-menu-name {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--ink-m);
}

/* ── Search Bar ───────────────────────────────────────────── */
.search-bar {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  background: var(--sage-pale);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 6px var(--space-3);
  flex: 1;
  max-width: 360px;
}

.search-bar input {
  border: none;
  background: transparent;
  outline: none;
  color: var(--ink);
  font-size: 0.875rem;
  flex: 1;
}

.search-bar input::placeholder { color: var(--ink-l); }

/* ── AI Loading Indicator ─────────────────────────────────── */
.ai-generating {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-4);
  background: linear-gradient(135deg, var(--sage-pale), #f0f4fe);
  border: 1px solid var(--sage-l);
  border-radius: var(--radius);
  color: var(--sage-d);
  font-size: 0.875rem;
}

.ai-dots {
  display: flex;
  gap: 4px;
}

.ai-dots span {
  width: 8px;
  height: 8px;
  background: var(--sage);
  border-radius: 50%;
  animation: ai-bounce 1.2s ease infinite;
}
.ai-dots span:nth-child(2) { animation-delay: 0.2s; }
.ai-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes ai-bounce {
  0%, 80%, 100% { transform: scale(0.7); opacity: 0.5; }
  40%            { transform: scale(1.1); opacity: 1; }
}

/* ── Scrollbar Styling ────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--sage-l);
  border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover { background: var(--sage); }

/* ── Tab Bar (used in Resources, etc.) ───────────────────── */
.tabs {
  display: flex;
  gap: 4px;
  border-bottom: 2px solid var(--border);
}

.tab {
  padding: var(--space-2) var(--space-4);
  border: none;
  border-bottom: 2px solid transparent;
  background: transparent;
  color: var(--ink-l);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  margin-bottom: -2px;
  transition: color .15s, border-color .15s;
}

.tab:hover { color: var(--sage-d); }

.tab.active {
  color: var(--sage-d);
  border-bottom-color: var(--sage-d);
}

/* ── Badge variants ──────────────────────────────────────── */
.badge-sage      { background: var(--sage-pale);  color: var(--sage-d); }
.badge-success   { background: #d1fae5; color: #065f46; }
.badge-error     { background: #fee2e2; color: #991b1b; }
.badge-warning   { background: #fef3c7; color: #92400e; }
.badge-info      { background: #dbeafe; color: #1e40af; }
.badge-secondary { background: var(--surface-alt); color: var(--ink-l); }
.badge-rust      { background: #fde8e2; color: var(--rust); }

/* ── Knowledge Base Resource Grid ───────────────────────── */
.resource-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: var(--space-4);
}

.resource-card {
  cursor: pointer;
  padding: 0;
  overflow: hidden;
  transition: transform .15s, box-shadow .15s;
}

.resource-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}

.resource-thumb {
  width: 100%;
  height: 140px;
  object-fit: cover;
  display: block;
}

.resource-thumb-placeholder {
  width: 100%;
  height: 140px;
  background: var(--sage-pale);
  display: flex;
  align-items: center;
  justify-content: center;
}

.resource-card-body {
  padding: var(--space-3) var(--space-4) var(--space-4);
}

.resource-title {
  font-weight: 600;
  font-size: 0.9375rem;
  color: var(--ink);
  line-height: 1.4;
}

/* ── Toggle Switch ────────────────────────────────────────────────────────── */

.toggle-switch {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
  flex-shrink: 0;
  cursor: pointer;
}

.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
  position: absolute;
}

.toggle-slider {
  position: absolute;
  inset: 0;
  background: var(--border);
  border-radius: 99px;
  transition: background 0.2s ease;
}

.toggle-slider::before {
  content: '';
  position: absolute;
  width: 18px;
  height: 18px;
  left: 3px;
  top: 3px;
  background: white;
  border-radius: 50%;
  transition: transform 0.2s ease;
  box-shadow: 0 1px 3px rgba(0,0,0,.2);
}

.toggle-switch input:checked + .toggle-slider {
  background: var(--sage);
}

.toggle-switch input:checked + .toggle-slider::before {
  transform: translateX(20px);
}

.toggle-switch input:focus-visible + .toggle-slider {
  outline: 2px solid var(--sage);
  outline-offset: 2px;
}

/* ── Responsive Component Overrides ──────────────────────── */
@media (max-width: 768px) {
  /* Patient cards: tighter on mobile */
  .patient-card { padding: var(--space-2) var(--space-3); gap: var(--space-2); }
  .patient-avatar { width: 36px; height: 36px; font-size: 0.75rem; }
  .patient-name { font-size: 0.875rem; }
  .patient-meta { font-size: 0.75rem; }

  /* Product grid: 2 cols, then 1 */
  .product-grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: var(--space-3); }
  .resource-grid { grid-template-columns: 1fr; }

  /* EASI grid: single column */
  .easi-grid { grid-template-columns: 1fr; }

  /* Feedback card */
  .feedback-collage { max-height: 180px; }
  .feedback-body { padding: var(--space-3); }

  /* Upload zone: less padding */
  .upload-zone { padding: var(--space-5) var(--space-3); }

  /* User dropdown: position better on mobile */
  #user-dropdown {
    right: var(--space-2) !important;
    top: 52px !important;
  }

  /* Patient profile tabs: scrollable horizontal */
  .tabs {
    flex-wrap: nowrap !important;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    gap: 0;
    padding-bottom: 2px;
    max-width: 100%;
    width: 100%;
  }
  .tabs::-webkit-scrollbar { display: none; }
  .tabs .tab {
    flex-shrink: 0;
    font-size: 0.75rem;
    padding: 6px 10px;
    white-space: nowrap;
  }

  /* Grid children: prevent blowout */
  [style*="display:grid"] > * {
    min-width: 0;
  }

  /* Patient profile photo: smaller on mobile */
  [style*="width:100px;height:100px;border-radius:50%"] {
    width: 64px !important;
    height: 64px !important;
    font-size: 1.5rem !important;
  }

  /* Inline flex layouts: wrap on mobile when too wide */
  [style*="display:flex;justify-content:space-between"] {
    flex-wrap: wrap;
    gap: var(--space-2);
  }

  /* SNAP-IV and screening test grids */
  [style*="grid-template-columns:repeat(auto-fill,minmax(120px"] {
    grid-template-columns: repeat(auto-fill, minmax(90px, 1fr)) !important;
  }

  /* Inline max-width constraints: allow full width */
  [style*="max-width:760px"],
  [style*="max-width:900px"],
  [style*="max-width:820px"],
  [style*="max-width:1100px"] {
    max-width: 100% !important;
  }

  /* Overlays/modals from JS: make full-width */
  [id$="-overlay"] > .card,
  [id$="-overlay"] > div > .card {
    width: 100% !important;
    max-width: 100% !important;
    max-height: 90vh;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  }

  /* Schedule week grid */
  [style*="grid-template-columns:repeat(7"] {
    grid-template-columns: repeat(7, minmax(36px, 1fr)) !important;
    font-size: 0.7rem;
  }

  /* Buttons in page headers: wrap */
  .page-header > div:last-child {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
  }

  /* RTE area: smaller */
  .rte-area {
    min-height: 200px;
    padding: var(--space-3);
    font-size: 0.875rem;
  }
  .rte-toolbar { padding: var(--space-1) var(--space-2); }
  .rte-btn { padding: 2px 6px; font-size: 0.75rem; }
}
