/* =============================================================
   KK Design System · Components v1.0
   依赖 tokens.css；所有样式以 .ds- 前缀隔离
   ============================================================= */

.ds-btn,
.ds-input,
.ds-select,
.ds-textarea,
.ds-card,
.ds-badge,
.ds-table,
.ds-kpi,
.ds-modal,
.ds-empty,
.ds-skeleton,
.ds-tab,
.ds-page,
.ds-toast {
    box-sizing: border-box;
}

/* ---------------- 按钮 ---------------- */
.ds-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    height: 40px;
    padding: 0 16px;
    border: 1px solid transparent;
    border-radius: var(--ds-radius-sm);
    background: transparent;
    color: var(--ds-text-secondary);
    font-family: inherit;
    font-size: var(--ds-text-base);
    font-weight: var(--ds-weight-semibold);
    line-height: 1;
    text-decoration: none;
    white-space: nowrap;
    cursor: pointer;
    user-select: none;
    transition: background var(--ds-duration) var(--ds-ease),
                border-color var(--ds-duration) var(--ds-ease),
                color var(--ds-duration) var(--ds-ease),
                box-shadow var(--ds-duration) var(--ds-ease),
                transform var(--ds-duration-fast) var(--ds-ease);
}

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

.ds-btn:disabled,
.ds-btn[aria-disabled="true"] {
    opacity: 0.45;
    cursor: not-allowed;
    pointer-events: none;
}

.ds-btn--primary {
    background: var(--ds-primary);
    color: var(--ds-primary-contrast);
    box-shadow: var(--ds-shadow-sm);
}
.ds-btn--primary:hover { background: var(--ds-primary-hover); }
.ds-btn--primary:active { background: var(--ds-primary-active); transform: translateY(0.5px); }

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

.ds-btn--ghost {
    background: transparent;
    color: var(--ds-text-secondary);
}
.ds-btn--ghost:hover {
    background: var(--ds-bg-subtle);
    color: var(--ds-text);
}

.ds-btn--danger {
    background: var(--ds-error);
    color: #FFFFFF;
}
.ds-btn--danger:hover { filter: brightness(0.94); }

.ds-btn--sm { height: 32px; padding: 0 12px; font-size: var(--ds-text-sm); border-radius: 7px; }
.ds-btn--lg { height: 48px; padding: 0 22px; font-size: var(--ds-text-md); border-radius: 10px; }
.ds-btn--block { width: 100%; }

.ds-btn--icon {
    width: 40px;
    padding: 0;
}
.ds-btn--icon.ds-btn--sm { width: 32px; }

/* ---------------- 表单 ---------------- */
.ds-field { display: flex; flex-direction: column; gap: 6px; }
.ds-label {
    font-size: var(--ds-text-sm);
    font-weight: var(--ds-weight-semibold);
    color: var(--ds-text-secondary);
}
.ds-input,
.ds-select,
.ds-textarea {
    width: 100%;
    height: 40px;
    padding: 0 12px;
    border: 1px solid var(--ds-border);
    border-radius: var(--ds-radius-sm);
    background: var(--ds-surface);
    color: var(--ds-text);
    font-family: inherit;
    font-size: var(--ds-text-base);
    transition: border-color var(--ds-duration) var(--ds-ease),
                box-shadow var(--ds-duration) var(--ds-ease),
                background var(--ds-duration) var(--ds-ease);
}
.ds-input::placeholder,
.ds-textarea::placeholder { color: var(--ds-text-subtle); }
.ds-input:hover,
.ds-select:hover,
.ds-textarea:hover { border-color: var(--ds-border-strong); }
.ds-input:focus,
.ds-select:focus,
.ds-textarea:focus {
    outline: none;
    border-color: var(--ds-primary);
    box-shadow: var(--ds-shadow-focus);
}
.ds-input:disabled,
.ds-select:disabled,
.ds-textarea:disabled {
    background: var(--ds-bg-subtle);
    color: var(--ds-text-muted);
    cursor: not-allowed;
}
.ds-textarea { height: auto; min-height: 96px; padding: 10px 12px; resize: vertical; }
.ds-help { font-size: var(--ds-text-xs); color: var(--ds-text-muted); }
.ds-help--error { color: var(--ds-error); }
.ds-input--error { border-color: var(--ds-error); }

.ds-search { position: relative; }
.ds-search .ds-input { padding-left: 38px; }
.ds-search__icon {
    position: absolute;
    left: 12px;
    top: 50%;
    width: 16px;
    height: 16px;
    transform: translateY(-50%);
    color: var(--ds-text-subtle);
    pointer-events: none;
}

/* ---------------- 卡片 ---------------- */
.ds-card {
    background: var(--ds-surface);
    border: 1px solid var(--ds-border);
    border-radius: var(--ds-radius-md);
    box-shadow: var(--ds-shadow-sm);
}
.ds-card--hover {
    transition: transform var(--ds-duration) var(--ds-ease),
                box-shadow var(--ds-duration) var(--ds-ease),
                border-color var(--ds-duration) var(--ds-ease);
}
.ds-card--hover:hover {
    transform: translateY(-2px);
    border-color: var(--ds-primary-lighter);
    box-shadow: var(--ds-shadow-md);
}
.ds-card__header { padding: 20px 20px 0; }
.ds-card__body { padding: 20px; }
.ds-card__footer { padding: 0 20px 20px; }

/* ---------------- 徽章 ---------------- */
.ds-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    height: 24px;
    padding: 0 10px;
    border: 1px solid transparent;
    border-radius: var(--ds-radius-pill);
    font-size: var(--ds-text-xs);
    font-weight: var(--ds-weight-semibold);
    line-height: 1;
    white-space: nowrap;
}
.ds-badge--neutral { background: var(--ds-bg-subtle); color: var(--ds-text-secondary); }
.ds-badge--success { background: var(--ds-success-bg); color: var(--ds-success); border-color: var(--ds-success-border); }
.ds-badge--warning { background: var(--ds-warning-bg); color: var(--ds-warning); border-color: var(--ds-warning-border); }
.ds-badge--error   { background: var(--ds-error-bg); color: var(--ds-error); border-color: var(--ds-error-border); }
.ds-badge--info    { background: var(--ds-info-bg); color: var(--ds-info); border-color: var(--ds-info-border); }
.ds-badge--primary { background: var(--ds-primary-light); color: var(--ds-primary); }
.ds-badge--dot::before {
    content: "";
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
}

/* ---------------- 表格 ---------------- */
.ds-table-wrap {
    width: 100%;
    overflow-x: auto;
    background: var(--ds-surface);
    border: 1px solid var(--ds-border);
    border-radius: var(--ds-radius-md);
}
.ds-table {
    width: 100%;
    border-collapse: collapse;
    font-size: var(--ds-text-base);
}
.ds-table th {
    position: sticky;
    top: 0;
    z-index: 1;
    padding: 12px 16px;
    background: var(--ds-bg-subtle);
    border-bottom: 1px solid var(--ds-border);
    color: var(--ds-text-muted);
    font-size: var(--ds-text-xs);
    font-weight: var(--ds-weight-semibold);
    text-align: left;
    white-space: nowrap;
}
.ds-table td {
    padding: 14px 16px;
    border-bottom: 1px solid var(--ds-border);
    color: var(--ds-text-secondary);
    vertical-align: middle;
}
.ds-table tbody tr:last-child td { border-bottom: 0; }
.ds-table tbody tr { transition: background var(--ds-duration-fast) var(--ds-ease); }
.ds-table tbody tr:hover { background: var(--ds-surface-hover); }
.ds-table .ds-num {
    color: var(--ds-text);
    font-variant-numeric: tabular-nums;
}
.ds-table__actions { text-align: right; white-space: nowrap; }

/* ---------------- 标签页 ---------------- */
.ds-tabs {
    display: flex;
    gap: 4px;
    overflow-x: auto;
    border-bottom: 1px solid var(--ds-border);
    scrollbar-width: none;
}
.ds-tabs::-webkit-scrollbar { display: none; }
.ds-tab {
    padding: 10px 14px;
    border-bottom: 2px solid transparent;
    color: var(--ds-text-muted);
    font-size: var(--ds-text-base);
    font-weight: var(--ds-weight-semibold);
    text-decoration: none;
    white-space: nowrap;
    transition: color var(--ds-duration) var(--ds-ease),
                border-color var(--ds-duration) var(--ds-ease);
}
.ds-tab:hover { color: var(--ds-text); }
.ds-tab--active { color: var(--ds-primary); border-bottom-color: var(--ds-primary); }

/* ---------------- 分页 ---------------- */
.ds-pagination { display: flex; align-items: center; gap: 6px; }
.ds-page {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 32px;
    height: 32px;
    padding: 0 8px;
    border: 1px solid var(--ds-border);
    border-radius: var(--ds-radius-sm);
    background: var(--ds-surface);
    color: var(--ds-text-secondary);
    font-size: var(--ds-text-sm);
    font-weight: var(--ds-weight-medium);
    text-decoration: none;
    cursor: pointer;
    transition: all var(--ds-duration) var(--ds-ease);
}
.ds-page:hover { border-color: var(--ds-primary); color: var(--ds-primary); }
.ds-page--active {
    background: var(--ds-primary);
    border-color: var(--ds-primary);
    color: var(--ds-primary-contrast);
}
.ds-page:disabled { opacity: 0.4; cursor: not-allowed; }

/* ---------------- KPI 卡片 ---------------- */
.ds-kpi {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 20px;
    background: var(--ds-surface);
    border: 1px solid var(--ds-border);
    border-radius: var(--ds-radius-md);
}
.ds-kpi__label { font-size: var(--ds-text-sm); color: var(--ds-text-muted); }
.ds-kpi__value {
    color: var(--ds-text);
    font-size: var(--ds-text-3xl);
    font-weight: var(--ds-weight-extrabold);
    line-height: 1.1;
    font-variant-numeric: tabular-nums;
    letter-spacing: -0.02em;
}
.ds-kpi__hint { font-size: var(--ds-text-xs); color: var(--ds-text-subtle); }

/* ---------------- 空状态 / 骨架屏 ---------------- */
.ds-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 56px 24px;
    color: var(--ds-text-muted);
    text-align: center;
}
.ds-empty__title { color: var(--ds-text-secondary); font-size: var(--ds-text-md); font-weight: var(--ds-weight-semibold); }
.ds-empty__desc { font-size: var(--ds-text-sm); color: var(--ds-text-subtle); }

.ds-skeleton {
    border-radius: var(--ds-radius-sm);
    background: linear-gradient(90deg, var(--ds-bg-subtle) 25%, var(--ds-bg-muted) 37%, var(--ds-bg-subtle) 63%);
    background-size: 400% 100%;
    animation: ds-shimmer 1.4s ease infinite;
}
@keyframes ds-shimmer {
    0% { background-position: 100% 50%; }
    100% { background-position: 0 50%; }
}

/* ---------------- 弹窗 / Toast ---------------- */
.ds-modal-mask {
    position: fixed;
    inset: 0;
    z-index: var(--ds-z-modal);
    display: none;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: rgba(15, 23, 42, 0.5);
    backdrop-filter: blur(2px);
}
.ds-modal-mask.is-open { display: flex; }
.ds-modal {
    display: flex;
    flex-direction: column;
    width: 100%;
    max-width: 520px;
    max-height: 85vh;
    overflow: hidden;
    background: var(--ds-surface);
    border-radius: var(--ds-radius-lg);
    box-shadow: var(--ds-shadow-lg);
}
.ds-modal__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 18px 22px;
    border-bottom: 1px solid var(--ds-border);
}
.ds-modal__title { color: var(--ds-text); font-size: var(--ds-text-md); font-weight: var(--ds-weight-bold); }
.ds-modal__body { padding: 20px 22px; overflow-y: auto; color: var(--ds-text-secondary); }
.ds-modal__footer {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    padding: 16px 22px;
    border-top: 1px solid var(--ds-border);
}

.ds-toast {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: var(--ds-z-toast);
    display: flex;
    align-items: center;
    gap: 10px;
    max-width: 360px;
    padding: 12px 16px;
    background: var(--ds-surface);
    border: 1px solid var(--ds-border);
    border-radius: var(--ds-radius-md);
    box-shadow: var(--ds-shadow-md);
    color: var(--ds-text-secondary);
    font-size: var(--ds-text-base);
}
.ds-toast--success { border-color: var(--ds-success-border); }
.ds-toast--error { border-color: var(--ds-error-border); }

/* ---------------- 布局工具 ---------------- */
.ds-container {
    width: 100%;
    max-width: var(--ds-container);
    margin: 0 auto;
    padding: 0 var(--ds-space-6);
}
@media (min-width: 1500px) {
    .ds-container { max-width: var(--ds-container-wide); padding: 0 var(--ds-space-8); }
}
.ds-row { display: flex; align-items: center; gap: 12px; }
.ds-stack { display: flex; flex-direction: column; gap: 16px; }
.ds-grid { display: grid; gap: 16px; }
.ds-grid--2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.ds-grid--3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.ds-grid--4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 1024px) {
    .ds-grid--4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .ds-grid--3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 640px) {
    .ds-grid--2,
    .ds-grid--3,
    .ds-grid--4 { grid-template-columns: minmax(0, 1fr); }
}

/* ---------------- 无障碍 ---------------- */
@media (prefers-reduced-motion: reduce) {
    .ds-btn,
    .ds-card--hover,
    .ds-skeleton,
    .ds-table tbody tr,
    .ds-tab,
    .ds-page {
        transition-duration: 0.01ms !important;
        animation-duration: 0.01ms !important;
    }
}