/* =====================================================================
   Acctbot Shared Mobile Responsive & Grid-Containment Layer
   Prevents horizontal overflow on 360px-960px viewports and upgrades
   header/workbench alignment across tool and documentation pages.
   ===================================================================== */

html,
body {
  max-width: 100%;
  overflow-x: clip;
}

/* Prevent CSS Grid 1fr tracks & flex items from expanding to min-content width */
.editorial-grid > *,
.main-layout-grid > *,
.site-footer-grid > *,
.steps-grid > *,
.workbench-card,
.tool-workspace,
.article-body,
.doc-content,
.sidebar-card,
.step-card,
.tool-next-step-card > *,
.packages-guarantee-card > * {
  min-width: 0;
}

.article-body code,
.doc-content code,
.formula-card,
.formula-eq,
.formula-desc,
.intent-disambiguation-banner,
.intent-disambiguation-banner code {
  max-width: 100%;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.comp-table-wrap,
.doc-table-wrap {
  max-width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.hero-glow-ambient,
.bottom-cta-ambient {
  max-width: 100vw;
}

/* Accessible Mobile Hamburger Toggle & Slide-In Side Panel */
html.mobile-drawer-open,
html.mobile-drawer-open body {
  overflow: hidden;
}

.mobile-nav-toggle {
  display: none;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border-radius: 10px;
  border: 1px solid var(--border-subtle, #eae8e1);
  background: #ffffff;
  color: var(--text-main, #121316);
  cursor: pointer;
  flex-shrink: 0;
  box-shadow: var(--shadow-sm, 0 1px 3px rgba(0, 0, 0, 0.04));
  transition: background-color 0.15s ease, border-color 0.15s ease;
}

.mobile-nav-toggle:hover,
.mobile-nav-toggle[aria-expanded="true"] {
  border-color: var(--accent-orange, #ff5b00);
  color: var(--accent-orange, #ff5b00);
}

.brand-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.mobile-nav-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 2000;
  background: rgba(18, 19, 22, 0.48);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
}

.mobile-nav-drawer {
  display: none;
  flex-direction: column;
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(310px, 84vw);
  max-width: 100%;
  height: 100dvh;
  z-index: 2001;
  padding: 0;
  background: #faf9f6;
  border-left: 1px solid var(--border-subtle, #eae8e1);
  box-shadow: -16px 0 40px rgba(18, 19, 22, 0.16);
  overflow-y: auto;
  overscroll-behavior: contain;
}

.mobile-drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  background: #ffffff;
  border-bottom: 1px solid var(--border-subtle, #eae8e1);
  flex-shrink: 0;
}

.mobile-drawer-brand {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 1rem;
  font-weight: 800;
  color: var(--text-main, #121316);
  letter-spacing: -0.02em;
}

.mobile-drawer-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border-radius: 10px;
  border: 1px solid var(--border-subtle, #eae8e1);
  background: #ffffff;
  color: var(--text-main, #121316);
  cursor: pointer;
  flex-shrink: 0;
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.mobile-drawer-close:hover {
  border-color: var(--accent-orange, #ff5b00);
  color: var(--accent-orange, #ff5b00);
}

.mobile-drawer-links {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 14px 12px;
  flex: 1 1 auto;
}

.mobile-nav-drawer a:not(.btn) {
  display: flex;
  align-items: center;
  min-height: 44px;
  padding: 10px 14px;
  border-radius: 10px;
  color: var(--text-secondary, #4a5160);
  text-decoration: none;
  font-size: 0.96rem;
  font-weight: 600;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.mobile-nav-drawer a:not(.btn):hover,
.mobile-nav-drawer a:not(.btn).active {
  background: var(--accent-orange-soft, rgba(255, 91, 0, 0.1));
  color: var(--accent-orange, #ff5b00);
  font-weight: 700;
}

.mobile-drawer-footer {
  display: none;
  padding: 14px 16px max(18px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--border-subtle, #eae8e1);
  background: #ffffff;
  flex-shrink: 0;
}

.mobile-nav-drawer .mobile-drawer-cta {
  display: none !important;
  margin-top: 0;
  width: 100%;
  justify-content: center;
  white-space: normal !important;
  text-align: center;
}

@keyframes acctbotSidePanelIn {
  from {
    transform: translateX(100%);
  }
  to {
    transform: translateX(0);
  }
}

@media (prefers-reduced-motion: reduce) {
  .mobile-nav-drawer.is-open {
    animation: none;
  }
}

@media (max-width: 960px) {
  header .nav-links {
    display: none !important;
  }

  .mobile-nav-toggle {
    display: inline-flex;
  }

  .mobile-nav-backdrop.is-open {
    display: block;
  }

  .mobile-nav-drawer.is-open {
    display: flex;
    animation: acctbotSidePanelIn 0.2s cubic-bezier(0.22, 1, 0.36, 1);
  }

  .editorial-grid,
  .main-layout-grid {
    grid-template-columns: minmax(0, 1fr) !important;
    gap: 28px !important;
  }

  .sidebar-card {
    position: static !important;
    top: auto !important;
  }
}

@media (max-width: 768px) {
  .workbench-card .btn,
  .tool-workspace .btn,
  .tool-next-step-card .btn,
  .packages-guarantee-card .btn {
    white-space: normal !important;
    max-width: 100%;
  }

  .mobile-sticky-cta a.btn.btn-orange,
  .mobile-sticky-cta .btn-orange {
    flex-shrink: 0 !important;
    white-space: nowrap !important;
    padding: 9px 14px !important;
    font-size: 0.79rem !important;
    min-height: 36px;
  }
}

@media (max-width: 680px) {
  header .header-inner > .btn-orange,
  header .header-inner > div > .btn-orange {
    display: none !important;
  }

  .mobile-drawer-footer {
    display: block;
  }

  .mobile-nav-drawer .mobile-drawer-cta {
    display: inline-flex !important;
  }
}

@media (max-width: 640px) {
  .container {
    padding: 0 16px !important;
  }

  .header-inner {
    height: 64px !important;
    gap: 10px !important;
  }

  .brand-wrap {
    gap: 10px !important;
    min-width: 0;
  }

  .brand-title {
    font-size: 1.08rem !important;
  }

  .brand-subtitle {
    font-size: 0.68rem !important;
    white-space: nowrap;
  }

  .hero-section,
  .tool-hero-wrap {
    padding: 28px 0 22px !important;
  }

  .hero-title,
  .tool-hero h1,
  .tool-page-title {
    font-size: clamp(1.72rem, 7vw, 2.2rem) !important;
    line-height: 1.16 !important;
    overflow-wrap: break-word;
  }

  .hero-subtitle,
  .tool-page-subtitle {
    font-size: 0.96rem !important;
    line-height: 1.56 !important;
  }

  .hero-badge-pill,
  .tool-page-badge {
    max-width: 100%;
    font-size: 0.76rem !important;
    padding: 6px 12px !important;
    line-height: 1.35;
  }

  .breadcrumb-bar {
    font-size: 0.78rem;
    line-height: 1.45;
  }

  /* Tool Workspaces */
  .workbench-card,
  .tool-workspace {
    padding: 18px 14px !important;
    border-radius: 18px !important;
    margin-bottom: 32px !important;
  }

  .intent-disambiguation-banner {
    padding: 12px 14px !important;
    gap: 10px !important;
    font-size: 0.84rem !important;
  }

  .workbench-action-buttons,
  .workbench-export-buttons,
  .bsc-controls-strip,
  .bsc-balance-group,
  .bsc-quick-actions {
    width: 100%;
    flex-wrap: wrap !important;
  }

  .workbench-card .btn,
  .tool-workspace .btn {
    white-space: normal !important;
    text-align: center;
    line-height: 1.3;
    min-height: 40px;
    height: auto !important;
    max-width: 100%;
  }

  #bsc-drop-zone,
  #eps-drop-zone,
  #ais-drop-zone {
    padding: 20px 14px !important;
  }

  #bsc-drop-zone button,
  #eps-drop-zone button,
  #ais-drop-zone button {
    max-width: 100%;
    white-space: normal !important;
    line-height: 1.35;
  }

  /* Bank statement converter balance inputs stack cleanly */
  .bsc-balance-field {
    flex: 1 1 130px;
    min-width: 0;
  }

  .bsc-balance-field input {
    width: 100% !important;
  }

  /* E-commerce payout sample dropdown opens safely inside mobile screen */
  #eps-sample-menu {
    left: 0 !important;
    right: auto !important;
    max-width: calc(100vw - 64px);
  }

  /* Invoice splitter grids & naming pattern toolbar */
  #ais-invoices-grid {
    grid-template-columns: minmax(0, 1fr) !important;
  }

  .ais-naming-toolbar {
    width: 100%;
    flex-wrap: wrap !important;
    max-width: 100%;
  }

  .ais-naming-toolbar select {
    max-width: 100%;
    min-width: 0;
    flex: 1 1 180px;
  }

  /* Responsive Grids with large min-width thresholds */
  .responsive-card-grid {
    grid-template-columns: minmax(0, 1fr) !important;
  }

  .workflow-steps-section {
    padding: 22px 16px !important;
    margin: 28px 0 16px !important;
  }

  .tool-next-step-card,
  .packages-guarantee-card {
    padding: 18px 16px !important;
  }

  .guarantee-badge-pill {
    white-space: normal !important;
    max-width: 100%;
  }

  .tool-next-step-card .btn,
  .packages-guarantee-card .btn,
  .workbench-card a.btn.btn-orange,
  .tool-workspace a.btn.btn-orange,
  button.btn.btn-orange {
    max-width: 100%;
    white-space: normal !important;
    text-align: center;
  }

  /* Keep bottom sticky CTA bar crisp on a single clean row */
  .mobile-sticky-cta {
    gap: 10px !important;
    padding: 10px 14px !important;
  }

  .mobile-sticky-text {
    min-width: 0;
    flex: 1;
  }

  .mobile-sticky-title {
    font-size: 0.82rem !important;
    line-height: 1.25;
  }

  .mobile-sticky-sub {
    font-size: 0.7rem !important;
    line-height: 1.25;
  }

  .mobile-sticky-cta a.btn.btn-orange,
  .mobile-sticky-cta .btn-orange {
    flex-shrink: 0 !important;
    white-space: nowrap !important;
    padding: 9px 14px !important;
    font-size: 0.79rem !important;
  }
}
