/* TOOLKIT Shared Components
   Button variants (Google Material 3), dialog buttons, toast notification.
   颜色变量自带默认值(自包含);页面若定义了 --md-sys-color-* 会覆盖默认。
*/
:root {
    --md-sys-color-primary: #0b57d0;
    --md-sys-color-on-primary: #fff;
    --md-sys-color-on-surface: #1f1f1f;
    --md-sys-color-surface-container-lowest: #fff;
}
[data-dark],
[data-theme="dark"] {
    --md-sys-color-primary: rgb(168 199 250);
    --md-sys-color-on-primary: rgb(6 46 111);
    --md-sys-color-on-surface: rgb(227 227 227);
    --md-sys-color-surface-container-lowest: rgb(14 14 14);
    --md-sys-color-primary-container: rgb(8 66 160);
}

/* ══════════════════════════════════════════════════════════════════
   Google Material 3 Filled Button — .btn-primary
   ══════════════════════════════════════════════════════════════════ */
.btn-primary {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
    min-width: 64px;
    height: 40px;
    padding: 0 24px;
    margin: 0;
    vertical-align: middle;
    overflow: hidden;

    border: none;
    border-radius: 20px;
    background-color: var(--md-sys-color-primary, #0b57d0);
    color: var(--md-sys-color-on-primary, #fff);
    box-shadow: none;

    font-family: "Google Sans", Roboto, Arial, sans-serif;
    font-size: 0.875rem;
    font-weight: 500;
    letter-spacing: 0;
    line-height: 1.4285714286;
    text-transform: none;
    text-decoration: none;
    white-space: nowrap;

    cursor: pointer;
    user-select: none;
    -webkit-appearance: none;
    outline: none;
    -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
    -webkit-font-smoothing: antialiased;
    will-change: transform, opacity;

    transition: background-color 0.28s cubic-bezier(0.4, 0, 0.2, 1),
                box-shadow 0.28s cubic-bezier(0.4, 0, 0.2, 1);
}

.btn-primary:hover {
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12), 0 1px 2px rgba(0, 0, 0, 0.08);
}

.btn-primary:active {
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12), 0 1px 2px rgba(0, 0, 0, 0.08);
}

.btn-primary:disabled {
    opacity: 0.38;
    cursor: not-allowed;
    box-shadow: none;
}

/* ══════════════════════════════════════════════════════════════════
   Google Material 3 Text Button — .btn-text
   ══════════════════════════════════════════════════════════════════ */
.btn-text {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
    min-width: 0;
    height: 40px;
    padding: 0 16px;
    margin: 0;
    vertical-align: middle;
    overflow: hidden;

    border: none;
    border-radius: 20px;
    background-color: transparent;
    color: var(--md-sys-color-primary, #0b57d0);
    outline: none;

    font-family: "Google Sans", Roboto, Arial, sans-serif;
    font-size: 0.875rem;
    font-weight: 500;
    letter-spacing: 0;
    line-height: 1.4285714286;
    text-transform: none;
    text-decoration: none;
    text-align: center;
    white-space: nowrap;

    cursor: pointer;
    user-select: none;
    -webkit-appearance: none;
    -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
    -webkit-font-smoothing: antialiased;
    will-change: transform, opacity;

    transition: background-color 0.2s ease;
}

.btn-text:hover {
    background-color: rgba(11, 87, 208, 0.06);
}

.btn-text:active {
    background-color: rgba(11, 87, 208, 0.14);
}

.btn-text:disabled {
    opacity: 0.38;
    cursor: not-allowed;
}

[data-dark] .btn-text:hover,
[data-theme="dark"] .btn-text:hover {
    background-color: rgba(168, 199, 250, 0.10);
}

[data-dark] .btn-text:active,
[data-theme="dark"] .btn-text:active {
    background-color: rgba(168, 199, 250, 0.18);
}

/* ══════════════════════════════════════════════════════════════════
   Ripple Effect
   ══════════════════════════════════════════════════════════════════ */
@keyframes ripple-anim {
    to {
        transform: scale(4);
        opacity: 0;
    }
}

.btn-primary .ripple,
.btn-text .ripple {
    position: absolute;
    border-radius: 50%;
    transform: scale(0);
    animation: ripple-anim 0.6s ease-out forwards;
    pointer-events: none;
}

.btn-primary .ripple {
    background-color: rgba(255, 255, 255, 0.28);
}

.btn-text .ripple {
    background-color: rgba(11, 87, 208, 0.18);
}

[data-dark] .btn-text .ripple,
[data-theme="dark"] .btn-text .ripple {
    background-color: rgba(168, 199, 250, 0.22);
}

/* ══════════════════════════════════════════════════════════════════
   未登录时的"登录"按钮 — 覆盖头像区(.user-avatar)为蓝色胶囊
   ══════════════════════════════════════════════════════════════════ */
.user-avatar.login-btn {
    width: auto;
    min-width: 76px;
    height: 40px;
    padding: 0 20px;
    border-radius: 20px;
    border: none;
    background: var(--md-sys-color-primary, #0b57d0);
    color: var(--md-sys-color-on-primary, #fff);
    font-family: "Google Sans", Roboto, Arial, sans-serif;
    font-size: 14px;
    font-weight: 500;
    letter-spacing: 0;
    text-transform: none;
    align-items: center;
    justify-content: center;
    box-shadow: none;
    transition: box-shadow .2s ease, background .2s ease;
}
.user-avatar.login-btn:hover {
    background: var(--md-sys-color-primary, #0b57d0);
    box-shadow: 0 1px 3px rgba(0, 0, 0, .12), 0 1px 2px rgba(0, 0, 0, .08);
}
.user-avatar.login-btn .login-text {
    display: inline-block;
    line-height: 1;
}

/* ══════════════════════════════════════════════════════════════════
   MD3 Dialogs — 结构 + 按钮(全量;变量带默认值,页面 token 可覆盖)
   ══════════════════════════════════════════════════════════════════ */
.dialog-overlay {
    position: fixed; inset: 0; z-index: 2000;
    background: color-mix(in srgb, var(--md-sys-color-scrim, rgba(0,0,0,.5)) 32%, transparent);
    display: none; align-items: center; justify-content: center;
    animation: dialogFadeIn .2s cubic-bezier(.2,0,0,1);
}
@keyframes dialogFadeIn { from { opacity: 0; } to { opacity: 1; } }
.dialog-overlay.open { display: flex; }
.dialog-box {
    background: var(--md-sys-color-surface-container-high, #e9eef6);
    color: var(--md-sys-color-on-surface, #1f1f1f);
    border-radius: 28px; padding: 24px;
    min-width: 360px; max-width: 440px;
    box-shadow: 0 1px 3px rgba(0,0,0,.3), 0 4px 8px rgba(0,0,0,.15);
    animation: dialogIn .28s cubic-bezier(.2,0,0,1);
}
@keyframes dialogIn { from { opacity: 0; transform: scale(.92) translateY(16px); } to { opacity: 1; transform: scale(1) translateY(0); } }
.dialog-box h3 { font-family: 'Google Sans', Roboto, Arial, sans-serif; font-size: 24px; font-weight: 400; margin: 0 0 20px; color: var(--md-sys-color-on-surface, #1f1f1f); }
.dialog-input-group { margin-bottom: 12px; }
.dialog-input-group label { display: block; font-size: 13px; color: var(--md-sys-color-on-surface-variant, #444746); margin-bottom: 6px; }
.dialog-input {
    width: 100%; padding: 14px 16px; border-radius: 12px;
    border: 1px solid var(--md-sys-color-outline-variant, #c4c7c5);
    font-family: Roboto, Arial, sans-serif; font-size: 16px;
    color: var(--md-sys-color-on-surface, #1f1f1f); background: var(--md-sys-color-surface-bright, #fff);
    outline: none; box-sizing: border-box;
    transition: border-color .15s cubic-bezier(.2,0,0,1), box-shadow .15s cubic-bezier(.2,0,0,1);
}
.dialog-input:hover { border-color: var(--md-sys-color-on-surface-variant, #444746); }
.dialog-input:focus { border-color: var(--md-sys-color-primary, #0b57d0); box-shadow: 0 0 0 2px var(--md-sys-color-primary-container, #d3e3fd); }
.dialog-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; margin-top: 24px; }
.dialog-btn {
    font-family: 'Google Sans', Roboto, Arial, sans-serif; font-size: 14px; font-weight: 500;
    padding: 10px 24px; border-radius: 999px; border: none; cursor: pointer;
    position: relative; overflow: hidden; min-height: 40px;
    transition: background .15s cubic-bezier(.2,0,0,1), box-shadow .25s cubic-bezier(.2,0,0,1);
    letter-spacing: .1px;
}
.dialog-btn-cancel { background: transparent; color: var(--md-sys-color-primary, #0b57d0); }
.dialog-btn-cancel:hover { background: color-mix(in srgb, var(--md-sys-color-primary, #0b57d0) 8%, transparent); }
.dialog-btn-save { background: var(--md-sys-color-primary, #0b57d0); color: var(--md-sys-color-on-primary, #fff); }
.dialog-btn-save:hover { background: color-mix(in srgb, var(--md-sys-color-on-primary, #fff) 8%, var(--md-sys-color-primary, #0b57d0)); box-shadow: 0 1px 2px rgba(0,0,0,.3), 0 1px 3px rgba(0,0,0,.15); }
.dialog-btn-save:active { background: color-mix(in srgb, var(--md-sys-color-on-primary, #fff) 12%, var(--md-sys-color-primary, #0b57d0)); }
.dialog-btn-danger { background: #ea4335; color: #fff; }
.dialog-btn-danger:hover { opacity: .85; }

/* ── Loading Spinner (CSS-only, inside buttons) ── */
.btn-spinner {
    display: inline-block; width: 20px; height: 20px;
    border: 2px solid rgba(255,255,255,.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: btn-spin .6s linear infinite;
    vertical-align: middle;
}
.btn-text .btn-spinner {
    border-color: rgba(11,87,208,.2);
    border-top-color: var(--md-sys-color-primary, #0b57d0);
}
@keyframes btn-spin { to { transform: rotate(360deg); } }

/* ══════════════════════════════════════════════════════════════════
   Toast Notification
   ══════════════════════════════════════════════════════════════════ */
.toast-bar {
    position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
    background: #323232; color: #fff; padding: 12px 24px;
    border-radius: 8px; font-size: 14px; z-index: 99999;
    opacity: 0; transition: opacity .25s; pointer-events: none;
    box-shadow: 0 3px 12px rgba(0,0,0,.4);
}
.toast-bar.show { opacity: 1; pointer-events: auto; }
.toast-bar.error { background: var(--md-error, #ea4335); }

/* ══════════════════════════════════════════════════════════════════
   Page Transition Progress Bar (Google 风格,不确定进度)
   页面跳转时顶部 4px 蓝色条:点击链接显示(transition.js 控制)
   ══════════════════════════════════════════════════════════════════ */
.top-progress {
    position: fixed;
    top: 0; left: 0; right: 0;
    height: 4px;
    z-index: 99999;
    /* 无轨道背景:只有一条指示线(Google 官方风格) */
    opacity: 0;
    pointer-events: none;
    transition: opacity .25s ease;
    overflow: hidden;
}
.top-progress.active { opacity: 1; }
.top-progress .bar {
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 100%;
    background: #4285f4; /* Google 蓝,比 primary #0b57d0 浅一档 */
    transform: scaleX(0);
    transform-origin: left center;
    animation: top-progress-slide 1.6s cubic-bezier(.4, 0, .2, 1) infinite;
}
[data-dark] .top-progress .bar,
[data-theme="dark"] .top-progress .bar {
    background: #a8c7fa; /* 深色下保持浅蓝 */
}
/* 官方不定长动画:从左端生长到全宽,再从右端缩回(无 track 的经典效果) */
@keyframes top-progress-slide {
    0%   { transform: scaleX(0);    transform-origin: left center; }
    45%  { transform: scaleX(1);    transform-origin: left center; }
    55%  { transform: scaleX(1);    transform-origin: right center; }
    100% { transform: scaleX(0);    transform-origin: right center; }
}

/* ══════════════════════════════════════════════════════════════════
   Responsive
   ══════════════════════════════════════════════════════════════════ */
@media (max-width: 400px) {
    .btn-primary,
    .btn-text {
        height: 36px;
        font-size: 0.8125rem;
    }
    .btn-primary { padding: 0 20px; }
    .btn-text   { padding: 0 12px; }
}
