/* SHINHA Form Tools — Responsive */
@media (max-width: 1024px) {
  .tool-layout {
    grid-template-columns: 360px 1fr;
  }
}

/* ── Tool mobile UX (<=767px) — Stage 1.7 Mobile First ── */
@media (max-width: 767px) {
  /* Hide desktop / legacy mobile UI */
  .mobile-tab-bar,
  .mobile-sticky-bar,
  .beta-banner,
  .tool-toolbar,
  .tool-sidebar,
  .form-panel__header,
  .form-panel__hint,
  .preview-edit-hint,
  .zoom-bar,
  .customize-launcher,
  .export-panel,
  .preview-mobile-actions,
  .appearance-drawer {
    display: none !important;
  }

  body.page-tool .form-actions {
    display: none !important;
  }

  .app-header__subtitle {
    display: none;
  }

  /* Mobile action bar */
  .mobile-tool-actions {
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 56px;
    z-index: 50;
    background: #fff;
    border-bottom: 1px solid #dde1e8;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
  }

  .mobile-tool-actions__row {
    display: flex;
    width: 100%;
  }

  .mobile-tool-actions__row--export {
    border-top: 1px solid #eef0f4;
  }

  .mobile-tool-actions__btn {
    flex: 1;
    min-height: 44px;
    padding: 10px 12px;
    border: none;
    border-right: 1px solid #eef0f4;
    background: #fff;
    font-family: inherit;
    font-size: 14px;
    font-weight: 600;
    color: #1a4b8c;
    cursor: pointer;
    transition: background 0.15s;
  }

  .mobile-tool-actions__btn:last-child {
    border-right: none;
  }

  .mobile-tool-actions__btn:active {
    background: #f0f6ff;
  }

  .mobile-tool-actions__btn--accent {
    color: #1a4b8c;
    background: #f0f6ff;
  }

  .mobile-tool-actions__btn--export {
    font-size: 13px;
    background: #f8f9fb;
  }

  .mobile-tool-actions__btn--export:first-child {
    color: #fff;
    background: #1a4b8c;
  }

  .mobile-tool-actions__btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
  }

  .mobile-export-footer {
    display: none !important;
  }

  /* Preview-first scroll layout */
  html,
  body.page-tool {
    overflow-x: hidden;
    overflow-y: auto;
  }

  /* Sheet open: must beat body.page-tool overflow-y:auto or document scrolls
     under the sheet and sticky footers jump mid-viewport (Safari). */
  body.page-tool.is-tool-sheet-open {
    overflow: hidden !important;
  }

  .tool-layout {
    display: block;
    height: auto;
    min-height: auto;
    overflow: visible;
  }

  /*
    IMPORTANT:
    Mobile must not reflow template preview internals.
    Preview templates are design canvases and should only be scaled as a whole.
    Do not add media queries on .core-preview__grid / __row / __value here.
  */

  .preview-area {
    display: flex !important;
    flex-direction: column;
    height: auto;
    min-height: 0;
    max-height: none;
    overflow: visible;
    background: #fff;
  }

  .preview-viewport {
    flex: none;
    /* Block layout so zoomed content can scroll to full left/right edges */
    display: block;
    position: relative;
    height: auto;
    min-height: 0;
    /* Allow pan when pinch-zoomed; height capped by zoom-preview.js */
    overflow: auto;
    padding: 12px 12px 16px;
    margin-bottom: 0;
    background: #c8cdd6;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-x pan-y;
  }

  .preview-viewport.is-pinch-zooming {
    touch-action: none;
  }

  .preview-canvas {
    display: block;
    position: relative;
    margin: 0 auto;
    overflow: hidden;
    flex-shrink: 0;
    transform: none;
  }

  .btn-remember-data__short {
    display: none;
  }

  .tool-sheet__footer .btn-remember-data {
    font-size: 13px;
    line-height: 1.3;
    white-space: normal;
    text-align: center;
  }

  .tool-sheet__footer .btn-remember-data .btn-remember-data__short {
    display: inline;
  }

  .tool-sheet__footer .btn-remember-data .btn-remember-data__full {
    display: none;
  }

  /*
   * #data-sheet (Nạp dữ liệu) — mobile footer at visible bottom.
   * Evidence (live computed on 390×844): footer is OUTSIDE #data-sheet-form-mount;
   * scrollport must be .tool-sheet__body only. Mid-float / large gap below footer on
   * iPhone Safari comes from:
   * (A) .tool-sheet__footer { position:sticky; bottom:0 } (color-tools.css) when
   *     panel/document is the scrollport (nested #form-panel-content scroll, or
   *     body.page-tool overflow-y:auto under the sheet);
   * (B) height:92dvh sized to a layout viewport taller than the *visible* Safari
   *     area → empty region below the footer in the visual viewport.
   * Fix: kill sticky on this sheet; size sheet to svh; panel = 92% of that sheet;
   * body min-height:0 + sole overflow-y:auto; neutralize mounted form scroll.
   */
  #data-sheet.tool-sheet {
    height: 100vh;
    max-height: 100vh;
    height: 100dvh;
    max-height: 100dvh;
    height: 100svh;
    max-height: 100svh;
  }

  #data-sheet .tool-sheet__panel {
    height: 92%;
    max-height: 92%;
    overflow: hidden;
  }

  #data-sheet .tool-sheet__header {
    position: relative !important;
    top: auto !important;
  }

  #data-sheet .tool-sheet__header,
  #data-sheet .tool-sheet__quick,
  #data-sheet .tool-sheet__section-label {
    flex: 0 0 auto;
  }

  #data-sheet .tool-sheet__body {
    flex: 1 1 auto;
    min-height: 0;
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 20px;
  }

  /* Mounted desktop form host must not create a second scrollport */
  #data-sheet .tool-sheet__body > .form-panel__content,
  #data-sheet .tool-sheet__body > #form-panel-content {
    flex: none !important;
    overflow: visible !important;
    height: auto !important;
    max-height: none !important;
    min-height: 0 !important;
  }

  #data-sheet .tool-sheet__footer {
    position: relative !important;
    top: auto !important;
    bottom: auto !important;
    inset: auto !important;
    flex: 0 0 auto;
    margin-top: auto;
    background: #fff;
    border-top: 1px solid #eef0f4;
    padding-top: 12px;
    padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
    z-index: 3;
  }

  /* Contact widget: icon only, hide when sheet open */
  body.page-tool .contact-widget__toggle-text--desktop,
  body.page-tool .contact-widget__toggle-text--mobile {
    display: none !important;
  }

  body.page-tool .contact-widget__toggle {
    width: 48px;
    height: 48px;
    min-width: 48px;
    border-radius: 50%;
    padding: 0;
    justify-content: center;
  }

  body.page-tool .contact-widget {
    bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  }

  body.page-tool.is-tool-sheet-open .contact-widget {
    display: none !important;
  }

  .theme-tools__grid {
    grid-template-columns: 1fr;
  }

  body.page-tool .shinha-toast {
    bottom: calc(24px + env(safe-area-inset-bottom, 0px));
  }

  body.page-tool .form-input,
  body.page-tool select.form-input {
    min-height: 44px;
    font-size: 15px;
  }

  /* Export clone: full design layout, no mobile scale/transform */
  body.export-mode .export-clone-host,
  .export-clone-host[data-export-mode="true"] {
    position: fixed !important;
    left: -99999px !important;
    top: 0 !important;
    z-index: -1 !important;
    pointer-events: none !important;
    overflow: visible !important;
    transform: none !important;
    width: auto !important;
    height: auto !important;
  }

  body.export-mode .export-clone-host .core-preview,
  .export-clone-host[data-export-mode="true"] .core-preview {
    width: 210mm !important;
    max-width: none !important;
    min-width: 0 !important;
    transform: none !important;
    zoom: 1 !important;
    font-size: 13px !important;
    padding: 16mm 14mm !important;
  }

  body.export-mode .export-clone-host .core-preview__grid,
  .export-clone-host[data-export-mode="true"] .core-preview__grid {
    grid-template-columns: 1fr 1fr !important;
  }

  body.export-mode .export-clone-host .core-preview__header,
  .export-clone-host[data-export-mode="true"] .core-preview__header {
    padding-right: 110px !important;
  }

  body.export-mode .export-clone-host .core-preview__logo,
  .export-clone-host[data-export-mode="true"] .core-preview__logo {
    position: absolute !important;
    top: 12mm !important;
    right: 14mm !important;
    width: 100px !important;
    height: 70px !important;
    margin-bottom: 0 !important;
  }
}

@media (max-width: 768px) {
  .page-index .hero h1 {
    font-size: 24px;
  }

  .page-index .hero {
    padding: 32px 16px;
  }

  .template-grid {
    grid-template-columns: 1fr;
  }

  .form-actions {
    position: relative;
  }
}

@media (max-width: 480px) {
  .btn {
    padding: 7px 12px;
    font-size: 13px;
  }

  .form-panel__content {
    padding: 10px 12px 20px;
  }

  .beta-banner {
    font-size: 12px;
    padding: 8px 12px;
  }
}

/* Safe area for notched phones */
@supports (padding: env(safe-area-inset-bottom)) {
  .form-actions {
    padding-bottom: calc(8px + env(safe-area-inset-bottom));
  }

  .shinha-toast {
    bottom: calc(24px + env(safe-area-inset-bottom));
  }
}

/* ── Home page responsive ── */
@media (max-width: 1199px) {
  .template-gallery__grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 24px 28px;
  }

  .hero-visual {
    min-height: 360px;
  }

  .hero-mascot {
    max-width: min(340px, 80%);
  }

  .hero-deco__panel--1 { width: 180px; height: 130px; }
  .hero-deco__panel--2 { width: 160px; height: 120px; }
}

@media (max-width: 991px) {
  .home-header__nav {
    display: none;
    position: absolute;
    top: 72px;
    left: 0;
    right: 0;
    flex-direction: column;
    background: rgba(255, 255, 255, 0.98);
    padding: 16px 24px 20px;
    border-bottom: 1px solid var(--shinha-border, #D8E4F5);
    gap: 14px;
    box-shadow: 0 12px 28px rgba(6, 26, 64, 0.1);
  }

  .home-header__nav.is-open {
    display: flex;
  }

  .home-nav-dropdown {
    width: 100%;
  }

  .home-nav-dropdown__menu {
    position: static;
    min-width: 0;
    margin-top: 6px;
    padding: 0 0 0 12px;
    border: none;
    border-radius: 0;
    box-shadow: none;
    background: transparent;
  }

  .home-nav-dropdown__menu a {
    padding: 8px 0;
    white-space: normal;
  }

  .home-header__menu-btn {
    display: flex;
  }

  .home-header__actions .home-btn--outline {
    display: none;
  }

  .hero-section__grid {
    grid-template-columns: 1fr;
    gap: 32px;
  }

  .hero-visual {
    order: 2;
    min-height: 340px;
  }

  .template-gallery__grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 20px 24px;
  }

  .custom-design-section__inner {
    flex-direction: column;
    text-align: center;
    padding: 32px 28px;
  }

  .custom-design-section__list {
    grid-template-columns: 1fr;
    text-align: left;
  }

  .home-footer__grid {
    grid-template-columns: 1fr 1fr;
    gap: 24px;
  }
}

@media (max-width: 767px) {
  .home-container {
    padding: 0 14px;
  }

  .hero-section .home-container {
    padding: 0 14px;
  }

  .hero-section {
    padding: 28px 0 24px;
  }

  .hero-section__cta {
    flex-direction: column;
  }

  .hero-section__cta .home-btn {
    width: 100%;
  }

  .hero-features {
    grid-template-columns: 1fr;
  }

  .hero-mascot {
    max-width: min(300px, 85%);
  }

  .hero-deco__panel--1,
  .hero-deco__badge {
    display: none;
  }

  .hero-float-card--2,
  .hero-float-card--4,
  .hero-float-card--5 {
    display: none;
  }

  .hero-float-card--1 {
    left: 0;
    top: 4%;
  }

  .hero-float-card--3 {
    right: 0;
    top: 8%;
  }

  .hero-deco__panel--2 {
    display: none;
  }

  .template-gallery__grid {
    grid-template-columns: minmax(0, 1fr);
    gap: 20px;
    width: 100%;
    max-width: 100%;
  }

  .template-gallery {
    padding: 36px 0 40px;
  }

  .home-footer__grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 420px) {
  .home-container {
    padding: 0 16px;
  }

  .site-brand__logo {
    height: 56px;
    max-height: 56px;
    width: auto;
    object-fit: contain;
  }

  .site-brand__name {
    font-size: 18px;
  }

  .hero-mascot {
    max-width: min(260px, 90%);
  }

  .hero-deco {
    display: none;
  }

  .hero-float-card {
    display: none;
  }

  .template-card__actions {
    flex-direction: column;
  }

  .template-card__actions .home-btn {
    width: 100%;
  }
}
