:root {
    --app-height: 100vh;
    --font-ui: "Segoe UI", "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", sans-serif;
    --bg-top: #dcecff;
    --bg-bottom: #eff5fb;
    --panel: rgba(255, 255, 255, 0.84);
    --panel-strong: rgba(255, 255, 255, 0.94);
    --border: rgba(149, 175, 206, 0.32);
    --text: #12263f;
    --muted: #6a7b90;
    --accent: #3390ec;
    --accent-deep: #1c7dd9;
    --accent-soft: #eaf4ff;
    --success: #4aaf64;
    --warning: #f59f00;
    --danger: #e45f63;
    --shadow-lg: 0 22px 48px rgba(15, 42, 76, 0.18);
    --shadow-md: 0 12px 24px rgba(16, 48, 82, 0.12);
    --radius-xl: 28px;
    --radius-lg: 20px;
    --radius-md: 16px;
    --radius-sm: 12px;
}

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

* {
    box-sizing: border-box;
}

html,
body {
    height: 100%;
    min-height: var(--app-height);
    overflow-x: hidden;
    margin: 0;
    font-family: var(--font-ui);
    color: var(--text);
    background:
        radial-gradient(circle at top right, rgba(102, 187, 255, 0.22), transparent 26rem),
        radial-gradient(circle at left bottom, rgba(77, 179, 129, 0.16), transparent 28rem),
        linear-gradient(180deg, var(--bg-top) 0%, var(--bg-bottom) 100%);
}

body {
    position: relative;
}

body::before {
    content: "";
    position: fixed;
    inset: 0;
    pointer-events: none;
    background-image:
        linear-gradient(rgba(255, 255, 255, 0.12) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255, 255, 255, 0.08) 1px, transparent 1px);
    background-size: 26px 26px;
    mask-image: linear-gradient(180deg, rgba(0, 0, 0, 0.28), transparent 85%);
}

button,
input,
textarea {
    font: inherit;
}

a {
    color: inherit;
    text-decoration: none;
}

.page-shell,
.chat-list-page,
.chat-thread-page,
.page-login {
    height: 100%;
    min-height: var(--app-height);
}

.page-main,
.chat-list-page,
.chat-thread-page {
    overflow: hidden;
}

.page-main > form,
.chat-list-page > form,
.chat-thread-page > form,
.page-login > form {
    height: 100%;
}

.page-main > form,
.chat-list-page > form,
.chat-thread-page > form {
    display: flex;
}

.page-login > form {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.surface-shell {
    width: 100%;
    max-width: 1180px;
    margin: 0 auto;
    min-height: 0;
    height: 100%;
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    background: var(--panel);
    backdrop-filter: blur(18px);
    box-shadow: var(--shadow-lg);
    overflow: hidden;
}

.page-main {
    overflow: hidden;
    padding: 16px;
}

.shell-layout {
    display: flex;
    flex-direction: column;
    min-height: calc(var(--app-height) - 32px);
}

.shell-header {
    display: grid;
    grid-template-columns: 1fr auto auto;
    gap: 16px;
    align-items: center;
    padding: 18px 22px;
    background: linear-gradient(135deg, rgba(51, 144, 236, 0.16), rgba(255, 255, 255, 0.8));
    border-bottom: 1px solid var(--border);
}

.shell-brand {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.shell-title {
    font-size: clamp(1.15rem, 1rem + 0.8vw, 1.75rem);
    font-weight: 800;
    letter-spacing: 0.02em;
}

.shell-subtitle,
.shell-resolution,
.panel-hint,
.chat-handle,
.chat-time,
.message-meta,
.friend-subtitle,
.login-note,
.empty-state-text,
.topbar-meta {
    color: var(--muted);
}

.shell-user {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 4px;
    min-width: 0;
}

.shell-user-name {
    font-weight: 700;
    color: var(--accent-deep);
    word-break: break-word;
}

.shell-logout,
.primary-button,
.ghost-button,
.secondary-button {
    border: 0;
    border-radius: 999px;
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease, background-color 0.2s ease, opacity 0.2s ease;
}

.shell-logout,
.primary-button {
    padding: 0.8rem 1.3rem;
    background: linear-gradient(135deg, var(--accent), var(--accent-deep));
    color: #fff;
    font-weight: 700;
    box-shadow: 0 12px 22px rgba(51, 144, 236, 0.28);
}

.shell-logout:hover,
.primary-button:hover,
.ghost-button:hover,
.secondary-button:hover,
.chat-list-item:hover,
.avatar-button:hover,
.back-button:hover {
    transform: translateY(-1px);
}

.shell-frame {
    flex: 1;
    min-height: 0;
    padding: 14px;
    display: flex;
}

.shell-iframe {
    width: 100%;
    height: 100%;
    border: 0;
    border-radius: 22px;
    background: rgba(255, 255, 255, 0.64);
}

.chat-list-page,
.chat-thread-page {
    padding: 16px;
}

.chat-panel,
.thread-panel {
    width: 100%;
    max-width: 980px;
    margin: 0 auto;
    min-height: 0;
    height: 100%;
    display: flex;
    flex-direction: column;
    background: var(--panel-strong);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    overflow: hidden;
    box-shadow: var(--shadow-lg);
    backdrop-filter: blur(18px);
}

.list-topbar,
.thread-header {
    position: sticky;
    top: 0;
    z-index: 3;
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 18px;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.98), rgba(248, 251, 255, 0.94));
    border-bottom: 1px solid var(--border);
}

.topbar-main,
.friend-meta {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 0;
}

.topbar-title,
.friend-name,
.login-brand {
    font-size: clamp(1.1rem, 1rem + 0.5vw, 1.45rem);
    font-weight: 800;
}

.topbar-tools {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.search-shell {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: min(100%, 280px);
    padding: 0.7rem 1rem;
    border-radius: 999px;
    background: #f6faff;
    border: 1px solid rgba(51, 144, 236, 0.12);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.88);
}

.search-shell span,
.countdown-label {
    flex: 0 0 auto;
}

.search-shell input,
.composer-input {
    width: 100%;
    border: 0;
    outline: none;
    background: transparent;
    color: var(--text);
}

.search-shell input::placeholder,
.composer-input::placeholder {
    color: #8ea0b3;
}

.ghost-button,
.secondary-button,
.back-button {
    padding: 0.72rem 1.05rem;
    background: #edf4fc;
    color: var(--accent-deep);
    font-weight: 700;
    box-shadow: 0 8px 16px rgba(56, 118, 171, 0.12);
}

.back-button {
    border-radius: 999px;
    white-space: nowrap;
}

.meta-pill,
.countdown-pill {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.55rem 0.9rem;
    min-height: 2.6rem;
    border-radius: 999px;
    background: #f5f8fd;
    border: 1px solid rgba(18, 38, 63, 0.08);
    font-weight: 700;
}

.countdown-pill {
    color: var(--danger);
}

.chat-list-scroll,
.thread-scroll {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
}

.chat-list-scroll {
    display: flex;
    padding: 14px;
    background:
        radial-gradient(circle at top left, rgba(51, 144, 236, 0.08), transparent 18rem),
        linear-gradient(180deg, rgba(240, 247, 255, 0.94), rgba(255, 255, 255, 0.9));
}

.chat-list {
    flex: 1;
    display: grid;
    gap: 12px;
    width: 100%;
    min-height: 100%;
    align-content: start;
    grid-auto-rows: max-content;
}

.chat-list-item {
    display: flex;
    align-items: center;
    gap: 14px;
    min-width: 0;
    padding: 14px 16px;
    border-radius: var(--radius-lg);
    border: 1px solid rgba(51, 144, 236, 0.1);
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.96), rgba(243, 248, 255, 0.92));
    box-shadow: var(--shadow-md);
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
}

.chat-list-item:hover {
    border-color: rgba(51, 144, 236, 0.3);
    box-shadow: 0 16px 26px rgba(20, 66, 120, 0.16);
}

.avatar-button {
    width: 58px;
    height: 58px;
    padding: 0;
    border-radius: 50%;
    overflow: hidden;
    border: 2px solid rgba(51, 144, 236, 0.18);
    background: #fff;
    flex: 0 0 auto;
    box-shadow: 0 8px 18px rgba(26, 66, 117, 0.14);
}

.chat-avatar {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.chat-list-copy {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.chat-row {
    display: flex;
    align-items: center;
    gap: 12px;
    justify-content: space-between;
    min-width: 0;
}

.chat-row-bottom {
    align-items: flex-end;
}

.chat-name-wrap {
    min-width: 0;
    display: flex;
    align-items: baseline;
    gap: 8px;
    flex-wrap: wrap;
}

.chat-name {
    font-size: 1rem;
    font-weight: 800;
}

.chat-handle {
    font-size: 0.84rem;
}

.chat-time {
    font-weight: 700;
}

.chat-preview {
    min-width: 0;
    flex: 1;
    font-size: 0.94rem;
    line-height: 1.45;
    font-weight: 700;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat-preview.incoming {
    color: #516274;
}

.chat-preview.outgoing {
    color: var(--accent-deep);
}

.chat-preview.outgoing::before {
    content: "\6211\FF1A\0020";
    font-weight: 700;
}

.chat-badge {
    min-width: 1.9rem;
    height: 1.9rem;
    padding: 0 0.45rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 999px;
    background: var(--accent);
    color: #fff;
    font-size: 0.82rem;
    font-weight: 800;
    box-shadow: 0 8px 16px rgba(51, 144, 236, 0.22);
}

.chat-badge.unread {
    background: linear-gradient(135deg, #ff6b6b, #e03131);
    color: #fff;
    box-shadow: 0 8px 16px rgba(224, 49, 49, 0.22);
}

.chat-badge.muted {
    background: #e8f1fb;
    color: var(--accent-deep);
    box-shadow: none;
}

.empty-state {
    margin: 14px;
    padding: 40px 24px;
    border-radius: var(--radius-lg);
    border: 1px dashed rgba(51, 144, 236, 0.24);
    background: rgba(255, 255, 255, 0.7);
    text-align: center;
}

.empty-state-title {
    font-size: 1.1rem;
    font-weight: 800;
    margin-bottom: 10px;
}

.thread-scroll {
    display: block;
    padding: 18px 14px 10px;
    background:
        radial-gradient(circle at top left, rgba(51, 144, 236, 0.08), transparent 18rem),
        linear-gradient(180deg, rgba(240, 247, 255, 0.98), rgba(236, 245, 252, 0.96));
}

.day-divider {
    display: flex;
    justify-content: center;
    margin: 12px 0 16px;
}

.day-divider span {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.45rem 0.85rem;
    border-radius: 999px;
    background: rgba(18, 38, 63, 0.08);
    color: var(--muted);
    font-size: 0.82rem;
    font-weight: 700;
}

.message-row {
    display: flex;
    margin-bottom: 12px;
}

.message-row.incoming {
    justify-content: flex-start;
}

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

.message-bubble {
    max-width: min(100%, 36rem);
    padding: 0.9rem 1rem 0.7rem;
    border-radius: 22px;
    box-shadow: 0 12px 24px rgba(18, 44, 76, 0.1);
    border: 1px solid rgba(18, 38, 63, 0.06);
}

.message-row.incoming .message-bubble {
    background: #fff;
    border-top-left-radius: 8px;
}

.message-row.outgoing .message-bubble {
    background: linear-gradient(180deg, #e2f4ff, #d2ebff);
    border-top-right-radius: 8px;
}

.message-text {
    font-size: 1rem;
    line-height: 1.58;
    white-space: pre-wrap;
    word-break: break-word;
}

.message-meta {
    margin-top: 8px;
    text-align: right;
    font-size: 0.78rem;
    font-weight: 700;
}

.thread-composer {
    padding: 16px;
    border-top: 1px solid var(--border);
    background: rgba(255, 255, 255, 0.94);
}

.composer-shell {
    display: flex;
    align-items: flex-end;
    gap: 12px;
    padding: 12px;
    border-radius: 24px;
    background: #f6fbff;
    border: 1px solid rgba(51, 144, 236, 0.16);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.88);
}

.composer-input {
    min-height: 56px;
    max-height: 160px;
    resize: none;
    padding: 8px 10px;
}

.composer-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

.primary-button[disabled] {
    opacity: 0.45;
    cursor: not-allowed;
    box-shadow: none;
}

.page-login {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.login-card {
    width: min(100%, 460px);
    padding: 34px 30px 28px;
    border-radius: 30px;
    background: rgba(255, 255, 255, 0.9);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-lg);
    backdrop-filter: blur(18px);
}

.login-brand {
    margin-bottom: 8px;
}

.login-note {
    margin-bottom: 24px;
    line-height: 1.55;
}

.login-form {
    display: grid;
    gap: 14px;
}

.form-label {
    display: grid;
    gap: 8px;
    font-size: 0.92rem;
    font-weight: 700;
    color: var(--muted);
}

.form-control {
    width: 100%;
    padding: 0.95rem 1rem;
    border-radius: 16px;
    border: 1px solid rgba(51, 144, 236, 0.18);
    background: #f7fbff;
    color: var(--text);
    outline: none;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.form-control:focus,
.search-shell:focus-within,
.composer-shell:focus-within {
    border-color: rgba(51, 144, 236, 0.45);
    box-shadow: 0 0 0 4px rgba(51, 144, 236, 0.12);
}

.login-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
}

.error-msg {
    min-height: 1.25rem;
    color: var(--danger);
    font-weight: 700;
}

@media (max-width: 900px) {
    .shell-header {
        grid-template-columns: minmax(0, 1fr) auto;
        grid-template-areas:
            "brand logout"
            "user logout";
        align-items: start;
        gap: 10px 12px;
    }

    .shell-brand {
        grid-area: brand;
    }

    .shell-user {
        grid-area: user;
        align-items: flex-start;
    }

    .shell-logout {
        grid-area: logout;
        align-self: start;
    }

    .topbar-tools {
        margin-left: 0;
        justify-content: flex-start;
    }
}

@media (max-width: 640px) {
    .page-main,
    .chat-list-page,
    .chat-thread-page,
    .page-login {
        padding: 6px;
    }

    .surface-shell,
    .chat-panel,
    .thread-panel {
        min-height: 0;
        height: 100%;
        border-radius: 18px;
    }

    .shell-header,
    .list-topbar,
    .thread-header,
    .thread-composer {
        padding: 10px;
    }

    .shell-header {
        gap: 8px 10px;
    }

    .shell-frame {
        padding: 6px;
    }

    .shell-iframe {
        border-radius: 16px;
    }

    .shell-title {
        font-size: 1.15rem;
    }

    .shell-user-name {
        font-size: 1rem;
    }

    .shell-resolution {
        display: none;
    }

    .shell-logout {
        padding: 0.5rem 0.82rem;
        font-size: 0.88rem;
        line-height: 1;
        box-shadow: 0 8px 16px rgba(51, 144, 236, 0.22);
    }

    .chat-list-scroll,
    .thread-scroll {
        padding-left: 6px;
        padding-right: 6px;
        overflow-x: hidden;
    }

    .topbar-tools,
    .composer-shell {
        width: 100%;
    }

    .list-topbar {
        gap: 6px;
        padding: 8px 10px;
    }

    .topbar-main {
        display: none;
    }

    .topbar-title {
        font-size: 0.95rem;
    }

    .topbar-meta {
        display: none;
    }

    .topbar-tools {
        display: flex;
        flex-wrap: nowrap;
        gap: 6px;
        align-items: center;
    }

    .search-shell {
        flex: 1 1 auto;
        min-width: 0;
        width: auto;
        padding: 0.38rem 0.6rem;
        gap: 6px;
        border-radius: 18px;
    }

    .search-shell span {
        font-size: 0.84rem;
    }

    .search-shell input {
        font-size: 0.82rem;
    }

    .ghost-button,
    .meta-pill,
    .countdown-pill {
        flex: 0 0 auto;
        width: 2.15rem;
        min-width: 2.15rem;
        height: 2.15rem;
        min-height: 2.15rem;
        padding: 0;
        font-size: 0.82rem;
        box-shadow: none;
    }

    .ghost-button {
        font-size: 0.94rem;
        line-height: 1;
    }

    .meta-pill,
    .countdown-pill,
    .ghost-button {
        border-radius: 999px;
    }

    .countdown-label {
        display: none;
    }

    .countdown-pill #lblCountdown {
        margin-left: 0 !important;
    }

    .chat-list-scroll {
        padding: 6px;
    }

    .chat-list {
        gap: 8px;
        overflow-x: hidden;
    }

    .chat-list-item {
        gap: 8px;
        padding: 10px;
        overflow: hidden;
    }

    .avatar-button {
        width: 46px;
        height: 46px;
    }

    .chat-list-copy {
        gap: 4px;
    }

    .chat-row {
        gap: 6px;
        align-items: flex-start;
    }

    .chat-name {
        font-size: 1.35rem;
        font-weight: 900;
    }

    .chat-time {
        flex: 0 0 4.3rem;
        max-width: 4.3rem;
        font-size: 0.9rem;
        font-weight: 800;
        line-height: 1.15;
        text-align: right;
        white-space: normal;
    }

    .chat-preview {
        font-size: 1.2rem;
        font-weight: 800;
    }

    .chat-badge {
        min-width: 1.55rem;
        height: 1.55rem;
        font-size: 0.72rem;
    }

    .composer-shell {
        flex-direction: column;
        align-items: stretch;
    }

    .composer-actions {
        justify-content: flex-end;
    }

    .message-bubble {
        max-width: 92%;
    }

    .thread-header {
        display: grid;
        grid-template-columns: auto minmax(0, 1fr) auto;
        gap: 8px;
        align-items: center;
        width: 100%;
    }

    .thread-header .friend-meta {
        min-width: 0;
    }

    .thread-header .friend-name {
        font-size: 1.05rem;
        line-height: 1.2;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        writing-mode: horizontal-tb;
        word-break: keep-all;
    }

    .thread-header .topbar-tools {
        width: auto;
        margin-left: 0;
        justify-content: flex-end;
        justify-self: end;
    }

    .thread-header .meta-pill {
        width: auto;
        min-width: 3.55rem;
        height: 2.05rem;
        min-height: 2.05rem;
        padding: 0 0.6rem;
        font-size: 0.82rem;
        white-space: nowrap;
    }

    .back-button {
        padding: 0.5rem 0.78rem;
        font-size: 0.88rem;
        line-height: 1;
    }

    .thread-scroll {
        padding: 10px 8px 8px;
    }

    .thread-composer {
        padding: 8px;
    }

    .thread-panel .composer-shell {
        flex-direction: row;
        align-items: flex-end;
        gap: 8px;
        padding: 8px;
        border-radius: 18px;
    }

    .thread-panel .composer-input {
        min-height: 44px;
        max-height: 132px;
        font-size: 0.95rem;
        padding: 6px 8px;
    }

    .thread-panel .composer-actions {
        flex: 0 0 auto;
        justify-content: flex-end;
    }

    .thread-panel .primary-button {
        min-width: 4.2rem;
        padding: 0.68rem 0.95rem;
        font-size: 0.92rem;
        box-shadow: 0 8px 16px rgba(51, 144, 236, 0.2);
    }
}
