:root {
    color-scheme: dark;
    --bg: #0b0f0d;
    --surface: #111814;
    --surface-raised: #18211c;
    --surface-hover: #202c25;
    --line: #2a382f;
    --line-soft: rgba(255, 255, 255, 0.07);
    --text: #f3f7f4;
    --text-muted: #98a69d;
    --accent: #65d79a;
    --accent-strong: #38b979;
    --accent-ink: #07130d;
    --danger: #ff8c82;
    --shadow: 0 18px 50px rgba(0, 0, 0, 0.38);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

* {
    box-sizing: border-box;
}

html,
body {
    width: 100%;
    min-width: 320px;
    height: 100%;
    margin: 0;
}

body {
    overflow: hidden;
    color: var(--text);
    background: var(--bg);
    font-size: 15px;
    line-height: 1.5;
}

button,
input,
textarea {
    color: inherit;
    font: inherit;
    letter-spacing: 0;
}

button {
    border: 0;
}

button:not(:disabled) {
    cursor: pointer;
}

button:disabled {
    cursor: not-allowed;
    opacity: 0.38;
}

button:focus-visible,
input:focus-visible,
textarea:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

[hidden] {
    display: none !important;
}

.app-shell {
    display: grid;
    grid-template-columns: 340px minmax(0, 1fr);
    width: 100%;
    height: 100dvh;
    min-height: 480px;
}

.sidebar {
    z-index: 10;
    display: flex;
    min-width: 0;
    flex-direction: column;
    overflow: hidden;
    background: var(--surface);
    border-right: 1px solid var(--line);
}

.brand-bar,
.conversation-header {
    display: flex;
    min-height: 76px;
    align-items: center;
    flex: 0 0 auto;
}

.brand-bar {
    gap: 12px;
    padding: 14px 18px;
    border-bottom: 1px solid var(--line-soft);
}

.brand-mark,
.avatar {
    display: grid;
    flex: 0 0 auto;
    place-items: center;
    overflow: hidden;
    border-radius: 50%;
    color: #d9ffe9;
    background: #274737;
    font-weight: 700;
    user-select: none;
}

.brand-mark {
    width: 42px;
    height: 42px;
    border-radius: 8px;
    color: var(--accent-ink);
    background: var(--accent);
    font-size: 20px;
}

.avatar {
    width: 42px;
    height: 42px;
}

.avatar-self {
    color: #dce9ff;
    background: #33496d;
}

.brand-bar h1,
.brand-bar p,
.welcome-state h2,
.welcome-state p,
.modal h2,
.modal p {
    margin: 0;
}

.brand-bar h1 {
    font-size: 16px;
    line-height: 1.3;
}

.brand-bar p {
    margin-top: 2px;
    color: var(--text-muted);
    font-size: 12px;
}

.status-dot {
    display: inline-block;
    width: 7px;
    height: 7px;
    margin-right: 6px;
    border-radius: 50%;
    background: var(--accent);
    box-shadow: 0 0 0 3px rgba(101, 215, 154, 0.12);
}

.icon-button {
    display: grid;
    width: 38px;
    height: 38px;
    flex: 0 0 auto;
    place-items: center;
    border: 1px solid transparent;
    border-radius: 6px;
    color: var(--text-muted);
    background: transparent;
    font-weight: 700;
    transition: color 150ms ease, background 150ms ease, border-color 150ms ease;
}

.icon-button:not(:disabled):hover {
    color: var(--text);
    background: var(--surface-hover);
    border-color: var(--line);
}

.mobile-close,
.menu-button {
    display: none;
}

.mobile-close {
    margin-left: auto;
}

.identity-card {
    display: flex;
    min-width: 0;
    align-items: center;
    gap: 12px;
    margin: 16px;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface-raised);
}

.identity-copy,
.peer-copy {
    display: flex;
    min-width: 0;
    flex: 1;
    flex-direction: column;
}

.identity-copy strong,
.identity-copy span,
.peer-copy strong,
.peer-copy span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.identity-copy strong,
.peer-copy strong {
    font-size: 14px;
}

.identity-copy span,
.peer-copy span {
    color: var(--text-muted);
    font-size: 12px;
}

.contacts-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 4px 20px 10px;
    color: var(--text-muted);
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
}

.contact-count {
    min-width: 22px;
    padding: 1px 7px;
    border-radius: 999px;
    color: var(--text);
    background: var(--surface-hover);
    text-align: center;
}

.contact-list {
    overflow-y: auto;
    padding: 0 10px 12px;
}

.contact-item {
    display: flex;
    width: 100%;
    min-width: 0;
    align-items: center;
    gap: 12px;
    padding: 11px 10px;
    border-radius: 7px;
    color: var(--text);
    background: transparent;
    text-align: left;
}

.contact-item:hover,
.contact-item.active {
    background: var(--surface-hover);
}

.contact-item.active {
    box-shadow: inset 3px 0 var(--accent);
}

.empty-contacts {
    display: flex;
    flex: 1;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    padding: 30px;
    color: var(--text-muted);
    text-align: center;
}

.empty-contacts strong {
    margin-top: 12px;
    color: var(--text);
    font-size: 14px;
}

.empty-contacts span {
    max-width: 230px;
    margin-top: 6px;
    font-size: 12px;
}

.empty-lock {
    display: grid;
    width: 48px;
    height: 48px;
    place-items: center;
    border: 1px solid var(--line);
    border-radius: 50%;
    color: var(--accent);
    background: var(--surface-raised);
    font-size: 24px;
}

.conversation {
    display: flex;
    min-width: 0;
    flex-direction: column;
    overflow: hidden;
    background: #0e1310;
}

.conversation-header {
    gap: 12px;
    padding: 12px 22px;
    background: rgba(17, 24, 20, 0.94);
    border-bottom: 1px solid var(--line);
}

.conversation-header > .icon-button:last-child {
    margin-left: auto;
}

.messages {
    display: flex;
    min-height: 0;
    flex: 1;
    flex-direction: column;
    gap: 10px;
    overflow-y: auto;
    padding: 28px clamp(20px, 6vw, 92px);
    scrollbar-color: var(--line) transparent;
}

.welcome-state {
    display: flex;
    max-width: 520px;
    margin: auto;
    align-items: center;
    flex-direction: column;
    color: var(--text-muted);
    text-align: center;
}

.shield,
.modal-icon {
    display: grid;
    width: 64px;
    height: 64px;
    place-items: center;
    border: 1px solid #376047;
    border-radius: 50%;
    color: var(--accent);
    background: #15241b;
    font-size: 30px;
}

.welcome-state h2 {
    margin-top: 20px;
    color: var(--text);
    font-size: clamp(20px, 3vw, 28px);
    line-height: 1.25;
}

.welcome-state p {
    max-width: 460px;
    margin-top: 10px;
}

.security-points {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px;
    margin-top: 24px;
}

.security-points span {
    padding: 5px 10px;
    border: 1px solid var(--line);
    border-radius: 999px;
    color: #b7c4bc;
    background: var(--surface);
    font-size: 11px;
}

.message {
    display: flex;
    max-width: min(72%, 680px);
    flex-direction: column;
}

.message.sent,
.message.outgoing,
.message.mine {
    align-self: flex-end;
    align-items: flex-end;
}

.message.received,
.message.incoming {
    align-self: flex-start;
    align-items: flex-start;
}

.message-bubble,
.message-content {
    padding: 10px 14px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface-raised);
    overflow: hidden;
    overflow-wrap: anywhere;
    white-space: pre-wrap;
}

.message-image {
    display: block;
    width: min(360px, 60vw);
    max-height: 420px;
    object-fit: contain;
}

.message-audio {
    display: block;
    width: min(320px, 60vw);
    height: 40px;
}

.sent .message-bubble,
.outgoing .message-bubble,
.mine .message-bubble,
.sent .message-content,
.outgoing .message-content,
.mine .message-content {
    color: #082015;
    background: var(--accent);
    border-color: var(--accent);
}

.message-time,
.message-meta {
    margin-top: 4px;
    color: var(--text-muted);
    font-size: 11px;
}

.composer {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    padding: 14px clamp(18px, 4vw, 56px) 18px;
    background: var(--surface);
    border-top: 1px solid var(--line);
}

.composer textarea {
    width: 100%;
    min-height: 46px;
    max-height: 150px;
    resize: none;
    padding: 11px 14px;
    border: 1px solid var(--line);
    border-radius: 7px;
    color: var(--text);
    background: var(--surface-raised);
}

.composer textarea::placeholder {
    color: #758279;
}

.composer-tool {
    display: grid;
    width: 42px;
    height: 46px;
    flex: 0 0 auto;
    place-items: center;
    border: 1px solid var(--line);
    border-radius: 7px;
    color: var(--text-muted);
    background: var(--surface-raised);
    font-size: 17px;
}

.composer-tool:hover {
    color: var(--text);
    border-color: #526159;
}

.send-button {
    display: grid;
    width: 46px;
    height: 46px;
    flex: 0 0 auto;
    place-items: center;
    border-radius: 7px;
    color: var(--accent-ink);
    background: var(--accent);
    font-size: 18px;
    transition: background 150ms ease, transform 150ms ease;
}

.send-button:hover {
    background: #79e5aa;
}

.send-button:active {
    transform: translateY(1px);
}

.modal-backdrop {
    position: fixed;
    z-index: 100;
    inset: 0;
    display: grid;
    overflow-y: auto;
    place-items: center;
    padding: 24px;
    background: rgba(3, 7, 5, 0.78);
    backdrop-filter: blur(8px);
}

.modal {
    position: relative;
    width: min(100%, 480px);
    padding: 32px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface-raised);
    box-shadow: var(--shadow);
}

.modal-close {
    position: absolute;
    top: 12px;
    right: 12px;
}

.modal-icon {
    width: 52px;
    height: 52px;
    margin-bottom: 18px;
    font-size: 24px;
}

.modal h2 {
    padding-right: 38px;
    font-size: 22px;
}

.modal > p {
    margin-top: 9px;
    color: var(--text-muted);
    font-size: 14px;
}

.modal form {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 24px;
}

.modal label {
    color: #c5d0c9;
    font-size: 13px;
    font-weight: 700;
}

.modal input {
    width: 100%;
    height: 46px;
    padding: 0 13px;
    border: 1px solid var(--line);
    border-radius: 6px;
    color: var(--text);
    background: var(--surface);
}

.primary-button,
.secondary-button {
    min-height: 44px;
    padding: 10px 16px;
    border-radius: 6px;
    font-weight: 700;
}

.primary-button {
    margin-top: 6px;
    color: var(--accent-ink);
    background: var(--accent);
}

.primary-button:hover {
    background: #79e5aa;
}

.secondary-button {
    color: var(--text);
    background: var(--surface-hover);
    border: 1px solid var(--line);
}

.identity-details,
.security-details {
    margin-top: 22px;
}

.identity-details dl,
.security-details {
    margin-bottom: 18px;
}

.identity-details dl > div,
.security-details > div {
    display: grid;
    grid-template-columns: 110px minmax(0, 1fr);
    gap: 12px;
    padding: 10px 0;
    border-bottom: 1px solid var(--line-soft);
}

.identity-details dt,
.security-details dt {
    color: var(--text-muted);
}

.identity-details dd,
.security-details dd {
    min-width: 0;
    margin: 0;
    overflow-wrap: anywhere;
    text-align: right;
}

.identity-details .secondary-button,
.modal > .secondary-button {
    width: 100%;
}

.toast {
    position: fixed;
    z-index: 200;
    right: 22px;
    bottom: 22px;
    max-width: min(360px, calc(100vw - 32px));
    padding: 11px 15px;
    border: 1px solid var(--line);
    border-radius: 6px;
    color: var(--text);
    background: #202c25;
    box-shadow: var(--shadow);
    opacity: 0;
    pointer-events: none;
    transform: translateY(10px);
    transition: opacity 180ms ease, transform 180ms ease;
}

.toast.show,
.toast.visible {
    opacity: 1;
    transform: translateY(0);
}

@media (max-width: 760px) {
    .app-shell {
        display: block;
    }

    .sidebar {
        position: fixed;
        inset: 0 12% 0 0;
        box-shadow: var(--shadow);
        transform: translateX(-105%);
        transition: transform 200ms ease;
    }

    .sidebar.open,
    .sidebar.is-open {
        transform: translateX(0);
    }

    .mobile-close,
    .menu-button {
        display: grid;
    }

    .conversation {
        height: 100dvh;
    }

    .conversation-header {
        min-height: 68px;
        padding: 10px 12px;
    }

    .messages {
        padding: 22px 14px;
    }

    .message {
        max-width: 86%;
    }

    .composer {
        padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
    }

    .modal-backdrop {
        align-items: end;
        padding: 12px;
    }

    .modal {
        padding: 26px 20px 20px;
    }
}

@media (max-width: 420px) {
    .sidebar {
        right: 0;
    }

    .peer-copy span {
        max-width: 190px;
    }

    .identity-details dl > div,
    .security-details > div {
        grid-template-columns: 1fr;
        gap: 3px;
    }

    .identity-details dd,
    .security-details dd {
        text-align: left;
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        scroll-behavior: auto !important;
        transition-duration: 0.01ms !important;
    }
}