/* EduOS Commercial UI Guard v21
   Final cross-platform polish layer. Loaded last to normalize legacy screens safely. */
:root{
  --eduos-page:#f4f7fb;--eduos-surface:#fff;--eduos-ink:#10213d;--eduos-muted:#64748b;
  --eduos-line:#dfe7f2;--eduos-primary:#1768e8;--eduos-primary-dark:#0f4fb7;
  --eduos-danger:#dc2626;--eduos-success:#16834b;--eduos-radius:18px;
  --eduos-shadow:0 12px 34px rgba(15,35,75,.08);--eduos-focus:0 0 0 4px rgba(23,104,232,.15)
}
*,*::before,*::after{box-sizing:border-box}
html{max-width:100%;overflow-x:hidden;-webkit-text-size-adjust:100%}
body{max-width:100%;overflow-x:hidden;text-rendering:optimizeLegibility;-webkit-font-smoothing:antialiased}
img,svg,video,canvas,iframe{max-width:100%}
img,video{height:auto}
iframe{border:0}
main,.container,.container-fluid,.portal-main,.portal-content,.ll-main,.content,.page-content{min-width:0;max-width:100%}

/* Typography and overflow safety */
h1,h2,h3,h4,h5,h6,p,span,strong,small,label,legend,a,button,th,td,li,dd,dt{
  overflow-wrap:anywhere;word-break:normal
}
h1,h2,h3,h4,h5,h6{line-height:1.2;text-wrap:balance}
p,.form-text,.helptext,.text-muted,.muted{line-height:1.55}
pre,code{max-width:100%;white-space:pre-wrap;overflow-wrap:anywhere}

/* Cards and panels */
.card,.portal-card,.page-card,.responsive-card,.ol-card,.ol-panel,.list-card,.panel,.dashboard-card,
[class*="-card"]:not(.card-img-overlay):not(.command-palette-kbd){
  min-width:0
}
.card,.portal-card,.page-card,.responsive-card,.ol-card,.ol-panel,.list-card,.panel,.dashboard-card{
  border-color:var(--eduos-line);border-radius:var(--eduos-radius);box-shadow:var(--eduos-shadow);
  overflow:visible;background-clip:padding-box
}
.card-body,.portal-card-body,.panel-body,.modal-body{min-width:0;padding:clamp(1rem,2.2vw,1.5rem)}
.card-header,.card-footer,.modal-header,.modal-footer{min-width:0;padding:1rem 1.25rem;border-color:var(--eduos-line)}
.card-title{margin-bottom:.45rem;line-height:1.25}
.card-text:last-child{margin-bottom:0}
.row>*{min-width:0}

/* Forms */
form{max-width:100%}
fieldset{min-width:0;border:0;padding:0;margin:0}
label,.form-label{display:block;margin-bottom:.4rem;font-weight:700;color:var(--eduos-ink);line-height:1.35}
input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="color"]),
select,textarea,.form-control,.form-select{
  display:block;width:100%;max-width:100%;min-height:46px;padding:.72rem .85rem;
  border:1px solid #cbd6e5;border-radius:12px;background:#fff;color:var(--eduos-ink);
  font:inherit;line-height:1.35;box-shadow:none;transition:border-color .16s,box-shadow .16s,background .16s
}
textarea,.form-control[type="textarea"]{min-height:112px;resize:vertical}
select,.form-select{padding-right:2.4rem}
input:focus,select:focus,textarea:focus,.form-control:focus,.form-select:focus{
  border-color:var(--eduos-primary);box-shadow:var(--eduos-focus);outline:0
}
input::placeholder,textarea::placeholder{color:#94a3b8;opacity:1}
input:disabled,select:disabled,textarea:disabled,.form-control:disabled{
  background:#eef2f7;color:#7b8798;cursor:not-allowed;opacity:1
}
.form-group,.mb-3:has(>label),.field-wrapper,.form-field{min-width:0;margin-bottom:1rem}
.form-text,.helptext,form small{display:block;margin-top:.35rem;color:var(--eduos-muted);font-size:.82rem}
.errorlist,.invalid-feedback,.field-error{margin:.4rem 0 0;padding-left:1.1rem;color:#b42318;font-size:.85rem}
.is-invalid,.error input,.error select,.error textarea{border-color:#dc2626!important}
.form-check{display:flex;align-items:flex-start;gap:.55rem;min-width:0}
.form-check-input,input[type="checkbox"],input[type="radio"]{flex:0 0 auto;margin-top:.2rem}
.input-group{display:flex;align-items:stretch;min-width:0;flex-wrap:nowrap}
.input-group>*{min-width:0}
.input-group>.form-control{flex:1 1 auto}

/* Buttons and action rows */
button,.btn,input[type="submit"],input[type="button"],input[type="reset"]{
  max-width:100%;min-height:42px;display:inline-flex;align-items:center;justify-content:center;gap:.45rem;
  padding:.66rem 1rem;border-radius:11px;font-weight:800;line-height:1.2;text-align:center;
  white-space:normal;overflow-wrap:anywhere;vertical-align:middle;text-decoration:none;cursor:pointer;
  transition:transform .14s,box-shadow .14s,background-color .14s,border-color .14s,color .14s
}
button:hover,.btn:hover,input[type="submit"]:hover{transform:translateY(-1px)}
button:focus-visible,.btn:focus-visible,a:focus-visible{outline:0;box-shadow:var(--eduos-focus)}
button:disabled,.btn.disabled,.btn:disabled{transform:none;cursor:not-allowed;opacity:.62}
.btn-primary{background:var(--eduos-primary);border-color:var(--eduos-primary);color:#fff}
.btn-primary:hover{background:var(--eduos-primary-dark);border-color:var(--eduos-primary-dark);color:#fff}
.btn-danger{background:var(--eduos-danger);border-color:var(--eduos-danger);color:#fff}
.btn-success{background:var(--eduos-success);border-color:var(--eduos-success);color:#fff}
.btn-sm{min-height:36px;padding:.48rem .75rem;font-size:.84rem}
.btn-lg{min-height:50px;padding:.82rem 1.2rem}
.btn-group,.action-group,.actions,.card-actions,.form-actions,.page-actions,.toolbar,.button-row{
  display:flex;align-items:center;gap:.65rem;flex-wrap:wrap;min-width:0
}
.btn-group>.btn{flex:0 1 auto}

/* Alerts, badges and chips */
.alert,.message,.notification,.callout{max-width:100%;border-radius:14px;padding:.85rem 1rem;line-height:1.5;overflow-wrap:anywhere}
.badge,.chip,.pill,.mini-pill{max-width:100%;white-space:normal;line-height:1.25;text-align:center}

/* Tables */
.table-responsive,.responsive-table-wrapper,[class*="table-wrap"]{width:100%;max-width:100%;overflow-x:auto;-webkit-overflow-scrolling:touch;border-radius:14px}
table,.table{width:100%;max-width:100%;border-collapse:separate;border-spacing:0}
th,td,.table th,.table td{vertical-align:middle;overflow-wrap:anywhere;word-break:normal}
th{font-weight:800}
td .btn,th .btn{margin:.12rem}

/* Navigation and headers */
.nav,.navbar-nav,.portal-nav,.ll-nav,.breadcrumb{min-width:0}
.nav-link,.navbar a,.portal-nav a,.ll-nav a{overflow-wrap:anywhere}
.dropdown-menu{max-width:min(92vw,360px);overflow-wrap:anywhere;border-radius:14px;box-shadow:0 18px 44px rgba(15,35,75,.16)}

/* Modals, drawers and floating layers */
.modal,.offcanvas,[role="dialog"]{max-width:100vw}
.modal-dialog{width:auto;max-width:min(94vw,720px);margin:1.5rem auto}
.modal-content{max-height:calc(100dvh - 3rem);overflow:hidden;border:0;border-radius:20px;box-shadow:0 28px 70px rgba(2,12,27,.28)}
.modal-body{overflow-y:auto}
.modal-header,.modal-footer{display:flex;align-items:center;gap:.75rem;flex-wrap:wrap}
.modal-header .btn-close{margin-left:auto;min-height:auto;padding:.65rem}
.toast-container{max-width:calc(100vw - 1.5rem)}

/* Grid safeguards */
.grid,.cards-grid,.dashboard-grid,.stats-grid,[class*="card-grid"]{min-width:0}
[class*="grid-template-columns"]>*{min-width:0}

/* Prevent fixed widgets from covering content */
body{padding-bottom:env(safe-area-inset-bottom)}
[style*="position: fixed"],[style*="position:fixed"]{max-width:calc(100vw - 16px)}

/* Commercial empty states */
.empty-state,.no-data,.empty-card{padding:clamp(1.5rem,4vw,3rem);text-align:center;border:1px dashed #cbd6e5;border-radius:18px;background:rgba(255,255,255,.72)}

/* Mobile-first correction layer */
@media(max-width:767.98px){
  :root{--eduos-radius:16px}
  body{font-size:15px}
  main,.container,.container-fluid,.portal-content,.ll-main,.page-content{padding-left:12px!important;padding-right:12px!important}
  h1{font-size:clamp(1.55rem,7vw,2rem)}h2{font-size:clamp(1.3rem,6vw,1.7rem)}
  .row{--bs-gutter-x:1rem}
  .card,.portal-card,.page-card,.ol-card,.ol-panel,.panel{border-radius:16px}
  .card-body,.portal-card-body,.panel-body,.modal-body{padding:1rem}
  .card-header,.card-footer,.modal-header,.modal-footer{padding:.9rem 1rem}
  .d-flex.justify-content-between,.page-header,.page-head,.ll-page-head,.portal-page-head{
    align-items:stretch!important;flex-direction:column;gap:.75rem
  }
  .d-flex.justify-content-between>.btn,.page-actions>.btn,.form-actions>.btn,.card-actions>.btn{width:100%}
  .btn-group,.action-group,.actions,.card-actions,.form-actions,.page-actions,.toolbar,.button-row{align-items:stretch}
  .btn-group>.btn,.action-group>.btn,.actions>.btn,.card-actions>.btn,.form-actions>.btn,.page-actions>.btn{flex:1 1 100%;width:100%}
  button,.btn,input[type="submit"],input[type="button"],input[type="reset"]{min-height:44px}
  .input-group{flex-wrap:wrap;gap:.5rem}
  .input-group>*{width:100%;border-radius:11px!important}
  .table-responsive,.responsive-table-wrapper{margin-inline:0}
  th,td,.table th,.table td{padding:.72rem .65rem;min-width:110px;white-space:normal!important}
  th:first-child,td:first-child{min-width:140px}
  .modal-dialog{max-width:calc(100vw - 20px);margin:10px auto}
  .modal-content{max-height:calc(100dvh - 20px);border-radius:16px}
  .dropdown-menu{max-width:calc(100vw - 24px)}
  .ll-nav,.navbar-nav{gap:.35rem}
}

@media(max-width:420px){
  .badge,.chip,.pill,.mini-pill{font-size:.72rem}
  .card-body,.portal-card-body,.panel-body{padding:.9rem}
  main,.container,.container-fluid,.portal-content,.ll-main,.page-content{padding-left:10px!important;padding-right:10px!important}
}

/* Dark mode compatibility */
body.theme-dark .card,body.theme-dark .portal-card,body.theme-dark .page-card,body.theme-dark .panel{border-color:rgba(148,163,184,.18)}
body.theme-dark input:not([type="checkbox"]):not([type="radio"]),body.theme-dark select,body.theme-dark textarea,
body.theme-dark .form-control,body.theme-dark .form-select{background:#111c2d;color:#e5eefc;border-color:rgba(148,163,184,.28)}
body.theme-dark input::placeholder,body.theme-dark textarea::placeholder{color:#8291a7}
