/* ==========================================================================
   mobile.css  —  MOBILE LAYOUT (production + local dono)

   HAR phone par (production aur local) yahi file load hoti hai —
   saare mobile layout rules isi ek file me hain.

   --------------------------------------------------------------------
   KAISE TEST KAREIN
   --------------------------------------------------------------------
   Desktop :  F12 → Ctrl+Shift+M → Pixel 7   (ya "Responsive" → 360 x 800)
   Phone   :  http://192.168.135.27/
   Dono jagah mobile layout dikhega. PC ka desktop layout nahi badlega.

   --------------------------------------------------------------------
   SEEKH
   --------------------------------------------------------------------
   1. Har rule @media (max-width: ...) ke andar likho.
      Bina media query ke rule likhoge to desktop bhi toot jayega.

   2. Mobile hone ka test karna ho to Chrome me "Inspect" karke
      console me likho:
          matchMedia('(max-width: 768px)').matches

   3. Koi bhi rule likhne se pehle dekho ki wo already
      style.css me nahi hai. Yahan sirf NAYA/override karna hai.

   --------------------------------------------------------------------
   RELATIVE PATHS
   --------------------------------------------------------------------
   <base href> ke baad load hoti hai:
       url('css/style.css')   → sahi
   Absolute path ya /assets/... mat likhna.
   ========================================================================== */


/* ---------- 1. GENERIC TABLE -> CARD (sabhi tables, har module) ----------
   mobile-table.js har td par data-label bhar deta hai, aur ye usi label
   ko value ke bagal me dikhata hai. Desktop par in rules apply hi nahi
   hote (sirf max-width ke andar hain).                                    */

@media (max-width: 768px) {
  /* Table ka wrapper: scroll-bar hat jayega, kyunki ab card layout hai */
  .table-responsive,
  .table-scroll,
  .table-vp {
    overflow: visible !important;
    max-height: none !important;
  }

  /* thead chhup jayega — label td par dikhta hai.
     .sortable head ko chhupane se sorting buttons bhi chhup jayenge,
     isliye unhe alag se neeche dikhate hain. */
  table.gau-mtable thead {
    display: none;
  }

  table.gau-mtable,
  table.gau-mtable tbody,
  table.gau-mtable tr,
  table.gau-mtable td {
    display: block;
    width: 100%;
  }

  table.gau-mtable tr {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 14px;
    margin: 0 0 12px;
    padding: 12px 14px;
    box-shadow: 0 1px 3px rgba(15, 23, 42, .06);
  }

  table.gau-mtable td {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 7px 0;
    border: 0;
    border-bottom: 1px dashed var(--border-color);
    text-align: left !important;
    white-space: normal;
    word-break: break-word;
  }

  table.gau-mtable tr td:last-child {
    border-bottom: 0;
  }

  /* Label (data-label) — mobile-table.js ne bhara hai */
  table.gau-mtable td::before {
    content: attr(data-label);
    flex: 0 0 42%;
    max-width: 42%;
    font-size: .78rem;
    font-weight: 600;
    color: var(--text-secondary);
    line-height: 1.5;
  }

  /* Value ko aage dhakelne ke liye wrapper (sirf non-empty values) */
  table.gau-mtable td > * {
    min-width: 0;
  }

  /* Value seedha text hai (koi element nahi) to flex-grow karo */
  table.gau-mtable td:not(:has(> *)) {
    justify-content: flex-start;
  }

  /* Spinner / "koi record nahi" wali row — card banegi nahi */
  table.gau-mtable td[colspan],
  table.gau-mtable td.empty-state {
    display: block;
    padding: 20px 0;
    border: 0;
    text-align: center !important;
  }
  table.gau-mtable td[colspan]::before {
    content: none;
  }

  /* Photo column: badi photo mat dikha, chhoti thumbnail */
  table.gau-mtable td[data-label] img {
    max-width: 72px;
    max-height: 72px;
    border-radius: 8px;
  }

  /* Actions column ke buttons poori width ke, touch-friendly */
  table.gau-mtable td:last-child:not([colspan]) {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding-top: 10px;
  }
  table.gau-mtable td:last-child:not([colspan])::before {
    flex-basis: 100%;
    margin-bottom: 2px;
  }
  table.gau-mtable td:last-child a,
  table.gau-mtable td:last-child button {
    min-height: 40px;
    display: inline-flex;
    align-items: center;
    gap: 6px;
  }
}

/* ---------- 2. FILTER ROW (search + 5 dropdowns) ----------
   Ye inline width rakhte hain: search 160px, har select 150px.
   360px phone par total ~910px — bahut overflow karega. Isliye mobile
   par search poori line, aur filters do-do karke grid me.            */

@media (max-width: 768px) {
  div:has(> #searchInput) {
    display: grid !important;
    grid-template-columns: 1fr 1fr;
    gap: 8px !important;
    width: 100%;
  }
  div:has(> #searchInput) > #searchInput {
    grid-column: 1 / -1;
    width: 100% !important;
  }
  div:has(> #searchInput) > select.form-control {
    width: 100% !important;
    min-height: 42px;
  }

  /* "×" clear button bhi isi grid ka child hai. Full line lene ki jagah
     apni cell me compact button rahe — field jaisa hi 36px height. */
  div:has(> #searchInput) > .clear-filter-btn {
    justify-self: start;
    align-self: center;
    width: auto !important;
    min-width: 36px;
    height: 36px;
    min-height: 36px;
    padding: 0 12px !important;
    display: flex !important;
    align-items: center;
    justify-content: center;
  }

  /* "no record" / count wali line bhi theek ho jaye */
  #totalCount {
    font-size: .85rem;
  }
}

@media (max-width: 768px) {
  /* ------------------------------------------------------------------
     INLINE STYLES OVERRIDE
     ------------------------------------------------------------------
     Bahut se modules (jaise admin/attendance/regular.php) table par
     inline style lagate hain, e.g.
         min-width:940px;  width:100%;  font-size:.85rem
     aur uske upar <div style="overflow-x:auto">.
     Inline style stylesheet se jeet-ta hai, isliye yahan !important
     zaroori hai.

     .gau-mtable / .gau-mscroll classes mobile-table.js lagata hai
     (sirf un tables par jinke 4+ columns hain).                        */

  /* scroll wrapper: card layout me scroll ki zaroorat nahi */
  .gau-mscroll {
    overflow: visible !important;
    -webkit-overflow-scrolling: auto !important;
    max-height: none !important;
  }

  /* table ka fixed min-width hatana — 720/940/1000px phone par overflow */
  table.gau-mtable {
    min-width: 0 !important;
    width: 100% !important;
    table-layout: auto !important;
  }

  /* inline font-size chhoti hai; card me thoda bada padhne layak */
  table.gau-mtable tbody td {
    font-size: .9rem !important;
  }

  /* inline border/padding ko card ke apne rules se replace karo.
     Attendance ke td par inline padding:6px 8px lagta hai, jo card
     ke dashed divider ke saath clash karta tha. */
  table.gau-mtable tbody td {
    padding: 7px 0 !important;
    border: 0 !important;
    border-bottom: 1px dashed var(--border-color) !important;
    background: transparent !important;
    text-align: left !important;
  }
  table.gau-mtable tbody tr:last-child td {
    border-bottom: 0 !important;
  }

  /* inline th styling thead ke saath gayi; thead chhupa hai to theek hai,
     par sticky the ho to unpin kar do */
  table.gau-mtable thead th {
    position: static !important;
  }

  /* photo + action buttons */
  table.gau-mtable tbody td img {
    max-width: 72px !important;
    max-height: 72px !important;
    border-radius: 8px;
  }
  table.gau-mtable tbody td:last-child:not([colspan]) a,
  table.gau-mtable tbody td:last-child:not([colspan]) button {
    min-height: 40px;
    display: inline-flex;
    align-items: center;
    gap: 6px;
  }
}

/* ---------- 4. FULLSCREEN LIVE SEARCH ----------
   mobile-search.js: page ke maujuda search input (oninput wala) ko
   fullscreen overlay se mirror karta hai. Naya filter logic nahi — wo
   wahi chalta hai jo page par pehle se hai.                            */

/* Safety net: JS kabhi bhi viewport check karta hai, par agar kabhi miss
   ho jaye to overlay desktop par page ke andar inline na dikhe.           */
.gau-fs {
  display: none !important;
}

@media (max-width: 768px) {
  .gau-fs {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 100500;
    display: none;
    flex-direction: column;
    gap: 14px;
    padding: 0;
    background: var(--bg-primary);
    /* notch/status bar safe */
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
  }
  .gau-fs.is-open {
    display: flex;
  }

  .gau-fs__top {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 12px;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border-color);
  }

  .gau-fs__input {
    flex: 1;
    min-width: 0;
    height: 52px;
    padding: 0 16px;
    font-size: 1.05rem;
    border: 1px solid var(--border-color);
    border-radius: 12px;
    background: var(--bg-primary);
    color: var(--text-primary);
  }
  .gau-fs__input:focus {
    outline: 2px solid var(--primary);
    outline-offset: -1px;
  }

  .gau-fs__close {
    flex: 0 0 auto;
    width: 48px;
    height: 48px;
    border: 1px solid var(--border-color);
    border-radius: 12px;
    background: var(--bg-primary);
    color: var(--text-secondary);
    font-size: 1.6rem;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .gau-fs__count {
    padding: 0 16px;
    font-size: .88rem;
    font-weight: 600;
    color: var(--text-secondary);
  }

  .gau-fs__hint {
    margin-top: auto;
    padding: 0 16px 18px;
    font-size: .75rem;
    color: var(--text-secondary);
    text-align: center;
  }

  /* backdrop ke neeche ka page scroll na ho */
  body.gau-fs-open {
    overflow: hidden;
  }
}

/* ---------- 6. Niyamit UPSTHITI KA TOOLBAR ----------
   Source: admin/attendance/regular.php L129-150 (.rt-toolbar)

   Phone par pehle 6 cheezein ek hi line me thi (search + session +
   pin + print + download + book) — bahut bhaari aur chhoti thi.

   Ab:
     row 1 = search poori line, bada, 52px
     row 2 = session dropdown + pin
     row 3 = print / download / book buttons
   Sirf max-width: 768px tak. Desktop bilkul same.                       */

@media (max-width: 768px) {
  .rt-toolbar {
    display: grid !important;
    grid-template-columns: 1fr auto;
    grid-template-areas:
      "search search"
      "session pin"
      "actions actions";
    gap: 8px !important;
    align-items: center;
  }

  .rt-searchbox {
    grid-area: search;
    max-width: none !important;
    width: 100%;
  }
  /* bada, ungli se type karna aasan */
  .rt-searchbox input {
    height: 52px;
    font-size: 1rem;
    padding-left: 34px !important;
  }
  .rt-searchbox .fa-search {
    left: 12px !important;
    font-size: 0.95rem !important;
  }
  /* hint neeche dikhe, box ke andar overlap na kare */
  .rt-searchbox > div {
    white-space: normal !important;
    font-size: 0.78rem;
    padding-top: 2px;
  }

  .rt-session {
    grid-area: session;
    max-width: none !important;
    width: 100%;
    min-width: 0 !important;
    height: 40px;
    min-height: 40px;
    font-size: 0.9rem;
    padding-top: 0;
    padding-bottom: 0;
  }

  .rt-pin {
    grid-area: pin;
    width: 40px !important;
    min-width: 40px;
    height: 40px;
    min-height: 40px;
    padding: 0 !important;
    font-size: 0.82rem;
    border-radius: 6px;
  }

  /* Chhote buttons, sab DAAYE taraf, apni size ke — poori line me
     failane ki zaroorat nahi. flex:1 hata diya, isliye width: auto.
     margin-left:auto grid me kaam nahi karta, isliye justify-content. */
  .rt-actions {
    grid-area: actions;
    margin-left: 0 !important;
    width: 100%;
    justify-content: flex-end;
    align-items: center;
    gap: 6px !important;
  }
  .rt-actions > button,
  .rt-actions > div {
    flex: 0 0 auto;
  }
  .rt-actions button {
    min-height: 40px;
    height: 40px;
    width: 40px;
    padding: 0;
    justify-content: center;
    font-size: 0.82rem;
    border-radius: 6px;
  }
  /* dropdown panel ko bhi chhota — phone par bada panel screen gher leta.
     Buttons ab DAAYE taraf hain, isliye panel bhi daaye anchor ho. */
  .rt-actions > div > div {
    min-width: 150px !important;
    padding: 4px !important;
    right: 0 !important;
    left: auto !important;
  }
  .rt-actions > div > div > button {
    width: 100% !important;
    min-height: 40px;
    height: auto;
    padding: 6px 8px !important;
    font-size: 0.8rem !important;
    gap: 6px !important;
  }
}

/* ---------- 7. ATTENDANCE INDEX (index.php) TOOLBAR ----------
   Source: admin/attendance/index.php L85-93
   Ye "regular attendance" wala LIVE search hai (attCowSearch).

   Pehle: input width:320px par capped tha, ek line me 3 buttons.
   Ab mobile par:
     row 1 = search poori line, bada (52px)
     row 2 = naye cows / scan / beep buttons
   Class prefix "rtal" (rt-* regular.php ke liye, taaki na takraye). */

@media (max-width: 768px) {
  .rtal-toolbar {
    flex-wrap: wrap !important;
    row-gap: 8px !important;
  }
  .rtal-search {
    flex: 1 1 100% !important;
    width: 100% !important;
    max-width: none !important;
    min-width: 0 !important;
    height: 52px;
    font-size: 1rem;
  }
  .rtal-btn {
    min-height: 44px !important;
    font-size: 0.95rem;
    padding: 0 14px !important;
  }
  .rtal-beep {
    width: 44px !important;
    height: 44px !important;
    margin-left: auto;
    font-size: 1.1rem;
  }
}

/* ---------- 8. ATTENDANCE KE TEENO TABS EK LINE ME ----------
   Source: admin/attendance/index.php L48-52 (.rtal-tabs / .rtal-tab)

   Teeno tab ka naam lamba hai ("उपस्थिति सत्र", "नियमित उपस्थिति",
   "रीटैगिंग उपस्थिति"), isliye phone par flex-wrap se do line me
   toot rahe the. Ab teeno ek hi line me, barabar width, chhote font. */

@media (max-width: 768px) {
  .rtal-tabs {
    flex-wrap: nowrap !important;
    gap: 4px !important;
  }
  .rtal-tab {
    flex: 1 1 0;
    min-width: 0;
    min-height: 44px;
    padding: 8px 4px !important;
    font-size: 0.8rem;
    line-height: 1.3;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    -webkit-tap-highlight-color: transparent;
  }
  /* icon aur text ka antar kam, naam poora dikhe */
  .rtal-tab i {
    margin-right: 3px !important;
    font-size: 0.78rem;
  }
  /* teenon ke naam kat-na na pade, chhote screen par bhi poori line */
  @media (max-width: 420px) {
    .rtal-tab {
      font-size: 0.72rem;
      padding: 8px 2px !important;
    }
    .rtal-tab i {
      display: none;
    }
  }
}

/* ---------- 3. CARD LIST KI SPACING ----------
   cows/index.php me <div class="card"><div class="card-body" style="padding:0">
     <div class="table-responsive"> hai. Bahar wala .card poora screen
     chahta hai; margin sirf ANDAR wale container par, taaki cards ko
     dono taraf thodi jagah mile (double margin na ho).

   cards ke beech thoda zyada gap — ungli se select karna aasan ho. */

@media (max-width: 768px) {
  .card-body > .table-responsive {
    margin-left: 10px;
    margin-right: 10px;
  }

  /* cards ke beech aur list ke upar wala gap (sirf upar-niche)         */
  table.gau-mtable tbody tr {
    margin-bottom: 14px;
  }
  table.gau-mtable tbody tr:first-child {
    margin-top: 10px;
  }
  table.gau-mtable tbody tr:last-child {
    margin-bottom: 10px;
  }
}

/* ---------- 9. LOGIN CARD — NARROW + CENTERED + AUTO-FIT HEIGHT (mobile) ----------
   Sare chhote-size wale rules wapas original kar diye (logo, title,
   input, spacing — sab style.css jaisa).
   3 badlav:
     1. Card ki CHAURAI kam — max-width 420 -> 320px (+ side gap).
     2. Card ko center me laao — style.css ke <=480px rule me
        margin:16px tha, jisse card upar chipak jata tha.
     3. UNCHAI me auto-fit — dvh (dynamic viewport height) se screen
        browser-UI (address bar) ke hisaab se exact fit karti hai.
        100vh mobile par visible height se bada hota hai, isliye card
        neeche se cut hota tha / page scroll hota tha.                  */

@media (max-width: 768px) {
  .login-container {
    /* pehle 100vh (fallback), phir dvh — exact visible height */
    min-height: 100vh;
    min-height: 100dvh;
    padding: 16px 0;
    box-sizing: border-box;
  }
  .login-card {
    width: calc(100% - 32px);
    max-width: 320px !important;
    /* auto margin = flex container ke dono axis me perfect center */
    margin: auto !important;
    /* card ki unchai = visible screen ke andar hi fit */
    max-height: calc(100vh - 32px);
    max-height: calc(100dvh - 32px);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
}

/* Chhoti height wali screens (chhote phone / landscape) — card andar hi
   fit ho jaaye, andar ka scroll kam se kam ho. */
@media (max-width: 768px) and (max-height: 700px) {
  .login-card {
    padding: 22px 18px;
  }
  .login-card .login-logo {
    margin-bottom: 16px;
  }
  .login-card .login-logo h1 {
    font-size: 1.25rem;
  }
  .login-card .login-logo .emoji-icon {
    font-size: 2.2rem;
    margin-bottom: 6px;
  }
  .login-card .login-logo img {
    height: 54px;
    margin-bottom: 8px;
  }
  .login-card .form-group {
    margin-bottom: 12px;
  }
}
