/* ==========================================================================
   组件：按钮、表单、表格、徽标、卡片、统计、标签页、弹窗、提示、分页
   ========================================================================== */

/* ---------- 按钮 ---------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    height: 38px;
    padding: 0 16px;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    font-weight: 600;
    white-space: nowrap;
    transition: transform .08s, box-shadow .15s, background .15s, color .15s, border-color .15s;
}
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: .55; }
.btn-primary {
    color: #fff;
    background: linear-gradient(135deg, var(--primary), var(--primary-2));
    box-shadow: 0 6px 16px var(--primary-ring);
}
.btn-primary:hover:not(:disabled) { box-shadow: 0 10px 24px var(--primary-ring); filter: brightness(1.05); }
.btn-ghost {
    color: var(--text);
    background: rgba(255, 255, 255, .72);
    border-color: var(--line-strong);
}
.btn-ghost:hover:not(:disabled) { background: #fff; border-color: var(--primary-ring); color: var(--primary-600); }
.btn-danger { color: #fff; background: var(--danger); }
.btn-text {
    height: 30px;
    padding: 0 8px;
    color: var(--primary);
    background: transparent;
    font-weight: 500;
}
.btn-text:hover { background: var(--primary-soft); }
.btn-text.is-danger { color: var(--danger); }
.btn-text.is-danger:hover { background: var(--danger-soft); }
.btn-sm { height: 32px; padding: 0 12px; font-size: 13px; }
.btn-lg { height: 46px; font-size: 15px; border-radius: 13px; }
.btn-block { width: 100%; }

.icon-btn {
    width: 36px;
    height: 36px;
    display: inline-grid;
    place-items: center;
    border: 0;
    border-radius: 10px;
    background: transparent;
    color: var(--text-2);
}
.icon-btn:hover { background: rgba(15, 23, 42, .06); color: var(--text); }

/* ---------- 表单 ---------- */
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; margin-bottom: 14px; }
.field > span { font-size: 13px; font-weight: 600; color: var(--text); }
.field > span small { font-weight: 400; color: var(--text-3); margin-left: 4px; }

input:not([type="checkbox"]):not([type="radio"]):not([type="file"]), select, textarea {
    width: 100%;
    height: 40px;
    padding: 0 12px;
    border: 1px solid var(--line-strong);
    border-radius: var(--radius-sm);
    background: rgba(255, 255, 255, .85);
    transition: border-color .15s, box-shadow .15s, background .15s;
}
textarea { height: auto; padding: 10px 12px; resize: vertical; line-height: 1.5; }
select { appearance: none; padding-right: 34px; background-image: linear-gradient(45deg, transparent 50%, var(--text-2) 50%), linear-gradient(135deg, var(--text-2) 50%, transparent 50%); background-position: calc(100% - 17px) 50%, calc(100% - 12px) 50%; background-size: 5px 5px; background-repeat: no-repeat; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 4px var(--primary-ring); background: #fff; }
input::placeholder, textarea::placeholder { color: var(--text-3); }
.is-invalid { border-color: var(--danger) !important; }

.field-error { font-style: normal; font-size: 12px; color: var(--danger); min-height: 0; }
.field-error:empty { display: none; }
.form-error { color: var(--danger); font-size: 13px; }
.form-error:empty { display: none; }
.hint { font-size: 12.5px; color: var(--text-2); margin: 2px 0 14px; }
.notice {
    margin: 0 0 14px;
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    background: var(--warn-soft);
    color: #92400e;
    font-size: 13px;
}

.form-grid { display: grid; grid-template-columns: 1fr 1fr; column-gap: 14px; }
.field-full { grid-column: 1 / -1; }
.form-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 6px; }

.input-group { display: flex; gap: 8px; align-items: stretch; }
.input-group > input { flex: 1; min-width: 0; }
.input-group > .btn { height: 40px; flex: none; }

.input-icon { position: relative; }
.input-icon .icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--text-3); pointer-events: none; }
.input-icon input { padding-left: 40px !important; }

.check { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-2); margin: 0 0 12px; cursor: pointer; }
.check input { accent-color: var(--primary); width: 16px; height: 16px; }

/* 开关 */
.switch { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; margin-bottom: 14px; font-size: 13px; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch-track {
    position: relative;
    width: 40px;
    height: 23px;
    flex: none;
    border-radius: 999px;
    background: var(--line-strong);
    transition: background .15s;
}
.switch-track::after {
    content: "";
    position: absolute;
    left: 3px;
    top: 3px;
    width: 17px;
    height: 17px;
    border-radius: 50%;
    background: #fff;
    box-shadow: var(--shadow-sm);
    transition: transform .15s;
}
.switch input:checked + .switch-track { background: var(--primary); }
.switch input:checked + .switch-track::after { transform: translateX(17px); }
.switch input:focus-visible + .switch-track { outline: 3px solid var(--primary-ring); outline-offset: 2px; }

/* 单选卡片 */
.radio-row { display: grid; grid-template-columns: 180px 1fr; gap: 14px; align-items: center; padding: 14px 0; border-bottom: 1px solid var(--line); }
.radio-row-label { display: flex; flex-direction: column; gap: 4px; }
.radio-cards { display: flex; flex-wrap: wrap; gap: 8px; }
.radio-card { position: relative; cursor: pointer; }
.radio-card input { position: absolute; opacity: 0; }
.radio-card span {
    display: inline-block;
    padding: 8px 14px;
    border: 1px solid var(--line-strong);
    border-radius: 10px;
    background: rgba(255, 255, 255, .75);
    font-weight: 500;
    transition: all .15s;
}
.radio-card input:checked + span { border-color: var(--primary); background: var(--primary-soft); color: var(--primary-600); box-shadow: 0 0 0 3px var(--primary-ring); }
.radio-card input:focus-visible + span { outline: 3px solid var(--primary-ring); }

/* 选项标签 */
.chips { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    height: 32px;
    padding: 0 12px;
    border: 1px solid var(--line-strong);
    border-radius: 999px;
    background: rgba(255, 255, 255, .7);
    font-size: 13px;
    font-weight: 500;
}
.chip-btn:hover, .chip-btn.is-active { border-color: var(--primary); color: var(--primary-600); background: var(--primary-soft); }
.chips-lg .chip { height: 40px; padding: 0 18px; font-size: 14px; }
.chip-balance { color: var(--primary-600); border-color: var(--primary-ring); background: var(--primary-soft); }

/* ---------- 卡片 ---------- */
.card { border-radius: var(--radius-lg); padding: 18px 20px; min-width: 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.card-head h2 { font-size: 16px; font-weight: 650; }
.card-head h2 small { font-weight: 400; margin-left: 6px; }
.narrow-card { max-width: 520px; }
.settings-card { max-width: 860px; }

.page-head { display: flex; align-items: center; justify-content: space-between; gap: 14px; flex-wrap: wrap; }
.page-head > p { max-width: 760px; font-size: 13px; }
.page-actions { display: flex; gap: 10px; }

/* ---------- 工具栏 ---------- */
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 14px; }
.toolbar select { width: auto; min-width: 140px; }
.search { position: relative; flex: 1 1 220px; max-width: 320px; }
.search .icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--text-3); }
.search input { padding-left: 36px !important; }

/* ---------- 表格 ---------- */
.table-wrap { overflow-x: auto; margin: 0 -20px; padding: 0 20px; }
.table { width: 100%; border-collapse: collapse; }
.table th {
    padding: 10px 12px;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-2);
    text-align: left;
    white-space: nowrap;
    border-bottom: 1px solid var(--line-strong);
}
.table td { padding: 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
/* 数字列：表头与数据统一右对齐（.table th 的左对齐优先级更高，需单独覆盖） */
.table th.num, .table td.num { text-align: right; }
.table tbody tr { transition: background .12s; }
.table tbody tr:hover { background: rgba(255, 255, 255, .55); }
.table tbody tr:last-child td { border-bottom: 0; }
.table .actions { text-align: right; white-space: nowrap; }
.table-compact td { padding: 9px 10px; }
.cell-main { font-weight: 600; }
.cell-sub { font-size: 12px; color: var(--text-2); margin-top: 2px; }
.col-raw { min-width: 220px; max-width: 320px; }
.col-ua { max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.empty-row td:hover, .empty-row:hover { background: transparent !important; }

.empty { padding: 40px 10px; display: flex; flex-direction: column; align-items: center; gap: 8px; color: var(--text-3); }
.empty .icon { width: 34px; height: 34px; }
.empty-inline { color: var(--text-3); font-size: 13px; padding: 16px 0; text-align: center; }

details.raw summary { cursor: pointer; list-style: none; color: var(--text-2); }
details.raw summary::-webkit-details-marker { display: none; }
details.raw summary::after { content: " 展开"; color: var(--primary); font-size: 12px; }
details.raw[open] summary::after { content: " 收起"; }
details.raw pre {
    margin: 8px 0 0;
    padding: 10px;
    white-space: pre-wrap;
    word-break: break-word;
    border-radius: var(--radius-xs);
    background: rgba(15, 23, 42, .04);
    font-family: var(--font);
    font-size: 12.5px;
}

/* ---------- 徽标 ---------- */
.badge {
    display: inline-flex;
    align-items: center;
    height: 22px;
    padding: 0 8px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
}
.tone-ok { color: var(--ok); background: var(--ok-soft); }
.tone-warn { color: var(--warn); background: var(--warn-soft); }
.tone-danger { color: var(--danger); background: var(--danger-soft); }
.tone-info { color: var(--info); background: var(--info-soft); }
.tone-primary { color: var(--primary-600); background: var(--primary-soft); }
.tone-muted { color: var(--text-2); background: rgba(15, 23, 42, .06); }

/* ---------- 统计卡 ---------- */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: var(--gap); }
.stat { position: relative; border-radius: var(--radius-lg); padding: 18px 20px; display: flex; flex-direction: column; gap: 4px; }
.stat-icon {
    position: absolute;
    right: 16px;
    top: 16px;
    width: 40px;
    height: 40px;
    border-radius: 12px;
    display: grid;
    place-items: center;
}
.stat-label { color: var(--text-2); font-size: 13px; font-weight: 500; }
.stat-value { font-size: 28px; font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.stat-value small { font-size: 14px; font-weight: 500; color: var(--text-2); }
.stat-foot { font-size: 12px; color: var(--text-3); }
.stat-hero { background: linear-gradient(135deg, rgba(255, 255, 255, .78), rgba(255, 255, 255, .5)); }
.stat-hero .btn { align-self: flex-start; margin-top: 6px; }

/* ---------- 标签页 ---------- */
.tabs {
    display: inline-flex;
    flex-wrap: wrap;
    gap: 4px;
    padding: 4px;
    border-radius: 14px;
    background: rgba(255, 255, 255, .5);
    border: 1px solid var(--glass-border);
    -webkit-backdrop-filter: var(--blur);
    backdrop-filter: var(--blur);
}
.tab { padding: 7px 14px; border-radius: 10px; color: var(--text-2); font-weight: 500; white-space: nowrap; }
.tab:hover { color: var(--text); background: rgba(255, 255, 255, .7); }
.tab.is-active { color: var(--primary-600); background: #fff; box-shadow: var(--shadow-sm); font-weight: 600; }

.segmented { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 4px; padding: 4px; border-radius: 13px; background: rgba(15, 23, 42, .05); margin-bottom: 18px; }
.segmented button { height: 36px; border: 0; border-radius: 10px; background: transparent; color: var(--text-2); font-weight: 600; }
.segmented button.is-active { background: #fff; color: var(--primary-600); box-shadow: var(--shadow-sm); }

/* ---------- 分页 ---------- */
.pager { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; padding-top: 14px; font-size: 13px; }
.pager-links { display: flex; gap: 4px; flex-wrap: wrap; }
.pager-link { min-width: 32px; height: 32px; padding: 0 10px; display: inline-grid; place-items: center; border-radius: 9px; color: var(--text-2); }
.pager-link:hover { background: rgba(255, 255, 255, .8); color: var(--text); }
.pager-link.is-current { background: var(--primary); color: #fff; font-weight: 600; }
.pager-gap { padding: 0 4px; color: var(--text-3); line-height: 32px; }

/* ---------- 弹窗 ---------- */
dialog.modal {
    width: min(620px, calc(100vw - 24px));
    max-height: calc(100vh - 40px);
    padding: 0;
    border: 0;
    background: transparent;
    overflow: visible;
}
dialog.modal-sm { width: min(440px, calc(100vw - 24px)); }
dialog.modal-lg { width: min(880px, calc(100vw - 24px)); }
dialog.modal::backdrop { background: rgba(15, 23, 42, .32); -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px); }
dialog.modal[open] .modal-card { animation: modal-in .18s ease-out; }
@keyframes modal-in { from { opacity: 0; transform: translateY(10px) scale(.98); } }

.modal-card {
    display: block;
    max-height: calc(100vh - 40px);
    overflow-y: auto;
    padding: 20px 22px;
    border-radius: var(--radius-lg);
    background: rgba(255, 255, 255, .86);
    box-shadow: var(--shadow-lg);
}
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 16px; }
.modal-head h3 { font-size: 17px; font-weight: 650; }
.modal-text { color: var(--text-2); margin-bottom: 16px; white-space: pre-line; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }

.reveal-box {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px;
    border-radius: var(--radius-sm);
    background: rgba(15, 23, 42, .05);
}
.reveal-box code { flex: 1; word-break: break-all; font-size: 13px; }

/* ---------- 提示 ---------- */
.toast-stack {
    position: fixed;
    top: 18px;
    right: 18px;
    z-index: 100;
    display: flex;
    flex-direction: column;
    gap: 10px;
    pointer-events: none;
}
.toast {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 220px;
    max-width: 380px;
    padding: 12px 16px;
    border-radius: 13px;
    background: rgba(255, 255, 255, .92);
    border: 1px solid var(--glass-border);
    box-shadow: var(--shadow-lg);
    -webkit-backdrop-filter: var(--blur);
    backdrop-filter: var(--blur);
    font-weight: 500;
    pointer-events: auto;
    animation: toast-in .2s ease-out;
}
.toast::before { content: ""; width: 8px; height: 8px; border-radius: 50%; flex: none; background: var(--ok); }
.toast.is-error::before { background: var(--danger); }
.toast.is-leaving { opacity: 0; transform: translateX(10px); transition: all .2s; }
@keyframes toast-in { from { opacity: 0; transform: translateY(-6px); } }

/* ---------- 其他 ---------- */
.code-line {
    display: block;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    background: rgba(15, 23, 42, .05);
    word-break: break-all;
    cursor: copy;
}
.code-line em { font-style: normal; color: var(--primary-600); }

@media (max-width: 640px) {
    .form-grid { grid-template-columns: 1fr; }
    .radio-row { grid-template-columns: 1fr; }
    .card { padding: 16px; }
    .table-wrap { margin: 0 -16px; padding: 0 16px; }
    .search { max-width: none; }
    .toolbar select { flex: 1; }
}
