/* 编辑式基础：以排版、边界和留白分层；兼容旧令牌名，避免业务组件因换肤失效。 */
:root {
    color-scheme: light;
    --bg-start: #f7f7f2;
    --bg-end: #f7f7f2;
    --surface: #ffffff;
    --surface-strong: #ffffff;
    --surface-muted: #f0f2eb;
    --surface-flat: #ffffff;
    --primary: #236552;
    --primary-strong: #194b3d;
    --primary-soft: #d7f2d9;
    --on-primary: #ffffff;
    --text: #172824;
    --text-muted: #5d6b66;
    --text-faint: #5d6b66;
    --success: #236552;
    --success-soft: #e4f3e6;
    --warning: #825010;
    --warning-soft: #fff0d9;
    --danger: #a33636;
    --danger-soft: #fae8e5;
    --info: #28577b;
    --info-soft: #e7eff6;
    --border: #dce2da;
    --border-strong: #7c9085;
    --highlight: transparent;
    --shadow-dark: rgba(23, 40, 36, 0.14);
    --shadow-raised: 0 16px 48px var(--shadow-dark);
    --shadow-large: var(--shadow-raised);
    --shadow-soft: none;
    --shadow-small: none;
    --shadow-inset: none;
    --focus: #236552;
    --radius-xl: 20px;
    --radius-lg: 12px;
    --radius-md: 8px;
    --radius-sm: 8px;
    --radius-pill: 999px;
    --space-1: 4px;
    --space-2: 8px;
    --space-3: 12px;
    --space-4: 16px;
    --space-5: 24px;
    --space-6: 32px;
    --space-7: 48px;
    --space-8: 64px;
    --ease: 180ms cubic-bezier(0.22, 0.61, 0.36, 1);
    --ease-state: 320ms cubic-bezier(0.22, 0.61, 0.36, 1);
    --font-sans: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
    --font-mono: ui-monospace, "Cascadia Code", "SFMono-Regular", Consolas, monospace;
    --z-nav: 20;
    --z-toast: 40;
    --z-dialog: 50;
}

:root[data-theme="dark"] {
    color-scheme: dark;
    --bg-start: #111916;
    --bg-end: #111916;
    --surface: #19231f;
    --surface-strong: #202d26;
    --surface-muted: #202d26;
    --surface-flat: #19231f;
    --primary: #b9e8c8;
    --primary-strong: #cef5d9;
    --primary-soft: #2a4233;
    --on-primary: #122218;
    --text: #edf3ed;
    --text-muted: #b0bdb4;
    --text-faint: #b0bdb4;
    --success: #b9e8c8;
    --success-soft: #263d30;
    --warning: #f1c98f;
    --warning-soft: #3e3222;
    --danger: #f1b0ab;
    --danger-soft: #3c2826;
    --info: #b5d4f0;
    --info-soft: #253747;
    --border: #35473b;
    --border-strong: #879a8b;
    --shadow-dark: rgba(0, 0, 0, 0.32);
    --focus: #b9e8c8;
}

@media (prefers-color-scheme: dark) {
    :root[data-theme="auto"] {
        color-scheme: dark;
        --bg-start: #111916;
        --bg-end: #111916;
        --surface: #19231f;
        --surface-strong: #202d26;
        --surface-muted: #202d26;
        --surface-flat: #19231f;
        --primary: #b9e8c8;
        --primary-strong: #cef5d9;
        --primary-soft: #2a4233;
        --on-primary: #122218;
        --text: #edf3ed;
        --text-muted: #b0bdb4;
        --text-faint: #b0bdb4;
        --success: #b9e8c8;
        --success-soft: #263d30;
        --warning: #f1c98f;
        --warning-soft: #3e3222;
        --danger: #f1b0ab;
        --danger-soft: #3c2826;
        --info: #b5d4f0;
        --info-soft: #253747;
        --border: #35473b;
        --border-strong: #879a8b;
        --shadow-dark: rgba(0, 0, 0, 0.32);
        --focus: #b9e8c8;
    }
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

html {
    min-width: 320px;
    min-height: 100%;
    background: var(--bg-end);
    scroll-behavior: smooth;
}

body {
    min-height: 100vh;
    margin: 0;
    color: var(--text);
    background: var(--bg-start);
    font-family: var(--font-sans);
    font-size: 16px;
    line-height: 1.55;
    text-rendering: optimizeLegibility;
    -webkit-font-smoothing: antialiased;
}

button,
input,
select,
textarea {
    font: inherit;
}

/* 原生占位文字在暗色表面过暗；统一主题颜色并移除浏览器默认半透明。 */
input::placeholder,
textarea::placeholder {
    color: var(--text-muted);
    opacity: 1;
}

button,
[role="button"] {
    touch-action: manipulation;
}

button:not(:disabled),
[role="button"]:not([aria-disabled="true"]) {
    cursor: pointer;
}

button:disabled,
[aria-disabled="true"] {
    cursor: not-allowed;
    opacity: 0.58;
}

a {
    color: var(--primary-strong);
    text-underline-offset: 0.18em;
}

/* 大标题在窄屏与文字放大时平衡断行，避免末行只剩一个字。 */
h1,
h2 {
    text-wrap: balance;
}

img,
svg {
    max-width: 100%;
}

.icon,
.ui-icon {
    width: 1.15rem;
    height: 1.15rem;
    flex: 0 0 auto;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
}

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

:where(a, button, input, select, textarea, summary, [tabindex]):focus-visible {
    outline: 3px solid var(--focus);
    outline-offset: 3px;
}

.soft-card,
.ui-card {
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    background: var(--surface);
    box-shadow: var(--shadow-soft);
}

.ui-card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: var(--space-5);
}

.button,
.btn,
.primary-button,
.icon-button,
.ui-button {
    min-height: 44px;
    border-radius: var(--radius-md);
    transition: transform var(--ease), box-shadow var(--ease), border-color var(--ease), background-color var(--ease), color var(--ease), opacity var(--ease);
}

@media (hover: hover) and (pointer: fine) {
    .button:not(:disabled):hover,
    .btn:not(:disabled):hover,
    .primary-button:not(:disabled):hover,
    .icon-button:not(:disabled):hover,
    .ui-button:not(:disabled):hover,
    .soft-card.is-interactive:hover,
    .ui-card.is-interactive:hover {
        transform: translateY(-1px);
        border-color: var(--border-strong);
    }
}

.button:not(:disabled):active,
.btn:not(:disabled):active,
.primary-button:not(:disabled):active,
.icon-button:not(:disabled):active,
.ui-button:not(:disabled):active,
.soft-card.is-interactive:active,
.ui-card.is-interactive:active {
    transform: translateY(1px);
}

.ui-field {
    width: 100%;
    min-height: 44px;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    color: var(--text);
    background: var(--surface);
    box-shadow: var(--shadow-inset);
    transition: border-color var(--ease), box-shadow var(--ease), background-color var(--ease);
}

.ui-field[aria-invalid="true"] {
    border-color: var(--danger);
}

.ui-field:focus {
    border-color: var(--primary);
}

.table-shell,
.ui-table-shell {
    width: 100%;
    overflow-x: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    background: var(--surface-flat);
    box-shadow: var(--shadow-small);
    overscroll-behavior-inline: contain;
}

.ui-table-shell table {
    width: 100%;
    border-collapse: collapse;
}

.ui-table-shell thead {
    position: sticky;
    top: 0;
    z-index: 1;
    background: var(--surface-strong);
}

.ui-table-shell th,
.ui-table-shell td {
    padding: 12px 14px;
    border-bottom: 1px solid var(--border);
    text-align: left;
    vertical-align: middle;
}

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

.toast-region,
.ui-toast-region {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: var(--z-toast);
    display: grid;
    width: min(380px, calc(100vw - 32px));
    gap: 8px;
    pointer-events: none;
}

.toast,
.ui-toast {
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    justify-self: end;
    width: fit-content;
    max-width: min(320px, 100%);
    gap: 8px;
    min-height: 40px;
    padding: 6px 10px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    color: var(--text);
    background: var(--surface-strong);
    box-shadow: var(--shadow-small);
    font-size: 0.875rem;
    line-height: 1.35;
    pointer-events: auto;
    animation: ui-toast-in var(--ease) both;
}

.ui-toast-icon {
    width: 18px;
    height: 18px;
}

.ui-toast-message {
    min-width: 0;
    overflow-wrap: anywhere;
}

.ui-toast[data-type="success"],
.toast.success {
    border-color: color-mix(in srgb, var(--success) 55%, transparent);
}

.ui-toast[data-type="error"],
.toast.error {
    border-color: color-mix(in srgb, var(--danger) 62%, transparent);
}

.ui-toast-close {
    display: grid;
    width: 32px;
    min-height: 32px;
    padding: 0;
    place-items: center;
    border: 0;
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    background: transparent;
}

dialog.ui-dialog {
    /* 默认收敛为中等尺寸，避免只有少量内容时仍占据大半屏幕。 */
    width: min(560px, calc(100vw - 32px));
    max-height: min(84vh, 720px);
    max-height: min(84dvh, 720px);
    padding: 0;
    overflow: auto;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-xl);
    color: var(--text);
    background: var(--surface);
    box-shadow: var(--shadow-raised);
}

/* 按内容密度分档，而不是让所有功能弹窗共享同一个过大宽度。 */
dialog.ui-dialog.ui-dialog--compact {
    width: min(420px, calc(100vw - 32px));
    max-height: min(76vh, 560px);
    max-height: min(76dvh, 560px);
}

dialog.ui-dialog.ui-dialog--medium {
    width: min(560px, calc(100vw - 32px));
    max-height: min(84vh, 720px);
    max-height: min(84dvh, 720px);
}

dialog.ui-dialog.ui-dialog--wide {
    width: min(760px, calc(100vw - 32px));
    max-height: min(88vh, 800px);
    max-height: min(88dvh, 800px);
}

dialog.ui-dialog::backdrop {
    background: rgba(10, 22, 19, 0.42);
    backdrop-filter: blur(4px);
}

.ui-spinner {
    width: 22px;
    height: 22px;
    border: 3px solid var(--primary-soft);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: ui-spin 0.75s linear infinite;
}

.ui-skeleton {
    min-height: 1em;
    border-radius: var(--radius-sm);
    background: linear-gradient(90deg, var(--surface-muted), var(--surface-strong), var(--surface-muted));
    background-size: 200% 100%;
    animation: ui-skeleton 1.4s ease-in-out infinite;
}

[aria-busy="true"] {
    cursor: progress;
}

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

@keyframes ui-skeleton {
    to { background-position: -200% 0; }
}

@keyframes ui-toast-in {
    from { opacity: 0; transform: translateY(-8px); }
    to { opacity: 1; transform: translateY(0); }
}

@media (max-width: 768px) {
    .ui-card-grid {
        grid-template-columns: 1fr;
        gap: var(--space-4);
    }

    .toast-region,
    .ui-toast-region {
        top: auto;
        right: 16px;
        bottom: max(16px, env(safe-area-inset-bottom));
        left: 16px;
        width: auto;
    }
}

@media (max-width: 480px) {
    :root {
        --radius-xl: 20px;
        --radius-lg: 12px;
    }

    /* 窄屏仍使用 16px 输入字号，避免移动浏览器在聚焦时自动放大。 */
    body {
        font-size: 16px;
    }
}

@media (prefers-reduced-motion: reduce) {
    html {
        scroll-behavior: auto;
    }

    *,
    *::before,
    *::after {
        scroll-behavior: auto !important;
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* 共享的展示组件只定义外观，不引入新的业务状态或页面框架。 */
[hidden] { display: none !important; }
button { color: inherit; }
:where(input, select, textarea) { font-size: 16px; }
::selection { color: var(--text); background: var(--primary-soft); }
:where(h1, h2, h3, p, dd) { overflow-wrap: anywhere; }
:where(h1, h2, h3) { letter-spacing: -0.035em; }
:where(code, pre, kbd) { font-family: var(--font-mono); }
.skip-link {
    position: fixed; top: 12px; left: 12px; z-index: 100;
    padding: 12px 16px; border-radius: var(--radius-md);
    color: var(--on-primary); background: var(--primary);
    transform: translateY(-180%); text-decoration: none;
}
.skip-link:focus { transform: translateY(0); }
.eyebrow, .step-label {
    margin: 0 0 8px; color: var(--text-muted);
    font: 600 12px/1.4 var(--font-mono); letter-spacing: 0.1em;
}
.page-topbar {
    display: flex; align-items: center; justify-content: space-between; gap: 16px;
    width: min(1240px, calc(100% - 48px)); min-height: 88px;
    margin: 0 auto; border-bottom: 1px solid var(--border);
}
.brand-link, .brand, .back-link {
    display: inline-flex; align-items: center; gap: 10px; min-height: 44px;
    color: var(--text); text-decoration: none; font-weight: 750;
}
.brand-link, .brand { font-size: 20px; letter-spacing: -0.06em; }
.brand-link > .ui-icon, .brand-symbol {
    width: 32px; height: 32px; color: var(--primary);
}
.brand-caption { color: var(--text-muted); font: 12px/1.4 var(--font-mono); letter-spacing: 0.02em; }
.soft-panel, .ui-card { border: 1px solid var(--border); background: var(--surface); box-shadow: none; border-radius: var(--radius-xl); }
.soft-button, .button, .btn, .icon-button, .primary-button {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    min-height: 44px; padding: 10px 16px; border: 1px solid var(--border);
    border-radius: var(--radius-md); color: var(--text); background: var(--surface);
    font-size: 14px; font-weight: 650; line-height: 1.4; text-decoration: none;
}
.icon-button { width: 44px; padding: 0; flex: 0 0 auto; }
.soft-button-primary, .button-primary, .btn-primary, .primary-button {
    color: var(--on-primary); border-color: var(--primary); background: var(--primary);
}
.soft-button-quiet { border-color: transparent; background: transparent; }
.soft-button-secondary { color: var(--primary-strong); }
.button-danger, .btn-danger { color: var(--danger); border-color: var(--border); background: var(--surface); }
.full-width, .btn-block { width: 100%; }
.input-shell {
    display: flex; align-items: center; gap: 12px; min-height: 52px; padding: 0 14px;
    color: var(--text-muted); background: var(--surface); border: 1px solid var(--border-strong);
    border-radius: var(--radius-md); transition: border-color var(--ease), outline-color var(--ease);
}
.input-shell input, .input-shell select {
    width: 100%; min-width: 0; min-height: 50px; padding: 0; border: 0; outline: 0;
    color: var(--text); background: transparent; font-size: 16px;
}
.input-shell input::placeholder { color: var(--text-muted); opacity: 1; }
.input-shell:focus-within { outline: 2px solid var(--focus); outline-offset: 3px; }
.input-shell.is-invalid, .input-shell:has([aria-invalid="true"]) { border-color: var(--danger); }
.input-shell :focus-visible { outline: 0; }
.step-index {
    display: grid; width: 40px; height: 40px; flex: 0 0 auto; place-items: center;
    border: 1px solid var(--border); border-radius: var(--radius-md);
    color: var(--primary-strong); background: var(--surface-muted); font: 14px var(--font-mono);
}
.dialog-card { position: relative; padding: 32px; }
.dialog-close { position: absolute; top: 16px; right: 16px; }
.dialog-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 12px; margin-top: 24px; }
.ui-dialog[open], .modal.is-open .modal-content { animation: ui-surface-in var(--ease-state) both; }
@keyframes ui-surface-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }
@media (hover: hover) and (pointer: fine) {
    .soft-button:not(:disabled):hover, .button:not(:disabled):hover, .btn:not(:disabled):hover, .icon-button:not(:disabled):hover { border-color: var(--border-strong); background: var(--surface-muted); }
    .soft-button-primary:not(:disabled):hover, .button-primary:not(:disabled):hover, .btn-primary:not(:disabled):hover, .primary-button:not(:disabled):hover { background: var(--primary-strong); border-color: var(--primary-strong); }
    .button-danger:not(:disabled):hover, .btn-danger:not(:disabled):hover { background: var(--danger-soft); border-color: var(--danger); }
}
@media (max-width: 720px) {
    .page-topbar { width: calc(100% - 32px); min-height: 72px; }
    .brand-caption { display: none; }
}
@media (max-width: 480px) { .dialog-card { padding: 24px; } }
/* 此规则置于共享动效之后，确保减少动效确实覆盖新增的组件转场。 */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}

/* 次要操作也使用同一节奏，不另造弹跳动效。 */
.soft-button { transition: color var(--ease), background-color var(--ease), border-color var(--ease); }
