/* =========================================================
   前端优化补充样式
   - 骨架屏 Skeleton Loader
   - Toast 通知
   - 动画系统
   - 响应式增强
   - 暗黑模式适配关键组件
   - 滚动条美化
   - 空状态 & 加载状态
   ========================================================= */

/* ---------- 滚动条美化 ---------- */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 5px;
    transition: background var(--t);
}
::-webkit-scrollbar-thumb:hover { background: var(--muted); }
[data-theme="dark"] ::-webkit-scrollbar-thumb:hover { background: #64748b; }

/* ---------- 骨架屏 ---------- */
.skeleton {
    background: var(--skeleton-bg);
    background-size: 400% 100%;
    border-radius: var(--r-sm);
    animation: skeletonShimmer 1.4s ease infinite;
    min-height: 16px;
}
@keyframes skeletonShimmer {
    0%   { background-position: 100% 50%; }
    100% { background-position: 0 50%; }
}
.skeleton-line { height: 14px; margin-bottom: 10px; }
.skeleton-line.last { width: 60%; }
.skeleton-h { height: 28px; margin-bottom: 16px; width: 50%; }
.skeleton-card { height: 120px; border-radius: var(--r-card); margin-bottom: 16px; }
.skeleton-avatar {
    width: 40px; height: 40px; border-radius: 50%;
    background: var(--skeleton-bg);
    background-size: 400% 100%;
    animation: skeletonShimmer 1.4s ease infinite;
}
/* 骨架屏容器 */
.skeleton-wrap { padding: 4px; }
.skeleton-wrap .skeleton-row { display: flex; gap: 12px; margin-bottom: 14px; }
.skeleton-wrap .skeleton-main { flex: 1; }

/* ---------- Toast 通知 ---------- */
.toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 100000;
    display: flex;
    flex-direction: column;
    gap: 10px;
    pointer-events: none;
    max-width: 360px;
}
.toast {
    padding: 12px 18px;
    border-radius: var(--r-card);
    background: var(--card);
    box-shadow: var(--shadow-hover);
    border: 1px solid var(--border);
    color: var(--text);
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 200px;
    pointer-events: auto;
    font-size: 14px;
    animation: toastIn 0.3s cubic-bezier(0.34, 1.56, 0.64, 1),
               toastOut 0.3s ease 2.7s forwards;
    will-change: transform, opacity;
}
.toast.toast-out { animation: toastOut 0.3s ease forwards; }
.toast-icon {
    width: 20px; height: 20px;
    flex-shrink: 0;
    display: inline-flex; align-items: center; justify-content: center;
    border-radius: 50%;
    font-size: 12px;
    color: #fff;
}
.toast-success .toast-icon { background: var(--st-ok); }
.toast-error .toast-icon { background: var(--st-err); }
.toast-warning .toast-icon { background: var(--st-run); }
.toast-info .toast-icon { background: var(--st-info); }
.toast-msg { flex: 1; line-height: 1.4; }
.toast-close {
    cursor: pointer;
    color: var(--muted);
    font-size: 16px;
    line-height: 1;
    padding: 2px;
    border-radius: 4px;
    transition: background var(--t), color var(--t);
}
.toast-close:hover { background: var(--card-2); color: var(--text); }
@keyframes toastIn {
    from { transform: translateX(120%); opacity: 0; }
    to   { transform: translateX(0);    opacity: 1; }
}
@keyframes toastOut {
    from { transform: translateX(0);    opacity: 1; }
    to   { transform: translateX(120%); opacity: 0; }
}

/* ---------- 通用动画 ---------- */
.fade-in { animation: fadeIn var(--t) ease; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.slide-up { animation: slideUp 0.3s ease; }
@keyframes slideUp {
    from { opacity: 0; transform: translateY(12px); }
    to   { opacity: 1; transform: translateY(0); }
}

.scale-in { animation: scaleIn 0.2s ease; }
@keyframes scaleIn {
    from { opacity: 0; transform: scale(0.94); }
    to   { opacity: 1; transform: scale(1); }
}

.pulse-dot {
    display: inline-block;
    width: 8px; height: 8px;
    border-radius: 50%;
    background: var(--st-run);
    animation: pulseDot 1.2s ease infinite;
}
@keyframes pulseDot {
    0%,100% { box-shadow: 0 0 0 0 rgba(245,158,11,0.5); }
    50%     { box-shadow: 0 0 0 6px rgba(245,158,11,0); }
}
.pulse-dot.ok { background: var(--st-ok); animation-name: pulseDotOk; }
@keyframes pulseDotOk {
    0%,100% { box-shadow: 0 0 0 0 rgba(16,185,129,0.5); }
    50%     { box-shadow: 0 0 0 6px rgba(16,185,129,0); }
}

/* 加载旋转 */
.spinner {
    width: 18px; height: 18px;
    border: 2px solid rgba(99,102,241,0.2);
    border-top-color: var(--brand);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    display: inline-block;
    vertical-align: middle;
}
.spinner.lg { width: 32px; height: 32px; border-width: 3px; }
.spinner.white {
    border-color: rgba(255,255,255,0.3);
    border-top-color: #fff;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* 空状态 */
.empty-state {
    padding: 60px 24px;
    text-align: center;
    color: var(--muted);
}
.empty-state .empty-icon {
    font-size: 56px;
    margin-bottom: 16px;
    opacity: 0.5;
}
.empty-state h3 {
    font-size: 18px;
    margin-bottom: 8px;
    color: var(--text-sub);
}
.empty-state p { font-size: 14px; }

/* 键盘快捷键提示 */
.kbd {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 2px 8px;
    min-width: 22px;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 12px;
    font-weight: 500;
    color: var(--text-sub);
    background: var(--card-2);
    border: 1px solid var(--border);
    border-bottom-width: 2px;
    border-radius: 4px;
    line-height: 1.4;
}
.kbd-hint {
    font-size: 12px;
    color: var(--muted);
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

/* 小浮动按钮组 (回到顶部、主题切换) */
.fab-group {
    position: fixed;
    right: 20px;
    bottom: 20px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.fab {
    width: 44px; height: 44px;
    border-radius: 50%;
    background: var(--card);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-md);
    color: var(--text);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: all var(--t);
    font-size: 18px;
}
.fab:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-hover);
    color: var(--brand);
}
.fab:active { transform: translateY(0); }
.fab .ui-icon { width: 19px; height: 19px; }
.fab-primary {
    background: linear-gradient(135deg, var(--btn-primary), var(--brand-hover));
    color: #fff;
    border: none;
    box-shadow: var(--shadow-brand);
}
.fab-primary:hover { color: #fff; }

/* 暗黑模式补充适配 - 通用卡片和表单 */
[data-theme="dark"] .card,
[data-theme="dark"] .modal-content {
    background: var(--card);
    border-color: var(--border);
    color: var(--text);
}
[data-theme="dark"] h1,
[data-theme="dark"] h2,
[data-theme="dark"] h3,
[data-theme="dark"] h4,
[data-theme="dark"] h5,
[data-theme="dark"] .status-title,
[data-theme="dark"] .nav-title {
    color: var(--text);
}
[data-theme="dark"] label,
[data-theme="dark"] .form-label {
    color: var(--text-sub);
}
[data-theme="dark"] textarea,
[data-theme="dark"] input[type="text"],
[data-theme="dark"] input[type="number"],
[data-theme="dark"] input[type="password"],
[data-theme="dark"] input[type="email"],
[data-theme="dark"] input[type="search"],
[data-theme="dark"] select {
    background: var(--input-bg);
    border-color: var(--border);
    color: var(--text);
}
[data-theme="dark"] textarea:focus,
[data-theme="dark"] input:focus,
[data-theme="dark"] select:focus {
    border-color: var(--brand);
    box-shadow: 0 0 0 3px rgba(99,102,241,0.2);
    outline: none;
}
[data-theme="dark"] textarea::placeholder,
[data-theme="dark"] input::placeholder {
    color: var(--muted);
}
[data-theme="dark"] .ai-desc {
    background: var(--st-info-soft);
    border-color: var(--border);
    color: var(--text-sub);
}
[data-theme="dark"] .status-header { border-bottom-color: var(--border); }
[data-theme="dark"] .breadcrumb {
    background: var(--card-2);
    border-color: var(--border);
}
[data-theme="dark"] .modal-backdrop {
    background: rgba(0,0,0,0.7);
}

/* ---------- 响应式增强 ---------- */
/* 平板优化：768-1199px */
@media (max-width: 1199px) and (min-width: 768px) {
    .container { max-width: 100%; padding: 0 12px; }
    body { padding: 12px; }
}
/* 手机优化：<768px */
@media (max-width: 767px) {
    body { padding: 10px; }
    .container { padding: 0 8px; }
    h1 { font-size: 20px; margin-bottom: 20px; }
    .card { padding: 16px; border-radius: 10px; margin-bottom: 14px; }
    .row { gap: 10px; }
    .row .form-group { min-width: 100%; }
    .btn { padding: 9px 18px; font-size: 13px; }
    .btn-group { gap: 8px; }
    .toast-container { top: 10px; right: 10px; left: 10px; max-width: none; }
    .toast { min-width: 0; padding: 10px 14px; font-size: 13px; }
    .fab-group { right: 12px; bottom: 12px; }
    .fab { width: 40px; height: 40px; font-size: 16px; }
}
/* 超小屏：<480px */
@media (max-width: 479px) {
    body { padding: 8px; }
    .card { padding: 12px; }
    .btn { padding: 8px 14px; width: 100%; justify-content: center; }
    .btn-group .btn { flex: 1; }
}
/* 大屏优化：>1600px 提升最大宽度体验 */
@media (min-width: 1920px) {
    .container { max-width: 1800px; }
}

/* ---------- 可访问性：减少动画 ---------- */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* ---------- 文本选择颜色 ---------- */
::selection {
    background: var(--brand-soft);
    color: var(--brand-dark);
}
[data-theme="dark"] ::selection {
    background: rgba(99,102,241,0.3);
    color: #e0e7ff;
}

/* ---------- 全局焦点样式增强（可访问性） ---------- */
:focus-visible {
    outline: 2px solid var(--brand);
    outline-offset: 2px;
    border-radius: var(--r-sm);
}
button:focus-visible, .btn:focus-visible { outline-offset: 2px; }
