/* ==========================================================
   QuickScanHub - Responsive overrides
   Loaded after app.css. Mobile-first patches.
   ========================================================== */

/* Prevent any horizontal scroll on the whole document */
html, body {
  max-width: 100%;
  overflow-x: hidden;
}

/* ---------- HEADER ---------- */
@media (max-width: 880px) {
  .site-header { padding: 0; }

  .header-inner {
    flex-wrap: wrap;
    padding: 12px 16px;
    gap: 8px;
  }

  .logo { font-size: 16px; }
  .logo-mark { width: 28px; height: 28px; font-size: 15px; }

  /* Hide the in-header nav links on mobile (Features/Generator anchors) */
  .nav { display: none; }

  .controls {
    gap: 6px;
    flex-wrap: wrap;
  }

  .lang-select {
    padding: 6px 8px;
    font-size: 12px;
    max-width: 110px;
  }

  .icon-btn {
    width: 34px;
    height: 34px;
  }

  /* Make the auth buttons smaller and not wrap text */
  .controls .btn {
    padding: 8px 12px;
    font-size: 13px;
  }
}

/* On very small screens stack the auth buttons full-width below the controls row */
@media (max-width: 480px) {
  .header-inner {
    padding: 10px 12px;
  }
  /* If both Sign In and Get Started buttons are there, hide the first one */
  .controls > a.btn.secondary { display: none; }
}

/* ---------- HERO ---------- */
@media (max-width: 880px) {
  .hero { padding: 40px 16px 24px; }
  .hero h1 { font-size: clamp(28px, 8vw, 40px); line-height: 1.15; }
  .hero .subtitle { font-size: 15px; }
  .hero-cta .btn { width: 100%; }
  .hero-cta { flex-direction: column; }
}

/* ---------- FEATURES ---------- */
@media (max-width: 880px) {
  .features { padding: 32px 16px; }
  .features h2 { font-size: 24px; margin-bottom: 24px; }
  .feature-grid { gap: 12px; }
  .feature { padding: 20px 14px; }
}

/* ---------- GENERATOR + EDITOR ---------- */
@media (max-width: 880px) {
  .generator { padding: 32px 16px; }
  .generator .panel-title { font-size: 22px; }
  .generator .panel-sub { font-size: 14px; }

  .gen-layout { gap: 16px; }

  .card { padding: 16px; }

  /* Tabs: allow horizontal scroll instead of bursting */
  .type-tabs {
    overflow-x: auto;
    scrollbar-width: none;
    -ms-overflow-style: none;
  }
  .type-tabs::-webkit-scrollbar { display: none; }
  .type-tab {
    padding: 8px 12px;
    font-size: 13px;
  }

  /* Color picker rows */
  .field-grid { grid-template-columns: 1fr; gap: 12px; }
  .color-input { width: 42px; height: 38px; }

  /* Style grids: 4 columns instead of unlimited */
  .style-grid {
    grid-template-columns: repeat(4, 1fr);
    gap: 6px;
  }
  .style-btn { padding: 6px; }
}

/* ---------- PREVIEW QR (the main culprit) ---------- */
.preview-panel { min-width: 0; }
.preview-box {
  max-width: 100%;
  padding: 16px;
  overflow: hidden;
}
.preview-box > div { max-width: 100%; }
.preview-box svg,
.preview-box canvas,
.preview-box img {
  max-width: 100% !important;
  height: auto !important;
}

@media (max-width: 880px) {
  .preview-panel { position: static; }
  .preview-box { padding: 12px; min-height: 240px; }
  .preview-actions { flex-direction: column; }
  .preview-actions .btn { width: 100%; }
}

/* ---------- INPUT FILE ON MOBILE ---------- */
input[type="file"] {
  max-width: 100%;
  font-size: 12px;
}
@media (max-width: 880px) {
  input[type="file"] { font-size: 11px; }
}

/* ---------- DASHBOARD LAYOUT ---------- */
@media (max-width: 880px) {
  .dash-layout {
    grid-template-columns: 1fr;
    padding: 12px;
    gap: 12px;
  }
  .dash-sidebar {
    flex-direction: row;
    overflow-x: auto;
    scrollbar-width: none;
    padding: 6px;
    gap: 4px;
    -webkit-overflow-scrolling: touch;
  }
  .dash-sidebar::-webkit-scrollbar { display: none; }
  .dash-sidebar a {
    padding: 8px 12px;
    font-size: 13px;
    white-space: nowrap;
    flex-shrink: 0;
  }
}

/* ---------- TABLES (horizontal scroll instead of squish) ---------- */
.card > .table,
.card > div > .table {
  display: block;
}
@media (max-width: 880px) {
  /* Wrap any table inside a card with horizontal scroll */
  .card {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  .table { min-width: 600px; font-size: 13px; }
  .table th, .table td { padding: 10px 8px; }

  /* Action buttons inside table cells */
  .table .btn.small {
    padding: 5px 9px;
    font-size: 11px;
  }
}

/* ---------- STAT GRID ---------- */
@media (max-width: 600px) {
  .stat-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .stat { padding: 14px; }
  .stat .value { font-size: 24px; }
  .stat .label { font-size: 11px; }
}

/* ---------- BAR LIST (analytics) ---------- */
@media (max-width: 880px) {
  .bar-row {
    grid-template-columns: 90px 1fr 40px;
    font-size: 12px;
  }
}

/* ---------- TOAST ---------- */
@media (max-width: 600px) {
  .toast {
    left: 16px;
    right: 16px;
    transform: translateY(100px);
    width: auto;
  }
  .toast.show { transform: translateY(0); }
}

/* ---------- MODAL ---------- */
@media (max-width: 600px) {
  .modal {
    padding: 20px;
    border-radius: 16px;
    max-height: 95vh;
  }
}

/* ---------- AUTH PAGES ---------- */
@media (max-width: 480px) {
  main > .card {
    padding: 20px;
    border-radius: 14px;
  }
}

/* ---------- CHART ---------- */
@media (max-width: 880px) {
  .chart-container { height: 220px; }
}

/* ==========================================================
   RTL fixes - prevent horizontal overflow in Hebrew/Arabic
   ========================================================== */

html[dir="rtl"] body,
html[dir="rtl"] {
  overflow-x: clip;
}

/* All sections should respect viewport width */
.hero, .features, .generator, main, .container {
  max-width: 100%;
  overflow-x: hidden;
}

/* Force any wide child to clip nicely */
@media (max-width: 880px) {
  .gen-layout, .dash-layout, .feature-grid, .stat-grid {
    max-width: 100%;
  }

  .card, .preview-box {
    max-width: 100%;
    box-sizing: border-box;
  }

  /* Style grid icons may overflow on iPhone - cap them */
  .style-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
  .style-btn {
    min-width: 0;
    max-width: 100%;
  }

  /* Inputs should never exceed parent */
  input, select, textarea {
    max-width: 100%;
    box-sizing: border-box;
  }

  /* Color row may push beyond - cap */
  .color-row {
    flex-wrap: wrap;
    max-width: 100%;
  }
  .color-row input[type="text"] {
    min-width: 0;
    flex: 1 1 100px;
  }
}

/* Header in RTL - the controls were getting pushed off-screen */
@media (max-width: 880px) {
  html[dir="rtl"] .header-inner,
  html[dir="ltr"] .header-inner {
    max-width: 100%;
    box-sizing: border-box;
  }
  html[dir="rtl"] .controls,
  html[dir="ltr"] .controls {
    min-width: 0;
  }
}

/* ==========================================================
   RTL fixes - prevent horizontal overflow in Hebrew/Arabic
   ========================================================== */

html[dir="rtl"] body,
html[dir="rtl"] {
  overflow-x: clip;
}

/* All sections should respect viewport width */
.hero, .features, .generator, main, .container {
  max-width: 100%;
  overflow-x: hidden;
}

/* Force any wide child to clip nicely */
@media (max-width: 880px) {
  .gen-layout, .dash-layout, .feature-grid, .stat-grid {
    max-width: 100%;
  }

  .card, .preview-box {
    max-width: 100%;
    box-sizing: border-box;
  }

  /* Style grid icons may overflow on iPhone - cap them */
  .style-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
  .style-btn {
    min-width: 0;
    max-width: 100%;
  }

  /* Inputs should never exceed parent */
  input, select, textarea {
    max-width: 100%;
    box-sizing: border-box;
  }

  /* Color row may push beyond - cap */
  .color-row {
    flex-wrap: wrap;
    max-width: 100%;
  }
  .color-row input[type="text"] {
    min-width: 0;
    flex: 1 1 100px;
  }
}

/* Header in RTL - the controls were getting pushed off-screen */
@media (max-width: 880px) {
  html[dir="rtl"] .header-inner,
  html[dir="ltr"] .header-inner {
    max-width: 100%;
    box-sizing: border-box;
  }
  html[dir="rtl"] .controls,
  html[dir="ltr"] .controls {
    min-width: 0;
  }
}

/* ==========================================================
   Final overflow fixes - iOS Safari edge cases
   ========================================================== */

/* Universal box-sizing for ALL elements */
*, *::before, *::after {
  box-sizing: border-box;
}

/* The card itself must not overflow its grid cell */
.gen-layout > .card,
.gen-layout > .preview-panel,
.dash-main > .card,
.dash-main > div {
  min-width: 0;
  max-width: 100%;
  width: 100%;
}

/* The grid layouts themselves need min-width:0 to allow shrinking */
.gen-layout, .dash-layout, .dash-main {
  min-width: 0;
}

/* Any direct child of .card */
.card > * {
  max-width: 100%;
  min-width: 0;
}

/* Color row: stack on tight screens */
@media (max-width: 480px) {
  .color-row {
    flex-wrap: nowrap;
    align-items: stretch;
  }
  .color-row input[type="text"] {
    min-width: 0;
    width: 100%;
    flex: 1;
  }
  .color-input {
    flex-shrink: 0;
    width: 42px;
  }
}

/* Type tabs - ensure they scroll horizontally cleanly */
.type-tabs {
  width: 100%;
  max-width: 100%;
}
.type-tab {
  flex-shrink: 0;
}

/* Generator section padding fix */
@media (max-width: 600px) {
  .generator .container,
  .features .container,
  .hero .container {
    padding-left: 12px;
    padding-right: 12px;
  }
  .card { padding: 14px; }
}

/* ==========================================================
   Final overflow fixes - iOS Safari edge cases
   ========================================================== */

/* Universal box-sizing for ALL elements */
*, *::before, *::after {
  box-sizing: border-box;
}

/* The card itself must not overflow its grid cell */
.gen-layout > .card,
.gen-layout > .preview-panel,
.dash-main > .card,
.dash-main > div {
  min-width: 0;
  max-width: 100%;
  width: 100%;
}

/* The grid layouts themselves need min-width:0 to allow shrinking */
.gen-layout, .dash-layout, .dash-main {
  min-width: 0;
}

/* Any direct child of .card */
.card > * {
  max-width: 100%;
  min-width: 0;
}

/* Color row: stack on tight screens */
@media (max-width: 480px) {
  .color-row {
    flex-wrap: nowrap;
    align-items: stretch;
  }
  .color-row input[type="text"] {
    min-width: 0;
    width: 100%;
    flex: 1;
  }
  .color-input {
    flex-shrink: 0;
    width: 42px;
  }
}

/* Type tabs - ensure they scroll horizontally cleanly */
.type-tabs {
  width: 100%;
  max-width: 100%;
}
.type-tab {
  flex-shrink: 0;
}

/* Generator section padding fix */
@media (max-width: 600px) {
  .generator .container,
  .features .container,
  .hero .container {
    padding-left: 12px;
    padding-right: 12px;
  }
  .card { padding: 14px; }
}

/* ==========================================================
   Type tabs - wrap into grid instead of horizontal scroll on mobile
   ========================================================== */

@media (max-width: 880px) {
  .type-tabs {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
    overflow-x: visible;
    padding: 6px;
  }
  .type-tab {
    padding: 10px 8px;
    font-size: 13px;
    text-align: center;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
}

@media (max-width: 380px) {
  .type-tabs {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* ==========================================================
   QR preview - never crop, scale to fit
   ========================================================== */

.preview-box {
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: visible;
}

.preview-box > div,
.preview-box > div > div {
  max-width: 100% !important;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* The qr-code-styling library outputs an SVG with fixed width/height attributes.
   Force them to be responsive. */
.preview-box svg {
  width: 100% !important;
  height: auto !important;
  max-width: 360px !important;
}

/* When wrapped with a frame, the wrapper div needs to scale too */
.preview-box [style*="border"] {
  max-width: 100% !important;
  width: auto !important;
  box-sizing: border-box;
}

@media (max-width: 600px) {
  .preview-box {
    padding: 12px;
  }
  .preview-box svg {
    max-width: 280px !important;
  }
}

/* ==========================================================
   QR preview - constrain to a reasonable size on mobile
   ========================================================== */

@media (max-width: 880px) {
  .preview-box {
    padding: 16px;
    min-height: 0;
  }
  .preview-box svg {
    max-width: 240px !important;
    width: 100% !important;
    height: auto !important;
  }
  /* The frame wrapper div */
  .preview-box > div,
  .preview-box [style*="border"] {
    max-width: 280px !important;
  }
}

@media (max-width: 480px) {
  .preview-box svg {
    max-width: 200px !important;
  }
  .preview-box > div,
  .preview-box [style*="border"] {
    max-width: 240px !important;
  }
}

/* Center the preview content */
.preview-box {
  text-align: center;
}
.preview-box > div {
  margin: 0 auto;
}

/* ==========================================================
   QR preview - constrain to a reasonable size on mobile
   ========================================================== */

@media (max-width: 880px) {
  .preview-box {
    padding: 16px;
    min-height: 0;
  }
  .preview-box svg {
    max-width: 240px !important;
    width: 100% !important;
    height: auto !important;
  }
  /* The frame wrapper div */
  .preview-box > div,
  .preview-box [style*="border"] {
    max-width: 280px !important;
  }
}

@media (max-width: 480px) {
  .preview-box svg {
    max-width: 200px !important;
  }
  .preview-box > div,
  .preview-box [style*="border"] {
    max-width: 240px !important;
  }
}

/* Center the preview content */
.preview-box {
  text-align: center;
}
.preview-box > div {
  margin: 0 auto;
}

/* ==========================================================
   QR preview - FINAL fix using container constraints
   ========================================================== */

/* Reset what we did before */
.preview-box svg {
  max-width: none !important;
}
.preview-box > div,
.preview-box [style*="border"] {
  max-width: none !important;
}

/* Use container query approach: scale via the container */
.preview-box {
  padding: 16px;
  max-width: 100%;
  overflow: hidden;
}

/* Mobile: scale down the entire preview content */
@media (max-width: 600px) {
  .preview-box {
    padding: 8px;
  }
  /* Scale the inner content to fit */
  .preview-box > div:first-child {
    transform: scale(0.7);
    transform-origin: center center;
    margin: -15% 0;
  }
}

@media (max-width: 400px) {
  .preview-box > div:first-child {
    transform: scale(0.55);
    margin: -22% 0;
  }
}

/* ==========================================================
   QR preview - FINAL fix using container constraints
   ========================================================== */

/* Reset what we did before */
.preview-box svg {
  max-width: none !important;
}
.preview-box > div,
.preview-box [style*="border"] {
  max-width: none !important;
}

/* Use container query approach: scale via the container */
.preview-box {
  padding: 16px;
  max-width: 100%;
  overflow: hidden;
}

/* Mobile: scale down the entire preview content */
@media (max-width: 600px) {
  .preview-box {
    padding: 8px;
  }
  /* Scale the inner content to fit */
  .preview-box > div:first-child {
    transform: scale(0.7);
    transform-origin: center center;
    margin: -15% 0;
  }
}

@media (max-width: 400px) {
  .preview-box > div:first-child {
    transform: scale(0.55);
    margin: -22% 0;
  }
}

/* ==========================================================
   QR preview - more aggressive scaling for thick frames
   ========================================================== */

@media (max-width: 600px) {
  .preview-box {
    padding: 4px;
    overflow: hidden;
  }
  .preview-box > div:first-child {
    transform: scale(0.6);
    margin: -20% 0;
  }
}

@media (max-width: 400px) {
  .preview-box > div:first-child {
    transform: scale(0.5);
    margin: -25% 0;
  }
}

/* Force ALL inline-styled wrappers to shrink */
.preview-box [style*="padding"],
.preview-box [style*="border"],
.preview-box [style*="border-radius"] {
  max-width: 100% !important;
  box-sizing: border-box !important;
}

/* ==========================================================
   QR preview - PROPER aspect-ratio preservation
   ========================================================== */

/* Reset all previous attempts */
.preview-box {
  padding: 20px !important;
  overflow: visible !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
}

.preview-box > div:first-child {
  transform: none !important;
  margin: 0 !important;
  max-width: 100% !important;
  display: inline-block !important;
}

/* Force SVG to preserve aspect ratio */
.preview-box svg {
  display: block !important;
  width: auto !important;
  height: auto !important;
  max-width: 100% !important;
  max-height: 60vh !important;
}

/* The frame wrapper (when there's a frame) - it has inline styles */
.preview-box > div > div {
  display: inline-block !important;
  max-width: 100% !important;
}

/* On mobile, give the QR a sensible max size */
@media (max-width: 600px) {
  .preview-box {
    padding: 12px !important;
  }
  .preview-box svg {
    max-width: min(260px, calc(100vw - 80px)) !important;
  }
}

@media (max-width: 400px) {
  .preview-box svg {
    max-width: min(220px, calc(100vw - 60px)) !important;
  }
}

/* ==========================================================
   QR preview - PROPER aspect-ratio preservation
   ========================================================== */

/* Reset all previous attempts */
.preview-box {
  padding: 20px !important;
  overflow: visible !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
}

.preview-box > div:first-child {
  transform: none !important;
  margin: 0 !important;
  max-width: 100% !important;
  display: inline-block !important;
}

/* Force SVG to preserve aspect ratio */
.preview-box svg {
  display: block !important;
  width: auto !important;
  height: auto !important;
  max-width: 100% !important;
  max-height: 60vh !important;
}

/* The frame wrapper (when there's a frame) - it has inline styles */
.preview-box > div > div {
  display: inline-block !important;
  max-width: 100% !important;
}

/* On mobile, give the QR a sensible max size */
@media (max-width: 600px) {
  .preview-box {
    padding: 12px !important;
  }
  .preview-box svg {
    max-width: min(260px, calc(100vw - 80px)) !important;
  }
}

@media (max-width: 400px) {
  .preview-box svg {
    max-width: min(220px, calc(100vw - 60px)) !important;
  }
}
