:root {
    --brand: #2563eb;
    --brand-dark: #1d4ed8;
    --ink: #0f172a;
    --muted: #64748b;
    --bg: #f5f7fb;
    --card: #ffffff;
    --line: #e6eaf2;
    --danger: #dc2626;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", sans-serif;
    background: var(--bg); color: var(--ink); -webkit-text-size-adjust: 100%;
}
img, video { max-width: 100%; }
a { color: var(--brand); text-decoration: none; }
.muted { color: var(--muted); }
.empty { color: var(--muted); text-align: center; padding: 26px 0; }

/* ── buttons ── */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    padding: 8px 16px; border: 1px solid var(--line); border-radius: 8px;
    background: #fff; color: var(--ink); font-size: 14px; cursor: pointer; transition: all .2s;
}
.btn:hover { border-color: var(--brand); color: var(--brand); }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-dark); border-color: var(--brand-dark); color: #fff; }
.btn-sm { padding: 5px 11px; font-size: 13px; }
.btn-danger { color: var(--danger); border-color: #fecaca; }
.btn-danger:hover { background: #fef2f2; border-color: var(--danger); color: var(--danger); }
.btn-block { width: 100%; padding: 11px; font-size: 15px; }

/* ── layout ── */
.admin-layout { display: flex; min-height: 100vh; }
.admin-side {
    width: 230px; background: #0f172a; color: #fff; padding: 22px 0;
    position: fixed; height: 100vh; overflow-y: auto;
}
.admin-logo { font-size: 18px; font-weight: 800; padding: 0 22px 20px; border-bottom: 1px solid rgba(255,255,255,.1); margin-bottom: 12px; }
.admin-side nav { display: flex; flex-direction: column; }
.admin-side nav a { color: #cbd5e1; padding: 12px 22px; font-size: 14px; transition: background .2s; }
.admin-side nav a:hover { background: #1e293b; color: #fff; }
.admin-side nav a.active { background: var(--brand); color: #fff; }
.admin-overlay { display: none; }
.admin-main { margin-left: 230px; flex: 1; min-width: 0; padding: 0 28px 40px; }
.admin-top {
    display: flex; align-items: center; gap: 14px;
    padding: 18px 0; border-bottom: 1px solid var(--line); margin-bottom: 22px;
}
.admin-top h1 { font-size: 21px; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.admin-user { font-size: 14px; color: var(--muted); }
.menu-btn { display: none; background: #fff; border: 1px solid var(--line); border-radius: 8px; font-size: 18px; padding: 6px 11px; cursor: pointer; }

/* ── cards / flash ── */
.card {
    background: var(--card); border-radius: 12px; padding: 20px; margin-bottom: 20px;
    box-shadow: 0 1px 3px rgba(15,23,42,.07); overflow-x: auto;
}
.card h3 { font-size: 16px; margin-bottom: 14px; }
.flash-wrap { margin-bottom: 16px; }
.flash { background: #d1fae5; border: 1px solid #a7f3d0; color: #065f46; padding: 10px 16px; border-radius: 8px; margin-bottom: 8px; }

/* ── stats ── */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 16px; margin-bottom: 20px; }
.stat { background: var(--card); border-radius: 12px; padding: 20px; box-shadow: 0 1px 3px rgba(15,23,42,.07); }
.stat-num { font-size: 30px; font-weight: 800; color: var(--brand); }
.stat-label { color: var(--muted); font-size: 14px; margin-top: 4px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }

/* ── bars ── */
.bars { display: flex; align-items: flex-end; gap: 12px; height: 180px; padding-top: 10px; }
.bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; }
.bar-wrap { flex: 1; width: 100%; display: flex; align-items: flex-end; justify-content: center; }
.bar { width: 60%; max-width: 44px; min-height: 2px; background: linear-gradient(180deg, #60a5fa, #2563eb); border-radius: 6px 6px 0 0; }
.bar-count { font-size: 12px; color: var(--muted); margin-top: 6px; }
.bar-label { font-size: 12px; color: var(--muted); }

/* ── tables ── */
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th, .table td { padding: 10px 12px; text-align: left; border-bottom: 1px solid #eef2f7; vertical-align: middle; }
.table th { background: #f8fafc; color: #374151; font-weight: 600; white-space: nowrap; }
.table tr:hover td { background: #f8fafc; }
.actions { display: flex; gap: 8px; align-items: center; }
.actions form { display: inline; }
.thumb { width: 54px; height: 40px; object-fit: cover; border-radius: 6px; }
.badge { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 12px; background: #e5e7eb; color: #374151; }
.badge.ok { background: #d1fae5; color: #065f46; }

/* ── forms ── */
label { display: block; margin-bottom: 14px; font-size: 14px; color: #374151; }
input[type="text"], input[type="password"], input[type="number"], input[type="file"], select, textarea {
    width: 100%; padding: 9px 12px; margin-top: 5px; border: 1px solid var(--line);
    border-radius: 8px; font-size: 14px; font-family: inherit; background: #fff;
}
input[type="file"] { padding: 7px; }
textarea { resize: vertical; min-height: 60px; }
label.checkbox { display: flex; align-items: center; gap: 8px; }
label.checkbox input { width: auto; margin: 0; }
.inline-form { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.inline-form input[type="text"], .inline-form input[type="file"] { flex: 1; min-width: 160px; width: auto; margin: 0; }
.inline-form .btn { white-space: nowrap; }
.form-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.span-2 { grid-column: span 2; }
.save-bar { position: sticky; bottom: 0; background: var(--bg); padding: 12px 0; }
.hint { color: var(--muted); font-size: 13px; margin-top: 10px; line-height: 1.7; }

/* ── media ── */
.cover-preview { margin-top: 8px; width: 180px; border-radius: 10px; }
.media-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px; }
.media-item { position: relative; border-radius: 10px; overflow: hidden; background: #f1f5f9; }
.media-item img, .media-item video { width: 100%; height: 110px; object-fit: cover; }
.media-model {
    display: flex; align-items: center; justify-content: center; gap: 6px;
    height: 110px; background: linear-gradient(135deg, #eef2ff, #e0e7ff);
    color: #1e40af; font-size: 14px;
}
.media-model span { max-width: 80%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.media-del { position: absolute; top: 6px; right: 6px; }
.media-del button {
    width: 24px; height: 24px; border: none; border-radius: 50%;
    background: rgba(0,0,0,.6); color: #fff; cursor: pointer; line-height: 1;
}
.media-del button:hover { background: var(--danger); }

/* ── rich editor ── */
.editor-toolbar { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.editor-toolbar button {
    padding: 5px 10px; border: 1px solid var(--line); border-radius: 6px;
    background: #fff; cursor: pointer; font-size: 13px;
}
.editor-toolbar button:hover { border-color: var(--brand); color: var(--brand); }
.rich-editor {
    min-height: 320px; border: 1px solid var(--line); border-radius: 10px;
    padding: 16px; background: #fff; overflow-y: auto; line-height: 1.7;
}
.rich-editor:focus { outline: 2px solid #bfdbfe; border-color: var(--brand); }
.rich-editor img, .rich-editor video { border-radius: 8px; margin: 8px 0; }
.rich-editor h2 { font-size: 20px; margin: 14px 0 8px; }
.rich-editor p { margin: 8px 0; }

/* ── firmware ── */
.fw-block { border: 1px solid var(--line); border-radius: 10px; padding: 16px; margin-bottom: 16px; }
.fw-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 10px; flex-wrap: wrap; }
.fw-edit { margin: 8px 0 12px; }
.fw-edit summary { cursor: pointer; font-size: 14px; color: var(--brand); margin-bottom: 8px; }
.fw-edit form { border: 1px dashed var(--line); border-radius: 8px; padding: 14px; background: #f8fafc; }

/* ── login ── */
.login-page {
    min-height: 100vh; display: flex; align-items: center; justify-content: center;
    background: linear-gradient(135deg, #0f172a 0%, #1d4ed8 100%); padding: 20px;
}
.login-card {
    background: #fff; border-radius: 14px; padding: 36px 32px; width: 380px; max-width: 94vw;
    box-shadow: 0 24px 60px rgba(0,0,0,.35);
}
.login-brand { font-size: 22px; font-weight: 800; text-align: center; color: var(--brand); margin-bottom: 22px; }
.login-card .flash { background: #fef2f2; border-color: #fecaca; color: #991b1b; }
.back-link { display: block; text-align: center; margin-top: 16px; font-size: 13px; color: var(--muted); }

/* ── responsive ── */
@media (max-width: 900px) {
    .admin-side {
        width: 240px; transform: translateX(-100%); transition: transform .25s;
        z-index: 1100; box-shadow: 2px 0 14px rgba(0,0,0,.25);
    }
    .admin-side.open { transform: translateX(0); }
    .admin-overlay {
        display: none; position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 1050;
    }
    .admin-overlay.show { display: block; }
    .menu-btn { display: inline-block; }
    .admin-main { margin-left: 0; padding: 0 14px 30px; }
    .grid-2 { grid-template-columns: 1fr; }
    .form-grid-2 { grid-template-columns: 1fr; }
    .span-2 { grid-column: span 1; }
    .admin-top h1 { font-size: 18px; }
}

@media (max-width: 640px) {
    .stat-grid { grid-template-columns: repeat(2, 1fr); }
    .stat-num { font-size: 24px; }
    .card { padding: 14px; }
    .table { font-size: 13px; }
    .table th, .table td { padding: 8px 9px; }
    .inline-form input[type="text"], .inline-form input[type="file"] { min-width: 120px; }

    /* 表格转卡片 */
    .r-table thead { display: none; }
    .r-table, .r-table tbody, .r-table tr, .r-table td { display: block; width: 100%; }
    .r-table tr {
        border: 1px solid var(--line); border-radius: 10px; margin-bottom: 12px;
        padding: 4px 12px; background: #fff;
    }
    .r-table tr:hover td { background: transparent; }
    .r-table td {
        display: flex; align-items: center; justify-content: space-between; gap: 12px;
        padding: 8px 0; border-bottom: 1px dashed #eef2f7; text-align: right;
    }
    .r-table td:last-child { border-bottom: none; flex-wrap: wrap; justify-content: flex-end; gap: 8px; }
    .r-table td::before {
        content: attr(data-label); flex: 0 0 auto; font-weight: 600;
        color: var(--muted); text-align: left; white-space: nowrap;
    }
    .r-table td.r-empty { display: block; text-align: center; }
    .r-table td.r-empty::before { content: none; }
}
