:root {
    --app-height: 100svh;
    /*--safe-bottom: env(safe-area-inset-bottom);*/
    --safe-bottom: 0px;
    --swipe-offset: 0px;
    --underlay-offset: -48px;
    --underlay-shift: 48px;
    --edge-swipe-width: 120px;
    --swipe-open-duration: 250ms;
    --swipe-close-duration: 200ms;
    /*--swipe-easing: cubic-bezier(.2, .8, .2, 1);*/
    --swipe-easing: cubic-bezier(0.32, 0.94, 0.60, 1);
    /* Good smooth release: cubic-bezier(0.25, 0.10, 0.25, 1); */
    --swipe-close-easing: cubic-bezier(0.25, 0.10, 0.25, 0.30);

    --bg: #f4f7fb;
    --surface: #ffffff;
    --surface-soft: #eef3f8;
    --surface-translucent: rgba(255, 255, 255, .94);
    --bottom-bar: rgba(255, 255, 255, .98);
    --text: #17212b;
    --muted: #6b7a8a;
    --line: #dce5ee;
    --row-line: rgba(220, 229, 238, .72);
    --accent: #1f8eff;
    --accent-dark: #0d6fd2;
    --mint: #18b99a;
    --amber: #f4a33b;
    --rose: #ef6262;
    --active-soft: #e5f2ff;
    --press-soft: #eaf2fa;
    --hover-soft: #f0f5fa;
    --filter-active: #e3f1ff;
    --filter-pressed: #d8ecff;
    --shell-from: #e8eef5;
    --shell-to: #f4f7fb;
    --header-line: rgba(138, 159, 180, .36);
    --bubble-shadow: rgba(92, 114, 138, .16);
    --input-bg: #ffffff;
    --send-disabled: #cbd8e4;
    --message-meta: rgba(86, 106, 124, .78);
    --wallpaper-dot: rgba(31, 142, 255, .08);
    --wallpaper-gloss-start: rgba(255, 255, 255, .55);
    --wallpaper-gloss-end: rgba(255, 255, 255, 0);
    --dialog-shadow: rgba(23, 33, 43, .16);
    --settings-chevron: #9baaba;
    --bubble-in: #ffffff;
    --bubble-out: #dff3df;
    --wallpaper: #dfe9f2;
    color-scheme: light;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
}

:root[data-theme="dark"] {
    --bg: #070b10;
    --surface: #0b1118;
    --surface-soft: #151d27;
    --surface-translucent: rgba(11, 17, 24, .94);
    --bottom-bar: rgba(11, 17, 24, .98);
    --text: #eef3f8;
    --muted: #91a1b3;
    --line: #202a36;
    --row-line: rgba(44, 56, 72, .72);
    --accent: #4da3ff;
    --accent-dark: #7bbcff;
    --mint: #35c8aa;
    --amber: #f2b45a;
    --rose: #ff7878;
    --active-soft: #122b43;
    --press-soft: #172433;
    --hover-soft: #141f2b;
    --filter-active: #133353;
    --filter-pressed: #183d61;
    --shell-from: #1b2531;
    --shell-to: #101821;
    --header-line: rgba(104, 125, 148, .32);
    --bubble-shadow: rgba(0, 0, 0, .24);
    --input-bg: #0f1720;
    --send-disabled: #334253;
    --message-meta: rgba(167, 179, 192, .74);
    --wallpaper-dot: rgba(77, 163, 255, .10);
    --wallpaper-gloss-start: rgba(255, 255, 255, .04);
    --wallpaper-gloss-end: rgba(255, 255, 255, 0);
    --dialog-shadow: rgba(0, 0, 0, .36);
    --settings-chevron: #6f8194;
    --bubble-in: #202a36;
    --bubble-out: #1d4c3f;
    --wallpaper: #070c12;
    color-scheme: dark;
}

* {
    box-sizing: border-box;
}

html,
body {
    width: 100%;
    height: 100%;
    margin: 0;
    overflow: hidden;
    background: var(--surface);
    color: var(--text);
    overscroll-behavior: none;
    -webkit-text-size-adjust: 100%;
}

html {
    min-height: -webkit-fill-available;
}

body {
    min-height: 100dvh;
    min-height: -webkit-fill-available;
    -webkit-font-smoothing: antialiased;
    -webkit-tap-highlight-color: transparent;
    text-rendering: optimizeLegibility;
}

body[data-view="dialog"] {
    background: var(--surface);
}

button,
input,
textarea {
    font: inherit;
}

button {
    border: 0;
}

.chat-sidebar,
.dialog-header,
.composer {
    -webkit-user-select: none;
    user-select: none;
}

input,
textarea,
.message-text {
    -webkit-user-select: text;
    user-select: text;
}

.icon-sprite {
    display: none;
}

.app-frame {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 1;
    width: 100vw;
    height: auto;
    min-height: 0;
    display: grid;
    grid-template-columns: 368px minmax(0, 1fr);
    overflow: hidden;
    background: var(--surface);
}

.chat-sidebar,
.dialog-pane {
    min-width: 0;
    min-height: 0;
}

.chat-sidebar {
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto;
    border-right: 1px solid var(--line);
    background: var(--surface);
}

.sidebar-header {
    padding: calc(12px + env(safe-area-inset-top)) 12px 10px;
    border-bottom: 1px solid var(--line);
    background: var(--surface);
}

.brand-row {
    display: grid;
    grid-template-columns: 44px minmax(0, 1fr) 44px 44px;
    align-items: center;
    gap: 8px;
    min-height: 44px;
}

.brand-copy {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    min-width: 0;
    gap: 10px;
}

.brand-copy strong {
    overflow: hidden;
    font-size: 20px;
    line-height: 1.2;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.brand-copy span {
    flex: 0 0 auto;
    color: var(--mint);
    font-size: 12px;
    font-weight: 700;
}

.icon-button {
    width: 44px;
    height: 44px;
    display: inline-grid;
    place-items: center;
    flex: 0 0 auto;
    border-radius: 50%;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
    transition: background-color 120ms ease, color 120ms ease, transform 120ms ease;
    touch-action: manipulation;
}

.icon-button svg {
    width: 22px;
    height: 22px;
    fill: none;
    stroke: currentColor;
    stroke-linecap: round;
    stroke-linejoin: round;
    stroke-width: 2;
}

.icon-button:active {
    transform: scale(.94);
}

.icon-button.is-pressed {
    background: var(--surface-soft);
    transform: scale(.94);
}

.icon-button:disabled {
    opacity: .48;
    cursor: default;
}

.push-button.is-enabled {
    background: rgba(31, 142, 255, .12);
    color: var(--accent);
}

@media (hover: hover) {
    .icon-button:hover {
        background: var(--surface-soft);
        color: var(--accent-dark);
    }
}

.search-box {
    height: 40px;
    display: grid;
    grid-template-columns: 24px minmax(0, 1fr);
    align-items: center;
    gap: 8px;
    margin: 10px 0;
    padding: 0 12px;
    border-radius: 8px;
    background: var(--surface-soft);
    color: var(--muted);
}

.search-box svg {
    width: 19px;
    height: 19px;
    fill: none;
    stroke: currentColor;
    stroke-linecap: round;
    stroke-linejoin: round;
    stroke-width: 2;
}

.search-box input {
    width: 100%;
    min-width: 0;
    border: 0;
    outline: 0;
    background: transparent;
    color: var(--text);
}

.search-box input::placeholder {
    color: var(--muted);
}

.chat-filters {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 6px;
}

.filter-button {
    min-width: 0;
    height: 34px;
    padding: 0 8px;
    border-radius: 8px;
    background: transparent;
    color: var(--muted);
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
    white-space: nowrap;
}

.filter-button.is-active {
    background: var(--filter-active);
    color: var(--accent-dark);
}

.filter-button.is-pressed {
    background: var(--filter-pressed);
}

.chat-filters.is-hidden {
    display: none;
}

.chat-list {
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    padding: 0;
}

.chat-row {
    width: 100%;
    height: 72px;
    display: grid;
    grid-template-columns: 52px minmax(0, 1fr) minmax(34px, auto);
    align-items: center;
    gap: 10px;
    padding: 0 14px;
    border-radius: 0;
    border-bottom: 1px solid var(--row-line);
    background: transparent;
    color: inherit;
    cursor: pointer;
    text-align: left;
    contain: layout paint style;
    touch-action: manipulation;
    transition: background-color 100ms ease;
}

.chat-row.is-active {
    background: var(--active-soft);
}

.chat-row.is-pressed {
    background: var(--press-soft);
}

@media (hover: hover) {
    .chat-row:hover {
        background: var(--hover-soft);
    }
}

.avatar,
.dialog-avatar {
    display: grid;
    place-items: center;
    border-radius: 50%;
    background: var(--avatar-color, var(--accent));
    color: #ffffff;
    font-weight: 800;
}

.avatar {
    width: 52px;
    height: 52px;
    font-size: 18px;
}

.chat-main {
    display: grid;
    gap: 1px;
    min-width: 0;
}

.chat-title {
    display: block;
    min-width: 0;
}

.chat-title strong {
    display: block;
    overflow: hidden;
    font-size: 14.5px;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat-preview {
    display: -webkit-box;
    overflow: hidden;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    color: var(--muted);
    font-size: 13px;
    line-height: 1.35;
    text-overflow: ellipsis;
}

.chat-preview.has-draft {
    color: var(--accent-dark);
}

.chat-meta {
    display: grid;
    align-self: stretch;
    align-content: center;
    justify-items: end;
    gap: 7px;
    min-width: 34px;
    padding: 9px 0;
}

.chat-time {
    color: var(--muted);
    font-size: 12px;
    line-height: 1;
    white-space: nowrap;
}

.chat-indicators {
    min-height: 20px;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 6px;
}

.pin-dot,
.unread-badge {
    display: grid;
    place-items: center;
    min-width: 20px;
    height: 20px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 800;
}

.pin-dot {
    width: 8px;
    min-width: 8px;
    height: 8px;
    background: var(--amber);
}

.unread-badge {
    padding: 0 6px;
    background: var(--accent);
    color: #ffffff;
}

.empty-list {
    display: grid;
    place-items: center;
    min-height: 160px;
    padding: 24px;
    color: var(--muted);
    font-size: 14px;
    text-align: center;
}

.section-row {
    width: 100%;
    min-height: 68px;
    display: grid;
    grid-template-columns: 52px minmax(0, 1fr) minmax(38px, auto);
    align-items: center;
    gap: 10px;
    padding: 0 14px;
    border-radius: 0;
    border-bottom: 1px solid var(--row-line);
    background: transparent;
    color: inherit;
    cursor: pointer;
    text-align: left;
    touch-action: manipulation;
    transition: background-color 100ms ease;
}

.section-row.is-settings {
    grid-template-columns: 44px minmax(0, 1fr) 18px;
    min-height: 58px;
}

.section-row.is-theme {
    grid-template-columns: 44px minmax(0, 1fr) 112px;
}

.section-row.is-pressed {
    background: var(--press-soft);
}

@media (hover: hover) {
    .section-row:hover {
        background: var(--hover-soft);
    }
}

.section-icon {
    width: 44px;
    height: 44px;
    display: grid;
    place-items: center;
    border-radius: 50%;
    background: var(--surface-soft);
    color: var(--accent);
}

.section-icon svg {
    width: 22px;
    height: 22px;
    fill: none;
    stroke: currentColor;
    stroke-linecap: round;
    stroke-linejoin: round;
    stroke-width: 2;
}

.section-main {
    min-width: 0;
    display: grid;
    gap: 3px;
}

.section-main strong,
.section-main span,
.section-meta {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.section-main strong {
    font-size: 15px;
    line-height: 1.25;
}

.section-main span {
    color: var(--muted);
    font-size: 13px;
    line-height: 1.25;
}

.section-meta {
    justify-self: end;
    color: var(--muted);
    font-size: 12px;
    line-height: 1;
}

.section-meta.is-missed {
    color: var(--rose);
    font-weight: 700;
}

.settings-chevron {
    color: var(--settings-chevron);
    font-size: 20px;
    line-height: 1;
}

.theme-switch {
    width: 112px;
    height: 34px;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-items: center;
    gap: 2px;
    padding: 3px;
    border-radius: 999px;
    background: var(--surface-soft);
    color: var(--muted);
}

.theme-option {
    height: 28px;
    display: grid;
    place-items: center;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 800;
    line-height: 1;
}

.theme-option.is-active {
    background: var(--surface);
    color: var(--accent);
    box-shadow: 0 1px 4px var(--bubble-shadow);
}

.bottom-tabs {
    min-height: 64px;
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 2px;
    padding: 5px 6px 6px;
    border-top: 1px solid var(--line);
    background: var(--bottom-bar);
}

.tab-button {
    min-width: 0;
    height: 52px;
    display: grid;
    grid-template-rows: 24px 16px;
    align-content: center;
    justify-items: center;
    gap: 3px;
    padding: 4px 2px;
    border-radius: 8px;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
    touch-action: manipulation;
    transition: background-color 120ms ease, color 120ms ease;
}

.tab-button svg {
    width: 23px;
    height: 23px;
    fill: none;
    stroke: currentColor;
    stroke-linecap: round;
    stroke-linejoin: round;
    stroke-width: 2;
}

.tab-button span {
    max-width: 100%;
    overflow: hidden;
    font-size: 10.5px;
    font-weight: 700;
    line-height: 1;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.tab-button.is-active {
    color: var(--accent);
}

.tab-button.is-pressed {
    background: var(--surface-soft);
}

@media (hover: hover) {
    .tab-button:hover {
        background: var(--surface-soft);
        color: var(--accent-dark);
    }
}

.shell-row,
.shell-message {
    pointer-events: none;
}

.shell-avatar,
.shell-line {
    overflow: hidden;
    background: linear-gradient(90deg, var(--shell-from), var(--shell-to));
    color: transparent;
}

.shell-line {
    display: inline-block;
    height: 12px;
    border-radius: 999px;
}

.shell-line-strong {
    width: 52%;
    height: 14px;
}

.shell-line-time {
    width: 42px;
}

.shell-line-preview {
    width: 78%;
}

.shell-message .message-bubble {
    width: min(420px, 76vw);
}

.shell-message-line {
    width: 100%;
    height: 13px;
    margin: 2px 0;
}

.shell-message-short {
    width: 64%;
}

.dialog-pane {
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto;
    background:
        radial-gradient(circle at 24px 24px, var(--wallpaper-dot) 0 2px, transparent 2px 100%),
        linear-gradient(135deg, var(--wallpaper-gloss-start), var(--wallpaper-gloss-end)),
        var(--wallpaper);
    background-size: 48px 48px, 100% 100%, auto;
}

.edge-swipe-zone {
    display: none;
}

.dialog-header {
    min-width: 0;
    display: grid;
    grid-template-columns: 42px minmax(0, 1fr) 44px 44px;
    align-items: center;
    gap: 8px;
    padding: calc(8px + env(safe-area-inset-top)) 12px 8px;
    border-bottom: 1px solid var(--header-line);
    background: var(--surface-translucent);
}

.back-button {
    display: none;
}

.dialog-avatar {
    width: 42px;
    height: 42px;
    font-size: 16px;
}

.dialog-title {
    min-width: 0;
}

.dialog-title strong,
.dialog-title span {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.dialog-title strong {
    font-size: 16px;
    line-height: 1.2;
}

.dialog-title span {
    margin-top: 2px;
    color: var(--muted);
    font-size: 12px;
}

.messages-shell {
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-y;
}

.messages-shell.is-scroll-locked {
    -webkit-overflow-scrolling: auto;
}

.messages-shell.is-scroll-stopped {
    overflow-y: hidden;
    -webkit-overflow-scrolling: auto;
}

.messages-list {
    width: min(100%, 780px);
    min-height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    gap: 6px;
    margin: 0 auto;
    padding: 18px 16px;
}

.message-row {
    display: flex;
}

.message-row.is-own {
    justify-content: flex-end;
}

.message-bubble {
    max-width: min(620px, 78%);
    padding: 8px 10px 7px;
    border-radius: 14px;
    background: var(--bubble-in);
    color: var(--text);
    box-shadow: 0 1px 0 var(--bubble-shadow);
}

.message-bubble::after {
    display: block;
    clear: both;
    content: "";
}

.message-row.is-own .message-bubble {
    background: var(--bubble-out);
}

.message-text {
    position: relative;
    z-index: 7;
    display: inline;
    font-size: 15px;
    line-height: 1.35;
    overflow-wrap: anywhere;
}

.message-foot {
    float: right;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    margin: 4px 0 0 8px;
    color: var(--message-meta);
    font-size: 11px;
    line-height: 1;
    white-space: nowrap;
}

.message-foot svg {
    width: 14px;
    height: 14px;
    fill: none;
    stroke: currentColor;
    stroke-linecap: round;
    stroke-linejoin: round;
    stroke-width: 2.2;
}

.composer {
    display: grid;
    grid-template-columns: 44px minmax(0, 1fr) 44px;
    align-items: end;
    gap: 8px;
    padding: 8px 12px max(8px, var(--safe-bottom));
    border-top: 1px solid var(--header-line);
    background: var(--surface);
}

.composer textarea {
    display: block;
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 42px;
    max-height: 132px;
    min-width: 0;
    padding: 10px 14px;
    border: 1px solid var(--line);
    border-radius: 21px;
    outline: 0;
    background: var(--input-bg);
    background-clip: padding-box;
    color: var(--text);
    box-shadow: none;
    font-size: 16px;
    line-height: 20px;
    overflow-y: auto;
    resize: none;
    -webkit-overflow-scrolling: touch;
}

.composer textarea:focus {
    border-color: rgba(31, 142, 255, .58);
}

.send-button {
    background: var(--accent);
    color: #ffffff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    line-height: 1;
}

.send-button svg {
    display: block;
    transform: translate(1px, -1px);
}

.send-button:disabled {
    background: var(--send-disabled);
    color: #ffffff;
    cursor: default;
    transform: none;
}

@media (max-width: 760px) {
    .app-frame {
        width: 100vw;
        grid-template-columns: 100vw;
    }

    .chat-sidebar,
    .dialog-pane {
        position: absolute;
        inset: 0;
        width: 100vw;
    }

    .chat-sidebar {
        z-index: 1;
        border-right: 0;
        transform: translate3d(0, 0, 0);
        transition: transform var(--swipe-open-duration) var(--swipe-easing);
        will-change: transform;
    }

    .dialog-pane {
        z-index: 2;
        transform: translate3d(100vw, 0, 0);
        transition: transform var(--swipe-open-duration) var(--swipe-easing);
        will-change: transform;
        box-shadow: -18px 0 40px var(--dialog-shadow);
    }

    .edge-swipe-zone {
        position: absolute;
        top: 0;
        bottom: 0;
        left: 0;
        z-index: 6;
        display: block;
        width: var(--edge-swipe-width);
        background: transparent;
        pointer-events: auto;
        touch-action: none;
    }

    body[data-closing="true"] .dialog-pane {
        transition-duration: var(--swipe-close-duration);
        transition-timing-function: var(--swipe-close-easing);
    }

    body[data-closing="true"] .chat-sidebar {
        transition-duration: var(--swipe-close-duration);
        transition-timing-function: var(--swipe-close-easing);
    }

    body[data-view="dialog"] .dialog-pane {
        transform: translate3d(var(--swipe-offset), 0, 0);
    }

    body[data-swiping="true"] .dialog-pane {
        transition: none;
    }

    body[data-view="dialog"] .chat-sidebar {
        transform: translate3d(var(--underlay-offset), 0, 0);
        pointer-events: none;
    }

    body[data-swiping="true"] .chat-sidebar {
        transition: none;
    }

    .dialog-header {
        position: relative;
        z-index: 7;
        grid-template-columns: 44px 42px minmax(0, 1fr) 44px 44px;
    }

    .composer {
        position: relative;
        z-index: 7;
    }

    .back-button {
        display: inline-grid;
    }

    .messages-list {
        padding: 14px 10px;
    }

    .message-bubble {
        max-width: 84%;
    }
}

@media (max-width: 380px) {
    .brand-copy strong {
        font-size: 18px;
    }

    .dialog-header {
        gap: 4px;
        padding-left: 8px;
        padding-right: 8px;
    }

    .composer {
        gap: 6px;
        padding-left: 8px;
        padding-right: 8px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .app-frame,
    .chat-sidebar,
    .dialog-pane,
    .icon-button {
        transition: none;
    }
}
