/* =====================================================
   OnlineInvoicesMaker — Mobile-First Generator CSS
   Breakpoints: Mobile ≤767px | Tablet 768-1024px
===================================================== */

/* Force header height variable on small screens */
@media (max-width: 1024px) {
  :root {
    --header-height: 60px;
  }
}

/* =====================================================
   TABLET (768px – 1024px) — Same as mobile:
   Single column, tab switcher, sticky bar
   NO split layout on tablet
===================================================== */
@media (min-width: 768px) and (max-width: 1024px) {

  /* ── CRITICAL: allow scrolling — override generator.css overflow:hidden ── */
  body.generator-body {
    overflow-x: hidden !important;
    overflow-y: auto !important;
    padding-bottom: 24px !important;
    height: auto !important;
  }

  /* Page: scrollable, not fixed height */
  .generator-page {
    height: auto !important;
    min-height: 100vh !important;
    overflow: visible !important;
    padding-top: var(--header-height, 60px) !important;
    background: #f4f5fb !important;
  }
  [data-theme="dark"] .generator-page {
    background: #0a0f1e !important;
  }

  /* Single column — hide preview panel */
  .generator-main {
    grid-template-columns: 1fr !important;
    height: auto !important;
    overflow: visible !important;
    display: block !important;
  }

  .generator-preview-panel {
    display: none !important;
  }

  .generator-form-panel {
    display: flex !important;
    flex-direction: column !important;
    height: auto !important;
    overflow: visible !important;
    padding: 16px 16px 100px !important;
    border-right: none !important;
  }

  /* Show tab switcher */
  .mobile-tab-switcher {
    display: flex !important;
  }

  /* Hide progress steps */
  .progress-steps { display: none !important; }

  /* Toolbar compact */
  .generator-toolbar {
    padding: 0 16px !important;
    height: auto !important;
    min-height: 52px !important;
    flex-wrap: wrap !important;
    gap: 6px !important;
    padding-top: 8px !important;
    padding-bottom: 8px !important;
  }
  .toolbar-btn-text { display: none !important; }
  .toolbar-btn { padding: 8px 10px !important; }
  /* Hide download from toolbar — use sticky bar */
  .toolbar-right .toolbar-btn-primary { display: none !important; }

  /* Template bar: scrollable */
  .template-select-bar {
    padding: 8px 12px !important;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch !important;
  }
  /* Hide color swatches in template bar */
  .template-select-bar > div[style*="margin-left:auto"] { display: none !important; }

  /* Form inputs single column */
  .form-row { grid-template-columns: 1fr !important; gap: 0 !important; }
  .form-control { height: 46px !important; font-size: 0.95rem !important; }

  /* body scroll */
  body.generator-body { overflow-y: auto !important; }
}

/* =====================================================
   MOBILE: max-width 767px
   Full step-based accordion UI
===================================================== */
@media (max-width: 767px) {

  /* ── Page layout ── */
  body.generator-body {
    overflow-x: hidden !important;
    overflow-y: auto !important;
    padding-bottom: 24px !important;
    height: auto !important;
  }

  .generator-page {
    height: auto !important;
    min-height: 100vh !important;
    overflow: visible !important;
    padding-top: var(--header-height, 60px) !important;
    padding-bottom: 0 !important;
    background: #f4f5fb !important;
  }

  [data-theme="dark"] .generator-page {
    background: #0a0f1e !important;
  }

  /* ── Hide desktop preview panel ── */
  .generator-preview-panel {
    display: none !important;
  }

  /* ── Show form panel full width ── */
  .generator-main {
    grid-template-columns: 1fr !important;
    height: auto !important;
    overflow: visible !important;
    display: block !important;
  }

  .generator-form-panel {
    display: flex !important;
    flex-direction: column !important;
    height: auto !important;
    overflow: visible !important;
    padding: 12px 12px 100px !important;
    border-right: none !important;
  }

  /* ── Show tab switcher on mobile (Edit Invoice / Live Preview) ── */
  .mobile-tab-switcher { display: flex !important; }
  .progress-steps { display: none !important; }

  /* ── Toolbar: compact strip ── */
  .generator-toolbar {
    padding: 0 12px !important;
    height: auto !important;
    min-height: 50px !important;
    flex-wrap: wrap !important;
    gap: 6px !important;
    padding-top: 8px !important;
    padding-bottom: 8px !important;
  }

  .toolbar-btn-text { display: none !important; }
  .toolbar-btn { padding: 8px 10px !important; font-size: 0.8rem !important; }
  .toolbar-btn-primary { padding: 8px 12px !important; }

  /* Hide download button from toolbar on mobile (use sticky bar instead) */
  .toolbar-right .toolbar-btn-primary { display: none !important; }

  /* ── Template bar ── */
  .template-select-bar {
    padding: 8px 12px !important;
    gap: 5px !important;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch !important;
  }

  .template-label { font-size: 0.65rem !important; }
  .template-pill { padding: 5px 10px !important; font-size: 0.72rem !important; }

  /* Hide color swatches in template bar on mobile (use branding section) */
  .template-select-bar > div[style*="margin-left:auto"] { display: none !important; }

  /* ── Presets strip ── */
  .presets-strip {
    padding: 10px 12px !important;
    gap: 6px !important;
    flex-wrap: wrap !important;
  }

  /* ── Form sections — accordion ── */
  .form-section {
    border-radius: 12px !important;
    margin-bottom: 10px !important;
    box-shadow: 0 2px 8px rgba(0,0,0,0.06) !important;
  }

  .form-section-header {
    padding: 16px 16px !important;
    min-height: 58px !important;
    -webkit-tap-highlight-color: transparent;
  }

  .form-section-header h3 {
    font-size: 0.95rem !important;
    font-weight: 700 !important;
  }

  .section-icon {
    width: 36px !important;
    height: 36px !important;
    font-size: 0.88rem !important;
  }

  .form-section-body {
    padding: 16px !important;
  }

  /* ── Form inputs ── */
  .form-row {
    grid-template-columns: 1fr !important;
    gap: 0 !important;
  }

  .form-group {
    margin-bottom: 14px !important;
  }

  .form-group label {
    font-size: 0.78rem !important;
    margin-bottom: 5px !important;
  }

  .form-control {
    height: 46px !important;
    font-size: 0.95rem !important;
    padding: 12px 14px !important;
    border-radius: 10px !important;
    /* Large touch target */
    -webkit-appearance: none;
  }

  textarea.form-control {
    height: auto !important;
    min-height: 80px !important;
  }

  select.form-control {
    height: 46px !important;
  }

  /* ── Items table → card-style on mobile ── */
  .items-table-wrapper {
    overflow: visible !important;
  }

  .items-table { display: none !important; }

  /* Mobile item cards (added by JS) */
  .mob-item-card {
    background: var(--bg-card, #fff);
    border: 1px solid var(--border, #e2e8f0);
    border-radius: 12px;
    padding: 14px;
    margin-bottom: 10px;
    position: relative;
    animation: itemCardIn 0.2s ease-out;
  }

  @keyframes itemCardIn {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
  }

  .mob-item-card .mob-item-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-top: 8px;
  }

  .mob-item-card .mob-item-desc {
    grid-column: 1 / -1;
  }

  .mob-item-card .mob-item-label {
    font-size: 0.7rem;
    font-weight: 700;
    color: var(--text-muted, #94a3b8);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 3px;
  }

  .mob-item-card input.form-control {
    height: 40px !important;
    font-size: 0.88rem !important;
    padding: 8px 10px !important;
  }

  .mob-item-card .mob-item-total {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid var(--border, #e2e8f0);
  }

  .mob-item-total-label {
    font-size: 0.78rem;
    color: var(--text-secondary, #475569);
    font-weight: 600;
  }

  .mob-item-total-val {
    font-size: 1rem;
    font-weight: 800;
    color: var(--primary, #6366f1);
  }

  .mob-item-remove {
    position: absolute;
    top: 10px;
    right: 10px;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: rgba(239,68,68,0.1);
    color: #ef4444;
    border: none;
    font-size: 0.75rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  /* ── Totals summary ── */
  .totals-block {
    font-size: 0.9rem !important;
  }

  .totals-row {
    padding: 7px 0 !important;
    font-size: 0.88rem !important;
  }

  .totals-row.grand-total .total-label,
  .totals-row.grand-total .total-value {
    font-size: 1.1rem !important;
  }

  /* ── Logo upload ── */
  .logo-upload-area {
    padding: 16px !important;
    min-height: 80px !important;
  }

  /* ── Signature canvas ── */
  .signature-canvas {
    height: 80px !important;
    touch-action: none;
  }

}

/* mob-sticky-bar removed */

/* =====================================================
   MOBILE FULLSCREEN PREVIEW MODAL
===================================================== */
.mob-preview-modal {
  display: none;
  position: fixed;
  inset: 0;
  background: #f0f2f8;
  z-index: 4000;
  flex-direction: column;
  overflow: hidden;
  /* Slide up animation */
  transform: translateY(100%);
  transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}

[data-theme="dark"] .mob-preview-modal {
  background: #060d1a;
}

.mob-preview-modal.open {
  display: flex;
  transform: translateY(0);
}

/* ── Preview header bar ── */
.mob-preview-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 0 12px;
  height: 58px;
  min-height: 58px;
  background: #ffffff;
  border-bottom: 1px solid #e2e8f0;
  flex-shrink: 0;
  padding-top: env(safe-area-inset-top, 0px);
}

[data-theme="dark"] .mob-preview-header {
  background: #1e293b;
  border-bottom-color: #334155;
}

.mob-preview-back {
  display: flex;
  align-items: center;
  gap: 8px;
  background: none;
  border: none;
  font-size: 0.88rem;
  font-weight: 600;
  color: #6366f1;
  cursor: pointer;
  padding: 8px 0;
  -webkit-tap-highlight-color: transparent;
}

.mob-preview-title {
  font-size: 0.88rem;
  font-weight: 700;
  color: #0f172a;
  flex-shrink: 0;
}
[data-theme="dark"] .mob-preview-title { color: #f1f5f9; }

/* ── Zoom controls ── */
.mob-zoom-controls {
  display: flex;
  align-items: center;
  gap: 2px;
  background: #f1f5f9;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 3px 4px;
  flex-shrink: 0;
}
[data-theme="dark"] .mob-zoom-controls {
  background: #0f172a;
  border-color: #334155;
}

.mob-zoom-btn {
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  border-radius: 6px;
  color: #475569;
  font-size: 0.85rem;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.15s, color 0.15s;
}
.mob-zoom-btn:active {
  background: rgba(99,102,241,0.12);
  color: #6366f1;
}
[data-theme="dark"] .mob-zoom-btn { color: #94a3b8; }

.mob-zoom-label {
  font-size: 0.72rem;
  font-weight: 700;
  color: #475569;
  min-width: 34px;
  text-align: center;
  letter-spacing: 0.02em;
}
[data-theme="dark"] .mob-zoom-label { color: #94a3b8; }

/* Header compact on very small screens */
@media (max-width: 380px) {
  .mob-preview-title { display: none; }
  .mob-zoom-label { min-width: 28px; font-size: 0.68rem; }
}

.mob-preview-dl {
  display: flex;
  align-items: center;
  gap: 6px;
  background: #6366f1;
  color: #ffffff;
  border: none;
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 0.82rem;
  font-weight: 700;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.mob-preview-dl:active {
  background: #4f46e5;
  transform: scale(0.97);
}

/* ── Preview body (scrollable) ── */
.mob-preview-body {
  flex: 1;
  overflow-y: auto;
  overflow-x: auto;
  padding: 16px 12px 40px;
  -webkit-overflow-scrolling: touch;
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* Invoice scales to fit screen */
.mob-preview-body .invoice-document {
  width: 100% !important;
  max-width: 100% !important;
  transform: scale(0.78) !important;
  transform-origin: top center !important;
  margin-bottom: -60px !important;
}

/* ── Swipe hint ── */
.mob-swipe-hint {
  position: absolute;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0,0,0,0.5);
  color: #fff;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 6px 16px;
  border-radius: 99px;
  display: flex;
  align-items: center;
  gap: 6px;
  pointer-events: none;
  animation: hintFade 2.5s ease forwards;
  animation-delay: 1s;
  opacity: 0;
}

@keyframes hintFade {
  0%   { opacity: 0; }
  20%  { opacity: 1; }
  80%  { opacity: 1; }
  100% { opacity: 0; }
}

/* =====================================================
   TABLET SPECIFIC TWEAKS
===================================================== */
@media (min-width: 768px) and (max-width: 1024px) {

  .generator-toolbar {
    gap: 6px !important;
  }

  .form-section-header {
    padding: 12px 14px !important;
  }

  .form-section-header h3 {
    font-size: 0.9rem !important;
  }

  .invoice-preview-title {
    font-size: 0.78rem !important;
  }

  /* compact form inputs on tablet */
  .form-control {
    height: 40px !important;
    font-size: 0.88rem !important;
  }

  .form-group label {
    font-size: 0.75rem !important;
  }
}

/* =====================================================
   AUTO-SAVE INDICATOR
===================================================== */
.autosave-indicator {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 0.7rem;
  font-weight: 600;
  color: #10b981;
  opacity: 0;
  transition: opacity 0.3s ease;
  padding: 4px 8px;
  background: rgba(16,185,129,0.08);
  border-radius: 6px;
  border: 1px solid rgba(16,185,129,0.2);
}

.autosave-indicator.visible {
  opacity: 1;
}

/* =====================================================
   SECTION OPEN INDICATOR (accordion state)
===================================================== */
.form-section.active-section {
  border-color: rgba(99,102,241,0.35) !important;
  box-shadow: 0 4px 20px rgba(99,102,241,0.1) !important;
}

.form-section.active-section .section-icon {
  background: linear-gradient(135deg, #6366f1, #4f46e5) !important;
  color: #fff !important;
}

.form-section.active-section .form-section-header h3 {
  color: var(--primary, #6366f1) !important;
}

/* =====================================================
   SMOOTH SECTION BODY ANIMATION
===================================================== */
.form-section-body {
  transition: max-height 0.3s cubic-bezier(0.4,0,0.2,1),
              opacity 0.25s ease,
              padding 0.25s ease;
  overflow: hidden;
}

/* Collapsed */
.form-section.collapsed .form-section-body {
  max-height: 0 !important;
  opacity: 0 !important;
  padding-top: 0 !important;
  padding-bottom: 0 !important;
}

/* Open */
.form-section:not(.collapsed) .form-section-body {
  max-height: 2000px;
  opacity: 1;
}

/* Chevron rotation */
.form-section.collapsed .section-toggle-icon {
  transform: rotate(-90deg);
}

.section-toggle-icon {
  transition: transform 0.25s ease;
  color: var(--text-muted, #94a3b8);
  font-size: 0.78rem;
}

/* =====================================================
   MOBILE ITEM CARD STYLES (used by JS on mobile)
===================================================== */
#mobileItemsContainer {
  display: none;
}

@media (max-width: 767px) {
  #mobileItemsContainer {
    display: block;
  }
}

/* Add item button inside section */
.mob-add-item-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 13px;
  background: rgba(99,102,241,0.07);
  border: 1.5px dashed rgba(99,102,241,0.35);
  border-radius: 10px;
  color: #6366f1;
  font-size: 0.88rem;
  font-weight: 700;
  cursor: pointer;
  margin-top: 8px;
  transition: background 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.mob-add-item-btn:active {
  background: rgba(99,102,241,0.14);
}
