/* ===================================================================
   vebs — phone layout (≤ 767px). Desktop is untouched: every rule here
   sits inside the media query below.
   Lists become cards: js/cv-mobile.js labels each cell with its column
   name (data-label) and tags the title, checkbox and action cells.
   =================================================================== */
@media (max-width: 767.98px) {

  /* ── Shell: nothing may push the page wider than the screen ─────────── */
  /* safety net only (the rules below keep content inside the screen). Set on <html> alone: putting
     overflow on <body> as well would make <body> the scroll container and break window scrolling. */
  html { overflow-x: hidden; }
  .cv-main, .cv-content, .cv-card, .cv-card-body { min-width: 0; max-width: 100%; }
  .cv-content { padding: .75rem .75rem 5rem; }   /* bottom room so the Jarvis button never hides the pager */
  .cv-popout-main { padding: .6rem .6rem 5rem; }
  .cv-popout-bar { flex-wrap: wrap; gap: .4rem; }
  .cv-popout-bar > * { min-width: 0; }
  .cv-jarvis { right: .75rem; bottom: .75rem; }
  .cv-jarvis-fab { width: 46px; height: 46px; }
  .cv-jarvis-panel { position: fixed; left: .5rem; right: .5rem; bottom: 4.25rem; width: auto; max-width: none; height: min(540px, calc(100dvh - 6rem)); }
  :is(.cv-content, .cv-popout-main) :is(img, video, iframe), .cv-window img { max-width: 100%; height: auto; }
  :is(.cv-content, .cv-popout-main) pre, .cv-window pre { white-space: pre-wrap; overflow-wrap: anywhere; }
  :is(.cv-content, .cv-popout-main) code { overflow-wrap: anywhere; }
  .cv-content > footer, .cv-main > footer { justify-content: center !important; text-align: center; }

  .cv-toolbar { padding: 0 .6rem; gap: .4rem; }
  .cv-toolbar > div { min-width: 0; }
  .cv-toolbar > div:last-child { gap: .2rem !important; flex-shrink: 0; }
  .cv-toolbar h1 { font-size: 1rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .cv-crumb { white-space: nowrap; overflow: hidden; }
  .cv-icon-btn { width: 36px; height: 36px; }
  .cv-client-switch { max-width: 112px; padding: .3rem .5rem; overflow: hidden; }
  .cv-client-switch > *:not(.cv-client-code):not(i) { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
  /* dropdown panels (bell, user, client switcher) open full-width under the toolbar */
  .cv-panel { position: fixed; left: .5rem; right: .5rem; top: calc(var(--cv-header-height) + .35rem); width: auto !important; max-height: calc(100dvh - var(--cv-header-height) - 1rem); overflow-y: auto; }
  .cv-sidebar { width: min(var(--cv-sidebar-width), 86vw); }
  .cv-sidebar.is-open { box-shadow: 0 0 0 100vmax rgba(15,23,42,.45); }

  /* ── Page furniture ─────────────────────────────────────────────────── */
  .cv-page-actions { gap: .6rem; align-items: stretch; }
  .cv-page-actions > * { min-width: 0; max-width: 100%; }
  .cv-page-actions > .cv-inline-actions { flex-wrap: wrap; }
  .cv-page-actions > .cv-filter-bar, .cv-page-actions > form { flex: 1 1 100% !important; }
  .cv-filter-bar { padding: .7rem .75rem !important; gap: .55rem; }
  .cv-filter-bar > * { flex: 1 1 100% !important; min-width: 0 !important; max-width: 100% !important; }
  .cv-filter-bar > button, .cv-filter-bar > .kt-btn { flex: 0 0 auto !important; }
  .cv-filter-bar input:not([type=checkbox]):not([type=radio]), .cv-filter-bar select, .cv-filter-bar .cv-dd, .cv-filter-bar .cv-ms { width: 100% !important; max-width: 100%; }
  .cv-inline-actions { flex-wrap: wrap; }
  .cv-card-header { flex-wrap: wrap; gap: .5rem; padding: .75rem .85rem; }
  .cv-card-header > * { min-width: 0; }
  .cv-card-body { padding: .85rem; }
  .cv-tabs { margin-bottom: .85rem; }
  .cv-tabs-wrap > div[style*="margin-left:auto"] { margin-left: 0 !important; flex-wrap: wrap; width: 100%; }
  .cv-stats { grid-template-columns: 1fr 1fr; gap: .6rem; }
  .cv-stat { padding: .75rem; gap: .6rem; }
  .cv-form-grid > * { min-width: 0; grid-column: auto !important; }
  .cv-form-grid { grid-template-columns: 1fr !important; }
  /* inline style grids with fixed side columns collapse to one column */
  :is(.cv-content, .cv-popout-main) [style*="grid-template-columns"] { grid-template-columns: 1fr !important; }
  :is(.cv-content, .cv-popout-main) [style*="grid-column"] { grid-column: auto !important; }
  :is(.cv-content, .cv-popout-main) [style*="min-width:2"], :is(.cv-content, .cv-popout-main) [style*="min-width: 2"], :is(.cv-content, .cv-popout-main) [style*="min-width:3"], :is(.cv-content, .cv-popout-main) [style*="min-width:1"] { min-width: 0 !important; }
  :is(.cv-content, .cv-popout-main) [style*="width:2"]:not(td):not(th):not(col), :is(.cv-content, .cv-popout-main) [style*="width:3"]:not(td):not(th):not(col) { max-width: 100%; }
  .cv-dd, .cv-ms, .cv-editor { max-width: 100%; }
  .cv-editor-body { max-height: 50vh; }

  /* three-pane screens stack */
  .cv-inbox, .cv-chat, .cv-guide, .cv-dash-grid { grid-template-columns: 1fr !important; height: auto !important; min-height: 0; }
  .cv-inbox > .cv-card, .cv-chat > .cv-card { height: auto; max-height: none; }
  .cv-inbox-list .cv-card-body { max-height: 65vh; }
  .cv-chat-list .cv-card-body { max-height: 40vh; }
  .cv-chat-main { height: 75vh !important; }
  .cv-dash-wide { grid-column: auto !important; }
  .cv-chat-msg { max-width: 88%; }
  .cv-inbox-reading, .cv-chat-main { scroll-margin-top: calc(var(--cv-header-height) + .5rem); }
  .cv-kpis { grid-template-columns: 1fr 1fr; }
  .cv-mail-order { gap: .5rem; }

  /* ── windows and dialogs (cv-ui.js): full-width sheet ──────────────── */
  .cv-window { left: 6px; right: 6px; top: 6px; transform: none; width: auto !important; min-width: 0; max-width: none; max-height: calc(100dvh - 12px); }
  .cv-window.cv-window-dialog { top: 50%; transform: translateY(-50%); }
  .cv-window-content { padding: .85rem; }
  .cv-window-titlebar { padding: .55rem .6rem .55rem .9rem; }
  .cv-popup { max-width: calc(100vw - 16px); }
  .cv-dd-list li { padding: .6rem .65rem; }   /* finger-sized list rows */
  .cv-toasts { top: auto; bottom: 4.5rem; right: 12px; left: 12px; width: auto; }

  /* ── Lists as cards (shared by grids and plain tables) ────────── */
  table.cv-cards { display: block; width: 100% !important; min-width: 0 !important; border: 0 !important; background: transparent; table-layout: auto; }
  table.cv-cards > colgroup { display: none; }
  table.cv-cards > tbody { display: block; }
  table.cv-cards > tbody > tr {
    position: relative; display: block; margin: 0 0 .6rem; padding: .55rem .8rem .5rem;
    background: #fff; border: 1px solid #e2e8f0 !important; border-radius: .75rem; box-shadow: 0 1px 2px rgba(15,23,42,.04);
  }
  table.cv-cards > tbody > tr:last-child { margin-bottom: 0; }
  /* value cell: label on the left (absolutely placed), value flows right-aligned beside it */
  table.cv-cards > tbody > tr > td {
    position: relative !important; display: block; box-sizing: border-box;
    width: auto !important; max-width: 100%; min-width: 0; height: auto !important; padding: .28rem 0 !important; margin: 0;
    border: 0 !important; background: transparent !important; text-align: left !important; overflow: visible !important;
    white-space: normal !important; text-overflow: clip !important; overflow-wrap: anywhere; font-size: .82rem; line-height: 1.4;
  }
  table.cv-cards > tbody > tr > td[data-label]:not([data-label=""]) { padding-left: calc(38% + .75rem) !important; text-align: right !important; min-height: 1.6rem; }
  table.cv-cards > tbody > tr > td * { max-width: 100%; }
  table.cv-cards > tbody > tr > td[data-label]:not([data-label=""])::before {
    content: attr(data-label); position: absolute; left: 0; top: .34rem; width: 38%; text-align: left; white-space: normal;
    font-size: .68rem; font-weight: 600; letter-spacing: .03em; text-transform: uppercase; color: var(--cv-muted); line-height: 1.3;
  }
  table.cv-cards > tbody > tr > td[data-label]:not([data-label=""]) > div[style*="display:flex"],
  table.cv-cards > tbody > tr > td[data-label]:not([data-label=""]) > div[style*="display: flex"] { justify-content: flex-end; }
  table.cv-cards > tbody > tr > td.cv-cell-title[data-label], table.cv-cards > tbody > tr > td.cv-cell-title {
    padding: .2rem 0 .45rem !important; margin-bottom: .2rem; text-align: left !important; font-size: .9rem; font-weight: 600;
    border-bottom: 1px solid #f1f5f9 !important;
  }
  table.cv-cards > tbody > tr > td.cv-cell-title::before { display: none !important; }
  table.cv-cards > tbody > tr > td.cv-cell-title > div[style*="display:flex"] { justify-content: flex-start; }
  table.cv-cards > tbody > tr > td.cv-cell-empty { display: none !important; }
  table.cv-cards > tbody > tr > td.cv-cell-actions {
    display: flex; justify-content: flex-end; flex-wrap: wrap; gap: .35rem; margin-top: .25rem; padding: .5rem 0 0 !important; border-top: 1px solid #f1f5f9 !important;
  }
  table.cv-cards > tbody > tr > td.cv-cell-actions .kt-btn { min-width: 38px; min-height: 34px; padding: .3rem .55rem !important; }
  /* selection checkbox sits top-right on the card */
  table.cv-cards > tbody > tr.cv-has-check > td.cv-cell-title[data-label] { padding-right: 2rem !important; }
  table.cv-cards > tbody > tr > td.cv-cell-check { position: absolute !important; z-index: 2; top: .5rem; right: .7rem; left: auto; padding: .2rem !important; width: auto !important; }
  table.cv-cards > tbody > tr > td.cv-cell-check input { width: 18px; height: 18px; }
  /* group headings, detail rows and "no records" span the stack */
  table.cv-cards > tbody > tr.cv-row-full { padding: .5rem .75rem; }
  table.cv-cards > tbody > tr.cv-row-full > td { display: block; text-align: left !important; padding: 0 !important; }
  table.cv-cards > tbody > tr.cv-row-full.hidden { display: none !important; }
  table.cv-cards > tbody > tr.cv-pnr-group { background: #f1f5f9; border-color: #e2e8f0; margin-top: .4rem; }
  table.cv-cards > tbody > tr.cv-pnr-detail { margin-top: -.45rem; border-top-left-radius: 0; border-top-right-radius: 0; background: #fafcff; }
  table.cv-cards > tbody > tr.cv-pnr-detail > td > div { padding-left: .25rem !important; }

  /* plain tables: no column header strip (labels are on the cards); keep a select-all box if there is one */
  table.cv-cards.cv-plain > thead { display: block; }
  table.cv-cards.cv-plain > thead > tr { display: flex; justify-content: flex-end; padding: 0 0 .4rem; }
  table.cv-cards.cv-plain > thead > tr > th { display: none; }
  table.cv-cards.cv-plain > thead > tr > th.cv-th-check { display: inline-flex; align-items: center; gap: .4rem; width: auto !important; padding: 0 .2rem !important; border: 0 !important; background: transparent !important; font-size: .75rem; }
  table.cv-cards.cv-plain > thead > tr > th.cv-th-check::after { content: 'Select all'; font-weight: 500; color: var(--cv-muted); text-transform: none; letter-spacing: 0; }
  table.cv-cards.cv-plain > thead:not(:has(.cv-th-check)) { display: none; }
  table.cv-cards.cv-nolabels > tbody > tr > td { text-align: left !important; }
  .cv-card > .cv-card-body[style*="padding:0"] > table.cv-cards,
  .cv-card-body[style*="padding:0"] table.cv-cards,
  .cv-card > table.cv-cards,
  .pt-card > table.cv-cards { padding: .6rem; }
  .cv-card:has(> table.cv-cards), .cv-card-body:has(> table.cv-cards) { background: transparent; }

  /* ── grid (cv-ui.js) → cards ────────────────────────────────────────── */
  .cv-grid { border: 0; border-radius: 0; background: transparent; overflow: visible; }
  .cv-card:has(> .cv-grid) { border: 0; background: transparent; }
  .cv-grid .cv-grid-scroll { max-height: none !important; overflow: visible; }
  .cv-grid table.cv-cards { padding: 0; min-width: 0 !important; }

  /* header row becomes a wrap of sort/filter chips */
  .cv-grid table.cv-cards > thead { display: block; }
  .cv-grid table.cv-cards > thead > tr { display: flex; flex-wrap: wrap; gap: .35rem; padding: 0 0 .65rem; background: transparent; }
  .cv-grid table.cv-cards > thead > tr::before {
    content: 'Sort / filter'; align-self: center; font-size: .68rem; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--cv-muted); margin-right: .15rem;
  }
  .cv-grid.cv-grid-nochips table.cv-cards > thead { display: none; }
  .cv-grid table.cv-cards > thead th {
    position: relative; display: inline-flex; align-items: center; width: auto !important; min-width: 0; max-width: 100%; height: auto;
    padding: .1rem .2rem .1rem .65rem !important; border: 1px solid #e2e8f0 !important; border-radius: 999px;
    background: #fff !important; font-size: .74rem; white-space: nowrap;
  }
  .cv-grid table.cv-cards > thead th .cv-th-sort { padding: .3rem .1rem; }
  .cv-grid table.cv-cards > thead th .cv-th-filter { width: 1.9rem; height: 1.9rem; }
  .cv-grid table.cv-cards > thead th.is-sorted, .cv-grid table.cv-cards > thead th.is-filtered { border-color: var(--cv-primary) !important; color: var(--cv-primary); }
  .cv-grid table.cv-cards > thead th.cv-th-hide { display: none !important; }
  .cv-grid table.cv-cards > thead th.cv-th-check { padding: .3rem .65rem !important; gap: .4rem; }
  .cv-grid table.cv-cards > thead th.cv-th-check::after { content: 'Select all'; font-weight: 500; color: var(--cv-muted); }

  /* the cards themselves */
  .cv-grid table.cv-cards > tbody > tr > td { background: transparent !important; }
  .cv-grid table.cv-cards > tbody > tr.cv-row-selected { background: color-mix(in srgb, var(--cv-primary) 7%, #fff); border-color: var(--cv-primary) !important; }
  .cv-grid table.cv-cards > tbody > tr.cv-grid-norecords { background: #fff; }

  /* pager: compact "page x / y" instead of the number strip */
  .cv-grid .cv-grid-pager { justify-content: center; gap: .4rem; margin-top: .6rem; padding: .45rem .5rem; background: #fff; border: 1px solid #e2e8f0; border-radius: .75rem; }
  .cv-grid .cv-pg-nums { display: none; }
  .cv-grid .cv-pg-compact { display: inline; }
  .cv-grid .cv-pg-btn { min-width: 2.4rem; height: 2.4rem; }
  .cv-grid .cv-pg-info { flex-basis: 100%; text-align: center; margin: 0; order: 9; }
}
