/* css/analytics.css - Engagement & Audit Views */

.sa-engagement-layout {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(280px, 1fr);
  gap: 14px;
}

@media (max-width: 900px) {
  .sa-engagement-layout {
    grid-template-columns: 1fr;
  }
}

.sa-report-frame {
  margin-top: 8px;
  border-radius: 10px;
  background: rgba(15, 23, 42, 0.5);
  padding: 10px;
  min-height: 300px;
  display: flex;
  flex-direction: column;
}

/* Upload Dropzone Improvements */
.sa-dropzone {
  border-radius: 12px;
  border: 1px dashed var(--border-slate);
  padding: 24px 10px;
  text-align: center;
  transition: all 0.15s ease;
}

.sa-dropzone:hover {
  border-color: var(--accent-blue);
  background: rgba(56, 189, 248, 0.05);
}

.sa-progress {
  margin-top: 12px;
  width: 100%;
  height: 6px;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.8);
  overflow: hidden;
}

.sa-progress-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #38bdf8, #22c55e);
  transition: width 0.25s ease;
}

/* --- Social Authority Accordion System --- */
.sa-analytics-container {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 20px;
}

.sa-accordion-item {
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid rgba(255, 255, 255, 0.05);
  border-radius: 12px;
  overflow: hidden;
  transition: all 0.3s ease;
  backdrop-filter: blur(10px);
}

.sa-accordion-item[open] {
  background: rgba(3, 5, 18, 0.6);
  border-color: rgba(167, 139, 250, 0.3);
  /* Lila sutil al abrir */
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
}

.sa-accordion-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 24px;
  cursor: pointer;
  list-style: none;
  /* Ocultar triángulo default */
}

.sa-accordion-header::-webkit-details-marker {
  display: none;
}

.sa-header-content h3 {
  margin: 0;
  font-size: 1.1rem;
  color: #fff;
  font-weight: 600;
}

.sa-header-content p {
  margin: 4px 0 0;
  font-size: 0.85rem;
  color: #94a3b8;
}

.sa-icon-toggle {
  font-size: 1.5rem;
  color: #a78bfa;
  /* Lila */
  transition: transform 0.3s ease;
}

details[open] .sa-icon-toggle {
  transform: rotate(45deg);
  /* Efecto de + a x */
  color: #2dd4bf;
  /* Cambia a Aqua al abrir */
}

.sa-accordion-body {
  padding: 0 24px 24px;
  border-top: 1px solid rgba(255, 255, 255, 0.05);
  animation: slideDown 0.3s ease-out;
}

/* KPI Grid */
.sa-kpi-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin-bottom: 24px;
  margin-top: 24px;
}

.sa-kpi-grid--4col {
  grid-template-columns: repeat(4, 1fr);
}

.sa-kpi-card {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.08);
  padding: 20px;
  border-radius: 16px;
  text-align: center;
  display: flex !important;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 140px;
  transition: transform 0.2s ease, border-color 0.2s ease;
}

/* Scoped Audit KPIs to match Engagement Premium look */
.sa-audit-kpi-grid {
  gap: 20px !important;
  margin-top: 25px !important;
}

.sa-audit-kpi-grid .sa-kpi-card {
  padding: 30px 20px !important;
  border-radius: 20px !important;
  min-height: 160px !important;
  background: rgba(255, 255, 255, 0.04) !important;
  border-color: rgba(255, 255, 255, 0.12) !important;
}

.sa-kpi-card:hover {
  transform: translateY(-2px);
  border-color: rgba(167, 139, 250, 0.4);
}

/* Ensure hidden cards get flexed correctly when shown */
.sa-kpi-hidden {
  display: none !important;
}

.sa-tabpanel.is-expanded .sa-kpi-hidden {
  display: flex !important;
  flex-direction: column;
  align-items: center;
  justify-content: center !important;
  /* Force bisect center logic */
  min-height: 140px;
  /* Sync with main KPIs */
}

.sa-kpi-card .label {
  flex: 1;
  /* Top half */
  display: flex;
  align-items: flex-end;
  /* Sits exactly on the center baseline from top */
  justify-content: center;
  font-size: 0.75rem;
  color: #94a3b8;
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 2px;
  /* Micro gap at bisect line */
  line-height: 1.2;
}

.sa-kpi-card h2 {
  flex: 1;
  /* Bottom half */
  display: flex;
  align-items: flex-start;
  /* Sits exactly on the center baseline from bottom */
  justify-content: center;
  font-size: 1.8rem;
  color: #fff;
  margin: 0;
  margin-top: 2px;
  /* Micro gap at bisect line */
  background: linear-gradient(to right, #fff, #a78bfa);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

/* Charts Containers */
.sa-chart-container-lg {
  height: 380px;
  /* Aligned with table height */
  width: 100%;
}

/* Split Layout (Table + Chart) */
.sa-overview-split {
  display: grid;
  grid-template-columns: 1fr;
  /* Normal: One column */
  gap: 20px;
  margin-top: 20px;
}

#sa-view-engagement #card-overview-top-posts {
  display: none !important;
  /* STRICT HIDE IN NORMAL MODE */
}

.sa-tabpanel.is-expanded .sa-overview-split {
  grid-template-columns: 1fr 1fr !important;
  /* Expanded: Two columns */
  align-items: stretch;
}

#sa-view-engagement .sa-tabpanel.is-expanded #card-overview-top-posts {
  display: flex !important;
  /* STRICT SHOW IN EXPANDED MODE */
  height: 100% !important;
  flex-direction: column !important;
  align-items: flex-start !important;
  /* Forces title and table to the left */
  padding: 12px !important;
}

#sa-view-engagement .sa-overview-split .sa-chart-container-lg,
#sa-view-engagement .sa-overview-split .sa-table-wrap {
  height: 380px !important;
  /* Sync height between sides */
}



#card-overview-top-posts h3 {
  margin: 0 0 16px 0 !important;
  font-size: 16px;
  color: #fff;
  font-weight: 600;
  text-align: left !important;
  /* FORCE TOP-LEFT */
}

.sa-overview-split .sa-table-wrap {
  flex-grow: 1 !important;
  display: flex !important;
  flex-direction: column !important;
  overflow-y: auto !important;
  /* ENABLE SCROLL */
  overflow-x: hidden !important;
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 12px;
}

#table-overview-top-posts {
  width: 95% !important;
  /* Stretch to fill container */
  margin: 0 auto;
  border-collapse: collapse;
  table-layout: fixed;
  /* Ensures column widths are stable */
}

#table-overview-top-posts thead th {
  height: 40px;
  line-height: 40px;
  padding: 0 12px;
  text-align: left;
  color: #64748b;
  font-size: 11px;
  text-transform: uppercase;
}

/* Precise Column Widths */
#table-overview-top-posts thead th:nth-child(1) {
  width: 18%;
}

/* Date */
#table-overview-top-posts thead th:nth-child(2) {
  width: 58%;
}

/* Post - Maximized space */
#table-overview-top-posts thead th:nth-child(3) {
  width: 12%;
}

/* Imps - Narrowed */
#table-overview-top-posts thead th:nth-child(4) {
  width: 12%;
}

/* ER% - Narrowed */

#table-overview-top-posts tbody tr {
  height: 54px !important;
  /* Optimized to fill exactly 6 rows in the synced card height */
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
}

#table-overview-top-posts tbody td {
  padding: 8px 12px;
  vertical-align: middle;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Sticky Header */
#table-overview-top-posts thead th {
  position: sticky;
  top: 0;
  background: #0f172a;
  z-index: 10;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.1);
}

.sa-row-split {
  display: flex;
  gap: 20px;
  margin-top: 20px;
}

.sa-col-half {
  flex: 1;
  /* height: 650px; Removed to respect new Grid layout */
  display: flex;
  flex-direction: column;
}

.sa-col-half .sa-chart-card {
  flex: 1;
  /* Fills the parent height */
  height: 100%;
  display: flex;
  flex-direction: column;
}

.sa-col-half .sa-table-wrap {
  flex: 1;
  /* Fills the card height */
  overflow: auto;
}

@keyframes slideDown {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Badges */
.sa-badge {
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 0.7rem;
  font-weight: bold;
}

.sa-badge--linkedin {
  background: rgba(0, 119, 181, 0.2);
  color: #4db3ff;
}

.sa-badge--x {
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
}

/* Table styling for insights */
.sa-table-wrapper {
  margin-top: 20px;
  overflow-x: auto;
}

.sa-table {
  width: 100%;
  border-collapse: collapse;
  color: #cbd5e1;
  font-size: 0.9rem;
}

.sa-table th {
  text-align: left;
  padding: 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  color: #94a3b8;
  text-transform: uppercase;
  font-size: 0.75rem;
  letter-spacing: 1px;
}

.sa-table td {
  padding: 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.sa-num {
  font-family: monospace;
  color: #fff;
}

.sa-highlight {
  color: #a78bfa;
  font-weight: 600;
}

/* Discovery Items */
.sa-opportunity-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border-radius: 8px;
  background: rgba(167, 139, 250, 0.05);
  margin-bottom: 10px;
  border: 1px solid rgba(167, 139, 250, 0.1);
}

.sa-btn-xs {
  background: #a78bfa;
  color: #000;
  border: none;
  padding: 4px 10px;
  border-radius: 4px;
  font-size: 0.7rem;
  font-weight: bold;
  cursor: pointer;
  margin-left: auto;
}

/* ===========================
   Engagement Analytics Premium v1
   Tabs + Fixed 70/30 + Expand Panels + Uploaded Files List
   =========================== */

.sa-engagement-layout {
  grid-template-columns: minmax(0, 7fr) minmax(340px, 3fr);
  align-items: start;
}

/* Keep 70/30 on desktop; stack only on small screens */
@media (max-width: 760px) {
  .sa-engagement-layout {
    grid-template-columns: 1fr;
  }

  .sa-right-panel {
    position: relative;
    height: auto;
  }
}

.sa-analytics-container {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-width: 0;
}

.sa-right-panel {
  position: sticky;
  top: 14px;
  height: calc(100vh - 28px);
  overflow: auto;
  padding-right: 2px;
  /* avoid scrollbar overlay */
}

/* Header: Redesigned for Multi-row Layout & Precision Alignment */
.sa-report-header {
  display: flex !important;
  flex-direction: column !important;
  align-items: flex-start !important;
  gap: 0 !important;
  /* Controlado internamente por márgenes */
  padding: 14px !important;
  /* Margen estándar del sistema (Rojo) */
  border: 1px solid var(--border-slate);
  background: rgba(255, 255, 255, 0.02);
  border-radius: 16px;
  width: 100%;
  box-sizing: border-box;
}

.sa-header-titles {
  width: 100%;
  margin-bottom: 12px;
}

.sa-header-titles h1 {
  margin: 0 0 4px 0 !important;
  font-size: 1.1rem;
}

.sa-header-titles p {
  margin: 0 !important;
  font-size: 0.8rem;
  color: var(--text-dim);
}

.sa-header-actions {
  display: flex;
  width: 100%;
  justify-content: space-between;
  align-items: center;
  margin-top: 5px;
}

/* Specific tabs for Desktop (shared with filters row) */
.sa-audit-tabs {
  margin: 0 !important;
  display: flex;
  gap: 12px;
}

.sa-audit-filter {
  margin-left: auto !important;
  flex-shrink: 0;
}

/* KPI Adjustment (Desktop) */
.sa-audit-kpi-grid {
  padding: 0 !important;
  margin-top: 15px !important;
  /* Succión vertical refinada */
}

@media (max-width: 900px) {

  /* Mobile: Mirror Engagement Analytics natural spacing */
  #sa-view-audit .sa-engagement-layout {
    width: 100% !important;
    margin: 0 !important;
    display: flex !important;
    flex-direction: column !important;
    align-items: center !important;
  }

  .sa-analytics-container {
    padding: 10px 0 !important;
    /* Let global 15px handle the air */
    width: 100% !important;
    display: flex !important;
    flex-direction: column !important;
    align-items: center !important;
  }

  .sa-report-header {
    width: 100% !important;
    margin: 0 0 16px 0 !important;
    padding: 24px 18px !important;
    /* Premium internal padding */
    gap: 20px !important;
    text-align: left !important;
    box-sizing: border-box !important;
    display: flex !important;
    flex-direction: column !important;
    align-items: flex-start !important;
    /* Card/Pad border visible & unified with KPIs below */
    border: 1px solid rgba(255, 255, 255, 0.12) !important;
    border-radius: 12px !important;
    background: rgba(255, 255, 255, 0.04) !important;
    /* Igual que KPIs para consistencia */
  }

  .sa-header-titles {
    text-align: left !important;
    width: 100% !important;
    margin-bottom: 0 !important;
  }

  /* 4 Rows Mobile Logic: Professional center alignment */
  .sa-header-actions {
    display: flex !important;
    flex-direction: column !important;
    gap: 15px !important;
    /* Slightly tighter gap */
    width: 100% !important;
    align-items: center !important;
  }

  .sa-audit-tabs {
    width: 100% !important;
    display: flex !important;
    flex-wrap: nowrap !important;
    /* Force same row */
    justify-content: center !important;
    gap: 6px !important;
    /* Tighter gap to fit */
    overflow-x: auto !important;
    /* Allow scroll if screen is very small */
    padding-bottom: 5px;
    -webkit-overflow-scrolling: touch;
  }

  /* Make tab buttons slightly more compact to help them fit in one row */
  .sa-audit-tabs .sa-tab {
    padding: 8px 10px !important;
    font-size: 0.75rem !important;
    white-space: nowrap !important;
  }

  .sa-audit-filter {
    margin: 0 auto !important;
    display: flex !important;
    justify-content: center !important;
  }

  /* Centered KPIs Mobile: Compacted to prevent crowding */
  .sa-audit-kpi-grid {
    width: 100% !important;
    margin: 0 0 16px 0 !important;
    padding: 0 !important;
    display: grid !important;
    grid-template-columns: 1fr 1fr !important;
    gap: 10px !important;
    /* Tighter gap */
  }

  .sa-audit-kpi-grid .sa-kpi-card {
    width: 100% !important;
    margin: 0 !important;
    padding: 10px 8px !important;
    /* Compact padding */
    min-height: 100px !important;
    /* Reduced height */
    border-radius: 12px !important;
  }

  .sa-audit-kpi-grid .sa-kpi-card h2 {
    font-size: 1.3rem !important;
    /* Smaller numbers */
  }

  .sa-audit-kpi-grid .sa-kpi-card .label {
    font-size: 0.65rem !important;
    /* Smaller labels */
  }

  /* Engagement Tabs Mobile: 3x3 layout */
  #sa-view-engagement .sa-tabs {
    display: grid !important;
    grid-template-columns: repeat(3, 1fr) !important;
    gap: 8px !important;
    width: 100% !important;
    margin-top: 20px !important;
  }

  #sa-view-engagement .sa-tab,
  #sa-view-engagement .sa-btn-tab-action {
    padding: 8px 4px !important;
    /* Tighter padding for 3-col */
    font-size: 11px !important;
    justify-content: center !important;
    width: 100% !important;
    text-align: center !important;
    white-space: normal !important;
    /* Allow break if needed */
    height: 42px !important;
    /* Fixed height for symmetry */
    display: flex !important;
    align-items: center !important;
  }

  /* Hide icon on mobile export button to save space if needed, or keep it */
  #sa-view-engagement .sa-btn-tab-action svg {
    display: none !important;
  }

  /* Engagement Panel Header Centering (Mobile) */
  #sa-view-engagement .sa-panel-header {
    flex-direction: column !important;
    align-items: center !important;
    text-align: center !important;
    gap: 20px !important;
    padding: 20px 15px !important;
  }

  #sa-view-engagement .sa-header-content {
    text-align: center !important;
    width: 100% !important;
  }

  #sa-view-engagement .sa-header-center {
    width: 100% !important;
    justify-content: center !important;
    align-items: center !important;
  }

  #sa-view-engagement .sa-panel-actions {
    width: 100% !important;
    justify-content: center !important;
    margin-left: 0 !important;
  }

  /* Sidebar pads (AI Assistant & Upload) Mirrored Spacing */
  .sa-right-panel {
    width: 100% !important;
    padding: 0 !important;
    /* Inherit global padding */
  }

  .sa-right-panel section {
    width: 100% !important;
    margin: 0 0 16px 0 !important;
    box-sizing: border-box !important;
  }
}

/* Fix deformed X button in pill selectors */
.sa-pill-btn {
  min-width: 42px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 10px;
  flex-shrink: 0;
}

.sa-overview-charts-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 20px;
  margin-top: 20px;
}

@media (max-width: 900px) {
  .sa-overview-charts-grid {
    grid-template-columns: 1fr;
  }
}

.sa-report-title {
  margin: 0;
  font-size: 18px;
  letter-spacing: 0.2px;
}

.sa-report-subtitle {
  margin: 4px 0 0 0;
  color: var(--text-muted);
  font-size: 13px;
}

/* Tabs */
.sa-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 15px;
  /* Aumentado +7px de aire (era aprox 8px implícitos) */
}

.sa-tab {
  border: 1px solid rgba(255, 255, 255, 0.10);
  background: rgba(255, 255, 255, 0.02);
  color: rgba(255, 255, 255, 0.85);
  padding: 8px 12px;
  border-radius: 999px;
  font-size: 13px;
  cursor: pointer;
  transition: transform .12s ease, background .12s ease, border-color .12s ease;
}

.sa-tab:hover {
  transform: translateY(-1px);
  border-color: rgba(167, 139, 250, 0.55);
}

.sa-tab.is-active {
  background: var(--gradient-sa);
  border-color: rgba(167, 139, 250, 0.55);
  color: #fff;
  font-weight: 600;
  box-shadow: 0 2px 10px rgba(124, 58, 237, 0.3);
}

/* Specific styling for the Export button to match tabs but as an action */
.sa-btn-tab-action {
  border: 1px solid rgba(255, 255, 255, 0.10);
  background: rgba(255, 255, 255, 0.02);
  color: rgba(255, 255, 255, 0.85);
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 13px;
  cursor: pointer;
  display: flex;
  align-items: center;
  transition: transform .12s ease, background .12s ease, border-color .12s ease;
  font-family: inherit;
  font-weight: 500;
}

.sa-btn-tab-action:hover {
  transform: translateY(-1px);
  border-color: rgba(167, 139, 250, 0.55);
  background: rgba(255, 255, 255, 0.05);
  color: #fff;
}

.sa-btn-tab-action svg {
  opacity: 0.7;
}

.sa-btn-tab-action:hover svg {
  opacity: 1;
}

/* Panels */
.sa-tabpanel {
  display: none;
  border: 1px solid var(--border-slate);
  background: rgba(255, 255, 255, 0.02);
  border-radius: 16px;
  overflow: hidden;
}

.sa-tabpanel.is-active {
  display: block;
}

.sa-panel-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.sa-panel-header h3 {
  margin: 0;
  font-size: 16px;
}

.sa-panel-header p {
  margin: 4px 0 0 0;
  color: var(--text-muted);
  font-size: 13px;
}

.sa-panel-actions {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
}

.sa-pill-selector--header {
  background: rgba(0, 0, 0, 0.2);
  border: 1px solid rgba(255, 255, 255, 0.1);
  margin-right: 8px;
}

.sa-pill-selector--header {
  background: rgba(0, 0, 0, 0.2);
  border: 1px solid rgba(255, 255, 255, 0.1);
  margin-right: 8px;
}

.sa-panel-content {
  padding: 14px 16px 16px 16px;
}

.sa-card-title {
  margin: 0 0 10px 0;
  font-size: 13px;
  color: rgba(255, 255, 255, 0.85);
}

/* Explain box */
.sa-panel-explain {
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(255, 255, 255, 0.02);
  border-radius: 14px;
  padding: 12px 12px;
  margin-bottom: 12px;
}

.sa-panel-explain h4 {
  margin: 0 0 6px 0;
  font-size: 13px;
}

.sa-panel-explain p {
  margin: 0;
  color: var(--text-muted);
  font-size: 13px;
  line-height: 1.35;
}

/* Grid helpers */
.sa-grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

@media (max-width: 980px) {
  .sa-grid-2 {
    grid-template-columns: 1fr;
  }
}

.sa-chart-card {
  border: 1px solid rgba(255, 255, 255, 0.06);
  background: rgba(3, 5, 18, 0.35);
  border-radius: 14px;
  padding: 12px;
  padding-bottom: 24px;
  /* Added breathing room for timeline labels */
}

.sa-table-wrap {
  overflow: auto;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.06);
}

/* Empty state */
.sa-empty-state {
  text-align: center;
  padding: 22px 12px;
  border: 1px dashed rgba(255, 255, 255, 0.12);
  border-radius: 14px;
  background: rgba(3, 5, 18, 0.25);
}

.sa-empty-icon {
  font-size: 24px;
  margin-bottom: 6px;
}

.sa-empty-state h4 {
  margin: 0 0 6px 0;
}

.sa-empty-state p {
  margin: 0;
  color: var(--text-muted);
}

/* Expand to fullscreen (glassmorphism) */
.sa-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(3, 5, 18, 0.55);
  backdrop-filter: blur(7px);
  z-index: 1000;
}

.sa-tabpanel.is-expanded {
  position: fixed;
  inset: 22px;
  z-index: 1001;
  display: block;
  overflow: auto;
  background: rgba(12, 15, 30, 0.55);
  border: 1px solid rgba(255, 255, 255, 0.14);
  box-shadow: 0 20px 70px rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(16px);
  border-radius: 22px;
}

body.sa-modal-open {
  overflow: hidden;
}

/* Buttons (safe, small additions; won't override global if present) */
.sa-btn-danger {
  background: rgba(239, 68, 68, 0.12);
  border: 1px solid rgba(239, 68, 68, 0.35);
  color: rgba(255, 255, 255, 0.9);
}

.sa-btn-danger:hover {
  background: rgba(239, 68, 68, 0.18);
}

.sa-btn-xs {
  padding: 6px 10px;
  font-size: 12px;
}

/* Upload files list */
.sa-upload-actions {
  display: flex;
  justify-content: center;
  margin: 12px 0 6px 0;
  padding-top: 12px;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
}

.sa-upload-files {
  margin-top: 10px;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  padding-top: 12px;
}

.sa-upload-files-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}

.sa-upload-files-header h3 {
  margin: 0;
  font-size: 13px;
  color: rgba(255, 255, 255, 0.88);
}

.sa-file-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* Expanded Only Utility */
.sa-tabpanel:not(.is-expanded) .sa-expanded-only {
  display: none !important;
}

/* Leaderboards Specific Layout */
/* Leaderboards Specific Layout */
#sa-section-leaderboards .sa-panel-content {
  min-height: 600px;
  /* Ensure normal mode is tall enough for charts */
}

#sa-section-leaderboards .sa-chart-container-lg {
  min-height: 400px;
  /* Increase height for charts */
}

#sa-section-leaderboards.is-expanded .sa-expanded-only {
  margin-top: 100px !important;
  /* Adjusted for 5-item list height */
  position: relative;
  z-index: 5;
  display: block !important;
  width: 100%;
}

/* --- Diagnostics Tab --- */
#sa-section-diagnostics .sa-header-center {
  display: flex !important;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

#diag-kpi-row {
  display: flex;
  flex-wrap: wrap;
  /* Allow wrapping or nice row */
  gap: 16px;
  justify-content: space-between;
}

.sa-diag-kpi {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 12px 16px;
  flex: 1;
  min-width: 120px;
  text-align: center;
  transition: all 0.3s ease;
}

.sa-diag-kpi h4 {
  font-size: 0.8em;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.sa-diag-kpi .sa-val {
  font-size: 1.4em;
  font-weight: 700;
  color: var(--text-main);
}

.sa-diag-kpi.is-highlight .sa-val {
  color: var(--accent-yellow);
  /* Yellow for Opportunities */
}

.sa-diag-kpi.is-secondary .sa-val {
  color: var(--accent-blue);
  /* Blue for Context */
}

/* Hide secondary KPIs in normal mode */
#sa-section-diagnostics:not(.is-expanded) .sa-kpi-secondary {
  display: none !important;
}

/* Heatmap Grid */
.sa-heatmap-grid {
  display: grid;
  grid-template-columns: 40px repeat(24, 1fr);
  /* Label + 24 Hours */
  grid-template-rows: 20px repeat(7, 1fr);
  /* Header + 7 Days */
  gap: 2px;
  height: 100%;
  font-size: 10px;
}

.sa-hm-cell {
  background: var(--bg-main);
  border-radius: 2px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
}

.sa-hm-header {
  color: var(--text-muted);
  font-weight: bold;
  text-align: center;
}

.sa-hm-label {
  justify-content: flex-start;
  padding-left: 4px;
  color: var(--text-muted);
}

.sa-file-list-empty {
  color: var(--text-muted);
  font-size: 12.5px;
  padding: 8px 0;
}

.sa-file-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(3, 5, 18, 0.30);
  border-radius: 12px;
  padding: 10px 10px;
}

.sa-file-meta {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.sa-file-name {
  font-size: 12.5px;
  color: rgba(255, 255, 255, 0.9);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 240px;
}

.sa-file-sub {
  font-size: 12px;
  color: var(--text-muted);
  display: flex;
  gap: 10px;
}

.sa-file-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.sa-file-del {
  width: 32px;
  height: 32px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.10);
  background: rgba(255, 255, 255, 0.02);
  color: rgba(255, 255, 255, 0.85);
  cursor: pointer;
}

.sa-file-del:hover {
  border-color: rgba(239, 68, 68, 0.55);
  background: rgba(239, 68, 68, 0.10);
}

.sa-files-footnote {
  margin: 10px 0 0 0;
  font-size: 12px;
}

/* Dropzone hint */
.sa-dropzone-hint {
  margin: 8px 0 0 0;
  color: var(--text-muted);
  font-size: 12px;
}

/* Consolidated duplicate section removed */


/* =========================
   EXPANDED MODE OVERRIDES
   ========================= */

/* 1. KPI Grid becomes Flex Row */
.sa-tabpanel.is-expanded .sa-kpi-grid {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  gap: 12px;
  margin-bottom: 16px;
  grid-template-columns: none;
  /* Reset grid */
}

/* 2. Show hidden cards */
.sa-tabpanel.is-expanded .sa-kpi-card.sa-kpi-hidden,
.sa-tabpanel.is-expanded .sa-perf-hidden {
  display: flex !important;
  /* Fixed: was block, preventing centering */
  flex-direction: column;
  align-items: center;
  justify-content: center;
  /* Force bisect center */
  animation: fadeIn 0.4s ease forwards;
}

/* 3. Normal-sized cards in expanded layout - inherits Red Line rules from above */
.sa-tabpanel.is-expanded .sa-kpi-card {
  flex: 1;
  /* Stretch to fill space in flex container */
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(5px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Time Filter Spacing */
.sa-time-filter {
  margin-top: 4px;
}

@media (max-width: 768px) {
  .sa-kpi-grid {
    grid-template-columns: 1fr;
  }
}

/* Overview overrides removed - consolidated in Master block above */

/* Mobile responsiveness for split */
@media (max-width: 900px) {
  .sa-tabpanel.is-expanded .sa-overview-split {
    grid-template-columns: 1fr;
    /* Stack on smaller screens */
  }
}

/* =========================
   Engagement Chat Input (Hub Style - High Specificity)
   ========================= */
#sa-view-engagement .sa-chat-input-area {
  display: flex !important;
  flex-direction: column !important;
  gap: 12px;
  margin-top: 16px;
  width: 100%;
}

#sa-view-engagement .sa-chat-textarea,
#sa-view-audit .sa-chat-textarea {
  width: 100% !important;
  display: block;
  background: rgba(15, 17, 26, 0.7) !important;
  border: 1px solid rgba(255, 255, 255, 0.1) !important;
  border-radius: 12px !important;
  padding: 14px !important;
  color: #fff !important;
  font-family: inherit;
  font-size: 0.95rem;
  resize: vertical;
  min-height: 80px;
  box-sizing: border-box !important;
  outline: none;
  transition: border-color 0.2s;
  margin-bottom: 25px !important;
}

#sa-view-engagement .sa-chat-textarea:focus,
#sa-view-audit .sa-chat-textarea:focus {
  border-color: #a78bfa !important;
}

#sa-view-engagement .sa-chat-controls,
#sa-view-audit .sa-chat-controls {
  display: flex !important;
  justify-content: space-between !important;
  align-items: center !important;
  width: 100%;
}

#sa-view-engagement .sa-sync-btn,
#sa-view-audit .sa-sync-btn {
  background: rgba(167, 139, 250, 0.1) !important;
  color: #a78bfa !important;
  border: 1px solid rgba(167, 139, 250, 0.3) !important;
  padding: 8px 16px !important;
  border-radius: 8px !important;
  font-size: 0.85rem !important;
  font-weight: 600 !important;
  display: flex !important;
  align-items: center;
  gap: 6px;
  transition: all 0.2s;
  cursor: pointer;
}

#sa-view-engagement .sa-sync-btn:hover,
#sa-view-audit .sa-sync-btn:hover {
  background: rgba(167, 139, 250, 0.2) !important;
  transform: translateY(-1px);
  border-color: rgba(167, 139, 250, 0.5) !important;
}

#sa-view-engagement .sa-send-btn,
#sa-view-audit .sa-send-btn {
  width: 42px !important;
  height: 42px !important;
  border-radius: 50% !important;
  background: #a78bfa !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  border: none !important;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
}

#sa-view-engagement .sa-send-btn:hover {
  transform: scale(1.05);
  box-shadow: 0 4px 12px rgba(167, 139, 250, 0.4);
}

.sa-send-btn img {
  width: 20px;
  height: 20px;
  filter: brightness(0) invert(1);
}

/* =========================
   CONTENT PERFORMANCE SECTION
   ========================= */
/* #sa-section-content-performance {
   margin-top: 30px; Removed to align with Overview tab 
} */

.sa-performance-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-top: 20px;
}

/* Card Specifics */
.sa-card--table,
.sa-card--heatmap {
  display: flex;
  flex-direction: column;
  min-height: 320px;
}

.sa-card h3 {
  margin-bottom: 20px;
  font-size: 16px;
  font-weight: 600;
  color: #fff;
}

/* Data Bars Table */
.sa-table--bars th {
  text-transform: uppercase;
  font-size: 11px;
  letter-spacing: 0.5px;
  color: var(--text-muted);
}

.sa-table--bars td {
  padding: 10px 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.03);
  font-size: 13px;
  vertical-align: middle;
}

.sa-bar-cell {
  position: relative;
  z-index: 1;
  overflow: hidden;
  color: #fff;
  /* font-weight: 500;  removed to match design */
}

/* The bar background */
.sa-data-bar {
  position: absolute;
  top: 4px;
  bottom: 4px;
  left: 0;
  background: rgba(89, 218, 197, 0.15);
  /* Tech Green tint */
  border-radius: 4px;
  z-index: -1;
  transition: width 0.5s ease;
}

/* Heatmap Grid */
.sa-heatmap-container {
  display: grid;
  grid-template-columns: 100px repeat(3, 1fr);
  /* Label + 3 buckets */
  gap: 8px;
  margin-bottom: auto;
}

.sa-heatmap-header {
  text-align: center;
  font-size: 11px;
  color: var(--text-muted);
  padding-bottom: 8px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.sa-heatmap-row-label {
  display: flex;
  align-items: center;
  font-size: 13px;
  color: #fff;
  font-weight: 500;
}

.sa-heatmap-cell {
  background: rgba(255, 255, 255, 0.03);
  border-radius: 6px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 600;
  color: #fff;
  transition: all 0.2s;
}

/* Heatmap Legend */
.sa-heatmap-legend {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-top: 20px;
  font-size: 11px;
  color: var(--text-muted);
}

.sa-gradient-bar {
  width: 120px;
  height: 6px;
  border-radius: 3px;
  background: linear-gradient(to right, rgba(89, 218, 197, 0.1), rgba(89, 218, 197, 1));
}

/* Utility: Show only when expanded */
.sa-expand-only {
  display: none !important;
}

.sa-tabpanel.is-expanded .sa-expand-only {
  display: block !important;
}

/* Hidden elements */
.sa-perf-hidden {
  display: none;
}

/* Controls */
.sa-controls-group {
  display: flex;
  gap: 12px;
  align-items: center;
}

/* End of analytics specific styles */

/* Mobile */
@media (max-width: 768px) {
  .sa-performance-grid {
    grid-template-columns: 1fr;
  }
}

/* Button Inactive State (for Expand/Close logic) */
.sa-btn-inactive {
  opacity: 0.4;
  pointer-events: none;
  filter: grayscale(100%);
}

/* =========================
   EXPERIMENTS TAB LAYOUT
   ========================= */
.sa-experiments-layout {
  display: flex;
  gap: 20px;
  align-items: stretch !important;
  /* Force main and sidebar to match */
}

@media (max-width: 900px) {
  .sa-experiments-layout {
    flex-direction: column;
  }
}

.sa-exp-sidebar {
  width: 280px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.sa-exp-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 20px;
  min-width: 0;
  height: 432px !important;
  /* Sync height to align with top of Shares card */
}

.sa-exp-main .sa-card--table {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100%;
}

.sa-exp-main .sa-table-wrap {
  flex: 1 !important;
  overflow: auto !important;
  /* Essential for both Y and X scrolling */
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 12px;
}

/* Precise Column Widths for Experiments Table */
#table-experiments {
  width: 100%;
  min-width: 900px;
  /* Prevent overlap in narrow normal mode */
}

#table-experiments thead th:nth-child(1) {
  width: 13%;
}

/* Experiment */
#table-experiments thead th:nth-child(2) {
  width: 11%;
}

/* Date */
#table-experiments thead th:nth-child(3) {
  width: 11%;
}

/* Channel */
#table-experiments thead th:nth-child(4) {
  width: 9%;
}

/* Format */
#table-experiments thead th:nth-child(5) {
  width: 24%;
}

/* Snippet (Reduced to fix gap) */
#table-experiments thead th:nth-child(6) {
  width: 7%;
}

/* Imps */
#table-experiments thead th:nth-child(7) {
  width: 7%;
}

/* Inter */
#table-experiments thead th:nth-child(8) {
  width: 6%;
}

/* ER% */
#table-experiments thead th:nth-child(9) {
  width: 6%;
}

/* Save% */
#table-experiments thead th:nth-child(10) {
  width: 6%;
}

/* Auth */

/* Filter Box */
.sa-exp-filter-box label {
  display: block;
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.sa-custom-select {
  position: relative;
  width: 100%;
}

.sa-select-trigger {
  background: rgba(15, 23, 42, 0.6);
  border: 1px solid rgba(255, 255, 255, 0.1);
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
  user-select: none;
}

.sa-select-trigger:hover {
  border-color: rgba(167, 139, 250, 0.5);
}

.sa-select-dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: #0f172a;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  margin-top: 4px;
  z-index: 50;
  max-height: 200px;
  overflow-y: auto;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.5);
  padding: 6px;
}

.sa-select-option {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 13px;
  color: #cbd5e1;
}

.sa-select-option:hover {
  background: rgba(255, 255, 255, 0.05);
}

.sa-select-option input[type="checkbox"] {
  accent-color: #a78bfa;
  cursor: pointer;
}

/* Scorecards Mini (sidebar) */
.sa-exp-scorecards {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.sa-kpi-card-mini {
  background: rgba(255, 255, 255, 0.03);
  border-radius: 10px;
  padding: 16px;
  text-align: center;
  border: 1px solid rgba(255, 255, 255, 0.05);
}

.sa-kpi-card-mini .label {
  display: block;
  font-size: 12px;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.sa-kpi-card-mini h2 {
  font-size: 24px;
  font-weight: 700;
  margin: 0;
  color: #fff;
}

/* Rich List for Leaderboards */
.sa-list-rich {
  list-style: none;
  padding: 0;
  margin: 0;
}

.sa-list-rich li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  transition: background 0.2s;
}

.sa-list-rich li:hover {
  background: rgba(255, 255, 255, 0.02);
}

.sa-list-rich li:last-child {
  border-bottom: none;
}

.sa-rich-content {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
  margin-right: 16px;
}

.sa-rich-title {
  font-weight: 500;
  color: #fff;
  font-size: 0.95rem;
  line-height: 1.4;
}

.sa-rich-meta {
  font-size: 0.75rem;
  color: #94a3b8;
  display: flex;
  gap: 8px;
  align-items: center;
}

.sa-rich-meta span {
  background: rgba(255, 255, 255, 0.05);
  padding: 2px 6px;
  border-radius: 4px;
}

.sa-rich-score-box {
  text-align: right;
  min-width: 60px;
}

.sa-rich-score {
  font-weight: 700;
  color: #a78bfa;
  font-size: 1.2rem;
  display: block;
}

.sa-rich-score-label {
  font-size: 0.65rem;
  color: #64748b;
  text-transform: uppercase;
  display: block;
}

.sa-table--compact td,
.sa-table--compact th {
  padding: 8px 10px;
  font-size: 12.5px;
}

/* Detailed Leaderboard Enhancements */
#table-leader-full {
  border-collapse: separate;
  border-spacing: 0 4px;
  margin-top: 1rem;
}

#table-leader-full thead th {
  background: rgba(15, 23, 42, 0.8) !important;
  color: var(--text-muted) !important;
  font-size: 0.75rem !important;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 12px 16px !important;
  border-bottom: 2px solid var(--accent-aqua);
}

#table-leader-full tbody tr {
  background: rgba(255, 255, 255, 0.02);
  transition: background 0.2s ease;
}

#table-leader-full tbody tr:hover {
  background: rgba(45, 212, 191, 0.05);
}

#table-leader-full td {
  padding: 12px 16px !important;
  border: none !important;
  vertical-align: middle;
}

/* Diagnostics Adaptive Split */
.sa-diagnostics-split {
  display: grid;
  grid-template-columns: 1fr;
  gap: 20px;
  margin-top: 24px;
}

.sa-tabpanel.is-expanded .sa-diagnostics-split {
  grid-template-columns: 1fr 1fr !important;
}

.sa-diagnostics-split .sa-card {
  margin: 0 !important;
  /* Reset margin inside grid */
}

/* Support classes for Audit JS injection */
.sa-chart-header {
  display: flex !important;
  justify-content: space-between !important;
  align-items: center !important;
  margin-bottom: 16px !important;
}

.sa-chart-canvas-container {
  height: 300px !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
}

/* Specific for labs scatter/format */
.sa-overview-charts-grid .sa-chart-canvas-container {
  height: 320px !important;
}

.sa-chart-card h3 {
  margin: 0 0 16px 4px !important;
  font-size: 16px !important;
  color: #ffffff !important;
  font-weight: 600 !important;
  text-transform: none !important;
  letter-spacing: normal !important;
}

.sa-lab-insight-card {
  padding: 24px !important;
  margin-top: 20px !important;
  background: linear-gradient(135deg, rgba(167, 139, 250, 0.1) 0%, rgba(15, 23, 42, 0.4) 100%) !important;
  border: 1px solid rgba(167, 139, 250, 0.2) !important;
  border-radius: 12px;
}

.sa-lab-insight-card h3 {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 0 !important;
  color: #ffffff;
}

.sa-lab-insight-card p {
  color: #e2e8f0;
  line-height: 1.6;
  margin-bottom: 0 !important;
}