/* =====================================================================
   MOBILE OVERRIDES — m.edbot.to
   Applied at viewport ≤ 768px. Desktop styles in terminal.css remain
   intact for larger viewports.
   Patterns sourced from skills/frontend-design-ultimate/references/
   mobile-patterns.md.
   ===================================================================== */

/* Hamburger button — hidden on desktop, shown on mobile */
.m-hamburger {
  display: none;
  position: fixed;
  top: 10px;
  left: 10px;
  z-index: 1000;
  width: 44px;
  height: 44px;
  background: #fafafa;
  border: 1px solid #e5e5e5;
  border-radius: 8px;
  cursor: pointer;
  align-items: center;
  justify-content: center;
  box-shadow: 0 1px 4px rgba(0,0,0,0.08);
}
.m-hamburger svg { width: 22px; height: 22px; fill: #0a0a0a; }

/* Backdrop — shown when menu is open */
.m-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.35);
  z-index: 900;
}

@media (max-width: 768px) {
  /* === SIDEBAR → slide-in === */
  .m-hamburger { display: flex; }
  .m-backdrop.open { display: block; }

  #sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 260px !important;
    max-width: 80vw;
    z-index: 950;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    overflow-y: auto;
    box-shadow: 2px 0 12px rgba(0,0,0,0.15);
    padding-top: 60px !important;  /* clear space for close-X */
  }
  #sidebar.open { transform: translateX(0); }

  /* Container: no side margins, full width */
  .terminal-container {
    width: 100% !important;
    min-width: 0 !important;
  }

  .terminal-body {
    padding: 56px 16px 80px !important;  /* top for hamburger, bottom for floating CTA */
    max-width: 100% !important;
  }

  /* Touch-friendly nav items */
  .nav-link {
    padding: 14px 18px !important;
    font-size: 15px !important;
    min-height: 44px;
    display: flex;
    align-items: center;
  }

  .nav-group-label {
    padding-top: 12px !important;
    padding-bottom: 6px !important;
  }

  /* === HEADINGS === */
  h1 { font-size: 22px !important; line-height: 1.25; }
  h2 { font-size: 18px !important; line-height: 1.3; }

  /* === GRIDS → single column === */
  #ab-grid,
  [style*="grid-template-columns: 1fr 1fr 1fr"],
  [style*="grid-template-columns: 1fr 1fr"],
  [style*="grid-template-columns: minmax"] {
    grid-template-columns: 1fr !important;
    gap: 12px !important;
  }

  /* Landing URL: override break-all (letter-per-line on narrow) with break-word */
  #landing-url, #thanks-url {
    word-break: break-word !important;
    overflow-wrap: anywhere !important;
    min-width: 0;
  }

  /* /build phone-frame preview: scale iframe to show FULL hero on mobile.
     Natural 390×760 viewport (matches landing mobile design) scaled via
     (100vw - 56px) / 390 to fit available screen width inside phone bezel.
     Parent screen sized proportionally so no vertical clipping. */
  #result-block > div {
    display: block !important;  /* collapse the 2-col grid */
  }
  #result-block > div > div:first-child {
    margin-bottom: 16px;
  }
  /* Screen (inside bezel): fixed height scales with iframe */
  #result-block [style*="border-radius: 26px"] {
    height: calc((100vw - 82px) / 390 * 760) !important;
    position: relative !important;
  }
  #landing-preview {
    width: 390px !important;
    height: 760px !important;
    transform: scale(calc((100vw - 82px) / 390px));
    transform-origin: 0 0 !important;
    position: absolute !important;
    top: 0;
    left: 0;
  }

  /* Style picker (/hero-variants) — tabs above + horizontal swipe carousel */
  #variants {
    display: flex !important;
    flex-direction: row !important;
    flex-wrap: nowrap !important;
    justify-content: flex-start !important;  /* override inline 'center' which overflows both sides */
    overflow-x: auto !important;
    scroll-snap-type: x mandatory !important;
    scroll-padding-left: 8px;
    gap: 12px !important;
    padding: 0 8px !important;
    margin-left: -8px;
    margin-right: -8px;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  #variants::-webkit-scrollbar { display: none; }

  .variant-card {
    flex: 0 0 calc(100vw - 48px) !important;
    max-width: 360px !important;
    padding: 10px !important;
    box-sizing: border-box;
    scroll-snap-align: start;
  }
  .variant-card > div:first-child {
    padding-right: 4px;
  }
  /* Phone frame: fit full hero vertically without cutting CTA+PS.
     Block layout (no flex) so iframe can be absolutely centered
     regardless of its transform/overflow. */
  .variant-card > div[style*="396px"] {
    width: 100% !important;
    max-width: none !important;
    height: 560px !important;
    overflow: hidden;
    position: relative;
    display: block !important;
  }
  /* Iframe natural size 390×760 (mobile landing viewport).
     Scale 0.7: visual 273×532 fits under 28px notch in 560px frame.
     Absolute + left:50% + negative margin-left = visual-centered in frame.
     margin-left = -(native_width * scale) / 2 = -(390 * 0.7) / 2 = -136.5 */
  .variant-card iframe {
    width: 390px !important;
    height: 760px !important;
    transform: scale(0.7);
    transform-origin: 0 0;
    position: absolute !important;
    left: 50%;
    top: 28px;
    margin-left: -136.5px !important;
    border: 0 !important;
    display: block !important;
  }

  /* Larger phones — scale up, recalculate centering offset */
  @media (min-width: 400px) and (max-width: 768px) {
    .variant-card iframe {
      transform: scale(0.75);
      margin-left: -146.25px !important;
    }
  }

  #variants::after {
    content: "";
    flex: 0 0 8px;
  }

  /* === TABLES → stacked cards === */
  table {
    width: 100%;
    border: none !important;
  }
  table thead {
    display: none;  /* hide table headers, use inline labels */
  }
  table tr {
    display: block;
    background: #fff;
    border: 1px solid #e5e5e5;
    border-radius: 8px;
    padding: 10px 12px;
    margin-bottom: 10px;
  }
  table td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 0 !important;
    border: none !important;
    gap: 8px;
  }
  table td:first-child {
    border-bottom: 1px solid #f0f0f0;
    padding-bottom: 10px !important;
    margin-bottom: 6px;
  }
  table td input[type="number"] {
    max-width: 80px;
  }
  table td input[type="text"],
  table td input[type="email"] {
    width: 100%;
  }

  /* === BUTTONS full-width default === */
  .btn {
    min-height: 44px;
    font-size: 15px !important;
  }
  .btn-accent,
  button[type="submit"] {
    width: 100%;
  }
  .btn-small {
    min-height: 36px;
    font-size: 12px !important;
    padding: 6px 12px !important;
  }

  /* === FORMS === */
  input[type="text"],
  input[type="email"],
  input[type="password"],
  input[type="number"],
  textarea,
  select {
    font-size: 16px !important;  /* prevent iOS auto-zoom */
    min-height: 44px;
    padding: 10px 12px !important;
  }
  textarea { min-height: 80px; }

  /* === PROJECT CARDS === */
  .project-card {
    padding: 12px 14px !important;
  }

  /* === FLOATING CTA BAR (where applicable) === */
  .m-floating-cta {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: #fff;
    border-top: 1px solid #e5e5e5;
    padding: 10px 12px;
    box-shadow: 0 -2px 8px rgba(0,0,0,0.06);
    z-index: 100;
    display: flex;
    gap: 8px;
  }
  .m-floating-cta .btn { flex: 1; }

  /* === HIDE legacy desktop-only elements (none yet, placeholder) === */

  /* === Creatives page 3-col → stack === */
  #ab-grid > div {
    margin-bottom: 0;
  }

  /* === Btn-group wrap === */
  .btn-group {
    flex-wrap: wrap;
  }

  /* === Hero sections / welcome === */
  [style*="display: flex"][style*="gap: 10px"] {
    flex-wrap: wrap;
  }

  /* === Ankety sticky-toolbar — wrap to 2 rows === */
  .sticky-toolbar > div {
    flex-wrap: wrap !important;
    padding: 10px 12px !important;
    gap: 8px !important;
  }
  .sticky-toolbar .m-alt-input {
    flex: 1 1 calc(50% - 4px) !important;
    margin: 0 !important;
    min-width: 0;
    display: flex !important;
    align-items: center;
    justify-content: center;
    gap: 6px;
    background: #f3f4f6 !important;
    color: #0a0a0a !important;
    border: 1px solid #d4d4d4 !important;
    border-radius: 10px !important;
    padding: 12px 14px !important;
    font-weight: 600;
    font-size: 13px !important;
    box-shadow: 0 1px 2px rgba(0,0,0,0.04);
  }
  .sticky-toolbar .m-alt-input:active {
    background: #e5e7eb !important;
    transform: translateY(1px);
  }
  .sticky-toolbar .m-alt-icon {
    font-size: 18px;
    line-height: 1;
  }
  .sticky-toolbar #toolbar-done {
    flex: 1 1 100% !important;
    margin-left: 0 !important;
    order: 99;
    min-height: 48px;
    font-size: 15px !important;
    font-weight: 600;
    justify-content: center;
    display: flex !important;
    align-items: center;
  }

  /* === Dropzone on mobile — compact so first-screen shows CTA === */
  .dropzone {
    min-height: auto !important;
    padding: 20px 14px !important;
  }
  .dropzone .big {
    font-size: 16px !important;
  }

  /* Modal max-height to avoid covering sticky-toolbar */
  #upload-modal > div,
  #voice-modal > div {
    max-height: calc(100vh - 120px) !important;
  }

  /* === Code blocks scroll horizontally === */
  pre {
    overflow-x: auto;
    font-size: 11px;
  }

  /* === Long URLs break-word === */
  code, a {
    word-break: break-word;
  }
}

/* Very small screens (≤380px) — even more compact */
@media (max-width: 380px) {
  h1 { font-size: 20px !important; }
  .terminal-body { padding: 56px 12px 80px !important; }
  .nav-link { padding: 12px 14px !important; font-size: 14px !important; }
}
