/* ── MERIDIAN MOBILE ── breakpoint 640px ──────────────────────────────────── */

/* ── Kill old hamburger system everywhere ── */
.mobile-toggle { display: none !important; }

/* ── Mobile top header ── */
.mobile-header {
  display: none;
  position: fixed; top: 0; left: 0; right: 0; z-index: 900;
  min-height: 52px; background: #fff; border-bottom: 1px solid #eef0f3;
  padding: 0 16px; padding-top: env(safe-area-inset-top, 0px);
  align-items: center; justify-content: space-between;
  box-sizing: border-box;
}
.mobile-header-brand { display: flex; align-items: center; gap: 8px; }
.mobile-header-brand img { width: 26px; height: 26px; }
.mobile-header-brand span { font-family: 'DM Sans', sans-serif; font-size: 12px; font-weight: 600; letter-spacing: .35em; color: #0f1a3d; }
.mobile-avatar {
  width: 32px; height: 32px; border-radius: 50%; background: #2b57d0; color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 600; cursor: pointer; user-select: none;
}

/* ── Avatar dropdown menu ── */
.mobile-menu-overlay {
  display: none; position: fixed; inset: 0; z-index: 950; background: rgba(0,0,0,.25);
}
.mobile-menu-overlay.open { display: block; }
.mobile-menu {
  position: fixed; top: 52px; right: 12px; z-index: 960;
  width: 220px; background: #fff; border-radius: 12px;
  box-shadow: 0 8px 30px rgba(0,0,0,.15); padding: 8px 0;
  display: none;
}
.mobile-menu.open { display: block; }
.mobile-menu-user { padding: 12px 16px; border-bottom: 1px solid #f1f5f9; }
.mobile-menu-user-name { font-size: 13px; font-weight: 600; color: #0f172a; }
.mobile-menu-user-email { font-size: 11px; color: #94a3b8; margin-top: 2px; }
.mobile-menu-item {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 11px 16px; border: none; background: none; cursor: pointer;
  font-size: 13px; font-family: inherit; color: #475569; text-align: left;
}
.mobile-menu-item:hover { background: #f8fafc; }
.mobile-menu-item i { font-size: 16px; color: #64748b; }
.mobile-menu-item.danger { color: #dc2626; }
.mobile-menu-item.danger i { color: #dc2626; }
.mobile-menu-divider { height: 1px; background: #f1f5f9; margin: 4px 0; }

/* ── Bottom tab bar ── */
.mobile-tabs {
  display: none;
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 900;
  height: 60px; background: #fff; border-top: 1px solid #eef0f3;
  justify-content: space-around; align-items: center; padding: 0;
}
.mobile-tab {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 3px; text-decoration: none; color: #64748b; min-height: 44px; padding: 6px 0;
}
.mobile-tab i { font-size: 20px; }
.mobile-tab svg { width: 22px; height: 22px; flex-shrink: 0; }
.mobile-tab span { font-size: 10px; font-weight: 500; }
.mobile-tab.active { color: #2b57d0; }
.mobile-tab.active i, .mobile-tab.active svg { color: #2b57d0; }

/* ══════════════════════════════════════════════════════════════════════════ */
/* ── Breakpoint ≤640px                                                  ── */
/* ══════════════════════════════════════════════════════════════════════════ */
@media (max-width: 640px) {

  /* ── GLOBAL: nuke overflow at the root ───────────────────────────────── */
  html, body { overflow-x: hidden !important; }
  * { box-sizing: border-box !important; }

  /* Layout: kill sidebar, full width, tight padding */
  .layout { grid-template-columns: 1fr !important; }
  .sidebar { display: none !important; }

  /* ALL main containers — same 14px padding, no overflow */
  /* 52px header + safe-area-inset-top + 12px gap = ~64px top; 60px tabs + 14px = 74px bottom */
  .main,
  .proy-main { padding: 64px 14px 74px !important; padding-top: calc(52px + env(safe-area-inset-top, 0px) + 12px) !important; max-width: 100% !important; overflow-x: hidden !important; }

  /* Show mobile chrome */
  .mobile-header { display: flex !important; }
  .mobile-tabs { display: flex !important; }

  /* ── Analisis ── */
  .analisis-header { padding: 12px 14px 0 !important; margin-bottom: 12px !important; }
  .analisis-tabs { margin: 0 -14px !important; padding: 0 14px !important; }
  .analisis-tab { padding: 8px 12px 10px !important; font-size: 12px !important; }
  .analisis-body { flex-direction: column !important; }
  .analisis-main { gap: 14px !important; }

  /* Stack selectors */
  .us-form { flex-direction: column !important; }
  .us-field { min-width: 100% !important; width: 100% !important; }
  .us-btn { width: 100% !important; padding: 12px !important; min-height: 44px; }
  .est-form { flex-direction: column !important; }
  .est-form .ci-select { min-width: 100% !important; }
  .est-btn { width: 100% !important; padding: 12px !important; min-height: 44px; }

  /* Pills: fill width */
  .ci-pills { flex-wrap: wrap !important; }
  .ci-pill { flex: 1 !important; justify-content: center !important; min-height: 44px !important; padding: 8px 10px !important; }
  .ci-toggle { display: flex !important; width: 100% !important; }
  .ci-toggle-btn { flex: 1 !important; min-height: 44px !important; }

  /* Chips: wrap */
  .est-chips { gap: 6px !important; }
  .est-chip { min-height: 36px !important; padding: 6px 10px !important; }

  /* CI card */
  .ci-card { padding: 14px !important; }
  .est-card { padding: 14px !important; }

  /* Result card: numbers don't overflow */
  .est-price-val { font-size: 26px !important; }
  .ci-val { font-size: 22px !important; }
  .ci-arancel-pct { font-size: 22px !important; }

  /* Feed signals: tag below text */
  .tend-signal { flex-wrap: wrap !important; }
  .tend-right { flex-direction: row !important; width: 100% !important; margin-left: 22px !important; margin-top: 4px !important; gap: 8px !important; }

  /* Aranceles filters */
  .ci-filters { flex-direction: column !important; }
  .ci-filters .ci-select { min-width: 100% !important; }

  /* Panel */
  .panel { overflow: hidden !important; }
  .panel-header { padding: 10px 14px !important; flex-wrap: wrap !important; gap: 6px !important; }
  .panel-body { padding: 0 14px !important; }

  /* ── RESUMEN ────────────────────────────────────────────────────────── */
  .hero { padding: 16px !important; border-radius: 12px !important; }
  .hero-top { flex-wrap: wrap !important; gap: 6px !important; }
  .hero-value { font-size: 26px !important; word-break: break-word !important; }
  .hero-unit { font-size: 11px !important; }
  .hero-stats { display: grid !important; grid-template-columns: repeat(4, 1fr) !important; gap: 4px !important; font-size: 10px !important; }
  .hero-spark { height: 70px !important; width: 100% !important; }
  .hero .tw { font-size: 10px !important; padding: 2px 6px !important; }

  /* QS cards */
  .qs-grid, .qsgrid { grid-template-columns: 1fr !important; gap: 10px !important; }
  .qs { padding: 14px !important; height: auto !important; min-height: auto !important; max-height: none !important; }
  .qs-top { flex-wrap: wrap !important; gap: 4px !important; }
  .qs-tw { flex-wrap: wrap !important; }
  .qs-value { font-size: 22px !important; }
  .qs-name { font-size: 12px !important; }
  .qs-spark { min-height: 48px !important; height: 48px !important; width: 100% !important; }
  .qs-spark path { vector-effect: non-scaling-stroke; }
  .qs-period-btn { min-height: 32px !important; padding: 4px 8px !important; font-size: 11px !important; }
  .qs-stats { flex-wrap: wrap !important; gap: 4px 12px !important; font-size: 11px !important; }
  .qs-stat { white-space: nowrap !important; }
  .kpi-row { grid-template-columns: 1fr !important; gap: 10px !important; }

  /* Lower grid: activity + events */
  .lower-grid { display: flex !important; flex-direction: column !important; gap: 14px !important; }
  .lower-grid .panel { height: auto !important; min-height: auto !important; max-height: none !important; overflow: hidden !important; }
  .lower-grid .panel > div:not(.panel-header) { padding: 0 14px 14px !important; }
  #actChartWrap { height: 160px !important; flex: 0 0 auto !important; }
  #actChartSVG { width: 100% !important; }
  .act-grid { font-size: 11px !important; grid-template-columns: 1.3fr 40px 60px 55px 1fr !important; gap: 0 2px !important; }
  .act-hdr, .act-var-row { white-space: nowrap !important; }

  /* Activity sparkline cells */
  .avr-spark { width: 60px !important; min-width: 0 !important; }

  /* Activity panel: category tabs wrap */
  .act-cat-btn { padding: 6px 10px !important; font-size: 10px !important; }

  /* Hero time-window buttons: wrap */
  .hero-top .tw, .hero .tw { padding: 3px 6px !important; font-size: 10px !important; }

  /* Events */
  .eventos-section { height: auto !important; min-height: auto !important; max-height: none !important; overflow: hidden !important; }
  .ev-main { display: flex !important; flex-direction: column !important; min-width: 0 !important; overflow: hidden !important; }
  .ev-hoy-col { min-width: 0 !important; width: 100% !important; border-right: none !important; border-bottom: 2px solid #2b57d0 !important; max-height: 300px !important; overflow-y: auto !important; }
  .ev-hoy-col + div { width: 100% !important; max-height: 300px !important; overflow-y: auto !important; }
  .ev-chip-wrap { flex-wrap: wrap !important; }
  .ev-row { height: auto !important; min-height: auto !important; max-height: none !important;
    grid-template-columns: 1fr !important; }
  .ev-title { font-size: 11px !important; }
  .ev-item-title { font-size: 11px !important; }
  .ev-country-label, .ev-ctry-lbl { font-size: 12px !important; }
  .ev-day-num { font-size: 14px !important; }
  .ev-fbar { flex-wrap: wrap !important; gap: 4px !important; }
  .ev-gou-txt { font-size: 9px !important; }

  /* Modulos */
  .modulos-grid { grid-template-columns: 1fr !important; gap: 10px !important; }

  /* ── PROYECCIONES ───────────────────────────────────────────────────── */
  .proy-main { overflow-x: hidden !important; }

  /* Hero card (forecast) */
  .hero-card { padding: 16px !important; border-radius: 12px !important; margin-bottom: 14px !important; }

  /* Variable selector */
  .var-select-wrap { max-width: 100% !important; width: 100% !important; }
  .var-select-btn { max-width: 100% !important; overflow: hidden !important; text-overflow: ellipsis !important; white-space: nowrap !important; }

  /* Horizon toggles: single horizontal row */
  .horizon-toggles { display: flex !important; flex-wrap: wrap !important; gap: 4px !important; }
  .horizon-btn { flex: 1 1 auto !important; min-height: 40px !important; min-width: 0 !important; display: flex !important; align-items: center !important; justify-content: center !important; font-size: 12px !important; padding: 6px 8px !important; }

  /* Fan chart / canvas */
  .fan-chart-container { overflow: hidden !important; width: 100% !important; }
  .fan-chart-canvas { height: 200px !important; width: 100% !important; }
  canvas { max-width: 100% !important; }

  /* Forecast summary row */
  .fc-summary { flex-wrap: wrap !important; gap: 12px !important; }
  .fc-summary-value { font-size: 20px !important; word-break: break-word !important; }

  /* Secondary grid */
  .secondary-grid { grid-template-columns: 1fr !important; gap: 10px !important; }
  .secondary-card { padding: 14px !important; }
  .secondary-card-top { flex-wrap: wrap !important; gap: 6px !important; }
  .sc-value, .sec-value { font-size: 20px !important; word-break: break-word !important; }

  /* Sec horizons: 2-col grid */
  .sec-horizons { display: grid !important; grid-template-columns: repeat(2, 1fr) !important; gap: 6px !important; }
  .sec-row { flex-wrap: wrap !important; gap: 4px !important; }

  /* Chart legend: don't break words */
  .chart-legend { flex-wrap: wrap !important; gap: 8px 14px !important; font-size: 10px !important; }
  .legend-item { white-space: nowrap !important; }

  /* Empty profile */
  .empty-profile { padding: 20px !important; margin: 20px auto !important; max-width: 100% !important; }
  .empty-box p { max-width: 100% !important; }

  /* ── CONSULTOR ──────────────────────────────────────────────────────── */
  .consultor-wrap { max-width: 100% !important; width: 100% !important; padding: 0 !important;
    height: auto !important; min-height: auto !important; flex-direction: column !important; overflow: hidden !important; }
  .consultor-rail { display: none !important; }
  .consultor-center { padding: 0 !important; padding-top: calc(52px + env(safe-area-inset-top, 0px) + 14px) !important; overflow: visible !important; }
  .center-card { max-width: 100% !important; width: 100% !important; padding: 0 !important;
    margin: 0 !important; border-radius: 12px !important; min-height: auto !important;
    height: auto !important; flex: none !important; overflow: visible !important; }
  .center-scroll { padding: 24px 14px 80px !important; padding-top: 24px !important; overflow: visible !important; }
  .tlacuache-intro { max-width: 100% !important; font-size: 13px !important; }
  .tlacuache-hello h2 { font-size: 15px !important; }
  .intent-label { margin: 20px 0 10px !important; }
  .intent-grid { grid-template-columns: 1fr !important; gap: 10px !important; }
  .intent-card { min-width: 0 !important; padding: 14px !important; }
  .intent-pill { font-size: 12px !important; }
  .input-bar {
    position: fixed !important; bottom: 60px !important;
    left: 0 !important; right: 0 !important; width: 100% !important;
    border-radius: 0 !important; z-index: 800 !important;
    margin: 0 !important; padding: 8px 14px !important;
    background: #fff !important; border-top: 1px solid #eef0f3 !important;
  }
  .input-row { gap: 6px !important; }
  .input-field { font-size: 16px !important; padding: 10px 12px !important; }
  .input-notice { font-size: 10px !important; margin-top: 4px !important; }
  .live-strip { padding: 8px 14px !important; flex-wrap: wrap !important; gap: 8px !important; font-size: 11px !important; }

  /* ── Scrollable tables ── */
  .ci-desglose, table { overflow-x: auto; -webkit-overflow-scrolling: touch; }

  /* ── Touch targets ── */
  select, button { min-height: 44px; }
  .us-input-wrap { min-height: 44px; }
  .us-input-wrap select, .us-input-wrap input { min-height: 40px; }

  /* ── Charts / SVGs ── */
  svg.hero-spark { width: 100% !important; height: 70px !important; }
  svg.qs-spark { width: 100% !important; min-height: 40px !important; }
  /* Inline icon SVGs: don't constrain */
  .mobile-tab svg, .us-input-wrap svg, .ci-card-header svg,
  .est-title svg, .est-title i, .est-route-header svg, .diesel-pill svg,
  .ci-pill svg, .ci-pill i, i.ti,
  .mobile-header img, .mobile-avatar,
  .tend-dot, .est-bar-fill, .est-range-fill, .est-range-mid,
  .send-btn, .send-btn svg { max-width: none !important; }
}
