/* ═══════════════════════════════════════════════════════
   Lifesaver Attendance — Mobile & Tablet CSS  v4
   iPhone SE (375) → iPad Pro (1366)
═══════════════════════════════════════════════════════ */

/* ── CSS custom properties ── */
:root {
  --safe-top:    env(safe-area-inset-top,    0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left:   env(safe-area-inset-left,   0px);
  --safe-right:  env(safe-area-inset-right,  0px);
  --navy: #1B2B8B;
  --red:  #E8192C;
}

html { scroll-behavior: smooth; }
* { -webkit-tap-highlight-color: transparent; }

/* ── Toast (CSS-driven show/hide) ── */
.ls-toast-container {
  position: fixed;
  bottom: 80px;
  right: 16px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}
.ls-toast {
  color: #fff;
  padding: 12px 18px;
  border-radius: 12px;
  font-size: 13px;
  font-weight: 600;
  box-shadow: 0 4px 20px rgba(0,0,0,.25);
  pointer-events: all;
  cursor: pointer;
  max-width: 300px;
  opacity: 0;
  transform: translateY(12px);
  transition: opacity .25s ease, transform .25s ease;
}
.ls-toast.ls-toast-show { opacity: 1; transform: translateY(0); }
.ls-toast-success { background: #1D9E75; }
.ls-toast-error   { background: #E8192C; }
.ls-toast-info    { background: #1B2B8B; }
.ls-toast-warn    { background: #BA7517; }

/* ── Hamburger button ── */
.btn-hamburger {
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(255,255,255,0.15);
  border: 1.5px solid rgba(255,255,255,0.3);
  border-radius: 8px;
  color: #fff;
  font-size: 20px;
  padding: 4px 10px;
  cursor: pointer;
  line-height: 1.2;
  min-height: 36px;
  min-width: 42px;
  transition: background 0.15s;
}
.btn-hamburger:hover { background: rgba(255,255,255,0.25); }

/* ── Mobile nav overlay ── */
.mobile-nav-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  z-index: 1199;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.28s ease, visibility 0.28s ease;
}
.mobile-nav-overlay.open { opacity: 1; visibility: visible; }

/* ── Mobile slide-in drawer ── */
.mobile-drawer {
  position: fixed;
  top: 0;
  left: -290px;
  width: 280px;
  height: 100vh;
  height: 100dvh;
  background: var(--navy);
  z-index: 1200;
  transition: left 0.3s cubic-bezier(0.4,0,0.2,1);
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: 4px 0 24px rgba(0,0,0,0.35);
  padding-bottom: calc(20px + var(--safe-bottom));
  -webkit-overflow-scrolling: touch;
}
.mobile-drawer.open { left: 0; }
.mobile-drawer-header {
  display: flex;
  align-items: center;
  padding: 0 18px;
  height: 58px;
  background: rgba(0,0,0,0.18);
  border-bottom: 1px solid rgba(255,255,255,0.1);
  flex-shrink: 0;
}
.mobile-drawer-logo { font-size: 20px; font-weight: 700; flex: 1; }
.mobile-drawer-logo .logo-life  { color: #fff; }
.mobile-drawer-logo .logo-saver { color: var(--red); }
.mobile-drawer-close {
  background: rgba(255,255,255,0.15);
  border: none;
  color: #fff;
  font-size: 18px;
  border-radius: 6px;
  padding: 4px 10px;
  cursor: pointer;
  line-height: 1;
  min-height: 36px;
}
.mobile-drawer .nav-link {
  color: rgba(255,255,255,0.82) !important;
  padding: 15px 24px !important;
  border-bottom: 1px solid rgba(255,255,255,0.08) !important;
  border-left: 4px solid transparent !important;
  font-size: 14px !important;
  font-weight: 500;
  text-decoration: none;
  display: flex !important;
  align-items: center;
  gap: 8px;
  white-space: normal !important;
  transition: background 0.15s;
}
.mobile-drawer .nav-link:hover { background: rgba(255,255,255,0.1); color: #fff !important; }
.mobile-drawer .nav-link.active {
  background: rgba(255,255,255,0.12);
  color: #fff !important;
  border-left-color: var(--red) !important;
  padding-left: 20px !important;
  font-weight: 700;
}
.mobile-drawer .badge-count {
  background: var(--red);
  color: #fff;
  border-radius: 10px;
  padding: 1px 7px;
  font-size: 10px;
  font-weight: 700;
  margin-left: auto;
}

/* ── Table scroll hint ── */
.table-scroll-hint {
  display: none;
  font-size: 11px;
  color: #aaa;
  text-align: center;
  padding: 5px 8px;
  background: #f8f9fc;
  border-top: 1px solid #eee;
  opacity: 1;
  transition: opacity 0.3s;
}

/* ── Table → Card view ── */
@media (max-width: 768px) {
  .table-scroll-hint { display: block; }

  .ls-card-table {
    min-width: unset !important;
    width: 100%;
  }
  .ls-card-table thead { display: none; }
  .ls-card-table tbody tr {
    display: block;
    margin-bottom: 10px;
    border-radius: 12px;
    border: 1px solid #eee;
    background: #fff;
    box-shadow: 0 1px 4px rgba(0,0,0,0.06);
    overflow: hidden;
  }
  .ls-card-table tbody tr.ls-card-colspan { border-radius: 8px; }
  .ls-card-table td {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 10px;
    padding: 10px 14px;
    border-bottom: 1px solid #f5f5f5;
    font-size: 13px;
    min-height: unset !important;
    text-align: left !important;
  }
  .ls-card-table td:last-child { border-bottom: none; }
  .ls-card-table td::before {
    content: attr(data-label);
    font-size: 10px;
    font-weight: 700;
    color: #888;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    flex-shrink: 0;
    min-width: 80px;
    padding-top: 2px;
  }
  .ls-card-table td[colspan] { justify-content: center; }
  .ls-card-table td[colspan]::before { display: none; }

  [data-theme="dark"] .ls-card-table tbody tr { background: #1a1d2e; border-color: #2a2d3e; }
  [data-theme="dark"] .ls-card-table td { border-color: #2a2d3e; }
  [data-theme="dark"] .ls-card-table td::before { color: #666; }
}

/* ── Export button group (Reports) ── */
.ls-export-wrap { position: relative; width: 100%; }
.ls-export-toggle {
  width: 100%;
  padding: 11px;
  background: #555;
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  min-height: 44px;
}
.ls-export-group {
  display: none;
  flex-direction: column;
  gap: 6px;
  margin-top: 6px;
}
.ls-export-group.open { display: flex; }
.ls-export-group .btn-excel,
.ls-export-group .btn-pdf,
.ls-export-group .btn-print {
  width: 100%;
  text-align: center;
  justify-content: center;
  padding: 11px !important;
  display: block !important;
}

/* ── Bottom navigation bar ── */
.ls-bottom-nav {
  display: none;
}
@media (max-width: 768px) {
  .ls-bottom-nav {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: calc(56px + var(--safe-bottom));
    background: #fff;
    border-top: 1.5px solid #e5e7eb;
    z-index: 90;
    box-shadow: 0 -2px 12px rgba(0,0,0,0.08);
    padding-bottom: var(--safe-bottom);
  }
  .ls-bottom-nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    font-size: 9px;
    font-weight: 600;
    color: #888;
    text-decoration: none;
    border: none;
    background: none;
    cursor: pointer;
    transition: color 0.15s;
    padding: 0;
    min-height: 44px;
  }
  .ls-bottom-nav-item.active { color: var(--navy); }
  .ls-bottom-nav-item .ls-nav-icon { font-size: 22px; line-height: 1; }
  .ls-bottom-nav-item .ls-nav-label { font-size: 9px; }

  [data-theme="dark"] .ls-bottom-nav {
    background: #1a1d2e;
    border-color: #2a2d3e;
  }
  [data-theme="dark"] .ls-bottom-nav-item { color: #666; }
  [data-theme="dark"] .ls-bottom-nav-item.active { color: #7b9cff; }

  /* Push content above bottom nav */
  body { padding-bottom: calc(56px + var(--safe-bottom)); }
}


/* ═══════════════════════════════════════════════════════
   iPad Pro  (769px – 1024px)
═══════════════════════════════════════════════════════ */
@media (min-width: 769px) and (max-width: 1024px) {
  .navbar { padding: 0 0.8rem; }
  .nav-link { padding: 12px 10px; font-size: 12px; }
  .content { padding: 1.2rem; }
  .stat-grid { grid-template-columns: repeat(4, 1fr); gap: 10px; }
  .branch-grid { grid-template-columns: repeat(2, 1fr); }
  .devices-grid { grid-template-columns: repeat(2, 1fr); }
  .form-grid { grid-template-columns: repeat(2, 1fr); }
  .layout { grid-template-columns: 1fr; }
  table { font-size: 13px; }
  table thead th { position: sticky; top: 0; z-index: 2; }
}


/* ═══════════════════════════════════════════════════════
   Tablet / Mobile  (≤768px)
═══════════════════════════════════════════════════════ */
@media (max-width: 768px) {

  /* Topbar */
  .topbar {
    padding: 0 0.75rem;
    height: 52px;
    position: sticky;
    top: 0;
    z-index: 100;
    padding-top: var(--safe-top);
  }
  .logo { font-size: 18px; }
  .badge-role, .badge-user { display: none; }
  .btn-logout { padding: 5px 10px; font-size: 12px; }
  .btn-hamburger { display: flex; }
  .navbar { display: none; }

  /* Content */
  .content { padding: 0.9rem; }

  /* Page title */
  .page-title  { font-size: 16px; margin-bottom: 0.9rem; }
  .section-title { font-size: 13px; }

  /* Stat grid */
  .stat-grid { grid-template-columns: repeat(2, 1fr); gap: 8px; margin-bottom: 1rem; }
  .stat-val  { font-size: 26px; }
  .stat-card { padding: 0.85rem 1rem; }
  .stat-label { font-size: 10px; }

  /* Branch grid */
  .branch-grid  { grid-template-columns: 1fr; gap: 8px; }
  .branch-stats { flex-wrap: wrap; gap: 10px 18px; }

  /* Layout grids — force single column */
  .layout,
  .two-col,
  .form-grid,
  .form-row,
  .row2,
  .add-form-grid { grid-template-columns: 1fr !important; }

  /* Filter bar */
  .filter-bar {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
    padding: 0.75rem;
  }
  .filter-bar label { display: none; }
  .filter-bar input,
  .filter-bar select { width: 100%; }
  .btn-filter,
  .btn-add,
  .btn-absence,
  .btn-print,
  .btn-excel,
  .btn-pdf { width: 100%; text-align: center; justify-content: center; padding: 11px 16px; }

  /* Search bar */
  .search-bar    { flex-direction: column; gap: 8px; padding: 0.75rem; }
  .search-input  { min-width: unset; width: 100%; }
  .search-select { width: 100%; }
  .page-header   { flex-direction: column; align-items: stretch; gap: 8px; }
  .btn-add-emp   { width: 100%; text-align: center; padding: 12px; font-size: 14px; }

  /* Table wrapper */
  .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; border-radius: 10px; }

  /* Non-card tables: sticky first column */
  table:not(.ls-card-table) { min-width: 540px; font-size: 12px; }
  table:not(.ls-card-table) th { padding: 9px 10px; font-size: 10px; }
  table:not(.ls-card-table) td { padding: 8px 10px; }
  table:not(.ls-card-table) th:first-child,
  table:not(.ls-card-table) td:first-child {
    position: sticky;
    left: 0;
    background: #fafafa;
    z-index: 2;
    box-shadow: 2px 0 6px rgba(0,0,0,0.07);
  }
  [data-theme="dark"] table:not(.ls-card-table) th:first-child,
  [data-theme="dark"] table:not(.ls-card-table) td:first-child { background: #1a1d2e; }

  /* Action buttons — touch-friendly */
  .action-row   { flex-wrap: wrap; gap: 4px; }
  .btn          { padding: 7px 10px !important; font-size: 11px !important; min-height: 36px; }
  .action-btn   { padding: 7px 10px !important; font-size: 11px !important; min-height: 36px; }
  .btn-approve,
  .btn-reject   { padding: 7px 12px; font-size: 12px; min-height: 36px; }

  /* Summary grid */
  .summary-grid { grid-template-columns: repeat(2, 1fr); gap: 8px; }

  /* Devices grid */
  .devices-grid { grid-template-columns: 1fr; }

  /* Modal — bottom sheet */
  .modal-overlay { align-items: flex-end; }
  .modal,
  .modal-box {
    margin: 0;
    padding: 1.4rem 1.2rem;
    border-radius: 20px 20px 0 0;
    max-height: 92vh;
    max-height: 92dvh;
    overflow-y: auto;
    width: 100% !important;
    max-width: 100% !important;
    padding-bottom: calc(1.4rem + var(--safe-bottom));
    -webkit-overflow-scrolling: touch;
  }
  .modal-overlay.open { align-items: flex-end; }

  /* Employee card */
  .emp-card   { flex-direction: column; text-align: center; }
  .emp-avatar { margin: 0 auto; }

  /* Tabs */
  .tabs {
    overflow-x: auto;
    flex-wrap: nowrap;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
    gap: 5px;
  }
  .tabs::-webkit-scrollbar { display: none; }
  .tab-btn { padding: 8px 14px; font-size: 12px; white-space: nowrap; min-height: 40px; }

  /* Messages */
  .msg-header { flex-direction: column; gap: 6px; }
  .msg-actions { flex-wrap: wrap; gap: 6px; }

  /* Buttons */
  .btn-add  { padding: 10px 16px; font-size: 13px; }
  .btn-save { width: 100%; }
  .btn-submit { min-height: 48px; }
  .btn-leave-submit { width: 100%; padding: 12px; }
  .btn-message { min-height: 52px; font-size: 15px; }

  /* Employee profile */
  .leave-request-form .form-row { grid-template-columns: 1fr !important; }

  /* Footer */
  .footer { font-size: 10px; padding: 1rem; }

  /* Table header */
  .table-header { flex-direction: column; align-items: flex-start; gap: 8px; }
  .table-head   { flex-direction: column; gap: 6px; }
  .filter-tabs  { flex-wrap: wrap; gap: 5px; }

  /* Touch-friendly inputs — 44px min + prevent iOS zoom */
  input, select, button { min-height: 44px; }
  input[type="checkbox"],
  input[type="radio"] { min-height: unset; }
  .field input, .field select, .field textarea,
  .form-field input, .form-field select, .form-field textarea,
  .form-group input, .form-group select, .form-group textarea,
  .filter-bar input, .filter-bar select,
  .search-input, .search-select { font-size: 16px !important; }

  /* Salary structure inline inputs */
  .struct-form input, .struct-form select { min-height: 40px; font-size: 14px !important; }
}


/* ═══════════════════════════════════════════════════════
   Small Mobile  (≤480px)
═══════════════════════════════════════════════════════ */
@media (max-width: 480px) {
  .topbar     { padding: 0 0.55rem; height: 50px; }
  .logo       { font-size: 17px; }
  .content    { padding: 0.7rem; }
  .filter-bar { padding: 0.65rem; }
  .stat-grid  { grid-template-columns: repeat(2, 1fr); gap: 6px; }
  .stat-val   { font-size: 22px; }
  .stat-card  { padding: 0.75rem 0.9rem; }
  .summary-grid { grid-template-columns: repeat(2, 1fr); gap: 6px; }
  .topbar-right { gap: 4px; }
  .page-title   { flex-wrap: wrap; gap: 5px; font-size: 15px; }
  .btn-logout, .btn-dark, .btn-lang { font-size: 12px; padding: 4px 8px; min-height: 36px; }
  .leave-bal-card { padding: 0.75rem; }
  .leave-bal-nums { font-size: 20px; }
}


/* ═══════════════════════════════════════════════════════
   Very Small Mobile  (≤360px)
═══════════════════════════════════════════════════════ */
@media (max-width: 360px) {
  .logo       { font-size: 15px; }
  .stat-val   { font-size: 20px; }
  .content    { padding: 0.55rem; }
  .stat-grid  { gap: 5px; }
}


/* ═══════════════════════════════════════════════════════
   Dark mode — mobile-specific
═══════════════════════════════════════════════════════ */
[data-theme="dark"] .mobile-drawer         { background: #111827; }
[data-theme="dark"] .mobile-drawer-header  { background: rgba(0,0,0,0.3); }
[data-theme="dark"] .mobile-drawer .nav-link { color: rgba(255,255,255,0.75) !important; }
[data-theme="dark"] .mobile-drawer .nav-link:hover,
[data-theme="dark"] .mobile-drawer .nav-link.active { color: #fff !important; background: rgba(255,255,255,0.1); }
[data-theme="dark"] .table-scroll-hint { background: #1a1d2e; color: #555; border-color: #2a2d3e; }
[data-theme="dark"] .btn-hamburger    { background: rgba(255,255,255,0.1); }
[data-theme="dark"] .ls-export-toggle { background: #374151; }
