* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
}

html,
body {
    width: 100%;
    min-height: 100%;
    background: #e9edf5;
    color: #111827;
    overflow-x: hidden;
}

body[dir="rtl"] {
    direction: rtl;
}

.auth-page,
.mobile-shell,
.app {
    width: 100%;
    max-width: 480px;
    min-height: 100dvh;
    margin: 0 auto;
    background: #ffffff;
}

.auth-page {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 18px;
}

.auth-card {
    position: relative;
    width: 100%;
    padding: 26px 20px 22px;
    border-radius: 28px;
    background: #ffffff;
    box-shadow: 0 22px 65px rgba(15, 23, 42, .12);
}

.auth-lang {
    display: flex;
    justify-content: flex-end;
    gap: 6px;
    margin-bottom: 22px;
}

.auth-lang button {
    background: #f3f4f6;
    color: #111827;
    padding: 8px 10px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 800;
}

.brand {
    margin-bottom: 24px;
}

.brand h1,
h1 {
    font-size: 29px;
    letter-spacing: -0.04em;
}

.brand p,
p {
    color: #6b7280;
    margin-top: 7px;
    line-height: 1.45;
}

input,
select,
textarea {
    width: 100%;
    border: 1px solid #e5e7eb;
    border-radius: 17px;
    padding: 14px;
    font-size: 16px;
    margin-bottom: 12px;
    outline: none;
    background: #ffffff;
}

input:focus,
select:focus,
textarea:focus {
    border-color: #2563eb;
}

button,
.button-link {
    border: 0;
    border-radius: 17px;
    padding: 14px 18px;
    background: #111827;
    color: white;
    font-weight: 800;
    cursor: pointer;
    text-decoration: none;
    display: inline-block;
    text-align: center;
}

form button[type="submit"] {
    width: 100%;
}

.full {
    width: 100%;
    margin-top: 8px;
}

.ghost-btn,
.ghost-link {
    width: 100%;
    display: block;
    background: transparent;
    color: #374151;
    margin-top: 10px;
    text-align: center;
    text-decoration: none;
    border: 0;
    font-weight: 800;
}

.error {
    background: #fef2f2;
    color: #b91c1c;
    padding: 12px;
    border-radius: 14px;
    font-size: 14px;
    margin-bottom: 14px;
}

.mobile-shell {
    padding: 18px;
}

.home-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 22px;
}

.home-header h1 {
    font-size: 29px;
}

.home-header p {
    font-size: 13px;
}

.home-header a {
    color: #111827;
    text-decoration: none;
    font-weight: 800;
}

.new-chat-btn {
    display: block;
    width: 100%;
    background: #111827;
    color: white;
    text-decoration: none;
    text-align: center;
    padding: 16px;
    border-radius: 18px;
    font-weight: 900;
    margin-bottom: 20px;
}

.chat-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.chat-item {
    display: flex;
    gap: 14px;
    align-items: center;
    padding: 16px;
    border: 1px solid #edf0f4;
    border-radius: 22px;
    text-decoration: none;
    color: #111827;
    background: white;
}

.chat-avatar {
    width: 46px;
    height: 46px;
    border-radius: 16px;
    background: #f3f4f6;
    display: grid;
    place-items: center;
}

.chat-item strong {
    display: block;
    font-size: 15px;
}

.chat-item span {
    display: block;
    margin-top: 4px;
    font-size: 12px;
    color: #6b7280;
}

.empty {
    text-align: center;
    padding: 50px 20px;
    color: #6b7280;
}

.empty h2 {
    color: #111827;
    margin-bottom: 8px;
}

.app {
    height: 100dvh;
    display: flex;
    flex-direction: column;
}

.chat-header {
    height: 70px;
    padding: 12px 14px;
    display: flex;
    align-items: center;
    gap: 10px;
    border-bottom: 1px solid #edf0f4;
    background: rgba(255,255,255,.98);
    flex-shrink: 0;
}

.back-link {
    width: 38px;
    height: 38px;
    border-radius: 14px;
    display: grid;
    place-items: center;
    background: #f3f4f6;
    text-decoration: none;
    color: #111827;
    font-size: 30px;
    line-height: 1;
    flex: 0 0 auto;
}

.chat-title {
    flex: 1;
    min-width: 0;
}

.chat-title h1 {
    font-size: 16px;
    letter-spacing: -0.02em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-title p {
    font-size: 12px;
    margin-top: 2px;
}

.small-select {
    width: 68px;
    padding: 9px;
    margin: 0;
    border-radius: 12px;
    font-size: 13px;
}

.invite-mini {
    background: #111827;
    color: white;
    text-decoration: none;
    padding: 9px 11px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 800;
    flex: 0 0 auto;
}

.chat {
    flex: 1;
    overflow-y: auto;
    padding: 14px;
    background:
        radial-gradient(circle at top left, rgba(37,99,235,.08), transparent 34%),
        #f7f8fb;
    -webkit-overflow-scrolling: touch;
}

.message {
    max-width: 84%;
    margin-bottom: 14px;
}

.message.me {
    margin-left: auto;
}

.bubble {
    padding: 12px 14px;
    border-radius: 22px;
    font-size: 15px;
    line-height: 1.42;
    box-shadow: 0 8px 22px rgba(15,23,42,.06);
    word-wrap: break-word;
    white-space: pre-wrap;
}

.me .bubble {
    background: #1f2937;
    color: white;
    border-bottom-right-radius: 7px;
}

.other .bubble {
    background: white;
    color: #111827;
    border: 1px solid #eef0f4;
    border-bottom-left-radius: 7px;
}

.image-bubble {
    overflow: hidden;
    border-radius: 22px;
    background: #fff;
    box-shadow: 0 8px 22px rgba(15,23,42,.08);
}

.image-bubble img {
    display: block;
    max-width: 100%;
    height: auto;
}

.meta {
    margin-top: 5px;
    font-size: 11px;
    color: #9ca3af;
}

.me .meta {
    text-align: right;
}

.original {
    margin-top: 6px;
    padding: 0;
    background: transparent;
    color: #6b7280;
    font-size: 11px;
}

.composer {
    min-height: 68px;
    padding: 10px;
    padding-bottom: calc(10px + env(safe-area-inset-bottom));
    display: flex;
    align-items: flex-end;
    gap: 8px;
    border-top: 1px solid #edf0f4;
    background: white;
    flex-shrink: 0;
}

.composer textarea {
    flex: 1;
    margin: 0;
    min-height: 46px;
    max-height: 110px;
    resize: none;
    border-radius: 20px;
}

.icon-btn,
.send-btn {
    width: 46px;
    height: 46px;
    padding: 0;
    border-radius: 17px;
    flex: 0 0 auto;
}

.icon-btn {
    background: #f3f4f6;
    color: #111827;
    font-size: 23px;
}

.send-btn {
    background: #2563eb;
    font-size: 18px;
}

.message-menu {
    position: fixed;
    z-index: 9999;
    min-width: 150px;
    background: rgba(255,255,255,.96);
    backdrop-filter: blur(18px);
    border: 1px solid #e5e7eb;
    border-radius: 18px;
    box-shadow: 0 18px 50px rgba(15,23,42,.18);
    padding: 6px;
    display: none;
}

.message-menu.active {
    display: block;
}

.message-menu button {
    width: 100%;
    display: block;
    background: transparent;
    color: #111827;
    border-radius: 13px;
    padding: 11px 12px;
    font-size: 14px;
    font-weight: 700;
    text-align: left;
}

.message-menu button:hover {
    background: #f3f4f6;
}

body[dir="rtl"] .message-menu button {
    text-align: right;
}

.deleted-message {
    background: #f3f4f6 !important;
    color: #9ca3af !important;
    font-style: italic;
}

@media (min-width: 768px) {
    body {
        min-height: 100vh;
        padding: 28px;
        background:
            radial-gradient(circle at top left, rgba(37,99,235,.14), transparent 32%),
            linear-gradient(180deg, #eef1f6, #dde3ee);
    }

    .auth-page,
    .mobile-shell,
    .app {
        border-radius: 34px;
        box-shadow: 0 30px 90px rgba(15,23,42,.14);
        overflow: hidden;
    }

    .auth-page {
        max-width: 480px;
        min-height: calc(100vh - 56px);
    }

    .mobile-shell,
    .app {
        height: calc(100vh - 56px);
        min-height: calc(100vh - 56px);
    }
}

@media (max-width: 360px) {
    .chat-header {
        gap: 7px;
        padding: 10px;
    }

    .small-select {
        width: 60px;
        font-size: 12px;
    }

    .invite-mini {
        padding: 8px 9px;
    }

    .chat-title h1 {
        font-size: 15px;
    }
}