/* SignatureFlow responsive hardening for authenticated web app.
   Targets phone, tablet portrait and tablet landscape while preserving desktop. */

html, body, #app { min-height: 100%; }
#app { height: 100dvh; }
.sf-shell-main, .sf-sidebar, .sf-template-preview-frame, .sf-pdf-area, .sf-cmp-table, table.sf-table {
  -webkit-overflow-scrolling: touch;
}

.sf-template-zoom-controls {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-left: auto;
  padding-left: 10px;
}
.sf-template-zoom-btn,
.sf-template-zoom-value {
  min-width: 32px;
  height: 32px;
  border: 1px solid #ded5e7;
  border-radius: 8px;
  background: #fff;
  color: #4c1d95;
  font: inherit;
  font-size: 13px;
  font-weight: 800;
  cursor: pointer;
  line-height: 1;
}
.sf-template-zoom-value { min-width: 58px; font-size: 11px; }
.sf-template-zoom-btn:hover:not(:disabled),
.sf-template-zoom-value:hover { background: #f7f2ff; border-color: #c4b5fd; }
.sf-template-zoom-btn:disabled { opacity: .42; cursor: default; }
.sf-template-preview-frame {
  overflow: auto !important;
  overscroll-behavior: contain;
  touch-action: pan-x pan-y pinch-zoom;
}
.sf-template-preview-page {
  transform-origin: top center;
  transition: width .16s ease;
}
.sf-template-preview-frame.sf-template-preview-zoomed .sf-template-preview-page {
  margin-left: 0;
  margin-right: 16px;
}

.sf-cmp-methodology {
  margin: 8px 0 0;
  font-size: 10.5px;
  line-height: 1.5;
  color: #8b8093;
}

/* Tablet landscape / smaller laptops */
@media (max-width: 1100px) {
  .sf-shell-main { padding-left: 20px; padding-right: 20px; }
  .sf-template-layout { grid-template-columns: minmax(280px, 330px) minmax(0, 1fr); gap: 16px; }
  .sf-template-preview-frame { height: 72dvh; }
  .sf-home-columns { grid-template-columns: 1fr; }
}

/* Tablet portrait: prioritize one clear column instead of squeezed panes. */
@media (max-width: 960px) {
  .sf-template-layout,
  .sf-editor-grid,
  .sf-status-grid { grid-template-columns: 1fr !important; }
  .sf-template-preview-pane { position: static !important; }
  .sf-template-preview-frame { height: 62dvh; min-height: 430px; }
  .sf-pdf-area { max-height: 68dvh; overflow: auto; }
  .sf-panel { min-width: 0; }
}

@media (max-width: 860px) {
  body { overscroll-behavior-y: none; }
  .sf-appheader {
    padding-left: max(12px, env(safe-area-inset-left));
    padding-right: max(12px, env(safe-area-inset-right));
  }
  .sf-appheader-right { min-width: 0; }
  .sf-shell-main {
    padding: 16px max(14px, env(safe-area-inset-right)) calc(30px + env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left));
  }
  .sf-sidebar {
    width: min(300px, 86vw) !important;
    padding-top: calc(16px + env(safe-area-inset-top));
    padding-bottom: calc(16px + env(safe-area-inset-bottom));
  }
  .sf-btn,
  .sf-sidebar-item,
  .sf-lang-opt,
  .sf-notif-bell { min-height: 42px; }
  .sf-sidebar-item { padding-top: 10px; padding-bottom: 10px; }
  .sf-row-between { align-items: stretch; }
  .sf-row-between > * { min-width: 0; }
  .sf-home-hero { border-radius: 14px; }
  .sf-template-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .sf-template-preview-header { gap: 8px; flex-wrap: wrap; }
  .sf-template-preview-status { order: 3; flex-basis: 100%; }
  .sf-template-zoom-controls { padding-left: 0; }
  table.sf-table { max-width: 100%; overflow-x: auto; }
  .sf-modal { max-width: calc(100vw - 28px); max-height: calc(100dvh - 28px); overflow: auto; }
}

/* Phones */
@media (max-width: 640px) {
  .sf-appheader { padding-top: 8px; padding-bottom: 8px; }
  .sf-appheader-right { gap: 6px; }
  .sf-topbar-brand h1 { font-size: 15px; }
  .sf-topbar-mark { width: 32px; height: 32px; }
  .sf-lang-opt { padding-left: 7px; padding-right: 7px; }
  .sf-notif-panel {
    position: fixed !important;
    top: 58px !important;
    left: 10px !important;
    right: 10px !important;
    width: auto !important;
    max-height: calc(100dvh - 78px) !important;
  }
  .sf-shell-main { padding-top: 12px; }
  .sf-main { padding: 16px 12px 30px; }
  .sf-row-between { gap: 10px; margin-bottom: 14px; }
  .sf-row-between h2 { font-size: 18px; }
  .sf-template-grid { grid-template-columns: 1fr; }
  .sf-template-card { padding: 15px; }
  .sf-template-layout { gap: 14px; }
  .sf-template-preview-frame {
    height: 56dvh;
    min-height: 360px;
    padding: 10px;
  }
  .sf-template-preview-header { padding: 10px 12px; }
  .sf-template-zoom-btn,
  .sf-template-zoom-value { height: 36px; }

  /* Prevent iOS form-focus zoom and make touch input comfortable. */
  input[type="text"], input[type="email"], input[type="number"], input[type="date"], input[type="password"], select, textarea {
    font-size: 16px !important;
    min-height: 44px;
  }
  .sf-btn { min-height: 44px; padding: 10px 14px; }

  /* Comparison becomes readable cards rather than a 560px-wide desktop table. */
  .sf-cmp-table { overflow: visible; }
  .sf-cmp-row {
    min-width: 0 !important;
    display: grid !important;
    grid-template-columns: 1fr 1fr;
    gap: 8px 10px;
    padding: 13px 2px;
  }
  .sf-cmp-label { grid-column: 1 / -1; }
  .sf-cmp-label strong { font-size: 13.5px; }
  .sf-cmp-label span { font-size: 11.5px; }
  .sf-cmp-cell {
    padding: 7px 8px;
    border-radius: 8px;
    background: #faf8fc;
    text-align: center;
  }
  .sf-cmp-head .sf-cmp-label { display: none; }
  .sf-cmp-head .sf-cmp-cell { background: transparent; padding: 0 4px; }
  .sf-cmp-savings {
    display: block !important;
    width: 100%;
    border-radius: 10px !important;
    line-height: 1.45;
  }
  .sf-cmp-price-row {
    flex-direction: column;
    align-items: flex-start;
    gap: 3px !important;
  }
  .sf-cmp-price-row span:last-child { text-align: left !important; }
  .sf-cmp-price-us { margin-left: 0 !important; margin-right: 0 !important; }

  /* Keep wide operational tables usable with touch without clipping actions. */
  table.sf-table { white-space: nowrap; border-radius: 10px; }
  table.sf-table th, table.sf-table td { padding: 11px 12px; }

  .sf-pdf-area {
    max-height: 64dvh;
    padding: 8px !important;
    overflow: auto !important;
    touch-action: pan-x pan-y pinch-zoom;
  }
  .sf-wizard-banner { font-size: 12px; }
  .sf-bulk-bar { flex-wrap: wrap; }
}

/* Very small phones */
@media (max-width: 430px) {
  .sf-topbar-brand h1 { display: none; }
  .sf-appheader-right > .sf-link:not(.sf-user) { font-size: 11px; }
  .sf-lang-opt { min-width: 34px; padding-left: 5px; padding-right: 5px; }
  .sf-shell-main { padding-left: 10px; padding-right: 10px; }
  .sf-panel, .sf-home-panel { padding: 14px; border-radius: 11px; }
  .sf-template-preview-frame { min-height: 320px; height: 52dvh; padding: 8px; }
  .sf-template-zoom-controls { width: 100%; justify-content: flex-end; }
  .sf-template-zoom-btn { min-width: 40px; }
  .sf-template-zoom-value { min-width: 64px; }
  .sf-cmp-row { grid-template-columns: 1fr; }
  .sf-cmp-head { grid-template-columns: 1fr 1fr; }
  .sf-cmp-head .sf-cmp-cell { display: block; }
  .sf-cmp-row:not(.sf-cmp-head) .sf-cmp-cell { width: 100%; }
}

/* Landscape phones: use scarce vertical space efficiently. */
@media (max-height: 520px) and (orientation: landscape) {
  .sf-template-preview-frame { height: 70dvh; min-height: 260px; }
  .sf-pdf-area { max-height: 72dvh; }
  .sf-notif-panel { max-height: calc(100dvh - 66px) !important; }
}

/* Mobile production polish: keep the complete CLM experience accessible on
   phones instead of shrinking desktop layouts or hiding operational actions. */
html, body { max-width: 100%; }
button, a, [role="button"] { touch-action: manipulation; }

@media (max-width: 760px) {
  body, #app { min-height: 100dvh; }
  .sf-shell, .sf-shell-main, #sf-shell-content { min-width: 0; max-width: 100%; }
  .sf-shell-main { overscroll-behavior: contain; }
  .sf-hamburger, .sf-notif-bell, .sf-sidebar-item { min-width: 44px; min-height: 44px; }

  .sf-home-hero.sf-home-hero-actions-only { padding: 15px; border-radius: 16px; }
  .sf-home-hero.sf-home-hero-actions-only .sf-home-hero-actions { gap: 9px; }
  .sf-home-hero.sf-home-hero-actions-only .sf-hero-btn { min-height: 46px; }
  body .sf-dash-kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px; }
  .sf-dash-kpi { min-height: 88px; gap: 9px; padding: 12px 10px; border-radius: 13px; }
  .sf-dash-kpi-icon { width: 36px; height: 36px; border-radius: 11px; }
  .sf-dash-kpi-icon .sf-icon { width: 18px; height: 18px; }
  .sf-dash-kpi-value { margin-bottom: 3px; font-size: 23px; }
  .sf-dash-kpi-label { font-size: 10px; line-height: 1.35; overflow-wrap: anywhere; }
  .sf-dash-kpi-meta { font-size: 9px; line-height: 1.35; }
  .sf-dash-grid { gap: 11px; margin-bottom: 11px; }
  .sf-dash-panel { padding: 15px 13px; border-radius: 14px; }
  .sf-dash-panel-head { gap: 9px; margin-bottom: 14px; }
  .sf-dash-panel-head h3 { font-size: 14px; }
  .sf-dash-bars { height: 184px; grid-template-columns: repeat(6, minmax(0, 1fr)); }
  .sf-dash-bar-track { min-height: 112px; }
  .sf-dash-donut-layout { min-height: 0; gap: 15px; }

  body .sf-admin-overview { gap: 9px; margin: 14px 0; }
  body .sf-admin-overview-card { min-height: 83px; padding: 13px; border-radius: 14px; }
  body .sf-admin-overview-card strong { font-size: 24px; }
  body .sf-admin-overview-card span { font-size: 10px; line-height: 1.4; }
  body .sf-admin-board { border-radius: 14px; }
  body .sf-admin-tabs {
    padding: 8px;
    gap: 3px;
    scroll-snap-type: x proximity;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }
  body .sf-admin-tabs::-webkit-scrollbar { display: none; }
  body .sf-admin-tab { min-height: 42px; padding: 8px 10px; scroll-snap-align: start; }
  body .sf-admin-toolbar { gap: 9px; padding: 12px; }
  body .sf-admin-search { min-height: 44px; width: 100%; }
  body .sf-admin-resource-table-wrap { overscroll-behavior-x: contain; -webkit-overflow-scrolling: touch; }
  body .sf-admin-resource-table th, body .sf-admin-resource-table td { padding: 11px 10px; }
  body .sf-admin-panel-content { padding: 0 12px 13px; }
  body .sf-admin-adjust-modal { max-width: calc(100vw - 24px); padding: 18px 14px; }
  body .sf-admin-resource-controls { grid-template-columns: 40px 52px 40px; }
  body .sf-admin-resource-controls button { min-height: 40px; height: 40px; }
  body .sf-admin-resource-controls input { height: 40px !important; }

  #sf-contracts-page { min-width: 0; }
  #sf-contract-grid { gap: 10px !important; margin-top: 10px !important; }
  #sf-contract-list { max-width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  #sf-contract-list .sf-contract-table { min-width: 620px; }
  .sf-clm-toolbar input, .sf-clm-toolbar select { min-width: 0 !important; width: 100%; }
  body .sf-contract-modal { padding: 10px; align-items: flex-end; }
  body .sf-contract-modal-card {
    width: 100% !important;
    max-height: min(92dvh, calc(100dvh - 20px));
    overflow-y: auto;
    padding: 18px 15px calc(18px + env(safe-area-inset-bottom));
    border-radius: 18px 18px 13px 13px;
    -webkit-overflow-scrolling: touch;
  }
  body .sf-contract-form-grid { grid-template-columns: 1fr !important; gap: 10px; }
  body .sf-contract-row { grid-template-columns: 1fr !important; gap: 8px; }
  body .sf-contract-remove { justify-self: end; min-width: 44px; min-height: 44px; }
}

@media (max-width: 390px) {
  .sf-shell-main { padding-left: 9px; padding-right: 9px; }
  .sf-dash-kpi { gap: 7px; padding: 11px 8px; }
  .sf-dash-kpi-icon { width: 31px; height: 31px; }
  .sf-dash-kpi-value { font-size: 20px; }
  .sf-dash-kpi-label { font-size: 9px; }
  body .sf-admin-overview-card { padding: 11px; }
  body .sf-admin-adjust-row { grid-template-columns: 1fr; }
  body .sf-admin-resource-controls { justify-content: end; }
}

@media (prefers-reduced-motion: reduce) {
  .sf-dash-kpi, .sf-template-preview-page { transition: none; }
}
