/* Emplus HRMS - custom styles (complements Tailwind) */

:root { color-scheme: light; }
[hidden] { display: none !important; }
/* overflow-x: clip hides sideways overflow WITHOUT turning the element into a
   scroll container (which `hidden` does — that broke mouse-wheel vertical
   scrolling, because a body scroll-container with overscroll-behavior:none
   swallowed the wheel instead of chaining it to the document). */
html { overflow-x: clip; overscroll-behavior-y: none; background: #f1f5f9; }
body { overflow-x: clip; }

/* ---------- Sidebar nav ---------- */
.nav-group-title {
  padding: 0 .75rem;
  margin-bottom: .35rem;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: #64748b;
}
.nav-link {
  position: relative;
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .55rem .75rem;
  border-radius: .6rem;
  font-size: .875rem;
  font-weight: 500;
  color: #cbd5e1;
  transition: background-color .15s, color .15s;
  white-space: nowrap;
}
.nav-link:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav-link svg { flex: 0 0 auto; width: 1.25rem; height: 1.25rem; }
.nav-active { background: #4f46e5 !important; color: #fff !important; }
.nav-active:hover { background: #4338ca !important; }
.nav-disabled { opacity: .55; cursor: default; }
.nav-disabled:hover { background: transparent; color: #cbd5e1; }
.nav-soon {
  margin-left: auto;
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: .05em;
  background: rgba(255,255,255,.1);
  color: #94a3b8;
  padding: 1px 6px;
  border-radius: 999px;
}
.sidebar-scroll::-webkit-scrollbar { width: 6px; }
.sidebar-scroll::-webkit-scrollbar-thumb { background: rgba(255,255,255,.12); border-radius: 3px; }

/* ---------- Collapsed (desktop icon-rail) state ---------- */
body.sidebar-collapsed #sidebar { width: 4.75rem; }
body.sidebar-collapsed #main    { margin-left: 4.75rem; }
body.sidebar-collapsed .nav-label,
body.sidebar-collapsed .nav-soon,
body.sidebar-collapsed .nav-group-title,
body.sidebar-collapsed .sidebar-brand { display: none; }
body.sidebar-collapsed .nav-link { justify-content: center; padding-left: 0; padding-right: 0; }
body.sidebar-collapsed .nav-group { border-top: 1px solid rgba(255,255,255,.07); padding-top: .75rem; }

/* On small screens the collapse class must not shift main / shrink drawer */
@media (max-width: 1023px) {
  body.sidebar-collapsed #sidebar { width: 16rem; }
  body.sidebar-collapsed #main    { margin-left: 0; }
  body.sidebar-collapsed .nav-label,
  body.sidebar-collapsed .nav-group-title,
  body.sidebar-collapsed .sidebar-brand { display: initial; }
  body.sidebar-collapsed .nav-link { justify-content: flex-start; padding-left: .75rem; padding-right: .75rem; }
}

/* ---------- Form helpers ---------- */
.form-label { display:block; margin-bottom:.3rem; font-size:.8rem; font-weight:600; color:#475569; }
.form-input, .form-select, textarea.form-input {
  width:100%; max-width:100%; border:1px solid #cbd5e1; border-radius:.6rem;
  padding:.55rem .75rem; font-size:.875rem; background:#fff; color:#1e293b;
  transition:border-color .15s, box-shadow .15s;
}
.form-input:focus, .form-select:focus, textarea.form-input:focus {
  outline:none; border-color:#6366f1; box-shadow:0 0 0 3px rgba(99,102,241,.15);
}
.form-hint { margin-top:.25rem; font-size:.72rem; color:#94a3b8; }
.req::after { content:" *"; color:#e11d48; }

.btn { display:inline-flex; align-items:center; gap:.5rem; border-radius:.6rem; padding:.55rem 1rem; font-size:.875rem; font-weight:600; transition:background-color .15s; cursor:pointer; }
.btn-primary { background:#4f46e5; color:#fff; } .btn-primary:hover { background:#4338ca; }
.btn-light   { background:#fff; color:#334155; border:1px solid #cbd5e1; } .btn-light:hover { background:#f8fafc; }
.btn-danger  { background:#e11d48; color:#fff; } .btn-danger:hover { background:#be123c; }

.card { background:#fff; border:1px solid #e2e8f0; border-radius:1rem; }

/* searchable single-select (combobox) */
.ss-native { display: none !important; }
.search-select { position: relative; }
.ss-menu { position:absolute; z-index:60; left:0; right:0; margin-top:.25rem; max-height:14rem; overflow-y:auto; background:#fff; border:1px solid #e2e8f0; border-radius:.6rem; box-shadow:0 12px 28px rgba(2,6,23,.12); }
.ss-opt { padding:.5rem .7rem; font-size:.875rem; cursor:pointer; }
.ss-opt:hover, .ss-opt.ss-active { background:#eef2ff; }
.ss-none { padding:.6rem .7rem; font-size:.8rem; color:#94a3b8; }

/* directory filter chips */
.dir-chip {
  font-size: .8rem; font-weight: 600; color: #475569;
  padding: .35rem .75rem; border-radius: 999px; border: 1px solid #e2e8f0; background: #fff;
  cursor: pointer; transition: all .15s; white-space: nowrap;
}
.dir-chip:hover { background: #f8fafc; }
.dir-chip.is-active { background: #4f46e5; border-color: #4f46e5; color: #fff; }
.dir-chip.is-active .text-slate-400 { color: #c7d2fe; }

/* collapsible entry form (mobile only; desktop keeps it visible) */
.form-panel-toggle { display: inline-flex; width: 100%; justify-content: center; margin-bottom: 1rem; }
@media (min-width: 1024px) {
  .form-panel-toggle { display: none !important; }
}
@media (max-width: 1023px) {
  .form-panel:not(.is-open) { display: none; }
}

/* toggle switch */
.switch { position:relative; display:inline-block; cursor:pointer; }
.switch input { position:absolute; opacity:0; width:0; height:0; }
.switch-track {
  display:block; width:44px; height:24px; border-radius:999px;
  background:#cbd5e1; transition:background-color .2s; position:relative;
}
.switch-thumb {
  position:absolute; top:2px; left:2px; width:20px; height:20px;
  background:#fff; border-radius:50%; transition:transform .2s; box-shadow:0 1px 2px rgba(0,0,0,.2);
}
.switch input:checked + .switch-track { background:#4f46e5; }
.switch input:checked + .switch-track .switch-thumb { transform:translateX(20px); }
.switch input:focus-visible + .switch-track { box-shadow:0 0 0 3px rgba(99,102,241,.3); }

/* inline "add master" button */
.add-master {
  display:inline-flex; align-items:center; gap:.15rem;
  font-size:.72rem; font-weight:600; color:#4f46e5;
  padding:.1rem .45rem; border-radius:.4rem; cursor:pointer;
  transition:background-color .15s;
}
.add-master:hover { background:#eef2ff; color:#4338ca; }

#masterModal.is-open { display:flex; }

/* checkbox pick list */
.pick-list { max-height: 11rem; overflow-y:auto; border:1px solid #cbd5e1; border-radius:.6rem; padding:.25rem; }
.pick-item { display:flex; align-items:center; gap:.5rem; padding:.4rem .5rem; border-radius:.4rem; font-size:.85rem; cursor:pointer; }
.pick-item:hover { background:#f1f5f9; }

/* ==========================================================================
   MOBILE APP LAYER  (phones / < md).  Above md the normal web app is kept.
   ========================================================================== */

/* ---------- Bottom tab bar (phones only) ---------- */
.mobile-tabbar { display: none; }
@media (max-width: 767px) {
  .mobile-tabbar {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 36;
    display: flex; align-items: stretch;
    height: calc(3.6rem + env(safe-area-inset-bottom));
    padding-bottom: env(safe-area-inset-bottom);
    background: rgba(255,255,255,.96);
    -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
    border-top: 1px solid #e2e8f0;
    box-shadow: 0 -4px 16px rgba(2,6,23,.06);
  }
  .tab-item {
    flex: 1 1 0; min-width: 0;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 3px; padding: .35rem 0;
    font-size: 10px; font-weight: 600; letter-spacing: .01em;
    color: #64748b; text-decoration: none;
    -webkit-tap-highlight-color: transparent;
    transition: color .15s, transform .1s;
  }
  .tab-item span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .tab-item svg { width: 22px; height: 22px; }
  .tab-item.is-active { color: #4f46e5; }
  .tab-item.is-active svg { stroke-width: 2.1; }
  .tab-item:active { transform: scale(.9); }
  /* keep page content clear of the bar */
  #main { padding-bottom: calc(4.2rem + env(safe-area-inset-bottom)); }
}

/* ---------- Data tables become stacked cards (phones only) ---------- */
@media (max-width: 767px) {
  table.cards-sm { display: block; width: 100%; border-collapse: collapse; }
  table.cards-sm > thead { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
  table.cards-sm > tbody { display: block; width: 100%; }
  table.cards-sm > tbody > tr {
    display: block; width: 100%;
    background: #fff; border: 1px solid #e2e8f0 !important; border-radius: .8rem;
    padding: .25rem .9rem; margin-bottom: .65rem;
    box-shadow: 0 1px 2px rgba(2,6,23,.05);
  }
  table.cards-sm > tbody > tr:hover { background: #fff; }
  table.cards-sm > tbody > tr > td {
    display: flex; align-items: center; justify-content: space-between; gap: 1rem;
    width: 100% !important; max-width: 100%;
    padding: .62rem 0 !important; margin: 0 !important;
    border: 0 !important; border-bottom: 1px solid #f1f5f9 !important;
    text-align: right; white-space: normal;
  }
  table.cards-sm > tbody > tr > td:last-child { border-bottom: 0 !important; }
  table.cards-sm > tbody > tr > td::before {
    content: attr(data-label);
    flex: 0 0 38%; text-align: left;
    font-size: .68rem; font-weight: 700; letter-spacing: .04em; text-transform: uppercase;
    color: #94a3b8;
  }
  /* a cell whose header was blank shows no label and lets its content fill */
  table.cards-sm > tbody > tr > td[data-label=""]::before { content: ""; flex-basis: 0; }
  /* empty-state / full-width rows (colspan) stay full width, centered */
  table.cards-sm > tbody > tr > td[colspan]:first-child:last-child { display: block; text-align: center; }
  table.cards-sm > tbody > tr > td[colspan]:first-child:last-child::before { display: none; }
  /* sticky first columns shouldn't stick inside a card */
  table.cards-sm > tbody > tr > td.sticky,
  table.cards-sm > tbody > tr > td[class*="sticky"] { position: static !important; }
}

/* ---------- Touch & spacing tweaks (phones only) ---------- */
@media (max-width: 767px) {
  .btn { padding: .62rem 1rem; }
  /* toolbars / filter chip rows scroll sideways instead of wrapping into a wall */
  .scroll-x-mobile { display: flex; gap: .5rem; overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
  .scroll-x-mobile::-webkit-scrollbar { display: none; }
}

/* ---------- Filter forms & controls fit the screen (phones only) ----------
   Native month/date pickers, search boxes and inline toolbars have intrinsic
   widths that overflow a phone. Make every control fill its row and shrink,
   and let toolbar rows wrap instead of pushing the page sideways. */
@media (max-width: 767px) {
  /* nothing may force the page wider than the viewport.
     clip (not hidden) so the card doesn't become a y-scroll container that
     would trap dropdown menus — same reason html/body use clip above. */
  main .card { overflow-x: clip; }

  /* every input/select/picker fills its field and can shrink to 0 */
  main .form-input, main .form-select,
  main form input:not([type=checkbox]):not([type=radio]):not([type=submit]):not([type=button]),
  main form select, main form textarea {
    width: 100% !important; min-width: 0;
    box-sizing: border-box;
  }
  /* a width cap (e.g. Tailwind max-w-[13rem]) still wins over the full-width default */
  /* iOS/Safari collapses EMPTY date/time pickers to minimal width (they only
     widen once a value is picked). Force them to always fill the field. */
  main input[type="month"], main input[type="date"], main input[type="time"],
  main input[type="datetime-local"], main input[type="week"] {
    -webkit-appearance: none; appearance: none;
    width: 100% !important; min-width: 100% !important; box-sizing: border-box;
  }
  main input[type="date"]::-webkit-date-and-time-value,
  main input[type="time"]::-webkit-date-and-time-value,
  main input[type="datetime-local"]::-webkit-date-and-time-value,
  main input[type="month"]::-webkit-date-and-time-value {
    text-align: left; min-width: 100%; margin: 0;
  }

  /* toolbar / filter rows wrap; their children may shrink */
  main form .flex { flex-wrap: wrap; row-gap: .75rem; }
  main form .flex > * { min-width: 0; max-width: 100%; }
  /* a wrapper that holds an input grows to fill its row (clean, full-width fields) */
  main form .flex > div:has(> .form-input),
  main form .flex > div:has(> .relative > .form-input),
  main form .flex > div:has(> input),
  main form .flex > div:has(> select) { flex: 1 1 10rem; }

  /* wide data grids: shrink the sticky name column so more day columns show */
  table.no-cards th.sticky, table.no-cards td.sticky {
    width: 9.5rem !important; min-width: 9.5rem !important; max-width: 9.5rem !important;
  }
  table.no-cards th.sticky > *, table.no-cards td.sticky > * { max-width: 100%; }
}

/* ---------- Native-feel polish (mobile-ui-design skill) ---------- */
@media (max-width: 767px) {
  /* 16px form fields prevent iOS Safari from auto-zooming on focus */
  main .form-input, main .form-select, main textarea,
  main form input:not([type=checkbox]):not([type=radio]),
  main form select, main form textarea,
  .mlog-field, #empSearch, #rangePicker { font-size: 16px !important; }

  /* Apple-HIG 44px touch targets */
  #main > header button, #main > header a { min-width: 44px; min-height: 44px; }
  main td a.rounded-lg, main td button.rounded-lg, main td button.punch-cell,
  main th a.rounded-lg, main th button.rounded-lg {
    min-width: 44px; min-height: 44px;
    display: inline-flex; align-items: center; justify-content: center;
  }
  .btn, .tab-item { min-height: 44px; }

  /* notch: push the sticky top bar below the status bar in an installed PWA */
  #main > header {
    padding-top: env(safe-area-inset-top);
    height: calc(4rem + env(safe-area-inset-top));
  }

  /* snappy native-style tap feedback */
  .btn:active, a.card:active, .tab-item:active,
  main td a.rounded-lg:active, main td button.rounded-lg:active { transform: scale(.97); }
}

/* Pull-to-refresh indicator (phones) */
#ptr {
  position: fixed; top: env(safe-area-inset-top); left: 50%;
  transform: translateX(-50%) translateY(-44px);
  z-index: 45; width: 40px; height: 40px; border-radius: 50%;
  display: none; align-items: center; justify-content: center;
  background: #fff; color: #4f46e5; box-shadow: 0 4px 14px rgba(2,6,23,.18);
  opacity: 0; pointer-events: none;
}
@media (max-width: 767px) { #ptr { display: flex; } }
#ptr.spin svg { animation: ptrspin .7s linear infinite; }
@keyframes ptrspin { to { transform: rotate(360deg); } }

/* Respect reduced-motion everywhere */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important; animation-iteration-count: 1 !important;
    transition-duration: .01ms !important; scroll-behavior: auto !important;
  }
}

/* searchable tag-select (chips + dropdown) */
.tagselect { position:relative; }
.ts-control {
  min-height:2.6rem; border:1px solid #cbd5e1; border-radius:.6rem;
  padding:.3rem .4rem; display:flex; flex-wrap:wrap; gap:.3rem; align-items:center; background:#fff;
}
.ts-control:focus-within { border-color:#6366f1; box-shadow:0 0 0 3px rgba(99,102,241,.15); }
.ts-chips { display:flex; flex-wrap:wrap; gap:.3rem; }
.ts-placeholder { color:#94a3b8; font-size:.85rem; padding:.15rem .25rem; }
.ts-chip { display:inline-flex; align-items:center; gap:.35rem; background:#eef2ff; color:#4338ca; border-radius:999px; padding:.2rem .4rem .2rem .6rem; font-size:.8rem; }
.ts-chip-x { cursor:pointer; border:none; background:transparent; color:#6366f1; font-size:1rem; line-height:1; padding:0; }
.ts-chip-x:hover { color:#e11d48; }
.ts-search { flex:1; min-width:8rem; border:none; outline:none; font-size:.85rem; padding:.25rem; background:transparent; color:#1e293b; }
.ts-menu { position:absolute; z-index:25; left:0; right:0; margin-top:.25rem; max-height:13rem; overflow-y:auto; background:#fff; border:1px solid #e2e8f0; border-radius:.6rem; box-shadow:0 12px 28px rgba(2,6,23,.12); }
.ts-item { padding:.5rem .7rem; font-size:.85rem; cursor:pointer; }
.ts-item:hover, .ts-item.ts-active { background:#eef2ff; }
.ts-note { padding:.6rem .7rem; font-size:.8rem; color:#94a3b8; }
