/* RateGuard Pro mobile adapter.
   Mobile-only layer for portal.html. Desktop remains governed by the base portal CSS. */

.rgp-mobile-bottom-nav,
.mb-mobile-cards,
.rgp-pull-refresh {
  display: none;
}

@media (max-width: 760px) {
  html,
  body {
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
  }

  body {
    padding-top: env(safe-area-inset-top, 0px);
    padding-bottom: calc(68px + env(safe-area-inset-bottom, 0px));
    background: #f9fafb;
    overscroll-behavior-y: contain;
  }

  .app-container {
    width: 100%;
    max-width: 100%;
    padding: 10px 10px calc(84px + env(safe-area-inset-bottom, 0px));
  }

  .top-nav {
    position: sticky !important;
    top: 0 !important;
    z-index: 950 !important;
    margin: -10px -10px 12px !important;
    padding: 10px 10px !important;
    border-radius: 0 0 14px 14px !important;
    gap: 8px !important;
    align-items: center !important;
    flex-wrap: nowrap !important;
  }

  .logo {
    gap: 9px;
    min-width: 0;
  }

  .logo-mark {
    transform: scale(0.9);
    transform-origin: left center;
  }

  .logo-text {
    font-size: 15px;
  }

  .logo-sub {
    display: none;
  }

  .nav-tabs {
    display: none !important;
  }

  .nav-right {
    margin-left: auto !important;
    gap: 6px !important;
    min-width: 0;
  }

  #celebDemoToggle,
  .btn-refresh {
    display: none !important;
  }

  .nav-user {
    max-width: 168px;
    min-height: 36px;
    padding: 7px 10px;
    gap: 7px;
    font-size: 12px;
  }

  #headerBrokerName {
    display: inline-block;
    max-width: 96px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    vertical-align: bottom;
  }

  .rgp-install-banner.is-shown {
    align-items: flex-start;
    gap: 10px;
    padding: 10px 12px;
  }

  .rgp-install-banner-cta {
    min-height: 36px;
  }

  .rgp-mobile-bottom-nav {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1200;
    display: none;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 2px;
    padding: 5px 8px calc(5px + env(safe-area-inset-bottom, 0px));
    background: rgba(255, 255, 255, 0.97);
    border-top: 1px solid #e5e7eb;
    box-shadow: 0 -10px 30px rgba(15, 23, 42, 0.12);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
  }

  body.rgp-mobile-nav-ready .rgp-mobile-bottom-nav {
    display: grid;
  }

  .rgp-pull-refresh {
    position: fixed;
    top: calc(8px + env(safe-area-inset-top, 0px));
    left: 50%;
    z-index: 1300;
    display: flex;
    align-items: center;
    gap: 8px;
    min-height: 38px;
    padding: 8px 13px;
    border: 1px solid #e5e7eb;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.97);
    color: #64748b;
    font-size: 12px;
    font-weight: 750;
    box-shadow: 0 10px 28px rgba(15, 23, 42, 0.13);
    opacity: 0;
    pointer-events: none;
    transform: translate(-50%, -56px);
    transition: opacity 0.16s ease, transform 0.16s ease, color 0.16s ease;
    white-space: nowrap;
  }

  .rgp-pull-refresh.visible,
  .rgp-pull-refresh.refreshing {
    opacity: 1;
  }

  .rgp-pull-refresh.ready {
    color: #b45309;
  }

  .rgp-pull-refresh.refreshing {
    color: #047857;
  }

  .rgp-pull-refresh-icon {
    width: 16px;
    height: 16px;
    border: 2px solid #cbd5e1;
    border-top-color: #d97706;
    border-radius: 50%;
    transition: transform 0.16s ease, border-top-color 0.16s ease;
  }

  .rgp-pull-refresh.ready .rgp-pull-refresh-icon {
    border-top-color: #b45309;
    transform: rotate(180deg);
  }

  .rgp-pull-refresh.refreshing .rgp-pull-refresh-icon {
    border-top-color: #059669;
    animation: rgpPullSpin 0.8s linear infinite;
  }

  @keyframes rgpPullSpin {
    to { transform: rotate(360deg); }
  }

  .rgp-mobile-nav-btn {
    min-width: 0;
    min-height: 48px;
    border: 0;
    border-radius: 12px;
    background: transparent;
    color: #6b7280;
    font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    font-size: 10.5px;
    font-weight: 750;
    line-height: 1.1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    cursor: pointer;
  }

  .rgp-mobile-nav-btn svg {
    width: 19px;
    height: 19px;
    stroke-width: 2;
  }

  .rgp-mobile-nav-btn.active {
    background: linear-gradient(135deg, #fffbeb, #fef3c7);
    color: #b45309;
  }

  .page-header,
  .mb-page-header {
    margin-bottom: 14px;
  }

  .page-header h1,
  .mb-page-title {
    font-size: 22px !important;
    letter-spacing: -0.02em;
  }

  .smart-briefing,
  .sidebar-section,
  .mb-section,
  .mb-snapshot-card,
  .mb-draw-card,
  .mb-email-banner,
  .mb-add-mortgage-card {
    border-radius: 14px;
  }

  .main-layout {
    display: flex !important;
    flex-direction: column;
    gap: 12px;
  }

  .sidebar {
    gap: 12px;
  }

  .sidebar-section {
    padding: 14px;
  }

  .smart-briefing {
    padding: 14px;
  }

  .smart-briefing-header {
    align-items: flex-start;
    gap: 10px;
  }

  .smart-briefing-greeting {
    font-size: 13px;
    line-height: 1.35;
  }

  .smart-briefing-cards {
    grid-template-columns: 1fr !important;
  }

  .controls,
  .v2-sticky-controls {
    gap: 10px !important;
  }

  .v2-sticky-controls {
    top: 0 !important;
    margin: 0 -10px 12px;
    padding: 10px;
    border-bottom-color: #e5e7eb;
  }

  .controls {
    flex-direction: column;
    align-items: stretch;
  }

  .search-box {
    min-width: 0;
    width: 100%;
  }

  .search-box input {
    min-height: 46px;
    font-size: 16px;
    border-radius: 12px;
  }

  .filter-group,
  .v2-filter-group,
  .rate-picker-buttons,
  .status-tabs,
  .mb-tabs,
  .cc-tabs-container {
    width: 100%;
    overflow-x: auto;
    flex-wrap: nowrap !important;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }

  .filter-group::-webkit-scrollbar,
  .v2-filter-group::-webkit-scrollbar,
  .rate-picker-buttons::-webkit-scrollbar,
  .status-tabs::-webkit-scrollbar,
  .mb-tabs::-webkit-scrollbar,
  .cc-tabs-container::-webkit-scrollbar {
    display: none;
  }

  .filter-btn,
  .v2-filter-btn,
  .status-tab,
  .mb-tab,
  .cc-tab {
    flex: 0 0 auto;
    min-height: 40px;
  }

  .sort-select {
    width: 100%;
    min-height: 44px;
    font-size: 16px;
  }

  .rate-explorer,
  .rate-picker,
  .rate-explorer-collapsed {
    padding: 12px;
    border-radius: 14px;
  }

  .rate-explorer-body,
  .rate-picker {
    flex-direction: column;
    align-items: stretch;
  }

  .rate-explorer-pills,
  .rate-explorer-impact {
    overflow-x: auto;
    flex-wrap: nowrap;
  }

  .cards {
    gap: 12px;
  }

  .opp-card,
  .opp-card.gmm-notice-live {
    display: grid !important;
    grid-template-columns: 1fr !important;
    align-items: stretch;
    gap: 12px;
    min-height: 0;
    padding: 14px 14px 42px 16px;
    border-radius: 16px;
  }

  .opp-card:hover {
    transform: none;
  }

  .opp-left,
  .opp-stats,
  .opp-hero,
  .gmm-notice-col,
  .amort-est-bar,
  .escalation-strip,
  .opp-expanded {
    grid-column: 1 / -1 !important;
    min-width: 0;
    width: 100%;
    max-width: 100%;
  }

  .opp-left {
    gap: 8px;
  }

  .opp-client {
    font-size: 16px;
    line-height: 1.25;
  }

  .opp-client .sub,
  .opp-lender {
    font-size: 13px;
  }

  .opp-lender {
    align-items: flex-start;
    gap: 6px;
  }

  .opp-lender > span {
    max-width: 100%;
  }

  .opp-lender > span[style*="margin"] {
    width: 100%;
    margin: -2px 0 !important;
    color: #94a3b8;
  }

  .pill-row {
    gap: 5px;
    max-width: 100%;
  }

  .pill {
    font-size: 10px;
    padding: 3px 7px;
    max-width: 100%;
    white-space: normal;
    line-height: 1.25;
  }

  .pill-gmm {
    max-width: 170px;
  }

  .gmm-notice-col {
    align-items: stretch;
    padding: 10px 12px;
    border: 1px solid #bfdbfe;
    border-radius: 12px;
    background: #eff6ff;
    text-align: left;
  }

  .gmm-notice-text {
    font-size: 12px;
    line-height: 1.45;
  }

  .gmm-notice-sep {
    display: block;
    height: 5px;
    color: transparent;
    margin: 0;
  }

  .gmm-notice-dismiss {
    align-self: flex-start;
    min-height: 34px;
  }

  .escalation-strip {
    align-items: flex-start;
    flex-wrap: wrap;
    padding: 10px 12px;
  }

  .escalation-strip .esc-text {
    flex: 1 1 100%;
    min-width: 0;
  }

  .escalation-strip .got-it-btn {
    min-height: 34px;
  }

  .opp-hero {
    display: grid;
    grid-template-columns: 1fr auto;
    column-gap: 10px;
    row-gap: 2px;
    text-align: left;
    min-width: 0;
    padding: 12px;
  }

  .hero-label-sm,
  .hero-sub {
    grid-column: 1 / 2;
  }

  .hero-value-lg {
    grid-column: 2 / 3;
    grid-row: 1 / span 2;
    align-self: center;
    font-size: 24px;
    white-space: nowrap;
  }

  .opp-stats {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
  }

  .opp-stats.mon-stats-4 {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }

  .stat-item,
  .header-stat {
    min-width: 0;
    background: rgba(255, 255, 255, 0.72);
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    padding: 8px 6px;
  }

  .stat-value {
    font-size: 14px;
    overflow-wrap: anywhere;
  }

  .stat-sub {
    overflow-wrap: anywhere;
  }

  .expand-cue {
    bottom: 12px;
    right: 14px;
    font-size: 11px;
  }

  .quick-note-btn {
    top: 10px;
    right: 10px;
    min-width: 34px;
    min-height: 34px;
    opacity: 0.75;
  }

  .quick-note-inline {
    padding: 14px;
  }

  .opp-expanded {
    padding-top: 12px;
    margin-top: 4px;
  }

  .expanded-grid,
  .deal-layout,
  .detail-grid,
  .v6-more-details-grid,
  .scenario-grid {
    grid-template-columns: 1fr !important;
  }

  .detail-box,
  .deal-col {
    padding: 12px;
  }

  .actions-box,
  .btn-grid,
  .opp-card .actions-box {
    grid-template-columns: 1fr !important;
    display: grid !important;
    gap: 8px !important;
  }

  .btn,
  .opp-card .actions-box button,
  .v6-save-btn,
  .modal-actions button,
  .drawer-footer button,
  .mb-btn,
  .mb-btn-action,
  .gmm-approval-btn {
    min-height: 44px;
    font-size: 13px;
  }

  .rc-tabs {
    overflow-x: auto;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }

  .rc-tabs::-webkit-scrollbar {
    display: none;
  }

  .rc-tab {
    flex: 0 0 auto;
    min-width: 108px;
    min-height: 40px;
  }

  .rc-slider-row,
  .rc-balance-row,
  .rc-status-bar,
  .rc-actions {
    flex-wrap: wrap;
  }

  .rc-metrics {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .drawer,
  .math-sidebar,
  .pov-drawer {
    width: 100vw !important;
    max-width: 100vw !important;
  }

  .modal-overlay,
  .enhanced-script-overlay,
  .gmm-approval-overlay,
  .compose-overlay,
  .briefing-popup-overlay {
    align-items: flex-end !important;
    padding: 0 !important;
  }

  .modal-card,
  .enhanced-script-card,
  .gmm-approval-card,
  .compose-card,
  .briefing-popup-card,
  .pourover-modal,
  .mb-modal {
    width: 100vw !important;
    max-width: 100vw !important;
    max-height: calc(100vh - env(safe-area-inset-top, 0px)) !important;
    border-radius: 18px 18px 0 0 !important;
  }

  .modal-card:not(.has-sticky-footer),
  .enhanced-script-card:not(.has-sticky-footer),
  .mb-modal {
    padding: 20px !important;
    overflow-y: auto;
  }

  .modal-actions,
  .drawer-footer,
  .gmm-approval-actions {
    flex-direction: column;
    align-items: stretch;
  }

  input,
  select,
  textarea {
    font-size: 16px !important;
  }

  /* My Book mobile cards */
  .mb-container {
    width: 100%;
    max-width: 100%;
  }

  .mb-header-top,
  .mb-client-header,
  .mb-match-banner-row,
  .mb-email-banner,
  .mb-add-mortgage-card,
  .mb-draw-card {
    flex-direction: column;
    align-items: stretch;
  }

  .mb-action-pills,
  .mb-header-stats,
  .mb-snapshot-grid,
  .mb-perf-stats {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 8px;
  }

  .mb-action-pill,
  .mb-boc-pill,
  .mb-stat,
  .mb-snapshot-card,
  .mb-perf-stat {
    min-width: 0;
  }

  .mb-two-col {
    grid-template-columns: 1fr !important;
    gap: 12px;
  }

  .mb-client-intro,
  .mb-client-actions,
  .mb-client-progress {
    width: 100%;
    align-items: stretch;
  }

  .mb-client-intro {
    flex-direction: column;
    gap: 12px;
  }

  .mb-client-actions .mb-search-box,
  .mb-search-box {
    width: 100% !important;
  }

  .mb-search-input {
    min-height: 46px;
  }

  .mb-tabs {
    display: flex;
    gap: 6px;
    padding-bottom: 4px;
  }

  .mb-table-wrapper {
    overflow: visible;
  }

  .mb-client-table {
    display: none;
  }

  .mb-mobile-cards {
    display: flex;
    flex-direction: column;
    gap: 10px;
  }

  .mb-mobile-card {
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 14px;
    padding: 13px;
    box-shadow: 0 1px 3px rgba(15, 23, 42, 0.05);
  }

  .mb-mobile-card.syncing {
    background: #fffbeb;
    border-color: #fde68a;
  }

  .mb-mobile-card-top {
    display: flex;
    align-items: flex-start;
    gap: 10px;
  }

  .mb-mobile-check {
    flex: 0 0 auto;
    padding-top: 2px;
  }

  .mb-mobile-main {
    flex: 1;
    min-width: 0;
  }

  .mb-mobile-name {
    font-size: 15px;
    font-weight: 800;
    color: #0f172a;
    line-height: 1.25;
  }

  .mb-mobile-meta {
    margin-top: 3px;
    font-size: 12px;
    color: #64748b;
    overflow-wrap: anywhere;
  }

  .mb-mobile-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 7px;
    margin-top: 10px;
  }

  .mb-mobile-stat {
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    padding: 8px 7px;
    min-width: 0;
  }

  .mb-mobile-label {
    font-size: 9px;
    font-weight: 800;
    color: #94a3b8;
    text-transform: uppercase;
    letter-spacing: 0.04em;
  }

  .mb-mobile-value {
    margin-top: 2px;
    font-size: 13px;
    font-weight: 800;
    color: #0f172a;
    overflow-wrap: anywhere;
  }

  .mb-mobile-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-top: 11px;
  }

  .mb-mobile-footer .mb-status-badge {
    min-width: 0;
  }

  .mb-mobile-action {
    flex: 0 0 auto;
    min-height: 40px;
  }

  .mb-table-footer {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }

  .mb-pagination {
    justify-content: center;
    flex-wrap: wrap;
  }

  .mb-floating-bar {
    left: 10px !important;
    right: 10px !important;
    bottom: calc(76px + env(safe-area-inset-bottom, 0px)) !important;
    width: auto !important;
  }

  /* Command Center mobile containment */
  .cc-page,
  .cc-tabs-section {
    max-width: 100%;
    overflow-x: hidden;
  }

  .cc-tabs-header,
  .cc-table-footer {
    flex-direction: column;
    align-items: stretch;
  }

  .cc-search-box,
  .cc-search-box input {
    width: 100%;
  }

  .cc-client-table {
    min-width: 740px;
  }

  .cc-tabs-section {
    overflow-x: auto;
  }
}
