/* Base styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --color-primary: #4a8de8;
    --color-primary-dark: #3a7bd4;
    --color-link: #2563eb;
    --color-danger: #dc2626;
    --color-success: #16a34a;
    --color-text: #333;
    --color-text-secondary: #666;
    --color-text-muted: #999;
    --color-bg: #fff;
    --color-bg-hover: #f5f5f5;
    --color-bg-secondary: #f9f9f9;
    --color-border: #e5e5e5;
    --color-border-light: #ccc;
}

html {
    touch-action: manipulation;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background-color: var(--color-bg-hover);
    color: var(--color-text);
    line-height: 1.6;
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
}

/* Card layout */
.card {
    background: var(--color-bg);
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    padding: 40px;
    width: 100%;
    max-width: 420px;
}

.card h1 {
    text-align: center;
    margin-bottom: 8px;
    font-size: 24px;
    color: #222;
}

/* Logo images - crop the square image to show only the text band */
.logo-title {
    height: 56px;
    display: inline-block;
}

.page-subtitle {
    text-align: center;
    font-size: 16px;
    color: var(--color-text-secondary);
    margin-bottom: 20px;
}

.top-bar-logo {
    height: 34px;
    display: block;
    margin-top: 2px;
}

/* Step indicator */
.steps {
    display: flex;
    justify-content: center;
    gap: 12px;
    margin-bottom: 28px;
}

.step {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 14px;
    color: var(--color-text-muted);
}

.step.active {
    color: var(--color-link);
    font-weight: 600;
}

.step-number {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    border: 2px solid var(--color-border-light);
    font-size: 12px;
    font-weight: 600;
}

.step.active .step-number {
    background-color: var(--color-primary);
    border-color: var(--color-primary);
    color: var(--color-bg);
}

.step-divider {
    width: 32px;
    height: 2px;
    background-color: var(--color-border-light);
    align-self: center;
}

/* Form fields */
.form-group {
    margin-bottom: 3px;
}

.form-group label {
    display: block;
    margin-bottom: 4px;
    font-size: 14px;
    font-weight: 500;
    color: #555;
}

.form-group input {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
    transition: border-color 0.2s;
}

.form-group input:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 2px rgba(74, 144, 217, 0.2);
}

.form-group input.error {
    border-color: #e74c3c;
}

/* Error messages */
.field-error {
    color: #e74c3c;
    font-size: 12px;
    margin-top: 4px;
    min-height: 18px;
}

.form-error {
    background-color: #fef2f2;
    border: 1px solid #fecaca;
    color: var(--color-danger);
    padding: 10px 14px;
    border-radius: 4px;
    font-size: 14px;
    margin-bottom: 16px;
    display: none;
}

.form-error.visible {
    display: block;
}

/* Success message */
.success-message {
    text-align: center;
    padding: 20px;
    display: none;
}

.success-message.visible {
    display: block;
}

.success-message .icon {
    font-size: 48px;
    margin-bottom: 12px;
}

.success-message h2 {
    font-size: 20px;
    color: var(--color-success);
    margin-bottom: 8px;
}

.success-message p {
    color: var(--color-text-secondary);
    font-size: 14px;
}

/* Buttons */
.btn {
    width: 100%;
    padding: 12px;
    border: none;
    border-radius: 4px;
    font-size: 16px;
    font-weight: 500;
    cursor: pointer;
    transition: background-color 0.2s, opacity 0.2s;
}

.btn-primary {
    background-color: var(--color-primary);
    color: var(--color-bg);
}

.btn-primary:hover:not(:disabled) {
    background-color: var(--color-primary-dark);
}

.btn-newline {
    background-color: var(--color-bg);
    color: var(--color-text-muted);
    border: 1px solid var(--color-border-light);
}

.btn-secondary {
    background-color: transparent;
    color: var(--color-link);
    border: 1px solid var(--color-primary);
    margin-top: 8px;
}

.btn-secondary:hover:not(:disabled) {
    background-color: #f0f7ff;
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* Info text */
.info-text {
    text-align: center;
    color: var(--color-text-secondary);
    font-size: 14px;
    margin-bottom: 20px;
}

/* Resend feedback */
.resend-feedback {
    text-align: center;
    color: var(--color-success);
    font-size: 13px;
    margin-top: 8px;
    min-height: 20px;
}

/* Hidden elements */
.hidden {
    display: none !important;
}

/* Login page links */
.login-links {
    text-align: center;
    margin-top: 16px;
    font-size: 14px;
}

.login-links a {
    color: var(--color-link);
    text-decoration: none;
}

.login-links a:hover {
    text-decoration: underline;
}

/* Success hint */
.success-hint {
    color: var(--color-success);
    font-size: 14px;
    margin-top: 8px;
    text-align: center;
}

/* Small button variant */
.btn-small {
    width: auto;
    padding: 6px 16px;
    font-size: 14px;
}

/* Avatar base class - shared properties for all avatar elements */
.avatar-base {
    background-color: var(--color-primary);
    color: var(--color-bg);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    background-size: cover;
    background-position: center;
    flex-shrink: 0;
}

/* ==========================================
   Main App Layout
   ========================================== */

html.app-html {
    height: 100%;
    overflow: hidden;
    overscroll-behavior: none;
}

body.app-body {
    padding: 0;
    display: block;
    background-color: var(--color-bg-hover);
    height: 100%;
    height: var(--app-height, 100%);
    overflow: hidden;
    overscroll-behavior: none;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
}

/* Allow text selection in input fields */
body.app-body .chat-input,
body.app-body .form-group input,
body.app-body .form-group textarea,
body.app-body .user-id-text {
    -webkit-touch-callout: default;
    -webkit-user-select: text;
    user-select: text;
}

/* Allow text selection in message content on non-touch devices only */
@media (pointer: fine) {
    body.app-body .message-content {
        -webkit-user-select: text;
        user-select: text;
    }
}

#account-select-view {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100%;
    padding: 20px;
}

/* Account selection */
.account-list {
    margin-bottom: 16px;
}

.account-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    border-radius: 8px;
    cursor: pointer;
    transition: background-color 0.15s;
    margin-bottom: 4px;
}

@media (hover: hover) and (pointer: fine) {
    .account-item-wrapper .account-item:hover {
        background-color: var(--color-bg-hover);
    }
}

.account-avatar {
    width: 44px;
    height: 44px;
    border-radius: 6px;
    font-size: 18px;
}

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

.account-name {
    font-size: 16px;
    font-weight: 500;
}

.account-hint {
    font-size: 12px;
    color: var(--color-text-muted);
}

/* Account item wrapper for swipe-to-delete */
.account-item-wrapper {
    position: relative;
    overflow: hidden;
    border-radius: 8px;
    margin-bottom: 4px;
}

.account-item-wrapper .account-item {
    position: relative;
    z-index: 1;
    background: var(--color-bg);
    margin-bottom: 0;
    transition: transform 0.2s ease;
    will-change: transform;
}

.account-delete-zone {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    width: 64px;
    background-color: #f87171;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}


.account-delete-zone svg {
    width: 22px;
    height: 22px;
    stroke: var(--color-bg);
    stroke-width: 1.8;
    fill: none;
    stroke-linecap: round;
    stroke-linejoin: round;
}

/* PC: hover close button */
.account-delete-btn {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    width: 24px;
    height: 24px;
    border: none;
    background: none;
    color: var(--color-text-muted);
    font-size: 16px;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.15s, color 0.15s;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    z-index: 2;
    border-radius: 4px;
}

.account-item:hover .account-delete-btn {
    opacity: 1;
}

.account-delete-btn:hover {
    color: var(--color-danger);
}

/* Avatar reminder banner */
.avatar-banner {
    background-color: #fffbeb;
    border-bottom: 1px solid #fde68a;
    padding: 8px 16px;
    font-size: 14px;
    color: #92400e;
    display: flex;
    align-items: center;
    gap: 4px;
}

.avatar-banner a {
    color: var(--color-link);
    text-decoration: none;
    cursor: pointer;
}

.avatar-banner-close {
    margin-left: auto;
    background: none;
    border: none;
    font-size: 18px;
    cursor: pointer;
    color: #92400e;
    padding: 0 4px;
}


/* Top bar */
.top-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 16px;
    background-color: var(--color-bg);
    border-bottom: 1px solid var(--color-border);
    height: 52px;
}


.top-bar-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.icon-btn {
    background: none;
    border: none;
    font-size: 20px;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
    color: #555;
    -webkit-tap-highlight-color: transparent;
}

.icon-btn:hover {
    background-color: #f0f0f0;
}

.avatar-btn {
    padding: 2px;
}

.top-bar-avatar {
    width: 32px;
    height: 32px;
    border-radius: 6px;
    font-size: 14px;
}

/* User menu */
.user-menu-wrapper {
    position: relative;
    display: flex;
}

:is(.user-menu, .plus-menu) {
    position: absolute;
    top: 40px;
    right: 0;
    background: var(--color-bg);
    border-radius: 8px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
    z-index: 100;
    overflow: hidden;
}

.user-menu { min-width: 160px; }
.plus-menu { min-width: 140px; }

:is(.user-menu-item, .plus-menu-item) {
    padding: 10px 16px;
    font-size: 14px;
    cursor: pointer;
    transition: background-color 0.15s;
}

:is(.user-menu-item, .plus-menu-item):hover {
    background-color: var(--color-bg-hover);
}

.user-menu-item.danger {
    color: var(--color-danger);
}

/* Plus menu (+ button dropdown) */
.plus-menu-wrapper {
    position: relative;
    display: flex;
}

/* Select friend list */
.select-friend-list {
    padding: 8px 0;
}

.select-friend-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 16px;
    cursor: pointer;
    transition: background-color 0.15s;
}

@media (hover: hover) and (pointer: fine) {
    .select-friend-item:hover {
        background-color: var(--color-bg-hover);
    }
}

.select-friend-item:active {
    background-color: #ebebeb;
}

.select-friend-avatar {
    width: 40px;
    height: 40px;
    border-radius: 6px;
    font-size: 16px;
}

.select-friend-name {
    font-size: 15px;
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

#main-app-view {
    display: flex;
    flex-direction: column;
    height: 100%;
}

/* App content layout */
.app-content {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* Contact panel */
.contact-panel {
    width: 320px;
    border-right: 1px solid var(--color-border);
    background-color: var(--color-bg);
    overflow-y: auto;
    flex-shrink: 0;
}

.friend-requests-entry {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    cursor: pointer;
    border-bottom: 1px solid #f0f0f0;
    font-size: 14px;
    color: #555;
}

.friend-requests-entry:hover {
    background-color: var(--color-bg-secondary);
}

.badge {
    background-color: #ef4444;
    color: var(--color-bg);
    font-size: 12px;
    padding: 2px 8px;
    border-radius: 10px;
    font-weight: 600;
}

.contact-list {
    /* Scrolls with parent */
}

/* Contact item wrapper for swipe-to-hide */
.contact-item-wrapper {
    position: relative;
    overflow: hidden;
}

.contact-item-wrapper .contact-item,
.contact-item-wrapper .contact-item:hover {
    position: relative;
    z-index: 1;
    background-color: var(--color-bg);
    transition: transform 0.2s ease;
    will-change: transform;
}

.contact-item-wrapper .contact-item:active,
.contact-item-wrapper .contact-item.active {
    position: relative;
    z-index: 1;
    background-color: #f0f0f0;
    transition: transform 0.2s ease;
    will-change: transform;
}

.contact-delete-zone {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    width: 64px;
    background-color: #fb923c;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}


.contact-delete-zone svg {
    width: 22px;
    height: 22px;
    stroke: var(--color-bg);
    stroke-width: 1.8;
    fill: none;
    stroke-linecap: round;
    stroke-linejoin: round;
}


.contact-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    cursor: pointer;
    transition: background-color 0.15s;
    border-bottom: 1px solid var(--color-bg-hover);
}

.contact-item:hover {
    background-color: var(--color-bg-secondary);
}

.contact-item.active {
    background-color: #e8f0fe;
}

.contact-avatar {
    width: 44px;
    height: 44px;
    border-radius: 6px;
    font-size: 18px;
}

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

.contact-top-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.contact-name {
    font-size: 15px;
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.contact-time {
    font-size: 12px;
    color: var(--color-text-muted);
    flex-shrink: 0;
    margin-left: 8px;
}

.contact-bottom-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 2px;
}

.contact-read-tag {
    font-size: 12px;
    flex-shrink: 0;
    margin-right: 4px;
}

.contact-read-tag-unread {
    color: var(--color-link);
}

.contact-read-tag-read {
    color: var(--color-text-muted);
}

.contact-draft-tag {
    font-size: 12px;
    flex-shrink: 0;
    margin-right: 4px;
    color: #e67e22;
}

.contact-preview {
    font-size: 13px;
    color: var(--color-text-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
}

.unread-badge {
    background-color: #ef4444;
    color: var(--color-bg);
    font-size: 11px;
    padding: 1px 6px;
    border-radius: 10px;
    font-weight: 600;
    flex-shrink: 0;
    margin-left: 8px;
}

.contact-empty {
    padding: 40px 16px;
    text-align: center;
    color: var(--color-text-muted);
    font-size: 14px;
}

.contact-empty .hint {
    font-size: 12px;
    margin-top: 8px;
}

/* Detail panel */
.detail-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    background-color: var(--color-bg-secondary);
    overflow: hidden;
}

.detail-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--color-text-muted);
    font-size: 16px;
}

/* Chat view */

.chat-view {
    display: flex;
    flex-direction: column;
    height: 100%;
}

.chat-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 16px;
    background-color: var(--color-bg);
    border-bottom: 1px solid var(--color-border);
}

.chat-header-name {
    font-size: 16px;
    font-weight: 500;
}

.back-btn {
    display: none;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    overscroll-behavior: contain;
}

/* Message row: avatar + bubble column */
.message-row {
    display: flex;
    gap: 8px;
}

.message-row-mine {
    flex-direction: row;
    justify-content: flex-end;
}

.message-row-other {
    flex-direction: row;
}

.message-avatar {
    width: 44px;
    height: 44px;
    border-radius: 6px;
    font-size: 18px;
}

.message-col {
    display: flex;
    flex-direction: column;
    min-width: 0;
    max-width: calc(100% - 182px);
    position: relative;
}

.has-touch .message-col {
    max-width: calc(100% - 104px);
}

.message-row-mine .message-col {
    align-items: flex-end;
}

.message-row-other .message-col {
    align-items: flex-start;
}

.message-bubble {
    padding: 10px 14px;
    border-radius: 12px;
    word-wrap: break-word;
    position: relative;
    min-width: 4em;
}

.message-row-mine .message-bubble {
    background-color: var(--color-primary);
    color: var(--color-bg);
    border-top-right-radius: 4px;
}

.message-row-other .message-bubble {
    background-color: var(--color-bg);
    border: 1px solid var(--color-border);
    border-top-left-radius: 4px;
}

.message-content {
    font-size: 15px;
    line-height: 1.5;
    word-break: break-word;
    overflow-wrap: break-word;
}

.message-content a {
    color: #1a73e8;
    text-decoration: underline;
    word-break: break-all;
}

.message-row-mine .message-content a {
    color: #e0edff;
}

.message-image {
    display: block;
    cursor: pointer;
}

.message-bubble-image.message-bubble-image-expired {
    background-color: #e8e8e8 !important;
}

.message-image-expired-label {
    display: flex;
    align-items: center;
    justify-content: center;
    color: #999;
    font-size: 13px;
}

.message-meta {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 2px;
    padding: 0 4px;
}

.message-time {
    font-size: 11px;
    color: var(--color-text-muted);
}

.message-status {
    font-size: 11px;
}

.message-status-unread {
    color: var(--color-link);
}

.message-status-read {
    color: var(--color-text-muted);
}

.message-system {
    text-align: center;
    color: var(--color-text-muted);
    font-size: 12px;
    padding: 4px 0;
}

/* New message hint */
.new-message-hint {
    text-align: center;
    padding: 6px 16px;
    background-color: rgba(74, 141, 232, 0.15);
    color: var(--color-link);
    font-size: 13px;
    cursor: pointer;
    flex-shrink: 0;
}

/* Chat resize handle (desktop only) */
.chat-resize-handle {
    height: 6px;
    background-color: var(--color-bg);
    border-top: 1px solid var(--color-border);
    cursor: ns-resize;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.chat-resize-handle::after {
    content: "";
    width: 32px;
    height: 3px;
    background-color: var(--color-border-light);
    border-radius: 2px;
}

/* Chat input */
.chat-input-area {
    display: flex;
    gap: 8px;
    padding: 12px 16px;
    background-color: var(--color-bg);
    flex-shrink: 0;
    height: 120px;
    overscroll-behavior: none;
}

.chat-input {
    flex: 1;
    padding: 10px 12px;
    border: 1px solid #ddd;
    border-radius: 12px;
    font-size: 14px;
    font-family: inherit;
    line-height: 1.5;
    outline: none;
    resize: none;
    height: 100%;
    overflow-y: auto;
}

.chat-input:focus {
    border-color: var(--color-primary);
}

.chat-btn-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
    align-self: stretch;
    justify-content: flex-end;
}

.chat-plus-btn {
    width: auto;
    padding: 8px 16px;
    border-radius: 12px;
    background-color: var(--color-bg);
    color: var(--color-text-muted);
    border: 1px solid var(--color-border-light);
}

.chat-newline-btn {
    width: auto;
    padding: 8px 16px;
    border-radius: 12px;
    background-color: var(--color-bg);
    color: var(--color-text-muted);
    border: 1px solid var(--color-border-light);
}

.chat-send-btn {
    width: auto;
    padding: 8px 20px;
    border-radius: 12px;
}

.chat-readonly-hint {
    padding: 12px 16px;
    text-align: center;
    color: var(--color-text-muted);
    font-size: 14px;
    background-color: var(--color-bg);
    flex-shrink: 0;
    border-top: 1px solid var(--color-border);
}

/* Search bar */
.search-bar {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
}

.search-bar input {
    flex: 1;
    padding: 10px 12px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
    transition: border-color 0.2s;
}

.search-bar input:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 2px rgba(74, 144, 217, 0.2);
}

/* Search results list */
.search-results {
    /* Container for search result items */
}

.search-result-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    border-radius: 8px;
    cursor: pointer;
    transition: background-color 0.15s;
    border-bottom: 1px solid #f0f0f0;
}

.search-result-item:hover {
    background-color: var(--color-bg-hover);
}

.search-result-avatar {
    width: 44px;
    height: 44px;
    border-radius: 6px;
    font-size: 18px;
}

.search-result-info {
    flex: 1;
    min-width: 0;
}

.search-result-name {
    font-size: 15px;
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.search-result-id {
    font-size: 12px;
    color: var(--color-text-muted);
}

/* Sub-views (add friend, friend requests, profile) */
.sub-view {
    display: flex;
    flex-direction: column;
    height: 100%;
}

.sub-view-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 16px;
    background-color: var(--color-bg);
    border-bottom: 1px solid var(--color-border);
    font-size: 16px;
    font-weight: 500;
}

.sub-view-content {
    padding: 24px 16px;
    overflow-y: auto;
    flex: 1;
}

/* Friend request list */
.friend-requests-list {
    overflow-y: auto;
    flex: 1;
}

.request-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    border-bottom: 1px solid #f0f0f0;
    cursor: pointer;
    transition: background-color 0.15s;
}

.request-item:hover {
    background-color: var(--color-bg-secondary);
}

.request-avatar {
    width: 44px;
    height: 44px;
    border-radius: 6px;
    font-size: 18px;
}

.request-name {
    font-size: 15px;
    font-weight: 500;
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.request-actions {
    display: flex;
    gap: 8px;
}

.request-actions .btn {
    margin-top: 0;
}

/* Profile */
.profile-avatar-section {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    margin-bottom: 24px;
}

.profile-avatar {
    width: 80px;
    height: 80px;
    border-radius: 10px;
    font-size: 32px;
}

.form-group textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
    font-family: inherit;
    resize: none;
    transition: border-color 0.2s;
}

.form-group textarea:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 2px rgba(74, 144, 217, 0.2);
}

/* Detail modal backdrop (desktop) */
.detail-modal-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.4);
    z-index: 150;
    opacity: 1;
    transition: opacity 200ms ease-in-out;
}

.detail-modal-backdrop.backdrop-enter {
    opacity: 0;
}

.detail-modal-backdrop.backdrop-exit {
    opacity: 0;
}

/* Desktop modal mode for profile and friend detail views */
.sub-view.desktop-modal {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 400px;
    max-height: 80vh;
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
    z-index: 160;
    background-color: var(--color-bg-secondary);
    overflow: hidden;
    opacity: 1;
    transition: opacity 200ms ease-in-out, transform 200ms ease-in-out;
}

.sub-view.desktop-modal.modal-enter {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.95);
}

.sub-view.desktop-modal.modal-exit {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.95);
}

.sub-view.desktop-modal .back-btn {
    display: none;
}

/* Chat header detail button */
.chat-detail-btn {
    margin-left: auto;
    font-size: 18px;
}

/* Friend detail view */
.friend-detail-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding-top: 40px;
}

.friend-detail-avatar {
    width: 80px;
    height: 80px;
    border-radius: 10px;
    font-size: 32px;
    margin-bottom: 16px;
}

.friend-detail-nickname {
    font-size: 20px;
    font-weight: 600;
    color: #222;
    margin-bottom: 4px;
}

/* User ID display (profile, friend detail, request detail) */
.profile-user-id {
    font-size: 12px;
    color: var(--color-text-muted);
    text-align: center;
    margin-bottom: 8px;
}

.friend-detail-bio {
    font-size: 14px;
    color: var(--color-text-secondary);
    margin-bottom: 32px;
    text-align: center;
    max-width: 280px;
    word-break: break-word;
}

.friend-detail-actions {
    width: 100%;
    max-width: 280px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.non-friend-hint {
    text-align: center;
    color: var(--color-text-muted);
    font-size: 14px;
    margin-bottom: 8px;
}

/* Danger button */
.btn-danger {
    background-color: var(--color-bg);
    color: var(--color-danger);
    border: 1px solid var(--color-danger);
}

.btn-danger:hover:not(:disabled) {
    background-color: #fef2f2;
}

/* Contact list non-friend label */
.contact-non-friend-tag {
    font-size: 11px;
    color: var(--color-text-muted);
    margin-left: 6px;
    flex-shrink: 0;
}

/* Confirmation modal */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
}

.modal-dialog {
    background: var(--color-bg);
    border-radius: 12px;
    padding: 24px;
    width: 320px;
    max-width: 90%;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
}

.modal-title {
    font-size: 16px;
    font-weight: 500;
    color: var(--color-text);
    margin-bottom: 16px;
    line-height: 1.5;
}

.modal-checkbox-area {
    margin-bottom: 16px;
}

.modal-checkbox-label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    color: #555;
    cursor: pointer;
}

.modal-checkbox-label input[type="checkbox"] {
    width: 16px;
    height: 16px;
    cursor: pointer;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

.modal-actions .btn {
    width: auto;
    min-width: 80px;
    margin-top: 0;
    padding: 8px 16px;
    font-size: 14px;
}

/* ==========================================
   Responsive: Mobile (< 768px)
   ========================================== */

@media (max-width: 767px) {
    /* Slide top bar and avatar banner together with contact panel */
    .top-bar,
    .avatar-banner {
        transition: transform 250ms ease-in-out;
    }

    #main-app-view:has(.contact-panel.slide-offscreen-left) > .top-bar,
    #main-app-view:has(.contact-panel.slide-offscreen-left) > .avatar-banner {
        transform: translateX(-100%);
    }

    /* On mobile, show the chat-specific bar (in-flow between chat-header and messages) */
    .connection-status-bar-chat {
        display: flex;
    }

    /* On mobile chat view, hide main bar (behind detail-panel) */
    #main-app-view:has(.contact-panel.slide-offscreen-left) > .connection-status-bar {
        max-height: 0 !important;
        padding: 0 16px !important;
    }


    #main-app-view {
        position: relative;
        overflow: hidden;
    }

    .contact-panel {
        width: 100%;
        border-right: none;
        overflow-y: auto;
        transition: transform 250ms ease-in-out;
        transform: translateX(0);
    }

    .detail-panel {
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 10;
        display: flex;
        transform: translateX(100%);
        transition: transform 250ms ease-in-out;
    }

    .detail-panel.mobile-visible {
        transform: translateX(0);
    }

    /* Slide animation classes */
    .contact-panel.slide-offscreen-left {
        transform: translateX(-100%);
    }

    .slide-offscreen-right {
        transform: translateX(100%) !important;
    }

    /* Sub-view transition support - absolute positioning for overlap during transitions */
    .sub-view {
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background-color: var(--color-bg-secondary);
        transition: transform 250ms ease-in-out;
    }

    .sub-view.slide-partial-left {
        transform: translateX(-30%);
    }

    .sub-view.slide-enter-right {
        transform: translateX(100%);
    }

    .detail-panel .detail-placeholder {
        display: none;
    }

    .back-btn {
        display: inline-flex;
    }

    .back-btn:hover,
    .icon-btn:hover {
        background-color: transparent;
    }

    .chat-detail-btn {
        display: inline-flex;
    }

    body.app-body .app-content {
        position: static;
    }

    .contact-empty {
        padding: 60px 24px;
    }

    .chat-resize-handle {
        display: none;
    }

    .chat-input-area {
        height: auto;
        padding-bottom: calc(env(safe-area-inset-bottom, 32px) + 32px);
        margin-bottom: 0;
    }

    .chat-input {
        height: auto;
        padding-top: 9px;
        padding-bottom: 9px;
    }

    .chat-btn-group {
        flex-direction: row;
        align-self: flex-end;
    }

    .chat-send-btn {
        display: none;
    }

    .btn.chat-plus-btn {
        padding: 9px 16px;
    }

    .btn.chat-newline-btn {
        padding: 9px 16px;
    }

    .contact-item:hover {
        background-color: transparent;
    }

    .contact-item:active,
    .contact-item.active {
        background-color: #f0f0f0;
    }
}

/* Connection status bar */
.connection-status-bar {
    background-color: #8a8a8a;
    color: #fff;
    text-align: center;
    font-size: 13px;
    line-height: 1;
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease, padding 0.3s ease, background-color 0.3s ease;
    padding: 0 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

.connection-status-bar.visible {
    max-height: 40px;
    padding: 8px 16px;
}

.connection-status-bar.recovered {
    background-color: #4caf50;
}

.connection-spinner {
    display: inline-block;
    width: 12px;
    height: 12px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: none;
    flex-shrink: 0;
}

.connection-status-bar.visible .connection-spinner {
    animation: conn-spin 0.8s linear infinite;
}

.connection-status-bar.recovered .connection-spinner {
    display: none;
}

/* Hide chat-specific connection bar on desktop (main bar is sufficient) */
@media (min-width: 768px) {
    .connection-status-bar-chat {
        display: none;
    }
}

@keyframes conn-spin {
    to { transform: rotate(360deg); }
}

.toast {
    position: fixed;
    top: calc(var(--app-height) - 140px);
    left: 50%;
    transform: translateX(-50%);
    background-color: rgba(0, 0, 0, 0.75);
    color: var(--color-bg);
    padding: 10px 24px;
    border-radius: 20px;
    font-size: 14px;
    z-index: 300;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.3s;
}

.toast.visible {
    opacity: 1;
}

/* PWA install gate overlay */
.pwa-install-gate {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, rgba(116, 200, 255, 0.32), rgba(247, 166, 199, 0.25) 45%, rgba(249, 210, 106, 0.2));
    background-color: var(--color-bg);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 600;
    text-align: center;
    padding: 20px;
    box-sizing: border-box;
}

@media (display-mode: standalone) {
    .pwa-install-gate {
        display: none !important;
    }
}

.pwa-gate-content {
    max-width: 360px;
    width: 100%;
}

.pwa-gate-logo {
    height: 64px;
    margin-bottom: 16px;
}

.pwa-gate-title {
    font-size: 20px;
    font-weight: 600;
    color: var(--color-text);
    margin: 0 0 8px;
}

.pwa-gate-subtitle {
    font-size: 14px;
    color: #888;
    margin: 0 0 24px;
    line-height: 1.5;
}

.pwa-gate-guide {
    margin-bottom: 24px;
}

.pwa-gate-install-btn {
    display: inline-block;
    width: 100%;
    padding: 14px;
    font-size: 16px;
    font-weight: 600;
    color: var(--color-bg);
    background-color: var(--color-primary);
    border: none;
    border-radius: 8px;
    cursor: pointer;
    margin-bottom: 16px;
    transition: background-color 0.2s;
}

.pwa-gate-install-btn:active {
    background-color: #3a7dd8;
}

.pwa-gate-skip {
    display: block;
    font-size: 13px;
    color: var(--color-text-muted);
    text-decoration: underline;
    cursor: pointer;
    border: none;
    background: none;
    margin: 0 auto;
    padding: 8px;
}

.pwa-gate-skip:active {
    color: var(--color-text-secondary);
}

.pwa-gate-success {
    color: var(--color-primary);
    font-size: 48px;
    margin-bottom: 16px;
}

/* Safari install guide (iOS & macOS) */
.pwa-safari-steps {
    text-align: left;
    margin: 0 auto 16px;
    max-width: 280px;
}

.pwa-safari-step {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
    font-size: 14px;
    color: #555;
    line-height: 1.4;
}

.pwa-safari-step-icon {
    flex-shrink: 0;
    width: 32px;
    height: 32px;
}

.pwa-safari-step-icon svg {
    width: 100%;
    height: 100%;
}

/* Splash screen */
.splash-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, rgba(116, 200, 255, 0.32), rgba(247, 166, 199, 0.25) 45%, rgba(249, 210, 106, 0.2));
    background-color: var(--color-bg);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 500;
    opacity: 1;
    transition: opacity 0.4s ease-out;
}

.splash-screen.splash-fade-out {
    opacity: 0;
}

.splash-logo {
    height: 72px;
}

/* Avatar lightbox */
.avatar-lightbox {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.85);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 250;
    cursor: pointer;
}

.avatar-lightbox-img {
    width: min(65vw, 65vh);
    height: min(65vw, 65vh);
    max-width: 65vw;
    max-height: 65vh;
    border-radius: 8px;
    will-change: transform;
    object-fit: contain;
    -webkit-touch-callout: default;
}

/* Message context menu (long-press on touch) */
.msg-context-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 300;
}

.msg-context-menu {
    position: fixed;
    display: flex;
    flex-direction: row;
    background: var(--color-bg);
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.18);
    padding: 4px 0;
    z-index: 301;
}

.msg-context-item {
    padding: 10px 20px;
    font-size: 15px;
    color: var(--color-text);
    cursor: pointer;
    white-space: nowrap;
}

.msg-context-item:active {
    background-color: #f0f0f0;
}

.message-row-mine .msg-bubble-selected {
    background-color: #3a7ad4;
}

.message-row-other .msg-bubble-selected {
    background-color: #e8e8e8;
}

/* ==========================================
   Responsive: Desktop panel overrides (>= 768px)
   Ensure mobile transitions/transforms don't affect desktop layout
   ========================================== */

@media (min-width: 768px) {
    .contact-panel,
    .detail-panel {
        transform: none !important;
        transition: none !important;
    }
}

/* ==========================================
   Responsive: Registration/Login pages (< 480px)
   ========================================== */

/* Responsive design for mobile */
@media (max-width: 480px) {
    body {
        padding: 0;
        align-items: flex-start;
    }

    .card {
        max-width: 100%;
        border-radius: 0;
        box-shadow: none;
        padding: 24px 16px;
        min-height: 100vh;
        min-height: 100dvh;
    }

    .card h1 {
        font-size: 20px;
    }

    .steps {
        gap: 8px;
        margin-bottom: 20px;
    }

    .step {
        font-size: 13px;
    }

    .step-divider {
        width: 20px;
    }

    .form-group input {
        font-size: 16px;
        padding: 12px;
    }

    .btn {
        font-size: 16px;
        padding: 14px;
    }
}

/* ========================================
   Reply feature styles
   ======================================== */

/* Reply preview bar (above input area) */
.reply-preview-bar {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    padding: 8px 14px;
    background-color: var(--color-bg-hover);
    border-bottom: 1px solid var(--color-border);
}

.reply-preview-bar.hidden {
    display: none;
}

.reply-preview-indicator {
    flex: 1;
    min-width: 0;
    border-left: 2px solid var(--color-primary);
    padding-left: 8px;
}

.reply-preview-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--color-text);
    line-height: 1.3;
}

.reply-preview-text {
    font-size: 13px;
    color: #888;
    line-height: 1.3;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.reply-preview-close {
    background: none;
    border: none;
    font-size: 18px;
    color: var(--color-text-muted);
    cursor: pointer;
    padding: 0 4px;
    line-height: 1;
    flex-shrink: 0;
}

.reply-preview-close:hover {
    color: var(--color-text);
}

/* Reply quote area inside message bubble */
.reply-quote {
    border-left: 2px solid var(--color-border-light);
    padding: 4px 8px;
    margin-bottom: 6px;
    cursor: pointer;
    border-radius: 2px;
}

.message-row-mine .reply-quote {
    border-left-color: rgba(255, 255, 255, 0.4);
}

.reply-quote-name {
    font-size: 13px;
    font-weight: 600;
    line-height: 1.3;
}

.message-row-other .reply-quote-name {
    color: #555;
}

.message-row-mine .reply-quote-name {
    color: rgba(255, 255, 255, 0.85);
}

.reply-quote-text {
    font-size: 13px;
    line-height: 1.3;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.message-row-other .reply-quote-text {
    color: #888;
}

.message-row-mine .reply-quote-text {
    color: rgba(255, 255, 255, 0.65);
}

/* When quote contains an image thumb, disable text truncation layout */
.reply-quote-text:has(.reply-quote-thumb) {
    display: block;
    -webkit-line-clamp: unset;
    overflow: visible;
}

/* Message highlight animation (jump target) */
@keyframes message-highlight-fade {
    0% { background-color: rgba(255, 220, 100, 0.4); }
    100% { background-color: transparent; }
}

@keyframes message-highlight-fade-mine {
    0% { background-color: #2e9e5e; }
    100% { background-color: #5a9de6; }
}

.message-highlight {
    animation: message-highlight-fade 1.5s ease-out;
}

.message-row-mine .message-highlight {
    animation: message-highlight-fade-mine 1.5s ease-out;
}

/* Hover action bar (desktop) */
.msg-action-bar {
    display: none;
    position: absolute;
    align-items: center;
    gap: 2px;
    z-index: 10;
    bottom: 0;
}

.message-row:hover .msg-action-bar {
    display: flex;
}

.has-touch .msg-action-bar {
    display: none !important;
}

.message-row-other .msg-action-bar {
    left: 100%;
    margin-left: 2px;
}

.message-row-mine .msg-action-bar {
    right: 100%;
    margin-right: 2px;
}

.msg-action-btn {
    background: none;
    border: none;
    padding: 4px 6px;
    cursor: pointer;
    font-size: 13px;
    color: var(--color-text-muted);
    border-radius: 4px;
    white-space: nowrap;
    line-height: 1;
}

.msg-action-btn:hover {
    background-color: rgba(0, 0, 0, 0.06);
    color: #555;
}

/* Image send modal */
.image-send-modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 900;
    display: flex;
    align-items: center;
    justify-content: center;
}

.image-send-modal-content {
    background: white;
    border-radius: 12px;
    padding: 24px;
    text-align: center;
    max-width: 300px;
    width: 80%;
}

.image-send-modal-preview {
    max-width: 200px;
    max-height: 200px;
    border-radius: 8px;
    object-fit: contain;
    margin-bottom: 16px;
}

.image-send-modal-status {
    color: var(--color-text-secondary);
    margin-bottom: 16px;
    font-size: 14px;
}

.image-send-modal-error {
    color: #dc3545;
    margin-bottom: 16px;
    font-size: 14px;
}

.image-send-modal-actions {
    display: flex;
    gap: 12px;
    justify-content: center;
    align-items: stretch;
}

.image-send-modal-actions .btn {
    border: 1px solid transparent;
    margin-top: 0;
}

.image-send-modal-actions .btn-secondary {
    border-color: var(--color-primary);
}

/* Chat plus button menu (image selection) */
.chat-plus-menu {
    position: absolute;
    bottom: 100%;
    right: 0;
    margin-bottom: 8px;
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.15);
    z-index: 100;
    min-width: 120px;
    overflow: hidden;
}

.chat-plus-menu-item {
    padding: 10px 16px;
    cursor: pointer;
    font-size: 14px;
    white-space: nowrap;
}

.chat-plus-menu-item:hover {
    background-color: #f0f0f0;
}

.chat-plus-menu-item:active {
    background-color: #e0e0e0;
}

/* Image viewer overlay */
.image-viewer-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.9);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.image-viewer-close {
    position: absolute;
    top: 16px;
    right: 16px;
    color: white;
    font-size: 28px;
    cursor: pointer;
    background: none;
    border: none;
    line-height: 1;
    padding: 8px;
    z-index: 1001;
}

.image-viewer-close:hover {
    opacity: 0.8;
}

.image-viewer-frame {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    border: none;
    background: transparent;
    transform-origin: center center;
}

/* Image bubble: no padding, image fills bubble edge-to-edge */
.message-bubble-image {
    padding: 0 !important;
    background-color: var(--color-bg) !important;
    border: 1px solid var(--color-border-light) !important;
    border-radius: 12px !important;
}

.message-bubble-image .message-image {
    border-radius: 11px;
}

.message-bubble-image .message-meta {
    padding: 2px 8px 4px;
}

.message-bubble-image .reply-quote {
    margin: 8px 8px 0;
}

.message-image-crop {
    object-fit: cover;
    object-position: top left;
}

.message-bubble-image .message-content {
    position: relative;
}

.message-image-tag {
    position: absolute;
    right: 6px;
    bottom: 6px;
    font-size: 11px;
    line-height: 1;
    padding: 2px 6px;
    border-radius: 4px;
    background: rgba(0, 0, 0, 0.45);
    color: var(--color-bg);
    pointer-events: none;
}

/* Reply preview bar thumbnail */
.reply-preview-thumb {
    max-height: 40px;
    border-radius: 4px;
    object-fit: contain;
}

/* Quote area thumbnail */
.reply-quote-thumb {
    border-radius: 4px;
    display: block;
    margin-top: 4px;
    margin-right: auto;
}

.reply-quote-thumb-expired {
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: #e8e8e8;
    border-radius: 4px;
    color: #999;
    font-size: 11px;
    margin-top: 4px;
}

