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

html,
body {
    height: 100%;
    overflow: hidden;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: #f0f2f5;
    color: #333;
    height: 100dvh;
    display: flex;
    justify-content: center;
    align-items: center;
}

.home-entry {
    position: fixed;
    top: max(12px, env(safe-area-inset-top));
    left: max(12px, env(safe-area-inset-left));
    z-index: 500;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    border-radius: 999px;
    border: 1px solid #dbe2ea;
    background: rgba(255, 255, 255, 0.95);
    box-shadow: 0 4px 14px rgba(15, 23, 42, 0.12);
    color: #0f172a;
    font-size: 0.88rem;
    font-weight: 600;
    line-height: 1;
    text-decoration: none;
    transition: transform 0.16s ease, box-shadow 0.16s ease, background-color 0.16s ease;
}

/* 聊天页面隐藏返回主页悬浮入口，避免遮挡聊天头部 */
body.chat-active .home-entry {
    display: none;
}

.home-entry:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 18px rgba(15, 23, 42, 0.16);
    background: #fff;
}

.home-entry img {
    width: 18px;
    height: 18px;
    display: block;
}

#app {
    width: 100%;
    max-width: 1000px;
    height: min(90vh, 900px);
    max-height: 100dvh;
    background: white;
    box-shadow: 0 10px 30px rgba(0,0,0,0.1);
    border-radius: 12px;
    overflow: hidden;
    display: flex;
}

.screen {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
}

.hidden {
    display: none !important;
}

/* 连接前界面样式 */
#connection-setup {
    padding: 40px;
    align-items: center;
    justify-content: flex-start;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.header {
    text-align: center;
    margin-bottom: 30px;
}

.header h1 {
    font-size: 2.5rem;
    color: #007bff;
    margin-bottom: 10px;
}

.usage-seo {
    margin: 0 auto 12px;
    max-width: 600px;
    color: #475569;
    font-size: 0.95rem;
    line-height: 1.45;
}

.usage-help {
    text-align: left;
    margin: 0 auto;
    max-width: 600px;
    padding: 10px 12px;
    border-radius: 8px;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
}

.usage-title {
    font-size: 0.92rem;
    font-weight: 600;
    color: #334155;
    margin-bottom: 6px;
}

.usage-list {
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
    color: #475569;
    font-size: 0.9rem;
    line-height: 1.45;
}

.usage-item {
    margin: 0;
}

.usage-url {
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
    color: #1d4ed8;
    word-break: break-all;
}

.usage-divider {
    position: relative;
    margin: 2px 0;
    text-align: center;
    color: #64748b;
    font-weight: 600;
    letter-spacing: 0.08em;
}

.usage-divider::before,
.usage-divider::after {
    content: "";
    position: absolute;
    top: 50%;
    width: calc(50% - 1.8em);
    border-top: 1px solid #cbd5e1;
}

.usage-divider::before {
    left: 0;
}

.usage-divider::after {
    right: 0;
}

.content {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    max-width: 400px;
    --connector-box-size: 300px;
    --connector-box-padding: 20px;
}

.toggle-content {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
}

#qrcode {
    width: var(--connector-box-size);
    height: var(--connector-box-size);
    padding: var(--connector-box-padding);
    background: white;
    border: 1px solid #ddd;
    border-radius: 8px;
    cursor: zoom-in;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: border-color 160ms ease, box-shadow 160ms ease, background-color 160ms ease;
}

#qrcode canvas,
#qrcode img {
    width: 100% !important;
    height: 100% !important;
    display: block;
}

#reader {
    width: 100%;
    max-width: 100%;
    border: 1px solid #ddd;
    min-height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #111;
    overflow: hidden;
}

#reader video {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.scanner-shell {
    position: relative;
    width: var(--connector-box-size);
    height: var(--connector-box-size);
    border-radius: 10px;
    overflow: hidden;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.2);
    transition: box-shadow 160ms ease, transform 160ms ease;
}

.scanner-overlay {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 2;
    transition: background-color 160ms ease;
}

.scanner-overlay .corner {
    position: absolute;
    width: 30px;
    height: 30px;
    border-color: #22c55e;
    border-style: solid;
    border-width: 0;
}

.scanner-overlay .corner.tl {
    top: 8px;
    left: 8px;
    border-top-width: 4px;
    border-left-width: 4px;
}

.scanner-overlay .corner.tr {
    top: 8px;
    right: 8px;
    border-top-width: 4px;
    border-right-width: 4px;
}

.scanner-overlay .corner.bl {
    bottom: 8px;
    left: 8px;
    border-bottom-width: 4px;
    border-left-width: 4px;
}

.scanner-overlay .corner.br {
    bottom: 8px;
    right: 8px;
    border-bottom-width: 4px;
    border-right-width: 4px;
}

.scan-line {
    position: absolute;
    left: 10px;
    right: 10px;
    top: 10px;
    height: 2px;
    border-radius: 2px;
    background: linear-gradient(90deg, transparent, #22c55e, transparent);
    box-shadow: 0 0 10px #22c55e;
    opacity: 0;
}

.scanner-shell.scanning .scan-line {
    opacity: 1;
    animation: scan-move 1.9s linear infinite;
}

.scanner-shell.scan-success {
    box-shadow: 0 0 0 4px rgba(34, 197, 94, 0.6), 0 6px 22px rgba(22, 163, 74, 0.4);
}

.scanner-shell.scan-success #reader {
    border-color: #22c55e;
    background: #10371f;
}

.scanner-shell.scan-success .scanner-overlay {
    background: rgba(34, 197, 94, 0.18);
}

.scanner-shell.scan-success .scanner-overlay .corner {
    border-color: #86efac;
}

.scanner-shell.scan-success .scan-line {
    opacity: 0;
    animation: none;
}

#qr-container.scan-success #qrcode {
    border-color: #22c55e;
    box-shadow: 0 0 0 4px rgba(34, 197, 94, 0.2);
    background-color: #f0fdf4;
}

@keyframes scan-move {
    0% { top: 12px; }
    50% { top: calc(100% - 14px); }
    100% { top: 12px; }
}

.hint {
    margin-top: 15px;
    color: #666;
    font-size: 0.9rem;
}

.controls {
    margin: 20px 0;
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.user-info {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 10px;
}

.user-info input {
    flex: 1;
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 4px;
}

.status-text {
    margin-top: 14px;
    font-size: 0.92rem;
    color: #495057;
    min-height: 1.3em;
    text-align: center;
}

/* 聊天界面样式 */
#chat-interface {
    flex-direction: row;
    position: relative;
}

.sidebar {
    width: 260px;
    border-right: 1px solid #eee;
    background: #f8f9fa;
    display: flex;
    flex-direction: column;
}

.sidebar-header {
    padding: 20px;
    border-bottom: 1px solid #eee;
}

.sidebar-header-main {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.settings-toggle {
    min-width: 36px;
    height: 36px;
    padding: 0;
    border-radius: 8px;
    font-size: 20px;
    line-height: 1;
}

.sidebar-settings {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px dashed #d1d5db;
}

.setting-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 0.92rem;
    color: #374151;
}

.setting-row + .setting-row {
    margin-top: 10px;
}

.setting-row input[type="checkbox"] {
    width: 18px;
    height: 18px;
}

.setting-number {
    width: 92px;
    padding: 4px 6px;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    font-size: 0.85rem;
    text-align: right;
    background: #fff;
    color: #111827;
}

.setting-action {
    width: 100%;
    margin-top: 10px;
    padding: 8px 10px;
    font-size: 0.88rem;
    background: #1f2937;
    transition: background-color 140ms ease;
}

.setting-action:hover {
    background: #111827;
}

.setting-action.state-success {
    background: #15803d;
}

.setting-action.state-success:hover {
    background: #166534;
}

#session-list {
    list-style: none;
    overflow-y: auto;
}

.session-item {
    padding: 15px 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
    transition: background 0.2s;
}

.session-item:hover {
    background: #e9ecef;
}

.session-item.active {
    background: #e7f1ff;
    border-left: 4px solid #007bff;
}

.session-item.session-empty {
    cursor: default;
    color: #6b7280;
    justify-content: center;
}

.session-delete {
    margin-left: auto;
    border: none;
    background: transparent;
    color: #9ca3af;
    font-size: 0.9rem;
    padding: 2px 6px;
    cursor: pointer;
}

.session-delete:hover {
    color: #ef4444;
}

.avatar {
    width: 40px;
    height: 40px;
    background: #007bff;
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
}

.main-chat {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.chat-header {
    padding: 15px 20px;
    border-bottom: 1px solid #eee;
    display: flex;
    justify-content: flex-start;
    align-items: center;
    gap: 10px;
}

.chat-header-main {
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 4px;
    flex: 1 1 auto;
    max-width: 100%;
}

.session-toggle {
    border: none;
    background: transparent;
    color: inherit;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
    max-width: 100%;
    flex: 0 1 auto;
    text-align: left;
    padding: 4px 6px;
    border-radius: 6px;
}

.session-toggle:hover {
    background: #f3f4f6;
}

.chat-title-text {
    font-size: 1.02rem;
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat-status,
.session-status {
    font-size: 0.72rem;
    padding: 2px 6px;
    border-radius: 999px;
    color: #fff;
    background: #6b7280;
    position: relative;
    overflow: visible;
}

.chat-status.online,
.session-status.online {
    background: #16a34a;
}

.chat-status.away,
.session-status.away {
    background: #d97706;
}

.chat-status.offline,
.session-status.offline {
    background: #6b7280;
}

.peer-reconnect {
    width: 26px;
    height: 26px;
    border: 1px solid #d1d5db;
    border-radius: 999px;
    background: #fff;
    color: #374151;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.86rem;
    line-height: 1;
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease;
}

.peer-reconnect:hover:not(:disabled) {
    background: #f3f4f6;
    border-color: #9ca3af;
}

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

.chat-menu-wrap {
    position: relative;
    display: inline-flex;
    align-items: center;
    margin-left: auto;
    flex: 0 0 auto;
}

.chat-menu-toggle {
    width: 30px;
    height: 30px;
    padding: 0;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    background: #fff;
    color: #374151;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    line-height: 1;
}

.chat-menu-toggle:hover {
    background: #f3f4f6;
    border-color: #9ca3af;
}

.chat-menu {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    min-width: 116px;
    padding: 6px;
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    background: #fff;
    box-shadow: 0 10px 24px rgba(0, 0, 0, 0.14);
    display: flex;
    flex-direction: column;
    gap: 4px;
    z-index: 90;
}

.chat-menu-item {
    width: 100%;
    padding: 8px 10px;
    border: none;
    border-radius: 6px;
    background: #fff;
    color: #111827;
    text-align: left;
}

.chat-menu-item:hover {
    background: #f3f4f6;
    color: #111827;
}

.chat-menu-item.chat-menu-item-danger {
    background: #fff;
    color: #b91c1c;
}

.chat-menu-item.chat-menu-item-danger:hover {
    background: #fee2e2;
    color: #991b1b;
}

.status-heart-float {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -35%) scale(var(--heart-scale, 1));
    color: #fb7185;
    font-size: 0.85rem;
    line-height: 1;
    opacity: 0;
    pointer-events: none;
    z-index: 3;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.22);
    animation: status-heart-rise var(--heart-duration, 1200ms) ease-out forwards;
}

@keyframes status-heart-rise {
    0% {
        opacity: 0;
        transform: translate(-50%, -35%) scale(calc(var(--heart-scale, 1) * 0.8));
    }
    16% {
        opacity: 0.95;
    }
    100% {
        opacity: 0;
        transform: translate(
            calc(-50% + var(--heart-drift, 0px)),
            calc(-50% - var(--heart-rise, 56px))
        ) scale(calc(var(--heart-scale, 1) * 1.12));
    }
}

.unread-badge,
.session-unread {
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    border-radius: 999px;
    background: #ef4444;
    color: #fff;
    font-size: 0.72rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.session-item {
    position: relative;
}

.session-status {
    margin-left: auto;
}

.session-item .peer-reconnect {
    margin-left: auto;
}

.session-item .session-status {
    margin-left: 2px;
}

.session-unread {
    margin-left: 6px;
}

#chat-interface.sidebar-collapsed .sidebar {
    width: 0;
    min-width: 0;
    border-right: none;
    overflow: hidden;
}

.messages-container {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    background: #fff;
    display: flex;
    flex-direction: column;
    gap: 10px;
    min-height: 0;
}

.chat-input-area {
    padding: 15px;
    border-top: 1px solid #eee;
}

.input-actions {
    margin-bottom: 10px;
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.input-wrapper {
    display: flex;
    gap: 10px;
}

#message-input {
    flex: 1;
    height: 60px;
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 4px;
    resize: none;
}

button {
    padding: 8px 16px;
    border: none;
    border-radius: 4px;
    background: #007bff;
    color: white;
    cursor: pointer;
}

button:hover {
    background: #0056b3;
}

button.secondary {
    background: #6c757d;
}

button.danger {
    background: #dc3545;
}

button.danger:hover {
    background: #bd2130;
}

.qr-modal {
    position: fixed;
    inset: 0;
    z-index: 10000;
    background: rgba(0, 0, 0, 0.84);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.qrcode-large {
    background: #fff;
    border-radius: 12px;
    padding: 16px;
    max-width: min(90vw, 90vh);
    max-height: min(90vw, 90vh);
    display: flex;
    align-items: center;
    justify-content: center;
}

.qrcode-large canvas,
.qrcode-large img {
    width: min(82vw, 82vh) !important;
    height: min(82vw, 82vh) !important;
    display: block;
}

.qr-modal-close {
    position: fixed;
    top: 16px;
    right: 16px;
    background: #111827;
}

.message {
    max-width: 70%;
    padding: 10px 12px;
    border-radius: 10px;
    line-height: 1.35;
    word-break: break-word;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.message-time {
    font-size: 0.72rem;
    opacity: 0.75;
}

.message-body {
    white-space: pre-wrap;
}

.message.me {
    align-self: flex-end;
    background: #007bff;
    color: #fff;
}

.message.peer {
    align-self: flex-start;
    background: #f1f3f5;
    color: #212529;
}

.message.system {
    align-self: center;
    background: #fff3cd;
    color: #664d03;
}

.session-backdrop {
    display: none;
}

.emoji-panel {
    margin-bottom: 10px;
    display: grid;
    grid-template-columns: repeat(8, minmax(0, 1fr));
    gap: 8px;
    padding: 10px;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    background: #f8fafc;
}

.emoji-btn {
    border: 1px solid #dbe2ea;
    background: #fff;
    color: #111827;
    padding: 6px 0;
    font-size: 1.15rem;
    line-height: 1;
    border-radius: 6px;
}

.emoji-btn:hover {
    background: #eef2ff;
}

.message.file .message-body,
.message.voice .message-body {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.transfer-progress {
    width: min(260px, 100%);
    height: 8px;
}

.transfer-meta {
    font-size: 0.78rem;
    opacity: 0.9;
}

.attachment-link {
    color: inherit;
    text-decoration: underline;
    text-underline-offset: 2px;
}

.message.peer .attachment-link,
.message.system .attachment-link {
    color: #1d4ed8;
}

.voice-audio {
    width: min(320px, 100%);
}

.video-modal {
    position: fixed;
    inset: 0;
    z-index: 11000;
    background: rgba(17, 24, 39, 0.78);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.video-card {
    width: min(920px, 100%);
    background: #fff;
    border-radius: 12px;
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.video-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
}

.video-settings {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.92rem;
}

.video-settings label {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.video-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
}

.video-pane {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.video-pane video {
    width: 100%;
    aspect-ratio: 16 / 9;
    border-radius: 8px;
    background: #111827;
    object-fit: cover;
}

.video-pane.video-off::after {
    content: "黑屏（未开启画面）";
    font-size: 0.82rem;
    color: #d1d5db;
}

.video-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
}

.file-offer-modal {
    position: fixed;
    inset: 0;
    z-index: 11100;
    background: rgba(17, 24, 39, 0.72);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.file-offer-card {
    width: min(480px, 100%);
    border-radius: 12px;
    background: #fff;
    padding: 18px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.file-offer-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

@media (max-width: 760px) {
    .home-entry {
        top: max(10px, env(safe-area-inset-top));
        left: max(10px, env(safe-area-inset-left));
        padding: 6px 10px;
        font-size: 0.84rem;
    }

    #app {
        width: 100vw;
        height: 100dvh;
        max-height: 100dvh;
        border-radius: 0;
    }

    #connection-setup {
        padding: 22px;
    }

    .content {
        --connector-box-size: 260px;
        --connector-box-padding: 16px;
    }

    .sidebar {
        position: absolute;
        left: 0;
        top: 0;
        bottom: 0;
        width: min(82vw, 320px);
        z-index: 40;
        transform: translateX(-106%);
        transition: transform 0.22s ease;
        box-shadow: 8px 0 24px rgba(0, 0, 0, 0.22);
    }

    #chat-interface.session-open .sidebar {
        transform: translateX(0);
    }

    .session-backdrop {
        display: block;
        position: absolute;
        inset: 0;
        z-index: 30;
        background: rgba(0, 0, 0, 0.36);
    }

    #chat-interface:not(.session-open) .session-backdrop {
        display: none !important;
    }

    .chat-header {
        padding: 12px 14px;
    }

    .chat-header-main {
        max-width: 100%;
    }

    .session-toggle {
        min-width: 0;
        max-width: 100%;
        padding: 8px 6px;
    }

    .chat-title-text {
        font-size: 1rem;
    }

    .emoji-panel {
        grid-template-columns: repeat(6, minmax(0, 1fr));
    }

    .video-grid {
        grid-template-columns: 1fr;
    }
}
