/* ==========================================================
   个人学习笔记系统 · 后台通用样式（三端自适应）
   桌面 >=1024 常驻侧栏 | 平板 768-1023 窄侧栏 | 手机 <768 抽屉侧栏
   ========================================================== */
:root {
    --bg: #f4f6fb;
    --surface: #ffffff;
    --line: #e9edf5;
    --ink: #0f172a;
    --ink-2: #334155;
    --muted: #94a3b8;
    --brand: #6366f1;
    --brand-2: #8b5cf6;
    --danger: #dc2626;
    --warn: #ea580c;
    --radius: 16px;
    --shadow: 0 6px 24px rgba(16, 24, 40, .045);
    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
    margin: 0;
    background: var(--bg);
    color: var(--ink-2);
    font-family: var(--font);
    font-size: 14px;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    overflow-x: hidden;
}
a { color: var(--brand); }

/* ---------- 顶部栏 ---------- */
.admin-header {
    position: sticky;
    top: 0;
    z-index: 30;
    height: 64px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 0 26px;
    background: rgba(255, 255, 255, .92);
    -webkit-backdrop-filter: blur(14px);
    backdrop-filter: blur(14px);
    border-bottom: 1px solid var(--line);
    box-shadow: 0 1px 3px rgba(16, 24, 40, .03);
}
.header-left { display: flex; align-items: center; gap: 12px; min-width: 0; }
.admin-header h1 {
    margin: 0;
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 17px;
    font-weight: 700;
    letter-spacing: .2px;
    color: var(--ink);
    white-space: nowrap;
}
.brand-mark {
    width: 32px;
    height: 32px;
    flex: 0 0 32px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 10px;
    color: #fff;
    background: linear-gradient(135deg, var(--brand), var(--brand-2));
    box-shadow: 0 5px 12px rgba(99, 102, 241, .3);
}
.user-info { display: flex; align-items: center; gap: 12px; font-size: 13.5px; color: #64748b; white-space: nowrap; }
.avatar {
    width: 30px; height: 30px; flex: 0 0 30px;
    display: inline-flex; align-items: center; justify-content: center;
    border-radius: 50%; background: #eef2ff; color: #4f46e5;
    font-weight: 700; font-size: 13px; text-transform: uppercase;
}
.user-info .logout {
    color: var(--danger); text-decoration: none; font-weight: 600;
    padding: 6px 10px; border-radius: 8px; transition: background .15s;
}
.user-info .logout:hover { background: #fef2f2; }
.menu-toggle {
    display: none;
    width: 38px; height: 38px; flex: 0 0 38px;
    flex-direction: column; align-items: center; justify-content: center; gap: 4px;
    border: 1px solid var(--line); border-radius: 10px; background: #fff; cursor: pointer;
}
.menu-toggle span { display: block; width: 17px; height: 2px; border-radius: 2px; background: var(--ink-2); transition: transform .2s, opacity .2s; }
.menu-toggle[aria-expanded="true"] span:nth-child(1) { transform: translateY(6px) rotate(45deg); }
.menu-toggle[aria-expanded="true"] span:nth-child(2) { opacity: 0; }
.menu-toggle[aria-expanded="true"] span:nth-child(3) { transform: translateY(-6px) rotate(-45deg); }

/* ---------- 主体与侧栏 ---------- */
.admin-body { display: flex; align-items: stretch; min-height: calc(100vh - 64px); }
.admin-sidebar {
    width: 232px; flex: 0 0 232px;
    position: sticky; top: 64px;
    height: calc(100vh - 64px);
    padding: 20px 12px;
    background: linear-gradient(180deg, #182235 0%, #0d1424 100%);
    overflow-y: auto;
    z-index: 20;
}
.side-label {
    padding: 8px 14px 6px;
    font-size: 11px; font-weight: 600; letter-spacing: 1.2px;
    color: #64748b; text-transform: uppercase;
}
.admin-sidebar a {
    display: flex; align-items: center; gap: 11px;
    padding: 11px 14px; margin-bottom: 4px;
    border-radius: 10px; color: #aeb9cc; text-decoration: none;
    font-size: 14px; font-weight: 500;
    transition: background .18s, color .18s, transform .18s;
}
.admin-sidebar a .ico { width: 20px; flex: 0 0 20px; text-align: center; font-size: 16px; }
.admin-sidebar a:hover { background: rgba(255, 255, 255, .07); color: #fff; transform: translateX(2px); }
.admin-sidebar a.active {
    background: linear-gradient(135deg, rgba(99, 102, 241, .95), rgba(139, 92, 246, .88));
    color: #fff;
    box-shadow: 0 6px 16px rgba(99, 102, 241, .28);
}
.side-foot { margin-top: 26px; padding: 14px; font-size: 11.5px; color: #4b5b74; border-top: 1px solid rgba(255,255,255,.07); }
.admin-overlay { display: none; }

/* ---------- 内容区 ---------- */
.admin-main { flex: 1; min-width: 0; width: 100%; max-width: 1280px; padding: 30px 34px 52px; }
.page-head {
    display: flex; align-items: center; justify-content: space-between;
    gap: 14px; flex-wrap: wrap; margin-bottom: 22px;
}
.page-title { margin: 0; font-size: clamp(20px, 2.2vw, 24px); font-weight: 700; letter-spacing: -.4px; color: var(--ink); }
.card {
    background: var(--surface); border: 1px solid var(--line);
    border-radius: var(--radius); padding: 26px 28px;
    box-shadow: var(--shadow); margin-bottom: 20px;
    animation: rise .32s ease both;
}
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.card-title { margin: 0 0 16px; font-size: 16px; font-weight: 700; color: var(--ink); }

/* ---------- 统计卡 ---------- */
.stats-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; margin-bottom: 22px; }
.stat-card {
    display: flex; align-items: center; gap: 18px;
    background: var(--surface); border: 1px solid var(--line);
    border-radius: var(--radius); padding: 22px 24px;
    box-shadow: var(--shadow); transition: transform .2s, box-shadow .2s;
    animation: rise .32s ease both;
}
.stat-card:nth-child(2) { animation-delay: .06s; }
.stat-card:hover { transform: translateY(-3px); box-shadow: 0 12px 30px rgba(16, 24, 40, .09); }
.stat-icon {
    width: 48px; height: 48px; flex: 0 0 48px;
    display: inline-flex; align-items: center; justify-content: center;
    border-radius: 14px; font-size: 22px;
    background: #eef2ff; color: #4f46e5;
}
.stat-card:nth-child(2) .stat-icon { background: #f5f3ff; color: #7c3aed; }
.stat-num { font-size: 30px; font-weight: 750; line-height: 1.15; color: var(--ink); letter-spacing: -.5px; }
.stat-label { font-size: 13px; color: var(--muted); margin-top: 2px; }

/* ---------- 表格 ---------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; min-width: 560px; border-collapse: collapse; }
th, td { padding: 13px 12px; text-align: left; border-bottom: 1px solid #f0f2f7; font-size: 14px; white-space: nowrap; }
th { font-size: 11.5px; font-weight: 700; letter-spacing: .6px; text-transform: uppercase; color: var(--muted); background: #fafbfe; }
th:first-child { border-radius: 8px 0 0 8px; }
th:last-child { border-radius: 0 8px 8px 0; }
tbody tr { transition: background .15s; }
tbody tr:hover { background: #fafbff; }
tbody tr:last-child td { border-bottom: none; }
td .btn { margin-right: 6px; }
.empty-row { text-align: center !important; color: var(--muted); padding: 30px 12px !important; }

/* ---------- 按钮 ---------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    min-height: 38px; padding: 9px 16px;
    border: 1px solid transparent; border-radius: 9px;
    font-family: inherit; font-size: 13.5px; font-weight: 600;
    text-decoration: none; cursor: pointer; white-space: nowrap;
    transition: transform .15s, box-shadow .15s, background .15s;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: linear-gradient(135deg, var(--brand), var(--brand-2)); color: #fff; box-shadow: 0 5px 14px rgba(99, 102, 241, .28); }
.btn-primary:hover { box-shadow: 0 8px 20px rgba(99, 102, 241, .4); }
.btn-ghost { background: #f1f5f9; color: #475569; }
.btn-ghost:hover { background: #e2e8f0; }
.btn-danger { background: #fef2f2; color: var(--danger); }
.btn-danger:hover { background: #fee2e2; }
.btn-edit { background: #fff7ed; color: var(--warn); }
.btn-edit:hover { background: #ffedd5; }
.form-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 4px; }

/* ---------- 表单 ---------- */
.form-group { margin-bottom: 20px; }
.form-group label { display: block; margin-bottom: 8px; font-size: 13.5px; font-weight: 600; color: var(--ink-2); }
.form-group input, .form-group textarea, .form-group select {
    display: block; width: 100%;
    padding: 11px 14px; border: 1.5px solid #e2e8f0; border-radius: 10px;
    background: #fbfcff; color: var(--ink);
    font-family: inherit; font-size: 15px; line-height: 1.6;
    transition: border-color .15s, box-shadow .15s, background .15s;
}
.form-group input::placeholder, .form-group textarea::placeholder { color: #aab4c5; }
.form-group input:focus, .form-group textarea:focus, .form-group select:focus {
    outline: none; border-color: #818cf8; background: #fff;
    box-shadow: 0 0 0 4px rgba(99, 102, 241, .12);
}
.form-group textarea { min-height: 300px; resize: vertical; }
.alert-error {
    background: #fef2f2; border: 1px solid #fecaca; color: #b91c1c;
    padding: 12px 14px; border-radius: 10px; margin-bottom: 18px; font-size: 14px;
}

/* ---------- 登录页 ---------- */
body.login-page {
    min-height: 100vh; display: flex; align-items: center; justify-content: center;
    padding: 20px;
    background:
        radial-gradient(circle at 15% 20%, rgba(255,255,255,.18), transparent 42%),
        radial-gradient(circle at 85% 80%, rgba(255,255,255,.12), transparent 40%),
        linear-gradient(135deg, #5b6ee8 0%, #7c5cd6 55%, #9b5fc0 100%);
}
.login-box {
    width: 100%; max-width: 400px;
    background: rgba(255, 255, 255, .97);
    -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
    border-radius: 20px; padding: 38px 32px 30px;
    box-shadow: 0 26px 64px rgba(30, 27, 75, .3);
    animation: rise .4s ease both;
}
.login-logo {
    width: 54px; height: 54px; margin: 0 auto 16px;
    display: flex; align-items: center; justify-content: center;
    border-radius: 16px; color: #fff;
    background: linear-gradient(135deg, var(--brand), var(--brand-2));
    box-shadow: 0 8px 20px rgba(99, 102, 241, .35);
}
.login-box h1 { margin: 0 0 6px; text-align: center; font-size: 21px; font-weight: 700; color: var(--ink); }
.login-box .sub { margin: 0 0 28px; text-align: center; font-size: 13.5px; color: var(--muted); }
.login-box .btn-primary { width: 100%; min-height: 46px; font-size: 15px; margin-top: 8px; }
.login-box .back { display: block; text-align: center; margin-top: 22px; color: #64748b; font-size: 13.5px; text-decoration: none; }
.login-box .back:hover { color: var(--brand); }

/* ---------- 图标（内联 SVG，跨端一致） ---------- */
.brand-mark svg { width: 18px; height: 18px; }
.login-logo svg { width: 26px; height: 26px; }
.admin-sidebar a .ico svg { width: 18px; height: 18px; display: block; margin: 0 auto; }
.stat-icon svg { width: 24px; height: 24px; }

/* ==========================================================
   响应式：平板
   ========================================================== */
@media (max-width: 1199px) {
    .admin-header { padding: 0 20px; }
    .admin-sidebar { width: 210px; flex-basis: 210px; }
    .admin-main { padding: 26px 24px 44px; }
    .card { padding: 22px 24px; }
}
@media (min-width: 768px) and (max-width: 1023px) {
    .admin-sidebar { width: 178px; flex-basis: 178px; padding: 16px 9px; }
    .admin-sidebar a { padding: 10px 11px; font-size: 13.5px; gap: 8px; }
    .admin-main { padding: 22px 18px 40px; }
    .card { padding: 20px 18px; }
    .stat-card { padding: 18px; gap: 12px; }
    .stat-icon { width: 42px; height: 42px; flex-basis: 42px; font-size: 19px; }
    .stat-num { font-size: 26px; }
    table { min-width: 520px; }
}

/* ==========================================================
   响应式：手机（侧栏改抽屉，内容区全宽）
   ========================================================== */
@media (max-width: 767px) {
    .admin-header { height: 58px; padding: 0 14px; }
    .admin-header h1 { font-size: 15px; gap: 8px; }
    .brand-mark { width: 29px; height: 29px; flex-basis: 29px; font-size: 14px; }
    .menu-toggle { display: inline-flex; }
    .user-info { gap: 8px; font-size: 12.5px; }
    .user-info .u-name { display: none; }
    .user-info .logout { padding: 6px 8px; }
    .admin-body { min-height: calc(100vh - 58px); }
    .admin-sidebar {
        position: fixed; top: 58px; left: 0; bottom: 0;
        width: 264px; height: auto; flex-basis: auto;
        z-index: 40; padding: 18px 12px;
        transform: translateX(-100%);
        transition: transform .26s cubic-bezier(.4, 0, .2, 1);
        box-shadow: none;
    }
    .admin-sidebar.open { transform: translateX(0); box-shadow: 10px 0 34px rgba(8, 15, 30, .28); }
    .admin-overlay {
        display: block; position: fixed; inset: 58px 0 0;
        background: rgba(15, 23, 42, .45); z-index: 35;
        opacity: 0; pointer-events: none; transition: opacity .26s;
    }
    .admin-overlay.show { opacity: 1; pointer-events: auto; }
    .admin-main { padding: 18px 14px 36px; }
    .page-head { margin-bottom: 16px; gap: 10px; }
    .page-title { font-size: 20px; }
    .page-head .btn { min-height: 36px; padding: 8px 13px; font-size: 13px; }
    .card { padding: 18px 15px; border-radius: 14px; margin-bottom: 16px; }
    .stats-row { gap: 12px; margin-bottom: 16px; }
    .stat-card { flex-direction: column; align-items: flex-start; gap: 8px; padding: 16px 14px; border-radius: 14px; }
    .stat-icon { width: 38px; height: 38px; flex-basis: 38px; font-size: 18px; border-radius: 11px; }
    .stat-num { font-size: 25px; }
    .stat-label { font-size: 12px; }
    .form-group { margin-bottom: 16px; }
    .form-group input, .form-group textarea, .form-group select { font-size: 16px; padding: 11px 13px; }
    .form-group textarea { min-height: 220px; }
    .form-actions { gap: 8px; }
    .form-actions .btn { flex: 1 1 auto; min-height: 42px; }
    table { min-width: 520px; }
    th, td { padding: 11px 10px; font-size: 13px; }
    td .btn { padding: 7px 11px; min-height: 34px; font-size: 12.5px; margin-right: 4px; }
    .login-box { padding: 32px 22px 26px; border-radius: 18px; }
}
@media (max-width: 380px) {
    .stats-row { grid-template-columns: 1fr 1fr; gap: 10px; }
    .stat-card { padding: 13px 11px; }
    .stat-num { font-size: 22px; }
    .brand-text { display: none; }
    .admin-main { padding-left: 12px; padding-right: 12px; }
}
@media (prefers-reduced-motion: reduce) {
    * { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
