/* query legacy pages - shared non-destructive beautify (2026-07-08) */
/* element/attribute selectors only; no markup changes required */
body{margin:8px;font-family:"Microsoft JhengHei","PingFang TC","Noto Sans TC",Arial,sans-serif;color:#1f2937;}
table{max-width:100%;}
td font,th font{font-size:15px;}
font[size="2"]{font-size:14px;}
th{padding:4px 6px;}
td{padding:3px 5px;}
tr[bgcolor="silver"]{background:#dce6f5;}
tr[bgcolor="silver"] th font{color:#0b3d91;}
input[type=text],input[type=password],select{padding:3px 6px;border:1px solid #9db2c8;border-radius:6px;font-size:15px;background:#fff;}
input[type=submit],input[type=button]{padding:4px 12px;border:1px solid #2f6f5f;border-radius:6px;background:#3d8a76;color:#fff;font-size:15px;cursor:pointer;}
input[type=submit]:hover,input[type=button]:hover{background:#2f6f5f;}
/* category header labels (bgcolor=sandybrown + white font) - force high contrast in every context */
table[bgcolor="sandybrown"]{background:#9a4a1e !important;border-color:#7a3a15 !important;}
table[bgcolor="sandybrown"] font,table[bgcolor="sandybrown"] td,table[bgcolor="sandybrown"] th{color:#ffffff !important;font-size:15px !important;font-weight:700;}
@media (max-width:640px){
  body{margin:4px;}
  input[type=text],select{max-width:95%;}
}

/* ------------------------------------------------------------------
   mobile: stop squeezing fixed-width legacy tables (2026-07-29)
   Reported by teachers: on a phone the layout is "cut off" and hard to
   operate. Cause: line 4 above forces <table width="650"> down to the
   ~360px viewport. Columns collapse to their min-content - a CJK label
   cell becomes one glyph per line - and cells that cannot shrink any
   further (rows of <select>) spill past the right edge and get clipped.
   Fix: let tables that declare a FIXED PIXEL width keep their natural
   width and let the page scroll sideways instead. Tables declared in %
   are fluid and keep the max-width:100% guard.
   [width$="%"] is what distinguishes the two - no markup change needed.
   Scoped to `screen` so print pagination (see @media print below) and
   the 2026-07-21 fixed-row report fix stay untouched.
   ------------------------------------------------------------------ */
/* html:not([data-pt-desktop]) guard: pages that include ui_head.asp are also
   shown inside the portal's content iframe, which is narrower than the window,
   so the media query alone would put desktop users into phone styling between
   900 and 1188px. portal.js stamps the attribute from the real window width;
   for pages opened outside the portal it is simply never set. */
@media screen and (max-width:900px){
  html:not([data-pt-desktop]) table[width]:not([width$="%"]){max-width:none;}

  /* iOS Safari zooms the page in whenever a focused field is under 16px,
     then leaves it zoomed - a large part of the "hard to operate" report.
     16px on the controls themselves stops the zoom; visual size is
     nearly unchanged (was 15px). */
  html:not([data-pt-desktop]) input[type=text],
  html:not([data-pt-desktop]) input[type=password],
  html:not([data-pt-desktop]) input[type=number],
  html:not([data-pt-desktop]) input:not([type]),
  html:not([data-pt-desktop]) select,
  html:not([data-pt-desktop]) textarea{font-size:16px;}

  html:not([data-pt-desktop]) input[type=text],
  html:not([data-pt-desktop]) input[type=password],
  html:not([data-pt-desktop]) input[type=number],
  html:not([data-pt-desktop]) input:not([type]),
  html:not([data-pt-desktop]) select,
  html:not([data-pt-desktop]) textarea{max-width:100%;}

  /* thumb-sized targets for the action buttons and the radio/checkbox
     grids used by the leave-application forms */
  html:not([data-pt-desktop]) input[type=submit],
  html:not([data-pt-desktop]) input[type=button],
  html:not([data-pt-desktop]) input[type=reset],
  html:not([data-pt-desktop]) button{
    min-height:40px;padding:8px 18px;
  }
  html:not([data-pt-desktop]) input[type=radio],
  html:not([data-pt-desktop]) input[type=checkbox]{
    width:18px;height:18px;vertical-align:-3px;
  }

  /* A 650px form canvas on a 390px screen has to pan sideways, and the legacy
     markup centres the submit button in that canvas - so at scrollLeft=0 its
     right edge is off screen, at full pan its left edge is, and it is only
     whole somewhere in the middle. Teachers reported exactly that on 186.
     Anchor it left and make it stick there while the page pans: measured 100%
     of scroll offsets vs 93% before.
     Deliberately TWO rules: if :has() is unsupported the whole selector list of
     the first rule is dropped, and the sticky rule must still take effect. */
  html:not([data-pt-desktop]) td:has(input[type=submit]),
  html:not([data-pt-desktop]) th:has(input[type=submit]){text-align:left;}
  html:not([data-pt-desktop]) input[type=submit]{position:sticky;left:6px;}
}
/* print: restore legacy metrics (2026-07-21)
   fixed-row report pages (teacher card = 40 rows/page, score sheets, selresult...)
   were paginated for the original compact row height; the screen beautify above
   inflated each row ~77% and spilled 1 sheet into 3. Screen look is unchanged. */
@media print{
  /* first value = fallback for browsers without revert; revert wins where supported */
  td{padding:0;padding:revert;}
  th{padding:0;padding:revert;}
  td font,th font{font-size:revert;}
  font[size="2"]{font-size:revert;}
}
