/* Phones and small tablets (UI-70). Loaded last so these rules win. Each page's own stylesheet already handles its
   layout (columns stacking, the top bar's menu button); this file adds the shared fixes: spacing, stacked headers and
   filters, scrolling tabs and tables, picker widths, and touch-sized controls. Tokens only. */

/* Nothing pushes the page wider than the screen; wide tables scroll inside their card instead. */
html, body { max-width: 100%; overflow-x: clip; } /* clip, not hidden: hidden would stop the top bar from staying put */
.table-responsive { -webkit-overflow-scrolling: touch; }
img, svg, video { max-width: 100%; }

/* Tablets */
@media (max-width: 991.98px) {
  .app-content { padding-inline: 16px; }
  .form-narrow, .settings-panel, .setup-card { max-width: 100%; width: 100%; }
}

/* Settings on a phone: first just the tiles; a tile opens its form alone, with a way back to the tiles */
.settings-back { display: none; }
@media (max-width: 991.98px) {
  .settings-layout.is-menu .settings-panel { display: none; }
  .settings-layout.is-open .settings-nav { display: none; }
  .settings-back { display: inline-flex; align-items: center; gap: 0.4rem; align-self: flex-start; margin-bottom: 0.6rem; font-size: 0.9rem; font-weight: 600; text-decoration: none; color: var(--lb-primary); }
  .settings-panel-header { flex-wrap: wrap; }
  .settings-back { flex: 0 0 100%; }
  .settings-nav { display: grid; grid-template-columns: repeat(auto-fit, minmax(9.5rem, 1fr)); gap: 0.4rem; overflow: visible; }
  .settings-nav-link { flex-direction: column; justify-content: center; gap: 0.35rem; min-height: 5rem; padding: 0.7rem 0.4rem; text-align: center; border: 1px solid var(--lb-border-soft); }
  .settings-nav-link.active { border-color: var(--lb-primary); }
  .settings-nav-link.active::before { display: none; }
  .settings-nav-title { font-size: 0.875rem; font-weight: 600; line-height: 1.2; }
}

/* Phones */
@media (max-width: 767.98px) {
  .app-content { padding: 16px 12px; }
  .app-content h1.h4 { font-size: 1.35rem; }

  /* Title above, buttons below at full width */
  .page-header { flex-direction: column; align-items: stretch; margin-bottom: 1rem; }
  .page-header > .d-flex, .page-header > .btn { width: 100%; }
  .page-header .btn { flex: 1 1 auto; }

  /* Filters stack: search first, then the pills, then the extra button (the date range) */
  .filter-bar { flex-direction: column; align-items: stretch; gap: 0.6rem; }
  .filter-search { flex: none; width: 100%; max-width: none; height: 2.75rem; }
  .filter-pills { gap: 0.4rem; }
  .filter-bar-extra { margin-left: 0; }
  .filter-bar-extra .btn, .range-pick-button { width: 100%; justify-content: center; }
  .filter-menu { max-width: calc(100vw - 2rem); }

  /* Tabs: all of them show. They share the row evenly, without icons, and wrap onto a second row if there are many. */
  .nav-tabs, .nav-pills { flex-wrap: wrap; gap: 0.25rem; }
  .nav-tabs .nav-link, .nav-pills .nav-link { flex: 1 1 auto; justify-content: center; padding-inline: 0.7rem; font-size: 0.9rem; white-space: nowrap; }
  .nav-tabs .nav-link > i, .nav-pills .nav-link > i { display: none; }

  /* Tables: every row becomes a small card, each cell showing its column title (stacked_tables.js fills data-label).
     The day-by-day attendance grid is a matrix, so it keeps its columns and scrolls. */
  .table:not(.attendance-grid) { display: block; }
  .table:not(.attendance-grid) thead { display: none; }
  .table:not(.attendance-grid) tbody { display: block; }
  .table:not(.attendance-grid) tbody tr { display: block; padding: 0.6rem 0.9rem; border-bottom: 1px solid var(--lb-border-soft); }
  .table:not(.attendance-grid) tbody tr:last-child { border-bottom: 0; }
  .table:not(.attendance-grid) tbody td {
    display: flex; align-items: center; justify-content: space-between; gap: 1rem; width: auto;
    padding: 0.4rem 0; text-align: right !important; border: 0; background: transparent;
  }
  .table:not(.attendance-grid) tbody td::before {
    content: attr(data-label); flex: none; max-width: 40%; text-align: left;
    font-size: 11.5px; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; color: var(--lb-muted);
  }
  .table:not(.attendance-grid) tbody td:not([data-label])::before, .table:not(.attendance-grid) tbody td[data-label=""]::before { content: none; }
  .table:not(.attendance-grid) tbody td:empty { display: none; }
  .table:not(.attendance-grid) tbody td > * { min-width: 0; }
  .table:not(.attendance-grid) tbody td.text-end, .table:not(.attendance-grid) tbody td .decision-actions { justify-content: flex-end; }
  .table-responsive:has(> .attendance-grid) { overflow-x: auto; }

  /* Forms: 16px text so phones don't zoom in on focus, comfortable touch height, buttons side by side or full width */
  .form-control, .form-select, .date-picker-box, .time-picker-box { font-size: 16px; min-height: 2.75rem; }
  .btn { display: inline-flex; align-items: center; justify-content: center; }
  form .btn { min-height: 2.75rem; }
  .card-body > form > .d-flex.gap-2:last-child .btn,
  .row > .col-12.d-flex.gap-2 .btn { flex: 1 1 0; }

  /* Pop-ups and pickers fit the screen */
  .dp-panel, .tp-panel { max-width: calc(100vw - 1.5rem); }
  .rp-panel { max-width: calc(100vw - 1rem); }
  .reject-picker { width: calc(100vw - 1rem); max-width: none; }

  /* Approve / Reject rows */
  .decision-actions { justify-content: flex-start; }
  .decision-actions .decision-reason.show, .decision-actions .decision-reason.collapsing { justify-content: flex-start; }
  .decision-actions .decision-reason .reason-pill { max-width: none; }

  /* Calendar days: the overtime label ("OT 2h", "+2h") is small and sits at the bottom of the day, so it never pushes the date out of its box */
  .attendance-cell { min-height: 36px; height: 36px; padding: 2px; align-items: center; justify-content: center; border-radius: 10px; }
  .attendance-cell-date { justify-content: center; }
  .attendance-cell .attendance-ot { position: absolute; bottom: 1px; left: 50%; padding: 0 3px; font-size: 0.5rem; line-height: 1.4; transform: translateX(-50%); }

  /* Pagination: info above, buttons centred */
  .pagination-bar { justify-content: center; }
  .pagination-bar .pagination { flex-wrap: wrap; justify-content: center; }
}

/* Small phones */
@media (max-width: 575.98px) {
  /* Top bar on a phone: menu button on the left; at the right the worked time, Check in / out and the account, all
     compact so they fit one row together. The logo mark steps aside (the menu button is the way in). */
  .topbar-inner { gap: 0.5rem; padding-inline: 12px; }
  .topbar-brand { display: none; }
  .topbar-toggle { margin-right: auto; width: 38px; height: 38px; }
  .topbar-end { gap: 0.4rem; min-width: 0; }
  .navbar-attendance { gap: 0.4rem; margin-left: 0; }
  .navbar-worked { gap: 0.3rem; padding: 0.3rem 0.6rem; font-size: 0.8rem; }
  .navbar-attendance .btn { min-width: 0; min-height: 2.3rem; padding: 0.3rem 0.85rem; font-size: 0.85rem; gap: 0.3rem; }
  .navbar-attendance .btn i { margin: 0 !important; }
  .topbar-user-avatar { width: 32px; height: 32px; }
  .card-body { padding: 1rem; }
  .btn { min-width: 0; }
  .user-menu { width: min(222px, calc(100vw - 1.5rem)); }
}

/* Touch screens: no hover-only details, bigger tap targets for the small buttons */
@media (hover: none) {
  .btn-compact, .btn-sm { min-height: 2.5rem; display: inline-flex; align-items: center; justify-content: center; }
}
