/* TenPlus CRM, phone layout. Loaded after theme-v2.css.
   Active only on screens up to 820px wide and while the new look (html.ui2) is on, so the desktop CRM is not touched.
   mobile-v3.js adds the "More" sheet to the bottom bar and the labels that turn tables into cards. */

.m-sheet,
.m-sheet-scrim {
  display: none;
}

@media (max-width: 820px) {
  html.ui2 {
    --m-nav: 62px;
    --m-bot: env(safe-area-inset-bottom, 0px);
    --m-top: env(safe-area-inset-top, 0px);
    -webkit-tap-highlight-color: transparent !important;
    -webkit-text-size-adjust: 100% !important;
    scroll-padding-bottom: calc(var(--m-nav) + var(--m-bot) + 16px) !important;
  }
  html.ui2 .app-shell,
  html.ui2 .workspace {
    display: block !important;
    height: auto !important;
    min-height: 100vh !important;
    min-height: 100dvh !important;
    overflow: visible !important;
  }

  /* ---- menu becomes a bottom bar ---- */
  html.ui2 .sidebar {
    position: fixed !important;
    top: auto !important;
    right: 0 !important;
    bottom: 0 !important;
    left: 0 !important;
    z-index: 1002 !important;
    width: auto !important;
    height: auto !important;
    max-height: none !important;
    display: block !important;
    padding: 6px 8px calc(6px + var(--m-bot)) !important;
    border: 0 !important;
    border-top: 1px solid rgba(255, 255, 255, 0.1) !important;
    border-radius: 0 !important;
    background: #0a1d1a !important;
    box-shadow: 0 -8px 24px -12px rgba(0, 0, 0, 0.35) !important;
    overflow: visible !important;
  }
  html.ui2 .sidebar .side-top,
  html.ui2 .sidebar .side-footer {
    display: none !important;
  }
  html.ui2 .sidebar .nav-list {
    display: flex !important;
    gap: 2px !important;
    margin: 0 !important;
    padding: 0 !important;
    overflow: visible !important;
  }
  html.ui2 .sidebar .nav-button {
    position: relative !important;
    flex: 1 1 0 !important;
    min-width: 0 !important;
    height: 50px !important;
    margin: 0 !important;
    padding: 4px 2px !important;
    display: flex !important;
    flex-direction: column !important;
    align-items: center !important;
    justify-content: center !important;
    gap: 3px !important;
    border: 0 !important;
    border-radius: 12px !important;
    background: transparent !important;
    color: rgba(255, 255, 255, 0.62) !important;
    font-size: 11px !important;
    font-weight: 600 !important;
    letter-spacing: 0 !important;
    text-decoration: none !important;
  }
  html.ui2 .sidebar .nav-button > span:not(.nav-badge) {
    display: block !important;
    max-width: 100% !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
    white-space: nowrap !important;
    line-height: 1.1 !important;
  }
  html.ui2 .sidebar .nav-button svg {
    width: 22px !important;
    height: 22px !important;
    flex: none !important;
  }
  html.ui2 .sidebar .nav-button.active {
    background: rgba(15, 157, 122, 0.3) !important;
    color: #fff !important;
  }
  html.ui2 .sidebar .nav-button .nav-badge {
    position: absolute !important;
    top: 2px !important;
    right: 14px !important;
    margin: 0 !important;
  }
  html.ui2 .sidebar .nav-button.m-hide {
    display: none !important;
  }
  html.ui2 .sidebar .m-more-btn.m-has-badge::after {
    content: "" !important;
    position: absolute !important;
    top: 6px !important;
    right: 18px !important;
    width: 9px !important;
    height: 9px !important;
    border-radius: 50% !important;
    background: #ef4444 !important;
    border: 2px solid #0a1d1a !important;
  }

  /* ---- "More" sheet ---- */
  html.ui2 .m-sheet-scrim {
    display: block !important;
    position: fixed !important;
    inset: 0 !important;
    z-index: 1000 !important;
    background: rgba(8, 20, 18, 0.5) !important;
    opacity: 0 !important;
    pointer-events: none !important;
    transition: opacity 0.18s ease !important;
  }
  html.ui2 .m-sheet {
    display: block !important;
    position: fixed !important;
    right: 0 !important;
    bottom: 0 !important;
    left: 0 !important;
    z-index: 1001 !important;
    max-height: 82vh !important;
    max-height: 82dvh !important;
    overflow-y: auto !important;
    padding: 10px 12px calc(var(--m-nav) + var(--m-bot) + 14px) !important;
    border-radius: 22px 22px 0 0 !important;
    background: #fff !important;
    box-shadow: 0 -20px 50px -16px rgba(15, 27, 45, 0.35) !important;
    transform: translateY(105%) !important;
    transition: transform 0.22s ease !important;
    visibility: hidden !important;
  }
  html.m-more-open.ui2 .m-sheet-scrim {
    opacity: 1 !important;
    pointer-events: auto !important;
  }
  html.m-more-open.ui2 .m-sheet {
    transform: none !important;
    visibility: visible !important;
  }
  html.ui2 .m-grab {
    width: 40px !important;
    height: 4px !important;
    margin: 2px auto 10px !important;
    border-radius: 4px !important;
    background: var(--v2-line-strong) !important;
  }
  html.ui2 .m-row {
    display: flex !important;
    align-items: center !important;
    gap: 14px !important;
    width: 100% !important;
    min-height: 54px !important;
    padding: 0 14px !important;
    border: 0 !important;
    border-radius: 14px !important;
    background: transparent !important;
    color: var(--v2-ink) !important;
    font: inherit !important;
    font-size: 16px !important;
    font-weight: 600 !important;
    text-align: left !important;
  }
  html.ui2 .m-row:active {
    background: var(--v2-accent-soft) !important;
  }
  html.ui2 .m-row svg {
    width: 22px !important;
    height: 22px !important;
    flex: none !important;
    color: var(--v2-accent-dark) !important;
  }
  html.ui2 .m-row.m-danger,
  html.ui2 .m-row.m-danger svg {
    color: #b42318 !important;
  }
  html.ui2 .m-sep {
    height: 1px !important;
    margin: 6px 4px !important;
    background: var(--v2-line) !important;
  }

  /* ---- top bar ---- */
  html.ui2 .content {
    min-width: 0 !important;
    height: auto !important;
    max-height: none !important;
    padding: 0 12px calc(var(--m-nav) + var(--m-bot) + 24px) !important;
    overflow: visible !important;
  }
  html.ui2 .topbar {
    position: sticky !important;
    top: 0 !important;
    z-index: 50 !important;
    display: flex !important;
    flex-direction: row !important;
    align-items: center !important;
    gap: 10px !important;
    margin: 0 -12px 12px !important;
    padding: calc(10px + var(--m-top)) 14px 10px !important;
    border: 0 !important;
    border-bottom: 1px solid var(--v2-line) !important;
    border-radius: 0 !important;
    background: #fff !important;
    box-shadow: none !important;
  }
  html.ui2 .topbar > div:first-child {
    flex: 1 1 auto !important;
    min-width: 0 !important;
  }
  html.ui2 .topbar h1 {
    margin: 0 !important;
    overflow: hidden !important;
    font-size: 20px !important;
    line-height: 1.25 !important;
    text-overflow: ellipsis !important;
    white-space: nowrap !important;
  }
  html.ui2 .topbar p {
    display: none !important;
  }
  html.ui2 .topbar .button-row {
    width: auto !important;
    flex: 0 0 auto !important;
    flex-wrap: nowrap !important;
    gap: 8px !important;
    margin: 0 !important;
  }
  html.ui2 .topbar .compact-select,
  html.ui2 .topbar .payment-chip {
    width: auto !important;
    min-height: 40px !important;
    height: 40px !important;
    padding: 0 8px !important;
    font-size: 14px !important;
  }
  html.ui2 .topbar .btn-primary {
    justify-content: center !important;
    flex: 0 0 44px !important;
    width: 44px !important;
    min-width: 44px !important;
    height: 44px !important;
    min-height: 44px !important;
    padding: 0 !important;
    border-radius: 14px !important;
    font-size: 0 !important;
  }
  html.ui2 .topbar .btn-primary svg {
    width: 22px !important;
    height: 22px !important;
    margin: 0 !important;
  }

  /* ---- cards, panels, grids ---- */
  html.ui2 .panel {
    border-radius: 16px !important;
  }
  html.ui2 .panel-header {
    flex-wrap: wrap !important;
    gap: 8px !important;
    padding: 14px !important;
  }
  html.ui2 .panel-body {
    padding: 12px 14px !important;
  }
  html.ui2 .dashboard-grid {
    grid-template-columns: 1fr !important;
    gap: 12px !important;
  }
  html.ui2 .form-grid,
  html.ui2 .form-grid.two {
    grid-template-columns: 1fr !important;
  }
  html.ui2 .toolbar {
    flex-wrap: wrap !important;
    gap: 8px !important;
  }
  html.ui2 .toolbar > * {
    flex: 1 1 140px !important;
  }
  html.ui2 .button-row {
    flex-wrap: wrap !important;
  }
  html.ui2 .row-actions {
    display: flex !important;
    flex-wrap: wrap !important;
    gap: 8px !important;
  }

  /* ---- finger-sized controls (16px text stops the phone zooming into fields) ---- */
  html.ui2 .btn {
    min-height: 46px !important;
    padding-right: 16px !important;
    padding-left: 16px !important;
    border-radius: 12px !important;
    font-size: 15px !important;
  }
  html.ui2 .btn-small {
    min-height: 40px !important;
    padding-right: 12px !important;
    padding-left: 12px !important;
    font-size: 14px !important;
  }
  html.ui2 .btn-icon {
    min-width: 44px !important;
    min-height: 44px !important;
  }
  html.ui2 input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="file"]),
  html.ui2 select,
  html.ui2 textarea,
  html.ui2 .search-input {
    min-height: 46px !important;
    padding-right: 12px !important;
    padding-left: 12px !important;
    border-radius: 12px !important;
    font-size: 16px !important;
  }
  html.ui2 textarea {
    min-height: 96px !important;
  }
  html.ui2 input[type="checkbox"],
  html.ui2 input[type="radio"] {
    width: 22px !important;
    height: 22px !important;
  }
  html.ui2 .check-row {
    display: flex !important;
    align-items: center !important;
    gap: 10px !important;
    min-height: 44px !important;
  }

  /* ---- tables become cards (labels are added by mobile-v3.js) ---- */
  html.ui2 .content table.m-cards,
  html.ui2 .content table.m-cards tbody {
    display: block !important;
    width: 100% !important;
    min-width: 0 !important;
    max-width: 100% !important;
    border: 0 !important;
    background: transparent !important;
  }
  html.ui2 .content table.m-cards thead {
    display: none !important;
  }
  html.ui2 .content table.m-cards tr {
    display: grid !important;
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    box-sizing: border-box !important;
    width: 100% !important;
    max-width: 100% !important;
    gap: 8px 12px !important;
    margin: 0 0 10px !important;
    padding: 12px 14px !important;
    border: 1px solid var(--v2-line) !important;
    border-radius: 14px !important;
    background: #fff !important;
    content-visibility: auto !important;
    contain-intrinsic-size: auto 170px !important;
  }
  html.ui2 .content table.m-cards td {
    display: block !important;
    min-width: 0 !important;
    padding: 0 !important;
    border: 0 !important;
    font-size: 14px !important;
    overflow-wrap: anywhere !important;
  }
  html.ui2 .content table.m-cards td::before {
    display: block !important;
    margin-bottom: 2px !important;
    color: var(--v2-muted) !important;
    font-size: 11px !important;
    font-weight: 600 !important;
    letter-spacing: 0.05em !important;
    text-transform: uppercase !important;
  }
  html.ui2 .content table.m-cards td:first-child,
  html.ui2 .content table.m-cards td:last-child,
  html.ui2 .content table.m-cards td[colspan] {
    grid-column: 1 / -1 !important;
  }
  html.ui2 .content table.m-cards td:first-child {
    font-size: 16px !important;
    font-weight: 600 !important;
  }

  /* ---- pop-ups become bottom sheets ---- */
  html.ui2 .modal-backdrop {
    z-index: 1200 !important;
    align-items: flex-end !important;
    padding: 0 !important;
  }
  html.ui2 .modal-panel {
    overflow: hidden !important;
    display: flex !important;
    flex-direction: column !important;
    width: 100% !important;
    max-width: none !important;
    max-height: calc(100vh - 20px - var(--m-top)) !important;
    max-height: calc(100dvh - 20px - var(--m-top)) !important;
    margin: 0 !important;
    border-radius: 20px 20px 0 0 !important;
  }
  html.ui2 .modal-header {
    padding: 14px 16px !important;
  }
  html.ui2 .modal-body {
    min-height: 0 !important;
    max-height: none !important;
    flex: 1 1 auto !important;
    padding: 14px 16px !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch !important;
  }
  html.ui2 .modal-footer {
    display: flex !important;
    gap: 10px !important;
    padding: 12px 16px calc(12px + var(--m-bot)) !important;
    border-top: 1px solid var(--v2-line) !important;
    background: #fff !important;
  }
  html.ui2 .modal-footer .btn {
    flex: 1 1 0 !important;
  }

  /* ---- messages sit above the bottom bar ---- */
  html.ui2 .crm-toast-stack {
    z-index: 1300 !important;
    top: auto !important;
    right: 12px !important;
    bottom: calc(var(--m-nav) + var(--m-bot) + 12px) !important;
    left: 12px !important;
  }
}
