/* ─── 后台样式 ───
   与前台共用同一套设计语言，但独立成文件，避免前台样式反复影响后台 */

:root {
    color-scheme: light;
    --c-bg: #f5f6f7;
    --c-surface: #ffffff;
    --c-border: #e3e8ef;
    --c-text: #1a2230;
    --c-dim: #5b6675;
    --c-mute: #8b98a5;
    --c-accent: #007d99;
    --c-accent-2: #00d8ff;
    --c-danger: #d94a4a;
    --radius: 0;
    --shadow: 0 2px 8px rgba(50, 50, 93, 0.06), 0 1px 3px rgba(0, 0, 0, 0.04);
    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
        "Hiragino Sans GB", "Microsoft YaHei", Arial, sans-serif;
    --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

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

body {
    margin: 0;
    min-height: 100vh;
    background: var(--c-bg);
    color: var(--c-text);
    font-family: var(--font);
    font-size: 14px;
    line-height: 1.7;
    -webkit-font-smoothing: antialiased;
}

a {
    color: var(--c-accent);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

/* ─── 布局：可折叠的深色侧栏 + 右侧白色内容 ─── */
.admin-layout {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    min-height: 100vh;
}

.admin-sidebar {
    position: sticky;
    top: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 64px;
    height: 100vh;
    padding: 10px 0 14px;
    overflow: hidden;
    background: #12161c;
    transition: width 0.25s cubic-bezier(0.4, 0, 0, 1);
}

.admin-sidebar.is-open {
    width: 240px;
    align-items: stretch;
}

.admin-sidebar.is-open .admin-sidebar.is-open .admin-sidebar:not(.is-open) /* 头部：纯文字居中，底部一条细线与菜单分隔 */
.admin-head {
    display: block;
    padding: 10px 12px 16px;
    text-align: center;
    text-decoration: none;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.admin-head:hover {
    text-decoration: none;
}

/* 收起为竖条时只留一个字，间距同步收紧 */
.admin-sidebar:not(.is-open) .admin-head {
    padding: 8px 0 14px;
}

.admin-head-mark {
    display: none;
    font-size: 16px;
    font-weight: 600;
    color: #fff;
    line-height: 1.2;
}

.admin-sidebar:not(.is-open) .admin-head-mark {
    display: block;
}

.admin-head-text {
    display: none;
}

.admin-sidebar.is-open .admin-head-text {
    display: block;
}

.admin-head-text b {
    display: block;
    font-size: 14px;
    font-weight: 600;
    letter-spacing: 0.01em;
    color: #fff;
    text-align: center;
}

.admin-head-text em {
    display: block;
    margin-top: 4px;
    font-style: normal;
    font-size: 11.5px;
    letter-spacing: 0.04em;
    color: rgba(255, 255, 255, 0.42);
    text-align: center;
}

/* 头部与菜单之间留出呼吸空间 */
.admin-menu {
    display: grid;
    gap: 0;
    width: 100%;
    padding-top: 8px;
}

/* 按钮撑满侧栏整行；收起时只显示图标，展开后左侧对齐并显示文字 */
.admin-menu a {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    width: 100%;
    height: 48px;
    color: rgba(255, 255, 255, 0.55);
    white-space: nowrap;
    transition: background-color 0.2s, color 0.2s;
}

.admin-menu a span {
    display: none;
    font-size: 13.5px;
}

.admin-sidebar.is-open .admin-menu a {
    justify-content: flex-start;
    padding-left: 20px;
}

.admin-sidebar.is-open .admin-menu a span {
    display: inline;
}

.admin-menu a:hover {
    color: #fff;
    background: rgba(255, 255, 255, 0.08);
    text-decoration: none;
}

.admin-menu a.is-active {
    color: #00d8ff;
    background: rgba(0, 216, 255, 0.14);
}

.admin-menu svg {
    flex: 0 0 auto;
    width: 17px;
    height: 17px;
    fill: currentColor;
}

/* 底部区撑满侧栏宽度，收起为竖条时按钮才能左右全宽 */
.admin-sidebar-foot {
    width: 100%;
    margin-top: auto;
}

.admin-sidebar-foot a,
.admin-sidebar-foot button {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    width: 100%;
    height: 48px;
    padding: 0;
    font-family: inherit;
    font-size: 13.5px;
    color: rgba(255, 255, 255, 0.45);
    background: transparent;
    border: 0;
    white-space: nowrap;
    cursor: pointer;
    transition: background-color 0.2s, color 0.2s;
}

.admin-sidebar-foot a span,
.admin-sidebar-foot button span {
    display: none;
    font-size: 13.5px;
}

.admin-sidebar.is-open .admin-sidebar-foot a,
.admin-sidebar-foot button {
    justify-content: flex-start;
    padding-left: 20px;
}

.admin-sidebar.is-open .admin-sidebar-foot a span,
.admin-sidebar.is-open .admin-sidebar-foot button span {
    display: inline;
}

.admin-sidebar-foot a:hover,
.admin-sidebar-foot button:hover {
    color: #fff;
    background: rgba(255, 255, 255, 0.08);
}

.admin-sidebar-foot svg {
    flex: 0 0 auto;
    width: 17px;
    height: 17px;
    fill: currentColor;
}

.admin-body {
    display: flex;
    flex-direction: column;
    min-width: 0;
    background: var(--c-bg);
}

.admin-topbar {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    gap: 16px;
    height: 56px;
    padding: 0 20px 0 12px;
    background: var(--c-surface);
    border-bottom: 1px solid var(--c-border);
}

/* 汉堡贴左侧，只做侧栏开关 */
.admin-burger {
    justify-self: start;
    display: grid;
    place-items: center;
    width: 34px;
    height: 34px;
    padding: 0;
    color: var(--c-dim);
    background: transparent;
    border: 0;
    cursor: pointer;
    transition: color 0.2s, background-color 0.2s;
}

.admin-burger:hover {
    color: var(--c-accent);
    background: var(--c-bg);
}

.admin-burger svg {
    width: 18px;
    height: 18px;
    fill: currentColor;
}

.admin-crumb {
    grid-column: 2;
    font-size: 13px;
    color: var(--c-mute);
    text-align: center;
}

.admin-topbar-right {
    grid-column: 3;
    justify-self: end;
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 13px;
    color: var(--c-dim);
}

.admin-back {
    color: var(--c-dim);
}

.admin-back:hover {
    color: var(--c-accent);
    text-decoration: none;
}

.admin-sep {
    color: var(--c-border);
    user-select: none;
}

.admin-crumb em {
    margin: 0 6px;
    font-style: normal;
    opacity: 0.5;
}

.admin-crumb b {
    font-weight: 500;
    color: var(--c-text);
}

.admin-user {
    display: flex;
    align-items: center;
    gap: 6px;
}

.admin-avatar {
    width: 26px;
    height: 26px;
    border-radius: 50%;   /* 头像是圆的，不参与直角改动 */
    object-fit: cover;
    background: var(--c-bg);
}

.admin-main {
    flex: 1;
    padding: 22px 24px 48px;
}

/* 未登录时的居中布局 */
.admin-auth {
    display: grid;
    place-items: center;
    min-height: 100vh;
}

.auth-page {
    width: 100%;
    padding: 24px;
}

/* ─── 工作台统计卡 ─── */
.stat-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 16px;
    margin-bottom: 20px;
}

.stat-card {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 18px 20px;
    background: var(--c-surface);
    border: 1px solid var(--c-border);
    border-radius: 0;
}

.stat-label {
    font-size: 12.5px;
    color: var(--c-mute);
}

.stat-value {
    margin-top: 6px;
    font-size: 26px;
    font-weight: 600;
    line-height: 1.1;
    color: var(--c-text);
}

.stat-icon {
    display: grid;
    place-items: center;
    width: 40px;
    height: 40px;
    border-radius: 0;
}

.stat-icon svg {
    width: 18px;
    height: 18px;
    fill: currentColor;
}

.tone-blue   { color: #3b82f6; background: rgba(59, 130, 246, 0.12); }
.tone-amber  { color: #e39b28; background: rgba(227, 155, 40, 0.12); }
.tone-green  { color: #27a567; background: rgba(39, 165, 103, 0.12); }
.tone-violet { color: #8b5cf6; background: rgba(139, 92, 246, 0.12); }

/* ─── 面板 ─── */
.panel {
    background: var(--c-surface);
    border: 1px solid var(--c-border);
    border-radius: 0;
    overflow: hidden;
}

.panel-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 18px;
    border-bottom: 1px solid var(--c-border);
}

.panel-title {
    font-size: 14px;
    font-weight: 600;
}

.panel-more {
    font-size: 12.5px;
    color: var(--c-mute);
}

.panel-more:hover {
    color: var(--c-accent);
    text-decoration: none;
}

.panel-empty {
    padding: 40px 18px;
    text-align: center;
    font-size: 13px;
    color: var(--c-mute);
}

@media (max-width: 860px) {
    .admin-layout {
        grid-template-columns: 1fr;
    }

    /* 窄屏侧栏转为顶部横条，仍保持深色；横排时不需要折叠 */
    .admin-sidebar,
    .admin-sidebar.is-open {
        width: 100%;
        height: auto;
        flex-direction: row;
        align-items: center;
        gap: 8px;
        padding: 8px 12px;
        position: sticky;
        top: 0;
        z-index: 20;
    }

        /* 横条形态下头部只留方块标记 */
    .admin-head {
        padding: 0;
    }

    .admin-head-text {
        display: none !important;
    }

    .admin-sidebar .admin-menu a,
    .admin-sidebar .admin-sidebar-foot a,
.admin-sidebar-foot button {
        width: 44px;
        padding-left: 0;
        justify-content: center;
    }

    .admin-sidebar .admin-menu a span,
    .admin-sidebar .admin-sidebar-foot a span,
.admin-sidebar-foot button span {
        display: none !important;
    }

    .admin-menu {
        grid-auto-flow: column;
        gap: 4px;
        width: auto;
    }

    /* 横排时不能再用整行宽度，否则每个图标都会撑满 */
    .admin-menu a {
        width: 44px;
    }

    .admin-sidebar-foot {
        margin-top: 0;
        margin-left: auto;
    }

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

    .admin-topbar {
        padding: 0 16px;
    }

    .admin-main {
        padding: 16px 16px 40px;
    }
}

/* 登录 / 初始化 */
.auth-box {
    max-width: 380px;
    margin: 60px auto;
    padding: 32px 30px 34px;
    background: var(--c-surface);
    border-radius: 0;
    box-shadow: var(--shadow);
}

.auth-box h1 {
    margin: 0;
    font-size: 20px;
    font-weight: 600;
}

.auth-sub {
    margin: 6px 0 22px;
    font-size: 13px;
    color: var(--c-mute);
}

.auth-error {
    margin-bottom: 16px;
    padding: 9px 12px;
    font-size: 13px;
    color: var(--c-danger);
    background: rgba(217, 74, 74, 0.08);
    border-radius: 0;
}

.auth-form label {
    display: block;
    margin-bottom: 14px;
}

.auth-form label span {
    display: block;
    margin-bottom: 6px;
    font-size: 13px;
    color: var(--c-dim);
}

.auth-form input[type="text"],
.auth-form input[type="password"] {
    width: 100%;
    height: 38px;
    padding: 0 12px;
    font-family: inherit;
    font-size: 14px;
    color: var(--c-text);
    background: var(--c-bg);
    border: 1px solid var(--c-border);
    border-radius: 0;
    outline: none;
    transition: border-color 0.2s;
}

.auth-form input:focus {
    border-color: var(--c-accent-2);
}

.btn-submit {
    width: 100%;
    height: 40px;
    margin-top: 8px;
    font-family: inherit;
    font-size: 14px;
    font-weight: 500;
    color: #fff;
    background: var(--c-accent);
    border: 0;
    border-radius: 0;
    cursor: pointer;
    transition: opacity 0.2s;
}

.btn-submit:hover {
    opacity: 0.9;
}

@media (max-width: 576px) {
    .auth-box {
        margin: 24px auto;
        padding: 24px 20px 26px;
    }
}

/* ─── 列表页 ─── */
.admin-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 18px;
}

.admin-bar h1 {
    margin: 0;
    font-size: 20px;
    font-weight: 600;
}

.admin-bar .count {
    margin-left: 6px;
    font-size: 13px;
    font-weight: 400;
    color: var(--c-mute);
}

.btn-primary {
    display: inline-flex;
    align-items: center;
    height: 36px;
    padding: 0 16px;
    font-size: 13.5px;
    color: #fff;
    background: var(--c-accent);
    border-radius: 0;
}

.btn-primary:hover {
    opacity: 0.9;
    text-decoration: none;
}

.admin-flash {
    margin-bottom: 16px;
    padding: 9px 14px;
    font-size: 13px;
    color: var(--c-accent);
    background: rgba(0, 216, 255, 0.1);
    border-radius: 0;
}

.admin-empty {
    padding: 60px 20px;
    text-align: center;
    color: var(--c-mute);
    background: var(--c-surface);
    border-radius: 0;
    box-shadow: var(--shadow);
}

.admin-table {
    width: 100%;
    border-collapse: collapse;
    overflow: hidden;
    background: var(--c-surface);
    border-radius: 0;
    box-shadow: var(--shadow);
}

/* 放进 panel 时由 panel 提供容器，表格不再自带圆角与阴影 */
.panel .admin-table {
    border-radius: 0;
    box-shadow: none;
}

.admin-table th,
.admin-table td {
    padding: 12px 16px;
    font-size: 13.5px;
    text-align: left;
    border-bottom: 1px solid var(--c-border);
}

.admin-table th {
    font-size: 12.5px;
    font-weight: 500;
    color: var(--c-mute);
    background: var(--c-bg);
}

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

.t-title {
    font-weight: 500;
    color: var(--c-text);
}

.t-title:hover {
    color: var(--c-accent);
    text-decoration: none;
}

.t-slug {
    margin-top: 3px;
    font-family: var(--mono);
    font-size: 12px;
    color: var(--c-mute);
}

.t-date {
    font-size: 12.5px;
    color: var(--c-mute);
    white-space: nowrap;
}

.t-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

.t-actions a {
    font-size: 13px;
}

.t-actions form {
    display: inline;
    margin: 0;
}

.link-danger {
    padding: 0;
    font-family: inherit;
    font-size: 13px;
    color: var(--c-danger);
    background: none;
    border: 0;
    cursor: pointer;
}

.badge {
    display: inline-block;
    padding: 1px 8px;
    font-size: 11.5px;
    border-radius: 0;
}

.badge-live {
    color: #0a7d4f;
    background: rgba(45, 206, 137, 0.14);
}

.badge-draft {
    color: var(--c-mute);
    background: var(--c-bg);
}

.badge-top {
    color: var(--c-accent);
    background: rgba(0, 216, 255, 0.14);
}

/* ─── 编辑器 ─── */
.editor-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 280px;
    gap: 20px;
    align-items: start;
}

.editor-main {
    padding: 18px;
    background: var(--c-surface);
    border-radius: 0;
    box-shadow: var(--shadow);
}

.ed-title {
    width: 100%;
    padding: 0 0 12px;
    font-family: inherit;
    font-size: 22px;
    font-weight: 600;
    color: var(--c-text);
    background: transparent;
    border: 0;
    border-bottom: 1px solid var(--c-border);
    outline: none;
}

.ed-title:focus {
    border-bottom-color: var(--c-accent-2);
}

.ed-body {
    width: 100%;
    min-height: 62vh;
    padding: 14px 18px 14px 0;
    font-family: var(--mono);
    font-size: 13.5px;
    line-height: 1.8;
    color: var(--c-text);
    background: transparent;
    border: 0;
    outline: none;
    resize: vertical;
}

/* 编辑 / 预览分屏：左边写，右边看，同一套渲染保证所见即所得 */
.ed-split {
    display: grid;
    grid-template-columns: 1fr 1fr;
    margin-top: 14px;
    border-top: 1px solid var(--c-border);
}

.ed-preview-title {
    margin: 0 0 14px;
    padding: 0 0 12px;
    font-size: 21px;
    font-weight: 600;
    line-height: 1.4;
    color: var(--c-text);
    border-bottom: 1px solid var(--c-border);
    word-break: break-word;
}

.ed-preview {
    position: relative;
    min-height: 62vh;
    max-height: 78vh;
    overflow-y: auto;
    padding: 14px 0 14px 18px;
    border-left: 1px solid var(--c-border);
    font-size: 14.5px;
    line-height: 1.8;
    color: var(--c-text);
}

.ed-preview-hint {
    font-size: 13px;
    color: var(--c-mute);
}

/* 预览区的正文排版：与前台文章保持一致的精简版 */
.ed-preview h1,
.ed-preview h2,
.ed-preview h3,
.ed-preview h4 {
    margin: 22px 0 10px;
    color: var(--c-text);
    line-height: 1.4;
}

.ed-preview h2 { font-size: 19px; }
.ed-preview h3 { font-size: 16px; }

.ed-preview p { margin: 12px 0; }

.ed-preview a {
    color: var(--c-accent);
    border-bottom: 1px solid rgba(0, 216, 255, 0.4);
}

.ed-preview ul,
.ed-preview ol {
    margin: 12px 0;
    padding-left: 22px;
}

.ed-preview li { margin: 5px 0; }

.ed-preview blockquote {
    margin: 16px 0;
    padding: 10px 14px;
    border-left: 3px solid var(--c-accent-2);
    background: var(--c-bg);
    color: var(--c-dim);
}

.ed-preview code {
    padding: 2px 5px;
    font-family: var(--mono);
    font-size: 0.9em;
    color: var(--c-accent);
    background: var(--c-bg);
    border-radius: 0;
}

.ed-preview .code-block {
    margin: 16px 0;
    border: 1px solid var(--c-border);
    border-radius: 0;
    overflow: hidden;
    background: var(--c-bg);
}

.ed-preview .code-bar {
    padding: 6px 12px;
    font-size: 11.5px;
    color: var(--c-mute);
    border-bottom: 1px solid var(--c-border);
}

.ed-preview .code-copy { display: none; }

.ed-preview .code-block pre {
    margin: 0;
    padding: 12px;
    overflow-x: auto;
}

.ed-preview .code-block code {
    padding: 0;
    background: none;
    color: var(--c-text);
    font-size: 12.5px;
    line-height: 1.7;
}

.ed-preview img {
    max-width: 100%;
    border-radius: 0;
}

.ed-preview hr {
    margin: 22px 0;
    border: 0;
    border-top: 1px solid var(--c-border);
}

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

.ed-preview th,
.ed-preview td {
    padding: 7px 10px;
    border: 1px solid var(--c-border);
    text-align: left;
}

.editor-side {
    display: grid;
    gap: 14px;
    padding: 18px;
    background: var(--c-surface);
    border-radius: 0;
    box-shadow: var(--shadow);
}

.side-field label {
    display: block;
    margin-bottom: 5px;
    font-size: 12.5px;
    color: var(--c-mute);
}

.side-field input,
.side-field select,
.side-field textarea {
    width: 100%;
    padding: 7px 10px;
    font-family: inherit;
    font-size: 13px;
    color: var(--c-text);
    background: var(--c-bg);
    border: 1px solid var(--c-border);
    border-radius: 0;
    outline: none;
}

.side-field textarea {
    resize: vertical;
}

.side-field input:focus,
.side-field select:focus,
.side-field textarea:focus {
    border-color: var(--c-accent-2);
}

.side-check {
    display: flex;
    align-items: center;
    gap: 7px;
    font-size: 13px;
    color: var(--c-dim);
    cursor: pointer;
}

.side-actions {
    display: grid;
    gap: 8px;
    margin-top: 4px;
}

.btn-ghost {
    height: 38px;
    font-family: inherit;
    font-size: 13.5px;
    color: var(--c-text);
    background: var(--c-bg);
    border: 1px solid var(--c-border);
    border-radius: 0;
    cursor: pointer;
}

.btn-ghost:hover {
    border-color: var(--c-accent-2);
}

.side-link {
    font-size: 12.5px;
    text-align: center;
    color: var(--c-mute);
}

@media (max-width: 860px) {
    .editor-grid {
        grid-template-columns: 1fr;
    }

    /* 窄屏不再左右分屏，预览挪到编辑器下方 */
    .ed-split {
        grid-template-columns: 1fr;
    }

    .ed-preview {
        min-height: 0;
        max-height: none;
        padding: 14px 0 0;
        border-left: 0;
        border-top: 1px solid var(--c-border);
    }

    .admin-table .t-date {
        display: none;
    }
}

/* ─── 轻提示（Ajax 操作用，不打断页面） ─── */
.admin-toast {
    position: fixed;
    left: 50%;
    bottom: 32px;
    z-index: 999;
    padding: 10px 20px;
    font-size: 13.5px;
    color: #fff;
    background: #1f2937;
    border-radius: 0;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
    animation: toast-in 0.22s ease forwards;
}

.admin-toast.is-error {
    background: var(--c-danger);
}

.admin-toast.is-out {
    animation: toast-out 0.3s ease forwards;
}

@keyframes toast-in {
    from { opacity: 0; transform: translate(-50%, 8px); }
    to   { opacity: 1; transform: translate(-50%, 0); }
}

@keyframes toast-out {
    from { opacity: 1; }
    to   { opacity: 0; }
}

/* ─── 提交中的转圈 ───
   按钮变灰的同时在文字前转一个圈，让「正在请求」这件事看得见 */
@keyframes admin-spin {
    to { transform: rotate(360deg); }
}

/* 只作用于按钮：预览区也用 is-loading 标记加载中，
   不限定元素会让按钮的转圈和透明度泄漏到预览区 */
button.is-loading {
    pointer-events: none;
    opacity: 0.72;
}

button.is-loading::before {
    content: "";
    display: inline-block;
    width: 12px;
    height: 12px;
    margin-right: 7px;
    vertical-align: -1px;
    border: 2px solid currentColor;
    border-top-color: transparent;
    border-radius: 50%;
    animation: admin-spin 0.7s linear infinite;
}

/* 预览正在重渲染：内容压暗 + 中间转圈，让人知道右边在更新 */
.ed-preview.is-loading .ed-preview-body {
    opacity: 0.35;
    transition: opacity 0.15s ease;
}

.ed-preview.is-loading::after {
    content: "";
    position: absolute;
    top: 50%;
    left: 50%;
    z-index: 2;
    width: 18px;
    height: 18px;
    margin: -9px 0 0 -9px;
    border: 2px solid var(--c-border);
    border-top-color: var(--c-accent);
    border-radius: 50%;
    animation: admin-spin 0.7s linear infinite;
}
