.crm-bottom-nav { display: none; }

@media (max-width: 860px) {
  /* Reserve the navigation row before the signed-in workspace first paints. */
  #app:not([hidden]) {
    grid-template-rows: minmax(0, 1fr);
    height: calc(100dvh - 60px - env(safe-area-inset-bottom, 0px));
  }
  #main { grid-area: 1/1; height: 100%; min-height: 0; }
  #app, #main, .chat-head, .composer-dock, .composer, .input-row, #composer-input,
  .input-row .send-btn, .crm-file-tools label { transition: none !important; }
  .crm-compact {
    --crm-nav-space: calc(60px + env(safe-area-inset-bottom, 0px));
    --crm-height: var(--crm-visible-height, 100dvh);
    --crm-top: var(--crm-visible-top, 0px);
  }
  .crm-keyboard { --crm-nav-space: 0px; }
  .crm-compact #app[hidden], .crm-bottom-nav[hidden], body:has(#app[hidden]) .crm-bottom-nav { display: none !important; }
  .crm-compact #app {
    position: fixed;
    inset: var(--crm-top) 0 auto;
    height: calc(var(--crm-height) - var(--crm-nav-space));
    grid-template-rows: minmax(0, 1fr);
  }
  .crm-compact #main { grid-area: 1/1; height: 100%; min-height: 0; }
  .crm-bottom-nav {
    position: fixed;
    inset: auto 0 0;
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: minmax(0, 1fr);
    height: var(--crm-nav-space);
    padding: 2px max(4px, env(safe-area-inset-right)) env(safe-area-inset-bottom) max(4px, env(safe-area-inset-left));
    background: #fff;
    border-top: 1px solid var(--line);
    z-index: 64;
  }
  .crm-keyboard .crm-bottom-nav { display: none; }
  .crm-bottom-nav button {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1px;
    min-height: 44px;
    color: var(--muted);
    font-size: 12px;
    line-height: 16px;
    font-weight: 570;
    touch-action: manipulation;
  }
  .crm-bottom-nav button > span {
    display: grid; place-items: center; width: 46px; height: 25px; border-radius: 9px;
  }
  .crm-bottom-nav .ic { width: 20px; height: 20px; }
  .crm-bottom-nav button[hidden] { display: none; }
  .crm-bottom-nav .is-current { color: var(--blue-ink); font-weight: 750; }
  .crm-bottom-nav .is-current > span { background: var(--blue-soft); }
  .crm-compact :focus-visible { outline: 2px solid var(--blue-ink); outline-offset: -2px; }

  /* Keyboard, panels and sheets share the usable space above the navigation bar. */
  .crm-compact #drawer-root, .crm-compact #scrim, .crm-compact #panel {
    top: var(--crm-top);
    bottom: auto;
    height: calc(var(--crm-height) - var(--crm-nav-space));
  }
  .crm-compact #drawer-root:not(.open) .drawer,
  .crm-compact #drawer-root:not(.open) .drawer-scrim { pointer-events: none; }
  .crm-compact #drawer-root .drawer { transition-duration: .18s; }
  .crm-compact #panel { background: #fff; }
  .crm-compact #sidebar {
    top: auto;
    right: 0;
    bottom: var(--crm-nav-space);
    width: min(100%, 560px);
    height: min(80dvh, 680px, calc(var(--crm-height) - var(--crm-nav-space) - 12px));
    margin-inline: auto;
    padding: 16px max(16px, env(safe-area-inset-right)) 12px max(16px, env(safe-area-inset-left));
    border: 1px solid var(--line);
    border-bottom: 0;
    border-radius: 22px 22px 0 0;
    background: #fff;
    backdrop-filter: none;
    transform: translateY(calc(100% + var(--crm-nav-space) + 12px));
    visibility: hidden;
    transition: transform .18s ease-out, visibility 0s linear .18s;
    gap: 10px;
    overflow-y: auto;
    overscroll-behavior: contain;
    scroll-padding-block: 12px;
  }
  .crm-compact #app.drawer-open #sidebar {
    transform: none; visibility: visible; transition-delay: 0s;
  }
  .crm-keyboard #sidebar {
    top: calc(var(--crm-top) + 4px); bottom: auto; height: calc(var(--crm-height) - 4px);
  }
  .crm-compact #sidebar > * { flex: none; }
  .crm-compact #sidebar .hist-scroll { overflow: visible; padding-bottom: 0; }
  .crm-compact #sidebar .nav-tiles { grid-template-columns: 1fr; }
  .crm-compact #sidebar .nav-tile { flex-direction: row; justify-content: center; min-height: 44px; gap: 8px; }
  .crm-compact #sidebar .nav-tile:is([data-view="chat"],[data-view="dash"],[data-view="clients"],[data-view="kb"],[data-view="experts"]) { display: none; }
  .crm-compact .crm-close-menu { margin-left: auto; }
  .crm-compact .hist-item { padding-block: 0; }
  .crm-compact .hist-more { width: 44px; height: 44px; opacity: 1; color: var(--muted); }
  .crm-compact .new-conv kbd { display: none; }
  .crm-compact .hist-rename { max-width: 65%; }
  .crm-compact .side-foot { margin-top: 2px; }
  .crm-compact #scrim { backdrop-filter: none; }
  .crm-compact .drawer-head, .crm-compact .chat-head { padding-top: max(8px, env(safe-area-inset-top)); }
  .crm-compact .drawer-body { overscroll-behavior: contain; }
  .crm-compact .drawer-foot { padding: 8px 12px; }
  .crm-compact .drawer-foot .btn { padding-inline: 6px; min-width: 44px; }
  .crm-compact #main .ka-menu, .crm-compact .chat-head .scope-badge, .crm-compact .composer .scope-row { display: none; }
  .crm-compact .chat-head .menu-btn, .crm-compact .head-btn:is(.crm-close-menu, .crm-heading-back) {
    display: inline-flex; align-items: center; justify-content: center; gap: 4px;
    width: auto; min-width: 44px; min-height: 44px; padding: 0 5px;
    color: var(--blue-ink); font-size: 12px; font-weight: 650; white-space: nowrap;
  }
  .crm-compact .chat-head .menu-btn::after { content: "会话记录"; }
  .crm-compact .head-btn:is(.crm-close-menu, .crm-heading-back) .ic { transform: rotate(180deg); width: 16px; }
  .crm-compact .drawer-head:has(.crm-heading-back) > [data-action="drawer-close"]:not(.crm-heading-back) { display: none; }
  .crm-compact .chat-head .head-actions { gap: 2px; }
  .crm-compact .msg-tools { opacity: 1; }
  .crm-compact .composer-dock { padding: 4px 8px 6px; }
  .crm-compact .composer { background: #fff; backdrop-filter: none; border-radius: 16px; }
  .crm-compact .composer-hint { display: none; }
  .crm-compact .scope-row { padding: 4px 6px 0; }
  .crm-compact .scope-seg { display: grid; grid-template-columns: repeat(4,minmax(0,1fr)); width: 100%; padding: 2px; }
  .crm-compact .scope-opt { min-height: 44px; justify-content: center; padding: 0 3px; gap: 3px; }
  .crm-compact .input-row { padding: 5px 6px; gap: 5px; align-items: center; flex-wrap: nowrap; }
  .crm-compact #composer-input { flex: 1 1 0; min-width: 0; font-size: 16px; min-height: 44px; line-height: 24px; padding-block: 10px; }
  .crm-compact .view { overscroll-behavior: contain; padding-bottom: 20px; }
  .crm-compact .view-inner { gap: 14px; }
  .crm-compact .view-head { gap: 8px; }
  .crm-compact .view-head-main { min-width: min(100%, 240px); }

  .crm-compact :is(.head-btn, .attach-btn, .send-btn, .side-user-cog, .msg-tool) { width: 44px; height: 44px; }
  .crm-compact :is(.new-conv, .hist-item, .side-link, .pop-item, .role-opt, .panel-tab,
    .p-mini, .p-art-back, .btn, .mini-btn, .expert-mount, .fchip, .sort-sel, .kb-domain,
    .rel-expand, .cap-sample, .fu-chip, .alert-row) { min-height: 44px; }
  .crm-compact .toggle::before { content: ""; position: absolute; inset: -10px 0; }
  .crm-compact :is(.att-x, .match-lock, .exp-chip button) { position: relative; }
  .crm-compact :is(.att-x, .match-lock, .exp-chip button)::after {
    content: ""; position: absolute; min-width: 44px; min-height: 44px;
    left: 50%; top: 50%; transform: translate(-50%, -50%);
  }
  .crm-compact :is(.side-search, .search-box, .form-field) :is(input,select) { min-height: 44px; font-size: 16px; }
  .crm-compact .toolbar:has(#client-q) {
    display: grid;
    grid-template-columns: minmax(0,1fr) auto;
    grid-template-areas: "search sort" "filters filters";
    gap: 8px;
  }
  .crm-compact .toolbar:has(#client-q) .search-box { grid-area: search; min-width: 0; max-width: none; }
  .crm-compact #client-sort { grid-area: sort; max-width: 110px; padding-inline: 6px; }
  .crm-compact .toolbar:has(#client-q) .filter-chips {
    grid-area: filters; flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; gap: 5px;
  }
  .crm-compact .toolbar:has(#client-q) .fchip { flex: 1 0 auto; padding-inline: 10px; }

  /* Card layout uses precisely the original role-filtered cells and row actions. */
  #clients-table { background: transparent; border: 0; box-shadow: none; border-radius: 0; }
  #clients-table .tbl-wrap { overflow: visible; }
  #clients-table table.tbl { display: block; width: 100%; min-width: 0; }
  #clients-table thead {
    position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap;
  }
  #clients-table tbody { display: grid; gap: 9px; }
  #clients-table tr[data-action] {
    position: relative; display: grid; grid-template-columns: minmax(0, 1fr) minmax(84px, auto);
    align-items: center; gap: 4px 8px; padding: 12px 13px 7px;
    border: 1px solid var(--line); border-radius: 14px; background: #fff;
  }
  #clients-table .tbl td { display: block; min-width: 0; padding: 0; border: 0; white-space: normal; line-height: 1.5; font-size: 12px; }
  #clients-table td:first-child { grid-column: 1; grid-row: 1; padding-bottom: 5px; }
  #clients-table .co-cell { gap: 8px; }
  #clients-table .co-cell > :last-child { min-width: 0; }
  #clients-table .co-cell b { font-size: 14px; white-space: normal; overflow-wrap: anywhere; }
  #clients-table .co-cell small { color: var(--muted); font-size: 11px; }
  #clients-table td:nth-child(4) { grid-area: 1/2; align-self: start; justify-self: end; }
  #clients-table td:nth-child(2) { grid-row: 2; grid-column: 1; }
  #clients-table td:nth-child(5) { grid-row: 2; grid-column: 2; }
  #clients-table td:nth-child(6):not(:last-child) { grid-column: 1; grid-row: 3; }
  #clients-table td:nth-child(7):not(:last-child) { grid-column: 2; grid-row: 3; }
  #clients-table td:nth-child(3) { grid-column: 1/-1; grid-row: 4; padding-right: 62px; overflow-wrap: anywhere; }
  #clients-table td:last-child { grid-column: 2; grid-row: 4; justify-self: end; }
  #clients-table td:last-child .mini-btn { display: flex; align-items: center; min-width: 48px; justify-content: center; }
  #clients-table td:nth-child(2)::before { content: "服务"; }
  #clients-table td:nth-child(3)::before { content: "服务期"; }
  #clients-table td:nth-child(5)::before { content: "经办"; }
  #clients-table td:nth-child(6):not(:last-child)::before { content: "年费"; }
  #clients-table td:nth-child(7):not(:last-child)::before { content: "待收"; }
  #clients-table .tbl td::before { color: var(--muted); font: 500 11px/1.5 var(--font); margin-right: 5px; }
  #clients-table .empty-state { background: #fff; border: 1px solid var(--line); border-radius: 14px; }

  /* The conversation and its context panel share the same embedded customer summary. */
  .crm-compact .card .tbl:has(td.co) { display: block; min-width: 0; width: 100%; }
  .crm-compact .card .tbl:has(td.co) thead {
    position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap;
  }
  .crm-compact .card .tbl:has(td.co) tbody { display: block; }
  .crm-compact .card .tbl tr[data-action="client-row"] {
    display: grid; grid-template-columns: minmax(0,1fr) auto; align-items: center;
    gap: 3px 6px; padding: 10px 12px; border-top: 1px solid var(--line);
  }
  .crm-compact .card .tbl tr[data-action="client-row"] td { border: 0; padding: 0; white-space: normal; font-size: 12px; }
  .crm-compact .card .tbl td.co { grid-area: 1/1; overflow-wrap: anywhere; font-weight: 700; }
  .crm-compact .card .tbl td:nth-child(4) { grid-area: 1/2; justify-self: end; }
  .crm-compact .card .tbl td:nth-child(2) { grid-area: 2/1; }
  .crm-compact .card .tbl td:nth-child(3) { grid-area: 2/2; text-align: right; }
  .crm-compact .card .tbl td:nth-child(5) { grid-area: 3/1; }
  .crm-compact .card .tbl td:nth-child(6) { grid-area: 3/2; text-align: right; }
  .crm-compact .card .tbl tr[data-action="client-row"] td::before { font: 500 11px/1.4 var(--font); color: var(--muted); }
  .crm-compact .card .tbl td:nth-child(3)::before { content: "到期 "; }
  .crm-compact .card .tbl td:nth-child(5)::before { content: "经办 "; }
  .crm-compact .card .tbl td.money::before { content: "待收 "; }
}

.crm-file-tools { display: none; }
@media (max-width: 860px) {
  .input-row > [data-action="attach"] { display: none; }
  .input-row .crm-file-tools { display: flex; flex: 0 0 44px; }
  .crm-file-tools label {
    display: grid; place-items: center;
    position: relative; width: 44px; height: 44px; overflow: hidden;
    color: var(--ink, #243348); border-radius: 9px; font-size: 11px;
    line-height: 13px; font-weight: 600; cursor: pointer;
  }
  .crm-file-tools label:focus-within { outline: 2px solid var(--blue, #087bea); outline-offset: -2px; }
  .crm-file-tools .ic { width: 18px; height: 18px; }
  .crm-file-tools input {
    position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0;
    cursor: pointer; touch-action: manipulation;
  }
  .crm-compact .att-strip { max-height: min(23dvh, 124px); overflow: auto; overscroll-behavior: contain; }
  .crm-compact #toast-root {
    top: calc(env(safe-area-inset-top, 0px) + 8px); bottom: auto;
    width: calc(100% - 24px); max-width: 450px;
  }
  .crm-compact .toast { max-width: 100%; pointer-events: none; }
  .crm-compact .toast-act { pointer-events: auto; }
  .crm-compact .toast:not(:has(.toast-act)):has(~ .toast:not(:has(.toast-act))) { display: none; }
}
