/* ============================================================================
   Breeze — 14 · ONE SHELL, EVERY SCREEN
   ----------------------------------------------------------------------------
   The desktop client is the only client now. Instead of shipping a second
   document for phones, this layer folds the same shell down to a single column:

     >= 821px   rail │ list │ chat │ drawer        (unchanged PC layout)
     <= 820px   one column, the rail becomes a dock, list and chat become
                two views of that column, the drawer is an overlay sheet

   Nothing here invents a feature — it is the same markup, the same script,
   the same handlers; only the arrangement changes. The view flip is a single
   attribute (`body[data-bz-view]`) written by responsive.js.
   ========================================================================== */

/* ---- the phone-only furniture is hidden until the breakpoint -------------- */

.bz-back-btn,
.bz-scrim {
    display: none;
}

/* ===========================================================================
   Narrow: one column + dock
   ========================================================================== */

@media (max-width: 820px) {
    :root {
        --bz-topbar-h: 54px;
        --bz-dock-h: 58px;
        --bz-space-lg: 1.125rem;
        --bz-space-md: 0.875rem;
    }

    /* -- the shell -------------------------------------------------------- */

    /* style.css sizes the shell as a floating card for a desk (min-width
       980px, rounded, shadowed). On a phone it has to be the page itself. */
    body {
        overflow: hidden;
    }

    #app-container {
        width: 100%;
        max-width: 100%;
        min-width: 0;
        height: 100vh;
        height: 100dvh;
        max-height: none;
        margin: 0;
        border-radius: 0;
        box-shadow: none;
    }

    #app-container[style*="flex"] {
        grid-template-columns: minmax(0, 1fr);
        grid-template-rows: var(--bz-topbar-h) minmax(0, 1fr) var(--bz-dock-h);
        height: 100vh;
        height: 100dvh;
    }

    /* in a thread the dock steps aside so the transcript gets the room */
    body[data-bz-view="chat"] #app-container[style*="flex"] {
        grid-template-rows: var(--bz-topbar-h) minmax(0, 1fr) 0;
    }

    /* -- slim global bar: brand on the left, the latency readout on the right
          (the rail's buttons move into the dock, so nothing is lost) -------- */

    .bz-topbar {
        gap: var(--bz-space-xs);
        padding: env(safe-area-inset-top) 12px 0 14px;
        background: rgba(252, 253, 252, 0.96);
    }

    /* theme.css pins every shell part with `#app-container > …`, so the
       placement has to be answered at the same specificity */
    #app-container > .bz-topbar { grid-area: 1 / 1 / 2 / 2; }

    .bz-brand-ver,
    .bz-topbar-sep,
    .bz-topbar-context,
    .bz-topbar-btn,
    .bz-brand-mark {
        display: none;
    }

    /* theme.css sheds the wordmark below 860px; here it is the page title */
    .bz-brand-name {
        display: inline-block;
        font-size: 17px;
    }

    /* theme.css drops the pill below 980px; on a phone it is the one reading
       worth keeping — same sentence as the desktop footbar, just tighter */
    .bz-sync-pill {
        display: inline-flex;
        margin-left: auto;
        padding: 5px 10px;
        font-size: var(--bz-text-xs);
        white-space: nowrap;
    }

    .bz-sync-label {
        display: inline;
    }

    #bz-sync-ms,
    #bz-foot-ms {
        font-variant-numeric: tabular-nums;
    }

    .bz-footbar {
        display: none;
    }

    /* -- rail → dock ------------------------------------------------------ */

    .wechat-rail {
        width: 100%;
        min-width: 0;
        height: var(--bz-dock-h);
        padding: 0 6px env(safe-area-inset-bottom);
        flex-direction: row;
        justify-content: space-between;
        align-items: center;
        gap: 2px;
        border-right: none;
        border-top: 1px solid var(--bz-hairline-soft);
        background: rgba(252, 253, 252, 0.97);
    }

    #app-container > .wechat-rail { grid-area: 3 / 1 / 4 / 2; }

    body[data-bz-view="chat"] .wechat-rail {
        display: none;
    }

    .rail-btn,
    .rail-avatar {
        flex: 1 1 0;
        width: auto;
        max-width: 62px;
        height: 46px;
        border-radius: 15px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }

    .rail-btn svg {
        width: 22px;
        height: 22px;
    }

    /* the badge anchors to its own button, not to the rail */
    .notice-btn {
        position: relative;
    }

    #notice-dot {
        top: 8px;
        right: 20px;
    }

    /* the tooltips are hover-only affordances; on a dock they only clip */
    .rail-btn::after {
        display: none;
    }

    /* order: 聊天 · 通讯录 · 通知 · 我 · 退出 */
    #tab-msg { order: 1; }
    #tab-contact { order: 2; }
    .rail-btn.notice-btn { order: 3; }
    .rail-avatar { order: 4; margin: 0; }
    .rail-btn.rail-bottom { order: 5; margin-top: 0; }

    .rail-avatar img {
        width: 30px;
        height: 30px;
        border-radius: 11px;
    }

    /* in a dock the slot *is* the avatar, so a presence badge over it just reads
       as an unread dot — drop it here */
    .rail-avatar .status-badge {
        display: none;
    }

    #notice-dot {
        top: 8px;
        right: 12px;
    }

    /* -- two views on one column ------------------------------------------ */

    #app-container > .sidebar,
    #app-container > .chat-area {
        grid-row: 2;
        grid-column: 1;
        min-width: 0;
        min-height: 0;
    }

    #app-container > .sidebar {
        display: flex;
        width: auto;
        border-right: none;
        background: transparent;
        backdrop-filter: none;
        -webkit-backdrop-filter: none;
    }

    #app-container > .chat-area {
        display: flex;
        animation: bz-view-in 220ms var(--bz-ease) both;
    }

    body[data-bz-view="list"] #app-container > .chat-area,
    body:not([data-bz-view]) #app-container > .chat-area {
        display: none;
    }

    body[data-bz-view="chat"] #app-container > .sidebar {
        display: none;
    }

    /* -- the list view ----------------------------------------------------- */

    .sidebar .list-header {
        padding: 10px 12px 6px;
        gap: 8px;
    }

    .search-wrap input {
        font-size: 16px; /* below this iOS zooms the page on focus */
        padding: 11px 14px;
    }

    .bz-search-kbd {
        display: none;
    }

    .bz-list-chips {
        padding: 2px 12px 8px;
        overflow-x: auto;
        scrollbar-width: none;
    }

    .bz-list-chips::-webkit-scrollbar {
        display: none;
    }

    .list-title {
        display: none;
    }

    #conversation-list,
    #contact-list,
    #request-panel {
        padding: 0 8px 10px;
    }

    .user-item {
        padding: 11px 10px;
        border-radius: var(--bz-r-md);
    }

    .user-item + .user-item {
        margin-top: 2px;
    }

    .user-item .avatar-box,
    .user-item .avatar-box img {
        width: 46px;
        height: 46px;
        border-radius: 15px;
    }

    .user-item h4 {
        font-size: var(--bz-text-title);
    }

    .user-item p {
        font-size: var(--bz-text-sm);
    }

    /* -- the chat view ----------------------------------------------------- */

    .chat-header {
        height: 58px;
        padding: 0 12px 0 6px;
        gap: 6px;
        background: rgba(252, 253, 252, 0.96);
    }

    body[data-bz-view="chat"] .bz-back-btn {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        width: 38px;
        height: 38px;
        flex: 0 0 auto;
        border: none;
        border-radius: 13px;
        background: transparent;
        color: var(--bz-on-surface);
        cursor: pointer;
        -webkit-tap-highlight-color: transparent;
    }

    .bz-back-btn svg {
        width: 22px;
        height: 22px;
        fill: none;
        stroke: currentColor;
        stroke-width: 2;
        stroke-linecap: round;
        stroke-linejoin: round;
    }

    .bz-back-btn:active {
        background: var(--bz-veil-sage-strong);
    }

    /* the title block is the only thing allowed to shrink; it truncates rather
       than pushing the actions off the bar */
    .chat-title-block {
        flex: 1 1 auto;
        min-width: 0;
    }

    #chat-title,
    #chat-subtitle {
        display: block;
        max-width: 100%;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    #chat-title {
        font-size: 1rem;
    }

    .chat-header-actions {
        flex: 0 0 auto;
        gap: 4px;
    }

    /* the labelled pill buttons become plain icons — the labels are the reason
       the bar used to overflow */
    .header-icon {
        width: 34px;
        min-width: 0;
        height: 34px;
        padding: 0;
        justify-content: center;
        background: transparent;
    }

    .header-icon::before {
        content: none;
    }

    .bz-header-avatar {
        display: none;
    }

    .bz-back-btn svg {
        width: 22px;
        height: 22px;
        fill: none;
        stroke: currentColor;
        stroke-width: 2;
        stroke-linecap: round;
        stroke-linejoin: round;
    }

    .chat-window {
        padding: 24px 12px 8px;
    }

    /* a phone transcript reads better without a column of avatars: the sender
       is already named on the first bubble of every run */
    .message .avatar-wrapper,
    .message .avatar-box {
        display: none;
    }

    .message {
        max-width: 88%;
        gap: 0;
    }

    .message.received {
        margin-right: 24px;
    }

    .message.sent {
        margin-left: 24px;
    }

    /* alignment already says who is who; the "我" tag is desk-only. Same
       selector as theme.css so the cascade lands on this one. */
    .message.sent .bubble-container:not(:has(.sender-name)) .bubble:not(.is-image) .msg-time::after {
        content: none;
    }

    .input-area {
        margin: 0 8px calc(8px + env(safe-area-inset-bottom));
        padding: 8px 10px 8px;
        border-radius: var(--bz-r-xl);
    }

    #msg-input {
        font-size: 16px; /* same iOS zoom guard */
        padding: 6px 2px;
    }

    /* a phone has no Enter key worth instructing about */
    .send-row {
        align-items: center;
        justify-content: flex-end;
        padding-top: 6px;
    }

    .send-row > span {
        display: none;
    }

    .send-btn {
        min-width: 76px;
        height: 40px;
        font-size: var(--bz-text-body);
    }

    .chat-toolbar {
        gap: 2px;
    }

    .tool-btn {
        width: 34px;
        height: 34px;
    }

    .chat-toolbar .bz-composer-status {
        display: none;
    }

    .emoji-picker {
        width: min(92vw, 360px);
        max-height: 44vh;
    }

    #scroll-bottom-btn {
        right: 14px;
        bottom: 108px;
    }

    /* -- drawer → overlay sheet ------------------------------------------- */

    #app-container > .detail-panel {
        position: fixed;
        top: 0;
        right: 0;
        bottom: 0;
        left: auto;
        width: min(88vw, 380px);
        max-width: none;
        padding: calc(14px + env(safe-area-inset-top)) 14px
                 calc(18px + env(safe-area-inset-bottom));
        z-index: 90;
        border-radius: var(--bz-r-xl) 0 0 var(--bz-r-xl);
        transform: translateX(101%);
        transition: transform var(--bz-dur) var(--bz-ease);
        will-change: transform;
    }

    #app-container > .detail-panel.is-open {
        width: min(88vw, 380px);
        min-width: 0;
        transform: none;
        animation: none;
    }

    .bz-scrim {
        display: block;
        position: fixed;
        inset: 0;
        z-index: 85;
        background: rgba(25, 31, 26, 0.32);
        opacity: 0;
        pointer-events: none;
        transition: opacity var(--bz-dur) var(--bz-ease);
    }

    body.bz-drawer-open .bz-scrim {
        opacity: 1;
        pointer-events: auto;
    }

    /* -- overlays that were sized for a desk ------------------------------- */

    .auth-card,
    #login-box,
    #register-box {
        width: min(92vw, 420px);
        padding: 22px 18px 20px;
    }

    .auth-card .input-group input,
    .auth-card input[type="text"],
    .auth-card input[type="password"],
    .auth-card input[type="email"] {
        font-size: 16px; /* the iOS focus-zoom guard, same as the composer */
    }

    .modal-box {
        width: min(94vw, 480px);
        max-height: 86dvh;
        overflow-y: auto;
    }

    .modal-overlay {
        padding: 12px;
    }

    .video-call-window {
        width: min(96vw, 420px);
        left: 50%;
        right: auto;
        transform: translateX(-50%);
    }

    .popover {
        width: min(92vw, 320px);
    }

    /* -- comfort on touch -------------------------------------------------- */

    .bz-chip,
    .icon-btn,
    .header-icon,
    .func-item,
    .menu-item,
    .sheet-item,
    .rail-btn,
    .rail-avatar,
    .tool-btn,
    .send-btn,
    .user-item,
    .bz-back-btn,
    .chat-header,
    .list-header {
        touch-action: manipulation;
    }

    /* keep the tapped row from flashing a grey box */
    .user-item,
    .rail-btn,
    .rail-avatar,
    .tool-btn,
    .bz-back-btn,
    .bz-chip,
    .icon-btn,
    .send-btn {
        -webkit-tap-highlight-color: transparent;
    }
}

/* the narrow shell is also the landscape phone / small tablet shape */
@media (max-width: 820px) and (max-height: 460px) {
    :root {
        --bz-topbar-h: 46px;
        --bz-dock-h: 50px;
    }

    .rail-btn,
    .rail-avatar {
        height: 40px;
    }
}

@keyframes bz-view-in {
    from {
        opacity: 0;
        transform: translateX(14px);
    }
    to {
        opacity: 1;
        transform: none;
    }
}

@media (prefers-reduced-motion: reduce) {
    #app-container > .chat-area {
        animation: none;
    }

    #app-container > .detail-panel {
        transition: none;
    }
}
