/* ============================================================================
   mobile-shell.css
   Camada de adaptações mobile-only (≤768px). Não afeta desktop.
   Inclui em qualquer página com sidebar para habilitar drawer + touch targets.
   ============================================================================ */

/* Hambúrguer escondido por padrão (só aparece em mobile via @media abaixo) */
.mobile-hamburger {
  display: none;
}

/* Overlay escondido por padrão */
.mobile-drawer-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
  z-index: 998;
  cursor: pointer;
}
body.mobile-drawer-open .mobile-drawer-overlay {
  display: block;
}

/* ============================================================================
   MOBILE BREAKPOINT — tudo que está aqui SÓ vale em telas <=768px.
   Em desktop nenhuma dessas regras dispara — a página renderiza igualzinho.
   ============================================================================ */
@media (max-width: 768px) {

  /* === SIDEBAR vira DRAWER fixo, fechado por padrão === */
  #sidebar {
    position: fixed !important;
    top: 0;
    left: 0;
    bottom: 0;
    width: 280px !important;
    min-width: 280px !important;
    max-width: 85vw;
    z-index: 999;
    transform: translateX(-100%);
    transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.45);
    overflow-y: auto;
  }
  #sidebar.mobile-open {
    transform: translateX(0);
  }

  /* Sidebar nunca fica em modo "collapsed" no mobile (sempre full quando aberto) */
  #sidebar.collapsed {
    width: 280px !important;
    min-width: 280px !important;
  }
  #sidebar.collapsed .sidebar-label,
  #sidebar.collapsed .nav-section-label,
  #sidebar.collapsed .sidebar-user-info {
    display: block !important;
  }
  #sidebar.collapsed .sidebar-logo {
    justify-content: space-between !important;
  }
  #sidebar.collapsed .sidebar-logo-lockup {
    display: flex !important;
  }
  #sidebar.collapsed .sidebar-logo-emblem {
    display: none !important;
  }

  /* IMPORTANTE — quando o drawer está aberto, restaurar TODAS as labels e o lockup,
     anulando @media (max-width: 900px) das páginas (dashboard, alertas-tecnicos, etc.)
     que forçam estilos colapsados via #sidebar (sem usar .collapsed). Sem esses overrides
     o drawer abre só com ícones, sem texto, deixando o emblem do logo gigante. */
  #sidebar.mobile-open .sidebar-label,
  #sidebar.mobile-open .nav-section-label,
  #sidebar.mobile-open .sidebar-user-info,
  #sidebar.mobile-open .sidebar-collapse-text {
    display: block !important;
  }
  #sidebar.mobile-open .sidebar-logo {
    justify-content: flex-start !important;
    padding: 1.1rem 1.2rem !important;
  }
  #sidebar.mobile-open .sidebar-logo-lockup {
    display: flex !important;
  }
  #sidebar.mobile-open .sidebar-logo-emblem {
    display: none !important;
  }
  #sidebar.mobile-open .nav-item {
    justify-content: flex-start !important;
  }

  /* === MAIN AREA ocupa toda a largura quando o drawer está fechado === */
  .main-area {
    width: 100% !important;
    margin-left: 0 !important;
  }

  /* === HAMBÚRGUER aparece === */
  .mobile-hamburger {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    background: rgba(72, 149, 255, 0.08);
    border: 1px solid rgba(96, 165, 250, 0.28);
    border-radius: 9px;
    color: var(--text-primary, #f5f7fa);
    cursor: pointer;
    flex-shrink: 0;
    padding: 0;
    margin-right: 0.6rem;
    transition: background 0.15s, border-color 0.15s;
  }
  .mobile-hamburger:hover,
  .mobile-hamburger:focus {
    background: rgba(72, 149, 255, 0.18);
    border-color: rgba(96, 165, 250, 0.5);
    outline: none;
  }
  .mobile-hamburger svg {
    width: 22px;
    height: 22px;
    stroke: currentColor;
    fill: none;
    stroke-width: 2.4;
    stroke-linecap: round;
    stroke-linejoin: round;
  }

  /* === HEADER readjust pra receber o hambúrguer === */
  .dash-header {
    padding-left: 1rem !important;
    padding-right: 1rem !important;
  }
  .dash-header-left {
    display: flex !important;
    align-items: center !important;
    min-width: 0;
    flex: 1;
  }
  .dash-header-left h1 {
    font-size: 1rem !important;
    line-height: 1.2;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .dash-header-left .greeting-meta {
    display: none !important; /* poupar espaço em mobile */
  }

  /* === HEADER buttons compactos === */
  .header-clock,
  .header-btn span {
    display: none; /* esconder texto, só ícone */
  }
  .header-btn {
    padding: 0.5rem !important;
    width: 40px;
    height: 40px;
    justify-content: center;
  }
  .header-btn svg {
    margin: 0;
  }

  /* === TABELAS — scroll horizontal com indicador === */
  .data-table,
  table.data {
    min-width: 540px; /* força scroll quando container é menor */
  }
  .data-table-wrap,
  div[style*="overflow-x"] {
    -webkit-overflow-scrolling: touch;
    position: relative;
  }
  /* Sombra sutil na borda direita pra sinalizar que tem mais conteúdo */
  div[style*="overflow-x:auto"]:not(:empty)::after,
  div[style*="overflow-x: auto"]:not(:empty)::after {
    content: '';
    position: sticky;
    right: 0;
    top: 0;
    bottom: 0;
    width: 24px;
    background: linear-gradient(90deg, transparent, rgba(0, 0, 0, 0.4));
    pointer-events: none;
  }

  /* === TOUCH TARGETS — mínimo 44px (Apple HIG / Material) === */
  .nav-item {
    min-height: 44px !important;
    padding: 0.7rem 0.85rem !important;
  }
  .filter-tab,
  .header-btn,
  .btn-icon {
    min-height: 40px;
  }
  .btn-primary,
  .btn-secondary,
  button[type="submit"] {
    min-height: 44px;
    padding-left: 1rem;
    padding-right: 1rem;
  }

  /* === GRIDS de KPI/cards stackam em 1 coluna === */
  .kpi-grid,
  .kpis,
  .feed-heatmap-grid {
    grid-template-columns: 1fr !important;
    gap: 0.75rem !important;
  }

  /* === SIDEBAR-USER (parte de baixo do drawer) — sempre visível em mobile === */
  .sidebar-user {
    border-top: 1px solid var(--line-strong, rgba(96,165,250,0.22));
  }

  /* Dash content padding mais apertado */
  .dash-content {
    padding: 1rem !important;
  }
}

/* ============================================================================
   FASE 2 — Polish: KPIs compactos, filtros scrolláveis, charts adaptáveis,
   tabelas com sticky header, grids reorganizados.
   ============================================================================ */
@media (max-width: 768px) {

  /* === KPIs compactos === */
  .kpi-card {
    padding: 0.85rem 1rem !important;
    border-radius: 12px !important;
  }
  .kpi-card .kpi-value {
    font-size: 1.45rem !important;
    line-height: 1.1;
  }
  .kpi-card .kpi-label {
    font-size: 0.65rem !important;
    letter-spacing: 0.08em;
  }
  .kpi-card .kpi-sub {
    font-size: 0.7rem !important;
  }
  .kpi-card.kpi-sentiment .kpi-value .fg-label {
    font-size: 0.5em !important;
  }

  /* === FILTROS — scroll horizontal suave, esconde scrollbar === */
  .filter-bar {
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
    flex-wrap: nowrap !important;
    padding-bottom: 4px;
    scrollbar-width: none; /* Firefox */
  }
  .filter-bar::-webkit-scrollbar {
    display: none; /* WebKit */
  }
  .filter-bar .filter-group {
    flex-shrink: 0;
  }
  .filter-bar .filter-sep {
    display: none !important; /* poupar espaço */
  }
  .filter-bar .filter-label {
    font-size: 0.62rem !important;
  }
  /* Pair filter trigger button vira full-width logo abaixo dos pills */
  .pair-filter-wrap {
    width: 100%;
    margin-top: 0.5rem;
  }
  .pair-filter-trigger {
    width: 100%;
    justify-content: center;
  }

  /* === TradingView chart — altura adaptável === */
  .tv-container,
  .tv-container > #tradingview_widget {
    height: 60vh !important;
    min-height: 360px !important;
    max-height: 560px !important;
  }
  /* Side panel do pair-detail vai pra baixo do chart em mobile */
  .pair-layout {
    grid-template-columns: 1fr !important;
  }
  .side-panel {
    width: 100% !important;
  }

  /* === TABELAS — sticky header pra scroll vertical em listas longas === */
  .data-table thead {
    position: sticky;
    top: 0;
    z-index: 2;
  }
  .data-table thead th {
    background: rgba(7, 16, 31, 0.98) !important;
    backdrop-filter: blur(4px);
  }

  /* === CRYPTO SELECT — grid em 2 colunas (não 3 nem 1) === */
  .pairs-grid {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 0.6rem !important;
  }
  .pair-card-top,
  .pair-card-mid,
  .pair-card-bot {
    font-size: 0.78rem !important;
  }

  /* === ACADEMY — módulos em 1 coluna (cards mais legíveis) === */
  .module-grid,
  .materials-grid {
    grid-template-columns: 1fr !important;
  }

  /* === HEATMAP de pares (12 pares) === */
  .heatmap,
  .tier-heatmap,
  div[class*="heatmap"] {
    grid-template-columns: repeat(3, 1fr) !important;
    gap: 0.4rem !important;
  }

  /* === CARDS gerais menos padding === */
  .dash-card,
  section.dash-card,
  .audit-section,
  .panel-card {
    padding: 1rem !important;
    border-radius: 12px !important;
  }
  .section-title {
    font-size: 0.9rem !important;
  }

  /* === ALERT cards mais compactos === */
  .alert-card {
    padding: 0.85rem !important;
  }

  /* === Sentiment bar em alertas-tecnicos === */
  .sent-bar,
  .sentiment-bar {
    height: 8px !important;
  }

  /* === Botões de ação principais === */
  .plan-cta,
  .header-btn-primary,
  .btn-cta {
    width: 100%;
    justify-content: center;
  }
}

/* Telas muito pequenas (≤480px) — compactação agressiva */
@media (max-width: 480px) {
  .dash-header-left h1 {
    font-size: 0.95rem !important;
  }
  .dash-header {
    padding: 0.7rem 0.85rem !important;
  }
  #sidebar {
    width: 260px !important;
    min-width: 260px !important;
  }

  /* KPIs ainda menores */
  .kpi-card .kpi-value {
    font-size: 1.25rem !important;
  }
  .kpi-card {
    padding: 0.7rem 0.85rem !important;
  }

  /* Chart bem menor */
  .tv-container,
  .tv-container > #tradingview_widget {
    height: 50vh !important;
    min-height: 300px !important;
  }

  /* Crypto-select volta pra 1 coluna em telas bem pequenas */
  .pairs-grid {
    grid-template-columns: 1fr !important;
  }

  /* Heatmap em 2 colunas em phones pequenos */
  .heatmap,
  .tier-heatmap {
    grid-template-columns: repeat(2, 1fr) !important;
  }

  /* Section title minimalista */
  .section-title {
    font-size: 0.82rem !important;
  }

  /* Section title icon menor */
  .section-title svg {
    width: 14px !important;
    height: 14px !important;
  }
}
