/* ============================================================================
 * 基础样式：重置、排版、通用组件
 *
 * 所有色值一律引用 tokens.css 的变量，禁止写死。
 * 对比度红线：正文 ≥ 4.5:1；--t3 只用于时间戳/占位符。
 * ==========================================================================*/

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

html {
    -webkit-text-size-adjust: 100%;
}

body {
    margin: 0;
    padding: 0;
    font-family: var(--font-sans);
    font-size: 14px;
    line-height: 1.6;
    color: var(--t1);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

h1, h2, h3, h4, h5, h6 {
    margin: 0 0 .6em;
    font-weight: 600;
    line-height: 1.35;
    color: var(--t1);
}

h1 { font-size: 22px; }
h2 { font-size: 18px; }
h3 { font-size: 16px; }
h4 { font-size: 14px; }

p { margin: 0 0 1em; }

a {
    color: var(--blue);
    text-decoration: none;
    transition: color var(--transition);
}

a:hover {
    color: var(--blue-deep);
    text-decoration: underline;
}

code, pre, kbd, samp {
    font-family: var(--font-mono);
    font-size: 13px;
}

code {
    background: var(--panel2);
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    padding: 1px 5px;
    color: var(--t1);
}

pre {
    background: var(--panel2);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 12px 14px;
    overflow-x: auto;
    margin: 0 0 1em;
}

hr {
    border: 0;
    border-top: 1px solid var(--line);
    margin: 20px 0;
}

/* --------------------------------------------------------------- 布局容器 */

.page {
    max-width: var(--page-max);
    margin: 0 auto;
    padding: 24px 20px 64px;
}

.page--narrow {
    max-width: 640px;
}

.page--blank {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px 20px;
    background: var(--bg);
}

/* --------------------------------------------------------------- 顶部导航 */

.nav {
    height: var(--nav-height);
    background: var(--panel);
    border-bottom: 1px solid var(--line);
    display: flex;
    align-items: center;
    padding: 0 20px;
    position: sticky;
    top: 0;
    z-index: 100;
}

.nav__inner {
    max-width: var(--page-max);
    width: 100%;
    margin: 0 auto;
    display: flex;
    align-items: center;
    gap: 20px;
}

.nav__brand {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 16px;
    font-weight: 600;
    color: var(--t1);
    text-decoration: none;
}

.nav__brand:hover {
    color: var(--t1);
    text-decoration: none;
}

/* logo 光点：用品牌渐变 */
.nav__logo {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--grad-blue);
    box-shadow: var(--shadow-blue);
    flex: 0 0 auto;
}

.nav__links {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-left: auto;
}

.nav__link {
    padding: 6px 12px;
    border-radius: var(--radius-sm);
    color: var(--t2);
    font-size: 14px;
    transition: background var(--transition), color var(--transition);
}

.nav__link:hover {
    background: var(--hover-bg);
    color: var(--blue);
    text-decoration: none;
}

.nav__link.is-active {
    background: var(--blue-bg);
    color: var(--info-text);
    font-weight: 500;
}

.nav__user {
    display: flex;
    align-items: center;
    gap: 8px;
    padding-left: 12px;
    margin-left: 8px;
    border-left: 1px solid var(--line);
    color: var(--t2);
    font-size: 13px;
}

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

.card {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    padding: 20px;
    margin-bottom: 16px;
}

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

.card__title {
    font-size: 15px;
    font-weight: 600;
    margin: 0 0 4px;
    color: var(--t1);
}

.card__desc {
    font-size: 13px;
    color: var(--t2);
    margin: 0;
}

.card__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 16px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--line);
}

.card__header h2 {
    margin: 0;
    font-size: 16px;
}

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

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    font-family: inherit;
    font-size: 14px;
    line-height: 1.4;
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    cursor: pointer;
    text-decoration: none;
    transition: background var(--transition), border-color var(--transition),
                color var(--transition), box-shadow var(--transition);
    white-space: nowrap;
    user-select: none;
}

.btn:hover { text-decoration: none; }

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

/* 主按钮：品牌渐变底 + 白字 + 蓝色阴影 */
.btn--primary {
    background: var(--grad-blue);
    color: #ffffff;
    box-shadow: var(--shadow-blue);
}

.btn--primary:hover {
    background: var(--blue-deep);
    color: #ffffff;
}

.btn--primary:active {
    box-shadow: none;
}

/* 次按钮：白底 + 浅线 + 深字 */
.btn--secondary {
    background: var(--panel);
    border-color: var(--line2);
    color: var(--t1);
}

.btn--secondary:hover {
    border-color: var(--hover-border);
    background: var(--hover-bg);
    color: var(--t1);
}

/* 幽灵按钮：无底无边，用于次要操作 */
.btn--ghost {
    background: transparent;
    color: var(--t2);
}

.btn--ghost:hover {
    background: var(--hover-bg);
    color: var(--blue);
}

/* 危险按钮：白底 + 粉边 + 红字 */
.btn--danger {
    background: var(--panel);
    border-color: var(--danger-border);
    color: var(--bad);
}

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

/* 成功按钮 */
.btn--success {
    background: var(--ok);
    border-color: var(--ok);
    color: #ffffff;
}

.btn--success:hover {
    background: var(--ok-hover);
    border-color: var(--ok-hover);
    color: #ffffff;
}

/* 禁用态 */
.btn:disabled,
.btn.is-disabled {
    background: var(--panel2);
    border-color: var(--disabled-border);
    color: var(--t3);
    cursor: not-allowed;
    box-shadow: none;
}

.btn--sm {
    font-size: 13px;
    padding: 5px 10px;
}

.btn--lg {
    font-size: 15px;
    padding: 11px 22px;
}

.btn--block {
    width: 100%;
}

.btn--loading {
    position: relative;
    color: transparent !important;
    pointer-events: none;
}

.btn--loading::after {
    content: "";
    position: absolute;
    width: 14px;
    height: 14px;
    border: 2px solid rgba(255, 255, 255, .45);
    border-top-color: #ffffff;
    border-radius: 50%;
    animation: spin .7s linear infinite;
}

.btn--secondary.btn--loading::after,
.btn--ghost.btn--loading::after {
    border-color: var(--line2);
    border-top-color: var(--blue);
}

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

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

.form-group {
    margin-bottom: 16px;
}

.form-label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: var(--t1);
    margin-bottom: 6px;
}

.form-label .required {
    color: var(--bad);
    margin-left: 2px;
}

.form-hint {
    font-size: 12px;
    color: var(--t2);
    margin-top: 5px;
    line-height: 1.5;
}

.form-error {
    font-size: 12px;
    color: var(--bad-text);
    margin-top: 5px;
}

.input,
.textarea,
.select {
    width: 100%;
    font-family: inherit;
    font-size: 14px;
    line-height: 1.5;
    color: var(--t1);
    background: var(--panel);
    border: 1px solid var(--line2);
    border-radius: var(--radius-sm);
    padding: 8px 12px;
    transition: border-color var(--transition), box-shadow var(--transition);
}

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

.input:focus,
.textarea:focus,
.select:focus {
    outline: none;
    border-color: var(--blue);
    box-shadow: 0 0 0 3px var(--blue-bg);
}

.input.is-error,
.textarea.is-error {
    border-color: var(--bad);
}

.input:disabled,
.textarea:disabled,
.select:disabled {
    background: var(--panel2);
    color: var(--t2);
    cursor: not-allowed;
}

.textarea {
    resize: vertical;
    min-height: 80px;
}

.textarea--code {
    font-family: var(--font-mono);
    font-size: 13px;
    line-height: 1.7;
}

.select {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%235e6774' d='M6 8L2 4h8z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 32px;
}

.form-row {
    display: flex;
    gap: 12px;
}

.form-row > * {
    flex: 1;
}

/* 复选框 */
.checkbox {
    display: inline-flex;
    align-items: flex-start;
    gap: 8px;
    font-size: 13px;
    color: var(--t1);
    cursor: pointer;
    line-height: 1.5;
}

.checkbox input[type="checkbox"] {
    margin: 3px 0 0;
    width: 15px;
    height: 15px;
    accent-color: var(--blue);
    cursor: pointer;
    flex: 0 0 auto;
}

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

.alert {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    border: 1px solid;
    font-size: 13px;
    line-height: 1.6;
    margin-bottom: 16px;
}

/* 三件套：浅底 + 中边框 + 深字 */
.alert--info {
    background: var(--info-bg);
    border-color: var(--info-border);
    color: var(--info-text);
}

.alert--success {
    background: var(--ok-bg);
    border-color: var(--ok-border);
    color: var(--ok-text);
}

.alert--warning {
    background: var(--warn-bg);
    border-color: var(--warn-border);
    color: var(--warn-text);
}

.alert--error {
    background: var(--bad-bg);
    border-color: var(--bad-border);
    color: var(--bad-text);
}

.alert__icon {
    flex: 0 0 auto;
    font-weight: 700;
    line-height: 1.6;
}

/* --------------------------------------------------------------- 徽章 */

.badge {
    display: inline-flex;
    align-items: center;
    font-size: 12px;
    line-height: 1.5;
    padding: 1px 8px;
    border-radius: var(--radius-pill);
    border: 1px solid;
    white-space: nowrap;
}

.badge--info {
    background: var(--blue-bg);
    border-color: var(--blue-border);
    color: var(--info-text);
}

.badge--success {
    background: var(--ok-bg);
    border-color: var(--ok-border);
    color: var(--ok-text);
}

.badge--warning {
    background: var(--warn-bg);
    border-color: var(--warn-border);
    color: var(--warn-text);
}

.badge--danger {
    background: var(--bad-bg);
    border-color: var(--bad-border);
    color: var(--bad-text);
}

.badge--neutral {
    background: var(--panel2);
    border-color: var(--line);
    color: var(--t2);
}

/* 状态圆点（非正文，允许使用 --ok / --warn 原色） */
.dot {
    display: inline-block;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    flex: 0 0 auto;
}

.dot--ok { background: var(--ok); }
.dot--warn { background: var(--warn); }
.dot--bad { background: var(--bad); }
.dot--idle { background: var(--t3); }

/* --------------------------------------------------------------- 表格 */

.table-wrap {
    overflow-x: auto;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--panel);
}

.table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.table th {
    background: var(--head-bg);
    color: var(--t2);
    font-weight: 500;
    text-align: left;
    padding: 10px 14px;
    border-bottom: 1px solid var(--line);
    white-space: nowrap;
}

.table td {
    padding: 10px 14px;
    border-bottom: 1px solid var(--line);
    color: var(--t1);
    vertical-align: middle;
}

.table tbody tr:last-child td {
    border-bottom: 0;
}

.table tbody tr:hover td {
    background: var(--row-hover);
}

.table__empty {
    text-align: center;
    color: var(--t2);
    padding: 32px 14px;
}

/* --------------------------------------------------------------- 文本工具 */

.text-dim { color: var(--t2); }
.text-muted { color: var(--t3); }        /* 仅用于时间戳、占位 */
.text-mono { font-family: var(--font-mono); }
.text-sm { font-size: 13px; }
.text-xs { font-size: 12px; }
.text-center { text-align: center; }
.text-right { text-align: right; }
.text-nowrap { white-space: nowrap; }
.text-break { word-break: break-all; }

/* --------------------------------------------------------------- 间距工具 */

.mt-0 { margin-top: 0; }
.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }
.mt-3 { margin-top: 24px; }
.mb-0 { margin-bottom: 0; }
.mb-1 { margin-bottom: 8px; }
.mb-2 { margin-bottom: 16px; }
.mb-3 { margin-bottom: 24px; }

/* --------------------------------------------------------------- 布局工具 */

.flex { display: flex; }
.flex-between { display: flex; align-items: center; justify-content: space-between; }
.flex-center { display: flex; align-items: center; }
.flex-wrap { flex-wrap: wrap; }
.gap-1 { gap: 8px; }
.gap-2 { gap: 16px; }
.ml-auto { margin-left: auto; }
.hidden { display: none !important; }

.grid {
    display: grid;
    gap: 16px;
}

.grid--2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid--3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }

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

.empty {
    text-align: center;
    padding: 48px 20px;
    color: var(--t2);
}

.empty__title {
    font-size: 15px;
    color: var(--t1);
    margin-bottom: 6px;
}

/* --------------------------------------------------------------- 加载 */

.spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid var(--line2);
    border-top-color: var(--blue);
    border-radius: 50%;
    animation: spin .7s linear infinite;
}

.skeleton {
    background: var(--panel2);
    border-radius: var(--radius-sm);
    animation: skeleton-pulse 1.4s ease-in-out infinite;
}

@keyframes skeleton-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: .55; }
}

/* --------------------------------------------------------------- 响应式 */

@media (max-width: 768px) {
    .page { padding: 16px 14px 48px; }
    .nav { padding: 0 14px; }
    .grid--2, .grid--3 { grid-template-columns: 1fr; }
    .form-row { flex-direction: column; gap: 0; }
    .card { padding: 16px; }
}

@media print {
    .nav, .btn { display: none; }
    body { background: #fff; }
}
