* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    padding: 0;
    min-height: 100%;
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    background: #0f172a;
    color: #e5e7eb;
}

body {
    min-height: 100vh;
}

.page {
    width: 100%;
    max-width: 720px;
    margin: 0 auto;
    padding: 18px;
}

.app-header {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-bottom: 18px;
}

.logo {
    width: 48px;
    height: 48px;
    border-radius: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #1d4ed8;
    box-shadow: 0 14px 35px rgba(29, 78, 216, 0.35);
    font-size: 24px;
}

h1,
h2,
h3,
p {
    margin: 0;
}

h1 {
    font-size: 24px;
    line-height: 1.15;
}

h2 {
    font-size: 20px;
    margin-bottom: 10px;
}

h3 {
    font-size: 18px;
    margin-bottom: 8px;
}

.app-header p,
.muted {
    color: #94a3b8;
    line-height: 1.45;
}

.card {
    background: #111827;
    border: 1px solid #243244;
    border-radius: 22px;
    padding: 18px;
    box-shadow: 0 20px 45px rgba(0, 0, 0, 0.25);
}

.hidden {
    display: none;
}

.button {
    appearance: none;
    border: 0;
    border-radius: 14px;
    background: #1d4ed8;
    color: #ffffff;
    font-weight: 700;
    font-size: 15px;
    line-height: 1;
    padding: 14px 16px;
    text-decoration: none;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 46px;
}

.button.secondary {
    background: #1f2937;
    color: #e5e7eb;
}

.actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    margin-top: 16px;
}

.user-line {
    color: #93c5fd;
    font-size: 14px;
    margin-bottom: 12px;
}


.main-key-generator {
    margin-top: 14px;
    padding: 14px;
    border-radius: 18px;
    background: #0b1220;
    border: 1px solid rgba(42, 171, 238, 0.18);
}

.main-key-title {
    color: #ffffff;
    font-size: 15px;
    font-weight: 800;
}

.main-key-description {
    margin-top: 6px;
    color: #94a3b8;
    font-size: 13px;
    line-height: 1.35;
}

.main-key-field {
    display: block;
    margin-top: 10px;
}

.main-key-actions {
    display: flex;
    gap: 10px;
    margin-top: 10px;
    flex-wrap: wrap;
}

.main-key-actions .button {
    min-height: 42px;
    padding: 12px 14px;
}

.empty-state {
    margin-top: 18px;
    padding: 22px;
    border-radius: 18px;
    background: #0b1220;
    border: 1px dashed #334155;
    text-align: center;
}

.empty-state p {
    color: #94a3b8;
    line-height: 1.45;
}

.room-swipe-row {
    position: relative;
    margin-top: 10px;
    border-radius: 16px;
    overflow: hidden;
    background: #7f1d1d;
    touch-action: pan-y;
}

.room-swipe-danger {
    position: absolute;
    top: 0;
    right: 0;
    width: 92px;
    height: 100%;
    border: 0;
    background: #ef4444;
    color: #ffffff;
    font-size: 14px;
    font-weight: 800;
    cursor: pointer;
}

.room-list-item {
    position: relative;
    width: 100%;
    min-height: 70px;
    border: 0;
    background: #17212b;
    color: #ffffff;
    padding: 10px 14px;
    text-align: left;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 12px;
    transition: transform 0.18s ease;
    z-index: 2;
}

.room-list-avatar {
    width: 46px;
    height: 46px;
    border-radius: 50%;
    background: linear-gradient(135deg, #2aabee 0%, #1d4ed8 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    flex: 0 0 46px;
}

.room-list-body {
    min-width: 0;
    flex: 1;
}

.room-list-tail {
    min-width: 34px;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    flex: 0 0 auto;
}

.room-unread-badge {
    min-width: 22px;
    height: 22px;
    padding: 0 7px;
    border-radius: 999px;
    background: #2aabee;
    color: #ffffff;
    font-size: 12px;
    font-weight: 800;
    line-height: 22px;
    text-align: center;
    box-shadow: 0 4px 12px rgba(42, 171, 238, 0.35);
}

.room-list-title {
    color: #ffffff;
    font-size: 16px;
    font-weight: 700;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.room-list-meta {
    margin-top: 4px;
    color: #8ea2b4;
    font-size: 13px;
}

.empty-icon {
    font-size: 32px;
    margin-bottom: 10px;
}

.field {
    display: grid;
    gap: 8px;
    margin-top: 16px;
}

.field span {
    color: #cbd5e1;
    font-size: 14px;
}

input {
    width: 100%;
    border: 1px solid #334155;
    border-radius: 14px;
    background: #0b1220;
    color: #e5e7eb;
    padding: 14px 15px;
    font-size: 16px;
    outline: none;
}

input:focus {
    border-color: #1d4ed8;
    box-shadow: 0 0 0 3px rgba(29, 78, 216, 0.25);
}

@media (max-width: 520px) {
    .page {
        padding: 14px;
    }

    .card {
        padding: 16px;
        border-radius: 20px;
    }

    .actions {
        flex-direction: column;
    }

    .button {
        width: 100%;
    }
}

/* Telegram-like chat */

body.chat-open {
    background: #111827;
    overflow: hidden;
}

body.chat-open .page {
    width: 100%;
    max-width: none;
    height: 100vh;
    min-height: 100vh;
    margin: 0;
    padding: 0;
}

body.chat-open .app-header {
    display: none;
}

body.chat-open main {
    height: 100vh;
    min-height: 100vh;
}

.chat-card {
    height: 100vh;
    min-height: 100vh;
    border: 0;
    border-radius: 0;
    padding: 0;
    background: #0e1621;
    box-shadow: none;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.chat-card.hidden {
    display: none;
}

.chat-topbar {
    height: 56px;
    min-height: 56px;
    padding: 6px 8px;
    background: #17212b;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 0 0 auto;
}

.chat-back-button,
.chat-icon-button,
.chat-send-button {
    appearance: none;
    border: 0;
    outline: 0;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    -webkit-tap-highlight-color: transparent;
}

.chat-back-button {
    width: 36px;
    height: 44px;
    background: transparent;
    color: #6ab3f3;
    font-size: 36px;
    line-height: 1;
    padding: 0;
    margin: 0;
}

.chat-avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: linear-gradient(135deg, #2aabee 0%, #1d4ed8 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    flex: 0 0 38px;
}

.chat-topbar-info {
    min-width: 0;
    flex: 1;
}

.chat-topbar-info-button {
    appearance: none;
    border: 0;
    background: transparent;
    padding: 0;
    text-align: left;
    cursor: pointer;
    display: block;
}

.chat-topbar-info h2 {
    margin: 0;
    color: #ffffff;
    font-size: 17px;
    line-height: 1.15;
    font-weight: 700;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-topbar-info p {
    margin: 2px 0 0;
    color: #8ea2b4;
    font-size: 13px;
    line-height: 1.15;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-icon-button {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: transparent;
    color: #6ab3f3;
    font-size: 18px;
    padding: 0;
    flex: 0 0 36px;
}

.chat-icon-button:active,
.chat-back-button:active,
.chat-send-button:active {
    transform: scale(0.96);
}

.chat-key-panel {
    padding: 10px 12px;
    background: #17212b;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    flex: 0 0 auto;
}

.chat-key-field {
    display: grid;
    gap: 6px;
    margin: 0;
}

.chat-key-field span {
    color: #8ea2b4;
    font-size: 13px;
}

.chat-key-field input {
    height: 42px;
    border: 1px solid rgba(106, 179, 243, 0.32);
    border-radius: 12px;
    background: #0e1621;
    color: #ffffff;
    padding: 10px 12px;
    font-size: 16px;
}

.chat-key-field input:focus {
    border-color: #2aabee;
    box-shadow: 0 0 0 3px rgba(42, 171, 238, 0.16);
}

.chat-messages-box {
    flex: 1 1 auto;
    overflow-y: auto;
    padding: 12px 9px 34px;
    background:
        radial-gradient(circle at 20% 0%, rgba(42, 171, 238, 0.10), transparent 26%),
        linear-gradient(180deg, #0e1621 0%, #101b27 100%);
    -webkit-overflow-scrolling: touch;
}

.chat-messages-list {
    min-height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    gap: 5px;
}

.chat-empty-text {
    align-self: center;
    margin: auto 0;
    max-width: 260px;
    padding: 8px 12px;
    border-radius: 999px;
    background: rgba(23, 33, 43, 0.88);
    color: #8ea2b4;
    text-align: center;
    font-size: 13px;
    line-height: 1.3;
}

.chat-message-row {
    display: flex;
    justify-content: flex-start;
    width: 100%;
}

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

.chat-bubble {
    position: relative;
    max-width: 78%;
    min-width: 52px;
    padding: 6px 9px 5px;
    border-radius: 13px 13px 13px 4px;
    background: #182533;
    color: #f4f7fb;
    box-shadow: 0 1px 1px rgba(0, 0, 0, 0.18);
    word-break: break-word;
}
.chat-bubble.can-delete {
    user-select: none;
    -webkit-user-select: none;
}

.chat-bubble.long-press-active {
    filter: brightness(1.18);
    transform: scale(0.985);
}

.chat-bubble.own {
    border-radius: 13px 13px 4px 13px;
    background: #2b5278;
    color: #ffffff;
}

.chat-bubble.decrypt-error {
    background: #6b1f2a;
    color: #ffe4e6;
}

.chat-message-sender {
    margin: 0 0 3px;
    color: #66b8ff;
    font-size: 12px;
    font-weight: 700;
    line-height: 1.2;
}

.chat-message-text {
    white-space: pre-wrap;
    font-size: 16px;
    line-height: 1.28;
}

.chat-message-time {
    float: right;
    margin: 5px 0 0 8px;
    color: rgba(244, 247, 251, 0.58);
    font-size: 11px;
    line-height: 1;
    white-space: nowrap;
}

.chat-message-receipt {
    display: inline-block;
    margin-left: 2px;
    color: rgba(244, 247, 251, 0.58);
    font-size: 12px;
    font-weight: 800;
    letter-spacing: -3px;
    vertical-align: -1px;
}

.chat-message-receipt.sent {
    letter-spacing: 0;
}

.chat-message-receipt.read {
    color: #6ab3f3;
}

.chat-topbar-info p.typing-active {
    color: #6ab3f3;
}

.chat-new-messages {
    position: fixed;
    left: 50%;
    bottom: calc(78px + env(safe-area-inset-bottom));
    transform: translateX(-50%);
    z-index: 8;
    border: 0;
    border-radius: 999px;
    background: rgba(42, 171, 238, 0.96);
    color: #ffffff;
    padding: 8px 13px;
    font-size: 13px;
    font-weight: 700;
    box-shadow: 0 10px 24px rgba(0, 0, 0, 0.32);
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.chat-new-messages.hidden {
    display: none;
}

.chat-action-backdrop {
    position: fixed;
    inset: 0;
    z-index: 20;
    background: rgba(0, 0, 0, 0.42);
}

.chat-action-backdrop.hidden {
    display: none;
}

.chat-message-actions {
    position: fixed;
    left: 10px;
    right: 10px;
    bottom: calc(10px + env(safe-area-inset-bottom));
    z-index: 21;
    padding: 8px;
    border-radius: 18px;
    background: #17212b;
    box-shadow: 0 18px 42px rgba(0, 0, 0, 0.45);
}

.chat-message-actions.hidden {
    display: none;
}

.chat-message-actions-title {
    padding: 10px 12px 8px;
    color: #8ea2b4;
    font-size: 13px;
    text-align: center;
}

.chat-message-action {
    width: 100%;
    min-height: 48px;
    border: 0;
    border-radius: 13px;
    background: #242f3d;
    color: #ffffff;
    font-size: 16px;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.chat-message-action + .chat-message-action {
    margin-top: 8px;
}

.chat-message-action.danger {
    color: #fecaca;
    background: rgba(127, 29, 29, 0.85);
}

.chat-message-action.cancel {
    color: #dbeafe;
    background: #1f2937;
}

/* Telegram-like room info */

.room-info-card {
    height: 100vh;
    min-height: 100vh;
    border: 0;
    border-radius: 0;
    padding: 0;
    background: #0e1621;
    box-shadow: none;
    overflow-y: auto;
}

.room-info-card.hidden {
    display: none;
}

.room-info-topbar {
    height: 56px;
    min-height: 56px;
    padding: 6px 8px;
    background: #17212b;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    display: flex;
    align-items: center;
    gap: 8px;
    position: sticky;
    top: 0;
    z-index: 3;
}

.room-info-back-button {
    width: 36px;
    height: 44px;
    border: 0;
    background: transparent;
    color: #6ab3f3;
    font-size: 36px;
    line-height: 1;
    padding: 0;
    cursor: pointer;
}

.room-info-topbar-title {
    color: #ffffff;
    font-size: 17px;
    font-weight: 700;
}

.room-info-header {
    padding: 24px 16px 18px;
    text-align: center;
    background: #0e1621;
}

.room-info-avatar {
    width: 84px;
    height: 84px;
    margin: 0 auto 12px;
    border-radius: 50%;
    background: linear-gradient(135deg, #2aabee 0%, #1d4ed8 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 38px;
}

.room-info-header h2 {
    margin: 0;
    color: #ffffff;
    font-size: 22px;
    line-height: 1.2;
}

.room-info-header p {
    margin-top: 5px;
    color: #8ea2b4;
    font-size: 14px;
}

.room-info-section {
    margin: 10px 10px 0;
    border-radius: 16px;
    background: #17212b;
    overflow: hidden;
}

.room-info-section-title {
    padding: 10px 14px 6px;
    color: #8ea2b4;
    font-size: 13px;
}

.room-info-participants {
    display: grid;
}

.room-info-participant {
    min-height: 58px;
    padding: 9px 14px;
    display: flex;
    align-items: center;
    gap: 12px;
    border-top: 1px solid rgba(255, 255, 255, 0.06);
}

.room-info-participant.can-kick {
    cursor: pointer;
}

.room-info-participant.can-kick:active {
    background: rgba(255, 255, 255, 0.06);
}

.room-info-participant-avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: #242f3d;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
}

.room-info-participant-body {
    min-width: 0;
    flex: 1;
}

.room-info-participant-name {
    color: #ffffff;
    font-size: 15px;
    font-weight: 650;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.room-info-participant-role {
    margin-top: 2px;
    color: #8ea2b4;
    font-size: 13px;
}

.room-info-actions-list {
    margin-bottom: 18px;
}

.room-info-action {
    width: 100%;
    min-height: 52px;
    border: 0;
    border-radius: 0;
    background: transparent;
    color: #ffffff;
    padding: 0 14px;
    font-size: 16px;
    text-align: left;
    cursor: pointer;
    display: flex;
    align-items: center;
    border-top: 1px solid rgba(255, 255, 255, 0.06);
}

.room-info-action:first-child {
    border-top: 0;
}

.room-info-action.danger {
    color: #fecaca;
}

.room-info-action.hidden {
    display: none;
}

.chat-compose {
    min-height: 58px;
    padding: 8px 9px calc(22px + env(safe-area-inset-bottom));
    background: #17212b;
    border-top: 1px solid rgba(255, 255, 255, 0.06);
    display: flex;
    align-items: flex-end;
    gap: 8px;
    flex: 0 0 auto;
}

.chat-compose input {
    height: 42px;
    min-height: 42px;
    flex: 1;
    border: 0;
    border-radius: 21px;
    background: #242f3d;
    color: #ffffff;
    padding: 10px 15px;
    font-size: 16px;
}

.chat-compose input::placeholder {
    color: #7f91a4;
}

.chat-compose input:focus {
    border: 0;
    box-shadow: none;
}

.chat-send-button {
    width: 42px;
    height: 42px;
    flex: 0 0 42px;
    border-radius: 50%;
    background: #2aabee;
    color: #ffffff;
    font-size: 18px;
    font-weight: 900;
    padding: 0 0 1px 2px;
}

@media (max-width: 520px) {
    body.chat-open .button {
        width: auto;
    }

    .chat-card {
        height: 100svh;
        min-height: 100svh;
    }

    .chat-bubble {
        max-width: 82%;
    }

    .chat-message-text {
        font-size: 15px;
    }
}
/* Telegram-like confirm sheet */

.app-confirm-backdrop {
    position: fixed;
    inset: 0;
    z-index: 30;
    background: rgba(0, 0, 0, 0.46);
}

.app-confirm-backdrop.hidden {
    display: none;
}

.app-confirm-sheet {
    position: fixed;
    left: 10px;
    right: 10px;
    bottom: calc(10px + env(safe-area-inset-bottom));
    z-index: 31;
    padding: 8px;
    border-radius: 18px;
    background: #17212b;
    box-shadow: 0 18px 42px rgba(0, 0, 0, 0.45);
}

.app-confirm-sheet.hidden {
    display: none;
}

.app-confirm-title {
    padding: 10px 12px 4px;
    color: #ffffff;
    font-size: 16px;
    font-weight: 800;
    text-align: center;
}

.app-confirm-text {
    padding: 0 12px 10px;
    color: #8ea2b4;
    font-size: 14px;
    line-height: 1.35;
    text-align: center;
}

.app-confirm-action {
    width: 100%;
    min-height: 48px;
    border: 0;
    border-radius: 13px;
    background: #242f3d;
    color: #ffffff;
    font-size: 16px;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.app-confirm-action + .app-confirm-action {
    margin-top: 8px;
}

.app-confirm-action.danger {
    color: #fecaca;
    background: rgba(127, 29, 29, 0.88);
}

.app-confirm-action.cancel {
    color: #dbeafe;
    background: #1f2937;
}


/* SecretKey attachments and room rename */
.chat-attach-button {
    appearance: none;
    border: 0;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: transparent;
    color: #6ab3f3;
    font-size: 30px;
    line-height: 1;
    padding: 0 0 3px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 38px;
    -webkit-tap-highlight-color: transparent;
}

.chat-attach-button:active {
    transform: scale(0.96);
}

.chat-attachment {
    clear: both;
    margin-top: 7px;
    padding: 8px;
    border-radius: 12px;
    background: rgba(0, 0, 0, 0.18);
}

.chat-attachment-title {
    color: #ffffff;
    font-size: 14px;
    font-weight: 700;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat-attachment-meta {
    margin-top: 3px;
    color: rgba(244, 247, 251, 0.68);
    font-size: 12px;
}

.chat-attachment-image {
    display: block;
    width: 164px;
    height: 164px;
    max-width: 100%;
    margin-top: 8px;
    border-radius: 12px;
    object-fit: cover;
    cursor: pointer;
    background: rgba(0, 0, 0, 0.22);
}

.chat-attachment-button {
    margin-top: 8px;
    width: 100%;
    min-height: 34px;
    border: 0;
    border-radius: 10px;
    background: rgba(42, 171, 238, 0.22);
    color: #dbeafe;
    font-size: 13px;
    font-weight: 800;
    cursor: pointer;
}

.room-info-title-row {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    max-width: 100%;
}

.room-info-title-row h2 {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.room-info-edit-button {
    width: 32px;
    height: 32px;
    border: 0;
    border-radius: 50%;
    background: #242f3d;
    color: #6ab3f3;
    font-size: 18px;
    font-weight: 800;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 32px;
}

.room-info-edit-button.hidden {
    display: none;
}

.room-rename-backdrop {
    position: fixed;
    inset: 0;
    z-index: 30;
    background: rgba(0, 0, 0, 0.42);
}

.room-rename-backdrop.hidden {
    display: none;
}

.room-rename-sheet {
    position: fixed;
    left: 10px;
    right: 10px;
    bottom: calc(10px + env(safe-area-inset-bottom));
    z-index: 31;
    padding: 12px;
    border-radius: 18px;
    background: #17212b;
    box-shadow: 0 18px 42px rgba(0, 0, 0, 0.45);
}

.room-rename-sheet.hidden {
    display: none;
}

.room-rename-title {
    padding: 4px 4px 10px;
    color: #ffffff;
    font-size: 16px;
    font-weight: 800;
    text-align: center;
}

.room-rename-sheet input {
    height: 44px;
    border: 1px solid rgba(106, 179, 243, 0.32);
    border-radius: 12px;
    background: #0e1621;
    color: #ffffff;
    padding: 10px 12px;
    font-size: 16px;
}

.room-rename-action {
    width: 100%;
    min-height: 46px;
    margin-top: 8px;
    border: 0;
    border-radius: 13px;
    background: #2aabee;
    color: #ffffff;
    font-size: 16px;
    font-weight: 800;
    cursor: pointer;
}

.room-rename-action.cancel {
    background: #1f2937;
    color: #dbeafe;
}


.photo-viewer-backdrop {
    position: fixed;
    inset: 0;
    z-index: 42;
    background: rgba(0, 0, 0, 0.86);
}

.photo-viewer-backdrop.hidden {
    display: none;
}

.photo-viewer {
    position: fixed;
    inset: 0;
    z-index: 43;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: calc(42px + env(safe-area-inset-top)) 12px calc(22px + env(safe-area-inset-bottom));
    pointer-events: none;
}

.photo-viewer.hidden {
    display: none;
}

.photo-viewer img {
    max-width: 100%;
    max-height: 100%;
    border-radius: 14px;
    object-fit: contain;
    box-shadow: 0 18px 50px rgba(0, 0, 0, 0.55);
    pointer-events: auto;
}

.photo-viewer-close {
    position: fixed;
    top: calc(10px + env(safe-area-inset-top));
    right: 12px;
    z-index: 44;
    width: 40px;
    height: 40px;
    border: 0;
    border-radius: 50%;
    background: rgba(23, 33, 43, 0.92);
    color: #ffffff;
    font-size: 28px;
    line-height: 1;
    cursor: pointer;
    pointer-events: auto;
}
