/* Touch mode: the bottom sheet and every rule that applies only under html[data-input="touch"].
   A desktop with a mouse never matches these selectors. */

.msheet-layer {
    position: fixed;
    inset: 0;
    z-index: 9200;
    -webkit-app-region: no-drag;
}

.msheet-scrim {
    position: absolute;
    inset: 0;
    background: var(--c-scrim);
    opacity: 0;
    transition: opacity var(--dur-fast) var(--ease-std);
}

.msheet {
    position: absolute;
    left: 0;
    right: 0;
    bottom: var(--msheet-kb, 0px);
    max-height: calc(var(--msheet-vh, 100dvh) - var(--space-6));
    overflow-y: auto;
    overscroll-behavior: contain;
    box-sizing: border-box;
    margin: 0 auto;
    max-width: 560px;
    padding: 0 var(--space-2) calc(var(--space-2) + env(safe-area-inset-bottom, 0px));
    border: 1px solid var(--c-border-float);
    border-bottom: 0;
    border-radius: var(--r-xl) var(--r-xl) 0 0;
    background: var(--c-bg-float-strong);
    -webkit-backdrop-filter: var(--backdrop-float);
    backdrop-filter: var(--backdrop-float);
    box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.22);
    color: var(--c-text-popup);
    font-family: var(--font-sans);
    transform: translateY(100%);
    transition: transform var(--dur-base) var(--ease-std);
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
}

.msheet:focus { outline: none; }

.msheet-layer.is-open .msheet-scrim { opacity: 1; }
.msheet-layer.is-open .msheet { transform: none; }

@media (prefers-reduced-motion: reduce) {
    .msheet, .msheet-scrim { transition: none; }
}

.msheet-grip {
    touch-action: none;
    padding-top: var(--space-2);
}

.msheet-handle {
    display: block;
    width: 36px;
    height: 4px;
    margin: 0 auto 6px;
    border-radius: 2px;
    background: var(--c-border);
}

.msheet-title {
    margin: 2px 14px var(--space-2);
    font-size: 17px;
    font-weight: 650;
    color: var(--c-text-popup);
}

.msheet-header {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-1) 14px var(--space-3);
    margin-bottom: var(--space-1);
    border-bottom: 1px solid var(--c-border-float);
}

.msheet-header-avatar {
    width: 40px;
    height: 40px;
    border-radius: var(--r-full);
    overflow: hidden;
    flex-shrink: 0;
}

.msheet-header-name {
    min-width: 0;
    font-size: 16px;
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.msheet-list {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.msheet-row {
    display: flex;
    align-items: center;
    gap: 14px;
    width: 100%;
    min-height: 52px;
    padding: 0 14px;
    border: 0;
    border-radius: 10px;
    background: transparent;
    color: var(--c-text-popup);
    font: inherit;
    font-size: 16px;
    text-align: left;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.msheet-row:active:not([disabled]),
.msheet-row:focus-visible { background: var(--c-accent-soft); }
.msheet-row:focus-visible { outline: 2px solid var(--c-accent); outline-offset: -2px; }
.msheet-row[disabled] { opacity: 0.45; cursor: default; }
.msheet-row.is-selected { font-weight: 600; background: var(--c-accent-light); }
.msheet-row.is-danger,
.msheet-row.is-danger .msheet-icon { color: var(--c-status-error-solid); }

.msheet-icon {
    display: inline-flex;
    justify-content: center;
    width: 22px;
    flex-shrink: 0;
    font-size: 18px;
    color: var(--c-text-secondary);
}

.msheet-label {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.msheet-check { flex-shrink: 0; color: var(--c-accent); }

.msheet-divider {
    height: 1px;
    margin: var(--space-1) 14px;
    background: var(--c-border-float);
}

.msheet-gap {
    height: var(--space-2);
    margin: 6px calc(-1 * var(--space-2));
    background: var(--c-border-float);
    opacity: 0.5;
}

.msheet-cancel {
    display: block;
    width: 100%;
    min-height: 52px;
    border: 0;
    border-radius: 10px;
    background: transparent;
    color: var(--c-text-popup);
    font: inherit;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.msheet-cancel:active,
.msheet-cancel:focus-visible { background: var(--c-accent-soft); }
.msheet-cancel:focus-visible { outline: 2px solid var(--c-accent); outline-offset: -2px; }

html[data-input="touch"] .is-pressing { transition: transform var(--dur-fast) var(--ease-std); transform: scale(0.98); }

/* Chat list rows: no text selection or callout under a finger; a swipe left slides the row over its actions. */
html[data-input="touch"] .contact-row {
    position: relative;
    overflow: hidden;
    touch-action: pan-y;
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
    -webkit-tap-highlight-color: transparent;
}

html[data-input="touch"] .contact-row > :not(.swipe-actions) {
    transform: translateX(var(--swipe-x, 0px));
    transition: transform var(--dur-base) var(--ease-std);
}

html[data-input="touch"] .contact-row.is-swiping > :not(.swipe-actions),
html[data-input="touch"] .contact-row.is-swiping .swipe-actions { transition: none; }

html[data-input="touch"] .swipe-actions {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    display: flex;
    transform: translateX(calc(100% + var(--swipe-x, 0px)));
    transition: transform var(--dur-base) var(--ease-std);
}

html[data-input="touch"] .swipe-action {
    width: 72px;
    height: 100%;
    border: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: var(--space-1);
    color: white;
    font: inherit;
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
}

html[data-input="touch"] .swipe-action i { font-size: 18px; }
html[data-input="touch"] .swipe-action--warn { background: color-mix(in srgb, var(--c-status-warn-solid) 60%, black); }
html[data-input="touch"] .swipe-action--danger { background: color-mix(in srgb, var(--c-status-error-solid) 85%, black); }

/* Messages: a long-press lifts the bubble over the sheet's scrim and the reaction bar grows to 44 px cells.
   The hover smiley never shows under a finger. */
html[data-input="touch"] .bubble-me,
html[data-input="touch"] .bubble-other {
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
}

html[data-input="touch"] #react-action-btn { display: none !important; }

html[data-input="touch"] .bubble-lift {
    position: fixed;
    z-index: 9205;
    pointer-events: none;
    transform: scale(1.03);
    transform-origin: center;
}

html[data-input="touch"] .bubble-lift > * {
    box-shadow: 0 10px 28px rgba(0, 0, 0, 0.35), 0 0 0 4px var(--c-accent-soft);
}

html[data-input="touch"] #bubble-quick-react.is-touch {
    z-index: 9210;
    padding: var(--space-1);
    background: var(--c-bg-float-strong);
    -webkit-backdrop-filter: var(--backdrop-float);
    backdrop-filter: var(--backdrop-float);
    border: 1px solid var(--c-border-float);
}

html[data-input="touch"] #bubble-quick-react .qr-emoji {
    width: 44px;
    height: 44px;
    font-size: 24px;
}

/* Keyboard: the shell fits the visible part of the screen, so the header and the composer stay put,
   and a dialog sits just above the keyboard. */
html[data-input="touch"] body { height: var(--vv-h, 100dvh); }
html[data-input="touch"] .app-dialog { bottom: var(--kb-inset, 0px); }
html[data-input="touch"].kb-open .app-dialog { align-items: flex-end; padding-bottom: var(--space-2); }

/* Targets: every control is at least 44×44 px under a finger. Small visuals keep their size and get
   an invisible hit area around them instead. The window controls exist only in the desktop frame. */
html[data-input="touch"] :is(button, [role="button"], [role="menuitem"], [role="menuitemcheckbox"], [role="tab"], [role="radio"], [role="option"]):not(.list-chip):not(.devices-menu__toggle):not(#app-titlebar button) {
    min-width: 44px !important;
    min-height: 44px !important;
}

html[data-input="touch"] .set-row--switch { min-height: 44px; }

html[data-input="touch"] .list-chip { height: 36px; min-width: 44px; position: relative; }
html[data-input="touch"] .list-chip::before { content: ''; position: absolute; inset: -4px 0; }

html[data-input="touch"] .devices-menu__toggle { position: relative; }
html[data-input="touch"] .devices-menu__toggle::after { content: ''; position: absolute; inset: -6px; }

html[data-input="touch"] .reaction-chip { position: relative; }
html[data-input="touch"] .reaction-chip::before { content: ''; position: absolute; inset: -10px -4px; }

html[data-input="touch"] #conn-dot::before,
html[data-input="touch"] #chat-transport-icon::before {
    content: '';
    position: absolute;
    left: 50%;
    top: 50%;
    width: 44px;
    height: 44px;
    transform: translate(-50%, -50%);
}
html[data-input="touch"] #chat-transport-icon { position: relative; }

html[data-input="touch"] #emoji-picker #emoji-grid { grid-template-columns: repeat(auto-fill, minmax(44px, 1fr)); }

/* Tooltips open on a tap and close on a tap elsewhere; a sticky hover after a tap never holds one open. */
html[data-input="touch"] :not(.tip-open) > :is(.conn-dot, .chat-transport-icon):not(:focus-visible) + .conn-tip { display: none; }
html[data-input="touch"] .tip-open > .conn-tip { display: block; }

/* The top-edge connection line: a 16 px strip across the whole width, opened by a tap like the tooltips. */
html[data-input="touch"] #conn-edge { height: 16px; }
html[data-input="touch"] #conn-edge #conn-edge-hit { min-width: 0 !important; min-height: 0 !important; }

/* Settings: a 28 px slider thumb on a 44 px track hit area; the 6 px track stays drawn in the middle. */
html[data-input="touch"] .ui-range {
    height: 44px;
    margin: 0;
    border-radius: 0;
    background-size: 100% 6px;
    background-position: center;
    background-repeat: no-repeat;
    touch-action: pan-y;
}
html[data-input="touch"] .ui-range::-webkit-slider-thumb { width: 28px; height: 28px; }
html[data-input="touch"] .ui-range::-moz-range-thumb { width: 28px; height: 28px; }
