/* 通用组件（v2） */

/* ------------------------------ 按钮 ------------------------------ */

.btn {
    --btn-h: 40px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    height: var(--btn-h);
    padding: 0 18px;
    border-radius: 10px;
    border: 1px solid transparent;
    background: transparent;
    color: var(--ink);
    font-size: 13.5px;
    font-weight: var(--weight-medium);
    line-height: 1;
    white-space: nowrap;
    transition: background var(--dur-2) var(--ease), color var(--dur-2) var(--ease),
        border-color var(--dur-2) var(--ease), transform var(--dur-1) var(--ease);
    user-select: none;
}

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

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

.btn svg {
    width: 17px;
    height: 17px;
    flex: none;
}

.btn-primary {
    background: var(--brand);
    color: #fff;
    border-color: var(--brand);
    box-shadow: none;
}

.btn-primary:hover:not(:disabled) {
    background: var(--brand-strong);
    border-color: var(--brand-strong);
}

[data-theme="dark"] .btn-primary {
    color: #06201c;
}

.btn-secondary {
    background: transparent;
    border-color: var(--line-strong);
    color: var(--ink-2);
    box-shadow: none;
}

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

.btn-soft {
    background: var(--brand-soft);
    border-color: var(--brand-line);
    color: var(--brand-strong);
}

.btn-soft:hover:not(:disabled) {
    background: var(--brand-line);
}

[data-theme="dark"] .btn-soft {
    color: var(--brand);
}

.btn-ghost {
    color: var(--muted);
    padding-left: 10px;
    padding-right: 10px;
}

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

.btn-danger {
    background: var(--danger);
    border-color: var(--danger);
    color: #fff;
}

.btn-danger:hover:not(:disabled) {
    filter: brightness(0.95);
}

.btn-danger-ghost {
    color: var(--danger);
}

.btn-danger-ghost:hover:not(:disabled) {
    background: var(--danger-soft);
}

.btn-sm {
    --btn-h: 34px;
    padding: 0 12px;
    font-size: 12.5px;
    border-radius: 8px;
}

.btn-sm svg { width: 15px; height: 15px; }

.btn-lg {
    --btn-h: 46px;
    padding: 0 22px;
    font-size: 15px;
    border-radius: 12px;
}

.btn-block { width: 100%; }

.btn-icon {
    width: 36px;
    height: 36px;
    padding: 0;
    border-radius: 9px;
    color: var(--muted);
}

.btn-icon:hover {
    background: var(--surface-2);
    color: var(--ink);
}

.icon-btn-sm {
    width: 30px;
    height: 30px;
    border-radius: 8px;
}

/* ------------------------------ 表单 ------------------------------ */

.field {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.label {
    font-size: 13px;
    font-weight: var(--weight-medium);
    color: var(--ink-2);
    display: flex;
    align-items: center;
    gap: 6px;
}

.label .optional {
    font-weight: var(--weight-regular);
    color: var(--muted-2);
    font-size: 12px;
}

.hint {
    font-size: 12px;
    color: var(--muted-2);
    line-height: 1.6;
}

.input,
.textarea {
    width: 100%;
    min-height: 44px;
    padding: 10px 14px;
    border-radius: 10px;
    border: 1px solid var(--line);
    background: var(--surface);
    color: var(--ink);
    font-size: 15px;
    line-height: 1.5;
    transition: border-color var(--dur-2), background var(--dur-2);
    -webkit-appearance: none;
    appearance: none;
}

.input::placeholder,
.textarea::placeholder {
    color: var(--muted-2);
}

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

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

.textarea {
    resize: vertical;
    line-height: 1.75;
    min-height: 112px;
}

.input-lg {
    min-height: 48px;
    padding: 12px 15px;
    font-size: 15px;
}

.input-icon {
    position: relative;
}

.input-icon > svg {
    position: absolute;
    left: 13px;
    top: 50%;
    transform: translateY(-50%);
    width: 17px;
    height: 17px;
    color: var(--muted-2);
    pointer-events: none;
}

.input-icon .input {
    padding-left: 40px;
}

.input-icon .input[type="password"],
.input-icon .input.has-toggle {
    padding-right: 44px;
}

.pwd-toggle {
    position: absolute;
    right: 6px;
    top: 50%;
    transform: translateY(-50%);
    width: 32px;
    height: 32px;
    border-radius: 7px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--muted-2);
    transition: background var(--dur-2), color var(--dur-2);
}

.pwd-toggle:hover {
    background: var(--surface-2);
    color: var(--ink-2);
}

.pwd-toggle svg { width: 16px; height: 16px; }

.field-error .input,
.field-error .textarea {
    border-color: var(--danger);
}

.error-text {
    font-size: 12.5px;
    color: var(--danger);
    display: flex;
    align-items: center;
    gap: 5px;
}

.counter {
    font-size: 12px;
    color: var(--muted-2);
    font-variant-numeric: tabular-nums;
}

/* 自定义下拉 */

.dropdown {
    position: relative;
    display: inline-block;
}

.dropdown-trigger {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    height: 40px;
    padding: 0 12px;
    border-radius: 10px;
    border: 1px solid var(--line);
    background: transparent;
    color: var(--ink-2);
    font-size: 13px;
    font-weight: var(--weight-medium);
    transition: border-color var(--dur-2), background var(--dur-2);
    max-width: 100%;
}

.dropdown-trigger:hover {
    border-color: var(--line-strong);
    background: var(--surface-2);
}

.dropdown-trigger[aria-expanded="true"] {
    border-color: var(--brand);
    background: var(--surface);
}

.dropdown-trigger .caret {
    width: 15px;
    height: 15px;
    color: var(--muted-2);
    transition: transform var(--dur-2) var(--ease);
}

.dropdown-trigger[aria-expanded="true"] .caret {
    transform: rotate(180deg);
}

.dropdown-trigger .value {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.dropdown-trigger.is-placeholder .value {
    color: var(--muted-2);
}

.dropdown-menu {
    position: absolute;
    z-index: var(--z-modal);
    min-width: 100%;
    max-height: 300px;
    overflow-y: auto;
    padding: 6px;
    border-radius: 12px;
    border: 1px solid var(--line);
    background: var(--surface);
    box-shadow: var(--shadow-md);
    animation: scale-in var(--dur-2) var(--ease-out);
    transform-origin: top center;
}

.dropdown-menu.is-up {
    transform-origin: bottom center;
}

.dropdown-item {
    display: flex;
    align-items: center;
    gap: 9px;
    width: 100%;
    padding: 9px 10px;
    border-radius: 8px;
    color: var(--ink-2);
    font-size: 13px;
    text-align: left;
    transition: background var(--dur-1), color var(--dur-1);
}

.dropdown-item:hover,
.dropdown-item.is-active {
    background: var(--surface-2);
    color: var(--ink);
}

.dropdown-item.is-selected {
    color: var(--brand-strong);
    font-weight: var(--weight-semibold);
}

[data-theme="dark"] .dropdown-item.is-selected { color: var(--brand); }

.dropdown-item .check {
    width: 15px;
    height: 15px;
    margin-left: auto;
    opacity: 0;
    color: var(--brand);
}

.dropdown-item.is-selected .check { opacity: 1; }

.dropdown-item .count {
    margin-left: auto;
    font-size: 11.5px;
    color: var(--muted-2);
    font-variant-numeric: tabular-nums;
}

.dropdown-sep {
    height: 1px;
    background: var(--line);
    margin: 5px 4px;
}

/* 开关 */

.switch {
    position: relative;
    width: 40px;
    height: 23px;
    border-radius: 99px;
    background: var(--line-strong);
    transition: background var(--dur-2) var(--ease);
    flex: none;
}

.switch::after {
    content: "";
    position: absolute;
    top: 3px;
    left: 3px;
    width: 17px;
    height: 17px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
    transition: transform var(--dur-2) var(--ease);
}

.switch[aria-checked="true"] {
    background: var(--brand);
}

.switch[aria-checked="true"]::after {
    transform: translateX(17px);
}

/* ------------------------------ 徽标与标签 ------------------------------ */

.badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    height: 20px;
    padding: 0 7px;
    border-radius: 4px;
    border: 1px solid var(--line);
    background: transparent;
    font-size: 11.5px;
    font-weight: var(--weight-medium);
    line-height: 1;
    letter-spacing: 0.01em;
    color: var(--muted);
    white-space: nowrap;
}

.badge-neutral { background: transparent; color: var(--muted); }
.badge-brand { background: var(--brand-soft); border-color: var(--brand-line); color: var(--brand-strong); }
.badge-success { background: var(--success-soft); border-color: var(--success-line); color: var(--success); }
.badge-warn { background: var(--warn-soft); border-color: var(--warn-line); color: var(--warn); }
.badge-danger { background: var(--danger-soft); border-color: var(--danger-line); color: var(--danger); }
.badge-accent { background: var(--accent-soft); border-color: var(--accent-line); color: var(--accent); }

[data-theme="dark"] .badge-brand { color: var(--brand); }

.chip {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    height: 24px;
    padding: 0 9px;
    border-radius: var(--r-full);
    border: 1px solid var(--line);
    background: transparent;
    color: var(--muted);
    font-size: 12px;
    transition: border-color var(--dur-2), color var(--dur-2), background var(--dur-2);
}

.chip:hover {
    border-color: var(--line-strong);
    color: var(--ink-2);
}

.chip.is-active {
    background: var(--brand-soft);
    border-color: var(--brand-line);
    color: var(--brand-strong);
    font-weight: var(--weight-semibold);
}

[data-theme="dark"] .chip.is-active { color: var(--brand); }

.chip-row {
    display: flex;
    flex-wrap: wrap;
    gap: 7px;
}

.dot {
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: currentColor;
    flex: none;
}

/* ------------------------------ 卡片 ------------------------------ */

.card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--r-lg);
    box-shadow: none;
}

.card-pad { padding: var(--sp-5); }
.card-pad-lg { padding: var(--sp-6); }

.card-hover {
    transition: border-color var(--dur-2), background var(--dur-2);
}

.card-hover:hover {
    border-color: var(--line-strong);
    background: var(--surface-2);
}

.card-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: var(--sp-4);
    padding: var(--sp-5) var(--sp-5) 0;
}

.card-title {
    font-family: var(--font-display);
    font-size: 19px;
    font-weight: var(--weight-semibold);
    letter-spacing: -0.02em;
    line-height: 1.35;
}

.card-sub {
    font-size: 12.5px;
    color: var(--muted);
    margin-top: 3px;
    line-height: 1.6;
}

/* ------------------------------ 头像 ------------------------------ */

.avatar {
    --size: 36px;
    width: var(--size);
    height: var(--size);
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--brand);
    color: #fff;
    font-size: calc(var(--size) * 0.38);
    font-weight: var(--weight-semibold);
    letter-spacing: 0.02em;
    flex: none;
    user-select: none;
    overflow: hidden;
}

.avatar-sm { --size: 30px; }
.avatar-lg { --size: 52px; }
.avatar-xl { --size: 72px; }

.avatar-soft {
    background: var(--brand-soft);
    color: var(--brand-strong);
}

[data-theme="dark"] .avatar-soft { color: var(--brand); }

/* ------------------------------ 提示条 ------------------------------ */

.notice {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 8px 0 8px 12px;
    border-radius: 0;
    border: 0;
    border-left: 2px solid var(--line-strong);
    background: transparent;
    font-size: 12.5px;
    color: var(--muted);
    line-height: 1.65;
}

.notice svg { width: 17px; height: 17px; flex: none; margin-top: 1px; }
.notice-info { border-left-color: var(--info); color: var(--info); background: transparent; }
.notice-warn { border-left-color: var(--warn); color: var(--warn); background: transparent; }
.notice-danger { border-left-color: var(--danger); color: var(--danger); background: transparent; }
.notice-brand { border-left-color: var(--brand); color: var(--brand-strong); background: transparent; }
[data-theme="dark"] .notice-brand { color: var(--brand); }

/* ------------------------------ 弹窗 ------------------------------ */

.modal-root {
    position: fixed;
    inset: 0;
    z-index: var(--z-modal);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: var(--overlay);
    backdrop-filter: blur(3px);
    animation: fade-in var(--dur-2) var(--ease);
}

.modal {
    position: relative;
    width: min(540px, 100%);
    max-height: min(86vh, 860px);
    display: flex;
    flex-direction: column;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 16px;
    box-shadow: var(--shadow-lg);
    animation: scale-in var(--dur-3) var(--ease-out);
    overflow: hidden;
}

.modal-lg { width: min(760px, 100%); }
.modal-sm { width: min(420px, 100%); }

.modal-head {
    display: flex;
    align-items: flex-start;
    gap: var(--sp-4);
    padding: 26px 26px 0;
    cursor: grab;
    touch-action: none;
}

.modal.is-dragging {
    user-select: none;
}

.modal.is-dragging .modal-head {
    cursor: grabbing;
}

.modal-head-text { flex: 1; min-width: 0; }

.modal-title {
    font-family: var(--font-display);
    font-size: 22px;
    font-weight: var(--weight-semibold);
    letter-spacing: -0.02em;
    line-height: 1.3;
}

.modal-desc {
    margin-top: 5px;
    font-size: 13px;
    color: var(--muted);
    line-height: 1.65;
}

.modal-body {
    padding: 22px 26px;
    overflow-y: auto;
    flex: 1;
}

.modal-foot {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 10px;
    padding: 16px 26px 24px;
    border-top: 1px solid var(--line);
    background: var(--surface);
}

.modal-close {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    color: var(--muted);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: none;
}

.modal-close:hover { background: var(--surface-2); color: var(--ink); }

/* 移动端底部抽屉 */
@media (max-width: 640px) {
    .modal-root {
        padding: 0;
        align-items: flex-end;
    }
    .modal {
        width: 100%;
        max-height: 90vh;
        border-radius: 18px 18px 0 0;
        border-bottom: 0;
        animation: sheet-up var(--dur-3) var(--ease-out);
        padding-bottom: env(safe-area-inset-bottom);
    }
    .modal-foot {
        padding-bottom: calc(16px + env(safe-area-inset-bottom));
    }
    @keyframes sheet-up {
        from { transform: translateY(24px); opacity: 0.6; }
        to { transform: translateY(0); opacity: 1; }
    }
}

/* ------------------------------ 提示消息 ------------------------------ */

.toast-stack {
    position: fixed;
    right: 20px;
    bottom: 20px;
    z-index: var(--z-toast);
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 10px;
    pointer-events: none;
    max-width: min(380px, calc(100vw - 32px));
}

.toast {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 11px 14px;
    border-radius: 10px;
    border: 1px solid var(--line);
    background: var(--surface);
    color: var(--ink-2);
    font-size: 13px;
    box-shadow: var(--shadow-sm);
    animation: toast-in var(--dur-3) var(--ease-out);
    pointer-events: auto;
}

.toast.is-out {
    animation: toast-out var(--dur-2) var(--ease) forwards;
}

.toast svg { width: 18px; height: 18px; flex: none; }
.toast-success svg { color: var(--success); }
.toast-error svg { color: var(--danger); }
.toast-info svg { color: var(--info); }

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

@keyframes toast-out {
    to { opacity: 0; transform: translateY(6px); }
}

@media (max-width: 640px) {
    .toast-stack {
        left: 16px;
        right: 16px;
        bottom: calc(84px + env(safe-area-inset-bottom));
        align-items: stretch;
        max-width: none;
    }
}

/* ------------------------------ 加载骨架 ------------------------------ */

.skeleton {
    border-radius: 8px;
    background: linear-gradient(90deg, var(--surface-3) 25%, var(--surface-2) 37%, var(--surface-3) 63%);
    background-size: 840px 100%;
    animation: shimmer 1.5s infinite linear;
}

.sk-line { height: 12px; margin-bottom: 10px; }
.sk-title { height: 18px; width: 42%; margin-bottom: 14px; }
.sk-card { height: 96px; border-radius: var(--r-md); }

.spinner {
    width: 18px;
    height: 18px;
    border: 2px solid currentColor;
    border-right-color: transparent;
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
    flex: none;
}

/* ------------------------------ 空状态 ------------------------------ */

.empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: var(--sp-9) var(--sp-5);
    gap: var(--sp-3);
}

.empty-icon {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--line);
    background: transparent;
    color: var(--muted);
    margin-bottom: 4px;
}

.empty-icon svg { width: 28px; height: 28px; }

.empty-rule {
    width: 24px;
    height: 1px;
    background: var(--line-strong);
    margin: 2px 0;
}

.empty-title {
    font-family: var(--font-display);
    font-size: 19px;
    font-weight: var(--weight-semibold);
    color: var(--ink-2);
    letter-spacing: -0.02em;
}

.empty-text {
    font-size: 13px;
    color: var(--muted);
    max-width: 380px;
    line-height: 1.7;
}

/* ------------------------------ 分段控件（下划线标签） ------------------------------ */

.segmented {
    display: flex;
    align-items: center;
    gap: 22px;
    padding: 0;
    border-radius: 0;
    background: transparent;
    border: 0;
    border-bottom: 1px solid var(--line);
    flex-wrap: wrap;
}

.segmented button {
    position: relative;
    height: 38px;
    padding: 0 1px;
    border-radius: 0;
    font-size: 13.5px;
    font-weight: var(--weight-medium);
    color: var(--muted);
    transition: color var(--dur-2);
    white-space: nowrap;
}

.segmented button:hover { color: var(--ink-2); }

.segmented button.is-active {
    background: transparent;
    color: var(--ink);
    font-weight: var(--weight-semibold);
    box-shadow: none;
}

.segmented button.is-active::after {
    content: "";
    position: absolute;
    left: 0;
    right: 0;
    bottom: -1px;
    height: 2px;
    background: var(--brand);
    border-radius: 2px;
}

/* ------------------------------ 分页 ------------------------------ */

.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: var(--sp-5) 0 0;
}

.page-btn {
    min-width: 34px;
    height: 34px;
    padding: 0 10px;
    border-radius: 8px;
    border: 1px solid transparent;
    background: transparent;
    color: var(--muted);
    font-size: 12.5px;
    font-variant-numeric: tabular-nums;
    transition: color var(--dur-2), background var(--dur-2), border-color var(--dur-2);
}

.page-btn:hover:not(:disabled) {
    border-color: var(--line);
    color: var(--ink);
}

.page-btn.is-active {
    background: transparent;
    border-color: var(--line-strong);
    color: var(--ink);
    font-weight: var(--weight-semibold);
}

.page-btn:disabled { opacity: 0.35; cursor: not-allowed; }

.page-info {
    font-size: 12px;
    color: var(--muted-2);
    padding: 0 6px;
}

/* ------------------------------ 进度条 ------------------------------ */

.progress {
    height: 4px;
    border-radius: 99px;
    background: var(--surface-3);
    overflow: hidden;
}

.progress-bar {
    height: 100%;
    border-radius: 99px;
    background: var(--brand);
    transition: width var(--dur-4) var(--ease);
}

/* ------------------------------ 标签页 ------------------------------ */

.tabs {
    display: flex;
    gap: 22px;
    border-bottom: 1px solid var(--line);
}

.tabs button {
    position: relative;
    height: 42px;
    padding: 0 1px;
    font-size: 13.5px;
    color: var(--muted);
    font-weight: var(--weight-medium);
    transition: color var(--dur-2);
}

.tabs button:hover { color: var(--ink-2); }

.tabs button.is-active {
    color: var(--ink);
    font-weight: var(--weight-semibold);
}

.tabs button.is-active::after {
    content: "";
    position: absolute;
    left: 0;
    right: 0;
    bottom: -1px;
    height: 2px;
    border-radius: 2px;
    background: var(--brand);
}

/* ------------------------------ 分隔标题 ------------------------------ */

.group-title {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 12px;
    font-weight: var(--weight-semibold);
    letter-spacing: 0.06em;
    color: var(--muted-2);
    text-transform: none;
    margin-bottom: var(--sp-3);
}

.group-title::after {
    content: "";
    flex: 1;
    height: 1px;
    background: var(--line);
}

/* ------------------------------ 统计条（替代四张卡） ------------------------------ */

.stat-grid .stat-card {
    position: relative;
    padding: 20px 24px;
    background: transparent;
    border: 0;
    border-left: 1px solid var(--line);
    border-radius: 0;
    box-shadow: none;
    overflow: visible;
    transition: none;
}

.stat-grid .stat-card:first-child {
    border-left: 0;
    padding-left: 0;
}

.stat-card .stat-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.stat-card .stat-label {
    font-size: 12.5px;
    color: var(--muted);
    font-weight: var(--weight-medium);
    letter-spacing: 0.01em;
}

.stat-card .stat-icon {
    display: none;
}

.stat-card .stat-value {
    margin-top: 8px;
    font-family: var(--font-display);
    font-size: 34px;
    font-weight: var(--weight-semibold);
    letter-spacing: -0.03em;
    line-height: 1;
    color: var(--ink);
    font-variant-numeric: tabular-nums;
    display: flex;
    align-items: baseline;
    gap: 5px;
}

.stat-card .stat-value small {
    font-family: var(--font-ui);
    font-size: 12.5px;
    font-weight: var(--weight-regular);
    color: var(--muted-2);
    letter-spacing: 0;
}

.stat-card .stat-foot {
    margin-top: 8px;
    font-size: 12px;
    color: var(--muted-2);
    display: flex;
    align-items: center;
    gap: 5px;
    line-height: 1.5;
}

.stat-card .stat-foot .up { color: var(--success); }
.stat-card .stat-foot .down { color: var(--danger); }

@media (max-width: 1080px) {
    .stat-grid .stat-card {
        border-left: 0;
        border-top: 1px solid var(--line);
        padding: 18px 0;
    }
    .stat-grid .stat-card:nth-child(-n + 2) {
        border-top: 0;
    }
}
