/* ==========================================================================
   LACMS responsive layer — loads AFTER every other stylesheet.
   Goal: the same design on phones, tablets, laptops and large screens.
   Breakpoints: 1400 / 1050 (sidebar becomes a drawer) / 768 / 576 / 400.
   ========================================================================== */

/* ---------- Base safety (all sizes) ---------- */
html{-webkit-text-size-adjust:100%;text-size-adjust:100%;scroll-padding-top:calc(var(--lacms-topbar-height,64px) + 12px)}
body{overflow-x:hidden}
img,svg,video,canvas,iframe{max-width:100%}
img,video{height:auto}
.lacms-main-content,.orlms-main-content{min-width:0}
.lacms-main-content>*,.orlms-main-content>*{min-width:0;max-width:100%}
.table-responsive{-webkit-overflow-scrolling:touch}
.card,.lo-card,.lacms-dashboard-panel{min-width:0}
h1,h2,h3,h4,.lo-head h1,.lo-head p{overflow-wrap:anywhere}
.lo-code,.lo-status{white-space:nowrap}
pre,code{white-space:pre-wrap;overflow-wrap:anywhere}

/* Very large screens: keep line lengths and cards from stretching forever */
@media (min-width:1700px){
  .lacms-main-content>*,.orlms-main-content>*{max-width:1640px;margin-left:auto;margin-right:auto;width:100%}
}

/* Small laptops */
@media (max-width:1400px){
  .lacms-problem-strip{grid-template-columns:repeat(3,1fr)}
}

/* ---------- Tablet and below: sidebar becomes a drawer (<=1050px) ---------- */
@media (max-width:1050px){
  /* A saved "collapsed" desktop state must never leak into the mobile drawer */
  body,body.sidebar-collapsed{--side:min(86vw,300px);--lacms-sidebar-width:min(86vw,300px)}
  body.sidebar-collapsed .lacms-topbar,
  body.sidebar-collapsed .orlms-topbar{left:0 !important}
  body.sidebar-collapsed .lacms-sidebar,
  body.sidebar-collapsed .orlms-sidebar{width:min(86vw,300px) !important}
  body.sidebar-collapsed .lacms-sidebar-brand{padding:1rem !important;justify-content:flex-start !important;flex-direction:row !important;gap:.7rem !important}
  body.sidebar-collapsed .lacms-sidebar-logo{width:60px !important;height:60px !important;max-width:60px !important;max-height:60px !important}
  body.sidebar-collapsed .lacms-sidebar-brand>div{display:flex !important}
  body.sidebar-collapsed .lacms-sidebar-section{display:block !important}
  body.sidebar-collapsed .lacms-office-card{display:flex !important}
  body.sidebar-collapsed .lacms-sidebar-link{display:grid !important;justify-content:normal !important;padding:.6rem .75rem !important;min-height:45px !important;border-radius:99px !important;margin:0 !important}
  body.sidebar-collapsed .lacms-sidebar-link>span,
  body.sidebar-collapsed .lacms-sidebar-link>em{display:inline !important}
  body.sidebar-collapsed .lacms-sidebar-link>i{font-size:.92rem !important}
  body.sidebar-collapsed .lacms-sidebar-footer>div{display:flex !important}
  body.sidebar-collapsed .lacms-sidebar-footer{justify-content:flex-start !important;padding:.7rem !important;margin:.65rem !important}
  body.sidebar-collapsed .lacms-collapse-toggle{display:none !important}

  .lacms-sidebar,.orlms-sidebar{height:100vh;height:100dvh;width:min(86vw,300px);max-width:100%;overflow-y:auto;overscroll-behavior:contain;z-index:1060;transition:transform .22s ease}
  .lacms-sidebar-backdrop,.orlms-sidebar-backdrop{z-index:1055}
  body.sidebar-open{overflow:hidden}
  .lacms-sidebar-link{min-height:48px}

  .lacms-topbar,.orlms-topbar{padding:0 .8rem}
  .lacms-topbar-actions,.orlms-topbar-actions{gap:.5rem}
  .lacms-main-content,.orlms-main-content{margin-left:0 !important;padding-left:1rem;padding-right:1rem}

  /* Layout blocks that were still multi-column on tablets */
  .lacms-dashboard-hero{grid-template-columns:1fr}
  .lacms-problem-strip{grid-template-columns:repeat(2,1fr)}
  .lacms-dashboard-module-grid,.lacms-status-grid{grid-template-columns:repeat(2,1fr)}
}

/* ---------- Tablet portrait (<=768px) ---------- */
@media (max-width:768px){
  /* 16px inputs stop iOS Safari from zooming the page when a field is tapped */
  .form-control,.form-select,input:not([type=checkbox]):not([type=radio]):not([type=range]),select,textarea{font-size:16px !important}
  .form-control:not(.form-control-sm):not(.form-control-lg),.form-select:not(.form-select-sm):not(.form-select-lg){min-height:44px}
  textarea.form-control{min-height:88px}
  .btn{min-height:42px;display:inline-flex;align-items:center;justify-content:center;gap:.4rem}
  .btn-sm{min-height:36px}
  .btn-group{flex-wrap:wrap}

  /* Headers, toolbars, filter bars wrap instead of overflowing */
  .lo-head,.lacms-module-header,.lacms-dashboard-panel-heading,.admin-table-footer,.sync-table-footer{flex-wrap:wrap}
  .lo-head{flex-direction:column;align-items:stretch}
  .lo-head .btn,.lo-head form .btn{flex:1 1 auto}
  .lo-head>div:last-child:not(:first-child){display:flex;flex-wrap:wrap;gap:.5rem}
  .lacms-dashboard-hero-actions{width:100%}
  .lacms-dashboard-hero-actions .btn{flex:1 1 160px}
  .card-header.d-flex,.lo-card>.card-header.d-flex{flex-wrap:wrap;gap:.5rem}

  /* Readable text: several components used 7–10px type */
  .lo-table td,.lo-table th,.table td,.table th{font-size:.8rem}
  .lo-table thead th,.table thead th{font-size:.7rem}
  .lo-stat small,.lo-grid small,.lo-flow small,.lo-history small,.lo-participant small,.lo-conflict small,.lo-calendar-date{font-size:.7rem}
  .lo-stat strong{font-size:1.2rem}
  .lo-grid strong,.lo-flow strong,.lo-history strong,.lo-participant strong,.lo-conflict strong,.lo-calendar-time{font-size:.8rem}
  .lo-head p,.lo-alert,.lo-eyebrow{font-size:.78rem}
  .lo-status,.lo-code{font-size:.7rem}
  .lacms-dashboard-feature-list small,.lacms-intelligence-card p,.lacms-empty-workspace span,.lacms-reminder-preview small,.lacms-login-note{font-size:.76rem}
  .lacms-reminder-preview label,.lacms-search-preview label,.lacms-login-card .form-label{font-size:.78rem}

  .lacms-prev-next{flex-direction:column}
  .lacms-prev-next>a{width:100%;min-width:0}
  .lo-participant{flex-wrap:wrap}

  /* Dropdowns and system pop-ups never exceed the screen */
  .dropdown-menu{max-width:calc(100vw - 1rem)}
  .lacms-subsystem-menu{width:min(320px,calc(100vw - 1rem)) !important}
  .swal2-popup{width:min(32em,calc(100vw - 1.5rem)) !important;padding:1.1rem !important;font-size:.95rem !important}
  .swal2-actions{flex-wrap:wrap;gap:.5rem}
  .swal2-html-container{overflow-wrap:anywhere}

  /* Modals: use the screen, scroll the body, keep buttons reachable */
  .modal-dialog{margin:.6rem auto;max-width:calc(100vw - 1.2rem)}
  .modal-dialog.modal-lg,.modal-dialog.modal-xl{max-width:calc(100vw - 1.2rem)}
  .modal-content{max-height:calc(100dvh - 1.2rem)}
  .modal-body{overflow-y:auto;-webkit-overflow-scrolling:touch}
  .modal-footer{flex-wrap:wrap;gap:.5rem}
  .modal-footer .btn{flex:1 1 130px}
}

/* ---------- Phones (<=576px) ---------- */
@media (max-width:576px){
  .lacms-main-content,.orlms-main-content{padding-left:.7rem;padding-right:.7rem}
  .lacms-topbar-brand strong{max-width:46vw;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
  .lacms-user-button{padding:.25rem}
  .lacms-avatar{width:36px;height:36px}

  .lo-head{padding:.9rem}
  .lo-head h1{font-size:1.2rem}
  .lo-card>.card-header{padding:.75rem .85rem}
  .lo-stat{min-height:72px}
  .lacms-dashboard-hero h1{font-size:1.5rem}

  /* One column everywhere */
  .lacms-problem-strip,.lacms-dashboard-module-grid,.lacms-status-grid,
  .lo-flow,.lo-grid,.lacms-context-strip,.lacms-workflow-grid,
  .lacms-feature-grid,.lacms-section-list,.lacms-reminder-preview,
  .lacms-search-preview,.lacms-record-fields.two-columns{grid-template-columns:1fr}
  .lacms-reminder-preview .wide,.lacms-search-preview .wide{grid-column:auto}

  /* Tables: swipe sideways inside their card, with a visible hint of overflow */
  .table-responsive{border-radius:10px;box-shadow:inset -10px 0 8px -8px rgba(15,33,55,.18)}
  .table-responsive .table{margin-bottom:0}
  .table-responsive .table th,.table-responsive .table td{padding:.55rem .6rem}

  /* Action buttons in cells keep a comfortable tap size */
  td .btn,td .btn-sm{min-height:38px;min-width:38px}
  td form{display:inline-block}

  /* Forms: full-width controls and stacked button rows */
  .row>[class*="col-"]{min-width:0}
  .d-flex.gap-2:not(.flex-nowrap),.d-flex.gap-3:not(.flex-nowrap){flex-wrap:wrap}
  .modal-dialog{margin:.4rem auto}

  /* Pagination and footer rows wrap */
  .pagination{flex-wrap:wrap;gap:.25rem}
  .admin-table-footer,.sync-table-footer{flex-direction:column;align-items:flex-start;gap:.5rem}
}

/* ---------- Small phones (<=400px) ---------- */
@media (max-width:400px){
  .lacms-main-content,.orlms-main-content{padding-left:.55rem;padding-right:.55rem}
  .lo-head h1{font-size:1.1rem}
  .btn{padding-left:.7rem;padding-right:.7rem}
  .lo-head .btn,.lacms-dashboard-hero-actions .btn{flex:1 1 100%}
  .lacms-topbar-brand strong{max-width:38vw}
}

/* ---------- Short landscape phones ---------- */
@media (max-height:480px) and (orientation:landscape){
  .lacms-sidebar-logo{width:44px !important;height:44px !important}
  .lacms-office-card{display:none !important}
  .modal-dialog{margin:.4rem auto}
  .modal-content{max-height:calc(100dvh - .8rem);border-radius:.5rem}
}

/* ---------- Touch devices: bigger targets, no sticky hover ---------- */
@media (pointer:coarse){
  .dropdown-item{padding-top:.6rem;padding-bottom:.6rem}
  .form-check-input{width:1.25em;height:1.25em}
  .lacms-menu-button{width:44px;height:44px}
  .page-link{min-width:40px;min-height:40px;display:inline-flex;align-items:center;justify-content:center}
}

/* ---------- Login, OTP, forgot/reset password pages ---------- */
@media (max-width:950px){
  .login-shell,.lacms-login-shell{min-height:100dvh}
  .login-brand-panel,.lacms-login-brand-panel{min-height:0 !important;padding:1.6rem 1.25rem !important}
  .lacms-login-brand-content h1{font-size:clamp(1.6rem,7vw,2.4rem)}
  .lacms-login-brand-content>p{font-size:.88rem;margin-top:.6rem}
}
/* Sign-in page: the page itself must scroll (it was locked with overflow:hidden),
   so the privacy notice at the bottom can always be reached on phones, tablets
   and short laptop windows. */
@media (max-width:992px),(max-height:720px){
  html,body{height:auto !important;min-height:100%;overflow-x:hidden !important;overflow-y:auto !important;-webkit-overflow-scrolling:touch}
  .login-wrapper{height:auto !important;min-height:100vh;min-height:100dvh;overflow:visible !important}
  .login-side{padding-bottom:calc(2rem + env(safe-area-inset-bottom,0px)) !important}
}
@media (max-width:992px){
  /* login.php: show the sign-in form without scrolling past a tall banner */
  .login-wrapper{min-height:100dvh}
  .brand-side{min-height:0 !important;padding:1.5rem 1.25rem !important}
  .login-side{min-height:0 !important;padding:1.25rem !important}
  .brand-side .brand-features{display:none !important}
}
@media (max-width:600px){
  .login-card,.lacms-login-card{padding:1.1rem !important;border-radius:14px}
  .lacms-login-features,.brand-features{display:none !important}
  .login-card .form-control,.lacms-login-card .form-control{font-size:16px}
  .lacms-login-card-heading p,.lacms-login-card-heading>span{font-size:.78rem}
}

/* ---------- Print: keep pages exactly as designed ---------- */
@media print{
  .lacms-sidebar,.orlms-sidebar,.lacms-topbar,.orlms-topbar,.lacms-sidebar-backdrop{display:none !important}
  .lacms-main-content,.orlms-main-content{margin:0 !important;padding:0 !important}
  body{overflow:visible}
}
