/* ============================================
   PacoHim 后台管理样式
   复用 style.css 的 :root 设计令牌，与站点视觉一致
   ============================================ */

/* ========== 布局基础 ========== */
.admin-body {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.hidden {
    display: none !important;
}

/* ========== 登录页 ========== */
.login-wrap {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background:
        radial-gradient(circle at 50% -10%, rgba(99, 102, 241, .14) 0%, transparent 55%),
        var(--bg);
}

.login-card {
    width: 100%;
    max-width: 380px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    padding: 40px 32px;
    box-shadow: var(--shadow-lg);
    animation: fadeInUp .5s var(--ease);
}

.login-logo {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    font-size: 20px;
    font-weight: 700;
    letter-spacing: -.02em;
    margin-bottom: 24px;
}

.login-title {
    font-size: 22px;
    font-weight: 700;
    text-align: center;
    letter-spacing: -.02em;
}

.login-sub {
    font-size: 14px;
    color: var(--text-secondary);
    text-align: center;
    margin: 8px 0 28px;
}

.login-hint {
    margin-top: 20px;
    font-size: 12px;
    color: var(--text-tertiary);
    text-align: center;
}

.login-hint code {
    padding: 1px 6px;
    background: var(--accent-light);
    border-radius: 4px;
    color: var(--accent);
    font-size: 12px;
}

/* ========== 后台骨架 ========== */
.app {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: 220px;
    flex-shrink: 0;
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    padding: 20px 12px;
    position: sticky;
    top: 0;
    height: 100vh;
}

.sidebar-logo {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 18px;
    font-weight: 700;
    letter-spacing: -.02em;
    padding: 4px 12px 20px;
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex: 1;
}

.side-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-secondary);
    border-radius: var(--radius-sm);
    transition: all .2s var(--ease);
    text-align: left;
}

.side-link:hover {
    color: var(--text);
    background: var(--surface-hover);
}

.side-link.active {
    color: var(--accent);
    background: var(--accent-light);
    font-weight: 600;
}

.side-link.danger {
    color: var(--text-secondary);
}

.side-link.danger:hover {
    color: #ef4444;
    background: rgba(239, 68, 68, .08);
}

.sidebar-footer {
    border-top: 1px solid var(--border-light);
    padding-top: 12px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

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

.app-topbar {
    height: 60px;
    flex-shrink: 0;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 28px;
    background: color-mix(in srgb, var(--surface) 60%, transparent);
    backdrop-filter: blur(12px);
}

.topbar-title {
    font-size: 18px;
    font-weight: 700;
    letter-spacing: -.02em;
}

.topbar-user {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 14px;
    color: var(--text-secondary);
}

.topbar-user-avatar {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: var(--accent-gradient);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    font-weight: 600;
}

.app-content {
    flex: 1;
    padding: 28px;
    overflow-y: auto;
}

/* ========== 工具栏 ========== */
.toolbar {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.input {
    width: 100%;
    padding: 9px 12px;
    font-size: 14px;
    font-family: inherit;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    transition: border-color .2s var(--ease), box-shadow .2s var(--ease);
}

.input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent);
}

textarea.input {
    resize: vertical;
    line-height: 1.6;
}

.input-search {
    max-width: 260px;
    margin-left: auto;
}

.input-select {
    width: auto;
}

/* ========== 表格 ========== */
.table-wrap {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
}

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

.table th,
.table td {
    text-align: left;
    padding: 13px 16px;
    border-bottom: 1px solid var(--border-light);
}

.table thead th {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: .03em;
    background: var(--surface-hover);
}

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

.table tbody tr {
    transition: background .15s var(--ease);
}

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

.th-actions {
    width: 130px;
    text-align: right;
}

.td-actions {
    text-align: right;
    white-space: nowrap;
}

.td-title {
    font-weight: 500;
    max-width: 320px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.td-muted {
    color: var(--text-secondary);
}

.table-empty {
    padding: 48px 24px;
    text-align: center;
    color: var(--text-tertiary);
    font-size: 14px;
}

/* ========== 徽章 ========== */
.badge {
    display: inline-block;
    padding: 3px 10px;
    font-size: 12px;
    font-weight: 600;
    border-radius: 12px;
    letter-spacing: .02em;
}

.badge-published {
    background: #ecfdf5;
    color: #047857;
}

.badge-draft {
    background: #f1f5f9;
    color: #64748b;
}

[data-theme="dark"] .badge-published {
    background: #022c22;
    color: #6ee7b7;
}

[data-theme="dark"] .badge-draft {
    background: #334155;
    color: #cbd5e1;
}

/* ========== 按钮 ========== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 9px 18px;
    font-size: 14px;
    font-weight: 500;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all .2s var(--ease);
    border: 1px solid transparent;
}

.btn-primary {
    color: #fff;
    background: var(--accent);
    box-shadow: 0 2px 8px rgba(99, 102, 241, .3);
}

.btn-primary:hover {
    filter: brightness(1.08);
    transform: translateY(-1px);
}

.btn-ghost {
    color: var(--text-secondary);
    background: transparent;
    border-color: var(--border);
}

.btn-ghost:hover {
    color: var(--text);
    background: var(--surface-hover);
}

.btn-danger {
    color: #ef4444;
    background: transparent;
    border-color: transparent;
}

.btn-danger:hover {
    background: rgba(239, 68, 68, .08);
}

.btn-sm {
    padding: 6px 12px;
    font-size: 13px;
}

.btn-block {
    width: 100%;
}

/* ========== 弹窗 ========== */
.admin-overlay {
    position: fixed;
    inset: 0;
    z-index: 300;
    background: rgba(15, 23, 42, .55);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 5vh 20px;
    overflow-y: auto;
    animation: fadeIn .2s var(--ease);
}

.admin-dialog {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    width: 100%;
    max-width: 480px;
    box-shadow: var(--shadow-xl);
    animation: modalIn .3s var(--ease-spring);
}

.admin-dialog-lg {
    max-width: 960px;
}

.dialog-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px;
    border-bottom: 1px solid var(--border-light);
}

.dialog-title {
    font-size: 18px;
    font-weight: 700;
    letter-spacing: -.02em;
}

.dialog-close {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    color: var(--text-secondary);
    transition: all .2s var(--ease);
}

.dialog-close:hover {
    color: var(--text);
    background: var(--surface-hover);
}

.dialog-body {
    padding: 24px;
}

/* ========== 表单 ========== */
.form-group {
    margin-bottom: 16px;
}

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

.req {
    color: #ef4444;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.form-actions {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    margin-top: 24px;
}

.form-error {
    color: #ef4444;
    font-size: 13px;
    background: rgba(239, 68, 68, .08);
    border: 1px solid rgba(239, 68, 68, .2);
    border-radius: var(--radius-sm);
    padding: 8px 12px;
    margin-bottom: 14px;
}

.form-tip {
    font-size: 12px;
    color: var(--text-tertiary);
    margin-top: -8px;
    margin-bottom: 8px;
}

/* ========== Markdown 编辑器 ========== */
.md-toolbar {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 4px;
    padding: 6px;
    margin-bottom: 8px;
    background: var(--surface-hover);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
}

.md-btn {
    padding: 5px 10px;
    font-size: 13px;
    color: var(--text-secondary);
    border-radius: 5px;
    transition: all .15s var(--ease);
    line-height: 1.2;
}

.md-btn:hover {
    color: var(--text);
    background: var(--surface);
}

.md-sep {
    width: 1px;
    height: 18px;
    background: var(--border);
    margin: 0 4px;
}

.md-wrap {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.md-input {
    font-family: 'SF Mono', 'Cascadia Code', 'Fira Code', monospace;
    font-size: 13px;
    line-height: 1.7;
    resize: vertical;
    min-height: 320px;
}

.md-preview {
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    padding: 14px 16px;
    overflow-y: auto;
    min-height: 320px;
    max-height: 520px;
    font-size: 14px;
    line-height: 1.7;
    color: var(--text);
}

.md-preview:empty::before {
    content: '预览区';
    color: var(--text-tertiary);
}

/* 预览排版 */
.md-preview h1, .md-preview h2, .md-preview h3, .md-preview h4 {
    font-weight: 700;
    letter-spacing: -.01em;
    margin: 1.2em 0 .5em;
    line-height: 1.3;
}

.md-preview h1 { font-size: 24px; }
.md-preview h2 { font-size: 20px; }
.md-preview h3 { font-size: 17px; }

.md-preview h1:first-child,
.md-preview h2:first-child,
.md-preview h3:first-child,
.md-preview p:first-child { margin-top: 0; }

.md-preview p { margin-bottom: .8em; }

.md-preview ul, .md-preview ol { margin: .6em 0; padding-left: 1.4em; }
.md-preview li { margin-bottom: .3em; }

.md-preview code {
    font-family: 'SF Mono', 'Cascadia Code', 'Fira Code', monospace;
    font-size: .88em;
    padding: 2px 6px;
    background: var(--accent-light);
    border-radius: 4px;
    color: var(--accent);
}

.md-preview pre {
    background: #1e293b;
    color: #e2e8f0;
    padding: 14px 16px;
    border-radius: var(--radius);
    overflow-x: auto;
    margin-bottom: .8em;
}

.md-preview pre code {
    background: none;
    color: inherit;
    padding: 0;
}

.md-preview blockquote {
    border-left: 3px solid var(--accent);
    padding: 2px 0 2px 14px;
    color: var(--text-secondary);
    margin: .6em 0;
}

.md-preview img {
    border-radius: var(--radius);
    margin: .6em 0;
}

.md-preview a {
    color: var(--accent);
    text-decoration: underline;
}

.md-preview hr {
    border: none;
    border-top: 1px solid var(--border);
    margin: 1.2em 0;
}

/* ========== 响应式 ========== */
@media (max-width: 768px) {
    .sidebar {
        width: 64px;
        padding: 20px 8px;
    }

    .sidebar-logo span,
    .side-link span {
        display: none;
    }

    .sidebar-logo {
        justify-content: center;
        padding: 4px 0 16px;
    }

    .side-link {
        justify-content: center;
        padding: 10px;
    }

    .app-content {
        padding: 16px;
    }

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

    .form-row,
    .md-wrap {
        grid-template-columns: 1fr;
    }

    .input-search {
        max-width: none;
        margin-left: 0;
        width: 100%;
    }

    .table th,
    .table td {
        padding: 10px 12px;
    }
}
