/* mobile.css - phone UX layer (loaded last, CSS only, no layout change on desktop). */
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body { padding-inline: env(safe-area-inset-left) env(safe-area-inset-right); }
.topbar { padding-top: env(safe-area-inset-top); }
.app-footer { padding-bottom: env(safe-area-inset-bottom); }
.toast-region { margin-bottom: env(safe-area-inset-bottom); }
.modal-foot { padding-bottom: max(12px, env(safe-area-inset-bottom)); }

@media (hover: none) and (pointer: coarse) {
  .btn, .icon-btn, .lang-btn, .icon-action, .tab, .chip, .crumb-back,
  .settings-nav a, .settings-nav button { min-height: 44px; }
  .icon-btn, .icon-action { min-width: 44px; }
  .table-wrap, .kanban, .task-board, .settings-nav, .line-editor { -webkit-overflow-scrolling: touch; overscroll-behavior-x: contain; }
  a, button, [role="button"] { -webkit-tap-highlight-color: rgba(11, 31, 75, 0.12); touch-action: manipulation; }
}

@media (max-width: 768px) {
  /* iOS zooms on focus when font-size < 16px */
  .input, .select, .textarea, input, select, textarea,
  .search-inline .input, .filter-select, .auth-refined .auth-form .input { font-size: 16px; }
  .search-inline .input, .filter-select { height: 44px; min-height: 44px; }
  .icon-btn { width: 44px; height: 44px; }
  .lang-btn { height: 40px; }
  .table-wrap { max-width: 100%; }
  .table { min-width: 560px; }
  .table td, .table th { white-space: nowrap; }
  .table td.wrap, .table td.note, .table td .wrap { white-space: normal; }
  .modal { max-height: calc(100dvh - 20px - env(safe-area-inset-bottom)); }
  .page { padding-bottom: calc(40px + env(safe-area-inset-bottom)); }
  img, video, canvas, svg { max-width: 100%; }
}

@media (max-width: 480px) {
  .page { width: calc(100% - 20px); }
  .topbar-inner, .app-footer-inner { width: calc(100% - 20px); }
  .page-head h1 { font-size: 21px; }
  .modal-backdrop { padding: 0; }
  .modal { width: 100%; max-width: 100%; border-end-start-radius: 0; border-end-end-radius: 0; max-height: 92dvh; }
  .modal-foot { display: flex; gap: 8px; }
  .modal-foot .btn { flex: 1 1 0; }
  .toolbar { gap: 8px; }
  .filter-select { flex: 1 1 100%; min-width: 0; }
  .user-popover { width: auto; inset-inline-start: 12px; }
}
/* ---- v2: select arrow (SVG), bottom nav, table cards, columns menu ---- */
select.select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-size: 12px 12px; background-position: right 12px center; background-repeat: no-repeat;
}
[dir="rtl"] select.select, select.select:dir(rtl) { background-position: left 12px center; }

.m-bottom-nav { display: none; }
@media (max-width: 767px) {
  .m-bottom-nav {
    display: flex; position: fixed; inset-inline: 0; bottom: 0; z-index: 60;
    background: rgba(255, 255, 255, 0.97); border-top: 1px solid var(--line, #e3e8ef);
    box-shadow: 0 -4px 16px rgba(11, 31, 75, 0.06);
    padding: 4px 6px calc(4px + env(safe-area-inset-bottom));
    -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
  }
  .m-bottom-nav a {
    flex: 1 1 0; min-height: 52px; display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 2px; color: var(--muted, #64748b); font-size: 10.5px; font-weight: 600; text-decoration: none; border-radius: 10px;
  }
  .m-bottom-nav a[hidden] { display: none; }
  .m-bottom-nav a.active { color: var(--brand, #1d4ed8); background: rgba(29, 78, 216, 0.07); }
  body.has-m-nav { padding-bottom: calc(64px + env(safe-area-inset-bottom)); }
  body.has-m-nav .toast-region { bottom: calc(72px + env(safe-area-inset-bottom)); }
  body.has-m-nav .topbar-actions [data-top="approvals"] { display: none; }
  body.has-m-nav .modal-backdrop { z-index: 80; }

  .contact-columns[open] > .contact-columns-menu {
    position: fixed; inset-inline: 12px; top: auto; bottom: calc(76px + env(safe-area-inset-bottom));
    min-width: 0; max-height: 60dvh; overflow-y: auto; z-index: 70;
  }
  .contact-columns-menu .checkbox { min-height: 40px; font-size: 14px; }
}
@media print { .m-bottom-nav { display: none !important; } }

@media (max-width: 480px) {
  .table.m-cardable { min-width: 0; border-collapse: separate; }
  .table.m-cardable thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .table.m-cardable, .table.m-cardable tbody, .table.m-cardable tr, .table.m-cardable td { display: block; width: 100%; }
  .table.m-cardable tr {
    background: #fff; border: 1px solid var(--line, #e3e8ef); border-radius: 12px;
    margin-bottom: 10px; padding: 6px 4px;
  }
  .table.m-cardable td {
    display: flex; justify-content: space-between; align-items: center; gap: 12px;
    white-space: normal; text-align: start; border: 0; padding: 7px 10px; min-height: 0;
  }
  .table.m-cardable td[data-label]::before {
    content: attr(data-label); flex: 0 0 auto; max-width: 45%;
    color: var(--muted, #64748b); font-size: 12px; font-weight: 600;
  }
  .table.m-cardable td:not([data-label]), .table.m-cardable td[data-label=""] { justify-content: flex-end; }
  .table.m-cardable td[colspan] { justify-content: center; }
  .table-wrap.round:has(.m-cardable) { border: 0; background: transparent; }
}
/* v3: stop stray 1-2px overflow (e.g. attendance context tabs) from widening the phone viewport. clip keeps position:sticky working. */
@media (max-width: 767px) { html, body { overflow-x: clip; } }

/* ---- v4: iPad and touch tablets (2026-11-21) -----------------------------
   A touch tablet has no hover, so the desktop header wrapped the search into a
   162px two-row bar in portrait; on a 1024px iPad the search itself collapsed
   to 57px. Keep one row on tablets, give the search real room, and turn every
   compact control into a proper touch target. Phone layouts (<=767px) keep
   their own two-row header and are untouched. */
@media (hover: none) and (pointer: coarse) and (min-width: 761px) and (max-width: 1400px) {
  .topbar-inner { flex-wrap: nowrap; gap: 8px; }
  .brand-company, .topbar-divider, .topbar-app, .search-kbd { display: none; }
  .search-shell { order: 0; flex: 1 1 180px; max-width: 560px; min-width: 0; }
}

/* Portrait tablets: the logo alone is enough; the user menu keeps the name. */
@media (hover: none) and (pointer: coarse) and (min-width: 761px) and (max-width: 1024px) {
  .brand-name { display: none; }
  .brand img { width: 36px; height: 36px; }
  .user-chip { padding: 2px; }
  .user-chip-text { display: none; }
}

@media (hover: none) and (pointer: coarse) {
  /* iPadOS zooms the page whenever a focused control is smaller than 16px. */
  .input, .select, .textarea,
  .search-box input, .search-inline .input, .inline-form .input, .inline-form .select,
  .filter-select, select, textarea,
  input:not([type="checkbox"]):not([type="radio"]):not([type="range"]) { font-size: 16px; }
  .input, .select, .toolbar .input, .toolbar .select,
  .search-inline .input, .filter-select { min-height: 44px; }
  .search-box { height: 44px; }
  .context-tab, .context-app, .context-back { min-height: 44px; }
  .context-tab { padding-inline: 12px; }
  .context-scroll { width: 44px; height: 44px; }
  .seg-btn { min-height: 40px; }
  .crumb { min-height: 40px; }
  .odoo-foot-link { min-height: 40px; padding-block: 8px; }
  .pager button { min-width: 40px; height: 40px; }
  .brand { min-height: 44px; }
  .btn.icon, .page-head .page-actions .btn { min-width: 40px; }
  /* Module sheets load after this file; scope through their containers. */
  .sales-command .sc-search .input { height: 44px; min-height: 44px; font-size: 16px; }
  .sales-command .sc-filters .filter-select,
  .sales-command .sc-filters .input { height: 44px; min-height: 44px; font-size: 16px; }
  .sales-command .sc-date { height: 44px; }
  .sales-command .sc-date .input { width: 128px; height: 40px; min-height: 40px; font-size: 16px; }
  .sales-recent .recent-chip { min-height: 40px; }
  .nq-rpt-toolbar-main .nq-rpt-preset { min-height: 40px; }
  .nq-rpt-range input { min-height: 44px; font-size: 16px; }
  .doc-toolbar .doc-search { height: 44px; }
  .doc-toolbar .doc-search input { font-size: 16px; }
  /* documents.css is injected after this file; the child selector wins. */
  .doc-card .doc-card-menu { width: 44px; height: 44px; top: 4px; inset-inline-end: 4px; }
  .doc-toolbar-end .doc-view-toggle button { min-height: 40px; }
  .doc-check input, .checkbox input, .radio input { width: 20px; height: 20px; }
  .checkbox { min-height: 40px; align-items: center; }
  .nq-net-retry { min-height: 44px; }
}

/* Long/wide tables (tablets only): pin the header while the list scrolls.
   The wrapper is already a horizontal scroller, so a page-level sticky can
   never reach the header; bound its height and let it scroll on both axes.
   Phones keep their card mode and page scrolling untouched. */
@media (hover: none) and (pointer: coarse) and (min-width: 761px) {
  .table-wrap {
    max-height: calc(100dvh - 150px);
    overflow: auto; -webkit-overflow-scrolling: touch;
  }
  .table thead th, .contact-grid-table thead th {
    position: sticky; top: 0; z-index: 5;
  }
  /* The pinned first column is also a header cell: it must outrank the other
     headers (the 621–900px rule sets z-index 1 on it). */
  .table thead th:first-child,
  .table:has(thead th:nth-child(6)) thead th:first-child,
  .contact-grid-table thead th:first-child { z-index: 6; }
  /* Dialogs keep their own body scroll; a capped table there would double up. */
  .modal .table-wrap, .modal-body .table-wrap { max-height: none; }
}
