/* ============================================================================
 *  YellowBox ML Hub — mobile.css  v2.0
 *  ----------------------------------------------------------------------------
 *  Correções específicas baseadas em prints reais:
 *    • Top 5 não sobrepõe Receita por Vendedor
 *    • Nomes de vendedores não colidem com valores
 *    • "AO VIVO" não quebra em 2 linhas
 *    • Filtros sem borda tracejada estranha
 *    • Title "Das..." cortado → mostra completo
 *    • Anúncios com colunas balanceadas
 *    • Modal de vendas com toast não tapando botões
 * ========================================================================= */

/* ═══════════════════════════════════════════════════════════════════════════
   TABLET 901-1024px
   ═══════════════════════════════════════════════════════════════════════════ */
@media (max-width: 1024px) and (min-width: 901px) {
  .sidebar { width: 200px !important; min-width: 200px !important; }
  .metrics-grid { grid-template-columns: repeat(3, 1fr) !important; }
  .charts-row:has(.chart-large) { grid-template-columns: 1fr !important; }
}

/* ═══════════════════════════════════════════════════════════════════════════
   MOBILE até 900px
   ═══════════════════════════════════════════════════════════════════════════ */
@media (max-width: 900px) {

  /* ─── BASE ──────────────────────────────────────────── */
  html { font-size: 13px; }
  body {
    display: block !important;
    height: auto !important;
    min-height: 100vh;
    overflow-x: hidden !important;
    overflow-y: auto !important;
  }

  /* ─── SIDEBAR como drawer ───────────────────────────── */
  .sidebar {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    height: 100vh !important;
    width: 80vw !important;
    min-width: 80vw !important;
    max-width: 320px !important;
    z-index: 9998 !important;
    transform: translateX(-100%);
    transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1) !important;
    box-shadow: 8px 0 30px rgba(0, 0, 0, 0.5);
    overflow-y: auto !important;
  }
  .sidebar.mobile-open { transform: translateX(0) !important; }
  .sidebar-collapse { display: none !important; }

  .sidebar-mobile-overlay {
    position: fixed; inset: 0;
    background: rgba(0, 0, 0, 0.55);
    backdrop-filter: blur(2px);
    z-index: 9997;
    opacity: 0; pointer-events: none;
    transition: opacity 0.25s;
  }
  .sidebar-mobile-overlay.active { opacity: 1; pointer-events: auto; }

  /* ─── MAIN WRAPPER ────────────────────────────────────── */
  .main-wrapper {
    width: 100% !important;
    max-width: 100vw !important;
    padding-top: 56px !important;
  }

  /* ─── TOPBAR reorganizada ────────────────────────────── */
  .topbar {
    position: fixed !important;
    top: 0; left: 0; right: 0;
    z-index: 9996;
    height: 56px;
    padding: 0 10px !important;
    background: #161616 !important;
    border-bottom: 1px solid #252525;
    display: flex !important;
    align-items: center !important;
    justify-content: space-between !important;
    gap: 6px !important;
    flex-wrap: nowrap !important;
  }
  .topbar-left {
    flex: 1 1 auto !important;
    min-width: 0 !important;
    gap: 8px !important;
    display: flex;
    align-items: center;
    overflow: hidden;
  }
  .topbar-title {
    font-size: 15px !important;
    font-weight: 700 !important;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
    flex: 1;
  }

  /* Botão hamburger */
  .yb-mobile-menu-btn {
    display: flex !important;
    align-items: center;
    justify-content: center;
    width: 38px; height: 38px;
    border-radius: 10px;
    border: 1px solid #333;
    background: #1a1a1a;
    color: #f5c518;
    font-size: 19px;
    cursor: pointer;
    flex-shrink: 0;
    padding: 0;
  }
  .yb-mobile-menu-btn:active { background: #222; transform: scale(0.96); }

  /* Topbar right + menu ⋮ */
  .topbar-right {
    gap: 6px !important;
    flex-wrap: nowrap !important;
    flex-shrink: 0 !important;
    display: flex;
    align-items: center;
  }

  /* Esconde tudo do topbar-right menos o menu ⋮ e AO VIVO */
  .topbar-clock,
  .topbar-right > *:not(.yb-mobile-topbar-menu):not([data-keep-mobile="true"]) {
    display: none !important;
  }

  /* Badge AO VIVO pequeno, 1 linha */
  [class*="live-badge"],
  .topbar-right span[style*="vermelho"],
  .topbar-right [data-keep-mobile="true"] {
    font-size: 9px !important;
    padding: 3px 6px !important;
    white-space: nowrap !important;
    flex-shrink: 0 !important;
    line-height: 1 !important;
  }

  /* Botão ⋮ */
  .yb-mobile-topbar-menu {
    display: flex !important;
    align-items: center;
    justify-content: center;
    width: 38px; height: 38px;
    border-radius: 10px;
    border: 1px solid #333;
    background: #1a1a1a;
    color: #f5c518;
    font-size: 22px;
    cursor: pointer;
    flex-shrink: 0;
    font-weight: 900;
    padding: 0;
  }

  /* Drawer do menu ⋮ */
  .yb-mobile-actions-drawer {
    position: fixed;
    top: 62px;
    right: 10px;
    background: #1a1a1a;
    border: 1px solid #333;
    border-radius: 14px;
    padding: 10px;
    box-shadow: 0 10px 30px rgba(0,0,0,.5);
    z-index: 9995;
    display: none;
    flex-direction: column;
    gap: 6px;
    min-width: 220px;
    max-width: calc(100vw - 20px);
  }
  .yb-mobile-actions-drawer.active { display: flex; }
  .yb-mobile-actions-drawer > * {
    width: 100% !important;
    justify-content: flex-start !important;
    text-align: left !important;
    font-size: 13px !important;
    padding: 10px 14px !important;
    min-width: 0 !important;
  }

  /* ─── PAGE HEADER ────────────────────────────────────── */
  .page-header { padding: 16px 14px !important; }
  .page-header h1, .page-header .page-title {
    font-size: 22px !important;
    line-height: 1.3 !important;
    font-weight: 800 !important;
  }
  .page-header .page-subtitle, .page-header p {
    font-size: 12px !important;
    line-height: 1.4 !important;
  }

  /* ─── FILTROS (período, loja) — limpa bordas coloridas ── */
  .filter-bar,
  .filters-row,
  .vendas-filters,
  .dashboard-filters {
    flex-direction: column !important;
    gap: 10px !important;
    padding: 12px 14px !important;
    align-items: stretch !important;
    border-radius: 12px !important;
  }
  .filter-bar > *, .filters-row > *,
  .vendas-filters > *, .dashboard-filters > * {
    width: 100% !important;
    max-width: 100% !important;
  }

  /* Remove bordas tracejadas laranja/vermelho no mobile */
  [style*="border:"][style*="dashed"],
  [style*="border: 1px dashed"] {
    border-style: solid !important;
    border-color: #333 !important;
  }

  /* ─── MÉTRICAS: 1 coluna ─────────────────────────────── */
  .metrics-grid {
    grid-template-columns: 1fr !important;
    gap: 10px !important;
    padding: 10px 14px !important;
  }
  .metric-card { padding: 14px !important; }
  .metric-value, .metrica-box-value {
    font-size: 24px !important;
    line-height: 1.1 !important;
  }
  .metric-value.metric-lg { font-size: 22px !important; }
  .metric-label, .metrica-box-label {
    font-size: 10px !important;
    letter-spacing: .05em !important;
  }
  .metric-sub, .metrica-box-sub { font-size: 11px !important; }

  /* ─── CHARTS ROW: tudo 1 coluna ───────────────────────── */
  .charts-row,
  .charts-row:has(.chart-large),
  .charts-row:has(.chart-card:nth-child(3)) {
    grid-template-columns: 1fr !important;
    gap: 12px !important;
    margin: 0 !important;
    padding: 10px 14px !important;
  }
  .chart-card { min-width: 0 !important; padding: 12px !important; }
  .chart-body { min-height: 200px !important; }
  .chart-title { font-size: 13px !important; }

  /* ─── TOP 5 DO DASHBOARD — problema de sobreposição ────── */
  #ybDashboardTopCharts,
  [id*="DashboardTop"] {
    margin: 12px 14px !important;
  }

  /* Força grid interno a 1 coluna */
  #ybDashboardTopCharts > div[style*="grid-template-columns"],
  [id*="DashboardTop"] > div[style*="grid-template-columns"] {
    grid-template-columns: 1fr !important;
    gap: 12px !important;
  }

  /* Linhas dos rankings: previne sobreposição de nome e valor */
  #ybDashboardTopCharts [style*="display:flex"]:has(>[style*="font-weight:800"]),
  #ybDashboardTopCharts > div > div > div[style*="display:flex"] {
    flex-wrap: wrap !important;
    row-gap: 6px !important;
    align-items: flex-start !important;
  }
  /* Garante min-width 0 em filhos de flex pra respeitar wrap */
  #ybDashboardTopCharts [style*="display:flex"] > * {
    min-width: 0 !important;
  }

  /* ─── INPUTS & SELECTS ──────────────────────────────── */
  select, input[type="text"], input[type="date"], input[type="search"],
  input[type="number"], input[type="password"], input[type="email"], textarea {
    width: 100% !important;
    min-height: 44px !important;
    font-size: 14px !important;
    padding: 10px 14px !important;
    border-radius: 10px !important;
    -webkit-appearance: none;
    appearance: none;
    box-sizing: border-box;
  }
  select {
    background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%23999' d='M6 8L0 0h12z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 14px center;
    padding-right: 34px !important;
  }

  /* ─── BOTÕES ──────────────────────────────────────────── */
  button, .btn, .btn-primary, .btn-secondary {
    min-height: 42px !important;
    font-size: 13px !important;
    padding: 10px 14px !important;
  }
  .btn-sm {
    min-height: 36px !important;
    font-size: 12px !important;
    padding: 8px 12px !important;
  }

  /* ─── TABELAS: scroll horizontal ─────────────────────── */
  table, .yb-table {
    display: block !important;
    width: 100% !important;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch !important;
    font-size: 12px !important;
  }
  .table-responsive, .yb-table-wrapper {
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch !important;
    width: 100% !important;
  }

  /* ─── MODAIS — tela cheia ────────────────────────────── */
  .modal-overlay,
  .modal-container,
  [class*="modal-overlay"] { padding: 0 !important; }

  .modal-content,
  .modal-body,
  .yb-modal-content,
  [class*="modal-content"] {
    width: 100vw !important;
    max-width: 100vw !important;
    min-height: 100vh !important;
    max-height: 100vh !important;
    border-radius: 0 !important;
    margin: 0 !important;
    display: flex;
    flex-direction: column;
  }

  /* Abas do modal (Anúncios/Vendas/Métricas) ficam no topo */
  .modal-tabs,
  .yb-modal-tabs,
  [class*="modal-tabs"] {
    position: sticky;
    top: 0;
    background: #161616;
    z-index: 10;
    padding: 10px 14px 0 !important;
    border-bottom: 1px solid #2a2a2a;
    display: flex;
    gap: 8px;
    overflow-x: auto;
  }
  .modal-tabs > * {
    flex-shrink: 0;
  }

  /* ─── TOAST: NÃO TAPA OS BOTÕES ──────────────────────── */
  .toast,
  .toast-container,
  [class*="toast"],
  [id*="toast"] {
    bottom: 16px !important;
    left: 10px !important;
    right: 10px !important;
    max-width: calc(100vw - 20px) !important;
    font-size: 12px !important;
    z-index: 9994 !important;
  }
  /* Mas toast de erro dentro de modal fica acima do botão do modal */
  .modal-content .toast,
  .modal-body .toast {
    position: sticky !important;
    bottom: 70px !important;
  }

  /* ─── VENDEDORES — cards empilhados ───────────────────── */
  .vendor-card, .yb-vendor-card { padding: 14px !important; }
  .vendor-metrics-grid, .vendor-stats-grid {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 8px !important;
  }

  /* ─── VENDAS & IMPRESSÃO (envios) ─────────────────────── */
  #enviosContent article { width: 100% !important; }
  #enviosContent article > div[style*="grid-template-columns"] {
    grid-template-columns: 1fr !important;
    gap: 12px !important;
    padding: 14px !important;
  }
  #enviosContent article > div > div[style*="grid-template-columns"] {
    grid-template-columns: repeat(2, 1fr) !important;
  }
  #enviosContent button[onclick*="setEnviosOperationalStatusFilter"] {
    flex: 1;
    min-width: 0;
    font-size: 10px !important;
    padding: 8px 6px !important;
  }

  /* ─── CATÁLOGO / ANÚNCIOS — balanceia colunas ─────────── */
  /* As tabelas de anúncios com colunas PREÇO / CUSTOS / MARGEM / ESTOQUE
     têm custo muito grande. Força cada coluna a largura razoável. */
  [class*="catalog"] table td,
  [class*="catalog"] table th {
    padding: 8px 10px !important;
    font-size: 11px !important;
    vertical-align: top !important;
  }
  [class*="catalog"] table td:first-child {
    min-width: 70px !important;
    max-width: 90px !important;
    word-break: break-all;
  }

  /* ─── ESTOQUE FULL ────────────────────────────────────── */
  .catalog-grid, .estoque-grid, .produtos-grid {
    grid-template-columns: 1fr !important;
    gap: 10px !important;
  }

  /* ─── FINANCEIRO ──────────────────────────────────────── */
  .chart-grid { grid-template-columns: 1fr !important; gap: 12px !important; }

  /* ─── RELATÓRIOS ──────────────────────────────────────── */
  .reports-grid { grid-template-columns: 1fr !important; }

  /* ─── LOGIN / ACESSO INTERNO — compacta ──────────────── */
  .yb-internal-access,
  .yb-internal-access-card,
  [class*="internal-access"] {
    padding: 16px !important;
    margin: 10px !important;
    max-width: calc(100vw - 20px) !important;
    box-sizing: border-box;
  }
  .yb-internal-access-card { padding: 20px 18px !important; }
  .yb-internal-access-text {
    font-size: 12px !important;
    line-height: 1.5 !important;
    margin: 8px 0 !important;
  }
  .yb-internal-access-input {
    font-size: 14px !important;
    padding: 12px 14px !important;
  }

  /* ─── AJUSTES GERAIS — grids inline hardcoded ─────────── */
  /* Regra geral: grids multi-coluna viram 1 coluna no celular.
     Exclui sidebar pra não quebrar o menu. */
  main [style*="grid-template-columns: repeat(3"],
  main [style*="grid-template-columns: repeat(4"],
  main [style*="grid-template-columns: repeat(5"],
  main [style*="grid-template-columns: repeat(auto-fit"],
  main [style*="grid-template-columns:minmax"] {
    grid-template-columns: 1fr !important;
  }
  main [style*="grid-template-columns: repeat(2"] {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }

  /* Min-widths grandes reseta */
  [style*="min-width:640"], [style*="min-width:600"],
  [style*="min-width:560"], [style*="min-width:520"],
  [style*="min-width:480"], [style*="min-width:460"],
  [style*="min-width:440"], [style*="min-width:420"],
  [style*="min-width:400"], [style*="min-width:380"],
  [style*="min-width:360"], [style*="min-width:340"],
  [style*="min-width:320"], [style*="min-width:300"],
  [style*="min-width:280"], [style*="min-width:260"] {
    min-width: 0 !important;
  }

  /* Scrollbar discreto */
  ::-webkit-scrollbar { width: 4px; height: 4px; }
}

/* ═══════════════════════════════════════════════════════════════════════════
   MOBILE PEQUENO — 430px (iPhone SE, compactos)
   ═══════════════════════════════════════════════════════════════════════════ */
@media (max-width: 430px) {
  html { font-size: 12px; }
  .page-header h1 { font-size: 20px !important; }
  .metric-value, .metrica-box-value { font-size: 22px !important; }
  .metric-value.metric-lg { font-size: 20px !important; }
  .topbar-title { font-size: 14px !important; }
  .sidebar { width: 86vw !important; min-width: 86vw !important; }

  .yb-mobile-menu-btn,
  .yb-mobile-topbar-menu {
    width: 36px !important;
    height: 36px !important;
  }

  [class*="live-badge"],
  .topbar-right [data-keep-mobile="true"] {
    font-size: 8px !important;
    padding: 3px 5px !important;
  }
}

/* ═══════════════════════════════════════════════════════════════════════════
   ESCONDE ELEMENTOS DO MOBILE NO DESKTOP
   ═══════════════════════════════════════════════════════════════════════════ */
.yb-mobile-menu-btn,
.yb-mobile-topbar-menu,
.sidebar-mobile-overlay,
.yb-mobile-actions-drawer { display: none; }

@media (min-width: 901px) {
  .yb-mobile-menu-btn,
  .yb-mobile-topbar-menu,
  .sidebar-mobile-overlay,
  .yb-mobile-actions-drawer { display: none !important; }
}


/* ===== YB CLEAN LAYOUT MOBILE POLISH ===== */
@media (max-width: 900px) {
  body {
    background: linear-gradient(180deg, #101214 0%, #12151a 100%) !important;
  }

  .topbar {
    top: 8px !important;
    left: 10px !important;
    right: 10px !important;
    width: auto !important;
    height: 54px !important;
    border-radius: 16px !important;
    padding: 0 12px !important;
    border: 1px solid rgba(255,255,255,0.07) !important;
    background: rgba(19,22,27,.92) !important;
    box-shadow: 0 16px 36px rgba(0,0,0,.24) !important;
  }

  .main-wrapper {
    padding-top: 72px !important;
  }

  .content {
    padding: 12px !important;
  }

  .page-header {
    padding: 12px 6px !important;
  }

  .metric-card,
  .chart-card,
  .vendor-search-bar,
  .vendor-table-wrap,
  .vendor-card,
  .report-card,
  .settings-card,
  .cp-filter-card,
  .cp-summary-card,
  .cp-table-card,
  .cp-drawer {
    border-radius: 16px !important;
  }

  .sidebar {
    border-right: 1px solid rgba(255,255,255,0.06) !important;
    background: rgba(16,18,20,.98) !important;
  }

  .yb-mobile-menu-btn,
  .yb-mobile-topbar-menu {
    border-radius: 12px !important;
    border-color: rgba(255,255,255,0.09) !important;
    background: rgba(255,255,255,0.04) !important;
  }
}

