/* OTOH — Mobile-first responsive layer (no feature removal) */

:root {
  --otoh-mobile-header-h: 56px;
  --otoh-l1-w: 84px;
  --otoh-l2-w: 300px;
  --otoh-safe-bottom: env(safe-area-inset-bottom, 0px);
}

/* Prevent horizontal page scroll on small screens */
html, body {
  overflow-x: hidden;
  max-width: 100vw;
}

body.otoh-mobile-open {
  overflow: hidden;
  position: fixed;
  width: 100%;
}

/* ========== Mobile top bar (hamburger + context) ========== */
.otoh-mobile-topbar {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--otoh-mobile-header-h);
  min-height: var(--otoh-mobile-header-h);
  background: var(--bg-surface, #fff);
  border-bottom: 1px solid var(--border);
  z-index: 2500;
  align-items: center;
  padding: 0 12px;
  padding-top: max(8px, env(safe-area-inset-top));
  gap: 10px;
  box-shadow: 0 2px 12px rgba(15, 23, 42, 0.06);
}

.otoh-mobile-menu-btn {
  width: 44px;
  height: 44px;
  min-width: 44px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #f8fafc;
  color: var(--text-main);
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
}

.otoh-mobile-topbar__title {
  flex: 1;
  min-width: 0;
  font-size: 14px;
  font-weight: 800;
  color: var(--text-main);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.otoh-mobile-topbar__actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.otoh-mobile-topbar__actions .icon-btn,
.otoh-mobile-topbar__actions .avatar-container {
  width: 40px;
  height: 40px;
  min-width: 40px;
}

/* ========== Dashboard shell ========== */
#dashboard-app.otoh-mobile-layout {
  flex-direction: column;
  width: 100%;
  max-width: 100vw;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

#dashboard-app.otoh-mobile-layout .sidebar-l1 {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: min(280px, 85vw);
  max-width: 320px;
  z-index: 2400;
  transform: translateX(-100%);
  transition: transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
  padding-top: max(12px, env(safe-area-inset-top));
  box-shadow: 4px 0 24px rgba(0, 0, 0, 0.15);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

#dashboard-app.otoh-mobile-layout.otoh-l1-open .sidebar-l1 {
  transform: translateX(0);
}

#dashboard-app.otoh-mobile-layout .sidebar-l1 .logo-icon {
  margin-bottom: 16px;
}

#dashboard-app.otoh-mobile-layout .sidebar-l1 .l1-nav-icon {
  width: 100%;
  max-width: 100%;
  height: auto;
  min-height: 48px;
  padding: 14px 0;
  margin: 4px 8px;
  border-radius: 12px;
  box-sizing: border-box;
}

#dashboard-app.otoh-mobile-layout .sidebar-l1 .l1-nav-icon i {
  font-size: 20px;
}

#dashboard-app.otoh-mobile-layout .sidebar-l1 .l1-nav-icon[data-tooltip]::after {
  display: none;
}

#dashboard-app.otoh-mobile-layout .main-content {
  margin-left: 0 !important;
  width: 100%;
  max-width: 100vw;
  min-height: 0;
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#dashboard-app.otoh-mobile-layout .top-header {
  height: auto;
  min-height: var(--otoh-mobile-header-h);
  padding: 12px 16px;
  padding-top: max(12px, env(safe-area-inset-top));
  flex-wrap: wrap;
  gap: 12px;
  align-items: stretch;
}

#dashboard-app.otoh-mobile-layout .client-switcher-container {
  width: 100%;
  order: 1;
}

#dashboard-app.otoh-mobile-layout .client-switcher-container select,
#dashboard-app.otoh-mobile-layout #selectMestreBpo {
  width: 100%;
  max-width: 100%;
  font-size: 14px;
  padding: 10px 12px;
}

#dashboard-app.otoh-mobile-layout .search-bar-wrapper {
  order: 3;
  width: 100%;
  margin: 0 !important;
  flex: 1 1 100%;
  min-width: 0;
}

#dashboard-app.otoh-mobile-layout .search-bar-wrapper form {
  width: 100%;
}

#dashboard-app.otoh-mobile-layout .search-bar-wrapper input {
  width: 100% !important;
  min-width: 0;
}

#dashboard-app.otoh-mobile-layout .header-actions {
  width: 100%;
  justify-content: flex-end;
  order: 2;
  gap: 8px;
}

#dashboard-app.otoh-mobile-layout .l3-container {
  padding: 16px 12px 24px;
  padding-bottom: calc(24px + var(--otoh-safe-bottom));
  overflow-x: hidden;
}

/* L2 drawer */
#dashboard-app.otoh-mobile-layout .sidebar-l2 {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: min(300px, 92vw);
  max-width: 340px;
  z-index: 2450;
  transform: translateX(-100%);
  transition: transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
  box-shadow: 4px 0 24px rgba(0, 0, 0, 0.12);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

#dashboard-app.otoh-mobile-layout.otoh-l2-open .sidebar-l2 {
  transform: translateX(0);
}

#dashboard-app.otoh-mobile-layout .sidebar-l2 .l2-header {
  padding: 16px;
  font-size: 16px;
}

#dashboard-app.otoh-mobile-layout .sidebar-l2 .l2-content {
  padding: 12px;
}

#dashboard-app.otoh-mobile-layout .l2-section-title {
  font-size: 10px;
  padding: 8px 12px 4px;
}

#dashboard-app.otoh-mobile-layout .l2-item {
  padding: 12px 14px !important;
  font-size: 13px;
}

/* Backdrop */
.otoh-drawer-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  z-index: 2300;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.otoh-drawer-backdrop.is-visible {
  display: block;
  opacity: 1;
}

/* ========== Accounting portal ========== */
#accounting-view.otoh-mobile-layout {
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 100vw;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

#accounting-view.otoh-mobile-layout .acc-sidebar {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: min(280px, 85vw);
  max-width: 300px;
  z-index: 2400;
  transform: translateX(-100%);
  transition: transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

#accounting-view.otoh-mobile-layout.otoh-l1-open .acc-sidebar {
  transform: translateX(0);
}

#accounting-view.otoh-mobile-layout .acc-layout {
  flex-direction: column;
  width: 100%;
}

#accounting-view.otoh-mobile-layout .acc-main {
  width: 100%;
  padding: 16px;
  padding-bottom: calc(24px + var(--otoh-safe-bottom));
  overflow-x: hidden;
}

#accounting-view.otoh-mobile-layout .acc-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

#accounting-view.otoh-mobile-layout .acc-topbar h1 {
  font-size: 22px;
}

#accounting-view.otoh-mobile-layout .acc-topbar .btn-primary {
  width: 100%;
  justify-content: center;
  padding: 14px 16px;
  font-size: 14px;
}

.sp-header {
  padding-top: max(16px, env(safe-area-inset-top));
}

/* ========== Tables scroll ========== */
.table-scroll-x,
.otoh-table-scroll {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin-bottom: 16px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #fff;
}

.table-scroll-x table,
.otoh-table-scroll table {
  min-width: 640px;
}

.table-scroll-x .data-table,
.otoh-table-scroll .data-table {
  font-size: 12px;
}

/* Utility */
.hide-mobile {
  display: none !important;
}

.show-mobile-only {
  display: none !important;
}

.w-100-mobile {
  width: 100% !important;
}

.flex-col-mobile {
  flex-direction: column !important;
}

.gap-mobile-sm {
  gap: 10px !important;
}

/* ========== Breakpoint: tablet landscape tweaks ========== */
@media (min-width: 769px) and (max-width: 1024px) {
  .otoh-mobile-topbar {
    display: none;
  }

  #dashboard-app.otoh-mobile-layout .main-content {
    padding-top: 24px;
  }

  .card-grid,
  .stagger-2.card-grid {
    grid-template-columns: repeat(2, 1fr) !important;
  }

  .est-hero__stats {
    grid-template-columns: repeat(4, 1fr) !important;
  }
}

/* ========== Desktop: restore sidebars (optional narrow) ========== */
@media (min-width: 1025px) {
  .hide-desktop {
    display: none !important;
  }
}

/* ========== Mobile breakpoint ========== */
@media (max-width: 768px) {
  .card-grid,
  .stagger-2.card-grid {
    grid-template-columns: 1fr !important;
    gap: 16px !important;
  }

  .page-title-row {
    flex-direction: column;
    align-items: flex-start !important;
    gap: 12px;
  }

  .page-title {
    font-size: 24px !important;
  }

  .page-title-row .btn-primary,
  .page-title-row .btn-outline {
    width: 100%;
    justify-content: center;
  }

  .card-grid .card {
    min-height: auto;
  }

  .pdv-segment-btn {
    min-height: 48px;
  }

  .pdv-equip-box {
    flex-direction: column;
    align-items: stretch !important;
  }

  .pdv-equip-extra {
    flex-wrap: wrap;
  }

  .est-grid {
    grid-template-columns: 1fr !important;
  }

  .est-hero {
    padding: 20px 16px !important;
  }

  .est-hero__stats {
    grid-template-columns: repeat(2, 1fr) !important;
    min-width: 0 !important;
  }

  .est-dscan__camera-wrap {
    min-height: 220px;
  }

  .input-group input,
  .input-group select,
  .form-group input,
  .form-group select {
    font-size: 16px;
    min-height: 44px;
  }

  .btn-primary,
  .btn-outline,
  .hero-form-btn,
  .otoh-tour__btn {
    min-height: 44px;
    padding: 12px 16px;
  }

  #modalInvestimento > div,
  #modalInvestimento .modal-custom-box {
    width: 100% !important;
    max-width: 100vw !important;
    max-height: 100vh !important;
    border-radius: 0 !important;
    margin: 0 !important;
  }

  .otoh-chatbot-container {
    bottom: calc(16px + var(--otoh-safe-bottom)) !important;
    right: 12px !important;
  }

  .otoh-chat-prompt {
    max-width: calc(100vw - 24px) !important;
  }

  .otoh-tour__card {
    max-width: calc(100vw - 24px) !important;
    left: 12px !important;
    right: 12px !important;
    bottom: calc(80px + var(--otoh-safe-bottom)) !important;
  }

  #painelLateralReembolso {
    max-width: 100% !important;
    width: 100% !important;
  }

  .faq-grid {
    grid-template-columns: 1fr !important;
  }

  .hero {
    flex-direction: column !important;
    padding: 40px 20px !important;
    min-height: auto !important;
  }

  .hero-text,
  .hero-form-container {
    width: 100% !important;
    max-width: 100% !important;
  }

  .grid-3 {
    grid-template-columns: 1fr !important;
  }

  .split-section {
    flex-direction: column !important;
    padding: 48px 20px !important;
    gap: 32px !important;
  }

  .split-text,
  .split-image {
    width: 100% !important;
  }

  .login-container,
  #login-view {
    flex-direction: column !important;
  }

  .login-left,
  .login-right {
    width: 100% !important;
    min-height: auto !important;
    padding: 32px 20px !important;
  }

  #login-view {
    height: auto !important;
    min-height: 100dvh;
  }

  .otoh-faturamento-emitir {
    width: 100%;
    flex-wrap: wrap;
    gap: 10px;
  }

  #cpCarteiraDetalhe,
  #crCarteiraDetalhe {
    padding: 12px !important;
  }

  .hide-mobile {
    display: none !important;
  }

  .show-mobile-only {
    display: block !important;
  }

  .otoh-mobile-topbar {
    display: flex;
  }

  /* Stack header user menu panels on very small screens */
  #painelMenuUsuarioSuspenso,
  #painelSininhoMestre {
    position: fixed !important;
    left: 8px !important;
    right: 8px !important;
    top: calc(var(--otoh-mobile-header-h) + 8px) !important;
    width: auto !important;
    max-width: calc(100vw - 16px);
  }

  .brands-row {
    gap: 24px !important;
  }

  .testimonials-header h2 {
    font-size: 28px !important;
  }

  .middle-cta h2 {
    font-size: 28px !important;
  }

  .cards-section h2 {
    font-size: 28px !important;
  }
}

/* ===== Landing (home pública) ===== */
@media (max-width: 768px) {
  .top-bar {
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
    text-align: left;
    padding: 8px 12px;
  }

  .navbar {
    padding: 12px 16px;
    gap: 10px;
    flex-wrap: wrap;
  }

  .nav-logo img {
    height: 26px;
  }

  .nav-toggle {
    display: flex !important;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: 12px;
    border: 1px solid rgba(148, 163, 184, 0.6);
    background: rgba(15, 23, 42, 0.9);
    color: #e5e7eb;
    margin-left: auto;
  }

  .nav-links {
    display: none;
    flex-direction: column;
    width: 100%;
    background: rgba(15, 23, 42, 0.96);
    border-radius: 16px;
    padding: 12px 0;
    margin-top: 8px;
  }

  .nav-links.open {
    display: flex;
  }

  .nav-links .nav-item {
    padding: 10px 16px;
    border-bottom: 1px solid rgba(148, 163, 184, 0.25);
  }

  .nav-links .nav-item:last-child {
    border-bottom: none;
  }

  .nav-actions {
    display: none;
    width: 100%;
    flex-direction: column;
    gap: 8px;
    margin-top: 8px;
  }

  .nav-actions.open {
    display: flex;
  }

  .nav-actions .btn-outline,
  .nav-actions .btn-login {
    width: 100%;
    justify-content: center;
    text-align: center;
  }

  .hero {
    padding: 40px 16px !important;
    min-height: auto !important;
  }

  .hero-text {
    text-align: left;
  }

  .hero-text h1 {
    font-size: 32px !important;
  }

  .hero-text p {
    font-size: 16px !important;
    margin-bottom: 24px !important;
  }

  .hero-form-container {
    margin-top: 16px;
    padding: 20px !important;
    border-radius: 16px !important;
    box-shadow: 0 15px 35px rgba(15, 23, 42, 0.35);
  }
}

/* Mobile nav row inside dashboard header */
.otoh-mobile-nav-row {
  display: none;
  width: 100%;
  gap: 8px;
  flex-shrink: 0;
}

@media (max-width: 768px) {
  .otoh-mobile-nav-row {
    display: flex !important;
  }

  .side-panel,
  #side-panel {
    width: 100% !important;
    max-width: 100vw !important;
    right: -100% !important;
  }

  #side-panel[style*="right: 0"] {
    right: 0 !important;
  }

  .modal-custom-box {
    max-width: calc(100vw - 24px) !important;
    width: 100% !important;
  }

  .modal-custom-overlay {
    padding: 12px !important;
    align-items: flex-end !important;
  }

  #accounting-view.otoh-mobile-layout .acc-main {
    padding-top: calc(var(--otoh-mobile-header-h) + 8px);
  }

  #accounting-view.otoh-mobile-layout .acc-header {
    flex-direction: column;
    align-items: flex-start !important;
    height: auto;
    padding: 16px;
    gap: 12px;
  }

  #accounting-view.otoh-mobile-layout .acc-header .header-actions {
    width: 100%;
    justify-content: flex-end;
  }

  #accounting-view.otoh-mobile-layout .acc-content-wrapper {
    padding: 16px 12px;
  }

  .client-card {
    height: auto !important;
    min-height: 200px;
  }

  .folder-grid {
    grid-template-columns: 1fr !important;
  }

  .otoh-chat-window {
    width: min(350px, calc(100vw - 24px)) !important;
    max-width: calc(100vw - 24px);
  }
}

/* Contas a pagar / receber */
@media (max-width: 768px) {
  .cp-radar-bar {
    flex-direction: column;
    align-items: stretch;
  }

  .cp-radar-btn {
    width: 100%;
    justify-content: center;
    min-height: 44px;
  }

  .cp-modal,
  .cp-modal--wide {
    max-width: 100vw !important;
    width: 100% !important;
    margin: 0 !important;
    border-radius: 0 !important;
    max-height: 100dvh !important;
  }

  .cp-modal__grid-2 {
    grid-template-columns: 1fr !important;
  }

  .cp-detalhe-grid {
    grid-template-columns: 1fr !important;
  }

  .cp-carteira-toolbar {
    flex-direction: column;
    align-items: stretch !important;
  }

  .cp-carteira-toolbar > * {
    width: 100%;
  }

  .cp-filtros-row {
    flex-direction: column !important;
  }

  .cp-filtros-row .input-group {
    width: 100% !important;
  }
}

/* Small phones */
@media (max-width: 380px) {
  .otoh-mobile-topbar__title {
    font-size: 12px;
  }

  #dashboard-app.otoh-mobile-layout .sidebar-l1 {
    width: min(260px, 90vw);
  }
}
