/* SealVero Mobile UI, Official Brand Sync & Touch-Friendly Field Placer */

/* Desktop defaults: keep mobile-only controls hidden */
.mobile-nav-left,
.mobile-menu-btn,
.mobile-brand-mark,
.mobile-drawer-close,
.mobile-drawer-search,
.mobile-drawer-cta,
.mobile-nav-backdrop {
  display: none;
}

/* Scroll-safe overlay defaults for Field Placer (works on both desktop & touch) */
.fp-overlay {
  touch-action: pan-x pan-y;
}
.fp-tag {
  touch-action: none;
}
.fp-scroll-btn {
  border-style: dashed;
}

/* Prevent accidental horizontal page bounce on phones */
html, body {
  max-width: 100%;
  overflow-x: clip;
}

@media (max-width: 900px) {
  /* 1. Reclaim 100% viewport width for the workspace */
  #workspace {
    display: block !important;
    grid-template-columns: 1fr !important;
    min-height: 100dvh;
  }

  .app-main {
    width: 100%;
    min-width: 0;
  }

  /* 2. Turn the sidebar into a smooth off-canvas slide-out drawer */
  .sidebar {
    position: fixed !important;
    top: 0;
    left: 0;
    bottom: 0;
    width: min(292px, 84vw) !important;
    height: 100dvh !important;
    padding: 18px 14px 24px !important;
    background: var(--surface) !important;
    border-right: 1px solid var(--line) !important;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.45);
    z-index: 50 !important;
    transform: translateX(-105%);
    transition: transform 0.24s cubic-bezier(0.22, 1, 0.36, 1), visibility 0.24s;
    visibility: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  body.mobile-nav-open {
    overflow: hidden;
  }

  body.mobile-nav-open .sidebar {
    transform: translateX(0);
    visibility: visible;
  }

  /* Override the legacy max-width:800px rules that hid icons & labels */
  .sidebar-brand {
    padding: 2px 6px 16px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: space-between !important;
    gap: 10px;
  }
  .sidebar-brand .logo {
    font-size: 22px !important;
  }
  .sidebar-brand .logo span.word,
  .sidebar-brand .logo span.dot {
    display: inline !important;
  }
  .sidebar-brand .logo-mark {
    width: 30px !important;
  }

  .mobile-drawer-close {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 10px;
    border: 1px solid var(--line);
    background: var(--surface2);
    color: var(--ink);
    cursor: pointer;
    flex-shrink: 0;
  }

  .mobile-drawer-search {
    display: flex !important;
    align-items: center;
    gap: 8px;
    margin: 0 2px 12px;
    padding: 9px 12px;
    border-radius: 10px;
    border: 1px solid var(--line);
    background: var(--surface2);
    color: var(--muted);
  }
  .mobile-drawer-search input {
    width: 100%;
    border: 0;
    background: transparent;
    color: var(--ink);
    font-size: 13px;
    outline: none;
  }
  .mobile-drawer-search svg {
    width: 15px;
    height: 15px;
    flex-shrink: 0;
  }

  .mobile-drawer-cta {
    display: flex !important;
    width: 100%;
    justify-content: center;
    margin: 0 0 14px;
    padding: 11px 14px;
  }

  .sidebar .navitem {
    justify-content: flex-start !important;
    padding: 12px 13px !important;
    min-height: 44px;
  }
  .sidebar .navitem span {
    display: inline-flex !important;
    align-items: center;
  }
  .sidebar .navcount {
    display: inline-flex !important;
    margin-left: auto !important;
  }
  .sidebar .side-label {
    display: block !important;
  }
  .sidebar .teamcard {
    display: block !important;
  }

  /* Dimmed backdrop behind open drawer */
  .mobile-nav-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(5, 10, 20, 0.58);
    backdrop-filter: blur(3px);
    -webkit-backdrop-filter: blur(3px);
    z-index: 45;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.22s ease;
  }
  body.mobile-nav-open .mobile-nav-backdrop {
    opacity: 1;
    pointer-events: auto;
  }

  /* 3. Clean, balanced mobile top bar with official SealVero logo */
  .topbar {
    height: 62px !important;
    padding: 0 14px !important;
    justify-content: space-between !important;
    gap: 10px !important;
  }

  .mobile-nav-left {
    display: flex !important;
    align-items: center;
    gap: 10px;
    min-width: 0;
  }

  .mobile-menu-btn {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: 11px;
    border: 1px solid var(--line);
    background: var(--surface);
    color: var(--ink);
    cursor: pointer;
    flex-shrink: 0;
    transition: background 0.15s, border-color 0.15s;
  }
  .mobile-menu-btn:active {
    transform: scale(0.96);
  }
  .mobile-menu-btn svg {
    width: 20px;
    height: 20px;
  }

  .mobile-brand-mark {
    display: inline-flex !important;
    align-items: center;
    gap: 7px;
    text-decoration: none;
    font-size: 20px !important;
    white-space: nowrap;
  }
  .mobile-brand-mark .logo-mark {
    width: 28px !important;
    height: 26px !important;
    flex-shrink: 0;
  }
  .mobile-brand-mark span.word,
  .mobile-brand-mark span.dot {
    display: inline !important;
  }

  .topbar .searchbox,
  .topbar .top-pill {
    display: none !important;
  }

  .top-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-left: auto;
    flex-shrink: 0;
  }

  .top-user .name {
    display: none !important;
  }

  /* 4. Spacious, balanced content layout */
  .content {
    padding: 16px 12px 72px !important;
  }

  .content .page-head,
  .content .view-head,
  .content .section-bar {
    flex-direction: column;
    align-items: stretch !important;
    gap: 14px;
  }

  .content .head-actions,
  .content .hero-actions,
  .content .btn-row {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
    width: 100%;
  }
  .content .head-actions .btn,
  .content .hero-actions .btn {
    width: 100%;
    justify-content: center;
    padding: 11px 12px;
    min-height: 44px;
  }

  /* KPI cards */
  .kpis {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 11px !important;
  }
  .kpi {
    padding: 16px 14px !important;
    min-height: 118px !important;
  }
  .kpi strong {
    font-size: 26px !important;
  }

  /* Panels, cards & tables */
  .panels,
  .panels.even,
  .template-grid,
  .integration-grid,
  .ai-results,
  .signer-review-grid {
    grid-template-columns: 1fr !important;
    gap: 14px !important;
  }

  .table-wrap {
    margin: 0 -4px;
    padding: 0 4px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .document-row {
    grid-template-columns: minmax(0, 1fr) auto !important;
    gap: 10px !important;
    padding: 14px 2px !important;
  }
  .document-row > div:nth-child(2),
  .document-row > div:nth-child(3),
  .document-row > div:nth-child(4) {
    display: none;
  }

  /* Modals fit cleanly within phone viewport */
  .overlay {
    padding: 12px !important;
    align-items: flex-end;
  }
  .dialog {
    width: 100% !important;
    max-width: 540px !important;
    max-height: 90dvh;
    overflow-y: auto;
    padding: 20px 16px !important;
    border-radius: 18px !important;
    margin: auto 0;
  }
  .form-grid {
    grid-template-columns: 1fr !important;
    gap: 12px !important;
  }
  .dialog-actions {
    flex-direction: column-reverse;
    gap: 8px;
  }
  .dialog-actions .btn {
    width: 100%;
    justify-content: center;
    min-height: 44px;
  }

  /* Field Placer mobile ergonomics */
  .fp-shell {
    border-radius: 14px;
  }
  .fp-head {
    flex-direction: column;
    align-items: stretch !important;
    gap: 10px !important;
    padding: 12px !important;
  }
  .fp-head-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
  }
  .fp-head-actions .btn {
    flex: 1 1 auto;
    justify-content: center;
  }
  .fp-toolbar {
    padding: 10px !important;
    gap: 10px !important;
  }
  .fp-stage {
    padding: 12px 6px 68px !important;
    align-items: center !important;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
  }
  .fp-page-wrap {
    max-width: 100%;
    height: auto !important;
  }
  .fp-pdf-canvas {
    width: 100% !important;
    max-width: 100%;
    height: auto !important;
  }
  .fp-overlay {
    z-index: 5;
    touch-action: manipulation;
  }
  .fp-tag-del {
    width: 24px !important;
    height: 24px !important;
    font-size: 14px !important;
    top: -10px !important;
    right: -10px !important;
  }
  .fp-tag-resize {
    width: 18px !important;
    height: 18px !important;
  }

  /* Fill & Sign toolbar on phones */
  .fs-toolbar {
    overflow-x: auto !important;
    flex-wrap: nowrap !important;
    -webkit-overflow-scrolling: touch;
  }
  .fs-stage {
    padding: 12px 6px 64px !important;
  }

  /* External signer screen polish */
  .signer-nav {
    padding: 14px 16px !important;
    gap: 10px;
  }
  .signer-main {
    margin: 18px auto !important;
    padding: 0 12px 56px !important;
  }
  .signer-steps {
    margin: 16px auto 18px !important;
  }
  .signer-card {
    padding: 18px 15px !important;
    border-radius: 16px !important;
  }
  .signer-card h1 {
    font-size: 22px !important;
  }
  .pdf-frame {
    height: 420px !important;
  }
  .signer-controls .btn {
    flex: 1 1 auto;
    justify-content: center;
    min-height: 42px;
  }

  .toast {
    left: 12px !important;
    right: 12px !important;
    bottom: 14px !important;
    max-width: none !important;
    text-align: center;
  }
}

@media (max-width: 600px) {
  #topNewBtn {
    display: none !important;
  }

  .land-nav {
    padding: 14px 16px !important;
    gap: 8px;
  }
  #landNavCta {
    padding: 8px 12px;
    font-size: 12px;
  }
  .hero {
    padding: 28px 16px 34px !important;
    gap: 28px !important;
  }
  .hero h1 {
    font-size: 40px !important;
    line-height: 1.06 !important;
  }
  .preview-body {
    grid-template-columns: 1fr !important;
  }
  .preview-side {
    display: none !important;
  }
  .preview-sub {
    grid-template-columns: 1fr !important;
  }
}
