/* ============================================================
   invoicebanale.com — Responsive Fix v2
   Fixes: navbar theme-btn spacing · left panel padding ·
          preview scaling · sticky download bar · all devices
   ============================================================ */

/* ─── 1. BASE ZOOM STABILITY ─────────────────────────────── */
html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  overflow-x: hidden;
  min-width: 0;
  width: 100%;
}

/* ─── 2. NAVBAR GLOBAL FIX ───────────────────────────────── */
/* Prevent theme toggle from drifting — keep everything in a
   tight right-aligned row with no gap explosion */
.navbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0;
  padding: 0 2rem;
  height: 68px;
  width: 100%;
  box-sizing: border-box;
  overflow: visible;
}

.nav-logo {
  flex: 0 0 auto;
  z-index: 1;
}

.nav-links {
  flex: 1 1 auto;
  justify-content: center;
}

/* Right group: theme toggle + settings + CTA + hamburger
   all in ONE flex row, flush right, no stray gaps */
.nav-cta {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
  margin-left: auto;
}

.theme-toggle {
  flex-shrink: 0;
  order: 0;
}

.nav-settings-btn {
  flex-shrink: 0;
  order: 1;
}

.nav-cta .btn,
.nav-cta .btn-gold {
  flex-shrink: 0;
  order: 2;
}

/* Hamburger immediately after nav-cta, same row */
.hamburger {
  flex-shrink: 0;
  margin-left: 6px;
  order: 3;
}

/* ─── 3. APP SHELL ───────────────────────────────────────── */
.app-shell {
  display: grid;
  grid-template-columns: 60% 40%;
  min-height: calc(100vh - 68px);
  width: 100%;
  overflow: hidden;
}

/* ─── 4. LEFT PANEL ──────────────────────────────────────── */
.panel-left {
  background: var(--bg-1);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  overflow-x: hidden;
  height: calc(100vh - 68px);
  position: sticky;
  top: 68px;
  min-width: 0;
}

/* ─── 5. RIGHT PANEL ─────────────────────────────────────── */
.panel-right {
  background: var(--bg);
  padding: 16px;
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-width: 0;
}

/* ─── 6. INVOICE CANVAS / PREVIEW ───────────────────────── */
#invoiceCanvas {
  background: #fff;
  border-radius: 10px;
  box-shadow: 0 16px 48px rgba(0,0,0,0.45);
  overflow: hidden;
  width: 100%;
  min-width: 0;
  position: relative;
}

#invoiceCanvas .inv-wrap,
#wInvoiceCanvas .inv-wrap {
  width: 100%;
  box-sizing: border-box;
}

#invoiceCanvas .inv-scale-wrap {
  transform-origin: top left;
  width: 794px;
}

/* Preview panel (wizard right column) */
.preview-panel {
  overflow: hidden;
}

.preview-panel-canvas {
  overflow-y: auto;
  overflow-x: hidden;
  position: relative;
}

/* ─── 7. FORM ROWS ───────────────────────────────────────── */
.form-row,
.form-row-3,
.w-form-row,
.w-form-row-3 {
  min-width: 0;
}

/* ─── 8. ITEMS TABLE ─────────────────────────────────────── */
.items-wrap,
.w-items-wrap {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.items-table,
.w-items-table {
  min-width: 360px;
}

/* ─── 9. TEMPLATE GRID ───────────────────────────────────── */
.template-grid,
.template-picker-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

/* ─── 10. HISTORY ITEMS ──────────────────────────────────── */
.history-item {
  flex-wrap: wrap;
  gap: 8px;
}

.history-item > div:first-child {
  flex: 1;
  min-width: 0;
}

/* ─── 11. AD SLOTS ───────────────────────────────────────── */
.ad-slot {
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  overflow: hidden;
}

.ad-slot-banner { height: clamp(50px, 10vw, 90px); }
.ad-slot-rect   { height: clamp(150px, 30vw, 280px); }

.ad-slot iframe,
.ad-slot img,
.ad-slot > * {
  max-width: 100%;
  height: auto;
}

/* ─── 12. MISC UTILITY ───────────────────────────────────── */
.btn,
.input,
.textarea,
.select,
input,
textarea,
select {
  max-width: 100%;
  box-sizing: border-box;
}

.color-palette,
.w-color-palette {
  flex-wrap: wrap;
}

.preview-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
}

.totals-box,
.w-totals-box,
.form-section,
.tab-content,
.items-wrap,
.w-items-wrap,
.template-grid,
.template-picker-grid,
.history-item {
  max-width: 100%;
  box-sizing: border-box;
}

/* All grid/flex children must allow shrinking */
.app-shell > *,
.panel-tabs > *,
.form-row > *,
.form-row-3 > *,
.w-form-row > *,
.w-form-row-3 > *,
.preview-toolbar > *,
.wizard-shell > * {
  min-width: 0;
}

/* ─── 13. MOBILE NAV ─────────────────────────────────────── */
.mobile-nav {
  overflow-y: auto;
  max-height: calc(100vh - 60px);
}

.mobile-nav .btn-pdf-mobile-nav {
  display: flex;
  width: 100%;
  justify-content: center;
  margin-top: 8px;
  border-radius: var(--r-sm);
  padding: 14px 20px;
  font-size: 1rem;
}

/* ─── 14. STICKY DOWNLOAD BAR ────────────────────────────── */
.sticky-dl-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 800;
  padding: 10px 16px;
  gap: 10px;
  flex-direction: row;
  align-items: center;
  background: rgba(255,255,255,0.97);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid var(--w-border, #e5e8f0);
  box-shadow: 0 -4px 20px rgba(0,0,0,0.1);
  box-sizing: border-box;
}

[data-theme="dark"] .sticky-dl-bar {
  background: rgba(14,14,15,0.96) !important;
  border-top-color: var(--border) !important;
}

/* Save button inside sticky bar */
.sticky-dl-bar #stickySaveBtn {
  flex-shrink: 0 !important;
  white-space: nowrap;
  min-width: 0;
}

/* Download PDF button inside sticky bar — fill remaining space */
.sticky-dl-bar .btn-download-pdf {
  flex: 1 1 auto !important;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ─────────────────────────────────────────────────────────
   BREAKPOINT: TABLET LANDSCAPE ≤ 1200px
   ───────────────────────────────────────────────────────── */
@media (max-width: 1200px) {
  .app-shell {
    grid-template-columns: 58% 42%;
  }
}

/* ─────────────────────────────────────────────────────────
   BREAKPOINT: TABLET / STACKED ≤ 1100px
   ───────────────────────────────────────────────────────── */
@media (max-width: 1100px) {
  .app-shell {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto;
  }

  .panel-left {
    height: auto;
    position: relative;
    top: 0;
    overflow-y: visible;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }

  .panel-right {
    height: auto;
    min-height: 500px;
  }

  .nav-cta .btn[id="btnPDF"] {
    display: none;
  }

  .btn-pdf-mobile {
    display: flex;
    width: 100%;
    justify-content: center;
    margin-bottom: 4px;
  }

  .preview-toolbar {
    justify-content: space-between;
  }
}

/* ─────────────────────────────────────────────────────────
   BREAKPOINT: TABLET PORTRAIT ≤ 900px
   ───────────────────────────────────────────────────────── */
@media (max-width: 900px) {
  /* Navbar: hide links + CTA buttons, keep theme + hamburger */
  .nav-links    { display: none !important; }
  .hamburger    { display: flex !important; flex-shrink: 0; }

  .nav-cta .btn,
  .nav-cta .btn-gold,
  .nav-cta .nav-settings-btn { display: none !important; }
  /* theme-toggle stays visible */

  .template-grid,
  .template-picker-grid { grid-template-columns: repeat(2, 1fr); }

  .form-row, .form-row-3,
  .w-form-row, .w-form-row-3 { grid-template-columns: 1fr; }

  .ad-slot-banner { height: 60px; }
}

/* ─────────────────────────────────────────────────────────
   BREAKPOINT: MOBILE ≤ 640px
   ───────────────────────────────────────────────────────── */
@media (max-width: 640px) {
  /* ── Body padding for fixed navbar ── */
  body {
    padding-top: 60px;
    padding-bottom: 74px; /* space for sticky download bar */
  }

  /* ── NAVBAR — tighter, no overflow ── */
  .navbar {
    padding: 0 14px !important;
    height: 60px !important;
    max-width: 100vw;
    overflow: visible;
    box-sizing: border-box;
  }

  .nav-logo-text { font-size: 0.98rem; }

  /* Nav-cta: only theme toggle remains visible */
  .nav-links          { display: none !important; }
  .nav-cta .btn,
  .nav-cta .btn-gold,
  .nav-cta .nav-settings-btn { display: none !important; }
  /* theme-toggle stays */
  .hamburger          { display: flex !important; flex-shrink: 0; }

  /* Ensure theme-toggle and hamburger have a comfortable gap */
  .nav-cta {
    gap: 6px;
    margin-left: auto;
  }

  .hamburger {
    margin-left: 4px;
  }

  .mobile-nav { top: 60px; }

  /* ── WIZARD SECTION LEFT PANEL ── */
  .wizard-section { padding: 40px 0 60px; }

  /* Step panel: proper left/right padding on mobile */
  .step-card { padding: 20px 16px !important; }
  .step-nav  { padding: 14px 16px !important; gap: 8px; }

  /* Step card title */
  .step-card-title { font-size: 1.1rem; }

  /* Form rows: single column, bigger touch targets */
  .w-form-row,
  .w-form-row-3,
  .form-row,
  .form-row-3 {
    grid-template-columns: 1fr !important;
    gap: 10px;
  }

  /* Inputs: taller for touch */
  .w-input,
  .w-textarea,
  .w-select {
    padding: 11px 14px;
    font-size: 0.9rem;
  }

  /* ── STEP PROGRESS BAR ── */
  .step-progress {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    justify-content: flex-start;
    padding: 0 16px 8px;
    margin-bottom: 24px;
    gap: 0;
  }
  .step-progress::-webkit-scrollbar { display: none; }

  .sp-item        { flex: 0 0 auto; min-width: 74px; max-width: none; }
  .sp-circle      { width: 32px; height: 32px; font-size: 0.78rem; }
  .sp-label       { font-size: 0.6rem; white-space: normal; }
  .sp-item:not(:last-child)::after { top: 15px; }

  /* ── PREVIEW PANEL (right column in wizard) ── */
  .preview-panel {
    position: relative !important;
    top: 0 !important;
    border-radius: 16px;
    margin: 0 0 16px;
  }

  .preview-panel-header {
    padding: 10px 14px;
    flex-wrap: wrap;
    gap: 6px;
  }

  .preview-panel-label { font-size: 0.7rem; }
  .preview-panel-badge { font-size: 0.65rem; padding: 3px 9px; }

  /* Canvas height limited, scrollable */
  .preview-panel-canvas {
    max-height: 300px !important;
    padding: 12px !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch;
    background: var(--w-bg-1);
  }

  /* Invoice canvas inside wizard — scale to fit */
  #wInvoiceCanvas {
    width: 100% !important;
    border-radius: 8px;
    overflow: hidden;
  }

  /* Scale inner invoice template to fit mobile width */
  #wInvoiceCanvas .inv-wrap {
    font-size: 10px !important;
  }

  /* Download bar inside preview panel — hidden on mobile,
     replaced by sticky bar at bottom */
  .download-bar { display: none !important; }

  /* ── STICKY DOWNLOAD BAR — polished mobile layout ── */
  .sticky-dl-bar {
    display: flex !important;
    padding: 10px 14px !important;
    gap: 10px !important;
    align-items: center;
    min-height: 58px;
  }

  /* Save button: compact pill */
  .sticky-dl-bar #stickySaveBtn {
    padding: 11px 14px !important;
    font-size: 0.82rem !important;
    border-radius: 10px !important;
    flex-shrink: 0 !important;
    display: flex !important;
    align-items: center;
    gap: 5px;
    white-space: nowrap;
    min-width: 72px;
  }

  /* Download PDF button: fills remaining width */
  .sticky-dl-bar .btn-download-pdf {
    flex: 1 !important;
    padding: 13px 14px !important;
    font-size: 0.95rem !important;
    font-weight: 700 !important;
    border-radius: 12px !important;
    justify-content: center !important;
    display: flex !important;
    align-items: center !important;
    gap: 8px !important;
    white-space: nowrap;
    overflow: hidden;
  }

  /* ── TEMPLATE PICKER ── */
  .template-picker-grid,
  .template-grid { grid-template-columns: repeat(2, 1fr); gap: 8px; }

  .w-tpl-preview { height: 80px; }

  /* ── ITEMS TABLE ── */
  .w-items-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .w-items-table { min-width: 340px; }
  .w-item-input  { font-size: 0.82rem; padding: 7px 8px; }

  /* ── TOTALS BOX ── */
  .w-totals-box  { padding: 11px 13px; }

  /* ── APP SHELL ── */
  .app-shell { grid-template-columns: 1fr; }
  .panel-left { padding-bottom: 0; }
  .panel-right { padding: 12px; }
  .tab-content { padding: 16px; }

  /* Panel tabs: scrollable */
  .panel-tabs {
    overflow-x: auto;
    scrollbar-width: none;
  }
  .panel-tabs::-webkit-scrollbar { display: none; }

  .panel-tab {
    flex-shrink: 0;
    font-size: 0.65rem;
    padding: 12px 10px;
  }

  /* Invoice canvas in panel */
  #invoiceCanvas { border-radius: 6px; box-shadow: 0 8px 24px rgba(0,0,0,0.4); }
  #invoiceCanvas .inv-wrap { font-size: 11px !important; }

  /* ── HISTORY & MISC ── */
  .history-item { padding: 9px 11px; }
  .totals-box   { padding: 10px 12px; }

  /* Ad slots slim */
  .ad-slot-banner { height: 50px; }
  .ad-slot-rect   { height: 150px; }

  /* Toasts: above sticky bar */
  .toast-container { bottom: 72px; right: 12px; left: 12px; }
  .toast { min-width: 0; max-width: 100%; }

  /* Floating disclaimer: above sticky bar */
  .float-disclaimer { bottom: 80px; }

  /* Action button rows */
  div[style*="display:flex; gap:8px"] { flex-wrap: wrap; }
}

/* ─────────────────────────────────────────────────────────
   BREAKPOINT: TINY MOBILE ≤ 380px
   ───────────────────────────────────────────────────────── */
@media (max-width: 380px) {
  .navbar {
    padding: 0 12px !important;
  }

  .nav-logo-text { font-size: 0.9rem; }

  .template-picker-grid,
  .template-grid {
    grid-template-columns: 1fr 1fr;
    gap: 6px;
  }

  .template-thumb-preview,
  .w-tpl-preview { height: 70px; }

  .template-thumb-label,
  .w-tpl-label { font-size: 0.6rem; padding: 4px 6px; }

  .panel-tab  { font-size: 0.6rem; padding: 11px 7px; letter-spacing: 0; }

  .items-table,
  .w-items-table { min-width: 300px; }

  .items-table colgroup col.c-desc { width: 40%; }
  .items-table colgroup col.c-qty  { width: 12%; }
  .items-table colgroup col.c-rate { width: 18%; }
  .items-table colgroup col.c-amt  { width: 20%; }
  .items-table colgroup col.c-del  { width: 10%; }

  .sp-item    { min-width: 62px; }
  .sp-circle  { width: 28px; height: 28px; font-size: 0.7rem; }
  .sp-label   { font-size: 0.52rem; }

  .sticky-dl-bar #stickySaveBtn {
    padding: 10px 10px !important;
    font-size: 0.78rem !important;
    min-width: 60px;
  }
  .sticky-dl-bar .btn-download-pdf {
    font-size: 0.88rem !important;
    padding: 12px 10px !important;
  }
}

/* ─────────────────────────────────────────────────────────
   LARGE SCREENS ≥ 1600px
   ───────────────────────────────────────────────────────── */
@media (min-width: 1600px) {
  .app-shell { grid-template-columns: 55% 45%; }
}

@media (min-width: 1920px) {
  .app-shell {
    max-width: 1920px;
    margin: 0 auto;
    grid-template-columns: 50% 50%;
  }
}

/* ─────────────────────────────────────────────────────────
   ZOOM STABILITY (80%–175%)
   ───────────────────────────────────────────────────────── */
@media (max-width: 900px) {
  .nav-links  { display: none; }
  .hamburger  { display: flex; }
}

.panel-right { contain: layout; }

/* ─────────────────────────────────────────────────────────
   PRINT / PDF
   ───────────────────────────────────────────────────────── */
@media print {
  .navbar,
  .panel-tabs,
  .panel-left,
  .btn-pdf-mobile,
  .sticky-dl-bar,
  .preview-toolbar { display: none !important; }

  .app-shell { display: block; }

  .panel-right { padding: 0; }

  #invoiceCanvas {
    box-shadow: none;
    border-radius: 0;
  }
}