/* 基础层：主题变量、重置、通用组件（前台与后台共用） */
:root {
    color-scheme: light;
    --bg: #f5f7fb;
    --surface: #ffffff;
    --surface-alt: #f0f3fa;
    --text: #1b2333;
    --muted: #6b768c;
    --border: #e3e8f2;
    --accent: #4c6fff;
    --accent-strong: #3a58e0;
    --accent-soft: rgba(76, 111, 255, .10);
    --danger: #dc4a4f;
    --danger-soft: rgba(220, 74, 79, .10);
    --ok: #129a52;
    --ok-soft: rgba(18, 154, 82, .12);
    --shadow: 0 10px 30px rgba(27, 35, 51, .08);
    --shadow-sm: 0 2px 10px rgba(27, 35, 51, .06);
    --radius: 14px;
    --radius-sm: 10px;
}

[data-theme="dark"] {
    color-scheme: dark;
    --bg: #0d111b;
    --surface: #161c28;
    --surface-alt: #1c2432;
    --text: #e9edf7;
    --muted: #96a1b6;
    --border: #283244;
    --accent: #8095ff;
    --accent-strong: #9bafff;
    --accent-soft: rgba(128, 149, 255, .14);
    --danger: #ff7679;
    --danger-soft: rgba(255, 118, 121, .12);
    --ok: #4cc98a;
    --ok-soft: rgba(76, 201, 138, .14);
    --shadow: 0 12px 34px rgba(0, 0, 0, .38);
    --shadow-sm: 0 2px 12px rgba(0, 0, 0, .28);
}

*, *::before, *::after { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: system-ui, -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
/* 视觉隐藏但保留语义：页面主标题只给搜索引擎与辅助技术读取 */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    clip-path: inset(50%);
    white-space: nowrap;
    border: 0;
}
h1, h2, h3, p { margin-top: 0; }
code {
    padding: 1px 6px;
    border-radius: 6px;
    background: var(--surface-alt);
    font-size: .9em;
}
kbd {
    padding: 1px 6px;
    border: 1px solid var(--border);
    border-bottom-width: 2px;
    border-radius: 6px;
    background: var(--surface);
    font-size: 12px;
    font-family: inherit;
}
.wrap { width: min(1380px, calc(100% - 40px)); margin: 0 auto; }
.muted { color: var(--muted); }
.noscript-tip { margin-top: 24px; color: var(--muted); font-size: 14px; }

/* 品牌 */
.brand { display: inline-flex; align-items: center; gap: 10px; font-weight: 700; }
.brand-mark {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border-radius: 10px;
    background: linear-gradient(135deg, #5a7bff, #9a6bff);
    color: #fff;
    font-size: 18px;
    box-shadow: 0 6px 16px rgba(90, 123, 255, .35);
}
.brand-text { font-size: 17px; letter-spacing: .3px; }
.brand-text small { display: block; font-size: 11px; font-weight: 500; color: var(--muted); }

/* 按钮 */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    font-size: 14px;
    font-weight: 600;
    white-space: nowrap;
    transition: transform .15s ease, border-color .15s ease, background .15s ease, box-shadow .15s ease;
}
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn:active { transform: translateY(1px); }
.btn-primary {
    border-color: transparent;
    background: var(--accent);
    color: #fff;
    box-shadow: 0 6px 16px rgba(76, 111, 255, .22);
}
.btn-primary:hover { background: var(--accent-strong); color: #fff; }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: var(--accent-soft); }
.btn-sm { padding: 5px 10px; font-size: 12px; border-radius: 8px; }
.btn-danger { color: var(--danger); border-color: var(--border); }
.btn-danger:hover { background: var(--danger-soft); border-color: var(--danger); color: var(--danger); }
.btn-block { width: 100%; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--surface);
    font-size: 16px;
}
.icon-btn:hover { border-color: var(--accent); }
.link-button {
    border: 0;
    background: none;
    padding: 0;
    color: var(--muted);
    font-size: 13px;
    text-align: left;
}
.link-button:hover { color: var(--accent); }
.side-link { color: var(--accent); font-size: 13px; }
.side-link:hover { text-decoration: underline; }

/* 表单 */
input[type="text"], input[type="search"], input[type="password"],
input[type="number"], input[type="url"], select, textarea {
    width: 100%;
    padding: 9px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    outline: none;
    transition: border-color .15s ease, box-shadow .15s ease;
}
input:focus, select:focus, textarea:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
}
input[type="file"] {
    width: 100%;
    padding: 9px;
    border: 1px dashed var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface-alt);
    font-size: 13px;
}
input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--accent); }
label { font-size: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field > span, .stack-form label { font-weight: 600; font-size: 13px; }
.field em { color: var(--danger); font-style: normal; }
.field-wide { grid-column: 1 / -1; }
.form-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px 20px;
}
.form-actions { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.form-actions .muted { font-size: 12px; }
.stack-form { display: flex; flex-direction: column; gap: 10px; }
.stack-form input, .stack-form select { max-width: 100%; }
.form-divider { width: 100%; height: 0; margin: 8px 0; border: 0; border-top: 1px solid var(--border); }
.code-textarea { min-height: 190px; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12.5px; line-height: 1.55; resize: vertical; }
.checkbox-line { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 500; }
.checkbox-field { justify-content: flex-end; }

/* 提示、面板、表格 */
.alert {
    padding: 11px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    font-size: 14px;
    margin-bottom: 20px;
}
.alert-success { border-color: var(--ok); background: var(--ok-soft); }
.alert-error { border-color: var(--danger); background: var(--danger-soft); color: var(--danger); }
.badge {
    display: inline-block;
    padding: 2px 9px;
    border-radius: 999px;
    background: var(--surface-alt);
    color: var(--muted);
    font-size: 12px;
    white-space: nowrap;
}
.badge-ok { background: var(--ok-soft); color: var(--ok); }
.badge-off { background: var(--danger-soft); color: var(--danger); }
.panel {
    padding: 20px;
    margin-bottom: 20px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: var(--shadow-sm);
}
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.panel-head h2 { margin: 0; font-size: 16px; }
.panel-text { color: var(--muted); font-size: 14px; }
.panel-narrow { max-width: 560px; }
.hint { margin: 14px 0 0; color: var(--muted); font-size: 12.5px; }
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th, .table td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
.table th { color: var(--muted); font-size: 12px; font-weight: 600; letter-spacing: .4px; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: var(--surface-alt); }
.table-link:hover { color: var(--accent); }
.row-actions { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.inline-form { display: inline-flex; margin: 0; }
.tile {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 42px;
    height: 42px;
    flex: none;
    border-radius: 12px;
    border: 1px solid hsl(var(--hue) 70% 55% / .20);
    background: hsl(var(--hue) 75% 55% / .14);
    color: hsl(var(--hue) 68% 38%);
    font-size: 19px;
    font-weight: 700;
    line-height: 1;
    /* icon 字段最长 16 个字符，超出色块时裁掉，避免撑破卡片 */
    overflow: hidden;
    white-space: nowrap;
}
[data-theme="dark"] .tile { color: hsl(var(--hue) 85% 75%); }
/* 图标图片优先；加载失败时 onerror 给父节点加 no-img，自动回退到首字符 */
.tile { position: relative; }
.tile-img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    padding: 6px;
    object-fit: contain;
    border-radius: 8px;
    background: #fff;
}
.tile-letter { display: inline; }
.tile.has-img .tile-letter { display: none; }
.tile.no-img .tile-letter { display: inline; }
.tile.no-img .tile-img { display: none; }
.tile-sm { width: 32px; height: 32px; border-radius: 9px; font-size: 15px; }
.tile-sm .tile-img { padding: 4px; border-radius: 6px; }

@media (max-width: 720px) {
    .wrap { width: min(100% - 28px, 1380px); }
    .form-grid { grid-template-columns: 1fr; }
    .field-wide { grid-column: auto; }
}
