/* ======================================================================
   SHEFAA Responsive Adaptive UI v1.0 - 2026-09-30
   Central responsive layer for desktop, tablet and mobile screens.
   This file intentionally changes presentation only; no server controls,
   IDs, postback behavior or business logic are modified.
   ====================================================================== */

:root{
  --shefaa-touch:44px;
  --shefaa-mobile-gap:10px;
  --shefaa-tablet-gap:14px;
}

html{
  width:100%;
  max-width:100%;
  -webkit-text-size-adjust:100%;
  text-size-adjust:100%;
}
body{
  width:100%;
  max-width:100%;
  overflow-x:hidden;
}
form{max-width:100%}
img,svg,video,canvas{max-width:100%;height:auto}
iframe{max-width:100%}
input,select,textarea,button{max-width:100%;font-family:inherit}
textarea{resize:vertical}

/* Never let the main application shell force horizontal page scrolling. */
.container,.app-layout,.main-with-sidebar,.master-page,.panel,.master-card,
.home-section,.welcome-panel,.data-window,.card,.box,.page,.sheet,
.report-page,.report-wrap,.print-page,.print-wrap,.receipt,.invoice{
  max-width:100%;
}

/* Shared horizontal scrolling surface used for wide data grids. */
.responsive-auto-scroll,
.table-wrap,.master-grid-wrap,.grid-wrap,.detail-grid-wrap,.import-preview-wrap,
.claims-grid-wrap,.results-wrap,.report-grid-wrap,.table-container{
  width:100%;
  max-width:100%;
  overflow-x:auto!important;
  overflow-y:auto;
  -webkit-overflow-scrolling:touch;
  overscroll-behavior-inline:contain;
  scrollbar-width:thin;
}
.responsive-auto-scroll{
  position:relative;
  border-radius:10px;
}
.responsive-auto-scroll > table{margin-inline:auto}
.responsive-auto-scroll.is-wide-table{
  box-shadow:inset 12px 0 12px -14px rgba(18,68,103,.28),
             inset -12px 0 12px -14px rgba(18,68,103,.28);
}

/* Touch friendly controls without affecting desktop density. */
body.device-phone button,
body.device-phone input[type="button"],
body.device-phone input[type="submit"],
body.device-phone input[type="reset"],
body.device-phone a.btn,
body.device-phone .btn,
body.device-phone .master-btn,
body.device-phone .grid-action-btn,
body.device-phone .system-back-btn,
body.device-phone .back-btn,
body.device-phone .return-btn{
  min-height:var(--shefaa-touch);
}

/* Modals must stay inside the visible screen on every device. */
.modal-panel,.modal-overlay,.import-modal-overlay,.overlay,
[class*="modal-overlay"],[class*="-overlay"]{
  max-width:100vw;
}
.edit-card,.import-card,.modal-card,.modal-content,[class*="modal-card"]{
  max-width:calc(100vw - 24px)!important;
  max-height:calc(100dvh - 24px)!important;
  overflow:auto;
  -webkit-overflow-scrolling:touch;
}

/* ===== TABLET: landscape / medium screens ===== */
@media (min-width:768px) and (max-width:1199px){
  .topbar{padding-inline:18px;gap:14px}
  .brand-text strong{font-size:18px}
  .container{padding:18px;min-height:calc(100vh - 170px)}
  .app-layout{grid-template-columns:205px minmax(0,1fr)}
  .side-menu{margin:18px 12px 18px 0}
  .side-menu-link{padding-inline-start:12px;padding-inline-end:43px;font-size:12.5px}
  .panel,.home-section{padding:18px}
  .welcome-panel{padding:22px}
  .home-cards{grid-template-columns:repeat(2,minmax(0,1fr))}
  .filters,.form-grid{grid-template-columns:repeat(2,minmax(0,1fr))}
  .wide{grid-column:span 2}

  .master-fields{gap:10px;padding:14px}
  .master-field.w-xs,.master-field.w-sm,.master-field.w-md,
  .master-field.w-lg,.master-field.w-xl{flex:1 1 calc(50% - 10px);max-width:none}
  .master-field.w-full{flex-basis:100%}
  .master-actions-bar,.actions,.grid-toolbar,.grid-toolbar-group,.master-header-actions{
    flex-wrap:wrap;
  }

  /* About-system: keep menu on the right and content comfortably readable. */
  .about-system-drawer{width:min(98vw,1180px)!important}
  .about-drawer-body{grid-template-columns:minmax(205px,24%) minmax(0,1fr)!important}
  .system-map-list,.guide-grid{grid-template-columns:1fr!important}
}

/* ===== TABLET portrait / compact laptop ===== */
@media (min-width:768px) and (max-width:930px){
  .app-layout{display:block!important}
  .side-menu{
    position:static!important;
    margin:12px 14px 0!important;
    display:grid!important;
    grid-template-columns:repeat(4,minmax(0,1fr));
    border-radius:12px;
  }
  .side-menu-heading{grid-column:1/-1}
  .side-menu-section-label{grid-column:1/-1}
  .side-menu-link{
    min-height:50px;
    border-bottom:0;
    border-left:1px solid #e8f0f5;
    justify-content:center;
    text-align:center;
    padding:10px 8px 10px 34px!important;
  }
  .side-menu-link:before{right:8px}
  .main-with-sidebar{padding:14px!important}
  .master-grid,.grid{min-width:720px}
}

/* ===== MOBILE: phones and small tablets ===== */
@media (max-width:767px){
  html,body{min-width:0!important;width:100%!important}
  body{font-size:14px}

  /* Header stacks naturally and never overflows. */
  .topbar{
    min-height:auto!important;
    padding:9px 10px!important;
    gap:8px!important;
    flex-wrap:wrap;
    align-items:center;
  }
  .brand-wrap{gap:9px;flex:1 1 210px;min-width:0}
  .header-logo{width:48px!important;height:44px!important;flex:0 0 48px}
  .brand-text{min-width:0;flex:1}
  .brand-text strong{
    display:block;
    max-width:100%;
    font-size:14px!important;
    line-height:1.45;
    white-space:normal!important;
    overflow-wrap:anywhere;
  }
  .brand-text span{display:none!important}
  .userbox{margin-inline-start:auto;gap:7px;max-width:100%}
  .user-name{display:none!important}
  #btnLogout,.logout-btn{
    min-height:40px!important;
    padding:8px 11px!important;
    font-size:11px!important;
    white-space:nowrap;
  }

  .nav{
    min-height:0!important;
    padding:6px 10px!important;
    overflow-x:auto;
    -webkit-overflow-scrolling:touch;
  }
  .nav a,.nav .home-nav-btn{
    min-height:42px!important;
    padding:8px 12px!important;
    margin:0!important;
    flex:0 0 auto;
  }

  .container,.main-with-sidebar,.embedded-main{
    width:100%!important;
    max-width:100%!important;
    padding:10px!important;
    margin:0!important;
  }
  .panel,.home-section,.welcome-panel,.master-card{
    border-radius:11px;
  }
  .panel,.home-section{padding:12px!important}
  .welcome-panel{padding:16px!important;margin-bottom:12px}
  .welcome-panel h1{font-size:20px!important;line-height:1.55}
  .welcome-panel p{font-size:12px}
  .welcome-panel:after{font-size:120px;left:10px}

  .page-title,.section-title-row,.master-page-header,.master-card-header,
  .grid-toolbar,.master-search-row,.master-header-actions{
    align-items:stretch!important;
    flex-direction:column!important;
    gap:8px!important;
  }
  .page-title h1,.master-page-header h1{font-size:20px!important}
  .page-title h2,.master-card-title h2{font-size:17px!important}
  .page-description,.master-page-header p{font-size:12px!important}

  /* Main app side menu becomes a compact mobile menu above content. */
  .app-layout{display:block!important;width:100%!important}
  .side-menu{
    position:static!important;
    top:auto!important;
    width:auto!important;
    margin:10px 10px 0!important;
    display:grid!important;
    grid-template-columns:repeat(2,minmax(0,1fr))!important;
    box-shadow:0 3px 12px rgba(20,63,90,.05);
  }
  .side-menu-heading,.side-menu-section-label{grid-column:1/-1!important}
  .side-menu-heading{padding:11px 12px!important}
  .side-menu-heading-icon{width:32px;height:32px}
  .side-menu-link{
    min-height:48px!important;
    border-bottom:1px solid #e8f0f5!important;
    border-left:1px solid #e8f0f5;
    padding:9px 36px 9px 7px!important;
    font-size:11px!important;
    line-height:1.45;
  }
  .side-menu-link:before{right:8px!important;width:22px;height:22px}
  .side-menu-link.active{padding-right:34px!important}

  /* Cards and form grids collapse to one column. */
  .home-cards,.filters,.form-grid,.import-mapping-grid,.doctor-form-grid{
    grid-template-columns:1fr!important;
  }
  .wide,.span-2,.span-3,.span-4,.s3,.s4{grid-column:1/-1!important}
  .home-card{padding:14px;gap:10px}
  .home-card-icon{width:43px;height:43px}

  .master-fields{display:block!important;padding:11px!important}
  .master-field,.master-field.w-xs,.master-field.w-sm,.master-field.w-md,
  .master-field.w-lg,.master-field.w-xl,.master-field.w-full{
    width:100%!important;
    max-width:none!important;
    min-width:0!important;
    margin-bottom:9px!important;
    flex:1 1 100%!important;
  }
  .master-field:last-child{margin-bottom:0!important}
  .master-label{min-width:96px}
  .master-control,.master-checks,.input,.ctrl,
  input[type="text"],input[type="password"],input[type="number"],input[type="date"],
  input[type="time"],input[type="email"],input[type="tel"],select,textarea{
    max-width:100%!important;
  }

  /* 16px prevents iOS/Android browsers from zooming into focused controls. */
  input[type="text"],input[type="password"],input[type="number"],input[type="date"],
  input[type="time"],input[type="email"],input[type="tel"],select,textarea,
  .input,.master-control,.ctrl{
    font-size:16px!important;
  }

  .master-actions-bar,.actions,.button-row,.action-row,.toolbar-actions,
  .grid-toolbar-group,.master-header-actions{
    display:flex!important;
    flex-wrap:wrap!important;
    width:100%;
    gap:7px!important;
  }
  .master-actions-bar > *, .actions > *, .button-row > *, .action-row > *,
  .toolbar-actions > *{
    flex:1 1 135px;
  }
  .master-btn,.btn,.grid-action-btn,.system-back-btn,.back-btn,.return-btn{
    white-space:normal;
    line-height:1.35;
  }

  .toolbar-select{min-width:0!important;width:100%;height:42px}
  .master-search-box{display:block!important;width:100%!important;max-width:none!important}
  .master-search-box .master-label{max-width:none!important;width:100%;margin-bottom:5px!important}
  .master-search-box .master-control{width:100%!important;max-width:none!important}

  /* Grids remain full-detail and scroll horizontally instead of shrinking text unreadably. */
  .master-grid,.grid,.detail-grid,.import-preview-grid,
  table[class*="grid"],table[class*="Grid"]{
    width:max-content;
    min-width:700px;
  }
  .master-grid th,.master-grid td,.grid th,.grid td,
  table[class*="grid"] th,table[class*="grid"] td{
    white-space:nowrap;
  }
  .master-grid th,.master-grid td,.grid th,.grid td{padding:8px 7px!important;font-size:12px!important}
  .grid-pager table,.pager table{min-width:0!important;width:auto!important}
  .grid-pager a,.grid-pager span,.pager a,.pager span{min-width:34px;min-height:34px;line-height:26px}

  /* Modal and popup layout for phones. */
  .modal-panel,.modal-overlay,.import-modal-overlay,[class*="modal-overlay"]{
    padding:8px!important;
    align-items:flex-start!important;
    overflow:auto!important;
  }
  .edit-card,.import-card,.modal-card,.modal-content,[class*="modal-card"]{
    width:100%!important;
    max-width:100%!important;
    max-height:calc(100dvh - 16px)!important;
    padding:12px!important;
    border-radius:12px!important;
  }
  .import-file{min-width:0!important;width:100%!important}
  .mapping-row{grid-template-columns:1fr!important}

  /* About-system on mobile: two clear top buttons + content below. */
  .about-system-drawer{width:100vw!important;max-width:100vw!important}
  .about-drawer-head{min-height:64px!important;padding:10px!important}
  .about-drawer-title strong{font-size:16px!important}
  .about-drawer-title span{font-size:8px!important}
  .about-drawer-body{display:flex!important;flex-direction:column!important;min-height:0!important}
  .about-drawer-menu{
    width:100%!important;
    position:sticky!important;
    top:0;
    z-index:5;
    display:grid!important;
    grid-template-columns:1fr 1fr!important;
    gap:7px!important;
    padding:8px!important;
  }
  .about-drawer-menu:before{grid-column:1/-1!important;margin:0!important}
  .about-drawer-tab{min-width:0!important;min-height:48px!important;padding:7px!important;font-size:10px!important}
  .about-drawer-tab-icon{width:30px!important;height:30px!important}
  .about-drawer-tab-arrow{display:none!important}
  .about-drawer-content{padding:10px 8px 20px!important;min-width:0!important}
  .about-content-heading{padding:11px!important}
  .about-content-heading h2{font-size:17px!important}
  .system-map-list,.guide-grid,.system-map-items{grid-template-columns:1fr!important}
  .system-map-section summary{padding:10px!important}
  .system-map-item{min-width:0!important;overflow-wrap:anywhere}
  .guide-card{padding:12px!important}

  /* Print/receipt pages when viewed (not printed) on a phone. */
  .invoice,.receipt,.print-page,.print-wrap,.report-page,.report-wrap,.sheet{
    width:100%!important;
    min-width:0!important;
    min-height:0!important;
    margin:0 auto!important;
    padding:10px!important;
  }

  .footer{padding:12px 10px;font-size:10px}
}

/* Extra-small phones */
@media (max-width:480px){
  .side-menu{grid-template-columns:1fr!important}
  .side-menu-heading,.side-menu-section-label{grid-column:1!important}
  .home-card{align-items:flex-start}
  .card-arrow{font-size:18px}
  .master-field{display:block!important}
  .master-label{
    width:100%!important;
    max-width:none!important;
    min-width:0!important;
    margin-bottom:5px!important;
  }
  .master-control,.master-checks{width:100%!important}
  .doctor-financial-row{grid-template-columns:1fr!important}
  .doctor-financial-row .master-label{max-width:none!important;flex-basis:auto!important}
  .doctor-financial-row .master-control{width:100%!important;max-width:none!important}
  .about-system-trigger{min-width:0!important;width:100%!important}
  .about-drawer-tab{grid-template-columns:28px minmax(0,1fr)!important}
}

/* Landscape phones: make overlays use the shorter screen efficiently. */
@media (max-width:900px) and (orientation:landscape){
  .edit-card,.import-card,.modal-card,.modal-content,[class*="modal-card"]{
    max-height:calc(100dvh - 12px)!important;
  }
  .about-drawer-head{min-height:56px!important;padding-block:7px!important}
  .about-drawer-content{padding-bottom:12px!important}
}

/* Keep print output unchanged by responsive screen rules. */
@media print{
  html,body{overflow:visible!important;width:auto!important;max-width:none!important}
  .responsive-auto-scroll{overflow:visible!important;box-shadow:none!important}
  .responsive-auto-scroll > table{width:100%}
}

/* ===== Standalone / special screens ===== */
@media screen and (max-width:767px){
  /* Appointment display screens still remain usable on a phone/tablet. */
  .display-shell{
    height:auto!important;
    min-height:100dvh!important;
    grid-template-rows:auto minmax(0,1fr) auto!important;
    overflow:auto!important;
  }
  .display-header{
    grid-template-columns:1fr auto!important;
    gap:8px!important;
    min-height:64px!important;
    padding:7px 9px!important;
  }
  .display-header .header-title{display:none!important}
  .display-main{min-height:520px;padding:7px!important;overflow:auto!important}
  .schedule-grid{height:auto!important;min-height:500px!important;grid-template-columns:1fr!important;grid-template-rows:none!important;overflow:visible!important}
  .ticker-label{min-width:95px!important}

  .tv-shell{
    width:100%!important;
    height:auto!important;
    min-height:100dvh!important;
    grid-template-rows:auto minmax(0,1fr) auto!important;
    overflow:auto!important;
  }
  .tv-main,.grid-panel{width:100%!important;max-width:100%!important;overflow-x:auto!important;-webkit-overflow-scrolling:touch}
  .tv-table{width:max-content!important;min-width:920px!important}
  .tv-title h1{font-size:18px!important}

  /* Login: image/branding area moves above the form on narrow devices. */
  .login-world-frame{
    width:100%!important;
    min-height:0!important;
    grid-template-columns:1fr!important;
    margin:0!important;
  }
  .login-page{padding:10px!important;align-items:flex-start!important}

  /* Standalone lookup/popups. */
  .lookup{width:100%!important;max-width:100%!important;padding:8px!important}
  .lookup .filters{grid-template-columns:1fr!important}
  .lookup .actions{display:flex!important;width:100%!important}
  .lookup .actions > *{flex:1 1 0}

  /* Receipts/reports are fitted to screen while preserving print CSS. */
  .receipt,.invoice,.report,.print-sheet,.print-container{
    width:100%!important;
    max-width:100%!important;
    min-width:0!important;
    min-height:0!important;
    margin:0!important;
    padding:10px!important;
  }
  .receipt .header,.invoice .header,.report .header{
    grid-template-columns:1fr!important;
    gap:8px!important;
    text-align:center!important;
  }

  /* A standalone report may contain an unwrapped wide table: keep it readable. */
  body > form{width:100%;max-width:100%}
  body > form > table,
  .receipt > table,.invoice > table,.report > table{
    max-width:100%;
  }
}
