/* Responsive layer.
   Breakpoints:  <=768px phone (tab bar, sheets)  |  769-1024px tablet  |  >1024px desktop */

/* ============ tablet ============ */
@media (max-width: 1024px) {
  .grid-scroll { max-height: calc(100dvh - 320px); }
  .settings-grid,
  .users-grid { grid-template-columns: 1fr; }
  .brand-text { display: none; }
}

/* ============ phone ============ */
@media (max-width: 768px) {
  /* iOS zooms any focused control under 16px — keep inputs at 16px. */
  .input, .select, textarea.input { font-size: 16px; }

  /* ---- header: title + account only; sections move to the tab bar ---- */
  .topbar {
    gap: 10px; padding: 8px 14px; padding-top: calc(8px + var(--safe-top));
    min-height: calc(52px + var(--safe-top));
  }
  .brand { font-size: 15px; }
  .brand-text { display: none; }
  .page-title { display: block; font-weight: 800; font-size: 16px; }
  .nav, .user-chip, .spacer { display: none; }
  .acc-btn {
    display: grid; place-items: center; margin-left: auto;
    width: 36px; height: 36px; border-radius: 50%;
    border: none; background: var(--primary); color: #fff;
    font-size: 13px; font-weight: 800; cursor: pointer;
  }

  /* ---- bottom tab bar ---- */
  .tabbar {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
    display: grid; grid-auto-flow: column; grid-auto-columns: 1fr;
    background: var(--surface); border-top: 1px solid var(--border);
    padding-bottom: var(--safe-bottom);
  }
  .tab-item {
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
    min-height: 56px; border: none; background: transparent;
    color: var(--muted); font-size: 11px; font-weight: 700; cursor: pointer;
  }
  .tab-icon { font-size: 20px; line-height: 1; }
  .tab-item.active { color: var(--primary); }

  /* room for the bar */
  .container { padding: 0 14px; margin: 14px auto calc(72px + var(--safe-bottom)); }
  .toast { bottom: calc(78px + var(--safe-bottom)); }

  /* ---- page ---- */
  .page-head { display: none; }          /* the header already names the screen */
  .card { padding: 14px; border-radius: 14px; }
  .card + .card { margin-top: 12px; }

  /* ---- schedule chrome ---- */
  .sched-chrome { margin-bottom: 10px; }
  .wk-head { padding-bottom: 14px; gap: 6px; }
  .wk-title { letter-spacing: -.02em; }
  .sched-controls { padding: 12px 0 10px; gap: 10px; }
  .week-bar { display: none; }
  .week-stepper { display: flex; width: 100%; }
  .ctl-right { width: 100%; gap: 8px; }
  .toolbar { display: contents; }          /* let search and modes flow in .ctl-right */
  .search-box { flex: 1 1 100%; width: auto; height: var(--tap); }
  .segmented { flex: 1; height: var(--tap); }
  .segmented button { flex: 1; justify-content: center; }
  .btn-line { flex: none; height: var(--tap); padding: 0 12px; }
  .cal-btn-text { display: none; }
  .toolbar-hint { display: none; }
  .pos-bar { gap: 8px; padding-bottom: 12px; }
  .pos-chips { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; }
  .pos-chips::-webkit-scrollbar { display: none; }
  .pos-chip { min-height: 32px; }

  /* ---- week meta ---- */
  .week-meta { gap: 4px 14px; font-size: 12.5px; }
  .week-meta-card { padding: 10px 14px; }

  /* ---- day view ---- */
  .day-head { padding: 12px 14px; }
  .day-title { font-size: 16px; }
  .day-sub { font-size: 13px; }
  .dv-row {
    display: grid; grid-template-columns: 1fr auto; gap: 6px 10px;
    align-items: start; padding: 11px 14px;
  }
  .dv-emp { width: auto; min-width: 0; }
  .dv-shifts { grid-column: 1 / -1; }
  .dv-total { grid-column: 2; grid-row: 1; }

  /* ---- table mode stays scrollable but leaner ---- */
  .grid-scroll { max-height: calc(100dvh - 300px); min-height: 240px; }
  table.grid { min-width: 720px; }
  .emp-cell { min-width: 132px; max-width: 150px; padding: 8px 10px; }
  .total-cell { min-width: 74px; width: 74px; padding: 8px 10px; }
  td.day-cell { min-width: 104px; }

  /* ---- admin ---- */
  .dropzone { padding: 22px 14px; }
  .upload-actions { flex-wrap: nowrap; }
  .upload-actions .btn { flex: 1; }
  .week-item { flex-wrap: wrap; }
  .wi-actions { width: 100%; justify-content: flex-start; }
  .wi-actions .btn { flex: 1; min-height: var(--tap); }
  .fr-name { max-width: 100%; }
  .fr-msg { flex-basis: 100%; text-align: left; }
  .create-form { flex-direction: column; align-items: stretch; }
  .create-form .input, .create-form .select { width: 100%; min-width: 0; }
  .create-actions .btn { width: 100%; min-height: var(--tap); }
  .audit-list { max-height: none; }

  /* settings + consent on phones */
  .color-pair { flex-direction: column; }
  .consent { bottom: calc(72px + var(--safe-bottom)); padding: 14px; }
  /* keep the page scrollable past the notice */
  body.has-consent .container { margin-bottom: calc(230px + var(--safe-bottom)); }
  .consent-actions { flex-direction: column-reverse; }
  .consent-actions .btn { width: 100%; min-height: var(--tap); }
  .cal-legend { font-size: 11.5px; }

  /* user list: table -> stacked cards */
  .dl-head { display: none; }
  .dl-row {
    grid-template-columns: 1fr auto; gap: 8px 10px;
    padding: 14px; border-bottom: 8px solid var(--bg);
  }
  .dl-row:last-child { border-bottom: none; }
  .dl-user { grid-column: 1; }
  .dl-role { grid-column: 2; grid-row: 1; justify-self: end; }
  .dl-note, .dl-date { grid-column: 1 / -1; display: flex; gap: 6px; font-size: 13px; }
  .dl-note::before, .dl-date::before {
    content: attr(data-label) ':'; color: var(--muted); font-weight: 600; flex: none;
  }
  .dl-note { white-space: normal; }
  .dl-actions { grid-column: 1 / -1; justify-content: stretch; gap: 8px; }
  .dl-actions .btn { flex: 1; min-height: var(--tap); }

  /* week items: stack the meta, full-width actions */
  .wi-title { font-size: 15px; }
  .wi-stats { font-size: 13px; }

  /* ---- touch targets ---- */
  .btn { min-height: var(--tap); }
  .btn-sm { min-height: 38px; }
  .icon-btn { width: var(--tap); height: var(--tap); }

  /* ---- overlays become bottom sheets ---- */
  .modal-backdrop { align-items: end; padding: 0; }
  .modal {
    max-width: none; width: 100%;
    border-radius: 18px 18px 0 0; border-bottom: none;
    padding: 8px 18px calc(20px + var(--safe-bottom));
    max-height: 88dvh; transform: translateY(100%);
  }
  .modal-backdrop.open .modal { transform: translateY(0); }
  .sheet-handle {
    display: block; width: 40px; height: 4px; margin: 6px auto 12px;
    border: none; border-radius: var(--radius-pill); background: var(--border); padding: 0;
  }
  .modal-actions { position: sticky; bottom: 0; background: var(--surface); padding-top: 10px; }
  .modal-actions .btn { flex: 1; min-height: var(--tap); }
  .cal-modal { max-width: none; }
  .cal-cell { font-size: 15px; }
  .login-card { padding: 26px 20px; }
}

/* ============ very small phones ============ */
@media (max-width: 400px) {
  .segmented button { font-size: 13px; }
  .day-pill { min-width: 48px; }
  .tab-label { font-size: 10px; }
  .ec-day-label { width: 54px; }
}

/* ============ landscape phones ============ */
@media (max-width: 900px) and (orientation: landscape) and (max-height: 480px) {
  .tabbar { display: none; }
  .nav { display: flex; }
  .container { margin-bottom: 16px; }
  .grid-scroll { max-height: calc(100dvh - 200px); }
}
