/* CRM filter panels — always-visible per-section filters.
   Keeps real filters/search visible for Leads, Calls, Citas and Sales.
   Quick views stay as secondary chips, never a substitute. */
.dashboard-mobile-filter-toggle { display: none; }
body.ui-crm-refresh #crmTab .crm-filters-panel-head {
  display: flex !important;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin: 10px 0 6px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--crm-line-soft, rgba(255, 255, 255, 0.07));
}
body.ui-crm-refresh #crmTab .crm-filters-panel-title {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--crm-ink-muted, rgba(232, 236, 244, 0.72));
}
body.ui-crm-refresh #crmTab .crm-filters-panel-title svg {
  width: 14px;
  height: 14px;
  color: var(--crm-accent, #6ca8ff);
}
body.ui-crm-refresh #crmTab .crm-filter-count {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--crm-accent, #6ca8ff);
  background: rgba(108, 168, 255, 0.12);
  border: 1px solid rgba(108, 168, 255, 0.28);
  border-radius: 999px;
  padding: 2px 9px;
}
body.ui-crm-refresh #crmTab .crm-filter-count[hidden] { display: none !important; }

/* Keep every filter label visible regardless of the legacy hide-by-default rules. */
body.ui-crm-refresh #crmTab .crm-view-toolbar label,
body.ui-crm-refresh[data-crm-filters="1"] #crmTab .crm-view-toolbar label {
  display: flex !important;
  flex-direction: column !important;
}
body.ui-crm-refresh #crmTab .crm-view-toolbar label > span,
body.ui-crm-refresh[data-crm-filters="1"] #crmTab .crm-view-toolbar label > span {
  display: block !important;
}

/* Quick views (VISTAS) = secondary chip row under the real filters. */
body.ui-crm-refresh #crmTab .crm-view-toolbar .crm-quick-views {
  flex-basis: 100% !important;
  width: 100% !important;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px dashed var(--crm-line-soft, rgba(255, 255, 255, 0.08));
}

@media (max-width: 768px) {
  /* Mobile: one compact, unified filter block.
     The separate "Filtros de X" header + count duplicated the metric cards and
     made the UI feel like two blocks. Hide that mobile header and keep the
     useful controls together: search -> filter pills -> views strip. */
  body.ui-crm-refresh #crmTab .crm-filters-panel-head {
    display: none !important;
  }

  /* Jose mobile order: Search -> real filters -> quick views -> metrics.
     The global executive KPI strip looked like a second metrics block above
     the filters; hide it only on mobile and keep the per-section summary below. */
  body.ui-crm-refresh #crmTab #crmExecutiveOverview {
    display: none !important;
  }

  body.ui-crm-refresh #crmTab .crm-view-toolbar,
  body.ui-crm-refresh[data-crm-filters="1"] #crmTab .crm-view-toolbar {
    display: flex !important;
    flex-wrap: wrap !important;
    grid-template-columns: none !important;
    gap: 6px !important;
    align-items: center !important;
    margin-top: 8px !important;
  }

  /* Search = compact full-width row first. */
  body.ui-crm-refresh #crmTab .crm-view-toolbar label:has(input[type="text"]),
  body.ui-crm-refresh[data-crm-filters="1"] #crmTab .crm-view-toolbar label:has(input[type="text"]) {
    order: 0 !important;
    flex: 1 1 100% !important;
    max-width: none !important;
    min-width: 0 !important;
    padding: 0 !important;
    border: none !important;
    background: transparent !important;
    gap: 0 !important;
  }
  body.ui-crm-refresh #crmTab .crm-view-toolbar label:has(input[type="text"]) > span,
  body.ui-crm-refresh[data-crm-filters="1"] #crmTab .crm-view-toolbar label:has(input[type="text"]) > span {
    display: none !important;
  }
  body.ui-crm-refresh #crmTab .crm-view-toolbar input[type="text"] {
    width: 100% !important;
    max-width: none !important;
    min-height: 32px !important;
    padding: 6px 10px !important;
    border: 1px solid var(--crm-line-medium, rgba(255, 255, 255, 0.12)) !important;
    border-radius: 9px !important;
    background: var(--crm-bg-elev-2, rgba(255, 255, 255, 0.03)) !important;
    font-size: 12px !important;
  }

  /* Select filters = low-height inline pills under the search. */
  body.ui-crm-refresh #crmTab .crm-view-toolbar label,
  body.ui-crm-refresh[data-crm-filters="1"] #crmTab .crm-view-toolbar label,
  body.ui-crm-refresh[data-crm-filters="1"] #crmTab .crm-view-toolbar label:not(:has(input[type="text"])) {
    order: 1 !important;
    display: inline-flex !important;
    flex-direction: row !important;
    align-items: center !important;
    flex: 1 1 calc(50% - 4px) !important;
    gap: 5px !important;
    min-width: 0 !important;
    max-width: calc(50% - 4px) !important;
    margin: 0 !important;
    padding: 2px 4px 2px 9px !important;
    border: 1px solid var(--crm-line-soft, rgba(255, 255, 255, 0.1)) !important;
    border-radius: 999px !important;
    background: var(--crm-bg-elev-2, rgba(255, 255, 255, 0.03)) !important;
  }
  body.ui-crm-refresh #crmTab .crm-view-toolbar label > span,
  body.ui-crm-refresh[data-crm-filters="1"] #crmTab .crm-view-toolbar label > span,
  body.ui-crm-refresh[data-crm-filters="1"] #crmTab .crm-view-toolbar label:not(:has(input[type="text"])) > span {
    display: inline !important;
    margin: 0 !important;
    white-space: nowrap !important;
    color: rgba(232, 236, 244, 0.55) !important;
    font-size: 9px !important;
    font-weight: 600 !important;
    letter-spacing: 0.055em !important;
    text-transform: uppercase !important;
  }
  body.ui-crm-refresh #crmTab .crm-view-toolbar select,
  body.ui-crm-refresh #crmTab .crm-view-toolbar input:not([type="text"]),
  body.ui-crm-refresh[data-crm-filters="1"] #crmTab .crm-view-toolbar label:not(:has(input[type="text"])) select,
  body.ui-crm-refresh[data-crm-filters="1"] #crmTab .crm-view-toolbar label:not(:has(input[type="text"])) input {
    width: auto !important;
    min-height: 27px !important;
    max-width: 48vw !important;
    padding: 3px 4px !important;
    border: none !important;
    background: transparent !important;
    font-size: 12px !important;
  }

  body.ui-crm-refresh #crmTab .crm-view-toolbar .crm-export-btn {
    order: 1 !important;
    flex: 0 0 auto !important;
    min-height: 28px !important;
    padding: 0 10px !important;
  }

  /* Quick views below the real filters. Same block, lighter secondary strip. */
  body.ui-crm-refresh #crmTab .crm-view-toolbar .crm-quick-views {
    order: 2 !important;
    flex-basis: 100% !important;
    width: 100% !important;
    margin-top: 2px !important;
    padding-top: 6px !important;
    display: flex !important;
    flex-wrap: nowrap !important;
    align-items: center !important;
    gap: 6px !important;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    border-top: 1px dashed var(--crm-line-soft, rgba(255, 255, 255, 0.08));
  }
  body.ui-crm-refresh #crmTab .crm-view-toolbar .crm-quick-views::-webkit-scrollbar {
    display: none;
  }
  body.ui-crm-refresh #crmTab .crm-view-toolbar .crm-quick-views > * {
    flex: 0 0 auto !important;
    white-space: nowrap !important;
  }

  .dashboard-mobile-filter-toggle {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    margin: 8px 0;
    padding: 9px 12px;
    border-radius: 8px;
    border: 1px solid var(--line, rgba(255, 255, 255, 0.12));
    background: rgba(248,85,31,.06);
    color: var(--text, #e8ecf4);
    font-size: 12.5px;
    font-weight: 700;
    cursor: pointer;
  }
  .dashboard-mobile-filter-toggle .dashboard-mobile-filter-chevron {
    color: var(--accent, #F8551F);
    transition: transform .2s ease;
  }
  .dashboard-mobile-filter-toggle.is-open {
    background: rgba(248,85,31,.12);
    border-color: rgba(248,85,31,.3);
  }
  .dashboard-mobile-filter-toggle.is-open .dashboard-mobile-filter-chevron {
    transform: rotate(180deg);
  }
  .master-toolbar.dashboard-mobile-filters-collapsed {
    display: none !important;
  }
  .master-toolbar.dashboard-mobile-filters-open {
    display: grid !important;
  }

  body.ui-crm-refresh #crmTab .dashboard-mobile-filter-toggle {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    margin: 8px 0;
    padding: 9px 12px;
    border-radius: 8px;
    border: 1px solid var(--crm-line-medium, rgba(255, 255, 255, 0.12));
    background: var(--crm-bg-elev-2, rgba(255, 255, 255, 0.03));
    color: var(--crm-ink, #e8ecf4);
    font-size: 12.5px;
    font-weight: 700;
  }
  body.ui-crm-refresh #crmTab .dashboard-mobile-filter-toggle .dashboard-mobile-filter-chevron {
    color: var(--crm-accent, #6ca8ff);
    transition: transform .2s ease;
  }
  body.ui-crm-refresh #crmTab .dashboard-mobile-filter-toggle.is-open .dashboard-mobile-filter-chevron {
    transform: rotate(180deg);
  }
  body.ui-crm-refresh #crmTab .crm-view-toolbar.dashboard-mobile-filters-collapsed,
  body.ui-crm-refresh[data-crm-filters="1"] #crmTab .crm-view-toolbar.dashboard-mobile-filters-collapsed {
    display: none !important;
  }
  body.ui-crm-refresh #crmTab .crm-view-toolbar.dashboard-mobile-filters-open,
  body.ui-crm-refresh[data-crm-filters="1"] #crmTab .crm-view-toolbar.dashboard-mobile-filters-open {
    display: flex !important;
  }
}
