/* ieccalc.com — universal mobile overrides
   Applies to all calculators (001-004) and v2 pages (account, admin, content).
   Layered AFTER each page's inline <style>, so it can override safely. */

/* ── Universal: prevent horizontal scroll, set base font, smooth scroll ── */
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body { overflow-x: hidden; }
img, svg, video, canvas, iframe { max-width: 100%; height: auto; }

/* ── Tablet & smaller (≤ 1024px): tighter padding ── */
@media (max-width: 1024px) {
  .container { padding-left: 14px !important; padding-right: 14px !important; }
}

/* ── Tablet (≤ 768px): single-column layout ── */
@media (max-width: 768px) {
  body { font-size: 14.5px; line-height: 1.5; }

  /* Heading scale */
  h1 { font-size: 22px !important; line-height: 1.25; }
  h2 { font-size: 17px !important; }
  h3 { font-size: 15px !important; }

  /* Header strip stacks: author block under title, full width */
  .header-top, .header-row, [class*="header-top"] { flex-direction: column !important; gap: 10px !important; }
  .header-right, [class*="header-right"] { text-align: left !important; }
  .author-links { justify-content: flex-start !important; }

  /* Stack 2/3/4-column grids defined inline as `grid-template-columns: 1fr 1fr` */
  [style*="grid-template-columns: 1fr 1fr"],
  [style*="grid-template-columns:1fr 1fr"],
  [style*="grid-template-columns: 1fr 1fr 1fr"],
  [style*="grid-template-columns:1fr 1fr 1fr"],
  [style*="grid-template-columns: 1fr 1fr 1fr 1fr"],
  [style*="grid-template-columns:1fr 1fr 1fr 1fr"] {
    grid-template-columns: 1fr !important;
  }

  /* Scrollable wide tables */
  table { font-size: 12.5px; }
  .table-wrap, .scroll-table {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border: 1px solid var(--line, #8a8f94);
    border-radius: 3px;
    margin: 8px 0;
  }

  /* Pre / code blocks wrap and shrink */
  pre, code { white-space: pre-wrap; word-break: break-word; font-size: 11.5px; }

  /* Touch-friendly form controls */
  input[type="text"], input[type="number"], input[type="email"], input[type="search"],
  input[type="tel"], input[type="url"], input[type="password"], select, textarea {
    min-height: 38px;
    font-size: 16px; /* prevents iOS zoom on focus */
    padding: 7px 10px;
  }
  button, .btn, .button, input[type="submit"], input[type="button"] {
    min-height: 38px;
    padding: 9px 14px;
    font-size: 13.5px;
  }

  /* Toolbar / button groups wrap */
  .toolbar, .btn-row, .btn-group, [class*="toolbar"], [class*="btn-group"] {
    flex-wrap: wrap !important;
    gap: 6px !important;
  }
  .toolbar button { height: auto !important; min-height: 36px; }

  /* Tabs: horizontal scroll instead of wrap-mess */
  .tabs, [role="tablist"] {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    flex-wrap: nowrap !important;
    scrollbar-width: thin;
  }
  .tab, [role="tab"] {
    flex-shrink: 0 !important;
    white-space: nowrap;
    padding: 10px 14px !important;
  }

  /* Ad-row collapses */
  .ad-row { grid-template-columns: 1fr !important; }
}

/* ── Phone (≤ 480px): compact ── */
@media (max-width: 480px) {
  body { font-size: 14px; }
  h1 { font-size: 20px !important; }
  .container { padding: 12px 10px 40px !important; }
  .chip { font-size: 10px; padding: 2px 6px; }
  .author-name { font-size: 13px; }
  .author-email { font-size: 12px; }
  .author-wa-hint { font-size: 11px; }
}

/* ── Canvas-heavy editors (Trench CAD in #004, sketch in #003) ──
   On phones, stack form + canvas vertically, show advisory. */
@media (max-width: 768px) {
  /* Trench CAD body has flex row (left form | canvas | right form) — stack on mobile */
  .tc-body, .tc-canvas-wrap, .tc-bar {
    flex-direction: column !important;
  }
  .tc-side, .tc-side-r, .tc-canvas-col {
    width: 100% !important;
    min-width: 0 !important;
    flex: none !important;
  }
  .tc-canvas-col {
    min-height: 360px;
    order: 99; /* canvas at the bottom — least useful on mobile */
  }
  /* Stack tc-grid2/3 mini-grids more aggressively */
  .tc-grid3 { grid-template-columns: 1fr 1fr 1fr !important; }
  .tc-grid2 { grid-template-columns: 1fr 1fr !important; }
}

@media (max-width: 600px) {
  canvas { display: block; max-width: 100%; height: auto; }
  /* Show advisory above any canvas-based editor container */
  #trenchCAD::before,
  .tc-canvas-wrap::before,
  #sketchEditor::before,
  .canvas-editor::before {
    content: "📱 The sketch / Trench CAD editor works best on a tablet or desktop (≥ 768px). On phone you can still review the layout but precise drawing is limited.";
    display: block;
    background: #fff8e1;
    border: 1px solid #f1c40f;
    color: #5d4d00;
    padding: 9px 11px;
    margin-bottom: 10px;
    font-size: 12px;
    line-height: 1.4;
    border-radius: 3px;
  }
  /* Allow horizontal scroll inside canvas col for wide canvases */
  .tc-canvas-col { overflow-x: auto; -webkit-overflow-scrolling: touch; }
}

/* ── v2 admin SPA: collapsible sidebar on narrow ── */
@media (max-width: 780px) {
  /* Drop the grid so nav doesn't get stretched to fill min-height */
  .layout {
    display: block !important;
    min-height: 0 !important;
  }
  nav.side {
    display: flex !important;
    flex-direction: row !important;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding: 0 !important;
    height: auto !important;
    border-bottom: 1px solid #000;
  }
  nav.side a {
    flex-shrink: 0;
    border-left: 0 !important;
    border-bottom: 3px solid transparent;
    padding: 11px 14px !important;
  }
  nav.side a.active {
    border-left: 0 !important;
    border-bottom-color: #fff;
  }
  main {
    min-height: 60vh;
  }
}

/* ── Disclaimer / footer: full-width on mobile ── */
@media (max-width: 768px) {
  footer { font-size: 12px; }
  footer .disclaimer { padding: 10px 12px; line-height: 1.45; }
}
