/* ==========================================================================
   Adriana's Traffic School - style.css
   Restores legacy rendering (global.css / register.css) on pages that also
   load the Tailwind v4 build (39rn-fix0gvd9_3ZeV.css).

   LOAD ORDER:  tailwind build  ->  global.css  ->  register.css  ->  style.css

   WHY THIS WORKS
   Every rule below is placed inside Tailwind's own `base` layer, so it:
     - beats Tailwind's Preflight reset (same layer, higher specificity),
     - still loses to Tailwind utilities (later layer), so the Tailwind
       header/footer are untouched,
     - still loses to global.css / register.css (unlayered), so every rule
       you already wrote keeps winning.
   `revert` hands each property back to the browser default, which is what
   the legacy sheets were written against.

   SCOPE
   Only elements inside the legacy containers below are affected. If a legacy
   page uses a wrapper not listed, add class="legacy" to it.
   ========================================================================== */

@layer base {

  /* 1. Container text: Tailwind sets html line-height 1.5 and body color
        #1e293b; legacy pages expect "normal" and black. */
  html :where(.legacy, #content, .content, #aff_content, .aff_content, #login_container, #registration_container, #receipt_container, #postage_container, #contact_container, #payment_container, #course_content) {
    line-height: normal;
    color: #000;
  }

  /* 2. Box model + borders: Preflight forces border-box and `border: 0 solid`
        on everything. Legacy widths (e.g. .contact_field 250px + 5px padding)
        assume content-box, and native controls/tables need their borders. */
  html :where(.legacy, #content, .content, #aff_content, .aff_content, #login_container, #registration_container, #receipt_container, #postage_container, #contact_container, #payment_container, #course_content),
  html :where(.legacy, #content, .content, #aff_content, .aff_content, #login_container, #registration_container, #receipt_container, #postage_container, #contact_container, #payment_container, #course_content) *,
  html :where(.legacy, #content, .content, #aff_content, .aff_content, #login_container, #registration_container, #receipt_container, #postage_container, #contact_container, #payment_container, #course_content) *::before,
  html :where(.legacy, #content, .content, #aff_content, .aff_content, #login_container, #registration_container, #receipt_container, #postage_container, #contact_container, #payment_container, #course_content) *::after {
    box-sizing: content-box;
    border-width: revert;
    border-style: revert;
    border-color: revert;
  }

  /* 3. Form controls: Preflight makes buttons/inputs transparent, borderless,
        square and font-inherited. This is what turned "Continue" into plain
        text. Restores the native button/field look. */
  html :where(.legacy, #content, .content, #aff_content, .aff_content, #login_container, #registration_container, #receipt_container, #postage_container, #contact_container, #payment_container, #course_content) :is(button, input, select, optgroup, textarea) {
    font: revert;
    letter-spacing: revert;
    color: revert;
    background-color: revert;
    border-radius: revert;
    appearance: revert;
    opacity: revert;
  }

  html :where(.legacy, #content, .content, #aff_content, .aff_content, #login_container, #registration_container, #receipt_container, #postage_container, #contact_container, #payment_container, #course_content) :is(button, input[type="button"], input[type="submit"], input[type="reset"]) {
    cursor: pointer;
  }

  html :where(.legacy, #content, .content, #aff_content, .aff_content, #login_container, #registration_container, #receipt_container, #postage_container, #contact_container, #payment_container, #course_content) ::placeholder {
    color: revert;
    opacity: revert;
  }

  /* 4. Lists: Preflight removes bullets/numbers (FAQ, course_desc, errors). */
  html :where(.legacy, #content, .content, #aff_content, .aff_content, #login_container, #registration_container, #receipt_container, #postage_container, #contact_container, #payment_container, #course_content) :is(ol, ul, menu) {
    list-style: revert;
  }

  /* 5. Headings: Preflight flattens h1-h6 to body size/weight. global.css
        restyles h1-h3; this restores h4-h6 (and any heading it misses). */
  html :where(.legacy, #content, .content, #aff_content, .aff_content, #login_container, #registration_container, #receipt_container, #postage_container, #contact_container, #payment_container, #course_content) :is(h1, h2, h3, h4, h5, h6) {
    font-size: revert;
    font-weight: revert;
  }

  /* 6. Images: Preflight makes images block-level, which breaks inline
        envelope/payment icons and centered logos inside text. */
  html :where(.legacy, #content, .content, #aff_content, .aff_content, #login_container, #registration_container, #receipt_container, #postage_container, #contact_container, #payment_container, #course_content) img {
    display: revert;
    vertical-align: revert;
  }

  /* 7. Tables: legacy tables (#menu_table, #crossroads) rely on cellspacing
        and the default separate border model. */
  html :where(.legacy, #content, .content, #aff_content, .aff_content, #login_container, #registration_container, #receipt_container, #postage_container, #contact_container, #payment_container, #course_content) table {
    border-collapse: revert;
    border-color: revert;
    text-indent: revert;
  }

  /* 8. Rules: Preflight turns <hr> into a 1px currentColor line. */
  html :where(.legacy, #content, .content, #aff_content, .aff_content, #login_container, #registration_container, #receipt_container, #postage_container, #contact_container, #payment_container, #course_content) hr {
    height: revert;
    color: revert;
  }

  /* 9. Small text: Preflight sets 80%; browser default is "smaller". */
  html :where(.legacy, #content, .content, #aff_content, .aff_content, #login_container, #registration_container, #receipt_container, #postage_container, #contact_container, #payment_container, #course_content) small {
    font-size: revert;
  }
}


/* ==========================================================================
   PART 2 - LAYOUT FIXES + MOBILE STACKING
   These rules are deliberately NOT layered: they must beat global.css,
   register.css and the inline <style> block in login.php. They are still
   scoped to the legacy containers, so the Tailwind header/footer are safe.
   ========================================================================== */

/* 10. Security questions centered.
       login.php prints <table border="0" cellspacing="5"> with no margin of
       its own; it relied on global.css `*{margin:0 auto}`, which Tailwind's
       reset is now beating. */
html body #login_container table {
  margin-left: auto;
  margin-right: auto;
}

/* 11. Stop fixed-width legacy blocks from causing sideways scrolling on
       tablets and small laptops (no visual change on desktop). */
html :where(.legacy, #content, .content, #aff_content, .aff_content, #login_container, #registration_container, #receipt_container, #postage_container, #contact_container, #payment_container, #course_content) :is(div, form, table, img, input, select, textarea, ul, ol, p) {
  max-width: 100%;
}

/* ---------- Mobile: everything stacks below 768px ---------- */
@media only screen and (max-width: 768px) {

  /* Padding/borders count inside widths so 100%-wide things fit. */
  html :where(.legacy, #content, .content, #aff_content, .aff_content, #login_container, #registration_container, #receipt_container, #postage_container, #contact_container, #payment_container, #course_content),
  html :where(.legacy, #content, .content, #aff_content, .aff_content, #login_container, #registration_container, #receipt_container, #postage_container, #contact_container, #payment_container, #course_content) * {
    box-sizing: border-box;
  }

  /* Page containers: full width with a small gutter.
     !important is needed to beat inline style="width:..." in the PHP. */
  html body :is(#content, .content, #aff_content, .aff_content, #login_container, #registration_container, #receipt_container, #receipt, #postage_container, #contact_container, #payment_container, #payment_options, #course_content, #evaluation, #final_note, #post_shipping, #crossroads, #security_entry, .registration_subdivision, #registration_container .price_row) {
    width: 100% !important;
    max-width: 100% !important;
    margin-left: 0 !important;
    margin-right: 0 !important;
  }
  html body :is(#content, .content, #aff_content, .aff_content, #login_container, #registration_container, #receipt_container, #payment_container, #course_content) {
    padding-left: 16px !important;
    padding-right: 16px !important;
  }

  /* Side-by-side columns stack. */
  html body :is(#registration_left_panel, #registration_panel, #rememberme, #submit),
  html body :where(.legacy, #content, .content, #aff_content, .aff_content, #login_container, #registration_container, #receipt_container, #postage_container, #contact_container, #payment_container, #course_content) :is(.timg, .tcont, .payment_option, .left, .right) {
    float: none !important;
    width: 100% !important;
    margin-left: 0 !important;
    margin-right: 0 !important;
    padding-left: 0 !important;
    padding-right: 0 !important;
    left: auto !important;
    border-right: 0 !important;
  }
  html body #registration_left_panel {
    margin-bottom: 20px !important;
  }

  /* Registration rows: label on top, field full width below. */
  html body #registration_container :is(.row, .reg_row, .frm_row, .row_err) {
    text-align: left;
  }
  html body #registration_container label {
    float: none;
    display: block;
    width: 100%;
    text-align: left;
  }
  html body #registration_container :is(.contact_field, select),
  html body #refer input {
    width: 100% !important;
  }

  /* 16px inputs stop iPhone from zooming in on focus. */
  html :where(.legacy, #content, .content, #aff_content, .aff_content, #login_container, #registration_container, #receipt_container, #postage_container, #contact_container, #payment_container, #course_content) :is(input[type="text"], input[type="email"], input[type="tel"], input[type="password"], input[type="number"], input:not([type]), select, textarea) {
    font-size: 16px !important;
  }

  /* Buttons: easy to tap. */
  html :where(.legacy, #content, .content, #aff_content, .aff_content, #login_container, #registration_container, #receipt_container, #postage_container, #contact_container, #payment_container, #course_content) :is(button, input[type="submit"], input[type="button"]) {
    min-height: 44px;
    padding: 10px 24px;
    font-size: 16px;
  }

  /* Login panel (inline <style> in login.php fixes it at 350x250 with a
     background image and indented labels). */
  html body #login_panel {
    width: 100% !important;
    height: auto !important;
    padding: 20px 0 !important;
    background: none !important;
  }
  html body #login_panel .label {
    padding: 0 !important;
    text-align: left !important;
  }
  html body #login_panel .login_form {
    width: 100% !important;
  }
  html body #login_panel div[align="right"] {
    padding: 10px 0 !important;
    text-align: center;
  }

  /* Security questions: each question becomes its own block, question on
     top, Yes/No underneath, larger text and radio buttons. */
  html body #login_container table,
  html body #login_container tbody,
  html body #login_container tr {
    display: block;
    width: 100%;
  }
  html body #login_container tr {
    padding: 12px 0;
    border-bottom: 1px solid #e5e5e5;
  }
  html body #login_container td {
    display: inline-block;
    padding: 4px 10px;
    font-size: 16px;
    text-align: center;
  }
  html body #login_container td:first-child {
    display: block;
    width: 100%;
    font-weight: bold;
  }
  html body #login_container input[type="radio"] {
    width: 22px;
    height: 22px;
    vertical-align: middle;
  }
  html body #login_container a {
    display: inline-block;
    padding: 10px 0;
  }

  /* Receipts, tables of info, long text: no sideways scroll. */
  html body #receipt {
    width: 100% !important;
  }
  html :where(.legacy, #content, .content, #aff_content, .aff_content, #registration_container, #receipt_container, #course_content) table {
    width: 100% !important;
  }
  html :where(.legacy, #content, .content, #aff_content, .aff_content, #login_container, #registration_container, #receipt_container, #course_content) :is(p, li, td, label, div) {
    overflow-wrap: anywhere;
  }
}


/* ==========================================================================
   PART 3 - MOBILE NAV DROPDOWN
   #mobile-menu sits inside #mobile-actions (the box holding Log In + the
   hamburger) and drops straight down from it, right-aligned, at least as
   wide as Log In + hamburger together. It is absolutely positioned, so it
   never pushes or squeezes the logo or buttons. Shown/hidden with `hidden`.
   ========================================================================== */
#mobile-actions {
  position: relative;
}
#mobile-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 100%;
  width: max-content;
  max-width: calc(100vw - 32px);
  margin: 0;
  padding: 4px 0;
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  box-shadow: 0 12px 24px rgba(15, 23, 42, 0.14);
  z-index: 60;
}
#mobile-menu a {
  display: block;
  padding: 12px 20px;
  font-size: 16px;
  font-weight: 500;
  color: #1e293b;
  text-decoration: none;
  white-space: nowrap;
  border-top: 1px solid #f1f5f9;
}
#mobile-menu a:first-child { border-top: 0; }
#mobile-menu a:hover,
#mobile-menu a:focus-visible {
  background: #f1f5f9;
  outline: none;
}
/* Tailwind's md breakpoint (48rem = 768px): desktop nav takes over. */
@media (min-width: 48rem) {
  #mobile-menu { display: none !important; }
}


/* ==========================================================================
   PART 4 - STUDENT HOME (home.php / menu_page.php): STACK THE BUTTONS
   On every phone (up to 768px, all iPhones in portrait), Continue Course,
   Edit Profile and Logout stack, centered, above the course table.
   The buttons keep their own padding, display and icons; only their
   floats/positions/widths are overridden. Earlier versions forced the links
   to full width with new padding, which pushed icons out of view.
   ========================================================================== */
@media only screen and (max-width: 768px) {

  /* If the buttons live in a layout table cell, let that table stack. */
  html body table:has(#link_continue, #link_edit, #link_logout):not(#menu_table),
  html body table:has(#link_continue, #link_edit, #link_logout):not(#menu_table) > tbody,
  html body table:has(#link_continue, #link_edit, #link_logout):not(#menu_table) > tbody > tr,
  html body table:has(#link_continue, #link_edit, #link_logout):not(#menu_table) > tbody > tr > td {
    display: block !important;
    width: 100% !important;
  }

  /* The element that directly holds the buttons: full width (it was a
     narrow right-hand column, which is why the stack sat off to the right),
     one centered column, buttons moved to the top. */
  html body :is(div, td, form, section, p, span):has(> #link_continue, > #link_edit, > #link_logout) {
    display: flex !important;
    flex-direction: column;
    align-items: center;
    float: none !important;
    position: static !important;
    width: 100% !important;
    max-width: 100% !important;
    margin-left: 0 !important;
    margin-right: 0 !important;
    padding-left: 0 !important;
    padding-right: 0 !important;
    text-align: center !important;
  }
  html body #link_continue { order: -3; }
  html body #link_edit     { order: -2; }
  html body #link_logout   { order: -1; }

  /* Each button: un-float, natural width, centered. */
  html body :is(#link_continue, #link_edit, #link_logout) {
    float: none !important;
    position: static !important;
    left: auto !important;
    right: auto !important;
    width: auto !important;
    max-width: 100% !important;
    margin: 0 auto 14px auto !important;
    text-align: center !important;
  }
  html body #link_logout { margin-bottom: 20px !important; }

  /* Keep icons from being squeezed out. */
  html body :is(#link_continue, #link_edit, #link_logout) :is(img, i, svg, span) {
    flex-shrink: 0;
  }

  /* Progress meter and course table fill the width below the buttons. */
  html body :is(#progress_meter, #menu_table, .menu_footer) {
    width: 100% !important;
    max-width: 100% !important;
    float: none !important;
  }
}
