/* USM_MOBILE_ADAPT_V1 — additive responsive styles. Desktop appearance is unchanged. */
@media (max-width: 780px) {
  html { -webkit-text-size-adjust: 100%; }
  .shell, .app-main, #page, .page, .card, .panel, .stack, .ac-card { min-width: 0; }
  .topbar {
    position: sticky; top: 0; z-index: 20; min-height: 60px; height: auto;
    padding: 8px max(12px, env(safe-area-inset-right)) 8px max(12px, env(safe-area-inset-left));
    gap: 8px; background: #fff;
  }
  .top-left, .top-right { min-width: 0; gap: 7px; }
  .top-left { flex: 1 1 auto; }
  .top-right { flex: 0 0 auto; }
  .crumb { min-width: 0; font-size: 11px; gap: 5px; }
  .crumb b { display: block; max-width: min(38vw, 280px); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  #openMenu, #closeMenu { min-width: 44px; min-height: 44px; font-size: 19px; }
  #logoutButton { min-height: 40px; min-width: 58px; padding: 9px 10px; }
  .account .avatar { width: 32px; height: 32px; }
  .sidebar { z-index: 60; width: min(300px, 86vw); height: 100dvh; overflow-y: auto; padding-bottom: max(20px, env(safe-area-inset-bottom)); }
  .sidebar .nav-item { min-height: 46px; }
  .backdrop.open { z-index: 59; }
  body.usm-mobile-locked { overflow: hidden; }
  .page { padding: 18px 14px max(36px, env(safe-area-inset-bottom)); }
  .page-heading { gap: 11px; margin-bottom: 16px; }
  .page-heading h1 { font-size: clamp(21px, 5.3vw, 26px); line-height: 1.2; overflow-wrap: anywhere; letter-spacing: -.5px; }
  .page-heading p { font-size: 12px; }
  .page-heading .heading-actions { display: flex; gap: 8px; }
  .page-heading .heading-actions .btn { min-width: 0; white-space: normal; }
  .panel { padding: 16px; }
  .panel-head { flex-wrap: wrap; }
  .dashboard-grid, .page-two, .user-grid, .ac-cols { grid-template-columns: minmax(0,1fr); }
  .kpis { grid-template-columns: repeat(2,minmax(0,1fr)); gap: 10px; }
  .kpi { padding: 14px; min-height: 118px; }
  .kpi-value { font-size: clamp(23px, 6vw, 30px); }
  .kpi-caption { line-height: 1.35; }
  .donut-layout { flex-wrap: wrap; justify-content: center; gap: 18px; }
  .legend { min-width: 190px; flex: 1 1 190px; }
  .manager-grid { grid-template-columns: repeat(2,minmax(0,1fr)); }
  .filters, .compact-filters { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 9px; align-items: stretch; }
  .filters .search, .compact-filters input[type="search"] { grid-column: 1 / -1; width: 100%; min-width: 0; }
  .compact-filters select, .compact-filters input, .filters .select, .filters .date, .compact-filters button {
    width: 100%; min-width: 0; max-width: none; margin: 0;
  }
  .filters .date-range { grid-column: 1 / -1; flex-basis: auto; }
  .compact-filters .btn, .filters .btn { min-height: 42px; }
  .pagination { flex-direction: column; align-items: stretch; gap: 11px; line-height: 1.5; }
  .pagination .pager { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
  .pagination .pager button { min-height: 44px; }
  .activity-item, .attention-item { min-width: 0; }
  .activity-item { flex-wrap: wrap; }
  .attention-item > div:not(.attention-icon):not(.attention-right) { min-width: 0; overflow-wrap: anywhere; }
  .attention-name, .attention-meta, .manager-name { overflow-wrap: anywhere; }
  .toast { bottom: max(12px, env(safe-area-inset-bottom)); left: 12px; right: 12px; max-width: none; }
  .drawer-backdrop.open { z-index: 79; }
  .drawer { z-index: 80; left: 0; right: 0; top: 0; bottom: 0; width: 100%; height: 100dvh; max-height: 100dvh; }
  .drawer-top { padding: max(15px, env(safe-area-inset-top)) 16px 12px; gap: 10px; flex: 0 0 auto; min-width: 0; }
  .drawer-top > div { min-width: 0; flex: 1; }
  .drawer-top h2 { font-size: 16px; line-height: 1.3; overflow-wrap: anywhere; word-break: break-word; max-height: 4.2em; overflow: auto; }
  #drawerClose { flex: 0 0 auto; min-width: 44px; min-height: 44px; font-size: 24px; }
  .drawer-body, #drawer > #drawerContent { padding: 14px 16px max(30px, env(safe-area-inset-bottom)); flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
  .drawer-metadata { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 9px; }
  .meta-field { min-width: 0; overflow-wrap: anywhere; }
  .criterion-inline { gap: 8px; align-items: flex-start; }
  .criterion-inline span { min-width: 0; }
  .criterion-inline strong { white-space: nowrap; }
  #drawer .usm-transcript-panel { padding: 12px; margin-top: 18px; }
  #drawer .usm-transcript-panel .panel-head { align-items: flex-start; }
  #drawer .usm-transcript-toggle { min-height: 42px; margin-left: 0; }
  #drawer .usm-transcript-toolbar { display: grid; grid-template-columns: minmax(0,1fr) auto; gap: 8px; }
  #drawer .usm-transcript-search { width: 100%; min-width: 0; max-width: none; grid-column: 1 / -1; }
  #drawer .usm-transcript-count { align-self: center; }
  #drawer .usm-transcript-toolbar .btn { min-height: 42px; }
  #drawer .usm-transcript-lines { max-height: min(30dvh,230px); overflow-y: auto; overscroll-behavior: contain; }
  #drawer .usm-transcript-line { max-width: 100%; overflow-wrap: anywhere; }
  .usm-cleanup-toolbar { gap: 8px; }
  .usm-cleanup-toolbar .btn { min-height: 44px; }
  .usm-cleanup-row { align-items: flex-start; }
  .usm-cleanup-row b { white-space: normal; text-align: right; }
  .ac-tabs { display: flex; flex-wrap: nowrap; gap: 8px; overflow-x: auto; overscroll-behavior-x: contain;
    scroll-snap-type: x proximity; padding: 2px 0 12px; -webkit-overflow-scrolling: touch; }
  .ac-tab { flex: 0 0 auto; min-height: 44px; padding: 10px 13px; scroll-snap-align: start; }
  .ac-content, #usmAdminCenter { min-width: 0; }
  .ac-stats { grid-template-columns: repeat(2,minmax(0,1fr)); gap: 9px; }
  .ac-stat { min-width: 0; padding: 13px; }
  .ac-stat strong { font-size: 24px; }
  .ac-info > div { flex-wrap: wrap; overflow-wrap: anywhere; }
  .ac-info strong { max-width: 100%; overflow-wrap: anywhere; }
  .ac-actions { gap: 8px; }
  .ac-actions .btn { min-height: 42px; white-space: normal; }
  .ac-formgrid { grid-template-columns: minmax(0,1fr); }
  .ac-filters { display: grid; grid-template-columns: minmax(0,1fr); gap: 10px; }
  .ac-filters label { min-width: 0; }
  .ac-filters .btn { min-height: 44px; }
  .ac-event { min-width: 0; }
  .ac-event small { overflow-wrap: anywhere; }
  .ac-modal-backdrop { z-index: 10010; padding: max(14px,env(safe-area-inset-top)) 12px max(14px,env(safe-area-inset-bottom)); align-items: flex-end; }
  .ac-modal { width: 100%; max-width: 520px; max-height: 94dvh; overflow-y: auto; border-radius: 16px; padding: 18px 16px; }
  .ac-modal .ac-actions { flex-wrap: wrap; }
  .ac-secret code { overflow-wrap: anywhere; }
  /* 16px inputs prevent Safari/iOS zoom while entering credentials. */
  .auth-card input, .ac-form input, .ac-filters input, .ac-filters select,
  .compact-filters input, .compact-filters select, .filters input, .filters select,
  .user-form input, .usm-transcript-search { font-size: 16px; }
}
@media (max-width: 640px) {
  .manager-grid { grid-template-columns: 1fr; }
  /* Tables become tappable stacked cards, preserving their original rows and click handlers. */
  #callsResults .table-wrap, .ac-tablewrap { overflow: visible; border: 0; background: transparent; }
  #callsResults table.data-table, .ac-tablewrap table.ac-table { display: block; width: 100%; min-width: 0; border: 0; }
  #callsResults table.data-table thead, .ac-tablewrap table.ac-table thead { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
  #callsResults table.data-table tbody, .ac-tablewrap table.ac-table tbody { display: grid; gap: 10px; }
  #callsResults table.data-table tbody tr, .ac-tablewrap table.ac-table tbody tr {
    display: grid; grid-template-columns: minmax(0,1fr) auto; gap: 8px 12px;
    padding: 13px; background: white; border: 1px solid #dde7f1; border-radius: 12px;
    box-shadow: 0 4px 18px rgba(24,48,79,.04); min-width: 0;
  }
  #callsResults table.data-table tbody td, .ac-tablewrap table.ac-table tbody td {
    min-width: 0; display: block; padding: 0 !important; border: 0; font-size: 12px;
    line-height: 1.45; overflow-wrap: anywhere;
  }
  #callsResults table.data-table tbody td::before, .ac-tablewrap table.ac-table tbody td::before {
    display: block; content: attr(data-mobile-label); font-size: 10px; font-weight: 650;
    line-height: 1.3; color: #778ba1; margin-bottom: 3px;
  }
  #callsResults table.data-table tbody td:not([data-mobile-label])::before,
  .ac-tablewrap table.ac-table tbody td:not([data-mobile-label])::before,
  #callsResults table.data-table tbody td[colspan]::before { content: none; }
  #callsResults table.data-table tbody td:nth-child(2) { grid-column: 1 / -1; grid-row: 1; font-weight: 700; color: #263f58; }
  #callsResults table.data-table tbody td:nth-child(1) { grid-column: 1; grid-row: 2; }
  #callsResults table.data-table tbody td:nth-child(3) { grid-column: 1; grid-row: 3; }
  #callsResults table.data-table tbody td:nth-child(4) { grid-column: 1; grid-row: 4; }
  #callsResults table.data-table tbody td:nth-child(5) { grid-column: 2; grid-row: 2; text-align: right; }
  #callsResults table.data-table tbody td:nth-child(6) { grid-column: 2; grid-row: 3; text-align: right; }
  #callsResults table.data-table tbody td:nth-child(5)::before,
  #callsResults table.data-table tbody td:nth-child(6)::before { text-align: right; }
  #callsResults table.data-table tbody td[colspan] { grid-column: 1 / -1; grid-row: auto; }
  .ac-tablewrap table.ac-table tbody tr { grid-template-columns: minmax(0,1fr); }
  .ac-tablewrap table.ac-table tbody td { grid-column: 1 !important; grid-row: auto !important; }
  .ac-tablewrap table.ac-table tbody td:first-child { font-weight: 700; font-size: 13px; color: #263f58; }
  .ac-tablewrap .ac-actions { margin: 4px 0 0; }
  .ac-tablewrap .ac-actions .btn { flex: 1 1 125px; min-height: 42px; }
  .ac-tablewrap table.ac-table tbody td .btn { min-height: 42px; }
}
@media (max-width: 440px) {
  .page { padding: 13px 10px max(30px, env(safe-area-inset-bottom)); }
  .page-heading h1 { font-size: 22px; }
  .panel { padding: 13px; }
  .kpi { padding: 12px 11px; }
  .kpi-head span { font-size: 10px; }
  .kpi-ico { width: 27px; height: 27px; }
  .kpi-value { font-size: 24px; }
  .donut-layout { flex-direction: column; }
  .legend { width: 100%; padding: 0; }
  .topbar .avatar { display: none; }
  .crumb b { max-width: 41vw; }
  #logoutButton { min-width: 55px; }
  #drawer .usm-transcript-toolbar { grid-template-columns: 1fr; }
  #drawer .usm-transcript-count { justify-self: start; }
  #drawer .usm-transcript-toolbar .btn { width: 100%; }
  .auth-screen { min-height: 100dvh; padding: max(14px,env(safe-area-inset-top)) 12px max(14px,env(safe-area-inset-bottom)); }
  .auth-card { padding: 20px; border-radius: 16px; }
  .auth-card h1 { font-size: 23px; }
  .auth-brand { margin-bottom: 16px; }
  .auth-brand strong { font-size: 19px; }
  .auth-brand img { height: 45px; width: 45px; }
  .ac-stat { padding: 11px; }
  .ac-stat strong { font-size: 22px; }
}
@media (prefers-reduced-motion: reduce) {
  .sidebar, .manager-card, .nav-item, .btn { transition: none !important; }
}
