/* ============================================
   CFBed Uploader 设计系统 v3.0
   依据：DESIGN.md（v3.0）
   规则：中性灰底 + 珊瑚橙/柠檬黄点缀；圆角 8/4/2px；浅阴影；内容左对齐；
        禁蓝紫渐变 / 毛玻璃 / 大圆角 / 纯黑底 / 装饰性动效。
   约定：令牌块内允许字面量；令牌块之外只允许 var(--token)。
   ============================================ */

/* ---------- 自托管字体：IBM Plex Mono（数据角色，latin + latin-ext）----------
   OFL-1.1，许可全文见 assets/fonts/OFL.txt。中文走系统栈，不做中文 Web 字体（§3.2）。
   这里不写 ?v= 版本号：模板里的 preload href 必须与下面的 url 逐字符一致才能命中缓存。 */
@font-face {
    font-family: "IBM Plex Mono";
    font-style: normal;
    font-weight: 400;
    font-display: swap;
    src: url("../fonts/ibm-plex-mono-latin-ext-400-normal.woff2") format("woff2");
    unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
    font-family: "IBM Plex Mono";
    font-style: normal;
    font-weight: 400;
    font-display: swap;
    src: url("../fonts/ibm-plex-mono-latin-400-normal.woff2") format("woff2");
    unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
    font-family: "IBM Plex Mono";
    font-style: normal;
    font-weight: 500;
    font-display: swap;
    src: url("../fonts/ibm-plex-mono-latin-ext-500-normal.woff2") format("woff2");
    unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
    font-family: "IBM Plex Mono";
    font-style: normal;
    font-weight: 500;
    font-display: swap;
    src: url("../fonts/ibm-plex-mono-latin-500-normal.woff2") format("woff2");
    unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
    font-family: "IBM Plex Mono";
    font-style: normal;
    font-weight: 600;
    font-display: swap;
    src: url("../fonts/ibm-plex-mono-latin-ext-600-normal.woff2") format("woff2");
    unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
    font-family: "IBM Plex Mono";
    font-style: normal;
    font-weight: 600;
    font-display: swap;
    src: url("../fonts/ibm-plex-mono-latin-600-normal.woff2") format("woff2");
    unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

:root {
    /* ---- 中性层（70%）---- */
    --bg: #F4F5F7;
    --bg-card: #FFFFFF;
    --bg-card-alt: #FAFBFC;
    --bg-hover: #F2F3F5;
    --border: #E5E6EB;
    --border-strong: #C9CDD4;
    --text-1: #1D2129;
    --text-2: #4E5A6B;
    --text-3: #86909C;

    /* ---- 点缀层（30%）---- */
    --primary: #F77234;
    --primary-hover: #E5621F;
    --primary-active: #D5571A;
    --primary-soft: #FEEFE6;
    --lemon: #FADC19;
    --lemon-soft: #FDF6D8;
    --success: #00B42A;
    --success-soft: #E8FFEA;
    --info: #0099FF;
    --info-strong: #0077E6;
    --info-soft: #E8F3FF;
    --warning: #D25F00;
    --warning-soft: #FFF7E8;
    --danger: #F53F3F;
    --danger-soft: #FFECE8;

    /* ---- 功能性颜色 ---- */
    --text-on-accent: #FFFFFF;
    --focus-ring: 0 0 0 3px rgba(247, 114, 52, 0.12);
    --overlay: rgba(29, 33, 41, 0.55);
    --scrollbar-thumb: #D5D8DE;

    /* ---- 侧栏（两主题同值：管理端恒为深色，是"你在管理区"的恒定视觉锚点）---- */
    --sidebar-bg: #1D2129;
    --sidebar-bg-alt: #171A1F;
    --sidebar-text-dim: #86909C;
    --sidebar-hover: rgba(255, 255, 255, 0.06);
    --sidebar-border: rgba(255, 255, 255, 0.08);

    /* ---- 字体 ---- */
    --font-ui: "PingFang SC", "HarmonyOS Sans SC", "MiSans", "Source Han Sans SC",
               "Noto Sans CJK SC", "Microsoft YaHei", sans-serif;
    --font-data: "IBM Plex Mono", ui-monospace, "Cascadia Mono", Consolas, monospace;

    /* ---- 字号（11 档收敛到 6 档）---- */
    --fs-xs: 12px;
    --fs-sm: 13px;
    --fs-md: 14px;
    --fs-lg: 16px;
    --fs-xl: 20px;
    --fs-2xl: 26px;

    /* ---- 行高 ---- */
    --lh-tight: 1.3;
    --lh-base: 1.6;
    --lh-compact: 1.45;

    /* ---- 间距（命名即 像素 ÷ 4）---- */
    --space-05: 2px;
    --space-1: 4px;
    --space-2: 8px;
    --space-3: 12px;
    --space-4: 16px;
    --space-6: 24px;
    --space-8: 32px;
    --space-12: 48px;

    /* ---- 圆角（嵌套必须递减：卡 8 / 钮 4 / 签 2）---- */
    --radius-card: 8px;
    --radius-btn: 4px;
    --radius-tag: 2px;
    --radius-pill: 999px;
    --radius-circle: 50%;

    /* ---- 阴影（三级）---- */
    --shadow-card: 0 1px 2px rgba(0, 0, 0, 0.04);
    --shadow-hover: 0 4px 12px rgba(0, 0, 0, 0.06);
    --shadow-float: 0 8px 24px rgba(0, 0, 0, 0.10);
    --shadow-knob: 0 1px 3px rgba(0, 0, 0, 0.2);

    /* ---- 时长（5 档收敛到 3 档）---- */
    --dur-fast: 150ms;
    --dur-base: 200ms;
    --dur-enter: 250ms;

    /* ---- 缓动（按用途分，不做全站统一）---- */
    --ease-standard: ease;
    --ease-out: cubic-bezier(0.2, 0, 0, 1);

    --transition: background var(--dur-fast) var(--ease-standard),
                  border-color var(--dur-fast) var(--ease-standard),
                  color var(--dur-fast) var(--ease-standard),
                  box-shadow var(--dur-fast) var(--ease-standard);
}

/* ============================================
   暗色主题：每个令牌必须同时给出暗色值，否则切到暗色会掉回浅色。
   成对书写、保持行序一致，方便肉眼比对。
   主色与状态色两主题同值，只改 soft 底色。
   ============================================ */
[data-theme="dark"] {
    --bg: #1F2329;
    --bg-card: #2A2D33;
    --bg-card-alt: #23262B;
    --bg-hover: #3A3D43;
    --border: #3A3D43;
    --border-strong: #4E5257;
    --text-1: #E5E6EB;
    --text-2: #B5B8BF;
    --text-3: #86909C;

    --primary-soft: #4A2A18;
    --lemon-soft: #4A4220;
    --success-soft: #1A3A1F;
    --info-soft: #16283A;
    --warning-soft: #3A2C18;
    --danger-soft: #4A1F1F;

    --info-strong: #4DA6FF;
    --warning: #E8A75C;

    --text-on-accent: #FFFFFF;
    --focus-ring: 0 0 0 3px rgba(247, 114, 52, 0.28);
    --overlay: rgba(0, 0, 0, 0.65);
    --scrollbar-thumb: #4A4E55;

    --shadow-card: 0 1px 2px rgba(0, 0, 0, 0.30);
    --shadow-hover: 0 4px 12px rgba(0, 0, 0, 0.40);
    --shadow-float: 0 8px 24px rgba(0, 0, 0, 0.50);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: var(--font-ui);
    background: var(--bg);
    color: var(--text-1);
    font-weight: 400;
    line-height: var(--lh-base);
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

/* 滚动条 */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--scrollbar-thumb); border-radius: var(--radius-tag); }
::-webkit-scrollbar-thumb:hover { background: var(--text-3); }

/* 通用链接 */
a { color: var(--info); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ============ 图标（内联 SVG 精灵）============
   规则见 DESIGN §8.1：24 视图框、fill:none、stroke:currentColor、1.5 线宽。
   颜色一律继承父级 color，天然适配两种主题；尺寸只这两档，同类按钮必须一致。 */
.icon {
    flex: 0 0 auto;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.5;
    stroke-linecap: round;
    stroke-linejoin: round;
    vertical-align: -0.125em;
}

/* 尺寸默认由 <svg width/height> 决定（icon() 的第二参数），
   下面三档只在需要 CSS 覆盖时使用，避免样式与属性两处打架。 */
.icon-sm { width: 13px; height: 13px; }
.icon-lg { width: 20px; height: 20px; }
.icon-xl { width: 40px; height: 40px; }
.icon-sprite { position: absolute; width: 0; height: 0; overflow: hidden; }

/* 按钮 / 链接里的图标跟文字同色同尺寸，不额外描边 */
.btn .icon { pointer-events: none; }

/* 加载态：16px 内联 SVG 匀速旋转（§7.3 明确不要大号旋转 loading） */
@keyframes spin {
    to { transform: rotate(360deg); }
}
.icon-spin { animation: spin 900ms linear infinite; }

/* ============ 顶栏 ============ */
.navbar {
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    padding: 0 var(--space-6);
    height: 56px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: none;
}

.nav-brand {
    font-size: var(--fs-lg);
    font-weight: 600;
    color: var(--text-1);
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

.nav-brand::before {
    content: "";
    width: 8px;
    height: 18px;
    background: var(--primary);
    border-radius: var(--radius-tag);
}

.nav-user {
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

.nav-user > span {
    color: var(--text-2);
    font-size: var(--fs-sm);
    font-weight: 400;
    max-width: 160px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    margin-right: var(--space-1);
}

/* ============ 按钮 ============ */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-4);
    border-radius: var(--radius-btn);
    font-size: var(--fs-md);
    font-weight: 400;
    font-family: inherit;
    cursor: pointer;
    transition: var(--transition);
    text-decoration: none !important;
    background: var(--bg-card);
    color: var(--text-1);
    border: 1px solid var(--border);
    line-height: var(--lh-compact);
}

.btn:hover {
    background: var(--bg-hover);
    border-color: var(--border-strong);
    color: var(--text-1);
}

.btn:active {
    transform: translateY(1px);
}

.btn:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

.btn-primary {
    background: var(--primary);
    border-color: var(--primary);
    color: var(--text-on-accent);
    font-weight: 600;
}

.btn-primary:hover {
    background: var(--primary-hover);
    border-color: var(--primary-hover);
    color: var(--text-on-accent);
}

.btn-primary:active {
    background: var(--primary-active);
    border-color: var(--primary-active);
}

.btn:disabled,
.btn.loading {
    opacity: 0.5;
    cursor: not-allowed;
    pointer-events: none;
}

.btn-sm {
    padding: var(--space-1) var(--space-3);
    font-size: var(--fs-sm);
}

.btn-ghost {
    background: transparent;
    border-color: transparent;
    color: var(--text-2);
}

.btn-ghost:hover {
    background: var(--bg-hover);
    border-color: transparent;
    color: var(--text-1);
}

/* 主题切换按钮：方形小图标按钮，跟其他 .btn-sm 风格一致 */
.theme-toggle {
    background: var(--bg-card);
    border: 1px solid var(--border);
    color: var(--text-1);
    width: 32px;
    height: 32px;
    padding: 0;
    border-radius: var(--radius-btn);
    cursor: pointer;
    line-height: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
}
.theme-toggle:hover {
    background: var(--bg-hover);
    border-color: var(--border-strong);
}
[data-theme="dark"] .theme-toggle:hover {
    border-color: var(--text-3);
}
/* 日/月图标：双形态内联 SVG，由 CSS 控制显隐。
   不写 textContent、不用 emoji 码点——编码或字体缺字都会变成方块。 */
.theme-toggle .icon { width: 16px; height: 16px; }
.theme-toggle .icon-sun { display: none; }
[data-theme="dark"] .theme-toggle .icon-sun { display: block; }
[data-theme="dark"] .theme-toggle .icon-moon { display: none; }

/* 网站图标（内联 SVG，原为 emoji）—— 顶部 nav 用 24px，侧边栏/登录页用 28-32px */
.brand-icon {
    height: 24px;
    width: 24px;
    object-fit: contain;
    flex-shrink: 0;
}
.brand-icon--lg {
    height: 32px;
    width: 32px;
}

.btn-danger {
    background: var(--bg-card);
    border-color: var(--danger);
    color: var(--danger);
}

.btn-danger:hover {
    background: var(--danger);
    border-color: var(--danger);
    color: var(--text-on-accent);
}

.btn-block {
    width: 100%;
    padding: var(--space-3);
    font-size: var(--fs-md);
}

/* 复制成功态 */
.btn.copied {
    border-color: var(--success);
    color: var(--success);
}

/* ============ 容器与卡片 ============ */
.container {
    max-width: 1080px;
    margin: 0 auto;
    padding: var(--space-6);
}

.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-card);
    padding: var(--space-6);
    box-shadow: var(--shadow-card);
}

/* 静态卡片不加悬停浮起：鼠标划过不是需要反馈的事件（DESIGN §1.3） */

/* ============ 表单 ============ */
.form-group {
    margin-bottom: var(--space-4);
}

.form-group label {
    display: block;
    margin-bottom: var(--space-1);
    font-size: var(--fs-sm);
    font-weight: 600;
    color: var(--text-2);
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: var(--space-2) var(--space-3);
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-btn);
    font-size: var(--fs-md);
    font-weight: 400;
    color: var(--text-1);
    transition: var(--transition);
    font-family: inherit;
}

.form-group input:hover,
.form-group select:hover,
.form-group textarea:hover {
    border-color: var(--border-strong);
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: var(--focus-ring);
}

.form-group input::placeholder {
    color: var(--text-3);
}

.form-group input:disabled {
    background: var(--bg-hover);
    color: var(--text-3);
    cursor: not-allowed;
}

.form-group small {
    display: block;
    margin-top: var(--space-1);
    font-size: var(--fs-xs);
    color: var(--text-3);
}

.form-error {
    color: var(--danger);
    font-size: var(--fs-xs);
    margin-top: var(--space-1);
    display: none;
}

.form-error.show { display: block; }

/* 同一条提示位既要报错也要报成功：底色与左边条必须一起切，
   否则会出现"绿字落在红底上"。 */
.error-msg.show { display: block; }
.error-msg.is-ok {
    color: var(--success);
    background: var(--success-soft);
    border-left-color: var(--success);
}

/* 密码强度条 */
.strength-meter {
    display: flex;
    gap: var(--space-1);
    margin-top: var(--space-2);
}

.strength-meter span {
    flex: 1;
    height: 3px;
    border-radius: var(--radius-tag);
    background: var(--border);
    transition: background var(--dur-base) var(--ease-standard);
}

.strength-meter.weak span:nth-child(1) { background: var(--danger); }
.strength-meter.medium span:nth-child(-n+2) { background: var(--lemon); }
.strength-meter.strong span { background: var(--success); }

.strength-text {
    font-size: var(--fs-xs);
    margin-top: var(--space-1);
    color: var(--text-3);
}

/* ============ 上传区域 ============ */
.upload-area {
    background: var(--bg-card-alt);
    border: 2px dashed var(--border-strong);
    border-radius: var(--radius-card);
    padding: var(--space-12) var(--space-8);
    text-align: center;
    cursor: pointer;
    transition: var(--transition);
    position: relative;
    overflow: hidden;
}

.upload-area:hover {
    border-color: var(--text-3);
}

/* 拖拽悬停：柠檬黄边框 + 淡黄背景 */
.upload-area.dragover {
    border-color: var(--lemon);
    background: var(--lemon-soft);
}

/* 上传区主图标：SVG 直接挂这个类（不是包一层 span）。
   emoji 是字形、靠 text-align 居中；SVG 是盒子，必须 margin auto。 */
.upload-icon {
    width: 40px;
    height: 40px;
    margin: 0 auto var(--space-3);
    display: block;
    color: var(--text-3);
}

.upload-content h2 {
    font-size: var(--fs-lg);
    font-weight: 600;
    margin-bottom: var(--space-1);
    color: var(--text-1);
}

.upload-content p {
    color: var(--text-3);
    margin-bottom: var(--space-4);
    font-size: var(--fs-sm);
}

/* ============ 上传队列 ============ */
.upload-queue {
    margin-top: var(--space-4);
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}

.queue-item {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-card);
    padding: var(--space-3) var(--space-4);
    display: flex;
    align-items: center;
    gap: var(--space-3);
    box-shadow: var(--shadow-card);
    animation: slideIn var(--dur-enter) var(--ease-out);
}

.queue-item.error { border-color: var(--danger); }
.queue-item.done { border-color: var(--success); }

.queue-thumb {
    width: 44px;
    height: 44px;
    border-radius: var(--radius-btn);
    object-fit: cover;
    flex-shrink: 0;
    background: var(--bg-hover);
    border: 1px solid var(--border);
}

.queue-info {
    flex: 1;
    min-width: 0;
}

.queue-name {
    font-size: var(--fs-sm);
    font-weight: 600;
    color: var(--text-1);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.queue-status {
    font-size: var(--fs-xs);
    color: var(--text-3);
    font-variant-numeric: tabular-nums;
}

.queue-item.error .queue-status { color: var(--danger); }
.queue-item.done .queue-status { color: var(--success); }

.queue-bar {
    margin-top: var(--space-1);
    height: 5px;
    background: var(--bg);
    border-radius: var(--radius-tag);
    overflow: hidden;
}

/* 进度条：珊瑚橙实心条 */
.queue-bar-fill {
    height: 100%;
    width: 0%;
    background: var(--primary);
    border-radius: var(--radius-tag);
    transition: width var(--dur-enter) var(--ease-standard);
}

.queue-item.done .queue-bar-fill { background: var(--success); }
.queue-item.error .queue-bar-fill { background: var(--danger); }

.queue-actions {
    display: flex;
    gap: var(--space-1);
    flex-shrink: 0;
}

/* ============ 上传结果卡片 ============ */
.results {
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
    margin-top: var(--space-6);
}

.result-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-card);
    padding: var(--space-4);
    display: flex;
    gap: var(--space-4);
    align-items: flex-start;
    box-shadow: var(--shadow-card);
    animation: slideIn var(--dur-enter) var(--ease-out);
}

.result-card.error {
    background: var(--danger-soft);
    border-color: var(--danger);
}

.result-preview {
    width: 112px;
    height: 112px;
    border-radius: var(--radius-btn);
    overflow: hidden;
    flex-shrink: 0;
    background: var(--bg-hover);
    border: 1px solid var(--border);
    cursor: zoom-in;
}

.result-preview img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.result-info {
    flex: 1;
    min-width: 0;
}

.result-filename {
    font-weight: 600;
    font-size: var(--fs-md);
    margin-bottom: var(--space-1);
    color: var(--text-1);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.result-meta {
    font-size: var(--fs-xs);
    color: var(--text-3);
    margin-bottom: var(--space-3);
    font-variant-numeric: tabular-nums;
}

.result-links {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}

.link-row {
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

.link-row span {
    font-size: var(--fs-xs);
    color: var(--text-3);
    min-width: 70px;
    font-weight: 400;
    flex-shrink: 0;
}

.link-row input {
    flex: 1;
    min-width: 0;
    padding: var(--space-1) var(--space-2);
    background: var(--bg-card-alt);
    border: 1px solid var(--border);
    border-radius: var(--radius-btn);
    font-size: var(--fs-xs);
    font-family: var(--font-data);
    color: var(--text-2);
    user-select: all;
}

.link-row input:focus {
    border-color: var(--primary);
    color: var(--text-1);
    outline: none;
}

.link-row button {
    padding: var(--space-1) var(--space-3);
    font-size: var(--fs-xs);
    white-space: nowrap;
}

/* ============ 我的记录（卡片网格） ============ */
.page-title {
    font-size: var(--fs-lg);
    font-weight: 600;
    color: var(--text-1);
    margin-bottom: var(--space-4);
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

.history-toolbar {
    display: flex;
    gap: var(--space-2);
    margin-bottom: var(--space-4);
    flex-wrap: wrap;
}

.history-toolbar input[type="text"],
.history-toolbar input[type="month"] {
    padding: var(--space-2) var(--space-3);
    border: 1px solid var(--border);
    border-radius: var(--radius-btn);
    background: var(--bg-card);
    color: var(--text-1);
    font-size: var(--fs-md);
    font-family: inherit;
    transition: var(--transition);
}

.history-toolbar input:hover { border-color: var(--border-strong); }
.history-toolbar input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: var(--focus-ring);
}

.history-toolbar input[type="text"] { flex: 1; min-width: 200px; }

/* 栅格间距 16px 24px */
.history-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: var(--space-4) var(--space-6);
}

.history-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-card);
    padding: var(--space-3);
    box-shadow: var(--shadow-card);
    transition: var(--transition);
    display: flex;
    flex-direction: column;
}

.history-card:hover {
    box-shadow: var(--shadow-hover);
    border-color: var(--border-strong);
}

.history-card-thumb {
    width: 100%;
    height: 150px;
    border-radius: var(--radius-btn);
    overflow: hidden;
    background: var(--bg-hover);
    border: 1px solid var(--border);
    cursor: zoom-in;
    margin-bottom: var(--space-2);
}

.history-card-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

/* 缩略图加载失败的兜底：容器铺满并居中，图标尺寸交给里面的 .icon-xl */
.no-thumb {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-3);
}

.history-card-body {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    flex: 1;
}

.history-card-title {
    font-size: var(--fs-sm);
    font-weight: 600;
    color: var(--text-1);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* 元数据冷数据：小字灰色靠左 */
.history-card-meta {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-05) var(--space-3);
    font-size: var(--fs-xs);
    font-variant-numeric: tabular-nums;
    color: var(--text-3);
    justify-content: flex-start;
}

.meta-views {
    color: var(--text-2);
    font-weight: 600;
}

/* 操作按钮常驻显示 */
.history-card-actions {
    display: flex;
    gap: var(--space-1);
    margin-top: auto;
    padding-top: var(--space-1);
}

.history-card-actions .btn {
    flex: 0 0 auto;
}

/* 兼容旧列表样式（设置页 Token 列表等） */
.history-list {
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
}

/* ============ 分页 ============ */
.pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: var(--space-3);
    margin-top: var(--space-6);
}

/* 管理端分页：底部右侧 */
.admin-main .pagination {
    justify-content: flex-end;
}

.pagination button {
    padding: var(--space-1) var(--space-3);
    font-size: var(--fs-sm);
}

.page-info {
    color: var(--text-3);
    font-size: var(--fs-sm);
    font-variant-numeric: tabular-nums;
}

/* ============ 空状态 / 加载 ============ */
.empty {
    text-align: center;
    padding: var(--space-12) var(--space-4);
    color: var(--text-3);
    font-size: var(--fs-md);
}

/* 空状态图标：容器只负责间距与透明度，尺寸交给里面的 .icon-xl */
.empty-icon {
    margin-bottom: var(--space-3);
    opacity: 0.6;
}

.loading {
    text-align: center;
    padding: var(--space-8);
    color: var(--text-3);
}

/* ============ Toast ============ */
.toast-wrap {
    position: fixed;
    bottom: 24px;
    right: 24px;
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    z-index: 2000;
}

.toast {
    padding: var(--space-3) var(--space-4);
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-card);
    box-shadow: var(--shadow-float);
    display: flex;
    align-items: center;
    gap: var(--space-2);
    font-size: var(--fs-sm);
    color: var(--text-1);
    max-width: 360px;
    animation: toastIn var(--dur-enter) var(--ease-out);
}

/* Toast 是瞬时状态条、不是内容卡片：色条保留但降到 2px（DESIGN §9.6） */
.toast-success { border-left: 2px solid var(--success); }
.toast-error   { border-left: 2px solid var(--danger); }
.toast-info    { border-left: 2px solid var(--info); }

.toast-icon { display: inline-flex; align-items: center; flex: 0 0 auto; }
.toast-success .toast-icon { color: var(--success); }
.toast-error   .toast-icon { color: var(--danger); }
.toast-info    .toast-icon { color: var(--info); }
.toast-text { min-width: 0; overflow-wrap: anywhere; }

.toast-out {
    opacity: 0;
    transform: translateY(8px);
    transition: opacity var(--dur-enter) var(--ease-standard),
                transform var(--dur-enter) var(--ease-standard);
}

@keyframes toastIn {
    from { opacity: 0; transform: translateY(16px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* ============ 灯箱 ============ */
.lightbox {
    position: fixed;
    inset: 0;
    background: var(--overlay);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 3000;
    cursor: zoom-out;
}

.lightbox.open { display: flex; }

.lightbox img {
    max-width: 92vw;
    max-height: 92vh;
    border-radius: var(--radius-card);
    box-shadow: var(--shadow-float);
    animation: lightboxIn var(--dur-enter) var(--ease-out);
}

@keyframes lightboxIn {
    from { opacity: 0; transform: scale(0.96); }
    to   { opacity: 1; transform: scale(1); }
}

/* ============ 登录 / 注册 ============ */
.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg);
}

.login-container {
    width: 100%;
    max-width: 400px;
    padding: var(--space-4);
}

.login-box {
    background: var(--bg-card);
    border: 1px solid var(--border);
    padding: 36px 32px;
    border-radius: var(--radius-card);
    box-shadow: var(--shadow-card);
}

.login-box h1 {
    font-size: var(--fs-xl);
    font-weight: 600;
    color: var(--text-1);
    margin-bottom: var(--space-1);
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

/* 标题下珊瑚橙短条，替代渐变装饰 */
.login-box h1::after {
    content: "";
    flex: 1;
    height: 3px;
    width: auto;
    max-width: 32px;
    background: var(--primary);
    border-radius: var(--radius-tag);
}

.subtitle {
    color: var(--text-3);
    margin-bottom: var(--space-6);
    font-size: var(--fs-sm);
    text-align: left;
}

.login-form .form-group {
    margin-bottom: var(--space-4);
}

.remember-row {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    margin-bottom: var(--space-4);
    font-size: var(--fs-sm);
    color: var(--text-2);
    user-select: none;
}

.remember-row input[type="checkbox"] {
    width: 15px;
    height: 15px;
    accent-color: var(--primary);
    cursor: pointer;
}

.error-msg {
    color: var(--danger);
    font-size: var(--fs-sm);
    margin-top: var(--space-3);
    display: none;
    padding: var(--space-2) var(--space-3);
    background: var(--danger-soft);
    border-radius: var(--radius-btn);
    border-left: 2px solid var(--danger);
}

/* ============ 管理后台 ============ */
.admin-page {
    display: flex;
    min-height: 100vh;
    background: var(--bg);
}

/* 侧边栏：恒深色，不跟随主题翻转（DESIGN §2.2） */
.admin-sidebar {
    width: 220px;
    background: var(--sidebar-bg);
    display: flex;
    flex-direction: column;
    position: fixed;
    height: 100vh;
}

/* 暗色模式下侧边栏要比页面背景更深，保持层次（非纯黑） */
/* 暗色下侧栏比页面更深，保持层次；两主题同值，是"你在管理区"的恒定信号 */

.sidebar-brand {
    padding: var(--space-4);
    font-size: var(--fs-lg);
    font-weight: 600;
    color: var(--text-on-accent);
    border-bottom: 1px solid var(--sidebar-border);
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

.sidebar-brand::before {
    content: "";
    width: 8px;
    height: 18px;
    background: var(--primary);
    border-radius: var(--radius-tag);
}

.sidebar-nav {
    flex: 1;
    padding: var(--space-3) 0;
}

.sidebar-nav a {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-3) var(--space-4);
    color: var(--sidebar-text-dim);
    text-decoration: none !important;
    font-size: var(--fs-md);
    font-weight: 400;
    transition: var(--transition);
    border-left: 3px solid transparent;
}

.sidebar-nav a:hover {
    color: var(--text-on-accent);
    background: var(--sidebar-hover);
}

/* 选中：白色文字 + 珊瑚橙左竖条 */
.sidebar-nav a.active {
    color: var(--text-on-accent);
    background: var(--sidebar-hover);
    border-left-color: var(--primary);
    font-weight: 600;
}

.sidebar-footer {
    padding: var(--space-3) var(--space-4);
    border-top: 1px solid var(--sidebar-border);
}

.sidebar-footer a {
    color: var(--sidebar-text-dim);
    text-decoration: none !important;
    font-size: var(--fs-sm);
    display: block;
    padding: var(--space-1) 0;
}

.sidebar-footer a:hover { color: var(--text-on-accent); }

.admin-main {
    margin-left: 220px;
    flex: 1;
    padding: var(--space-6);
    min-width: 0;
}

.admin-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--space-4);
    gap: var(--space-3);
    flex-wrap: wrap;
}

.admin-header-left {
    display: flex;
    align-items: center;
    gap: var(--space-4);
}

.admin-header h1 {
    font-size: var(--fs-lg);
    font-weight: 600;
    color: var(--text-1);
}

.admin-header-right {
    display: flex;
    gap: var(--space-2);
    align-items: center;
}

.admin-header-right input[type="text"],
.admin-header-right select {
    padding: var(--space-2) var(--space-3);
    border: 1px solid var(--border);
    border-radius: var(--radius-btn);
    background: var(--bg-card);
    color: var(--text-1);
    font-size: var(--fs-sm);
    font-family: inherit;
    transition: var(--transition);
}

.admin-header-right input:hover,
.admin-header-right select:hover { border-color: var(--border-strong); }

.admin-header-right input:focus,
.admin-header-right select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: var(--focus-ring);
}

/* 仪表盘卡片：左对齐、紧凑 */
.dashboard-cards {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: var(--space-4) var(--space-6);
    margin-bottom: var(--space-6);
}

.dashboard-cards .card {
    padding: var(--space-4);
}

.card-number {
    font-size: var(--fs-2xl);
    font-weight: 600;
    color: var(--text-1);
    margin-bottom: var(--space-05);
    line-height: var(--lh-tight);
    font-variant-numeric: tabular-nums;
}

.card-label {
    color: var(--text-3);
    font-size: var(--fs-sm);
    font-weight: 400;
}

/* ============ 表格（高密度后台） ============ */
.table-container {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-card);
    overflow-x: auto;
    box-shadow: var(--shadow-card);
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    min-width: 640px;
}

.data-table th,
.data-table td {
    padding: var(--space-2) var(--space-3);
    height: 46px;
    text-align: left;
    border-bottom: 1px solid var(--border);
    font-size: var(--fs-sm);
    color: var(--text-1);
    vertical-align: middle;
    font-variant-numeric: tabular-nums;
    line-height: var(--lh-compact);
}

.data-table th {
    background: var(--bg-card-alt);
    font-size: var(--fs-xs);
    font-weight: 600;
    color: var(--text-2);
    border-bottom: 1px solid var(--border);
}

/* 斑马纹辅助阅读 */
.data-table tbody tr:nth-child(even) td {
    background: var(--bg-card-alt);
}

.data-table tbody tr:hover td {
    background: var(--primary-soft);
}

.data-table tr:last-child td {
    border-bottom: none;
}

.data-table .btn {
    margin-right: var(--space-1);
}

.data-table .btn:last-child {
    margin-right: 0;
}

/* 徽章：2px 锐角 */
.badge {
    display: inline-flex;
    align-items: center;
    padding: var(--space-05) var(--space-2);
    border-radius: var(--radius-tag);
    font-size: var(--fs-xs);
    font-weight: 600;
    line-height: var(--lh-base);
}

.badge.admin {
    background: var(--primary-soft);
    color: var(--primary-active);
}

.badge.user {
    background: var(--bg-hover);
    color: var(--text-2);
}

.badge.active {
    background: var(--success-soft);
    color: var(--success);
}

.badge.inactive {
    background: var(--danger-soft);
    color: var(--danger);
}

/* ============ 弹窗 ============ */
.modal {
    position: fixed;
    inset: 0;
    background: var(--overlay);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1500;
    animation: fadeIn var(--dur-base) var(--ease-standard);
    padding: 20px;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to   { opacity: 1; }
}

.modal-content {
    background: var(--bg-card);
    border: 1px solid var(--border);
    padding: var(--space-6);
    border-radius: var(--radius-card);
    width: 100%;
    max-width: 440px;
    box-shadow: var(--shadow-float);
    animation: slideUp var(--dur-enter) var(--ease-out);
}

@keyframes slideUp {
    from { opacity: 0; transform: translateY(16px); }
    to   { opacity: 1; transform: translateY(0); }
}

.modal-content h3 {
    margin-bottom: var(--space-4);
    font-size: var(--fs-lg);
    font-weight: 600;
    color: var(--text-1);
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: var(--space-2);
    margin-top: var(--space-6);
}

@keyframes slideIn {
    from { opacity: 0; transform: translateY(-6px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* ============================================
   v3.0 移动端响应式
   断点体系：
     ≤1024px  平板（管理后台侧栏改抽屉）
     ≤768px   手机（导航折叠 / 表格卡片化 / 弹窗底部抽屉 / 两列变单列）
     ≤480px   小屏手机（进一步压缩间距与字号）
   原则：桌面样式不动，改动一律新增或包在 media query 内
   ============================================ */

/* ---------- 0. 全断点基础增强 ---------- */

/* 防 iOS 横屏字号被放大；长内容不撑破容器 */
body {
    -webkit-text-size-adjust: 100%;
}

img {
    max-width: 100%;
}

/* ---------- 1. 新增通用组件（桌面基线） ---------- */

/* 1.1 移动端汉堡按钮（前台导航），桌面隐藏 */
.nav-toggle {
    display: none;
    width: 40px;
    height: 40px;
    flex: 0 0 auto;
    align-items: center;
    justify-content: center;
    padding: 0;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-btn);
    color: var(--text-1);
    line-height: 1;
    font-family: inherit;
    cursor: pointer;
    transition: var(--transition);
}

.nav-toggle:hover {
    background: var(--bg-hover);
    border-color: var(--border-strong);
}

.nav-toggle:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

/* 1.2 管理后台抽屉按钮与遮罩，桌面隐藏 */
.sidebar-toggle {
    display: none;
    width: 40px;
    height: 40px;
    flex: 0 0 auto;
    align-items: center;
    justify-content: center;
    padding: 0;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-btn);
    color: var(--text-1);
    line-height: 1;
    font-family: inherit;
    cursor: pointer;
    transition: var(--transition);
}

.sidebar-toggle:hover {
    background: var(--bg-hover);
    border-color: var(--border-strong);
}

.sidebar-toggle:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

.sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: var(--overlay);
    z-index: 1150;
}

/* 1.3 开关 switch：56×30 iOS 风格滑块 */
.switch {
    position: relative;
    display: inline-block;
    width: 56px;
    height: 30px;
    flex: 0 0 auto;
    vertical-align: middle;
}

.switch input {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    margin: 0;
    opacity: 0;
    cursor: pointer;
    z-index: 2;
}

.switch-slider {
    position: absolute;
    inset: 0;
    background: var(--border-strong);
    border-radius: var(--radius-pill);
    pointer-events: none;
    transition: background var(--dur-base) var(--ease-standard);
}

.switch-slider::after {
    content: "";
    position: absolute;
    top: 3px;
    left: 3px;
    width: 24px;
    height: 24px;
    border-radius: var(--radius-circle);
    background: var(--text-on-accent);
    box-shadow: var(--shadow-knob);
    transition: transform var(--dur-base) var(--ease-standard);
}

.switch input:checked + .switch-slider {
    background: var(--primary);
}

.switch input:checked + .switch-slider::after {
    transform: translateX(26px);
}

.switch input:focus-visible + .switch-slider {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

.switch input:disabled + .switch-slider {
    opacity: 0.5;
}

/* 1.4 分段选择器 segmented：等分三列单选 */
.segmented {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: var(--space-2);
}

.segmented > label {
    position: relative;
    display: block;
    cursor: pointer;
    min-width: 0;
}

.segmented > label > input {
    position: absolute;
    width: 1px;
    height: 1px;
    opacity: 0;
    margin: 0;
}

.segmented > label > span {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: var(--space-05);
    min-height: 44px;
    padding: var(--space-2) var(--space-3);
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-btn);
    font-size: var(--fs-sm);
    font-weight: 600;
    color: var(--text-2);
    text-align: center;
    transition: var(--transition);
}

.segmented > label > span small {
    display: block;
    font-size: var(--fs-xs);
    font-weight: 400;
    line-height: var(--lh-compact);
    color: var(--text-3);
}

.segmented > label:hover > span {
    background: var(--bg-hover);
    border-color: var(--border-strong);
}

.segmented > label > input:checked + span {
    background: var(--primary-soft);
    border-color: var(--primary);
    color: var(--primary-active);
}

.segmented > label > input:checked + span small {
    color: var(--primary-active);
}

.segmented > label > input:focus-visible + span {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

.segmented > label > input:disabled + span {
    opacity: 0.5;
    cursor: not-allowed;
}

/* 1.5 模式说明卡 */
.mode-card {
    position: relative;
    background: var(--bg-card-alt);
    border: 1px solid var(--border);
    border-radius: var(--radius-card);
    padding: var(--space-3) var(--space-4);
    font-size: var(--fs-sm);
    line-height: var(--lh-base);
    color: var(--text-2);
    transition: var(--transition);
    overflow-wrap: anywhere;
}

.mode-card strong,
.mode-card h4 {
    display: block;
    margin-bottom: var(--space-1);
    font-size: var(--fs-sm);
    font-weight: 600;
    color: var(--text-1);
}

.mode-card.active {
    background: var(--primary-soft);
    border-color: var(--primary);
}

/* 左上角对勾：内联 SVG data URI，不依赖字体缺字 */
.mode-card.active::before {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    width: 22px;
    height: 22px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--primary) url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23fff' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M4.8 12.6 9.6 17.4 19.2 7.2'/%3E%3C/svg%3E") center/12px 12px no-repeat;
    border-radius: var(--radius-card) 0 var(--radius-tag) 0;
}

.mode-card.active > :first-child {
    padding-left: 26px;
}

/* 1.6 徽章补充色（形状复用 .badge） */
.badge.global {
    background: var(--info-soft);
    color: var(--info-strong);
}

.badge.warn {
    background: var(--warning-soft);
    color: var(--warning);
}

/* 1.7 两列栅格 */
.grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-4);
}

/* 1.8 窄容器（设置页等） */
.container-narrow {
    max-width: 560px;
    margin: 0 auto;
}

/* 1.9 端显隐工具类 */
.mobile-only {
    display: none;
}

/* 1.10 输入框 + 右侧按钮组合（Token 明文切换等） */
.input-with-action {
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

.input-with-action input,
.input-with-action select {
    flex: 1 1 auto;
    min-width: 0;
}

.input-with-action .btn {
    flex: 0 0 auto;
    white-space: nowrap;
}

/* ---------- 2. ≤1024px 平板：后台侧栏改抽屉 ---------- */
@media (max-width: 1024px) {
    .sidebar-toggle {
        display: inline-flex;
    }

    /* 侧边栏变左侧抽屉 */
    .admin-sidebar {
        position: fixed;
        left: 0;
        top: 0;
        height: 100%;
        width: 240px;
        max-width: 82vw;
        z-index: 1200;
        transform: translateX(-100%);
        transition: transform var(--dur-enter) var(--ease-out);
        box-shadow: var(--shadow-float);
        overflow-y: auto;
    }

    .admin-sidebar.open {
        transform: translateX(0);
    }

    .sidebar-backdrop.show {
        display: block;
    }

    /* 抽屉模式下正文占满宽度 */
    .admin-main {
        margin-left: 0;
    }

    /* 抽屉里恢复纵向导航与底部区块 */
    .sidebar-nav {
        display: block;
        overflow-x: visible;
        padding: var(--space-3) 0;
    }

    .sidebar-nav a {
        border-left: 3px solid transparent;
        border-bottom: none;
        white-space: normal;
        min-height: 44px;
    }

    .sidebar-nav a.active {
        border-left-color: var(--primary);
    }

    .sidebar-footer {
        display: block;
    }
}

/* ---------- 3. 769–1024px 平板专属栅格 ---------- */
@media (min-width: 769px) and (max-width: 1024px) {
    .history-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .dashboard-cards {
        grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    }
}

/* ---------- 4. ≤768px 手机 ---------- */
@media (max-width: 768px) {

    /* 4.1 容器与间距 */
    .container {
        padding: var(--space-4) var(--space-3);
    }

    .container-narrow {
        max-width: 100%;
        padding: var(--space-4);
    }

    .card {
        padding: var(--space-4);
    }

    .admin-main {
        padding: var(--space-4) var(--space-3);
    }

    .grid-2 {
        grid-template-columns: 1fr;
        gap: var(--space-3);
    }

    /* 4.2 端显隐工具类 */
    .mobile-only {
        display: block;
    }

    .desktop-only {
        display: none;
    }

    /* 4.3 前台导航折叠 */
    .navbar {
        flex-wrap: wrap;
        height: auto;
        min-height: 56px;
        padding: var(--space-2) var(--space-3);
        gap: var(--space-2);
    }

    .nav-brand {
        flex: 1 1 auto;
        min-width: 0;
        font-size: var(--fs-md);
    }

    .nav-toggle {
        display: inline-flex;
    }

    /* 默认收起，加 .open 展开为整宽纵向面板 */
    .nav-user {
        display: none;
        flex: 0 0 100%;
        width: 100%;
        flex-direction: column;
        align-items: stretch;
        gap: 0;
        margin-top: var(--space-1);
        padding-top: var(--space-05);
        border-top: 1px solid var(--border);
    }

    .nav-user.open {
        display: flex;
        animation: navPanelIn var(--dur-base) var(--ease-standard);
    }

    .nav-user .nav-username,
    .nav-user > span {
        width: 100%;
        max-width: none;
        margin: 0;
        padding: var(--space-2) var(--space-1);
        white-space: normal;
        overflow: visible;
        text-overflow: clip;
        border-bottom: 1px solid var(--border);
    }

    .nav-user > .btn {
        width: 100%;
        min-height: 44px;
        justify-content: flex-start;
        padding: var(--space-2) var(--space-1);
        font-size: var(--fs-md);
        background: transparent;
        border: none;
        border-bottom: 1px solid var(--border);
        border-radius: 0;
    }

    .nav-user > .btn:hover {
        background: var(--bg-hover);
    }

    .nav-user > .btn:last-child {
        border-bottom: none;
    }

    /* 4.4 表单：16px 防 iOS 自动缩放 + 44px 触控高度 */
    input:not([type="checkbox"]):not([type="radio"]):not([type="file"]):not([type="range"]),
    select,
    textarea,
    .form-group input:not([type="checkbox"]):not([type="radio"]),
    .form-group select,
    .form-group textarea,
    .history-toolbar input[type="text"],
    .history-toolbar input[type="month"],
    .admin-header-right input[type="text"],
    .admin-header-right select,
    .link-row input {
        /* 16px 是 iOS 不触发自动缩放的下限，恰好等于 --fs-lg */
        font-size: var(--fs-lg);
        min-height: 44px;
    }

    textarea {
        min-height: 88px;
    }

    /* 开关/单选的隐藏 input 不受上面高度影响 */
    .switch input,
    .segmented > label > input {
        min-height: 0;
    }

    .history-toolbar,
    .admin-header-right {
        width: 100%;
        flex-wrap: wrap;
    }

    .history-toolbar input[type="text"],
    .admin-header-right input[type="text"] {
        flex: 1 1 100%;
        min-width: 0;
    }

    /* 4.5 按钮触控目标 */
    .btn {
        min-height: 40px;
    }

    .btn-sm {
        min-height: 40px;
        padding: var(--space-2) var(--space-4);
        font-size: var(--fs-md);
    }

    .link-row button {
        min-height: 40px;
        padding: var(--space-2) var(--space-3);
        font-size: var(--fs-sm);
    }

    /* 4.6 上传区与队列 */
    .upload-area {
        padding: var(--space-8) var(--space-4);
    }

    .upload-content h2 {
        font-size: var(--fs-xl);
    }

    .upload-content p {
        margin-bottom: var(--space-4);
    }

    .queue-item {
        flex-wrap: wrap;
        gap: var(--space-2) var(--space-3);
        padding: var(--space-3);
    }

    .queue-info {
        flex: 1 1 60%;
    }

    .queue-actions {
        width: 100%;
        justify-content: flex-end;
    }

    /* 结果卡片纵向 */
    .result-card {
        flex-direction: column;
        gap: var(--space-3);
    }

    .result-preview {
        width: 100%;
        height: 200px;
    }

    .link-row {
        flex-wrap: wrap;
        gap: var(--space-1) var(--space-2);
    }

    .link-row span {
        min-width: 0;
        flex: 1 1 100%;
    }

    .link-row input {
        flex: 1 1 auto;
    }

    /* 4.7 历史记录栅格 */
    .history-grid {
        grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
        gap: var(--space-3);
    }

    .history-card-thumb {
        height: 120px;
    }

    /* 4.8 后台头部 */
    .admin-header {
        align-items: flex-start;
    }

    .admin-header-left {
        gap: var(--space-2);
        width: 100%;
    }

    .admin-header h1 {
        font-size: var(--fs-lg);
    }

    .dashboard-cards {
        grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
        gap: var(--space-3);
    }

    .dashboard-cards .card {
        padding: var(--space-3) var(--space-4);
    }

    .card-number {
        font-size: var(--fs-xl);
    }

    /* 4.9 数据表格卡片化（td 由页面层带 data-label） */
    .table-container {
        background: transparent;
        border: none;
        box-shadow: none;
        /* 兜底：极端宽内容仍可横向滚动 */
        overflow-x: auto;
    }

    .data-table {
        min-width: 0;
        border-collapse: separate;
        border-spacing: 0;
    }

    .data-table thead {
        display: none;
    }

    .data-table tbody,
    .data-table tr,
    .data-table td {
        display: block;
    }

    .data-table tbody tr {
        display: block;
        background: var(--bg-card);
        border: 1px solid var(--border);
        border-radius: var(--radius-card);
        margin-bottom: var(--space-3);
        padding: var(--space-2) var(--space-3);
        box-shadow: var(--shadow-card);
    }

    .data-table tbody tr:last-child {
        margin-bottom: 0;
    }

    .data-table tbody tr td,
    .data-table tbody tr:nth-child(even) td,
    .data-table tbody tr:hover td {
        display: flex;
        flex-wrap: wrap;
        align-items: center;
        justify-content: space-between;
        gap: var(--space-2) var(--space-3);
        height: auto;
        min-height: 0;
        padding: var(--space-1) 0;
        border: none;
        background: transparent;
        text-align: right;
        font-size: var(--fs-sm);
        overflow-wrap: anywhere;
    }

    .data-table td::before {
        content: attr(data-label);
        flex: 0 0 auto;
        color: var(--text-3);
        font-size: var(--fs-xs);
        font-weight: 400;
        text-align: left;
    }

    /* 无 data-label 的单元格（如空状态 colspan）居中显示 */
    .data-table td:not([data-label])::before {
        content: none;
    }

    .data-table td:not([data-label]) {
        justify-content: center;
        text-align: center;
    }

    /* 操作列：按钮组右对齐、可换行 */
    .data-table td .btn {
        margin-right: 0;
    }

    .data-table td .btn:first-of-type {
        margin-left: auto;
    }

    /* 4.10 分页 */
    .pagination,
    .admin-main .pagination {
        flex-wrap: wrap;
        justify-content: center;
        gap: var(--space-2);
    }

    /* 4.11 弹窗改底部抽屉 */
    .modal {
        padding: 0;
        align-items: flex-end;
    }

    .modal-content {
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100%;
        max-width: 100%;
        max-height: 85vh;
        overflow-y: auto;
        overflow-wrap: anywhere;
        padding: var(--space-4);
        border: none;
        border-radius: var(--radius-card) var(--radius-card) 0 0;
        animation: sheetUp var(--dur-enter) var(--ease-out);
    }

    .modal-actions {
        margin-top: var(--space-4);
    }

    .modal-actions .btn {
        flex: 1 1 auto;
    }

    /* 4.12 Toast：左右留白 + 避开底部横条 */
    .toast-wrap {
        left: var(--space-3);
        right: var(--space-3);
        bottom: var(--space-3);
    }

    .toast {
        max-width: 100%;
        overflow-wrap: anywhere;
    }

    /* 4.13 灯箱 */
    .lightbox img {
        max-width: 92vw;
        max-height: 80vh;
    }

    /* 4.14 长内容防溢出 */
    .card,
    .mode-card,
    .history-card-meta,
    .result-meta {
        overflow-wrap: anywhere;
    }

    /* 4.15 登录页 */
    .login-container {
        padding: var(--space-4);
    }

    .login-box {
        padding: var(--space-6) var(--space-4);
    }
}

/* ---------- 5. ≤480px 小屏手机 ---------- */
@media (max-width: 480px) {
    .container {
        padding: var(--space-3) var(--space-2);
    }

    .container-narrow {
        padding: var(--space-3) var(--space-2);
    }

    .admin-main {
        padding: var(--space-3) var(--space-2);
    }

    .card {
        padding: var(--space-3);
    }

    .page-title,
    .admin-header h1 {
        font-size: var(--fs-lg);
    }

    .upload-area {
        padding: var(--space-6) var(--space-3);
    }

    .upload-icon {
        width: 32px;
        height: 32px;
    }

    .upload-content h2 {
        font-size: var(--fs-lg);
    }

    /* 单列历史记录 */
    .history-grid {
        grid-template-columns: 1fr;
        gap: var(--space-2);
    }

    .history-card-thumb {
        height: 160px;
    }

    .dashboard-cards {
        grid-template-columns: 1fr;
    }

    /* 表格单元格改纵向堆叠 */
    .data-table tbody tr td,
    .data-table tbody tr:nth-child(even) td,
    .data-table tbody tr:hover td {
        flex-direction: column;
        align-items: flex-start;
        justify-content: flex-start;
        gap: var(--space-05);
        text-align: left;
    }

    .data-table td .btn:first-of-type {
        margin-left: 0;
    }

    .data-table td[data-label] .btn {
        flex: 0 0 auto;
    }

    /* 分段选择器改纵向 */
    .segmented {
        grid-template-columns: 1fr;
        gap: var(--space-1);
    }

    .modal-content {
        padding: var(--space-4) var(--space-3);
    }

    .modal-actions {
        flex-wrap: wrap;
    }

    .toast {
        font-size: var(--fs-sm);
    }

    .empty {
        padding: var(--space-8) var(--space-3);
    }
}

/* ---------- 6. 安全区适配（刘海屏 / 底部横条） ---------- */
@supports (padding: env(safe-area-inset-bottom)) {
    body {
        padding-bottom: env(safe-area-inset-bottom);
    }

    .toast-wrap {
        bottom: calc(var(--space-6) + env(safe-area-inset-bottom));
    }

    .sidebar-footer {
        padding-bottom: calc(var(--space-3) + env(safe-area-inset-bottom));
    }

    @media (max-width: 768px) {
        .navbar {
            padding-left: calc(var(--space-3) + env(safe-area-inset-left));
            padding-right: calc(var(--space-3) + env(safe-area-inset-right));
        }

        .modal-content {
            padding-bottom: calc(var(--space-4) + env(safe-area-inset-bottom));
        }

        .toast-wrap {
            bottom: calc(var(--space-3) + env(safe-area-inset-bottom));
        }
    }
}

/* ---------- 7. 动画 ---------- */
@keyframes navPanelIn {
    from { opacity: 0; transform: translateY(-6px); }
    to   { opacity: 1; transform: translateY(0); }
}

@keyframes sheetUp {
    from { transform: translateY(100%); }
    to   { transform: translateY(0); }
}

/* ============================================
   v3.0 新增组件
   仅补 DESIGN §1.1 要求但原文件缺失的两处：
   ① 记录页的「网格 / 列表」视图切换（列表视图 1.45 行高 + 8/12 内边距）
   ② 图标按钮的尺寸收敛（导航栏与侧栏同类按钮必须一致）
   ============================================ */

/* ---------- 视图切换（复用 .segmented 的选中态语言）---------- */
.view-switch {
    display: inline-flex;
    gap: 0;
    border: 1px solid var(--border);
    border-radius: var(--radius-btn);
    overflow: hidden;
    background: var(--bg-card);
}

.view-switch button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-1);
    min-height: 34px;
    padding: 0 var(--space-3);
    background: transparent;
    border: 0;
    border-radius: 0;
    color: var(--text-3);
    font-family: inherit;
    font-size: var(--fs-sm);
    cursor: pointer;
    transition: var(--transition);
}

.view-switch button + button {
    border-left: 1px solid var(--border);
}

.view-switch button:hover {
    background: var(--bg-hover);
    color: var(--text-1);
}

.view-switch button[aria-pressed="true"] {
    background: var(--primary-soft);
    color: var(--primary-active);
    font-weight: 600;
}

.view-switch button:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: -2px;
}

/* ---------- 列表视图：行高紧凑（1.45 + 8/12）---------- */
.history-grid.is-list {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}

.history-grid.is-list .history-card {
    flex-direction: row;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-2) var(--space-3);
}

.history-grid.is-list .history-card-thumb {
    width: 56px;
    height: 56px;
    margin-bottom: 0;
    flex: 0 0 auto;
}

.history-grid.is-list .history-card-body {
    flex-direction: row;
    align-items: center;
    gap: var(--space-3);
    line-height: var(--lh-compact);
}

.history-grid.is-list .history-card-title {
    flex: 1 1 auto;
    min-width: 0;
}

.history-grid.is-list .history-card-meta {
    flex: 0 0 auto;
}

.history-grid.is-list .history-card-actions {
    margin-top: 0;
    padding-top: 0;
    flex: 0 0 auto;
}

/* 列表视图下隐藏低频元数据，保住一行的信息密度 */
.history-grid.is-list .history-card-meta .meta-type {
    display: none;
}

/* ---------- 窄屏：列表视图退化为两行 ---------- */
@media (max-width: 768px) {
    .history-grid.is-list .history-card {
        flex-wrap: wrap;
    }

    .history-grid.is-list .history-card-body {
        flex-direction: column;
        align-items: flex-start;
        gap: var(--space-1);
        flex: 1 1 60%;
    }

    .history-grid.is-list .history-card-actions {
        width: 100%;
        justify-content: flex-end;
    }
}

/* ============================================
   v3.0 组件类：承接模板里原来的内联 style
   依据 DESIGN §2.3-4 / §9.5：PHP 只输出结构与数据，不输出颜色值。
   命名即令牌名（mt-4 = margin-top: var(--space-4)），不发明新刻度。
   ============================================ */
.mt-2 { margin-top: var(--space-2); }
.mt-3 { margin-top: var(--space-3); }
.mt-4 { margin-top: var(--space-4); }
.mt-6 { margin-top: var(--space-6); }
.mb-2 { margin-bottom: var(--space-2); }
.mb-3 { margin-bottom: var(--space-3); }
.mb-4 { margin-bottom: var(--space-4); }
.mb-6 { margin-bottom: var(--space-6); }

.card-title {
    font-size: var(--fs-lg);
    font-weight: 600;
    color: var(--text-1);
    margin-bottom: var(--space-4);
}
.card-note {
    color: var(--text-2);
    font-size: var(--fs-sm);
    line-height: var(--lh-base);
}
.text-muted { color: var(--text-3); }
.text-dim { color: var(--text-2); }
.mono { font-family: var(--font-data); }
.text-xs { font-size: var(--fs-xs); }
.text-sm { font-size: var(--fs-sm); }
.text-strong { font-weight: 600; }
.text-danger { color: var(--danger); }
.text-success { color: var(--success); }
.form-inline { padding: var(--space-2) 0; }
.field-static { background: var(--bg-hover); color: var(--text-3); }
.hr { border: 0; border-top: 1px solid var(--border); margin: var(--space-6) 0; }
.badge-row {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
    align-items: center;
}
.loading-block { width: 100%; }
/* 卡片内的底部操作行：左侧动作 + 右侧结果文字，用分隔线与正文断开 */
.card-actions {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    margin-top: var(--space-2);
    padding-top: var(--space-4);
    border-top: 1px solid var(--border);
    flex-wrap: wrap;
}
/* 空状态占满整个网格（原先写在模板的内联 style 里）*/
.empty-block { grid-column: 1 / -1; }

/* ---------- 认证页 ---------- */
.auth-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--space-2);
}
.auth-head h1 { margin: 0; }
.auth-alt {
    text-align: center;
    margin-top: var(--space-4);
    font-size: var(--fs-md);
    color: var(--text-2);
}
.auth-alt a { color: var(--info); text-decoration: none; }
.auth-alt a:hover { text-decoration: underline; }
/* 登录页底部的次要入口（注册 / 联系管理员） */
.auth-actions {
    margin-top: var(--space-4);
    padding-top: var(--space-4);
    border-top: 1px solid var(--border);
    font-size: var(--fs-sm);
    color: var(--text-3);
    text-align: left;
}

/* ---------- 个人设置：Token 列表 ---------- */
.token-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-3);
    border: 1px solid var(--border);
    border-radius: var(--radius-card);
    margin-bottom: var(--space-2);
    background: var(--bg-hover);
}
.token-item-main { min-width: 0; }
.token-item-name { font-weight: 600; font-size: var(--fs-md); }
.token-item-preview { font-size: var(--fs-xs); color: var(--text-3); margin-top: var(--space-1); }
.token-item-state { font-size: var(--fs-xs); color: var(--success); margin-top: var(--space-05); }
.token-empty { color: var(--text-3); padding: var(--space-3) 0; text-align: center; }
.token-global-hint { margin-bottom: var(--space-2); }
.token-global-preview { font-family: var(--font-data); font-size: var(--fs-xs); color: var(--text-3); margin-left: var(--space-2); }

/* ---------- 管理端：近 7 天趋势图 ---------- */
.trend {
    display: flex;
    align-items: flex-end;
    gap: var(--space-2);
    height: 140px;
}
.trend-col { flex: 1; text-align: center; }
.trend-count {
    font-size: var(--fs-xs);
    color: var(--text-1);
    font-weight: 600;
    margin-bottom: var(--space-1);
    font-variant-numeric: tabular-nums;
}
.trend-bar {
    background: var(--primary);
    border-radius: var(--radius-tag) var(--radius-tag) 0 0;
    margin: 0 auto;
    width: 60%;
}
.trend-day {
    font-size: var(--fs-xs);
    color: var(--text-3);
    margin-top: var(--space-1);
    font-variant-numeric: tabular-nums;
}

/* ---------- 表格：单元格窄化与不换行 ---------- */
.cell-clip { max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cell-actions { white-space: nowrap; }
.cell-empty { text-align: center; color: var(--text-3); padding: var(--space-8) var(--space-3); }
.cell-empty-error { text-align: center; color: var(--danger); padding: var(--space-8) var(--space-3); }

/* ---------- 行内提示条（内部工具页 / 表单顶部说明）---------- */
.alert-note {
    display: flex;
    gap: var(--space-2);
    align-items: flex-start;
    padding: var(--space-3);
    border: 1px solid var(--warning);
    border-radius: var(--radius-btn);
    background: var(--warning-soft);
    color: var(--warning);
    font-size: var(--fs-sm);
    line-height: var(--lh-base);
    margin-bottom: var(--space-6);
}
.alert-note .icon { margin-top: 1px; }
.alert-note strong { display: block; margin-bottom: var(--space-1); font-weight: 600; }
.alert-note.is-ok {
    border-color: var(--success);
    background: var(--success-soft);
    color: var(--success);
}
.alert-note.is-error {
    border-color: var(--danger);
    background: var(--danger-soft);
    color: var(--danger);
}
.note-plain {
    color: var(--text-2);
    font-size: var(--fs-sm);
    line-height: var(--lh-base);
}
.note-plain strong { color: var(--danger); }

/* ---------- 复选框 / 开关行：复选框与说明文字同排 ----------
   .form-group 内的 label 默认 display:block，这里必须用两段选择器
   （.form-group .check-row 权重 0-2-0）才能压过 .form-group label（0-1-1）。 */
.check-row,
.form-group .check-row {
    display: flex;
    align-items: center;
    gap: var(--space-2);
}
/* 同理：.form-group input 默认 width:100%，复选框要还原成固有宽度 */
.check-row input[type="checkbox"] {
    width: auto;
    flex: 0 0 auto;
    accent-color: var(--primary);
}

/* ---------- 多选下拉（权限选择）：给一个可见的展开高度 ---------- */
.select-multi {
    min-height: 100px;
}

/* ---------- 初始隐藏的模态：用 hidden 属性而不是内联 style ---------- */
.modal[hidden] { display: none; }

