/* ============================================
   POUSADA VIVA — PMS VIVA
   Mobile Responsive Styles
   ============================================ */

/* ---- TABLET & MOBILE (max 768px) ---- */
@media screen and (max-width: 768px) {

  /* Sidebar drawer */
  .sidebar {
    display: flex;
    position: fixed;
    left: -260px;
    top: 0;
    height: 100vh;
    width: 260px;
    z-index: 200;
    transition: left 0.3s ease;
    box-shadow: none;
  }
  .sidebar.mobile-open {
    left: 0;
    box-shadow: 4px 0 20px rgba(0,0,0,0.15);
  }
  .sidebar-toggle { display: none !important; }
  .sidebar.collapsed { width: 260px; }
  .sidebar-overlay {
    display: none;
    position: fixed; top: 0; left: 0;
    width: 100%; height: 100%;
    background: rgba(0,0,0,0.4);
    z-index: 199;
  }
  .sidebar-overlay.active { display: block; }

  /* Hamburger */
  .mobile-menu-btn {
    display: flex !important;
    align-items: center; justify-content: center;
    width: 44px; height: 44px;
    background: none;
    border: 1px solid var(--border);
    border-radius: 8px;
    cursor: pointer; font-size: 18px;
    color: var(--text-primary);
    margin-right: 12px;
  }
  .bottom-nav { display: none !important; }

  /* ── Mobile font minimums (exceto dentro do calendário que tem espaço limitado) ── */
  [style*="font-size:8px"]:not(.bk-cal-grid *),
  [style*="font-size: 8px"]:not(.bk-cal-grid *),
  [style*="font-size:9px"]:not(.bk-cal-grid *),
  [style*="font-size: 9px"]:not(.bk-cal-grid *) {
    font-size: 11px !important;
  }
  [style*="font-size:10px"]:not(.bk-cal-grid *),
  [style*="font-size: 10px"]:not(.bk-cal-grid *) {
    font-size: 11px !important;
  }

  /* Main content */
  .main-content {
    margin-left: 0 !important;
    padding-bottom: 16px;
    width: 100%; max-width: 100vw;
    overflow-x: hidden;
  }
  .tab-content {
    padding: 12px;
    width: 100%; max-width: 100%;
    box-sizing: border-box;
    overflow-x: hidden;
  }
  [id^="tab-"] > div,
  [id^="tab-"] > section {
    max-width: 100%;
    overflow-x: hidden;
  }

  /* Top bar */
  .top-bar { padding: 10px 12px; height: auto; gap: 8px; }
  .top-bar h2 {
    font-size: 15px; flex: 1;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  }

  /* ---- GRIDS ---- */
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
  .card-grid.grid-4 { grid-template-columns: repeat(2, 1fr); }
  .card-grid.grid-3 { grid-template-columns: 1fr; }
  .grid-auto { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
  .grid-auto-sm { grid-template-columns: 1fr 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .proposals-grid { grid-template-columns: 1fr; }
  .suggestions-grid { grid-template-columns: 1fr; }

  /* ---- CARDS ---- */
  .card { margin-left: 0; margin-right: 0; border-radius: 8px; }
  .card-body { padding: 12px; }
  .card-header { padding: 12px; }
  .card-header h4 { font-size: 14px; }

  .status-card { padding: 14px; gap: 10px; }
  .status-icon { width: 40px; height: 40px; font-size: 16px; }
  .status-value { font-size: 20px; }
  .status-label { font-size: 11px; }

  .kpi-card { padding: 12px; }
  .kpi-value, .kpi-card-value { font-size: 20px !important; word-break: break-word; }
  .kpi-label, .kpi-card-label { font-size: 11px; }
  .kpi-card-subtitle { font-size: 9px; }
  .kpi-card-details { font-size: 10px; }

  /* ---- CHARTS ---- */
  .chart-container { width: 100%; overflow-x: auto; }
  .chart-container canvas { min-width: 300px; }
  canvas { max-width: 100% !important; }

  /* ---- TABLES ---- */
  .table-wrapper, .scroll-wrapper {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin: 0 -12px; padding: 0 12px;
  }
  .data-table { min-width: 600px; }
  .data-table th, .data-table td { padding: 10px 12px; font-size: 13px; }
  table, .table-responsive, .table-wrapper, [style*="overflow-x"] {
    -webkit-overflow-scrolling: touch;
  }

  /* ---- MODALS ---- */
  .modal-content, .modal-sm {
    width: 100% !important; max-width: 100% !important;
    height: 100%; max-height: 100%;
    border-radius: 0;
    animation: modalInMobile 0.2s ease;
  }
  @keyframes modalInMobile {
    from { opacity: 0; transform: translateY(20px); }
    to   { opacity: 1; transform: translateY(0); }
  }

  /* ---- TOOLBARS & FILTERS ---- */
  .toolbar { flex-direction: column; align-items: stretch; }
  .filter-bar { flex-direction: column; }
  .filter-bar .form-select { width: 100%; min-width: auto; }
  .period-selector { flex-wrap: wrap; justify-content: center; }
  .toolbar-actions { justify-content: center; }
  .section-title { flex-direction: column; align-items: flex-start; gap: 8px; }

  /* ---- BUTTONS & TOUCH TARGETS ---- */
  .btn { min-height: 44px; padding: 12px 20px; }
  .btn-sm { min-height: 40px; padding: 8px 16px; }
  /* Touch targets — exceto micro-botões dentro do calendário e modais */
  .btn, a.btn, .toolbar button, .filter-bar button {
    min-height: 44px;
  }
  /* Botões dentro do calendário e modais mantêm tamanho original */
  .bk-cal-grid button,
  #bk-full-overlay button[style*="background:none"],
  #bk-full-overlay button[style*="padding:2px"],
  #bk-full-overlay button[style*="padding:3px"],
  button[style*="background:none"],
  button[style*="padding:2px"],
  button[style*="padding:3px"] {
    min-height: auto;
    min-width: auto;
  }

  /* ---- PROPOSALS ---- */
  .proposal-card-budget input { width: 100px; }
  .proposal-card-actions { flex-direction: column; }
  .proposal-card-actions .btn { width: 100%; justify-content: center; }

  /* ---- CREATIVE ---- */
  .drop-zone { padding: 24px; }
  .drop-zone-icon { font-size: 36px; }
  .preview-grid { flex-direction: column; align-items: center; }
  .feed-frame { width: 100%; max-width: 300px; }
  .stories-frame { width: 180px; }

  /* ---- BOOKINGS CALENDAR (mobile: scroll horizontal, expande vertical) ---- */
  .bk-cal-container { overflow: auto !important; -webkit-overflow-scrolling: touch; max-height: none !important; }
  .bk-cal-grid { min-width: max-content !important; }
  /* Touch: booking bars clicáveis sem interferir scroll */
  .bk-booking-bar { touch-action: auto !important; cursor: pointer !important; }
  .bk-cal-cell { touch-action: auto !important; min-height: 38px !important; }

  .dc-grid-wrap { overflow: auto !important; -webkit-overflow-scrolling: touch; }
  .dc-grid-wrap .bk-cal-grid { min-width: max-content !important; }

  .bk-nav-bar { flex-wrap: wrap; padding: 10px !important; gap: 6px; }
  .bk-nav-date { font-size: 13px !important; width: 100%; text-align: center; order: -1; }
  .dc-radio-bar { gap: 3px !important; }
  .dc-radio { font-size: 10px !important; padding: 3px 7px !important; }

  .bk-modal {
    max-width: 100% !important; width: 100% !important;
    max-height: 100vh !important; border-radius: 0 !important; margin: 0 !important;
  }
  .bk-modal-panels { flex-direction: column !important; }
  .bk-modal-panel-left, .bk-modal-panel-right {
    width: 100% !important; min-width: 0 !important; border: none !important;
  }

  /* ---- PIPELINE KANBAN ---- */
  .pipeline-board, .kanban-board { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .kanban-column { min-width: 200px !important; max-width: 220px !important; }

  /* ---- OCCUPANCY ---- */
  .occ-calendar-wrapper { overflow-x: auto; -webkit-overflow-scrolling: touch; }

  /* ---- CRM & FLOATING BOXES ---- */
  #crm-detail-box,
  #pipeline-detail-box,
  #pipeline-new-box {
    width: 95vw !important; max-width: 95vw !important;
    max-height: 95vh !important;
    border-radius: 8px !important;
  }

  /* ---- REPUTATION ---- */
  .rep-charts-grid { grid-template-columns: 1fr !important; }

  /* ---- REENGAGEMENT ---- */
  .reeng-queue-table { overflow-x: auto; -webkit-overflow-scrolling: touch; }

  /* ---- AI CHAT ---- */
  .ai-chat-container { height: calc(100vh - 140px) !important; min-height: 400px; }

  /* ---- ACCESS ---- */
  .access-table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .perm-matrix-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

  /* ---- SECTION TITLES ---- */
  .section-header h3, .rel-section-title, .rk-card-title { font-size: 14px !important; }

  /* ---- SEASONALITY ---- */
  .seasonality-banner { font-size: 13px; padding: 12px 16px; }

  /* ---- DYNAMIC MODALS (inline styles from JS) ---- */
  #bk-full-overlay, #bk-edit-overlay, .bke-overlay {
    padding: 0 !important;
    align-items: stretch !important;
    overflow-x: hidden !important;
  }
  #bk-full-overlay > div, #bk-edit-overlay > div, .bke-overlay > .bke-modal {
    max-width: 100vw !important;
    width: 100% !important;
    margin: 0 !important;
    border-radius: 0 !important;
    max-height: 100vh !important;
    height: 100vh !important;
    overflow-x: hidden !important;
  }
  #bk-full-overlay > div > div,
  #bk-full-overlay span,
  #bk-full-overlay a,
  #bk-full-overlay p,
  #bk-full-overlay div {
    max-width: 100% !important;
    box-sizing: border-box !important;
    overflow-wrap: break-word !important;
  }
  /* 2-column grid → 1 column on mobile */
  .bk-detail-grid {
    grid-template-columns: 1fr !important;
  }
  /* Info cards grids (check-in/out/noites, adultos/crianças/valor) */
  .bk-info-grid {
    grid-template-columns: 1fr 1fr !important;
  }
  .bk-info-grid > div:last-child:nth-child(odd) {
    grid-column: 1 / -1;
  }
  /* Force no horizontal scroll on modal content */
  #bk-full-overlay > div > div,
  #bk-edit-overlay > div > div {
    overflow-x: hidden !important;
    word-break: break-word;
  }
  /* Badges bar wrap */
  #bk-full-overlay [style*="flex-wrap:wrap"],
  #bk-full-overlay [style*="display:flex"] {
    flex-wrap: wrap !important;
  }
  .bke-grid { grid-template-columns: 1fr !important; }
  .bke-body { max-height: calc(100vh - 60px) !important; }
  .bke-rooms { grid-template-columns: repeat(2, 1fr) !important; }

  /* Quick payment popup */
  #bk-quick-pay {
    left: 8px !important; right: 8px !important;
    width: auto !important; max-width: none !important;
    top: auto !important; bottom: 20px !important;
    transform: none !important;
  }

  /* Booking bar tap target — bigger on mobile */
  .bk-booking-bar { min-height: 28px !important; }

  /* Detail modal buttons — full width on mobile */
  .bk-detail-actions { flex-direction: column !important; gap: 8px !important; }
  .bk-detail-actions button { width: 100% !important; min-height: 44px !important; justify-content: center !important; margin-left: 0 !important; }

  /* Edit modal adjustments */
  .bke-header { padding: 14px 16px !important; }
  .bke-body { padding: 16px !important; }
  .bke-actions { flex-direction: column !important; }
  .bke-actions button { width: 100% !important; min-height: 44px !important; justify-content: center; }

  /* Guest info fields — no overflow */
  #bk-full-overlay a,
  #bk-full-overlay span {
    word-break: break-word !important;
    overflow-wrap: break-word !important;
  }
  /* Payment form grid → 1 column */
  #bk-pay-form [style*="grid-template-columns"],
  #bk-payments-section [style*="grid-template-columns: 1fr 1fr"] {
    grid-template-columns: 1fr !important;
  }

  /* Payment form adjustments */
  #bk-pay-form, #ed-pay-form { padding: 8px !important; }
  #bk-pay-form [style*="grid-template-columns"],
  #ed-pay-form .bke-grid { grid-template-columns: 1fr !important; }

  /* ---- LOGIN ---- */
  .login-card { margin: 16px; padding: 28px 24px; }

  /* ---- TOASTS ---- */
  .toast-container { top: auto; bottom: 68px; right: 12px; left: 12px; }
  .toast { max-width: 100%; }

  /* ---- EMPTY STATE ---- */
  .empty-state { padding: 32px 16px; }
  .empty-state i { font-size: 36px; }
  .empty-state h3 { font-size: 14px; }

  /* ---- BOOKINGS EXTRA TABLES ---- */
  .bke-table-wrap {
    -webkit-overflow-scrolling: touch;
  }
  .bke-table {
    min-width: 600px;
  }

  /* ---- CONSULTA +/- BUTTONS ---- */
  button[onclick*="stepSplitField"] {
    width: 36px !important;
    height: 36px !important;
    font-size: 16px !important;
  }

  /* ---- SERVER MONITOR CARDS ---- */
  .rede-server-card {
    padding: 10px !important;
  }

  /* ---- BI TABLES ---- */
  .scroll-wrapper .data-table {
    min-width: 400px;
  }
}

/* ---- LANDSCAPE MOBILE ---- */
@media screen and (max-width: 768px) and (orientation: landscape) {
  .sidebar { display: none !important; }
  .main-content { margin-left: 0 !important; }
  .bk-cal-grid { min-width: auto !important; }
}

/* ---- SMALL MOBILE (max 480px) ---- */
@media screen and (max-width: 480px) {
  .card-grid.grid-4 { grid-template-columns: 1fr; }
  .grid-auto-sm { grid-template-columns: 1fr; }
  .bottom-nav-item { min-width: 48px; min-height: 44px; padding: 6px 4px; }
  .bottom-nav-item span { font-size: 10px; }
  .bottom-nav-item i { font-size: 18px; }
  .tab-content { padding: 8px; }
  .status-value { font-size: 18px; }
  .kpi-value, .kpi-card-value { font-size: 18px !important; }
}
