/* Mobile fixes for phones (tested at iPhone 17 Pro Max, 440 x 956).
   Loaded last so it only corrects layout, spacing and touch targets on small
   screens. Colours, type and components stay as in the approved design. */

/* Safe areas: content clears the notch, Dynamic Island and home indicator */
@media (max-width: 960px) {
  .topbar { padding-top: env(safe-area-inset-top); height: calc(56px + env(safe-area-inset-top)); }
  .sidebar { padding-top: env(safe-area-inset-top); padding-bottom: calc(12px + env(safe-area-inset-bottom)); }
  .dock { padding-bottom: env(safe-area-inset-bottom); }
  .dock button { height: 56px; }
  .toast { bottom: calc(72px + env(safe-area-inset-bottom)); }
  /* Drawer overlay sits above the floating mic and dock */
  .shade.show { z-index: 25; }
  .sidebar { z-index: 30; }
  body:has(.sidebar.open) .floating-assistant { opacity: 0; pointer-events: none; }
}

@media (max-width: 600px) {
  html, body { overflow-x: hidden; }
  .content { padding: 20px 16px calc(96px + env(safe-area-inset-bottom)); }

  /* iOS zooms into any field under 16px when it gets focus */
  input, select, textarea,
  .task-detail :is(input, select, textarea),
  .detail-body :is(input, select, textarea) { font-size: 16px; }

  /* Top bar: 44px touch targets, icons on one baseline, even gaps */
  .topbar { gap: 4px; }
  .topbar .icon-btn, .cmd-trigger { width: 40px; height: 44px; padding: 0; display: grid; place-items: center; }
  .menu-btn { margin-left: -10px; }
  .top-right { gap: 0; margin-right: -8px; }
  .topbar svg { width: 20px; height: 20px; }
  .top-logo { width: 72px; margin-left: 2px; }
  .bell-count { top: 6px; right: 4px; min-width: 16px; height: 16px; line-height: 16px; font-size: 10px; }

  /* Header: greeting block then full width action */
  .head { gap: 16px; }
  .head h1 { font-size: 28px; line-height: 1.15; }
  .head .btn.primary { width: 100%; height: 48px; border-radius: 12px; }

  /* Stats: clean 2 x 2 grid with matching dividers (was 4 cramped columns
     with a missing divider and a half top border) */
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stat { padding: 16px; border-left: 1px solid var(--line); border-top: 0; min-height: 80px; }
  .stat:nth-child(odd) { border-left: 0; }
  .stat:nth-child(n+3) { border-top: 1px solid var(--line); }
  .stat b { font-size: 26px; }
  .stat span { font-size: 13px; }

  /* Section headers: title and button centred on one line */
  .sec-head { align-items: center; min-height: 40px; margin-bottom: 12px; gap: 12px; }
  .sec-head .btn, .panel-head .btn { height: 36px; flex: none; }

  /* Deadline cards: due date stays on the title row instead of
     dropping to an empty second line; checkbox column matches its box */
  .tcard { grid-template-columns: 24px minmax(0, 1fr) auto; column-gap: 12px; row-gap: 4px; align-items: start; padding: 14px 16px 14px 14px; min-height: 0; }
  .tcard > .chk { grid-column: 1; grid-row: 1 / span 2; margin-top: -2px; }
  .tcard > div { grid-column: 2; grid-row: 1 / span 2; }
  .tcard > .due, .tcard > .stamp, .tcard.done > .stamp { grid-column: 3; grid-row: 1; justify-self: end; white-space: nowrap; max-width: none; font-size: 12px; }
  .tcard .t { font-size: 15px; line-height: 1.35; }
  .tcard .m { font-size: 12px; margin-top: 2px; }
  .tcard, .row { cursor: pointer; }

  /* Task toolbar: filters span the full width, sort and view toggle on
     one aligned row underneath */
  .toolbar { flex-wrap: wrap; overflow: visible; margin: 0 0 12px; padding: 0; gap: 8px; }
  .toolbar > .seg, #filters { width: 100%; max-width: none; overflow-x: auto; scrollbar-width: none; }
  #filters::-webkit-scrollbar { display: none; }
  .seg button { height: 36px; font-size: 13px; padding: 0 10px; }
  .toolbar .right { width: 100%; display: flex; align-items: center; gap: 8px; margin-left: 0; }
  .toolbar .right > :first-child { flex: 1; min-width: 0; }
  .toolbar .right select { width: 100%; height: 40px; }

  /* List rows: titles wrap to two lines instead of being cut off */
  .row { grid-template-columns: 24px minmax(0, 1fr) auto; column-gap: 12px; min-height: 52px; padding-top: 10px; padding-bottom: 10px; align-items: center; }
  .row .t { white-space: normal; overflow: visible; text-overflow: clip; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; line-height: 1.35; overflow: hidden; }
  .row .due { white-space: nowrap; font-size: 12px; }

  /* Team table fits the screen: no sideways scroll, Late column visible */
  .team { overflow-x: visible; }
  .team > .trow, .trow { min-width: 0; grid-template-columns: minmax(0, 1fr) 44px 44px 40px; gap: 8px; padding: 0 12px; }
  .trow > :not(:first-child) { text-align: right; justify-self: end; }

  /* Side panels share one inner padding */
  .panel { padding: 20px 16px; }
  .perf { flex-wrap: wrap; gap: 8px 12px; align-items: center; }
  .perf > span { flex: 1 1 180px; min-width: 0; }
  .perf .btn { flex: none; margin-left: auto; }

  /* Floating mic: clears the dock and home indicator, and content leaves
     room so it never covers buttons like View or People & teams */
  .floating-assistant { right: 16px; bottom: calc(72px + env(safe-area-inset-bottom)); width: 52px; height: 52px; }
  .content > :last-child { margin-bottom: 72px; }
  .sec-head:has(+ .toolbar) .btn,
  #team-sec .sec-head .btn { margin-right: 0; }

  /* Task dialog becomes a bottom sheet with its actions always reachable */
  .task-detail { width: 100%; max-width: none; margin: auto 0 0; max-height: calc(100dvh - env(safe-area-inset-top) - 24px); border-radius: 20px 20px 0 0; border-bottom: 0; }
  .task-detail[open] { display: flex; flex-direction: column; }
  .task-detail > form, .task-detail > .detail-body, .task-detail > .modal-body { overflow-y: auto; flex: 1; min-height: 0; }
  .detail-head { padding: 16px 16px 12px 20px; align-items: center; position: sticky; top: 0; background: var(--card); z-index: 1; }
  .detail-head h2 { font-size: 20px; line-height: 1.25; }
  .detail-head .icon-btn { width: 44px; height: 44px; flex: none; }
  .detail-head .icon-btn:focus:not(:focus-visible) { outline: none; }
  .task-detail .modal-body, .detail-body { padding: 16px 20px; }
  .task-detail .task-form-grid, .task-detail .task-review-actions { grid-template-columns: 1fr; }
  .task-assigned-field { display: grid; gap: 8px; }
  .task-assigned-field .field-caption { font-size: 13px; color: var(--text-2); }
  .task-assigned-field > div { display: flex; align-items: center; gap: 10px; font-size: 15px; }
  .task-detail .modal-actions, .detail-actions { padding: 12px 20px calc(12px + env(safe-area-inset-bottom)); position: sticky; bottom: 0; background: var(--card); }
  .task-detail .modal-actions .btn, .detail-actions .btn { flex: 1 1 140px; min-height: 44px; justify-content: center; }
}

/* Smaller phones (iPhone SE, mini) */
@media (max-width: 380px) {
  .head h1 { font-size: 24px; }
  .stat b { font-size: 22px; }
  .trow, .team > .trow { grid-template-columns: minmax(0, 1fr) 36px 36px 32px; }
}
