/* ============================================================================
   HAADF-STEM 去卷积工具页 —— 深色产品化工作台
   设计规范：docs/DESIGN_SYSTEM.md（Dark / Product v3.0）
   - 所有颜色 / 间距 / 字号均来自 :root token，不出现魔法色值
   - 无外部资源：字体同域自托管，图标全部内联 SVG
   ========================================================================== */

/* ---- 自托管字体（拉丁 Inter 变量字体；中文回落到系统字体栈） ---- */
@font-face {
    font-family: 'Inter';
    src: local('Inter'), url('/assets/fonts/inter-latin-var.woff2') format('woff2');
    font-weight: 400 900;
    font-display: swap;
}

/* ---- Token ---- */
:root {
    color-scheme: dark;

    /* 背景层级 */
    --bg: #0a0d14;
    --bg-elev: #0f1420;
    --surface: #141b2b;
    --surface-2: #1a2333;
    --surface-3: #222c40;

    /* 描边 */
    --border: rgba(255, 255, 255, .08);
    --border-strong: rgba(255, 255, 255, .16);

    /* 文本 */
    --text: #e8eefc;
    --text-muted: #9aa7bd;
    --text-dim: #6b7891;

    /* 品牌 */
    --brand: #7c5cff;
    --brand-2: #22d3ee;
    --brand-grad: linear-gradient(135deg, #7c5cff 0%, #22d3ee 100%);
    --brand-soft: rgba(124, 92, 255, .14);
    --on-brand: #ffffff;

    /* 语义色 */
    --ok: #34d399;
    --warn: #fbbf24;
    --danger: #f87171;

    /* 形状与阴影 */
    --r-sm: 8px;
    --r-md: 12px;
    --r-lg: 18px;
    --r-xl: 26px;
    --shadow-1: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow-2: 0 12px 32px rgba(0, 0, 0, .42);
    --glow: 0 0 0 1px rgba(124, 92, 255, .35), 0 18px 60px -20px rgba(124, 92, 255, .55);

    /* 间距（4 的倍数） */
    --s-1: 4px;
    --s-2: 8px;
    --s-3: 12px;
    --s-4: 16px;
    --s-5: 24px;
    --s-6: 32px;
    --s-7: 48px;
    --s-8: 64px;

    /* 字号 */
    --t-xs: 12px;
    --t-sm: 13px;
    --t-base: 15px;
    --t-lg: 17px;
    --t-xl: 22px;
    --t-2xl: 30px;
    --t-3xl: 42px;
    --t-4xl: 56px;
    --lh: 1.65;

    /* 动效 */
    --ease: cubic-bezier(.22, .61, .36, 1);
    --dur: 180ms;
    --focus-ring: 0 0 0 3px rgba(124, 92, 255, .45);

    /* 工具页派生 token */
    --header-h: 56px;
    --sidebar-w: 320px;
    --grid-line: rgba(255, 255, 255, .045);
    --overlay: rgba(10, 13, 20, .78);
    --track: rgba(255, 255, 255, .06);
    --hover-tint: rgba(255, 255, 255, .04);
    --scrollbar: rgba(255, 255, 255, .14);
    --scrollbar-hover: rgba(255, 255, 255, .24);
    --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

/* ---- 基础 ---- */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    height: 100%;
}

body {
    min-height: 100%;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', 'Noto Sans CJK SC', sans-serif;
    font-size: var(--t-base);
    line-height: var(--lh);
    background: var(--bg);
    color: var(--text);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    overflow: hidden;
}

::selection {
    background: var(--brand-soft);
    color: var(--text);
}

a {
    color: var(--brand-2);
    text-decoration: none;
}

a:hover {
    color: var(--text);
}

:focus-visible {
    outline: 2px solid var(--brand-2);
    outline-offset: 2px;
}

/* 输入类控件用边框 + 光晕表达焦点，避免双描边 */
.input:focus-visible,
.select:focus-visible,
.radio input:focus-visible,
.toggle input:focus-visible,
.console__log:focus-visible {
    outline: none;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
    border: 0;
}

.skip-link {
    position: fixed;
    top: 0;
    left: 50%;
    z-index: 200;
    transform: translate(-50%, -150%);
    padding: var(--s-2) var(--s-4);
    border-radius: 0 0 var(--r-md) var(--r-md);
    background: var(--brand-grad);
    color: var(--on-brand);
    font-size: var(--t-sm);
    font-weight: 600;
    transition: transform var(--dur) var(--ease);
}

.skip-link:focus {
    transform: translate(-50%, 0);
    color: var(--on-brand);
}

/* ---- 应用骨架 ---- */
.app-shell {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
    min-height: 0;
    overflow: hidden;
}

/* ==========================================================================
   顶栏 56px：品牌 | 当前文件 | 主操作
   ========================================================================== */
.app-header {
    flex: 0 0 var(--header-h);
    display: flex;
    align-items: center;
    gap: var(--s-4);
    height: var(--header-h);
    padding: 0 var(--s-4);
    background: var(--bg-elev);
    border-bottom: 1px solid var(--border);
    position: relative;
    z-index: 20;
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: var(--s-3);
    flex: 0 0 auto;
    min-width: 0;
    color: var(--text);
}

.brand:hover {
    color: var(--text);
}

.brand__mark {
    display: grid;
    place-items: center;
    flex: 0 0 auto;
    width: 32px;
    height: 32px;
    border-radius: var(--r-sm);
    background: var(--brand-soft);
    border: 1px solid var(--border);
    color: var(--brand-2);
}

.brand__mark svg {
    width: 20px;
    height: 20px;
}

.brand__text {
    display: flex;
    flex-direction: column;
    justify-content: center;
    line-height: 1.25;
    min-width: 0;
}

.brand__title {
    font-size: var(--t-base);
    font-weight: 650;
    letter-spacing: -.01em;
    white-space: nowrap;
}

.brand__sub {
    font-size: var(--t-xs);
    color: var(--text-muted);
    letter-spacing: .04em;
    white-space: nowrap;
}

/* 当前文件 */
.file-pill {
    display: flex;
    align-items: center;
    gap: var(--s-2);
    flex: 1 1 180px;
    min-width: 0;
    max-width: 460px;
    height: 38px;
    padding: 0 var(--s-3);
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    color: var(--text-dim);
    transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}

.file-pill:focus-within {
    border-color: var(--brand);
    box-shadow: var(--focus-ring);
}

.file-pill__icon {
    flex: 0 0 auto;
    width: 15px;
    height: 15px;
}

.file-pill__input {
    flex: 1 1 auto;
    min-width: 0;
    background: none;
    border: 0;
    color: var(--text);
    font-family: inherit;
    font-size: var(--t-sm);
    text-overflow: ellipsis;
}

.file-pill__input:focus {
    outline: none;
}

.file-pill__input::placeholder {
    color: var(--text-muted);
}

.header-actions {
    display: flex;
    align-items: center;
    gap: var(--s-2);
    margin-left: auto;
    flex: 0 0 auto;
}

.header-user {
    margin-left: var(--s-1);
    padding: var(--s-1) var(--s-2);
    border-radius: var(--r-sm);
    color: var(--text-muted);
    font-size: var(--t-sm);
    white-space: nowrap;
}

.header-user:hover {
    color: var(--text);
    background: var(--hover-tint);
}

/* ==========================================================================
   按钮
   ========================================================================== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--s-2);
    height: 38px;
    padding: 0 var(--s-3);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    background: var(--surface-2);
    color: var(--text);
    font-family: inherit;
    font-size: var(--t-sm);
    font-weight: 600;
    line-height: 1;
    white-space: nowrap;
    cursor: pointer;
    transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease),
        transform var(--dur) var(--ease), box-shadow var(--dur) var(--ease), filter var(--dur) var(--ease);
}

.btn svg {
    flex: 0 0 auto;
    width: 15px;
    height: 15px;
}

.btn:hover {
    background: var(--surface-3);
    border-color: var(--border-strong);
}

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

.btn:focus-visible {
    outline: none;
    box-shadow: var(--focus-ring);
}

.btn--primary {
    border-color: transparent;
    background: var(--brand-grad);
    color: var(--on-brand);
    box-shadow: var(--shadow-2);
}

.btn--primary:hover {
    background: var(--brand-grad);
    border-color: transparent;
    filter: brightness(1.06);
}

.btn--danger {
    border-color: transparent;
    background: var(--danger);
    color: var(--on-brand);
}

.btn--sm {
    height: 32px;
    padding: 0 var(--s-2);
    border-radius: var(--r-sm);
    font-size: var(--t-xs);
}

.btn:disabled,
.btn[disabled] {
    opacity: .4;
    cursor: not-allowed;
    box-shadow: none;
    transform: none;
    filter: none;
}

.btn--ghost:disabled:hover {
    background: var(--surface-2);
    border-color: var(--border);
}

/* ==========================================================================
   主体两栏：左侧参数栏 + 中央工作区
   ========================================================================== */
.app-body {
    flex: 1 1 auto;
    display: grid;
    grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
    min-height: 0;
}

/* ---- 侧栏 ---- */
.sidebar {
    display: grid;
    grid-template-rows: minmax(0, 1fr) auto;
    min-height: 0;
    min-width: 0;
    background: var(--bg-elev);
    border-right: 1px solid var(--border);
}

.sidebar__scroll {
    display: flex;
    flex-direction: column;
    gap: var(--s-3);
    min-height: 0;
    padding: var(--s-4);
    overflow-y: auto;
    overscroll-behavior: contain;
}

.sidebar__foot {
    padding: var(--s-3) var(--s-4);
    background: var(--bg-elev);
    border-top: 1px solid var(--border);
}

/* ---- 可折叠面板（<details>，零 JS） ---- */
.panel {
    flex: 0 0 auto;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    overflow: hidden;
    transition: border-color var(--dur) var(--ease);
}

.panel:hover {
    border-color: var(--border-strong);
}

.panel__head {
    display: flex;
    align-items: center;
    gap: var(--s-2);
    padding: var(--s-3) var(--s-4);
    font-size: var(--t-sm);
    font-weight: 600;
    color: var(--text);
    cursor: pointer;
    list-style: none;
    user-select: none;
    transition: background var(--dur) var(--ease);
}

.panel__head::-webkit-details-marker {
    display: none;
}

.panel__head::marker {
    content: '';
}

.panel__head:hover {
    background: var(--hover-tint);
}

.panel__head:focus-visible {
    outline: none;
    box-shadow: inset var(--focus-ring);
}

.panel__head svg {
    flex: 0 0 auto;
    width: 15px;
    height: 15px;
    color: var(--brand-2);
}

.panel__head::after {
    content: '+';
    margin-left: auto;
    color: var(--text-dim);
    font-size: var(--t-base);
    font-weight: 500;
    line-height: 1;
}

.panel[open] .panel__head::after {
    content: '\2212';
}

.panel.is-collapsed .panel__body {
    display: none;
}

.panel__body {
    display: grid;
    gap: var(--s-3);
    padding: var(--s-3) var(--s-4) var(--s-4);
    border-top: 1px solid var(--border);
    min-width: 0;
}

/* ---- 表单 ---- */
.field {
    display: grid;
    gap: var(--s-1);
    min-width: 0;
}

.field__label {
    padding: 0;
    font-size: var(--t-xs);
    font-weight: 600;
    color: var(--text-muted);
    letter-spacing: .01em;
}

.field__row {
    display: flex;
    align-items: center;
    gap: var(--s-2);
    min-width: 0;
}

.field__row .input {
    flex: 1 1 auto;
    min-width: 0;
}

.field__hint {
    display: flex;
    align-items: center;
    gap: var(--s-2);
    font-size: var(--t-xs);
    color: var(--text-muted);
    line-height: 1.5;
}

.field-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: var(--s-3);
    min-width: 0;
}

.input,
.select {
    width: 100%;
    height: 36px;
    padding: 0 var(--s-2);
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--r-sm);
    color: var(--text);
    font-family: inherit;
    font-size: var(--t-sm);
    line-height: 1;
    transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease),
        box-shadow var(--dur) var(--ease);
}

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

.input:focus,
.select:focus {
    outline: none;
    border-color: var(--brand);
    box-shadow: var(--focus-ring);
    background: var(--surface-3);
}

.input:disabled,
.select:disabled {
    opacity: .4;
    cursor: not-allowed;
}

.input[readonly] {
    color: var(--text-muted);
}

.input.is-manual {
    border-color: var(--warn);
    color: var(--warn);
    background: var(--surface-3);
}

/* ---- 单选（算法） ---- */
.radio-set {
    display: grid;
    gap: var(--s-2);
    min-width: 0;
    border: 0;
}

.radio-set legend {
    margin-bottom: var(--s-1);
}

.radio {
    display: flex;
    align-items: center;
    gap: var(--s-2);
    padding: var(--s-2) var(--s-3);
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--r-sm);
    font-size: var(--t-sm);
    color: var(--text-muted);
    cursor: pointer;
    transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease), color var(--dur) var(--ease);
}

.radio:hover {
    background: var(--surface-3);
    border-color: var(--border-strong);
}

.radio:has(input:checked) {
    background: var(--brand-soft);
    border-color: var(--brand);
    color: var(--text);
}

.radio:focus-within {
    box-shadow: var(--focus-ring);
}

.radio input {
    flex: 0 0 auto;
    width: 15px;
    height: 15px;
    margin: 0;
    accent-color: var(--brand);
}

.radio input:checked+span {
    color: var(--text);
    font-weight: 600;
}

/* ---- 复选 ---- */
.toggle {
    display: flex;
    align-items: center;
    gap: var(--s-2);
    padding: var(--s-2) var(--s-3);
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--r-sm);
    font-size: var(--t-sm);
    color: var(--text-muted);
    cursor: pointer;
    transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease), color var(--dur) var(--ease);
}

.toggle:hover {
    background: var(--surface-3);
    border-color: var(--border-strong);
}

.toggle:has(input:checked) {
    color: var(--text);
}

.toggle:focus-within {
    box-shadow: var(--focus-ring);
}

.toggle input {
    flex: 0 0 auto;
    width: 16px;
    height: 16px;
    margin: 0;
    accent-color: var(--brand);
}

.toggle input:checked+span {
    color: var(--text);
    font-weight: 600;
}

.toggle input:disabled,
.radio input:disabled {
    opacity: .4;
    cursor: not-allowed;
}

.toggle:has(input:disabled) {
    opacity: .55;
    cursor: not-allowed;
}

.badge {
    display: inline-flex;
    align-items: center;
    padding: 0 var(--s-2);
    border-radius: 999px;
    background: var(--brand-soft);
    color: var(--brand-2);
    font-size: var(--t-xs);
    font-weight: 600;
    line-height: 1.7;
    white-space: nowrap;
}

/* ==========================================================================
   工作区：标签页 + 画布舞台 + 状态栏
   ========================================================================== */
.workspace {
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
    background: var(--bg);
}

.tabs {
    display: flex;
    align-items: stretch;
    gap: var(--s-1);
    flex: 0 0 auto;
    padding: 0 var(--s-4);
    background: var(--bg-elev);
    border-bottom: 1px solid var(--border);
    overflow-x: auto;
}

.tab-header {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: var(--s-2);
    padding: var(--s-3) var(--s-3) calc(var(--s-3) + 2px);
    background: none;
    border: 0;
    color: var(--text-muted);
    font-family: inherit;
    font-size: var(--t-sm);
    font-weight: 600;
    white-space: nowrap;
    cursor: pointer;
    transition: color var(--dur) var(--ease);
}

.tab-header svg {
    flex: 0 0 auto;
    width: 15px;
    height: 15px;
}

.tab-header::after {
    content: '';
    position: absolute;
    left: var(--s-2);
    right: var(--s-2);
    bottom: -1px;
    height: 2px;
    border-radius: 2px;
    background: transparent;
    transition: background var(--dur) var(--ease);
}

.tab-header:hover {
    color: var(--text);
}

.tab-header:focus-visible {
    outline: none;
    box-shadow: var(--focus-ring);
    border-radius: var(--r-sm);
}

.tab-header.active {
    color: var(--text);
}

.tab-header.active::after {
    background: var(--brand-grad);
}

.stage {
    position: relative;
    display: flex;
    flex: 1 1 auto;
    min-height: 0;
    min-width: 0;
}

.tab-content {
    flex: 1 1 auto;
    display: none;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
}

.tab-content.active {
    display: flex;
}

/* 每个 tab 的显示控件工具栏 */
.viewbar {
    display: flex;
    align-items: center;
    gap: var(--s-4);
    flex: 0 0 auto;
    flex-wrap: wrap;
    padding: var(--s-2) var(--s-4);
    background: var(--bg-elev);
    border-bottom: 1px solid var(--border);
}

.viewbar__group {
    display: flex;
    align-items: center;
    gap: var(--s-2);
    min-width: 0;
}

.viewbar__label {
    font-size: var(--t-xs);
    font-weight: 600;
    color: var(--text-muted);
    letter-spacing: .05em;
    text-transform: uppercase;
    white-space: nowrap;
}

.viewbar .select {
    width: auto;
    min-width: 96px;
    height: 30px;
    font-size: var(--t-xs);
}

/* 画布舞台：细网格纹理 */
.canvas-wrap {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 1 1 auto;
    min-height: 0;
    min-width: 0;
    padding: var(--s-4);
    overflow: hidden;
    background-color: var(--bg);
    background-image:
        radial-gradient(circle at 50% 0%, var(--brand-soft), transparent 55%),
        linear-gradient(to right, var(--grid-line) 1px, transparent 1px),
        linear-gradient(to bottom, var(--grid-line) 1px, transparent 1px);
    background-size: auto, 26px 26px, 26px 26px;
    background-position: center top, 0 0, 0 0;
}

.image-canvas {
    position: relative;
    z-index: 1;
    display: block;
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--r-sm);
    box-shadow: var(--shadow-2);
}

/* 尚无图像时隐藏空 canvas，让空态占位居中（绘制后 JS 会写入 width 属性） */
.image-canvas:not([width]) {
    display: none;
}

.image-placeholder {
    position: absolute;
    inset: var(--s-4);
    z-index: 0;
    display: grid;
    place-content: center;
    justify-items: center;
    gap: var(--s-2);
    padding: var(--s-4);
    border: 1px dashed var(--border-strong);
    border-radius: var(--r-lg);
    color: var(--text-muted);
    font-size: var(--t-sm);
    text-align: center;
    pointer-events: none;
}

.image-placeholder svg {
    width: 40px;
    height: 40px;
    opacity: .65;
}

.image-placeholder span {
    max-width: 34ch;
}

/* ==========================================================================
   底部状态栏：进度 + 可折叠日志
   ========================================================================== */
.statusbar {
    position: relative;
    z-index: 10;
    display: flex;
    align-items: center;
    gap: var(--s-4);
    flex: 0 0 auto;
    min-height: 60px;
    padding: var(--s-2) var(--s-4);
    background: var(--bg-elev);
    border-top: 1px solid var(--border);
}

.statusbar__progress {
    display: flex;
    align-items: center;
    gap: var(--s-3);
    flex: 1 1 auto;
    min-width: 0;
    max-width: 520px;
}

.progress {
    position: relative;
    flex: 1 1 auto;
    height: 6px;
    border-radius: var(--r-sm);
    background: var(--track);
    overflow: hidden;
}

.progress__bar {
    width: 0%;
    height: 100%;
    border-radius: inherit;
    background: var(--brand-grad);
    transition: width .3s var(--ease);
}

.progress__text {
    flex: 0 0 auto;
    min-width: 42px;
    font-family: var(--font-mono);
    font-size: var(--t-xs);
    font-weight: 600;
    color: var(--text);
    text-align: right;
}

.statusbar__hint {
    margin-left: auto;
    font-size: var(--t-xs);
    color: var(--text-muted);
    white-space: nowrap;
}

/* 运行日志：details 弹层，停留在状态栏上方 */
.console {
    flex: 0 0 auto;
}

.console__toggle {
    display: inline-flex;
    align-items: center;
    gap: var(--s-1);
    padding: var(--s-2) var(--s-3);
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--r-sm);
    color: var(--text-muted);
    font-size: var(--t-xs);
    font-weight: 600;
    white-space: nowrap;
    list-style: none;
    cursor: pointer;
    transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease), color var(--dur) var(--ease);
}

.console__toggle::-webkit-details-marker {
    display: none;
}

.console__toggle::marker {
    content: '';
}

.console__toggle::before {
    content: '\25B8';
    color: var(--text-dim);
    font-size: 10px;
    line-height: 1;
}

.console__toggle:hover {
    background: var(--surface-3);
    border-color: var(--border-strong);
    color: var(--text);
}

.console__toggle:focus-visible {
    outline: none;
    box-shadow: var(--focus-ring);
}

.console[open] .console__toggle {
    border-color: var(--brand);
    color: var(--text);
}

.console[open] .console__toggle::before {
    content: '\25BE';
}

.console__body {
    position: absolute;
    left: var(--s-4);
    right: var(--s-4);
    bottom: calc(100% + var(--s-2));
    z-index: 30;
    display: flex;
    height: 220px;
    padding: var(--s-2);
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: var(--r-lg);
    box-shadow: var(--shadow-2);
}

.console__log {
    flex: 1 1 auto;
    width: 100%;
    height: 100%;
    padding: var(--s-2) var(--s-3);
    background: var(--bg);
    border: 0;
    border-radius: var(--r-md);
    color: var(--text-muted);
    font-family: var(--font-mono);
    font-size: var(--t-xs);
    line-height: 1.7;
    resize: none;
    white-space: pre-wrap;
}

.console__log:focus {
    outline: none;
    box-shadow: var(--focus-ring);
}

/* ==========================================================================
   加载遮罩
   ========================================================================== */
.loading-overlay {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: none;
    align-items: center;
    justify-content: center;
    padding: var(--s-4);
    background: var(--overlay);
    backdrop-filter: blur(6px);
}

.loading-overlay.active {
    display: flex;
}

.loading-overlay__panel {
    display: grid;
    justify-items: center;
    gap: var(--s-3);
    padding: var(--s-5) var(--s-6);
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: var(--r-lg);
    box-shadow: var(--glow);
}

.loading-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--track);
    border-top-color: var(--brand);
    border-radius: 50%;
    animation: spin 900ms linear infinite;
}

.loading-text {
    font-size: var(--t-sm);
    color: var(--text-muted);
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* ==========================================================================
   滚动条
   ========================================================================== */
* {
    scrollbar-width: thin;
    scrollbar-color: var(--scrollbar) transparent;
}

::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--scrollbar);
    background-clip: content-box;
    border: 2px solid transparent;
    border-radius: var(--r-sm);
}

::-webkit-scrollbar-thumb:hover {
    background: var(--scrollbar-hover);
    background-clip: content-box;
}

/* ==========================================================================
   响应式
   ========================================================================== */

/* 768–1199px：侧栏收窄 */
@media (max-width: 1199px) {
    :root {
        --sidebar-w: 280px;
    }
}

/* <1024px：侧栏置顶，面板横向滚动 */
@media (max-width: 1023px) {
    .app-body {
        grid-template-columns: minmax(0, 1fr);
        grid-template-rows: auto minmax(0, 1fr);
    }

    .sidebar {
        height: 42vh;
        max-height: 42vh;
        overflow: hidden;
        border-right: 0;
        border-bottom: 1px solid var(--border);
    }

    .sidebar__scroll {
        flex-direction: row;
        align-items: stretch;
        padding: var(--s-3);
        overflow-x: auto;
        overflow-y: hidden;
        scroll-snap-type: x proximity;
    }

    .panel {
        flex: 0 0 272px;
        max-height: 100%;
        overflow-y: auto;
        scroll-snap-align: start;
    }

    .sidebar__foot {
        padding: var(--s-2) var(--s-3);
    }

    .sidebar__foot .field {
        grid-template-columns: auto minmax(0, 1fr);
        align-items: center;
        gap: var(--s-2);
    }

    .statusbar__hint {
        display: none;
    }

    .header-user {
        display: none;
    }
}

/* <900px：品牌文字收起，给「当前文件」留出空间 */
@media (max-width: 900px) {
    .app-header {
        gap: var(--s-2);
        padding: 0 var(--s-3);
    }

    .brand__text {
        position: absolute;
        width: 1px;
        height: 1px;
        margin: -1px;
        overflow: hidden;
        clip-path: inset(50%);
        white-space: nowrap;
    }

    .header-actions {
        gap: var(--s-1);
    }
}

/* <768px：顶栏图标化 + 侧栏置顶 */
@media (max-width: 767px) {
    .brand__mark {
        width: 30px;
        height: 30px;
    }

    .file-pill {
        flex: 1 1 auto;
        max-width: none;
        height: 34px;
        padding: 0 var(--s-2);
    }

    .header-actions .btn {
        width: 36px;
        height: 36px;
        padding: 0;
    }

    .header-actions .btn__label {
        position: absolute;
        width: 1px;
        height: 1px;
        margin: -1px;
        overflow: hidden;
        clip-path: inset(50%);
        white-space: nowrap;
    }

    .header-user {
        display: none;
    }

    .sidebar {
        height: 40vh;
        max-height: 40vh;
    }

    .panel {
        flex-basis: 250px;
        border-radius: var(--r-md);
    }

    .tabs {
        padding: 0 var(--s-2);
    }

    .tab-header {
        padding: var(--s-2) var(--s-2) calc(var(--s-2) + 2px);
        font-size: var(--t-xs);
    }

    .viewbar {
        display: grid;
        grid-template-columns: repeat(3, minmax(0, 1fr));
        align-items: end;
        gap: var(--s-2);
        padding: var(--s-2) var(--s-3);
    }

    .viewbar__group {
        display: grid;
        gap: 2px;
        min-width: 0;
    }

    .viewbar .select {
        width: 100%;
        min-width: 0;
    }

    .canvas-wrap {
        padding: var(--s-2);
    }

    .image-placeholder {
        inset: var(--s-2);
        border-radius: var(--r-md);
    }

    .statusbar {
        gap: var(--s-2);
        min-height: 56px;
        padding: var(--s-2) var(--s-3);
    }

    .console__body {
        left: var(--s-2);
        right: var(--s-2);
        height: 180px;
    }
}

@media (max-width: 420px) {
    .file-pill__icon {
        display: none;
    }

    .field-grid {
        gap: var(--s-2);
    }

    .progress__text {
        min-width: 36px;
    }
}

/* ==========================================================================
   无障碍：减少动效
   ========================================================================== */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: .01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: .01ms !important;
        scroll-behavior: auto !important;
    }

    .loading-spinner {
        animation: none;
    }
}
