*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --header-bg: #075E54;
    --header-text: #ffffff;
    --chat-bg: #ECE5DD;
    --chat-bg-pattern: #DAD0C5;
    --sent-bg: #DCF8C6;
    --received-bg: #FFFFFF;
    --text-primary: #111B21;
    --text-secondary: #667781;
    --input-bg: #FFFFFF;
    --footer-bg: #F0F2F5;
    --accent: #25D366;
    --shadow: 0 1px 0.5px rgba(11, 20, 26, 0.13);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --safe-top: env(safe-area-inset-top, 0px);
}

html {
    height: 100%;
    height: 100dvh;
}

html,
body {
    width: 100%;
    -webkit-text-size-adjust: 100%;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: var(--chat-bg);
    color: var(--text-primary);
}

body {
    min-height: 100%;
    min-height: 100dvh;
    overflow: hidden;
    overscroll-behavior: none;
    touch-action: manipulation;
}

.app {
    display: flex;
    flex-direction: column;
    height: 100dvh;
    max-width: 720px;
    margin: 0 auto;
    background: var(--chat-bg);
    position: relative;
    overflow: hidden;
}

.chat-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: calc(10px + var(--safe-top)) 16px 10px;
    background: var(--header-bg);
    color: var(--header-text);
    flex-shrink: 0;
    z-index: 10;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

.header-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 18px;
}

.header-info h1 {
    font-size: 17px;
    font-weight: 600;
    line-height: 1.2;
}

.header-info {
    flex: 1;
    min-width: 0;
}

.logout-btn {
    width: 40px;
    height: 40px;
    border: none;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    text-decoration: none;
    position: relative;
    z-index: 20;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.logout-btn:active {
    background: rgba(255, 255, 255, 0.22);
}

.header-status {
    font-size: 13px;
    opacity: 0.85;
    margin-top: 2px;
}

.chat-main {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    background-color: var(--chat-bg);
    background-image:
        radial-gradient(circle at 20% 30%, rgba(255, 255, 255, 0.35) 0, transparent 50%),
        radial-gradient(circle at 80% 70%, rgba(255, 255, 255, 0.25) 0, transparent 45%);
}

.messages {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 12px 10px 16px;
    min-height: 100%;
    justify-content: flex-end;
}

.message-row {
    display: flex;
    width: 100%;
    animation: fadeIn 0.2s ease;
}

.message-row.sent {
    justify-content: flex-end;
}

.message-row.received {
    justify-content: flex-start;
}

.message-bubble {
    max-width: 82%;
    padding: 8px 12px 6px;
    border-radius: 8px;
    box-shadow: var(--shadow);
    word-wrap: break-word;
    overflow-wrap: anywhere;
    position: relative;
}

.message-row.sent .message-bubble {
    background: var(--sent-bg);
    border-top-right-radius: 2px;
}

.message-row.received .message-bubble {
    background: var(--received-bg);
    border-top-left-radius: 2px;
}

.sender-name {
    font-size: 12px;
    font-weight: 600;
    color: #E91E63;
    margin-bottom: 2px;
}

.message-row.sent .sender-name {
    display: none;
}

.message-text {
    font-size: 15px;
    line-height: 1.35;
    white-space: pre-wrap;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", sans-serif;
}

.message-text-emoji-only {
    font-size: 2.1rem;
    line-height: 1.2;
    letter-spacing: 0.04em;
    padding: 2px 0;
}

.inline-emoji {
    font-size: 1.65em;
    line-height: 1;
    vertical-align: -0.1em;
}

.message-meta {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 6px;
    margin-top: 4px;
}

.reply-action {
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-size: 14px;
    line-height: 1;
    padding: 0 2px;
    cursor: pointer;
    opacity: 0.7;
}

.reply-action:active {
    opacity: 1;
}

.reply-quote {
    border-left: 3px solid #25D366;
    background: rgba(0, 0, 0, 0.05);
    border-radius: 6px;
    padding: 6px 8px;
    margin-bottom: 6px;
    font-size: 12px;
    line-height: 1.35;
}

.reply-quote strong {
    display: block;
    color: #128C7E;
    font-size: 12px;
    margin-bottom: 2px;
}

.reply-quote span {
    display: block;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.message-row.sent .reply-quote {
    border-left-color: #128C7E;
}

.message-image-link {
    display: block;
    margin-bottom: 4px;
}

.message-image {
    display: block;
    max-width: 220px;
    width: 100%;
    border-radius: 8px;
    object-fit: cover;
}

.chat-footer {
    flex-shrink: 0;
    position: relative;
    z-index: 50;
    padding: 0 10px calc(8px + var(--safe-bottom));
    background: var(--footer-bg);
    border-top: 1px solid rgba(0, 0, 0, 0.06);
}

.reply-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 4px 8px 12px;
    background: #fff;
    border-bottom: 1px solid rgba(0, 0, 0, 0.06);
}

.reply-bar.hidden {
    display: none;
}

.reply-bar-line {
    width: 4px;
    align-self: stretch;
    border-radius: 4px;
    background: #25D366;
    flex-shrink: 0;
}

.reply-bar-body {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.reply-bar-body strong {
    font-size: 13px;
    color: #128C7E;
}

.reply-bar-body span {
    font-size: 13px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.reply-bar-close {
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-size: 24px;
    line-height: 1;
    width: 36px;
    height: 36px;
    cursor: pointer;
}

.attach-sheet {
    position: fixed;
    inset: 0;
    z-index: 120;
}

.attach-sheet.hidden {
    display: none;
}

.attach-sheet-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
}

.attach-sheet-panel {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    background: #fff;
    border-radius: 16px 16px 0 0;
    padding: 20px 16px calc(20px + var(--safe-bottom));
    display: flex;
    gap: 24px;
    justify-content: center;
}

.attach-option {
    border: none;
    background: transparent;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    min-width: 72px;
    font-size: 13px;
    color: var(--text-primary);
    cursor: pointer;
}

.attach-icon {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
}

.attach-icon-gallery {
    background: #7E57C2;
}

.attach-icon-camera {
    background: #E53935;
}

.attach-btn {
    width: 40px;
    height: 40px;
    border: none;
    border-radius: 50%;
    background: transparent;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
}

.attach-btn:active {
    background: rgba(0, 0, 0, 0.06);
}

.emoji-btn {
    width: 40px;
    height: 40px;
    border: none;
    border-radius: 50%;
    background: transparent;
    font-size: 24px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.emoji-btn:active {
    background: rgba(0, 0, 0, 0.06);
}

.emoji-panel {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 100%;
    background: #fff;
    border-top: 1px solid rgba(0, 0, 0, 0.08);
    box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.08);
    max-height: 240px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    z-index: 60;
}

.emoji-panel.hidden {
    display: none;
}

.emoji-panel-grid {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    gap: 2px;
    padding: 10px 8px;
}

.emoji-item {
    border: none;
    background: transparent;
    font-size: 26px;
    line-height: 1;
    padding: 8px 0;
    cursor: pointer;
    border-radius: 8px;
    touch-action: manipulation;
}

.emoji-item:active {
    background: rgba(0, 0, 0, 0.06);
}

.message-form {
    display: flex;
    align-items: flex-end;
    gap: 6px;
    padding: 8px 0;
}

.message-time {
    font-size: 11px;
    color: var(--text-secondary);
}

.message-input {
    flex: 1;
    min-height: 42px;
    max-height: 120px;
    padding: 10px 14px;
    border: none;
    border-radius: 22px;
    background: var(--input-bg);
    font-size: 16px;
    line-height: 1.3;
    outline: none;
    resize: none;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
    -webkit-appearance: none;
    appearance: none;
    touch-action: manipulation;
    pointer-events: auto;
    -webkit-user-select: text;
    user-select: text;
}

.message-input.is-locked {
    cursor: pointer;
}

.message-input:focus {
    box-shadow: 0 0 0 2px rgba(37, 211, 102, 0.25);
}

.send-btn {
    width: 44px;
    height: 44px;
    border: none;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    transition: transform 0.15s ease, opacity 0.15s ease;
}

.send-btn:active {
    transform: scale(0.94);
}

.send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.name-modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    z-index: 100;
}

.name-modal.hidden {
    display: none !important;
    pointer-events: none !important;
    visibility: hidden;
}

.name-modal-content {
    background: #fff;
    border-radius: 14px;
    padding: 24px 20px;
    width: 100%;
    max-width: 340px;
    text-align: center;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
}

.name-modal-content h2 {
    font-size: 20px;
    margin-bottom: 8px;
}

.name-modal-content p {
    font-size: 14px;
    color: var(--text-secondary);
    margin-bottom: 16px;
}

.name-choices {
    display: flex;
    gap: 14px;
    justify-content: center;
}

.name-choice-btn {
    width: 88px;
    height: 88px;
    border: none;
    border-radius: 50%;
    background: var(--header-bg);
    color: #fff;
    font-size: 34px;
    font-weight: 700;
    cursor: pointer;
    box-shadow: 0 4px 14px rgba(7, 94, 84, 0.35);
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.name-choice-btn:active {
    transform: scale(0.94);
}

.name-choice-btn[data-name="K"] {
    background: #128C7E;
}

.toast {
    position: fixed;
    left: 50%;
    bottom: calc(80px + var(--safe-bottom));
    transform: translateX(-50%) translateY(20px);
    background: rgba(17, 27, 33, 0.92);
    color: #fff;
    padding: 10px 16px;
    border-radius: 20px;
    font-size: 13px;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease, transform 0.25s ease;
    z-index: 200;
    max-width: 90%;
    text-align: center;
}

.toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

.empty-state {
    text-align: center;
    color: var(--text-secondary);
    font-size: 14px;
    padding: 40px 20px;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(6px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@media (min-width: 721px) {
    .app {
        border-left: 1px solid rgba(0, 0, 0, 0.08);
        border-right: 1px solid rgba(0, 0, 0, 0.08);
        box-shadow: 0 0 24px rgba(0, 0, 0, 0.08);
    }
}

.login-page {
    position: relative;
    overflow: hidden;
    background: #0a1614;
    color: #f5f5f7;
}

.login-bg-glow {
    position: fixed;
    border-radius: 50%;
    filter: blur(80px);
    pointer-events: none;
    z-index: 0;
}

.login-bg-glow--one {
    width: 280px;
    height: 280px;
    top: -80px;
    left: -60px;
    background: rgba(7, 94, 84, 0.45);
    animation: glowDrift 8s ease-in-out infinite;
}

.login-bg-glow--two {
    width: 240px;
    height: 240px;
    bottom: -60px;
    right: -40px;
    background: rgba(18, 140, 126, 0.3);
    animation: glowDrift 10s ease-in-out infinite reverse;
}

.login-shell {
    position: relative;
    z-index: 1;
    min-height: 100dvh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: calc(24px + env(safe-area-inset-top)) 18px calc(24px + env(safe-area-inset-bottom));
}

.login-card {
    width: 100%;
    max-width: 400px;
    background: rgba(18, 28, 26, 0.94);
    border: 1px solid rgba(37, 211, 102, 0.18);
    border-radius: 24px;
    padding: 36px 24px 28px;
    text-align: center;
    box-shadow:
        0 0 0 1px rgba(255, 255, 255, 0.04) inset,
        0 24px 64px rgba(0, 0, 0, 0.5),
        0 0 40px rgba(7, 94, 84, 0.15);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
}

.login-lock-badge {
    width: 72px;
    height: 72px;
    margin: 0 auto 20px;
    border-radius: 50%;
    background: rgba(7, 94, 84, 0.35);
    border: 1px solid rgba(37, 211, 102, 0.25);
    display: flex;
    align-items: center;
    justify-content: center;
}

.login-lock-icon {
    width: 32px;
    height: 32px;
    color: #25D366;
}

.login-label {
    display: inline-block;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: #25D366;
    background: rgba(37, 211, 102, 0.1);
    border: 1px solid rgba(37, 211, 102, 0.25);
    border-radius: 20px;
    padding: 5px 14px;
    margin-bottom: 14px;
}

.login-title {
    font-size: clamp(18px, 4.5vw, 22px);
    font-weight: 600;
    line-height: 1.4;
    color: #ffffff;
    margin-bottom: 24px;
    letter-spacing: -0.01em;
}

.login-error {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    background: rgba(239, 68, 68, 0.12);
    border: 1px solid rgba(239, 68, 68, 0.35);
    color: #fca5a5;
    border-radius: 12px;
    padding: 11px 14px;
    font-size: 13px;
    margin-bottom: 14px;
    text-align: left;
}

.login-form {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.login-input-wrap {
    position: relative;
}

.login-input-icon {
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    width: 18px;
    height: 18px;
    color: rgba(255, 255, 255, 0.35);
    pointer-events: none;
}

.login-input {
    width: 100%;
    padding: 15px 16px 15px 44px;
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 14px;
    font-size: 16px;
    outline: none;
    background: rgba(255, 255, 255, 0.06);
    color: #fff;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.login-input::placeholder {
    color: rgba(255, 255, 255, 0.3);
}

.login-input:focus {
    border-color: rgba(37, 211, 102, 0.55);
    box-shadow: 0 0 0 3px rgba(37, 211, 102, 0.15);
}

.login-btn {
    width: 100%;
    padding: 15px 18px;
    border: none;
    border-radius: 14px;
    background: linear-gradient(135deg, #075E54 0%, #128C7E 100%);
    color: #fff;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    box-shadow: 0 4px 20px rgba(7, 94, 84, 0.4);
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.login-btn:active {
    transform: scale(0.98);
    box-shadow: 0 2px 12px rgba(7, 94, 84, 0.3);
}

@keyframes glowDrift {
    0%, 100% {
        transform: translate(0, 0);
    }
    50% {
        transform: translate(20px, 16px);
    }
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}
