/* AHT Project Control — responsive/mobile layer
   Desktop styling remains in styles.css/branding.css. All rules here are
   limited to tablet/phone breakpoints so the existing desktop model is not changed. */

@media (max-width: 980px) {
  html,body{max-width:100%;overflow-x:hidden}
  body{-webkit-text-size-adjust:100%}

  .shell{display:block;min-height:100vh}
  .content-shell{width:100%;min-width:0}

  /* Tablet navigation becomes a compact, swipeable rail. */
  .sidebar{
    position:sticky;
    top:0;
    z-index:30;
    height:auto;
    padding:8px 10px;
    background:var(--slate);
    box-shadow:0 4px 14px rgba(38,53,62,.15);
  }
  .sidebar-brand,.sidebar-footer{display:none}
  .sidebar-nav{
    display:flex;
    flex-direction:row;
    gap:4px;
    overflow-x:auto;
    overscroll-behavior-x:contain;
    -webkit-overflow-scrolling:touch;
    scrollbar-width:none;
  }
  .sidebar-nav::-webkit-scrollbar{display:none}
  .sidebar-nav button{
    flex:0 0 auto;
    width:auto;
    min-height:42px;
    padding:9px 12px;
    white-space:nowrap;
    border-left:0;
    border-bottom:3px solid transparent;
  }
  .sidebar-nav button.active{border-left:0;border-bottom-color:var(--blue)}

  .topbar{
    padding:12px 18px;
    gap:12px;
    align-items:center;
    flex-direction:row;
  }
  .brand{min-width:0}
  .brand h1{font-size:18px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
  .brand p{white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
  .meta{margin-left:auto;text-align:right;min-width:0}
  .profile-chip{justify-content:flex-end}

  .container{width:100%;max-width:none;padding:20px}
  .project-grid{grid-template-columns:repeat(2,minmax(0,1fr))}
  .grid-kpi{grid-template-columns:repeat(2,minmax(0,1fr))}
  .grid-2,.agenda-grid{grid-template-columns:1fr}

  .page-header{gap:12px}
  .page-header>.actions,.toolbar .actions{display:flex;gap:8px;flex-wrap:wrap;justify-content:flex-end}

  /* Keep wide datasets readable instead of shrinking columns into illegibility. */
  .audit-table-scroll{overflow:auto;-webkit-overflow-scrolling:touch}
  .audit-table-scroll table{min-width:780px}
  .table-card>div[style*="overflow:auto"]{-webkit-overflow-scrolling:touch}

  /* Gantt stays a real timeline and scrolls horizontally on small screens. */
  .timeline{overflow:visible}
  .gantt-scroll{
    max-width:100%;
    overflow:auto;
    overscroll-behavior-x:contain;
    -webkit-overflow-scrolling:touch;
  }
  .gantt-shell{min-width:800px}
  .gantt-head,.gantt-row{grid-template-columns:230px minmax(570px,1fr)}
  .gantt-head>div:first-child,
  .gantt-label{
    position:sticky;
    left:0;
    z-index:3;
    background:#fff;
    box-shadow:1px 0 0 var(--line);
  }
  .gantt-head>div:first-child{z-index:6;background:#edf3f7}
  .gantt-row:nth-child(odd) .gantt-label{background:#fbfcfd}
}

@media (max-width: 700px) {
  :root{--mobile-edge:12px}

  /* Login */
  .login-screen{
    min-height:100dvh;
    place-items:center;
    padding:max(16px,env(safe-area-inset-top)) var(--mobile-edge) max(16px,env(safe-area-inset-bottom));
  }
  .login-card{
    width:100%;
    max-width:430px;
    padding:22px 18px;
    border-radius:14px;
  }
  .login-logo-wrap{margin-bottom:12px}
  .login-logo{width:min(210px,72%)}
  .login-card h1{font-size:24px}
  .login-card p{font-size:13px;line-height:1.4;margin-bottom:18px}
  .login-card select,.login-card input,.login-card button{min-height:46px;font-size:16px}
  .demo-note{line-height:1.4}

  /* Navigation and user header */
  .sidebar{padding-left:max(8px,env(safe-area-inset-left));padding-right:max(8px,env(safe-area-inset-right))}
  .sidebar-nav button{min-height:44px;padding:9px 11px;font-size:13px}
  .topbar{
    padding:11px max(14px,env(safe-area-inset-right)) 11px max(14px,env(safe-area-inset-left));
    align-items:flex-start;
    flex-direction:column;
  }
  .brand h1{font-size:17px}
  .brand p{font-size:12px}
  .meta{width:100%;margin:0;text-align:left}
  .profile-chip{width:100%;justify-content:flex-start}
  .userbar{justify-content:flex-start;flex-wrap:wrap}
  .userbar button{min-height:40px;padding:8px 11px}

  .container{padding:16px var(--mobile-edge) 28px}
  .page-header{flex-direction:column;align-items:stretch;margin-bottom:14px}
  .page-header h2{font-size:23px}
  .page-header p{line-height:1.42}
  .page-header>.actions,.toolbar .actions,.admin-header-actions{width:100%;justify-content:flex-start}

  .project-switcher{
    width:100%;
    display:grid;
    grid-template-columns:auto minmax(0,1fr);
    gap:8px;
  }
  .project-switcher select{width:100%;min-width:0;min-height:44px;font-size:16px}

  .btn{min-height:44px;padding:10px 13px}
  .page-header>.actions>.btn,.admin-header-actions>.btn{flex:1 1 auto}

  .project-grid{grid-template-columns:1fr;gap:12px}
  .project-card{padding:16px}
  .project-card:hover{transform:none}
  .project-card .stats{gap:6px}
  .stat-mini{padding:8px 5px}
  .stat-mini strong{font-size:17px}

  .summary-ribbon{grid-template-columns:1fr 1fr;gap:8px}
  .summary-cell{padding:10px 11px;min-width:0}
  .summary-cell .value{overflow-wrap:anywhere}
  .last-activity{padding:11px 12px}
  .grid-kpi{grid-template-columns:1fr 1fr;gap:9px}
  .kpi{padding:13px}
  .kpi .num{font-size:26px}
  .grid-2{gap:12px}
  .panel .body{min-height:0}

  /* Existing card rendering is used on phone; improve tap/readability. */
  .desktop-table{display:none!important}
  .mobile-cards{display:block!important}
  .mobile-record{padding:13px 14px;border-radius:10px;margin-bottom:10px;box-shadow:0 2px 8px rgba(15,23,42,.04)}
  .mobile-record h4{font-size:15px;line-height:1.35;padding-right:4px}
  .mobile-record .row{align-items:flex-start;line-height:1.35}
  .mobile-record .row>*:last-child{text-align:right;overflow-wrap:anywhere;min-width:0}
  .mobile-record .linkbtn{min-height:38px;padding:7px 0}

  .table-tools{display:grid;grid-template-columns:1fr;gap:8px}
  .table-tools input,.table-tools select,
  .audit-toolbar input,.audit-toolbar select{width:100%;min-height:44px;font-size:16px}

  /* Calendar: preserve the real seven-day month grid and let it swipe. */
  .calendar-card{max-width:100%;overflow:hidden}
  .calendar-card:has(.month-grid){overflow-x:auto;-webkit-overflow-scrolling:touch}
  .month-grid{grid-template-columns:repeat(7,minmax(92px,1fr));min-width:644px}
  .day-head{display:block;min-height:auto;position:sticky;top:0;z-index:2}
  .day-cell{min-height:84px;padding:7px}
  .event-dot{overflow:hidden;text-overflow:ellipsis}
  .agenda-day{grid-template-columns:74px minmax(0,1fr);gap:9px;padding:11px 12px}
  .agenda-pill{align-items:flex-start}
  .agenda-pill>span:first-child{min-width:0;overflow-wrap:anywhere}

  /* Gantt */
  .timeline{padding:10px;border-radius:9px}
  .gantt-shell{min-width:720px}
  .gantt-head,.gantt-row{grid-template-columns:205px minmax(515px,1fr)}
  .gantt-head>div,.gantt-label{padding-left:9px;padding-right:9px}
  .gantt-label strong{font-size:11px}
  .gantt-group-header{min-height:40px}
  .gantt-legend{gap:8px}
  .gantt-legend .gantt-note{width:100%;margin-left:0}

  /* Edit modal becomes a phone-safe sheet without changing save/delete logic. */
  .modal-backdrop{
    align-items:flex-end;
    padding:0;
    padding-bottom:env(safe-area-inset-bottom);
  }
  .modal{
    width:100%;
    max-width:none;
    max-height:92dvh;
    border-radius:14px 14px 0 0;
    padding:18px 14px calc(16px + env(safe-area-inset-bottom));
  }
  .modal h3{font-size:19px;margin-bottom:13px}
  .form-grid{grid-template-columns:1fr;gap:10px}
  .field.full{grid-column:auto}
  .field input,.field select,.field textarea{min-height:44px;font-size:16px}
  .field textarea{min-height:90px}
  .modal-actions{
    position:sticky;
    bottom:calc(-16px - env(safe-area-inset-bottom));
    margin:16px -14px calc(-16px - env(safe-area-inset-bottom));
    padding:10px 14px calc(10px + env(safe-area-inset-bottom));
    background:#fff;
    border-top:1px solid var(--line);
    z-index:2;
  }
  .modal-actions .btn{min-width:78px}

  /* Admin */
  .admin-grid,.project-admin-row,.checkbox-list{grid-template-columns:1fr}
  .project-admin-actions{justify-content:flex-start;flex-wrap:wrap}
  .admin-card-heading{align-items:flex-start;flex-wrap:wrap}
  .admin-card input,.admin-card select{min-height:44px;font-size:16px}
  .audit-toolbar{display:grid;grid-template-columns:1fr;gap:8px}
  .audit-table-scroll{max-height:none;border-radius:8px}
  .audit-table-scroll table{min-width:760px}

  .startup-status{padding:14px}
  .startup-card{padding:24px 18px}
}

@media (max-width: 480px) {
  .summary-ribbon{grid-template-columns:1fr}
  .grid-kpi{grid-template-columns:1fr 1fr}
  .project-card .stats{grid-template-columns:repeat(3,minmax(0,1fr))}
  .phase-progress-row{grid-template-columns:76px minmax(0,1fr) 34px}
  .agenda-day{grid-template-columns:1fr}
  .agenda-date{margin-bottom:2px}
  .modal-actions{gap:7px}
  .modal-actions .btn{flex:1 1 0;min-width:0}
  .modal-actions span{display:none}
}

@media (max-width: 360px) {
  .grid-kpi{grid-template-columns:1fr}
  .project-card .stats{grid-template-columns:1fr}
}

@media (max-width:768px){
  .entra-access-heading,.entra-table-heading{display:block}
  .entra-access-heading .btn{margin-top:10px;width:100%}
  .redeem-row{display:block}.redeem-row .btn{width:100%;margin-top:7px}
  .entra-user-table-wrap{margin-left:-2px;margin-right:-2px}
}


/* v0.14.9 — mobile Deliverables / Information Required parity */
@media (max-width:700px){
  /* Keep Deliverables filters available, while the desktop table itself stays hidden. */
  #deliverables .desktop-table{
    display:block!important;
    border:0;
    background:transparent;
    overflow:visible;
    margin-bottom:10px;
  }
  #deliverables .desktop-table>.table-tools{
    display:grid!important;
    grid-template-columns:1fr;
    border:1px solid var(--line);
    border-radius:10px;
    background:#fff;
  }
  #deliverables .desktop-table>div[style*="overflow:auto"]{
    display:none!important;
  }

  .mobile-record-heading{
    display:flex;
    align-items:flex-start;
    justify-content:space-between;
    gap:10px;
    margin-bottom:7px;
  }
  .mobile-record-heading>div{min-width:0}
  .mobile-record-heading h4{margin:0}
  .mobile-record-kicker{
    color:var(--muted);
    font-size:10px;
    font-weight:750;
    text-transform:uppercase;
    letter-spacing:.05em;
    margin-bottom:3px;
  }
  .mobile-record-current{
    font-size:12px;
    color:var(--muted);
    line-height:1.4;
    padding:8px 0 9px;
    border-bottom:1px solid #edf1f5;
  }
  .mobile-record-actions{
    padding-top:10px;
  }
  .mobile-record-actions .btn{
    width:100%;
  }
  .mobile-empty{
    background:#fff;
    border:1px solid var(--line);
    border-radius:10px;
    padding:16px;
    color:var(--muted);
    font-size:13px;
  }
}

/* v0.14.10 — compact mobile status badges */
@media (max-width:700px){
  .mobile-record-heading{
    align-items:flex-start;
  }

  .mobile-record-heading > .badge,
  .mobile-record-heading > span > .badge,
  .mobile-record .badge{
    display:inline-flex;
    align-items:center;
    justify-content:center;
    flex:0 0 auto;
    width:max-content;
    max-width:none;
    min-width:0;
    white-space:nowrap;
    line-height:1.15;
    text-align:center;
    vertical-align:top;
  }

  .mobile-record-heading h4{
    min-width:0;
  }
}

/* v0.14.11 — Microsoft access list on mobile */
@media (max-width:700px){
  .entra-user-table-wrap{
    max-height:400px;
    overflow:auto;
    -webkit-overflow-scrolling:touch;
    margin-left:0;
    margin-right:0;
    padding-top:4px;
  }
  .entra-user-table{
    min-width:720px;
  }
  .entra-user-table-wrap .entra-table-heading{
    min-width:100%;
    padding-left:2px;
    padding-right:2px;
  }
}

/* v0.14.12 — Current Dashboard Access mobile scrolling */
@media (max-width:700px){
  .entra-user-table-wrap{
    max-height:none!important;
    overflow:visible!important;
  }

  .entra-user-table-wrap .entra-user-table{
    display:block;
    width:100%;
    min-width:680px;
    max-height:320px;
    overflow:auto;
    -webkit-overflow-scrolling:touch;
  }

  .entra-user-table-wrap .entra-user-table thead,
  .entra-user-table-wrap .entra-user-table tbody{
    display:table;
    width:100%;
    min-width:680px;
    table-layout:fixed;
  }
}

/* v0.14.13 — Current Dashboard Access wrapper scroll mobile */
@media (max-width:700px){
  .entra-user-table-wrap{
    display:block!important;
    width:100%!important;
    max-height:320px!important;
    overflow:auto!important;
    -webkit-overflow-scrolling:touch;
    overscroll-behavior:contain;
    scrollbar-gutter:auto;
  }

  .entra-user-table-wrap .entra-user-table{
    display:table!important;
    width:760px!important;
    min-width:760px!important;
    max-height:none!important;
    overflow:visible!important;
  }

  .entra-user-table-wrap .entra-user-table thead{
    display:table-header-group!important;
  }

  .entra-user-table-wrap .entra-user-table tbody{
    display:table-row-group!important;
  }

  .entra-user-table-wrap .entra-table-heading{
    position:sticky!important;
    top:0!important;
    min-width:760px;
    z-index:5!important;
    background:#fbfdff!important;
  }

  .entra-user-table-wrap .entra-user-table thead th{
    position:sticky!important;
    top:45px!important;
    z-index:4!important;
  }
}

/* v0.14.14 — compact Current Dashboard Access viewport mobile */
@media (max-width:700px){
  .entra-user-table-wrap{
    height:245px!important;
    max-height:245px!important;
    overflow:auto!important;
    -webkit-overflow-scrolling:touch;
  }
}


/* v0.14.39 mobile usability */
@media(max-width:700px){

  .calendar-nav{
    display:grid;
    grid-template-columns:auto 1fr auto;
    gap:6px;
  }

  .calendar-nav-center{
    flex-direction:column;
    gap:4px;
  }

  .calendar-nav-center h3{
    text-align:center;
    font-size:13px;
  }

  .calendar-month-picker{
    width:100%;
    max-width:150px;
  }

  .calendar-today-btn{
    display:none;
  }

  .audit-toolbar{
    display:grid;
    grid-template-columns:1fr;
    gap:7px;
  }

  .audit-toolbar input,
  .audit-toolbar select{
    width:100%;
  }

  .audit-table-scroll{
    max-height:62vh!important;
    min-height:300px;
    overflow:auto!important;
    -webkit-overflow-scrolling:touch;
  }

  .audit-table-scroll table{
    min-width:820px;
  }

  .entra-user-table-wrap{
    height:auto!important;
    max-height:none!important;
    overflow:visible!important;
  }

  .entra-user-table-wrap .entra-user-table{
    display:block!important;
    max-height:330px!important;
    overflow:auto!important;
    -webkit-overflow-scrolling:touch;
  }

  .entra-user-table-wrap .entra-user-table thead,
  .entra-user-table-wrap .entra-user-table tbody{
    display:table!important;
    width:760px!important;
    min-width:760px!important;
  }

  .entra-user-table-wrap .entra-user-table thead{
    position:sticky!important;
    top:0!important;
    z-index:20!important;
  }

  .entra-user-table-wrap .entra-table-heading{
    position:relative!important;
    top:auto!important;
    min-width:0!important;
  }
}


/* v0.14.40 — compact calendar jump control */
@media(max-width:700px){
 .calendar-month-picker{height:34px!important;width:108px!important;max-width:108px!important;font-size:12px!important;}
 .calendar-nav-btn{height:34px!important;min-height:34px!important;min-width:34px!important;}
}

/* v0.14.42 mobile calendar cleanup */
@media(max-width:700px){.calendar-today-label{display:none}.calendar-nav-center{justify-content:center!important}.calendar-month-picker{max-width:125px!important}}


/* v0.14.43 — compact calendar month/year navigation on mobile */
@media(max-width:700px){
  .calendar-nav{
    min-height:40px!important;
    display:flex!important;
    align-items:center!important;
    gap:6px!important;
    flex-wrap:nowrap!important;
  }
  .calendar-month-stepper{height:34px;flex:0 0 auto;}
  .calendar-month-name{min-width:70px;padding:0 6px;font-size:11px;}
  .calendar-year-picker{width:76px!important;flex:0 0 76px!important;}
  .calendar-nav-spacer{display:none!important;}
  .calendar-today-label{display:none!important;}
  .calendar-today-btn{margin-left:auto!important;padding:0 10px!important;}
}


/* v0.14.45 — Project Activity mobile */
@media(max-width:700px){
 .last-activity{display:grid!important;grid-template-columns:1fr;gap:8px}
 .last-activity .activity-actions{margin-left:0}
 .activity-add-btn{width:100%}
 .project-activity-modal{width:calc(100vw - 20px);max-height:92vh}
 .project-activity-history{max-height:36vh}
}


/* v0.14.50 — comments mobile */
@media(max-width:700px){
  .mobile-record-actions{display:flex;align-items:center;gap:8px;flex-wrap:wrap}
  .comments-modal{width:calc(100vw - 20px);max-height:90vh}
  .comments-list{max-height:45vh}
  .comments-modal-heading{align-items:center}
  .comment-meta{gap:6px}
}


/* v0.14.51 — comments / mentions mobile */
@media(max-width:700px){
  .mobile-record-actions .comment-link{min-width:38px;min-height:34px}
  .comment-mention-list{max-height:220px}
}


/* v0.14.52 — project comment action mobile */
@media (max-width:700px){
  .last-activity .activity-actions{display:flex;flex-wrap:wrap;gap:7px;margin-top:8px}
  .project-comment-btn,.activity-add-btn{min-height:34px}
}

/* v0.14.57 — Summary activity controls */
@media(max-width:700px){
  .last-activity .activity-actions{
    display:grid;
    grid-template-columns:1fr 1fr;
    width:100%;
    gap:8px;
  }

  .last-activity .activity-actions .btn:not(.hidden){
    width:100%;
    min-width:0;
    margin:0;
    justify-content:center;
    text-align:center;
  }
}

/* v0.14.57 - compact mobile Project Comment */
@media(max-width:700px){

  .project-comment-btn .mobile-project-comment{
    position:relative;
    display:flex;
    flex-direction:column;
    align-items:center;
    justify-content:center;
    width:100%;
    line-height:1.1;
  }

  .project-comment-btn .comment-text-line{
    display:block;
    width:100%;
    text-align:center;
  }

  .project-comment-btn .comment-icon-wrap{
    position:absolute;
    left:14px;
    top:50%;
    transform:translateY(-50%);
    line-height:1;
  }

  .project-comment-btn .comment-icon{
    display:block;
    font-size:22px;
    line-height:1;
  }

  .project-comment-btn .comment-count{
    position:absolute;
    top:-5px;
    right:-7px;
    font-size:11px;
    font-weight:700;
    line-height:1;
  }
}

/* v0.14.57 - match Add Activity to Project Comment */
.mobile-activity-label{
  display:none;
}

@media(max-width:700px){
  .activity-add-btn .desktop-activity-label{
    display:none;
  }

  .activity-add-btn .mobile-activity-label{
    display:flex;
    flex-direction:column;
    align-items:center;
    justify-content:center;
    width:100%;
    line-height:1.1;
    text-align:center;
  }

  .activity-add-btn .mobile-activity-label span{
    display:block;
    width:100%;
    text-align:center;
  }
}

/* v0.14.57 - enforce mobile Add Activity label */
@media(max-width:700px){
  .activity-add-btn .desktop-activity-label{
    display:none !important;
  }

  .activity-add-btn .mobile-activity-label{
    display:flex !important;
    flex-direction:column;
    align-items:center;
    justify-content:center;
    width:100%;
    line-height:1.1;
    text-align:center;
  }
}
