/* ==========================================================================
   站点后台 · 单页控制台样式
   ========================================================================== */

:root {
    --ink: #111827;
    --ink-2: #374151;
    --ink-3: #4b5563;
    --muted: #6b7280;
    --muted-2: #9ca3af;
    --line: #e5e7eb;
    --line-soft: #f1f2f4;
    --bg: #ffffff;
    --bg-soft: #f7f8fa;
    --brand: #2563eb;
    --brand-ink: #1d4ed8;
    --brand-soft: #eff6ff;
    --ok: #059669;
    --ok-soft: #ecfdf5;
    --warn: #b45309;
    --warn-soft: #fffbeb;
    --danger: #dc2626;
    --danger-soft: #fef2f2;
    --radius: 12px;
    --radius-sm: 8px;
    --shadow-sm: 0 1px 2px rgba(16, 24, 40, .04), 0 1px 3px rgba(16, 24, 40, .06);
    --shadow-lg: 0 24px 60px rgba(16, 24, 40, .18);
    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", sans-serif;
    --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    --side-w: 232px;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
    margin: 0;
    background: var(--bg-soft);
    color: var(--ink);
    font-family: var(--font);
    font-size: 14px;
    line-height: 1.7;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--brand); text-decoration: none; }
a:hover { color: var(--brand-ink); }

/* ---------- 布局 ---------- */

.admin {
    display: grid;
    grid-template-columns: var(--side-w) minmax(0, 1fr);
    min-height: 100vh;
}

.side {
    position: sticky;
    top: 0;
    height: 100vh;
    display: flex;
    flex-direction: column;
    background: #fff;
    border-right: 1px solid var(--line);
    padding: 18px 14px;
}

.side__brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 4px 8px 18px;
    color: var(--ink);
    font-weight: 650;
    font-size: 15px;
}
.side__mark {
    width: 28px;
    height: 28px;
    border-radius: 8px;
    object-fit: contain;
    flex: none;
    display: block;
}

.side__group { margin-bottom: 6px; }
.side__label {
    padding: 10px 10px 6px;
    font-size: 11.5px;
    font-weight: 650;
    letter-spacing: .8px;
    text-transform: uppercase;
    color: var(--muted-2);
}
.side__link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    margin-bottom: 2px;
    border-radius: var(--radius-sm);
    color: var(--ink-3);
    font-size: 14px;
    cursor: pointer;
    transition: background .15s, color .15s;
}
.side__link:hover { background: var(--bg-soft); color: var(--ink); }
.side__link.is-active { background: var(--brand-soft); color: var(--brand-ink); font-weight: 550; }
.side__link svg { flex: 0 0 auto; opacity: .8; }
.side__link .count {
    margin-left: auto;
    font-size: 11.5px;
    color: var(--muted);
    background: var(--bg-soft);
    border-radius: 999px;
    padding: 0 7px;
}
.side__link.is-active .count { background: #fff; color: var(--brand-ink); }

.side__foot { margin-top: auto; padding-top: 14px; border-top: 1px solid var(--line-soft); }

.main { min-width: 0; display: flex; flex-direction: column; }

.topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    height: 60px;
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 0 26px;
    background: rgba(255, 255, 255, .9);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--line);
}
.topbar h1 { margin: 0; font-size: 16px; font-weight: 650; letter-spacing: -.2px; }
.topbar__spacer { margin-left: auto; }
.topbar__user {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: var(--muted);
    font-size: 13px;
}

.view { padding: 24px 26px 60px; }

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

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    height: 34px;
    padding: 0 14px;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    background: var(--bg-soft);
    color: var(--ink-2);
    font-family: inherit;
    font-size: 13.5px;
    font-weight: 500;
    cursor: pointer;
    white-space: nowrap;
    transition: background .15s, color .15s, border-color .15s;
}
.btn:hover { background: #eceef1; color: var(--ink); }
.btn--primary { background: var(--brand); color: #fff; }
.btn--primary:hover { background: var(--brand-ink); color: #fff; }
.btn--ghost { background: #fff; border-color: var(--line); }
.btn--ghost:hover { background: var(--bg-soft); }
.btn--danger { background: var(--danger-soft); color: var(--danger); }
.btn--danger:hover { background: #fee2e2; }
.btn--sm { height: 28px; padding: 0 10px; font-size: 12.5px; }
.btn--block { width: 100%; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }

/* ---------- 卡片 / 统计 ---------- */

.card {
    background: #fff;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
}
.card__head {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 18px;
    border-bottom: 1px solid var(--line-soft);
    font-weight: 600;
    font-size: 14px;
}
.card__head .right { margin-left: auto; display: flex; gap: 8px; align-items: center; }
.card__body { padding: 18px; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(152px, 1fr)); gap: 14px; }
.stat {
    padding: 16px 18px;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
}
.stat__label { color: var(--muted); font-size: 12.5px; }
.stat__value { font-size: 26px; font-weight: 700; letter-spacing: -.6px; line-height: 1.3; margin-top: 2px; }
.stat__hint { color: var(--muted-2); font-size: 12px; margin-top: 2px; }

.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 16px; }

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

.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.table th,
.table td { padding: 11px 14px; text-align: left; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
.table th {
    position: sticky;
    top: 0;
    background: #fbfbfc;
    color: var(--muted);
    font-weight: 600;
    font-size: 12.5px;
    white-space: nowrap;
}
.table tbody tr:hover { background: #fafbfc; }
.table td.title-cell { max-width: 420px; }
.table .cell-title { color: var(--ink); font-weight: 500; display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.table .cell-sub { color: var(--muted-2); font-size: 12px; }
.table .actions { display: flex; gap: 6px; justify-content: flex-end; }
.table .num { color: var(--muted); font-variant-numeric: tabular-nums; }

.badge {
    display: inline-flex;
    align-items: center;
    height: 22px;
    padding: 0 8px;
    border-radius: 999px;
    font-size: 12px;
    background: var(--bg-soft);
    color: var(--ink-3);
}
.badge--ok { background: var(--ok-soft); color: var(--ok); }
.badge--warn { background: var(--warn-soft); color: var(--warn); }
.badge--brand { background: var(--brand-soft); color: var(--brand-ink); }
.badge--danger { background: var(--danger-soft); color: var(--danger); }

/* 顶部提示条 */
.notice {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    margin-bottom: 14px;
    padding: 12px 16px;
    border-radius: var(--radius);
    font-size: 13px;
    border: 1px solid var(--line);
    background: #fff;
    color: var(--ink-3);
}
.notice--warn { background: var(--warn-soft); border-color: #fde68a; color: #92400e; }
.notice a { color: inherit; font-weight: 600; text-decoration: underline; }

/* 只读详情里的小标题与代码块 */
.kv-title { font-size: 12px; color: var(--muted-2); letter-spacing: .04em; margin: 0 0 6px; }
.mail-body {
    margin: 0;
    padding: 14px;
    background: var(--bg-soft);
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    font-size: 13px;
    line-height: 1.7;
    white-space: pre-wrap;
    word-break: break-word;
    max-height: 320px;
    overflow: auto;
}

.toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
    padding: 14px 18px;
    border-bottom: 1px solid var(--line-soft);
}
.toolbar .spacer { margin-left: auto; }

.input,
.select,
.textarea {
    height: 34px;
    padding: 0 11px;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    background: #fff;
    font-family: inherit;
    font-size: 13.5px;
    color: var(--ink);
    outline: none;
    transition: border-color .15s, box-shadow .15s;
}
.input:focus,
.select:focus,
.textarea:focus { border-color: #93c5fd; box-shadow: 0 0 0 3px rgba(37, 99, 235, .1); }
.input--search { width: 220px; padding-left: 30px; background: #fff url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%239ca3af' stroke-width='2'><circle cx='11' cy='11' r='7'/><path d='m20 20-3.2-3.2'/></svg>") no-repeat 9px center; }

.pager { display: flex; align-items: center; gap: 6px; padding: 14px 18px; border-top: 1px solid var(--line-soft); }
.pager__info { color: var(--muted); font-size: 12.5px; margin-right: auto; }
.pager__btn {
    min-width: 30px;
    height: 30px;
    padding: 0 8px;
    border: 1px solid var(--line);
    border-radius: 7px;
    background: #fff;
    color: var(--ink-3);
    font-size: 13px;
    cursor: pointer;
}
.pager__btn:hover:not([disabled]) { border-color: #c7d2fe; color: var(--brand); }
.pager__btn.is-active { background: var(--ink); border-color: var(--ink); color: #fff; }
.pager__btn[disabled] { opacity: .45; cursor: not-allowed; }

/* ---------- 抽屉编辑器 ---------- */

.drawer-mask {
    position: fixed;
    inset: 0;
    background: rgba(17, 24, 39, .35);
    opacity: 0;
    pointer-events: none;
    transition: opacity .2s;
    z-index: 60;
}
.drawer-mask.is-open { opacity: 1; pointer-events: auto; }

.drawer {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    width: min(760px, 94vw);
    display: flex;
    flex-direction: column;
    background: #fff;
    box-shadow: var(--shadow-lg);
    transform: translateX(102%);
    transition: transform .24s cubic-bezier(.32, .72, 0, 1);
    z-index: 61;
}
.drawer.is-open { transform: none; }
.drawer__head {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px 20px;
    border-bottom: 1px solid var(--line);
}
.drawer__head h2 { margin: 0; font-size: 15.5px; }
.drawer__head .right { margin-left: auto; display: flex; gap: 8px; }
.drawer__body { flex: 1; overflow: auto; padding: 20px; }
.drawer__foot {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 20px;
    border-top: 1px solid var(--line);
    background: #fcfcfd;
}
.drawer__foot .right { margin-left: auto; display: flex; gap: 8px; }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-grid .full { grid-column: 1 / -1; }

.field label { display: block; margin-bottom: 6px; font-size: 12.5px; font-weight: 600; color: var(--ink-2); }
.field .input,
.field .select,
.field .textarea { width: 100%; }
.field .textarea { height: auto; padding: 10px 12px; resize: vertical; min-height: 90px; line-height: 1.7; }
.field .textarea--code { font-family: var(--mono); font-size: 12.5px; }
.field__hint { margin: 6px 0 0; color: var(--muted-2); font-size: 12px; }

.editor-tabs { display: flex; gap: 6px; margin-bottom: 8px; }
.editor-tabs button {
    height: 28px;
    padding: 0 10px;
    border: 1px solid var(--line);
    border-radius: 7px;
    background: #fff;
    font-size: 12.5px;
    color: var(--ink-3);
    cursor: pointer;
}
.editor-tabs button.is-active { background: var(--brand-soft); border-color: #bfdbfe; color: var(--brand-ink); }
.editor-preview {
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    padding: 14px 16px;
    min-height: 260px;
    max-height: 52vh;
    overflow: auto;
    font-size: 14.5px;
    line-height: 1.8;
}
.editor-preview img { max-width: 100%; }
.editor-preview pre { background: #0f172a; color: #e2e8f0; padding: 14px; border-radius: 8px; overflow: auto; }
.editor-preview code { font-family: var(--mono); font-size: .9em; }
.editor-preview table { width: 100%; border-collapse: collapse; }
.editor-preview th, .editor-preview td { border: 1px solid var(--line); padding: 8px 10px; }

/* ---------- 弹窗 / 提示 ---------- */

.modal-mask {
    position: fixed;
    inset: 0;
    background: rgba(17, 24, 39, .4);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 80;
    padding: 24px;
}
.modal {
    width: min(420px, 100%);
    background: #fff;
    border-radius: 14px;
    box-shadow: var(--shadow-lg);
    overflow: hidden;
}
.modal__body { padding: 22px; }
.modal__title { margin: 0 0 8px; font-size: 16px; }
.modal__text { margin: 0; color: var(--ink-3); font-size: 13.5px; }
.modal__foot { display: flex; justify-content: flex-end; gap: 10px; padding: 14px 22px; border-top: 1px solid var(--line-soft); background: #fcfcfd; }

.toast-host { position: fixed; right: 20px; bottom: 20px; z-index: 120; display: flex; flex-direction: column; gap: 10px; }
.toast {
    min-width: 200px;
    max-width: 340px;
    padding: 11px 15px;
    border-radius: 10px;
    background: #111827;
    color: #fff;
    font-size: 13px;
    box-shadow: 0 10px 30px rgba(16, 24, 40, .22);
    animation: toast-in .18s ease-out;
}
.toast--ok { background: #065f46; }
.toast--err { background: #991b1b; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.empty-state { padding: 56px 20px; text-align: center; color: var(--muted); }
.empty-state strong { display: block; color: var(--ink-2); margin-bottom: 6px; }

.loading { padding: 40px; text-align: center; color: var(--muted); }
.spinner {
    width: 18px;
    height: 18px;
    border: 2px solid var(--line);
    border-top-color: var(--brand);
    border-radius: 50%;
    display: inline-block;
    animation: spin .7s linear infinite;
    vertical-align: -3px;
    margin-right: 8px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- 登录页 ---------- */

.login-wrap {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background:
        radial-gradient(900px 420px at 50% -10%, #eff6ff 0%, rgba(255, 255, 255, 0) 70%),
        var(--bg-soft);
}
.login-card {
    width: min(400px, 100%);
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 16px;
    padding: 32px;
    box-shadow: var(--shadow-sm);
}
.login-card h1 { margin: 0 0 6px; font-size: 20px; }
.login-card .sub { margin: 0 0 22px; color: var(--muted); font-size: 13.5px; }
.login-card .field { margin-bottom: 14px; }
.login-card .field input { width: 100%; height: 40px; }
.login-error {
    display: none;
    margin-bottom: 14px;
    padding: 9px 12px;
    border-radius: 8px;
    background: var(--danger-soft);
    color: var(--danger);
    font-size: 13px;
}
.login-error.is-open { display: block; }

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

@media (max-width: 860px) {
    .admin { grid-template-columns: 1fr; }
    .side {
        position: fixed;
        left: 0;
        top: 0;
        bottom: 0;
        width: 250px;
        z-index: 70;
        transform: translateX(-102%);
        transition: transform .22s;
    }
    .side.is-open { transform: none; }
    .view { padding: 18px 16px 60px; }
    .topbar { padding: 0 16px; }
    .form-grid { grid-template-columns: 1fr; }
    .input--search { width: 150px; }
    .side-toggle { display: inline-flex !important; }
}

.side-toggle {
    display: none;
    width: 34px;
    height: 34px;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    color: var(--ink-2);
    cursor: pointer;
}
