/**
 * 全站 UI 组件：Toast、空状态、全局搜索、进度条、简化模式、PWA
 */

/* ── Toast ── */
.app-toast-container {
    position: fixed;
    top: max(12px, env(safe-area-inset-top, 0px));
    left: 50%;
    transform: translateX(-50%);
    z-index: 10050;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    pointer-events: none;
    width: min(420px, calc(100vw - 24px));
}

.app-toast {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    width: 100%;
    padding: 11px 14px;
    border-radius: var(--ds-radius-lg, 10px);
    background: var(--ds-surface, #fff);
    box-shadow: var(--ds-shadow-md, 0 4px 20px rgba(15, 23, 42, 0.14)), 0 0 0 1px rgba(15, 23, 42, 0.06);
    font-size: 13px;
    line-height: 1.45;
    color: var(--ds-text, #1e293b);
    pointer-events: auto;
    opacity: 0;
    transform: translateY(-8px);
    transition: opacity 0.22s ease, transform 0.22s ease;
}

.app-toast.is-visible {
    opacity: 1;
    transform: translateY(0);
}

.app-toast.is-leaving {
    opacity: 0;
    transform: translateY(-6px);
}

.app-toast-icon {
    flex-shrink: 0;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 700;
    margin-top: 1px;
}

.app-toast--success .app-toast-icon { background: var(--ds-success-bg, #e8f5e9); color: var(--ds-success, #2e7d32); }
.app-toast--error .app-toast-icon { background: var(--ds-error-bg, #ffebee); color: var(--ds-error, #c62828); }
.app-toast--warning .app-toast-icon { background: var(--ds-warning-bg, #fff3e0); color: var(--ds-warning, #e65100); }
.app-toast--info .app-toast-icon { background: var(--ds-info-bg, #eef2ff); color: var(--ds-info, #1e3c72); }

.app-toast-msg {
    flex: 1;
    min-width: 0;
    word-break: break-word;
}

.app-toast-close {
    flex-shrink: 0;
    border: none;
    background: transparent;
    color: #94a3b8;
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
    padding: 0 0 0 4px;
    margin: -2px 0 0;
}
.app-toast-close:hover { color: #64748b; }

/* ── 空状态 / 错误状态 ── */
.empty-state {
    text-align: center;
    padding: 36px 20px;
    color: #78909c;
    background: var(--ds-surface, white);
    border-radius: var(--ds-radius-lg, 10px);
    border: 1px dashed var(--ds-border, #e2e8f0);
}

.empty-state--error {
    border-color: #ffcdd2;
    background: #fffafa;
}

.empty-state-icon {
    font-size: 2rem;
    line-height: 1;
    margin-bottom: 10px;
    opacity: 0.55;
}

.empty-state-title {
    font-size: 15px;
    font-weight: 600;
    color: #37474f;
    margin-bottom: 6px;
}

.empty-state-desc {
    font-size: 13px;
    color: #90a4ae;
    line-height: 1.5;
    max-width: 360px;
    margin: 0 auto;
}

.empty-state-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
    margin-top: 16px;
}

.empty-state-retry {
    padding: 8px 18px;
    border: none;
    border-radius: 8px;
    background: var(--ds-brand, #1e3c72);
    color: #fff;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
}
.empty-state-retry:hover { filter: brightness(1.08); }

.empty-state-retry.secondary {
    background: #eceff1;
    color: #546e7a;
}

/* ── 全局快捷搜索 ── */
.global-search-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 10040;
    background: rgba(15, 23, 42, 0.45);
    backdrop-filter: blur(2px);
    align-items: flex-start;
    justify-content: center;
    padding: max(60px, 8vh) 16px 16px;
}

.global-search-backdrop.show {
    display: flex;
}

.global-search-panel {
    width: min(520px, 100%);
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 16px 48px rgba(15, 23, 42, 0.2);
    overflow: hidden;
    animation: globalSearchIn 0.18s ease;
}

@keyframes globalSearchIn {
    from { opacity: 0; transform: translateY(-12px) scale(0.98); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

.global-search-head {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 14px;
    border-bottom: 1px solid #eef2f6;
}

.global-search-head input {
    flex: 1;
    border: none;
    outline: none;
    font-size: 16px;
    color: #1e293b;
    background: transparent;
    min-width: 0;
}

.global-search-head input::placeholder { color: #94a3b8; }

.global-search-kbd {
    flex-shrink: 0;
    font-size: 11px;
    color: #94a3b8;
    background: #f1f5f9;
    padding: 3px 7px;
    border-radius: 5px;
    white-space: nowrap;
}

.global-search-results {
    max-height: min(360px, 50vh);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.global-search-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 11px 16px;
    cursor: pointer;
    border-bottom: 1px solid #f8fafc;
    transition: background 0.12s;
}

.global-search-item:hover,
.global-search-item.is-active {
    background: #f0f4ff;
}

.global-search-item strong {
    font-size: 14px;
    color: #1e3c72;
}

.global-search-item .gs-code {
    font-size: 12px;
    color: #94a3b8;
    margin-left: 6px;
}

.global-search-item .gs-pct {
    font-size: 13px;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    flex-shrink: 0;
}

.global-search-item .gs-pct.up { color: #c62828; }
.global-search-item .gs-pct.down { color: #2e7d32; }
.global-search-item .gs-pct.flat { color: #90a4ae; }

.global-search-empty,
.global-search-hint {
    padding: 24px 16px;
    text-align: center;
    font-size: 13px;
    color: #94a3b8;
}

.global-search-foot {
    padding: 8px 14px;
    font-size: 11px;
    color: #b0bec5;
    border-top: 1px solid #f1f5f9;
    text-align: center;
}

@media (max-width: 768px) {
    .global-search-backdrop {
        padding: 0;
        align-items: stretch;
    }
    .global-search-panel {
        width: 100%;
        min-height: 100%;
        border-radius: 0;
        animation: none;
    }
    .global-search-kbd { display: none; }
}

/* ── 长任务进度条 ── */
.app-progress {
    text-align: left;
    padding: 28px 24px;
    background: var(--ds-surface, #fff);
    border-radius: var(--ds-radius-lg, 10px);
    border: 1px solid var(--ds-border, #e8edf3);
    max-width: 480px;
    margin: 0 auto;
}

.app-progress-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 12px;
}

.app-progress-label {
    font-size: 14px;
    font-weight: 600;
    color: var(--ds-brand, #1e3c72);
}

.app-progress-pct {
    font-size: 13px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    color: var(--ds-text-secondary, #546e7a);
}

.app-progress-track {
    height: 8px;
    background: var(--ds-bg-alt, #f0f2f5);
    border-radius: 999px;
    overflow: hidden;
}

.app-progress-bar {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, var(--ds-brand, #1e3c72), var(--ds-brand-light, #2d5a9e));
    border-radius: 999px;
    transition: width 0.25s ease;
}

.app-progress-meta {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    margin-top: 10px;
    font-size: 12px;
    color: var(--ds-text-muted, #90a4ae);
}

.app-progress-hint { flex-shrink: 0; }

.fm-progress-cell { padding: 0 !important; border: none !important; }

/* ── PWA 安装引导 ── */
.pwa-install-banner {
    position: fixed;
    bottom: calc(12px + env(safe-area-inset-bottom, 0px));
    left: 50%;
    transform: translateX(-50%);
    z-index: 10030;
    width: min(480px, calc(100vw - 24px));
    animation: pwaSlideUp 0.3s ease;
}

@keyframes pwaSlideUp {
    from { opacity: 0; transform: translateX(-50%) translateY(16px); }
    to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

.pwa-install-inner {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 14px;
    background: var(--ds-surface, #fff);
    border: 1px solid var(--ds-border, #e8edf3);
    border-radius: var(--ds-radius-xl, 12px);
    box-shadow: var(--ds-shadow-lg, 0 16px 48px rgba(15, 23, 42, 0.16));
}

.pwa-install-icon { font-size: 1.5rem; flex-shrink: 0; }

.pwa-install-text {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.pwa-install-text strong { font-size: 13px; color: var(--ds-text, #1e293b); }
.pwa-install-text span { font-size: 11px; color: var(--ds-text-muted, #90a4ae); }

.pwa-install-actions {
    display: flex;
    flex-direction: column;
    gap: 6px;
    flex-shrink: 0;
}

.pwa-install-btn {
    padding: 6px 12px;
    border: none;
    border-radius: var(--ds-radius-sm, 6px);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
}

.pwa-install-btn.primary {
    background: var(--ds-brand, #1e3c72);
    color: #fff;
}

.pwa-install-btn.ghost {
    background: transparent;
    color: var(--ds-text-muted, #90a4ae);
}

@media (max-width: 768px) {
    body.app-mobile-shell .pwa-install-banner {
        bottom: calc(var(--app-bottom-nav-h, 56px) + 8px);
    }
    .pwa-install-inner { flex-wrap: wrap; }
    .pwa-install-actions { flex-direction: row; width: 100%; }
    .pwa-install-btn { flex: 1; }
}
