/* Vision CRM — mobile / tablet optimizations for plugin pages */

/* ── Dashboard shell (agent home, project view) ── */
@media (max-width: 991px) {
  .vcrm-broker-dash .vcrm-tabs {
    display: flex;
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    border-bottom: 1px solid var(--vcrm-border, #e2e8f0);
  }

  .vcrm-broker-dash .vcrm-tabs::-webkit-scrollbar {
    display: none;
  }

  .vcrm-broker-dash .vcrm-tabs .nav-item {
    flex: 0 0 auto;
  }

  .vcrm-broker-dash .vcrm-tabs .nav-link {
    white-space: nowrap;
    padding: 10px 12px;
    font-size: 0.75rem;
  }

  .vcrm-broker-dash .vcrm-panel-head {
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
  }

  .vcrm-broker-dash .vcrm-panel-head > div,
  .vcrm-broker-dash .vcrm-panel-head .d-flex {
    width: 100%;
    flex-wrap: wrap;
    gap: 8px;
  }

  .vcrm-broker-dash .vcrm-hero {
    padding: 18px 16px;
    margin-bottom: 16px;
  }

  .vcrm-broker-dash .vcrm-hero-title {
    font-size: 1.25rem;
    line-height: 1.25;
  }

  .vcrm-broker-dash .vcrm-action-pills .btn {
    font-size: 0.75rem;
    padding: 5px 10px;
  }

  .vcrm-broker-dash .vcrm-alert-card {
    flex-direction: column;
    align-items: flex-start;
  }

  .vcrm-broker-dash .vcrm-alert-actions {
    width: 100%;
  }

  .vcrm-broker-dash .vcrm-alert-actions .btn {
    flex: 1 1 auto;
    min-width: calc(50% - 6px);
  }
}

@media (max-width: 767px) {
  /* List pages — toolbars & filters */
  body.vision_crm-page .title-button-group {
    width: 100%;
  }

  body.vision_crm-page .custom-toolbar .filter-item-box {
    width: 100%;
    max-width: 100%;
    margin-bottom: 8px;
  }

  body.vision_crm-page .custom-toolbar .filter-item-box .select2-container,
  body.vision_crm-page .custom-toolbar .filter-item-box .form-control,
  body.vision_crm-page .custom-toolbar .filter-item-box select {
    width: 100% !important;
    max-width: 100%;
  }

  body.vision_crm-page #enterprise-filter-chips {
    display: flex;
    flex-wrap: wrap;
    width: 100%;
    gap: 6px;
  }

  body.vision_crm-page #enterprise-filter-chips .btn-filter {
    margin: 0 !important;
    flex: 1 1 auto;
    min-width: calc(50% - 6px);
    font-size: 0.75rem;
    white-space: normal;
    line-height: 1.2;
    padding: 8px 10px;
  }

  /* Project lots kanban */
  .vcrm-project-lots #kanban-smart-filter {
    flex-direction: column;
    align-items: stretch !important;
    padding: 12px !important;
  }

  .vcrm-project-lots #kanban-smart-filter .filter-item-box {
    width: 100%;
    margin-right: 0 !important;
    margin-bottom: 8px;
  }

  .vcrm-project-lots #kanban-smart-filter .filter-item-box.ml-auto {
    margin-left: 0 !important;
  }

  .vcrm-project-lots #filter-search {
    width: 100%;
    max-width: 100%;
  }

  .vcrm-project-lots #bloc-button-group,
  .vcrm-project-lots #etatedd-button-group {
    display: flex;
    flex-wrap: wrap;
    width: 100%;
    gap: 4px;
  }

  .vcrm-project-lots #etatedd-button-group .btn-filter,
  .vcrm-project-lots #bloc-button-group .btn-filter {
    flex: 1 1 auto;
    min-width: calc(50% - 4px);
    font-size: 0.75rem;
    padding: 6px 4px;
    white-space: normal;
    line-height: 1.2;
  }

  .vcrm-project-lots #kanban-wrapper {
    height: calc(100vh - 140px);
    min-height: 560px;
    touch-action: pan-x;
    -webkit-overflow-scrolling: touch;
  }

  .vcrm-project-lots .kanban-item-list {
    height: calc(100vh - 220px) !important;
    min-height: 480px !important;
    max-height: none !important;
    overflow-y: auto !important;
    touch-action: pan-y;
    -webkit-overflow-scrolling: touch;
  }

  /* Modals */
  #vcrm-prereservation-modal .modal-dialog,
  #lot-details-modal .modal-dialog {
    margin: 0.5rem auto;
    max-width: calc(100vw - 1rem);
  }

  #vcrm-prereservation-modal .modal-body .row > [class*="col-"],
  #lot-details-modal .modal-body .row > [class*="col-"] {
    margin-bottom: 8px;
  }

  .vcrm-broker-dash .table td.option,
  .vcrm-broker-dash .table th.option {
    min-width: 72px;
  }
}

@media (max-width: 575px) {
  .vcrm-broker-dash .vcrm-kpi-grid,
  .vcrm-broker-dash .vcrm-widget-kpi-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 10px;
  }

  .vcrm-broker-dash .vcrm-data-row {
    grid-template-columns: 1fr;
    gap: 8px;
    padding: 12px 16px;
  }

  .vcrm-broker-dash .vcrm-data-row .text-end,
  .vcrm-broker-dash .vcrm-data-row .text-nowrap {
    text-align: left !important;
    white-space: normal;
  }

  .vcrm-broker-dash .vcrm-data-row .btn {
    width: 100%;
  }

  .vcrm-broker-dash .vcrm-hero-meta {
    gap: 6px;
  }

  .vcrm-broker-dash .vcrm-scope-pill {
    font-size: 0.6875rem;
    padding: 3px 8px;
  }

  .vcrm-broker-dash .vcrm-action-pills .btn {
    width: 100%;
    justify-content: center;
  }

  .vcrm-broker-dash .vcrm-pipeline-row {
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
  }

  .vcrm-broker-dash .vcrm-pipeline-count {
    text-align: left;
  }

  body.vision_crm-page #enterprise-filter-chips .btn-filter {
    min-width: 100%;
  }

  body.vision_crm-page .page-title h1 {
    font-size: 1.25rem;
    line-height: 1.3;
  }
}

@media (max-width: 800px) {
  body.vision_crm-page .table-responsive:has(table.dataTable.dtr-inline) {
    overflow-x: visible;
  }

  body.vision_crm-page table.dataTable.dtr-inline.collapsed {
    width: 100% !important;
  }

  body.vision_crm-page table.dataTable.dtr-inline.collapsed tbody tr td.child ul.dtr-details {
    width: 100%;
  }

  body.vision_crm-page table.dataTable.dtr-inline.collapsed tbody tr td.child ul.dtr-details > li {
    border-bottom: 1px solid rgba(0, 0, 0, 0.06);
    padding: 6px 0;
  }

  body.vision_crm-page table.dataTable.dtr-inline.collapsed tbody tr td.dtr-control {
    min-width: 36px;
  }
}

/* Bottom nav clearance for plugin FABs / mobile menu */
@media (max-width: 767px) {
  body.vision_crm-page .scrollable-page,
  body.phonelink-page .scrollable-page,
  body.vcrm-broker-mobile-nav .scrollable-page {
    padding-bottom: calc(72px + env(safe-area-inset-bottom, 0px));
  }
}

/* Broker / direction mobile bottom bar — 4 labelled tabs + softphone button in the centre */
@media (max-width: 575px) {
  body.vcrm-broker-mobile-nav #mobile-bottom-menu .d-flex {
    justify-content: space-between !important;
    align-items: stretch;
    padding-left: 4px !important;
    padding-right: 4px !important;
  }

  body.vcrm-broker-mobile-nav #mobile-bottom-menu .menu-item {
    flex: 1 1 0;
    min-width: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    min-height: 56px;
    padding: 6px 2px calc(10px + env(safe-area-inset-bottom, 0px));
    text-align: center;
    text-decoration: none;
  }

  body.vcrm-broker-mobile-nav #mobile-bottom-menu .menu-item::after {
    content: attr(title);
    display: block;
    max-width: 100%;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    font-size: 10.5px;
    font-weight: 500;
    line-height: 1.2;
  }

  body.vcrm-broker-mobile-nav #mobile-bottom-menu .vcrm-mobile-nav-item.active,
  body.vcrm-broker-mobile-nav #mobile-bottom-menu .vcrm-mobile-nav-item.active .icon {
    color: var(--vcrm-primary, #2563eb);
  }

  body.vcrm-broker-mobile-nav #mobile-bottom-menu .vcrm-mobile-nav-item.active::after {
    font-weight: 700;
  }

  /* Free the centre slot for the softphone button (only when PhoneLink renders it) */
  body.vcrm-broker-mobile-nav:has(.phonelink-softphone-fab) #mobile-bottom-menu .d-flex > .menu-item:nth-child(3) {
    margin-left: 72px;
  }

  body.vcrm-broker-mobile-nav .phonelink-softphone-fab,
  body.vcrm-broker-mobile-nav .phonelink-softphone-fab.above-chat {
    left: 0;
    right: 0;
    width: max-content;
    margin: 0 auto;
    bottom: calc(22px + env(safe-area-inset-bottom, 0px));
  }

  body.vcrm-broker-mobile-nav .phonelink-softphone-panel {
    bottom: calc(80px + env(safe-area-inset-bottom, 0px));
  }

  /* Bar out of the way while the menu is open or the keyboard is up */
  body.vcrm-broker-mobile-nav.sidebar-toggled .phonelink-softphone-fab.state-ready,
  body.vcrm-broker-mobile-nav.sidebar-toggled .phonelink-softphone-fab.state-offline,
  body.vcrm-broker-mobile-nav.vcrm-mobile-nav-typing .phonelink-softphone-fab.state-ready,
  body.vcrm-broker-mobile-nav.vcrm-mobile-nav-typing .phonelink-softphone-fab.state-offline,
  body.vcrm-broker-mobile-nav.vcrm-mobile-nav-typing #mobile-bottom-menu {
    display: none !important;
  }
}

@media (min-width: 576px) and (max-width: 991px) {
  .vcrm-broker-dash .vcrm-widget-kpi-grid {
    grid-template-columns: repeat(2, 1fr) !important;
  }
}

/* Mobile layout (PWA): kanban swipe, bottom-sheet modals, touch targets — existing markup only */
@media (max-width: 575px) {
  /* Leads kanban: one wide column per swipe, the next one peeks */
  .leads-kanban-view #kanban-wrapper {
    scroll-snap-type: x mandatory;
    scroll-padding-left: 8px;
  }

  .leads-kanban-view #kanban-container > .kanban-col {
    width: 85vw !important;
    margin: 0 6px;
    scroll-snap-align: start;
    scroll-snap-stop: always;
  }

  /* Modals open from the bottom, like the cards view sheet (.lead-cards-sheet) */
  body.vcrm-broker-mobile-nav #ajaxModal:not(.global-search-modal) .modal-dialog {
    display: flex;
    align-items: flex-end;
    min-height: 100%;
    max-width: 100%;
    margin: 0;
  }

  body.vcrm-broker-mobile-nav #ajaxModal:not(.global-search-modal) .modal-content {
    width: 100%;
    border: 0;
    border-radius: 22px 22px 0 0;
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }
}

@media (max-width: 767px) {
  body .phonelink-quick-dial-btn {
    width: 44px;
    height: 44px;
    min-width: 44px;
    min-height: 44px;
  }
}

/* v5 phone pass — same markup, theme colours only */
@media (max-width: 767px) {
  /* Kanban cards fill their column (core sets .kanban-item to 200px under 767px) */
  .leads-kanban-view .kanban-item {
    width: 100% !important;
    margin: 0 0 8px 0 !important;
    box-sizing: border-box;
  }

  /* Cartes view (leads/mobile): full-screen #lead-cards-app has its own call button in .lead-cards-nav,
     so the idle softphone button stays off it; ringing / in-call states remain visible */
  body:has(#lead-cards-app) .phonelink-softphone-fab.state-ready,
  body:has(#lead-cards-app) .phonelink-softphone-fab.state-offline {
    display: none !important;
  }
}

@media (max-width: 575px) {
  /* Kanban: compact column head, room under the last card for the softphone button */
  .leads-kanban-view .kanban-col-title {
    padding: 8px 10px !important;
    margin-bottom: 6px !important;
  }

  .leads-kanban-view .kanban-item-list {
    padding-bottom: 12px;
    scroll-padding-bottom: 12px;
  }

  /* No snapping while a card is dragged, so the board can auto-scroll to the next column */
  .leads-kanban-view #kanban-wrapper:has(.kanban-sortable-chosen) {
    scroll-snap-type: none;
  }

  /* Kanban filters: one compact block instead of three stacked rows */
  .leads-kanban-view #kanban-filters .filter-section-container {
    padding: 4px 8px;
  }

  .leads-kanban-view #kanban-filters .filter-section-flex-row {
    display: flex !important;
    flex-wrap: wrap;
    align-items: center;
  }

  .leads-kanban-view #kanban-filters .filter-section-left {
    display: flex !important;
    flex-wrap: wrap;
    align-items: center;
  }

  .leads-kanban-view #kanban-filters .filter-item-box {
    margin: 3px;
  }

  .leads-kanban-view #kanban-filters .filter-section-left .filter-item-box.reload-button-container {
    margin-left: auto;
  }

  /* Leads list / kanban / cards: tabs + title buttons on one swipeable strip */
  #page-content > .nav-tabs.title:has(.js-leads-cookie-tab) {
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }

  #page-content > .nav-tabs.title:has(.js-leads-cookie-tab)::-webkit-scrollbar {
    display: none;
  }

  #page-content > .nav-tabs.title:has(.js-leads-cookie-tab) > li {
    flex: 0 0 auto;
  }

  #page-content > .nav-tabs.title:has(.js-leads-cookie-tab) > .title-tab {
    display: none;
  }

  #page-content > .nav-tabs.title:has(.js-leads-cookie-tab) > li > a {
    white-space: nowrap;
    padding-left: 12px;
    padding-right: 12px;
  }

  #page-content > .nav-tabs.title:has(.js-leads-cookie-tab) > .js-leads-cookie-tab[data-tab="leads_trash"] > a {
    font-size: 0;
  }

  #page-content > .nav-tabs.title:has(.js-leads-cookie-tab) > .tab-title {
    flex: 0 0 auto;
    float: none;
    width: auto;
    margin-left: auto;
    padding: 0 4px;
  }

  #page-content > .nav-tabs.title:has(.js-leads-cookie-tab) .title-button-group {
    display: flex !important;
    flex-wrap: nowrap;
    gap: 4px;
    margin: 0 !important;
    float: none !important;
  }

  #page-content > .nav-tabs.title:has(.js-leads-cookie-tab) .title-button-group .btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 44px;
    min-height: 40px;
    margin: 0 !important;
    padding: 6px 10px;
    font-size: 0;
  }

  #page-content > .nav-tabs.title:has(.js-leads-cookie-tab) .title-button-group .btn .icon,
  #page-content > .nav-tabs.title:has(.js-leads-cookie-tab) .title-button-group .btn svg {
    margin: 0;
  }

  /* Lead page: title + actions stay on top while scrolling, buttons on one row */
  .leads-details-view .leads-page-title {
    position: sticky;
    top: 0;
    z-index: 5;
    background: #fff;
    padding: 8px 0 0;
  }

  .leads-details-view .leads-page-title h1 {
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
  }

  .leads-details-view .leads-page-title .title-button-group {
    display: flex !important;
    flex-wrap: nowrap;
    gap: 8px;
    width: 100% !important;
    padding: 4px 0 8px;
    margin: 0 !important;
  }

  .leads-details-view .leads-page-title .title-button-group .btn {
    flex: 1 1 0;
    width: auto !important;
    min-width: 0;
    min-height: 44px;
    margin: 0 !important;
    float: none !important;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
  }

  /* Lead notes: long Facebook notes wrap inside the card, delete stays in its column */
  .lead-notes-container #lead-details-page-note-table {
    table-layout: fixed;
    width: 100% !important;
  }

  .lead-notes-container #lead-details-page-note-table td {
    overflow-wrap: anywhere;
    word-break: break-word;
  }

  .lead-notes-container #lead-details-page-note-table th.option,
  .lead-notes-container #lead-details-page-note-table td.option {
    width: 64px !important;
    padding-left: 4px;
    padding-right: 4px;
  }

  /* Bottom sheet: keep a strip of the page visible above the sheet */
  body.vcrm-broker-mobile-nav #ajaxModal:not(.global-search-modal) .modal-dialog {
    padding-top: 16px;
  }

  /* Radios in modal forms: radio and its label stay aligned and fit on one line */
  #ajaxModal input.form-check-input[type="radio"] {
    float: none;
    margin: 0 4px 0 0;
    vertical-align: middle;
  }

  #ajaxModal input.form-check-input[type="radio"] + label {
    display: inline-block;
    margin: 0 10px 6px 0 !important;
    vertical-align: middle;
    white-space: nowrap;
  }

  /* Extra room under the last block (dashboard KPI, lists) above the bar and the call button */
  body.vcrm-broker-mobile-nav .main-scrollable-page::after {
    content: "";
    display: block;
    height: calc(24px + env(safe-area-inset-bottom, 0px));
  }

  /* Bottom bar slides away while scrolling down a long page, back on scroll up */
  body.vcrm-broker-mobile-nav #mobile-bottom-menu {
    transition: transform 0.2s ease;
  }

  body.vcrm-broker-mobile-nav.vcrm-mobile-nav-scrolled #mobile-bottom-menu {
    transform: translateY(110%);
  }

  body.vcrm-broker-mobile-nav.vcrm-mobile-nav-scrolled .phonelink-softphone-fab.state-ready,
  body.vcrm-broker-mobile-nav.vcrm-mobile-nav-scrolled .phonelink-softphone-fab.state-offline {
    transform: translateY(calc(100% + 40px));
  }
}
