/* ============================================================
   CSS: Modals, Toasts, Context Menu, Action Sheet, Dialogs
   设计系统: 毛玻璃遮罩 · 弹性入场 · 光池打光 · 多层阴影
   ============================================================ */

/* ================================================================
   Toast — 毛玻璃药丸 · 居中弹出
   ★ 第 11 窗口：入场改成「先建隐藏态 → 下一帧 .is-show」两拍（原来元素一建出来就是可见态，
     第一次弹没有过渡）；底色/描边改由这里的令牌决定（JS 里那串 inline 已经删掉，
     否则 inline 永远盖过这里 → 深色主题下吐司也是近乎纯白一块）。
   ================================================================ */
#custom-toast {
    position: fixed;
    bottom: calc(60px + var(--kbd-h, 0px));
    left: 50%;
    z-index: var(--z-toast);
    padding: 10px 22px;
    border-radius: 22px;
    background: var(--surface);
    color: var(--text-primary);
    font-size: 13px;
    letter-spacing: 0.3px;
    font-weight: 500;
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    pointer-events: none;
    /* 两拍入场：默认停在「淡一点、低一点、小一点」，加 .is-show 才走到终态 */
    opacity: 0;
    transform: translateX(-50%) translateY(8px) scale(0.98);
    transition: opacity 0.26s ease, transform 0.26s ease;
    white-space: nowrap;
    max-width: 88vw;
    overflow: hidden;
    text-overflow: ellipsis;
    box-shadow:
        0 1px 0 rgba(255,255,255,0.5) inset,
        0 8px 32px rgba(160,145,130,0.15);
    border: 1px solid var(--border);
}
#custom-toast.is-show { opacity: 1; transform: translateX(-50%) translateY(0) scale(1); }
@media (prefers-reduced-motion: reduce) {
    #custom-toast { transition: opacity 0.12s linear; transform: translateX(-50%); }
    #custom-toast.is-show { transform: translateX(-50%); }
}

/* ================================================================
   Confirm Dialog — 弹性弹入 + 光池顶部打光
   ★ 防闪烁（CODE-MAP 第十五节）：基类 opacity:0 + 仅 close 方向 transition；
     .show 里 transition:none + animation 独占（open 方向），JS 下一帧 rAF 添加。
   ================================================================ */
.confirm-overlay {
    position: fixed;
    inset: 0;
    /* ★ 去掉 backdrop-filter：叠在「更多」等毛玻璃面板上会双层合成重绘 → 弹窗先闪一下（血泪）。改用略深不透明底。 */
    background: rgba(30,25,20,0.46);
    z-index: var(--z-confirm);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.18s ease;
}
.confirm-overlay.show {
    opacity: 1;
    pointer-events: auto;
    transition: none;
    animation: fadeIn 0.18s ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.confirm-panel {
    background: var(--surface-solid);
    border-radius: 18px;
    padding: 26px 24px;
    max-width: 330px;
    width: 88%;
    box-shadow:
        0 1px 0 rgba(255,255,255,0.55) inset,
        0 12px 40px rgba(160,145,130,0.16),
        0 0 0 1px var(--border);
    text-align: center;
    position: relative;
    overflow: hidden;
}
/* ★ 进场动画只挂在 .show 上（禁止常驻基类，否则隐形插入阶段先播、再和淡入重演出「显示→消失→再显示」一闪）。
   面板不再单独 popIn（叠加双层进场容易出「显示→消失→再显示」），统一走 overlay 一次淡入。 */
.confirm-overlay.show .confirm-panel {
    transform: scale(1);
}
/* 光池：顶部一束柔光 */
.confirm-panel::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 120px;
    background: radial-gradient(120% 80% at 50% 0%, rgba(210,190,180,0.10), transparent 70%);
    pointer-events: none;
    z-index: 0;
    border-radius: 18px 18px 0 0;
}

@keyframes popIn {
    from { opacity: 0; transform: scale(0.92) translateY(8px); }
    to   { opacity: 1; transform: scale(1) translateY(0); }
}

.confirm-panel .confirm-msg {
    font-size: 15px;
    line-height: 1.7;
    margin-bottom: 22px;
    white-space: pre-wrap;
    color: var(--text-primary);
    letter-spacing: 0.2px;
    position: relative;
    z-index: 1;
}
/* 输入弹窗里的灰色小提示（换行居中，说明用途） */
.confirm-panel .confirm-msg .confirm-hint {
    display: block;
    margin-top: 8px;
    font-size: 11px;
    line-height: 1.5;
    font-weight: 400;
    color: var(--text-muted);
    text-align: center;
    letter-spacing: 0.2px;
}
/* customPrompt 输入框 */
.confirm-panel .confirm-input {
    width: 100%;
    padding: 9px 12px;
    margin: -8px 0 20px;
    border: 1px solid var(--border, rgba(0,0,0,0.1));
    border-radius: 10px;
    font-size: 14px;
    font-family: var(--font-body);
    background: var(--input-bg, rgba(255,255,255,0.7));
    color: var(--text-primary);
    position: relative;
    z-index: 1;
    outline: none;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
.confirm-panel .confirm-input:focus {
    border-color: var(--rose, #C9A8A8);
    box-shadow: 0 0 0 3px rgba(201, 168, 168, 0.18);
}
.confirm-panel .confirm-buttons {
    display: flex;
    gap: 10px;
    justify-content: center;
    position: relative;
    z-index: 1;
}
.confirm-panel .confirm-buttons button {
    padding: 10px 28px;
    border: none;
    border-radius: 22px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    transition: all 0.2s ease;
    letter-spacing: 0.2px;
}
.confirm-panel .confirm-ok-btn {
    background: var(--accent);
    color: #fff;
    box-shadow: 0 2px 6px rgba(160,145,130,0.16);
}
.confirm-panel .confirm-ok-btn:hover {
    background: var(--accent-hover, var(--accent));
    transform: translateY(-1px);
    box-shadow: 0 3px 8px rgba(160,145,130,0.22);
}
.confirm-panel .confirm-ok-btn:active { transform: scale(0.96); }
.confirm-panel .confirm-cancel-btn {
    background: var(--accent-light);
    color: var(--accent);
}
.confirm-panel .confirm-cancel-btn:hover { background: rgba(201,176,168,0.22); }
.confirm-panel .confirm-cancel-btn:active { transform: scale(0.96); }

/* ================================================================
   删除确认弹窗（微信式底部弹出）
   ================================================================ */
.del-chooser-overlay {
    position: fixed;
    inset: 0;
    /* ★ 去掉 backdrop-filter：叠在「更多」等毛玻璃面板上会双层合成重绘 → 删除确认框「先消失一下再出现」（血泪，同 confirm-overlay）。
       改用略深不透明底，叠层不闪。 */
    background: rgba(30,25,20,0.46);
    z-index: 350;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    padding-bottom: calc(20px + var(--safe-bottom));
    /* ★ 防闪烁同 confirm-overlay：基类隐藏 + close transition；.show animation 独占 */
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.18s ease;
}
.del-chooser-overlay.show {
    opacity: 1;
    pointer-events: auto;
    transition: none;
    animation: fadeIn 0.18s ease;
}
.del-chooser-panel {
    background: var(--surface-solid);
    border-radius: 18px;
    padding: 16px 0;
    max-width: 360px;
    width: 92%;
    box-shadow:
        0 1px 0 rgba(255,255,255,0.55) inset,
        var(--shadow-lg);
    border: 1px solid var(--border);
    animation: slideUp 0.3s ease;
    overflow: hidden;
}
@keyframes slideUp {
    from { transform: translateY(100%); opacity: 0; }
    to   { transform: translateY(0);    opacity: 1; }
}
.del-chooser-panel .dc-title {
    font-size: 14px;
    font-weight: 600;
    text-align: center;
    padding: 8px 16px 4px;
}
.del-chooser-panel .dc-sub {
    font-size: 12px;
    color: var(--text-muted);
    text-align: center;
    padding: 0 16px 12px;
}
.del-chooser-panel button {
    display: block;
    width: 100%;
    padding: 12px;
    background: none;
    border: none;
    border-top: 1px solid var(--divider);
    font-family: inherit;
    font-size: 14px;
    cursor: pointer;
    color: var(--text-primary);
    transition: background 0.15s ease;
}
.del-chooser-panel button:hover { background: var(--accent-light); }
.del-chooser-panel .dc-both { color: var(--danger); }
.del-chooser-panel .dc-cancel {
    font-weight: 600;
    margin-top: 8px;
    border-top: 8px solid var(--divider);
}

/* ================================================================
   Action Sheet（iOS 式底部操作表）
   ================================================================ */
.action-sheet-overlay {
    position: fixed;
    inset: 0;
    background: rgba(30,25,20,0.45);
    z-index: var(--z-sheet);
    display: flex;
    align-items: flex-end;
    justify-content: center;
    padding-bottom: calc(10px + var(--safe-bottom));
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 0.22s ease, visibility 0s 0.22s;   /* ★ close 方向 */
}
.action-sheet-overlay.open {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transition: none;
    animation: asFadeIn 0.22s ease;
}
@keyframes asFadeIn { from { opacity: 0; } to { opacity: 1; } }
.action-sheet-panel {
    background: var(--surface-solid);
    border-radius: 18px;
    max-width: 360px;
    width: 92%;
    box-shadow:
        0 1px 0 rgba(255,255,255,0.55) inset,
        var(--shadow-lg);
    border: 1px solid var(--border);
    overflow: hidden;
}
/* ★ 进场动画只挂 .open（禁止常驻基类，否则「显示→消失→再显示」一闪） */
.action-sheet-overlay.open .action-sheet-panel {
    animation: slideUp 0.3s ease;
}
.action-sheet-panel button {
    display: block;
    width: 100%;
    padding: 14px;
    background: none;
    border: none;
    border-bottom: 1px solid var(--divider);
    font-family: inherit;
    font-size: 15px;
    cursor: pointer;
    color: var(--text-primary);
    transition: background 0.15s ease;
}
.action-sheet-panel button:hover { background: var(--accent-light); }
.action-sheet-panel button:active { background: var(--accent-light); }
.action-sheet-panel .as-cancel-btn {
    font-weight: 600;
    color: var(--text-secondary);
    margin-top: 4px;
    border-bottom: none;
}

/* ================================================================
   Context Menu（右键/长按气泡菜单）— 毛玻璃卡片
   ================================================================ */
.msg-ctx-menu {
    position: fixed;
    z-index: 250;
    background: var(--surface);
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
    contain: layout style paint;  /* ★ 隔离布局影响，防止气泡闪烁 */
    border-radius: var(--radius-md);
    box-shadow:
        0 1px 0 rgba(255,255,255,0.5) inset,
        var(--shadow-lg);
    border: 1px solid var(--border);
    opacity: 0;
    transform: translateY(8px) scale(0.95);
    /* ★ 防闪烁（CODE-MAP 第十五节）：base 只留 close 方向 transition；
       open 方向由 .open 的 animation 独占（transition:none 断开双驱动）。
       旧实现 open 用 transition + visibility:hidden 首帧画终点再重跑 = 显示→消失→再出现。 */
    transition: opacity 0.15s ease, transform 0.15s ease;
    pointer-events: none;
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 2px;
    padding: 4px;
    min-width: fit-content;
    max-width: min(320px, 92vw);
}
.msg-ctx-menu.open {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
    transition: none;
    animation: ctxMenuIn 0.18s cubic-bezier(0.32, 0.72, 0, 1);
}
@keyframes ctxMenuIn {
    from { opacity: 0; transform: translateY(8px) scale(0.95); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}
.ctx-btn {
    min-width: 44px;
    height: 32px;
    padding: 2px 6px;
    background: none;
    border: none;
    border-radius: 6px;
    font-family: inherit;
    font-size: 11px;
    cursor: pointer;
    color: var(--text-primary);
    transition: background 0.12s ease, transform 0.12s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    flex-shrink: 0;
    white-space: nowrap;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}
.ctx-btn:active {
    background: var(--accent-light);
    transform: scale(0.95);
}
.ctx-btn:hover { background: var(--accent-light); }
.ctx-delete-btn { color: var(--danger); }

/* ================================================================
   Avatar Crop Editor（头像裁剪）
   ================================================================ */
.avatar-crop-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.9);
    /* ★ 2026-11：从 2100 提到 6000。开屏引导「一封请帖」是 5000 层，
       引导里点「放一张照片」时裁剪编辑器必须盖在它上面，否则点开像没反应（看不见摸不着）。 */
    z-index: 6000;
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    /* iOS 刘海/状态栏：容器 height:100% 会顶到屏幕最上沿，头部「取消/确认」被状态栏压住点不到。
       给遮罩加顶部安全区，把整个容器下移到刘海之下；安卓 safe-area=0 无影响。 */
    padding-top: var(--safe-top);
}
.avatar-crop-overlay.open { display: flex; }
.avatar-crop-container {
    width: 100%;
    max-width: 480px;
    display: flex;
    flex-direction: column;
    height: 100%;
}
.avatar-crop-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    color: #fff;
    flex-shrink: 0;
}
.avatar-crop-header button {
    background: none;
    border: none;
    color: #fff;
    font-size: 15px;
    cursor: pointer;
    font-family: inherit;
}
.avatar-crop-header span { font-size: 16px; font-weight: 600; }
.avatar-crop-area {
    flex: 1;
    position: relative;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
}
#avatar-crop-canvas { position: absolute; cursor: move; }
.avatar-crop-mask {
    position: absolute;
    inset: 0;
    pointer-events: none;
    box-shadow: 0 0 0 9999px rgba(0,0,0,0.55);
}
.avatar-crop-box {
    position: absolute;
    width: min(280px, 80vw);
    height: min(280px, 80vw);
    pointer-events: none;
    border: 2px solid rgba(255,255,255,0.9);
    border-radius: 4px;
    box-shadow: 0 0 0 9999px rgba(0,0,0,0.55);
}
.crop-grid {
    position: absolute;
    inset: 0;
    background-image:
        linear-gradient(rgba(255,255,255,0.2) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255,255,255,0.2) 1px, transparent 1px);
    background-size: 33.33% 33.33%;
}
.avatar-crop-hint {
    text-align: center;
    color: rgba(255,255,255,0.5);
    font-size: 12px;
    padding: 12px 16px 20px;
    flex-shrink: 0;
}

/* ================================================================
   Emoji Crop Editor（表情包裁剪，复用头像裁剪样式）
   ================================================================ */
.emoji-crop-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.9);
    z-index: 400;
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    /* iOS 刘海/状态栏：同头像裁剪，给顶部安全区，头部按钮不被状态栏压住 */
    padding-top: var(--safe-top);
}
.emoji-crop-overlay.open { display: flex; }
.emoji-crop-container {
    width: 100%;
    max-width: 480px;
    display: flex;
    flex-direction: column;
    height: 100%;
}
.emoji-crop-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    color: #fff;
    flex-shrink: 0;
}
.emoji-crop-header button {
    background: none;
    border: none;
    color: #fff;
    font-size: 15px;
    cursor: pointer;
    font-family: inherit;
}
.emoji-crop-header span { font-size: 16px; font-weight: 600; }
.ec-crop-area {
    flex: 1;
    position: relative;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
}
#ec-canvas { position: absolute; cursor: move; }
.ec-crop-mask {
    position: absolute;
    inset: 0;
    pointer-events: none;
    box-shadow: 0 0 0 9999px rgba(0,0,0,0.55);
}
.ec-crop-box {
    position: absolute;
    width: min(280px, 80vw);
    height: min(280px, 80vw);
    pointer-events: none;
    border: 2px solid rgba(255,255,255,0.9);
    border-radius: 4px;
    box-shadow: 0 0 0 9999px rgba(0,0,0,0.55);
}
.ec-crop-grid {
    position: absolute;
    inset: 0;
    background-image:
        linear-gradient(rgba(255,255,255,0.2) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255,255,255,0.2) 1px, transparent 1px);
    background-size: 33.33% 33.33%;
}
