/* Phone layer for every page, public site and back office (server/mobile-shell.js adds this file
   and js/mobile-shell.js to each page). It makes the site behave like an installed iOS / Android
   app on a phone: no tap flash or zoom-on-focus, thumb-sized controls, the back arrow always
   visible, swipe from the left edge to go back, and app-style slides between pages.
   Desktop is untouched: almost everything here sits under the 760px phone breakpoint
   (DESIGN-STANDARD.md §5) or applies only to touch screens. */

html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body { -webkit-tap-highlight-color: transparent; }
/* No 300 ms double-tap wait on controls. */
a, button, input, select, textarea, label, summary, [role="button"] { touch-action: manipulation; }
/* Notched phones in landscape: keep content clear of the rounded corners and the notch. */
body { padding-left: env(safe-area-inset-left); padding-right: env(safe-area-inset-right); }

@media (max-width: 760px) {
  /* iOS zooms into any field whose text is under 16px; that zoom is what makes forms feel broken. */
  input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="color"]),
  select,
  textarea { font-size: max(16px, 1em); }

  /* Thumb-sized targets (44 pt on iOS, 48 dp on Android). */
  .btn, button.btn, a.btn { min-height: 44px; }
  .btn.btn-sm { min-height: 38px; }

  /* Fields never run past the screen's edge. */
  input, select, textarea { max-width: 100%; }
  /* Small tables that aren't record lists (rates, previews) scroll sideways inside themselves. */
  table.gl-mini { display: block; max-width: 100%; overflow-x: auto; }

  /* Lists and tables scroll sideways inside their card, never the whole page. */
  html, body { overflow-x: clip; }
  .admin-table-wrap, .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; overscroll-behavior-x: contain; }

  /* Pop-up windows start below the Demo Mode notice, so their title and close button stay visible. */
  .modal-overlay { padding-top: calc(var(--rc-banner-h, 0px) + 12px + env(safe-area-inset-top)); }

  /* Native-style app bar: stays on top, frosted, compact. */
  .admin-topbar {
    position: sticky;
    /* Below the Demo Mode notice when there is one (its height is measured by mobile-shell.js). */
    top: var(--rc-banner-h, 0px);
    z-index: 60;
    padding-top: calc(8px + env(safe-area-inset-top));
    padding-bottom: 8px;
    background: color-mix(in srgb, var(--color-ink, #16201b) 88%, transparent);
    -webkit-backdrop-filter: saturate(160%) blur(16px);
    backdrop-filter: saturate(160%) blur(16px);
    box-shadow: 0 1px 0 rgba(255, 255, 255, 0.06);
  }
  /* With the bottom bar, the text "Back to dashboard" buttons only repeat the back arrow and the
     bottom bar; they go, so the app bar never squeezes or clips. */
  body.has-bottom-nav .admin-topbar-nav a.admin-nav-link,
  body.admin-shell:has(#profile-mount) .admin-topbar-nav a.admin-nav-link { display: none !important; }
  /* The app bar's round buttons keep their size; the brand name gives way instead. */
  .admin-topbar-nav > * { flex-shrink: 0; }
  .admin-topbar .brand { min-width: 0; flex-shrink: 1; }
  /* Without it (sign-in, public pages) the bar keeps its links, compact enough to fit whole. */
  .admin-topbar-nav .btn-outline.btn-sm { max-width: none; padding: 6px 10px; }
  .admin-topbar .lang-btn { padding-left: 9px; padding-right: 9px; }

  /* Demo Mode notice: one slim line instead of a third of the screen. */
  .demo-mode-banner { padding: 6px 12px !important; font-size: 0.74rem !important; line-height: 1.3 !important; }
  .demo-mode-banner span { display: -webkit-box; -webkit-line-clamp: 1; -webkit-box-orient: vertical; overflow: hidden; }

  /* Cards breathe like native list cells; long words never push buttons off the card. */
  .stat-card, .crm-card, .today-item, .info-card { border-radius: 16px; }
  /* Long words wrap only when a word is wider than the whole line (never "CALENDA / R"); a page
     title beside its main button lets the button drop below it instead. */
  h1, h2, h3, .crm-card-title, .stat-card strong { overflow-wrap: break-word; hyphens: manual; }
  .admin-toolbar { flex-wrap: wrap; row-gap: 12px; }
  .admin-toolbar h1 { min-width: min(100%, 10ch); }

  /* Dialogs become bottom sheets. */
  dialog { max-width: calc(100vw - 16px); }
}

/* Touch screens: the logo's back arrow is a real, always-visible button (no hover on a phone). */
@media (hover: none) {
  .admin-topbar .brand.has-back { padding-left: 38px; min-height: 44px; }
  .admin-topbar .brand.has-back .brand-back {
    opacity: 1;
    transform: none;
    width: 32px;
    height: 32px;
    margin-top: -16px;
  }
  .admin-topbar .brand.has-back .brand-mark { opacity: 1; transform: none; }
  .admin-topbar .brand.has-back:hover .brand-mark { opacity: 1; transform: none; }
  .admin-topbar .brand.has-back .brand-back svg { animation: none; }

  /* Press-and-hold on a deal card opens its actions: no text selection or iOS copy menu on top. */
  .crm-card, .ws-bottom-nav, .crm-stage-tab, .settings-nav-item { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }

  /* Press feedback, as on a native button. */
  .btn:active, .ws-bottom-nav a:active, .ws-bottom-nav button:active, .eco-app:active, .crm-card:active { transform: scale(0.97); transition: transform 0.08s ease; }
}

/* ---- Swipe from the left edge to go back (js/mobile-shell.js) */
.rc-swipe-back {
  position: fixed;
  z-index: 2147483000;
  top: 50%;
  left: 0;
  width: 44px;
  height: 44px;
  margin-top: -22px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: #1b1606;
  background: var(--color-gold, #c9a227);
  box-shadow: 0 8px 24px -8px rgba(0, 0, 0, 0.45);
  transform: translateX(-56px);
  opacity: 0;
  pointer-events: none;
}
.rc-swipe-back svg { width: 20px; height: 20px; }
.rc-swipe-back.is-ready { background: #fff; }
.rc-swipe-shade { position: fixed; inset: 0; z-index: 2147482999; background: #000; opacity: 0; pointer-events: none; }

/* Going back: a thin bar while the previous page loads (js/mobile-shell.js). There are no
   cross-page slide animations on purpose: View Transitions between pages left an empty,
   background-coloured screen on back navigation in WebKit (iPhone). */
.rc-nav-progress {
  position: fixed;
  z-index: 2147483001;
  top: 0;
  left: 0;
  height: 3px;
  width: 100%;
  background: var(--color-gold, #c9a227);
  transform-origin: 0 50%;
  animation: rc-nav-progress 1.4s cubic-bezier(0.2, 0.7, 0.2, 1) forwards;
}
@keyframes rc-nav-progress { from { transform: scaleX(0.08); } to { transform: scaleX(0.9); } }
@media (prefers-reduced-motion: reduce) { .rc-nav-progress { animation: none; transform: scaleX(0.6); } }

/* A tapped health ring shows its reasons (js/mobile-shell.js), inside the screen. */
.ws-health.is-open .ws-health-tip { opacity: 1; transform: none; }
@media (max-width: 760px) { .ws-health-tip { width: min(250px, calc(100vw - 48px)); } }

/* ---- CRM board on phones: one stage at a time, picked from a strip of stage tabs
   (public/js/crm-admin.js renderStageStrip). Wider screens keep every column side by side. */
.crm-stage-strip { display: none; }
@media (max-width: 760px) {
  .crm-stage-strip:not([hidden]) {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-x: contain;
    position: sticky;
    top: calc(var(--rc-banner-h, 0px) + var(--rc-appbar-h, 60px));
    /* Above the cards scrolling under it, below every open menu (pipeline, filters). */
    z-index: 2;
    margin: var(--space-3) calc(-1 * var(--space-3)) 0;
    padding: 10px var(--space-3);
    background: var(--color-cream, #f6f3ee);
    box-shadow: 0 6px 12px -10px rgba(0, 0, 0, 0.35);
  }
  .crm-stage-strip::-webkit-scrollbar { display: none; }
  .crm-stage-tab {
    flex: none;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-height: 40px;
    padding: 8px 14px;
    border-radius: 999px;
    border: 1px solid var(--color-border);
    background: var(--color-white);
    color: var(--color-ink);
    font-size: 0.88rem;
    font-weight: 600;
    white-space: nowrap;
  }
  .crm-stage-tab[aria-selected="true"] { background: var(--color-ink); color: var(--color-white); border-color: var(--color-ink); }
  .crm-stage-tab.is-terminal { font-weight: 500; }
  .crm-stage-tab-count {
    min-width: 22px;
    padding: 1px 7px;
    border-radius: 999px;
    background: rgba(128, 128, 128, 0.18);
    font-size: 0.78rem;
    font-variant-numeric: tabular-nums;
    text-align: center;
  }
  .crm-board.has-stage-strip { margin-top: var(--space-3); }
  .crm-board.has-stage-strip > .crm-column:not(.is-active-stage) { display: none; }
  .crm-board.has-stage-strip > .crm-column { min-height: 0; padding: var(--space-3) var(--space-2); }
}

/* ---- Lists on phones: every row a card (js/data-table.js marks its tables .dt-table and labels
   each cell). The first column is the card's title; the others are label / value pairs, two per
   line, numbers right where you read them. The header turns into a row of sort chips, with the
   columns button at its end. A sideways-scrolling table showed two columns at a time. */
@media (max-width: 640px) {
  .admin-table-wrap:has(> table.dt-table) { overflow-x: visible; border: 0; background: transparent; box-shadow: none; }
  table.dt-table, table.dt-table tbody { display: block; width: 100%; min-width: 0 !important; max-width: 100%; border: 0; background: transparent; }
  table.dt-table thead { display: block; }
  table.dt-table thead tr {
    display: flex;
    gap: 6px;
    align-items: center;
    overflow-x: auto;
    scrollbar-width: none;
    padding: 0 0 10px;
  }
  table.dt-table thead tr::-webkit-scrollbar { display: none; }
  table.dt-table thead th { flex: none; border: 0; padding: 0; background: transparent; position: static; }
  table.dt-table thead th.dt-lead { display: none; }
  table.dt-table thead .dt-sort {
    min-height: 36px;
    padding: 6px 12px;
    border-radius: 999px;
    border: 1px solid var(--color-border);
    background: var(--color-white);
    white-space: nowrap;
    font-size: 0.8rem;
  }
  table.dt-table thead th.is-sorted .dt-sort { background: var(--color-ink); color: var(--color-white); border-color: var(--color-ink); }
  table.dt-table thead th.dt-picker-th { position: sticky; right: 0; margin-left: auto; padding-left: 6px; background: var(--color-cream, #f6f3ee); }

  table.dt-table tbody tr {
    position: relative;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px 14px;
    margin: 0 0 10px;
    padding: 14px 16px;
    border: 1px solid var(--color-border);
    border-radius: 16px;
    background: var(--color-white);
  }
  table.dt-table tbody td {
    display: block;
    min-width: 0;
    padding: 0;
    border: 0;
    background: transparent;
    text-align: left;
    overflow-wrap: anywhere;
    font-variant-numeric: tabular-nums;
  }
  table.dt-table tbody td[data-label]::before {
    content: attr(data-label);
    display: block;
    margin-bottom: 2px;
    font-size: 0.7rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--color-text-muted);
  }
  /* The card's title: the first column that isn't a photo (after the checkbox, if any). Full
     width, no label. */
  table.dt-table tbody tr > td[data-label]:first-child:not([data-dt-col^="photo"]),
  table.dt-table tbody tr > td.dt-lead + td[data-label]:not([data-dt-col^="photo"]),
  table.dt-table tbody tr > td[data-dt-col^="photo"] + td[data-label] {
    grid-column: 1 / -1;
    font-size: 1rem;
    font-weight: 600;
    padding-right: 64px;
  }
  table.dt-table tbody tr > td[data-label]:first-child:not([data-dt-col^="photo"])::before,
  table.dt-table tbody tr > td.dt-lead + td[data-label]:not([data-dt-col^="photo"])::before,
  table.dt-table tbody tr > td[data-dt-col^="photo"] + td[data-label]::before { display: none; }
  /* A photo is the cell's leading avatar, as in an iOS / Android list. */
  table.dt-table tbody tr:has(> td[data-dt-col^="photo"]) { padding-left: 72px; min-height: 72px; }
  table.dt-table tbody td[data-dt-col^="photo"] { position: absolute; left: 14px; top: 14px; width: 44px; height: 44px; overflow: hidden; border-radius: 12px; }
  table.dt-table tbody td[data-dt-col^="photo"]::before { display: none; }
  table.dt-table tbody td[data-dt-col^="photo"] img { width: 44px; height: 44px; object-fit: cover; border-radius: 12px; }
  /* Empty cells add nothing on a phone. */
  table.dt-table tbody td[data-label]:empty, table.dt-table tbody td[data-blank] { display: none; }
  /* The row menu (⋯) and the selection checkbox sit in the card's top-right corner. */
  table.dt-table tbody td.dt-actions { position: absolute; top: 8px; right: 6px; }
  table.dt-table tbody td.dt-actions:empty { display: none; }
  /* Rows whose actions are real buttons (Eliminar, ↑ ↓ ✎ 🗑): a row of buttons at the bottom
     of the card, never on top of its text. A lone ⋯ stays in the corner. */
  table.dt-table tbody td.dt-actions:not(:empty):not(:has(> .row-menu-btn:only-child)) {
    position: static;
    grid-column: 1 / -1;
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 8px;
    padding-top: 10px;
    border-top: 1px solid var(--color-border);
  }
  table.dt-table tbody tr:has(> td.dt-actions:not(:empty):not(:has(> .row-menu-btn:only-child))) > td[data-label] { padding-right: 0; }
  table.dt-table tbody td select, table.dt-table tbody td input:not([type="checkbox"]):not([type="radio"]) { max-width: 100%; }
  table.dt-table tbody td.dt-lead { position: absolute; top: 16px; right: 46px; }
  table.dt-table tbody td.dt-lead input[type="checkbox"] { width: 20px; height: 20px; }
  /* Group headings (Agrupar por), notes and "no results" rows span the card list. */
  table.dt-table tbody tr.fs-group-row, table.dt-table tbody tr.fs-group-note,
  table.dt-table tbody tr:has(> td[colspan]) { display: block; padding: 0; border: 0; background: transparent; margin: 14px 0 8px; }
}

/* ---- Forms on phones: one field per line, as in a native form. Two 140px columns squeezed
   pairs like amount + currency into a 60px box. */
@media (max-width: 560px) {
  .field-row { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 760px) {
  /* Client page's ‹ 12 / 237 › pager fits beside the save status. */
  .cd-pager { gap: 4px; }
  .cd-pager-pos { min-width: 0; }
  /* Knowledge topics: the delete × is its own target next to the tab, not on top of it. */
  .study-tab-delete { margin-left: 2px; min-width: 32px; min-height: 32px; }
}

/* ---- Agenda (calendar) on phones: dots in the month grid, the picked day's events in full
   underneath (js/calendar-admin.js renderPhoneAgenda). */
.cal-phone-agenda { display: none; }
@media (max-width: 560px) {
  .cal-day .cal-event-chip, .cal-day .cal-closing-chip, .cal-day .cal-holiday-chip { display: none; }
  .cal-day { min-height: 52px; cursor: pointer; position: relative; }
  .cal-day.has-events::after {
    content: '';
    position: absolute;
    left: 50%;
    bottom: 8px;
    width: 6px;
    height: 6px;
    margin-left: -3px;
    border-radius: 50%;
    background: var(--color-gold, #c9a227);
  }
  .cal-day.is-picked { box-shadow: inset 0 0 0 2px var(--color-gold, #c9a227); }
  .cal-day .cal-day-num { font-variant-numeric: tabular-nums; }
  .cal-phone-agenda { display: block; margin-top: var(--space-4); }
  .cal-phone-agenda-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
  .cal-phone-agenda-head h2 { margin: 0; font-size: 1.05rem; text-transform: capitalize; }
  .cal-phone-agenda-list { display: grid; gap: 8px; }
  .cal-phone-agenda-list .cal-event-chip, .cal-phone-agenda-list .cal-closing-chip, .cal-phone-agenda-list .cal-holiday-chip {
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 48px;
    padding: 10px 14px;
    border-radius: 14px;
    font-size: 0.95rem;
    white-space: normal;
  }
  .cal-phone-agenda-list .cal-chip-text { flex: 1; min-width: 0; overflow: visible; white-space: normal; text-overflow: clip; }
  .cal-phone-agenda-list .cal-chip-check { flex: none; width: 26px; height: 26px; }
  .cal-phone-agenda-empty { margin: 0; padding: 16px; text-align: center; border: 1px dashed var(--color-border); border-radius: 14px; }
}

/* ---- Page head on narrow phones: the main action (+ Nuevo lead, + Agendar tarea…) becomes a
   round "+" button, as in a native app's top bar, so a long title never pushes it off the screen.
   Its text stays as the button's accessible name (visually hidden, not removed). */
@media (max-width: 420px) {
  .ui-page-head { grid-template-columns: minmax(0, 1fr) auto; }
  .ui-page-head .ui-btn-primary:has(> [data-icon]) { width: 48px; height: 48px; padding: 0; border-radius: 50%; justify-content: center; }
  .ui-page-head .ui-btn-primary:has(> [data-icon]) > span:not([data-icon]) {
    position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
  }
  .ui-page-head .ui-btn-primary:has(> [data-icon]) > [data-icon] svg { width: 22px; height: 22px; }
}

/* ---- Deal page on phones (admin/crm-lead.html; its own layout is in css/crm-lead.css). */
@media (max-width: 560px) {
  /* General · Adjuntos · Checklist · Ofertas: one row that scrolls, like a native tab bar. */
  #ld-tabs { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
  #ld-tabs::-webkit-scrollbar { display: none; }
  #ld-tabs > * { flex: none; }
  /* Linked properties: the whole name, on two lines if needed. */
  .crm-property-row-info, .crm-property-row-info * { white-space: normal; overflow: visible; text-overflow: clip; }
}

/* ---- Key figures (Reportes, Contabilidad, Propiedades…: .stat-grid) on phones: two per row,
   large, bold, aligned digits in the body font. 17px numbers in the decorative serif, one per
   screen-wide card, made a phone show two figures at a time. */
@media (max-width: 560px) {
  .stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; gap: 10px !important; }
  .stat-grid > .stat-card { padding: 14px; min-width: 0; }
  .stat-grid .stat-value {
    display: block;
    font-family: var(--font-body, Inter, system-ui, sans-serif);
    font-size: clamp(1.15rem, 5.4vw, 1.5rem);
    font-weight: 700;
    letter-spacing: -0.01em;
    line-height: 1.15;
    font-variant-numeric: tabular-nums;
    overflow-wrap: anywhere;
  }
  .stat-grid .stat-card > :not(.stat-value) { font-size: 0.78rem; }
}

/* ---- Tab rows (Contabilidad's tabs, the deal's tabs…: .crm-pipeline-switcher) on phones: one row
   that scrolls sideways, like a native tab bar, instead of four lines of chips before any content.
   The Calculadora menu inside it opens as a sheet above the bottom bar, so the scrolling row
   can't clip it. */
@media (max-width: 560px) {
  .crm-pipeline-switcher { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch; padding-bottom: 2px; }
  .crm-pipeline-switcher::-webkit-scrollbar { display: none; }
  .crm-pipeline-switcher > * { flex: none; }
  .calc-tab-dropdown-menu {
    position: fixed !important;
    left: 16px !important;
    right: 16px !important;
    top: auto !important;
    bottom: calc(76px + env(safe-area-inset-bottom)) !important;
    width: auto !important;
    max-height: 60vh;
    overflow-y: auto;
    z-index: 1200;
    border-radius: 16px;
  }
}

/* ---- Segmented switchers (.ui-segmented: report types, views, currencies) on phones: always one
   line that scrolls sideways. Wrapped onto several lines, their sliding highlight (sized for one
   line) covered the options on the second line. */
@media (max-width: 760px) {
  .ui-segmented { flex-wrap: nowrap !important; max-width: 100%; overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
  .ui-segmented::-webkit-scrollbar { display: none; }
  .ui-segmented > * { flex: none; white-space: nowrap; }
}

/* ---- Accounting statements on phones (js/mobile-shell.js stackTables): rows keep their order;
   each one shows the account on top (code, name) and its amounts below as labelled pairs, right
   aligned, so the debit / credit / balance columns are on screen instead of off its edge. */
@media (max-width: 560px) {
  table.rc-stack, table.rc-stack tbody, table.rc-stack tfoot { display: block; width: 100%; min-width: 0 !important; }
  table.rc-stack thead { display: none; }
  table.rc-stack tr { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 4px 12px; padding: 12px 4px; border-bottom: 1px solid var(--color-border); }
  /* Desktop column widths (e.g. a 160px Tipo column) don't apply to a stacked row. */
  table.rc-stack td { display: block; padding: 0 !important; border: 0 !important; width: auto !important; min-width: 0 !important; max-width: 100%; text-align: left; overflow-wrap: anywhere; }
  table.rc-stack td[data-label]::before { content: attr(data-label); display: block; font-size: 0.68rem; font-weight: 600; letter-spacing: 0.03em; text-transform: uppercase; color: var(--color-text-muted); }
  /* The first two columns (code / date, then name / description) are the row's heading. */
  table.rc-stack tr > td:nth-child(1) { grid-column: 1 / -1; font-size: 0.8rem; color: var(--color-text-muted); }
  table.rc-stack tr > td:nth-child(2) { grid-column: 1 / -1; font-weight: 600; }
  table.rc-stack tr > td:nth-child(-n+2)::before { display: none; }
  table.rc-stack td.gl-num { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
  table.rc-stack td.gl-num::before { text-align: right; }
  table.rc-stack td:empty { display: none; }
  table.rc-stack td[colspan] { grid-column: 1 / -1; }
  table.rc-stack tfoot tr { font-weight: 700; background: rgba(128, 128, 128, 0.08); border-radius: 12px; }
}

/* Rutas › Rutas · Analítica · Calificaciones: one segmented line on a phone, not a two-line pill. */
@media (max-width: 560px) {
  .routes-floating-nav { flex-wrap: nowrap; justify-content: space-between; gap: 2px; padding: 4px; }
  .routes-floating-nav > * { flex: 1 1 0; min-width: 0; justify-content: center; padding-left: 6px; padding-right: 6px; font-size: 0.85rem; white-space: nowrap; }
}

/* Public map: the provinces are one row that scrolls, so the map is on the first screen. */
@media (max-width: 560px) {
  .province-chips { flex-wrap: nowrap !important; overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch; padding-bottom: 4px; }
  .province-chips::-webkit-scrollbar { display: none; }
  .province-chips > * { flex: none; }
}

/* ======================================================================================
   Every screen shape, not only portrait phones: foldables (narrow cover screens, nearly
   square open screens), tablets in both orientations, phones held sideways.
   ====================================================================================== */

/* Touch screens of any width (tablets, phones sideways): no zoom-on-focus on iPhone, thumb-sized
   controls. The phone rules above key on width; a phone held sideways is wider than 760px. */
@media (pointer: coarse) {
  input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="color"]),
  select,
  textarea { font-size: max(16px, 1em); }
  .btn, button.btn, a.btn { min-height: 44px; }
  .btn.btn-sm { min-height: 38px; }
  .row-menu-btn, .icon-btn, .dt-picker-btn { min-width: 40px; min-height: 40px; }
}

/* Short screens (a phone held sideways, a flip phone's cover screen, a foldable's half screen):
   nothing pinned may take a big share of the height. The app bar, the Demo notice and the CRM stage tabs scroll away with
   the page; the bottom bar keeps only its icons. */
@media (max-height: 500px) {
  .admin-topbar { position: static !important; }
  .demo-mode-banner { position: static !important; }
  .crm-stage-strip:not([hidden]) { position: static !important; box-shadow: none; }
  /* Labels hidden visually only: they stay the links' accessible names. */
  .ws-bottom-nav a > span, .ws-bottom-nav button > span {
    position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
  }
  .has-bottom-nav .admin-main { padding-bottom: calc(64px + env(safe-area-inset-bottom)); }
  .ws-bottom-nav a, .ws-bottom-nav button { min-height: 40px; padding-top: 4px; padding-bottom: 4px; }
  .ui-sheet { max-height: 92dvh; }
  /* Public site: the header scrolls away; the listing's contact bar stays but slimmer. */
  .site-header { position: static !important; }
  .contact-sticky:not([hidden]) { padding-top: 6px !important; padding-bottom: calc(6px + env(safe-area-inset-bottom, 0px)) !important; }
  .contact-sticky-btn { min-height: 40px !important; }
  dialog, .modal-card, .gl-modal-card, .offer-modal-card { max-height: calc(100dvh - 16px); overflow-y: auto; }
}

/* Tablets in portrait and open foldables (761–1024px): the CRM board keeps its columns side by
   side and scrolls sideways (snapping to a column), as on a desktop — stacking every stage made a
   long page — and drag and drop keeps working. */
@media (min-width: 761px) and (max-width: 1024px) {
  .crm-board {
    grid-auto-flow: column !important;
    grid-auto-columns: minmax(280px, 42%) !important;
    overflow-x: auto;
    scroll-snap-type: x proximity;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-x: contain;
    padding-bottom: 8px;
  }
  .crm-board > .crm-column { scroll-snap-align: start; }
}

/* Reportes on small phones (≤420px, e.g. 320px iPhone SE / foldable cover screens): a value
   that doesn't fit beside its label goes under it, right-aligned, instead of past the edge; a
   two-currency amount may break at its "·". The donut stacks above its legend. */
@media (max-width: 420px) {
  .report-stat-row, .report-bar-row .top { flex-wrap: wrap; row-gap: 2px; }
  .report-stat-row .v, .report-bar-row .top .v { white-space: normal; flex-shrink: 1; min-width: 0; margin-left: auto; text-align: right; font-variant-numeric: tabular-nums; }
  .report-bar-row .top .n { white-space: normal; }
  .report-donut-legend-item { flex-wrap: wrap; }
  .report-donut-legend-item b { margin-left: auto; }
}

/* Client page header (client-detail.html): its WhatsApp / review / type badges / pager wrap onto
   two lines on narrow screens instead of pushing the ‹ 12 / 237 › pager past the edge. */
@media (max-width: 760px) {
  .cd-header-side { flex-wrap: wrap; row-gap: 8px; min-width: 0; }
  .cd-header-side > .cd-pager { margin-left: auto; }
}

/* Tablets, open foldables and iPad Split View (761–1100px): the CRM bar (pipeline + key figures |
   currency, view, tools) takes two rows instead of forcing one line, where the pipeline button
   ran into the currency switch. Wider screens keep the single line. */
@media (min-width: 761px) and (max-width: 1100px) {
  .ui-toolbar.has-kpis { flex-wrap: wrap !important; row-gap: 6px; }
  .ui-toolbar.has-kpis > .ui-toolbar-start { flex: 1 1 100% !important; }
  .ui-toolbar.has-kpis > .ui-toolbar-end { flex: 1 1 100% !important; justify-content: space-between; margin-left: 0; flex-wrap: wrap; row-gap: 6px; }
}
/* Any width: a topic's delete × is its own target beside the tab (it overlapped it by 6px). */
.study-tab-delete { margin-left: 2px !important; }
/* The donation banner's × keeps clear of the banner's text and button at every width. */
.donation-banner { padding-right: 44px; }

/* Safe areas on fixed bars: a phone held sideways has its notch / Dynamic Island and rounded
   corners on the sides, which body padding doesn't reach for fixed elements. */
.ws-bottom-nav, .contact-sticky { padding-left: max(6px, env(safe-area-inset-left)); padding-right: max(6px, env(safe-area-inset-right)); }

/* Today › CRM card on open foldables, iPad Split View and small tablets (561–1100px): the card is
   wide but short, so its decorative map would sit under the health bar and the news line. It's
   decoration only, shown where it has room (phones, desktops). */
@media (min-width: 561px) and (max-width: 1100px) {
  .eco-crm-map { display: none; }
  .eco-crm-figure { max-width: none; }
}

/* Search chips on small screens (≤420px: iPhone SE, Slide Over, foldable covers): a chip shrinks
   to the space it has (its value cut with "…") instead of sliding under the filter button; the
   chips take their own line when they need it. */
@media (max-width: 420px) {
  .fs-bar .fs-chips { max-width: 100%; min-width: 0; flex: 1 1 auto; }
  .fs-bar .fs-facet { max-width: 100%; min-width: 0; flex-shrink: 1; display: inline-flex; }
  .fs-bar .fs-facet-body { min-width: 0; overflow: hidden; display: inline-flex; }
  .fs-bar .fs-facet-values { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .fs-bar.has-facets .fs-chips { flex-basis: calc(100% - 96px); }
}

/* Public header on narrow phones: logo · ES/EN · bell · account · ☰ need ~390px. Under 400px the
   gaps and the language switch tighten; under 340px (iPhone SE 1st gen, Slide Over, cover screens)
   the wordmark is hidden visually (kept as the link's name), so ☰ is never pushed off screen. */
@media (max-width: 400px) {
  .site-header .nav { gap: 6px; padding-left: 12px; padding-right: 12px; }
  .site-header .nav-actions { gap: 4px; }
  .site-header .lang-btn { padding: 6px 7px; }
  .site-header .brand { min-width: 0; flex-shrink: 1; }
}
/* Phones: a one-word company name breaks between its bold and light parts (i18n.js
   renderBrandMarks) when it doesn't fit, rather than running under ES/EN and the account button
   or pushing ☰ off the screen. */
@media (max-width: 640px) {
  .site-header .brand { min-width: 0; flex-shrink: 1; }
  .site-header .brand > span { min-width: 0; }
  .site-header .brand-name { display: block; line-height: 1.1; }
}
@media (max-width: 340px) {
  .site-header .brand-name { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
}
/* Admin app bar on the narrowest screens (≤360px): back arrow · logo · search · bell · account;
   the "PROPTYCENTER ADMIN" wordmark is kept only as the logo link's name. */
@media (max-width: 360px) {
  .admin-topbar .brand-name { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
  .admin-topbar-nav { gap: 4px; }
}

/* ---- Large text (Android font scaling, iPhone text zoom) and the narrowest screens: text grows,
   so nothing may depend on a fixed height or a fixed minimum width. */
/* Today's app tiles: the hint is part of the tile's flow, under the name, not pinned to the
   bottom where a two-line name ran into it. */
.eco-app .eco-hint { position: static; margin-top: -4px; max-width: 100%; }
.eco-app { min-height: 0; }
@media (min-width: 761px) { .eco-app { min-height: 156px; } }
/* "Agrupar por" and the calendar's month heading wrap instead of running off the screen. */
.fs-group-pick { flex-wrap: wrap; max-width: 100%; min-width: 0; }
.fs-group-pick select { min-width: 0; max-width: 100%; }
.cal-nav { flex-wrap: wrap; row-gap: 6px; min-width: 0; }
.cal-month-label { min-width: 0; overflow-wrap: break-word; }
/* Search chips: the field name shrinks too ("Operació…"), never under the chip's ✎ / ×. */
.fs-facet-field { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@media (max-width: 360px) {
  /* Deal page: photo and name may stack; no minimum width on a 260px-wide screen. */
  .ld-hero-top { flex-wrap: wrap; }
  .ld-hero-main { flex-basis: 100%; min-width: 0; }
  /* Public listings and their details: one column, no 280px / 220px minimum. */
  .property-grid { grid-template-columns: minmax(0, 1fr) !important; }
  .detail-rows { grid-template-columns: minmax(0, 1fr) !important; }
}

/* ======================================================================================
   Dual-screen and spanned foldables (Surface Duo, a foldable iPhone / Android spanned across its
   fold): the browser reports the two screens as viewport segments. Nothing important may sit in
   the hinge between them. Browsers without the feature skip these rules.
   ====================================================================================== */
/* Side by side (vertical hinge, "book"): the page uses the first screen, as on a single phone,
   so no text, button or card is split by the hinge; dialogs and sheets stay on that screen too. */
@media (horizontal-viewport-segments: 2) {
  body { max-width: env(viewport-segment-width 0 0); }
  .ws-bottom-nav, .contact-sticky, .rc-nav-progress, .demo-mode-banner { right: auto !important; width: env(viewport-segment-width 0 0) !important; }
  .ui-sheet-overlay, .ws-palette-overlay, .modal-overlay, .confirm-modal-overlay { right: auto !important; width: env(viewport-segment-width 0 0) !important; }
  dialog, .modal-card, .gl-modal-card, .offer-modal-card { max-width: calc(env(viewport-segment-width 0 0) - 24px) !important; }
  /* Toasts are centred on the first screen, not on the two together (where they sat in the hinge). */
  .ui-toast-host { left: calc(env(viewport-segment-width 0 0) / 2) !important; max-width: calc(env(viewport-segment-width 0 0) - 32px) !important; }
}
/* Stacked (horizontal hinge, "laptop"): sheets, the search palette and pop-ups open on the bottom
   screen, under the hinge, where the thumb is; the page above scrolls normally. */
@media (vertical-viewport-segments: 2) {
  .ui-sheet { max-height: calc(env(viewport-segment-height 0 1) - 8px) !important; }
  .modal-overlay, .confirm-modal-overlay { top: env(viewport-segment-top 0 1) !important; }
  dialog, .modal-card, .gl-modal-card, .offer-modal-card { max-height: calc(env(viewport-segment-height 0 1) - 16px) !important; }
}

/* The iPhone / Android store apps never show what sells ProptyCenter plans (server/store-app.js). */
html[data-store-app] [data-purchase] { display: none !important; }
