/* PR1: mobile-native application shell. Desktop behavior remains unchanged. */
.mobile-shell-title,
.mobile-workspace-switch,
.mobile-tabbar{
  display:none;
}

@media(max-width:760px){
  :root{
    --mobile-header-height:58px;
    --mobile-tabbar-height:68px;
  }

  body{
    overscroll-behavior-y:none;
    -webkit-tap-highlight-color:transparent;
  }

  .shell,.shell.sidebar-collapsed,
  .page-scroll{
    height:100dvh;
  }

  .topbar{
    height:calc(var(--mobile-header-height) + env(safe-area-inset-top));
    min-height:calc(var(--mobile-header-height) + env(safe-area-inset-top));
    padding:env(safe-area-inset-top) 14px 0;
    gap:10px;
    flex-wrap:nowrap;
    justify-content:space-between;
    background:rgba(255,255,255,.96);
    border-bottom:1px solid rgba(223,229,236,.92);
    backdrop-filter:blur(18px);
  }

  .topbar:has(.impersonation-form){
    height:auto;
    min-height:calc(var(--mobile-header-height) + env(safe-area-inset-top));
    padding:calc(env(safe-area-inset-top) + 7px) 12px 7px;
    flex-wrap:wrap;
  }

  .topbar .mobile-menu-trigger,
  .topbar>.role-chip,
  .topbar>.org-chip:not(.impersonation-chip),
  .topbar>.user-chip{
    display:none!important;
  }

  .mobile-shell-title{
    display:flex;
    min-width:0;
    flex:1;
    flex-direction:column;
    justify-content:center;
    gap:1px;
  }

  .mobile-shell-title strong,
  .mobile-shell-title small{
    display:block;
    min-width:0;
    overflow:hidden;
    text-overflow:ellipsis;
    white-space:nowrap;
  }

  .mobile-shell-title strong{
    color:var(--ink);
    font-size:.96rem;
    line-height:1.2;
    font-weight:750;
  }

  .mobile-shell-title small{
    color:var(--muted);
    font-size:.68rem;
    line-height:1.2;
    font-weight:600;
  }

  .mobile-workspace-switch{
    display:inline-flex;
    flex:0 0 auto;
    width:40px;
    height:40px;
    min-height:40px;
    padding:0;
    border-radius:13px;
    border:1px solid var(--line);
    background:#fff;
    color:var(--ink);
    box-shadow:0 3px 12px rgba(0,41,83,.05);
  }

  .mobile-workspace-switch:active{
    transform:scale(.97);
    background:#f1f4f8;
  }

  .content{
    min-height:calc(100dvh - var(--mobile-header-height) - env(safe-area-inset-top));
    padding:16px 14px calc(var(--mobile-tabbar-height) + 24px + env(safe-area-inset-bottom));
  }

  .mobile-tabbar{
    position:fixed;
    z-index:58;
    left:0;
    right:0;
    bottom:0;
    display:grid;
    grid-auto-flow:column;
    grid-auto-columns:minmax(0,1fr);
    align-items:start;
    gap:2px;
    min-height:calc(var(--mobile-tabbar-height) + env(safe-area-inset-bottom));
    padding:6px 7px env(safe-area-inset-bottom);
    border-top:1px solid rgba(211,221,232,.96);
    background:rgba(255,255,255,.97);
    box-shadow:0 -10px 28px rgba(0,41,83,.08);
    backdrop-filter:blur(20px);
  }

  .mobile-tabbar a,
  .mobile-tabbar button{
    position:relative;
    min-width:0;
    min-height:56px;
    padding:5px 2px 4px;
    border:0;
    border-radius:12px;
    background:transparent;
    color:#6d7986;
    display:flex;
    flex-direction:column;
    align-items:center;
    justify-content:center;
    gap:3px;
    font:inherit;
    font-size:.62rem;
    line-height:1.1;
    font-weight:650;
    cursor:pointer;
  }

  .mobile-tabbar a svg,
  .mobile-tabbar button svg{
    width:21px;
    height:21px;
    stroke-width:1.9;
  }

  .mobile-tabbar a span,
  .mobile-tabbar button span{
    max-width:100%;
    overflow:hidden;
    text-overflow:ellipsis;
    white-space:nowrap;
  }

  .mobile-tabbar a.active{
    color:var(--accent);
    background:#e8f1f9;
  }

  .mobile-tabbar a.active::before{
    content:"";
    position:absolute;
    top:2px;
    left:50%;
    width:22px;
    height:3px;
    border-radius:999px;
    background:var(--accent);
    transform:translateX(-50%);
  }

  .mobile-tabbar a:active,
  .mobile-tabbar button:active{
    background:#edf2f7;
    transform:scale(.97);
  }

  .sidebar,.shell.sidebar-collapsed .sidebar{
    width:min(340px,90vw);
    padding-top:calc(14px + env(safe-area-inset-top));
    padding-bottom:calc(14px + env(safe-area-inset-bottom));
  }

  .sidebar .brand{
    min-height:48px;
    padding-right:48px;
  }

  .mobile-nav-close{
    display:inline-flex!important;
    position:absolute;
    right:12px;
    top:calc(14px + env(safe-area-inset-top));
    z-index:2;
    width:38px;
    height:38px;
    min-height:38px;
    padding:0;
    border:1px solid rgba(255,255,255,.12);
    border-radius:12px;
    background:rgba(255,255,255,.08);
    color:#fff;
  }

  .sidebar nav a,
  .sidebar-foot a,
  .sidebar-action{
    min-height:44px;
  }

  .drawer{
    padding-top:calc(18px + env(safe-area-inset-top));
    padding-bottom:calc(24px + env(safe-area-inset-bottom));
  }

  /* Ordinary HTMX navigation uses a slim progress treatment instead of blocking the page. */
  .page-loading-overlay,
  .shell.sidebar-collapsed .page-loading-overlay{
    inset:calc(var(--mobile-header-height) + env(safe-area-inset-top) - 2px) 0 auto 0;
    width:auto;
    height:3px;
    min-height:3px;
    display:block;
    background:transparent;
    backdrop-filter:none;
    overflow:hidden;
    pointer-events:none!important;
  }

  .page-loading-overlay .spinner,
  .page-loading-overlay>span:last-child{
    display:none;
  }

  .page-loading-overlay::after{
    content:"";
    display:block;
    width:34%;
    height:100%;
    border-radius:999px;
    background:var(--accent);
    transform:translateX(-120%);
  }

  .page-is-loading .page-loading-overlay::after{
    animation:mobile-shell-progress .8s ease-in-out infinite;
  }

  .page-is-loading .page-loading-overlay{
    pointer-events:none!important;
  }

  .shell-modal{
    margin-bottom:max(10px,env(safe-area-inset-bottom));
  }
}

@media(max-width:480px){
  .content{
    padding-left:12px;
    padding-right:12px;
  }

  .mobile-tabbar a,
  .mobile-tabbar button{
    font-size:.59rem;
  }
}

@keyframes mobile-shell-progress{
  0%{transform:translateX(-120%)}
  55%{transform:translateX(120%)}
  100%{transform:translateX(320%)}
}

@media(prefers-reduced-motion:reduce){
  .mobile-workspace-switch:active,
  .mobile-tabbar a:active,
  .mobile-tabbar button:active{
    transform:none;
  }

  .page-is-loading .page-loading-overlay::after{
    animation:none;
    width:100%;
    transform:none;
  }
}

/* PR2: mobile-first core operating workflows. Desktop remains unchanged. */
@media(max-width:760px){
  /* Resource lists: Deals, Properties, Contacts */
  .content .resource-quick-filters{
    gap:8px;
    margin-right:-14px;
    padding-right:14px;
    scroll-snap-type:x proximity;
  }
  .content .resource-filter-chip{
    min-height:38px;
    padding:8px 13px;
    scroll-snap-align:start;
  }
  .content .resource-filterbar{
    border-radius:16px;
    border-color:#d9e2eb;
    box-shadow:none;
    background:#fff;
  }
  .content .resource-table tbody tr.resource-record-row{
    border-radius:16px;
    box-shadow:0 5px 18px rgba(0,41,83,.055);
  }
  .content .resource-table tbody tr.resource-record-row td:first-child{
    display:block;
    padding:14px 14px 11px;
    background:#fff;
  }
  .content .resource-table tbody tr.resource-record-row td:first-child::before{
    display:none;
  }
  .content .resource-table tbody tr.resource-record-row td:not(:first-child):not(.resource-actions){
    grid-template-columns:minmax(88px,32%) minmax(0,1fr);
    padding-left:14px;
    padding-right:14px;
  }
  .content .resource-table tbody tr.resource-record-row .resource-actions{
    margin-top:2px;
    padding:10px 12px!important;
    border-top:1px solid #edf1f5;
    background:#f8fafc!important;
  }
  .content .resource-table tbody tr.resource-record-row .resource-actions::before{
    display:none;
  }
  .content .resource-table .resource-action{
    min-height:38px;
    padding:8px 10px;
    border:1px solid #e1e8ef;
    background:#fff;
  }
  .content .resource-property{
    min-width:0;
  }
  .content .resource-property-image{
    width:58px;
    height:48px;
    border-radius:11px;
  }
  .content .resource-page-head .form-actions button:last-child{
    position:fixed;
    z-index:57;
    right:14px;
    bottom:calc(var(--mobile-tabbar-height) + env(safe-area-inset-bottom) + 12px);
    min-height:48px;
    padding:0 16px;
    border-radius:999px;
    box-shadow:0 12px 30px rgba(0,41,83,.2);
  }

  /* Founder Home: keep the most important operating numbers dense and scannable. */
  .content .founder-head-actions{
    width:calc(100% + 14px);
    margin-right:-14px;
    display:flex!important;
    flex-wrap:nowrap!important;
    gap:8px;
    overflow-x:auto;
    padding:1px 14px 4px 0;
    scrollbar-width:none;
  }
  .content .founder-head-actions::-webkit-scrollbar{display:none}
  .content .founder-head-actions .button{
    flex:0 0 auto;
    min-height:40px;
    white-space:nowrap;
  }
  .content .founder-risk-filter{
    grid-template-columns:1fr 1fr!important;
    gap:9px;
    border-radius:16px;
    box-shadow:none;
  }
  .content .founder-risk-filter button{
    grid-column:1/-1;
  }
  .content .risk-metric-grid{
    grid-template-columns:repeat(2,minmax(0,1fr))!important;
    gap:9px;
  }
  .content .risk-metric:first-child{
    grid-column:1/-1;
  }
  .content .risk-metric{
    min-height:122px;
    border-radius:16px;
    box-shadow:none;
  }

  /* Collections: scheduled receivables become touch-first record cards. */
  .content .collections-workspace>section.panel{
    padding:0;
    border:0;
    background:transparent;
    box-shadow:none;
    overflow:visible;
  }
  .content .collections-workspace .collections-filters{
    grid-template-columns:1fr!important;
    gap:9px;
    padding:12px;
    margin-bottom:10px;
    border:1px solid var(--line);
    border-radius:16px;
    background:#fff;
  }
  .content .collections-workspace .collections-filters button{
    width:100%;
  }
  .content .collections-workspace .queue-meta{
    padding:0 2px;
    align-items:flex-start;
    flex-direction:column;
    gap:2px;
  }
  .content .collections-workspace .queue-table-wrap{
    overflow:visible;
    min-height:0;
    max-height:none;
  }
  .content .collections-workspace .queue-table{
    display:block;
    width:100%;
    min-width:0;
  }
  .content .collections-workspace .queue-table thead{
    display:none;
  }
  .content .collections-workspace .queue-table tbody{
    display:grid;
    gap:10px;
  }
  .content .collections-workspace .queue-table tbody>tr{
    display:flex;
    width:100%;
    flex-direction:column;
    overflow:hidden;
    border:1px solid var(--line);
    border-radius:16px;
    background:#fff;
    box-shadow:0 5px 18px rgba(0,41,83,.055);
  }
  .content .collections-workspace .queue-table tbody>tr>td{
    display:grid;
    grid-template-columns:96px minmax(0,1fr);
    align-items:start;
    gap:10px;
    width:100%;
    padding:9px 13px;
    border:0;
    border-bottom:1px solid #edf1f5;
    text-align:left;
  }
  .content .collections-workspace .queue-table tbody>tr>td::before{
    color:var(--muted);
    font-size:.64rem;
    line-height:1.3;
    font-weight:800;
    letter-spacing:.035em;
    text-transform:uppercase;
    padding-top:2px;
  }
  .content .collections-workspace .queue-table tbody>tr>td:nth-child(2){
    order:-3;
    display:block;
    padding-top:14px;
    padding-bottom:10px;
  }
  .content .collections-workspace .queue-table tbody>tr>td:nth-child(2)::before,
  .content .collections-workspace .queue-table tbody>tr>td:nth-child(1)::before,
  .content .collections-workspace .queue-table tbody>tr>td:nth-child(8)::before{
    display:none;
  }
  .content .collections-workspace .queue-table tbody>tr>td:nth-child(1){
    order:-2;
    display:block;
    padding-top:0;
    padding-bottom:10px;
  }
  .content .collections-workspace .queue-table tbody>tr>td:nth-child(3){order:-1}
  .content .collections-workspace .queue-table tbody>tr>td:nth-child(3)::before{content:"Deal"}
  .content .collections-workspace .queue-table tbody>tr>td:nth-child(4)::before{content:"Schedule"}
  .content .collections-workspace .queue-table tbody>tr>td:nth-child(5)::before{content:"Outstanding"}
  .content .collections-workspace .queue-table tbody>tr>td:nth-child(6)::before{content:"Due"}
  .content .collections-workspace .queue-table tbody>tr>td:nth-child(7)::before{content:"Reminder"}
  .content .collections-workspace .queue-table tbody>tr>td:nth-child(5) .queue-balance{
    font-size:1rem;
    color:var(--ink);
  }
  .content .collections-workspace .queue-table tbody>tr>td:nth-child(8){
    display:block;
    padding:10px 12px 12px;
    border-bottom:0;
    background:#f8fafc;
  }
  .content .collections-workspace .queue-actions{
    display:grid;
    grid-template-columns:repeat(2,minmax(0,1fr));
    gap:8px;
    width:100%;
  }
  .content .collections-workspace .queue-actions button{
    width:100%;
    min-height:42px;
    justify-content:center;
  }
  .content .collections-workspace .queue-table td[colspan]{
    display:block!important;
    padding:0!important;
    border:0!important;
  }
  .content .collections-workspace .queue-table td[colspan]::before{display:none!important}

  /* Payment Ledger: actual cash records use the same native record pattern. */
  .content .ledger-metrics{
    display:flex!important;
    grid-template-columns:none!important;
    gap:10px;
    overflow-x:auto;
    margin-right:-14px;
    padding-right:14px;
    scroll-snap-type:x mandatory;
    scrollbar-width:none;
  }
  .content .ledger-metrics::-webkit-scrollbar{display:none}
  .content .ledger-metrics>div{
    flex:0 0 min(78vw,300px);
    min-height:112px;
    border-radius:16px;
    scroll-snap-align:start;
    box-shadow:none;
  }
  .content .ledger-actions button{
    position:fixed;
    z-index:57;
    right:14px;
    bottom:calc(var(--mobile-tabbar-height) + env(safe-area-inset-bottom) + 12px);
    min-height:48px;
    padding:0 16px;
    border-radius:999px;
    box-shadow:0 12px 30px rgba(0,41,83,.2);
  }
  .content section.panel:has(.ledger-table-wrap){
    padding:0;
    border:0;
    background:transparent;
    box-shadow:none;
    overflow:visible;
  }
  .content .ledger-note{
    margin-bottom:10px;
    border-radius:14px;
    background:#fff;
  }
  .content .ledger-table-wrap{
    overflow:visible;
  }
  .content .ledger-table-wrap>table{
    display:block;
    width:100%;
  }
  .content .ledger-table-wrap>table thead{display:none}
  .content .ledger-table-wrap>table tbody{
    display:grid;
    gap:10px;
  }
  .content .ledger-table-wrap>table tbody>tr{
    display:flex;
    width:100%;
    flex-direction:column;
    overflow:hidden;
    border:1px solid var(--line);
    border-radius:16px;
    background:#fff;
    box-shadow:0 5px 18px rgba(0,41,83,.055);
  }
  .content .ledger-table-wrap>table tbody>tr>td{
    display:grid;
    grid-template-columns:92px minmax(0,1fr);
    gap:10px;
    align-items:start;
    width:100%;
    padding:9px 13px;
    border:0;
    border-bottom:1px solid #edf1f5;
    text-align:left;
  }
  .content .ledger-table-wrap>table tbody>tr>td::before{
    color:var(--muted);
    font-size:.64rem;
    line-height:1.3;
    font-weight:800;
    letter-spacing:.035em;
    text-transform:uppercase;
    padding-top:2px;
  }
  .content .ledger-table-wrap>table tbody>tr>td:nth-child(2){
    order:-3;
    display:block;
    padding-top:14px;
  }
  .content .ledger-table-wrap>table tbody>tr>td:nth-child(2)::before,
  .content .ledger-table-wrap>table tbody>tr>td:nth-child(7)::before{
    display:none;
  }
  .content .ledger-table-wrap>table tbody>tr>td:nth-child(1){order:-2}
  .content .ledger-table-wrap>table tbody>tr>td:nth-child(4){order:-1}
  .content .ledger-table-wrap>table tbody>tr>td:nth-child(1)::before{content:"Date"}
  .content .ledger-table-wrap>table tbody>tr>td:nth-child(3)::before{content:"Type"}
  .content .ledger-table-wrap>table tbody>tr>td:nth-child(4)::before{content:"Amount"}
  .content .ledger-table-wrap>table tbody>tr>td:nth-child(5)::before{content:"Status"}
  .content .ledger-table-wrap>table tbody>tr>td:nth-child(6)::before{content:"Reference"}
  .content .ledger-table-wrap>table tbody>tr>td:nth-child(4) strong{
    font-size:1rem;
    color:var(--ink);
  }
  .content .ledger-table-wrap>table tbody>tr>td:nth-child(7){
    display:block;
    padding:10px 12px 12px;
    border-bottom:0;
    background:#f8fafc;
  }
  .content .ledger-table-wrap>table tbody>tr>td:nth-child(7) form{margin:0}
  .content .ledger-table-wrap>table tbody>tr>td:nth-child(7) button{
    width:100%;
    min-height:40px;
    padding:8px 10px;
    border:1px solid #edd8d4;
    border-radius:10px;
    background:#fff;
  }
  .content .ledger-table-wrap>table td[colspan]{
    display:block!important;
    padding:24px 12px!important;
    border:0!important;
  }
  .content .ledger-table-wrap>table td[colspan]::before{display:none!important}
}

@media(max-width:430px){
  .content .risk-metric-grid{
    grid-template-columns:repeat(2,minmax(0,1fr))!important;
  }
  .content .risk-metric:first-child{
    grid-column:1/-1;
  }
  .content .risk-metric{
    min-height:116px;
    padding:11px;
  }
  .content .risk-metric small{
    font-size:.64rem;
  }
  .content .ledger-metrics>div{
    flex-basis:84vw;
  }
}
