:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #fafafa;
  --sidebar: #18181d;
  --text: #25252b;
  --muted: #777780;
  --line: #e7e7eb;
  --red: #b82025;
  --red-soft: #fff1f1;
  --gold: #b48a3a;
  --gold-soft: #fff8e8;
  --green: #27865a;
  --shadow: 0 14px 40px rgba(24, 24, 29, .08);
}

body.dark {
  --bg: #111115;
  --surface: #1b1b21;
  --surface-2: #222229;
  --text: #f4f1eb;
  --muted: #aaa7a4;
  --line: #32323a;
  --red-soft: #321a1d;
  --gold-soft: #2f281a;
  --shadow: 0 18px 50px rgba(0, 0, 0, .28);
}

* { box-sizing: border-box; }
html { background: var(--bg); }
body { margin: 0; min-height: 100vh; color: var(--text); font-family: Inter, "Microsoft YaHei", Arial, sans-serif; background: var(--bg); }
button, input, textarea, select { font: inherit; }
button, a { cursor: pointer; }
button { border: 0; }
.hidden { display: none !important; }
.admin-shell { min-height: 100vh; }

.login-page { min-height: 100vh; padding: 24px; display: grid; place-items: center; background: radial-gradient(circle at 50% 10%, rgba(184,32,37,.08), transparent 32%), var(--bg); }
.login-brand { display: flex; align-items: center; gap: 22px; }
.login-brand img { width: 36px; height: 36px; object-fit: contain; }
.login-brand strong, .login-brand span { display: block; }
.login-brand strong { font-size: 16px; letter-spacing: 3px; }
.login-brand span { margin-top: 3px; color: var(--gold); letter-spacing: 2px; font-size: 8px; }
.login-card { width: min(420px, 100%); display: grid; gap: 20px; padding: 36px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); box-shadow: var(--shadow); }
.login-card small, .admin-header small, .editor-dialog small { color: var(--red); font-weight: 700; letter-spacing: 2px; }
.login-card h1 { margin: 8px 0 0; font-size: 30px; }
.login-card p { margin: 10px 0 0; color: var(--muted); line-height: 1.7; }
label { display: grid; gap: 8px; color: var(--text); font-size: 13px; font-weight: 600; }
input, textarea, select { width: 100%; padding: 12px 14px; color: var(--text); border: 1px solid var(--line); border-radius: 9px; background: var(--surface); outline: none; }
input:focus, textarea:focus, select:focus { border-color: var(--gold); box-shadow: 0 0 0 3px rgba(180,138,58,.1); }
textarea { min-height: 110px; resize: vertical; line-height: 1.7; }
.status { min-height: 18px; color: var(--red); font-size: 13px; }

.primary-button, .ghost-button, .danger-outline, .icon-button, .row-action { min-height: 40px; padding: 0 17px; display: inline-flex; align-items: center; justify-content: center; border-radius: 8px; font-weight: 700; }
.primary-button { color: #fff; background: var(--red); box-shadow: 0 8px 20px rgba(184,32,37,.18); }
.primary-button:hover { background: #9f171c; }
.ghost-button, .icon-button, .row-action { color: var(--text); border: 1px solid var(--line); background: var(--surface); }
.danger-outline { color: var(--red); border: 1px solid rgba(184,32,37,.3); background: transparent; }
.icon-button { width: 40px; padding: 0; font-size: 20px; }

.dashboard { min-height: 100vh; display: grid; grid-template-columns: 248px minmax(0, 1fr); }
.sidebar { position: sticky; top: 0; height: 100vh; padding: 24px 18px; display: flex; flex-direction: column; color: #f7f4ee; background: var(--sidebar); }
.side-brand { margin: 0 8px 30px; display: flex; align-items: center; gap: 13px; color: #fff; text-decoration: none; }
.side-brand img { width: 32px; height: 32px; object-fit: contain; }
.side-brand strong, .side-brand small { display: block; }
.side-brand strong { letter-spacing: 2px; }
.side-brand small { margin-top: 4px; color: #9999a2; font-size: 10px; }
.side-nav { display: grid; gap: 5px; }
.side-nav p { margin: 20px 12px 7px; color: #74747d; font-size: 11px; letter-spacing: 2px; }
.nav-item { min-height: 44px; padding: 0 14px; display: flex; align-items: center; gap: 12px; color: #c9c9cf; border-radius: 8px; background: transparent; text-align: left; }
.nav-item span { width: 20px; color: #8d8d95; text-align: center; }
.nav-item:hover, .nav-item.active { color: #fff; background: rgba(255,255,255,.085); }
.nav-item.active::after { content: ""; width: 3px; height: 20px; margin-left: auto; border-radius: 2px; background: var(--red); }
.side-footer { margin-top: auto; padding: 18px 10px 4px; display: grid; gap: 14px; border-top: 1px solid rgba(255,255,255,.1); font-size: 12px; }
.side-footer a { color: #e9d08d; text-decoration: none; }
.side-footer div { color: #9999a2; }
.online-dot { width: 7px; height: 7px; margin-right: 8px; display: inline-block; border-radius: 50%; background: #43bc79; box-shadow: 0 0 0 4px rgba(67,188,121,.12); }

.main-area { min-width: 0; padding: 28px clamp(22px, 4vw, 54px) 60px; }
.admin-header { min-height: 72px; margin-bottom: 28px; display: flex; align-items: center; justify-content: space-between; gap: 20px; }
.admin-header h1 { margin: 5px 0 0; font-size: 26px; }
.header-actions { display: flex; gap: 10px; }
.admin-panel { display: none; }
.admin-panel.active { display: block; }

.welcome-card { padding: 34px 38px; display: flex; align-items: center; justify-content: space-between; gap: 24px; color: #fff; border-radius: 16px; background: linear-gradient(120deg, #202027, #381c20 75%, #7c1b20); box-shadow: var(--shadow); }
.welcome-card small { color: #e4c473; letter-spacing: 3px; }
.welcome-card h2 { margin: 10px 0 7px; font-size: 28px; }
.welcome-card p { margin: 0; color: #cbc7c4; }
.stat-grid { margin: 22px 0 34px; display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }
.stat-card { padding: 22px; border: 1px solid var(--line); border-radius: 13px; background: var(--surface); }
.stat-card span { color: var(--muted); font-size: 13px; }
.stat-card strong { margin-top: 10px; display: block; font-size: 30px; }
.stat-card small { color: var(--green); }
.section-heading { margin-bottom: 20px; display: flex; align-items: center; justify-content: space-between; gap: 20px; }
.section-heading h2 { margin: 0; font-size: 22px; }
.section-heading p { margin: 7px 0 0; color: var(--muted); font-size: 14px; }
.quick-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; }
.quick-grid button { min-height: 150px; padding: 24px; display: grid; align-content: start; gap: 10px; color: var(--text); border: 1px solid var(--line); border-radius: 13px; background: var(--surface); text-align: left; }
.quick-grid button:hover { border-color: rgba(180,138,58,.5); transform: translateY(-2px); box-shadow: var(--shadow); }
.quick-grid b { font-size: 18px; }
.quick-grid span { color: var(--muted); }
.quick-grid i { margin-top: 15px; color: var(--red); font-style: normal; font-weight: 700; font-size: 13px; }

.list-toolbar { margin-bottom: 16px; display: flex; align-items: center; justify-content: space-between; gap: 18px; }
.list-toolbar > span { color: var(--muted); font-size: 13px; }
.search-box { width: min(480px, 100%); display: flex; align-items: center; gap: 8px; padding-left: 13px; color: var(--muted); border: 1px solid var(--line); border-radius: 9px; background: var(--surface); }
.search-box input { border: 0; box-shadow: none; background: transparent; }
.content-list, .message-list { display: grid; gap: 10px; }
.admin-pagination { min-height: 44px; margin-top: 20px; display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 8px; }
.admin-pagination[hidden] { display: none; }
.admin-pagination button { min-width: 42px; height: 42px; padding: 0 13px; color: var(--text); border: 1px solid var(--line); border-radius: 8px; background: var(--surface); cursor: pointer; }
.admin-pagination button:hover { color: var(--red); border-color: var(--red); }
.admin-pagination button.active { color: #fff; border-color: var(--red); background: var(--red); box-shadow: 0 7px 18px rgba(171, 34, 40, .2); }
.admin-page-ellipsis { min-width: 26px; text-align: center; color: var(--muted); font-weight: 700; }
.content-row { min-height: 92px; padding: 13px 16px; display: grid; grid-template-columns: 68px minmax(220px, 1.6fr) minmax(140px, .8fr) minmax(120px, .7fr) auto; align-items: center; gap: 16px; border: 1px solid var(--line); border-radius: 11px; background: var(--surface); }
.content-row:hover { border-color: rgba(180,138,58,.45); box-shadow: 0 8px 24px rgba(20,20,24,.05); }
.row-thumb { width: 64px; height: 64px; display: grid; place-items: center; overflow: hidden; color: #fff; border-radius: 9px; background: linear-gradient(135deg, #2d3440, #8d2429); background-size: cover; background-position: center; font-weight: 800; }
.row-main strong, .row-main span, .row-cell strong, .row-cell span { display: block; }
.row-main strong { margin-bottom: 7px; }
.row-main span, .row-cell span { color: var(--muted); font-size: 12px; line-height: 1.5; }
.row-cell strong { margin-bottom: 5px; font-size: 13px; }
.row-actions { display: flex; gap: 8px; }
.row-action { min-height: 34px; padding: 0 12px; font-size: 12px; }
.row-action.edit { color: var(--gold); }
.row-action.delete { color: var(--red); }
.badge { width: fit-content; padding: 5px 9px; display: inline-block; color: var(--green); border-radius: 20px; background: rgba(39,134,90,.1); font-size: 11px; }
.badge.muted { color: var(--muted); background: var(--surface-2); }
.featured-mark { margin-left: 7px; padding: 3px 7px; color: var(--red); border-radius: 20px; background: var(--red-soft); font-size: 10px; font-style: normal; font-weight: 700; }
.empty-state { padding: 55px 20px; color: var(--muted); border: 1px dashed var(--line); border-radius: 12px; background: var(--surface); text-align: center; }

.settings-list { display: grid; gap: 12px; }
.settings-item { padding: 20px 22px; display: flex; align-items: center; justify-content: space-between; gap: 24px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); }
.settings-item > div { display: flex; align-items: center; gap: 17px; }
.settings-icon { width: 48px; height: 48px; display: grid; place-items: center; color: var(--red); border-radius: 10px; background: var(--red-soft); font-size: 20px; }
.settings-item strong, .settings-item span { display: block; }
.settings-item span { margin-top: 5px; color: var(--muted); font-size: 13px; }
.message-card { padding: 18px 20px; display: grid; grid-template-columns: 220px minmax(260px, 1fr) 170px; gap: 20px; align-items: start; border: 1px solid var(--line); border-radius: 11px; background: var(--surface); }
.message-card strong, .message-card span, .message-card small { display: block; }
.message-card span, .message-card small { margin-top: 5px; color: var(--muted); font-size: 12px; }
.message-card p { margin: 0; line-height: 1.8; }
.message-actions { display: grid; gap: 8px; }
.system-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; }
.system-grid article { min-height: 150px; padding: 24px; display: grid; align-content: start; gap: 10px; border: 1px solid var(--line); border-radius: 13px; background: var(--surface); }
.system-grid small, .system-grid span { color: var(--muted); }
.system-grid strong { font-size: 20px; }
.analytics-layout, .security-layout { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.analytics-card, .security-card { padding: 22px; border: 1px solid var(--line); border-radius: 13px; background: var(--surface); }
.analytics-card h3, .security-card h3 { margin: 0 0 8px; }
.security-card { display: grid; align-content: start; gap: 14px; }
.security-card > p { margin: 0 0 4px; color: var(--muted); }
.security-card label { display: grid; gap: 7px; color: var(--muted); font-size: 12px; }
.trend-list, .ranking-list, .session-list, .login-history { display: grid; gap: 9px; margin-top: 16px; }
.trend-row, .ranking-row, .session-row, .login-row { padding: 12px 14px; display: grid; align-items: center; gap: 10px; border: 1px solid var(--line); border-radius: 9px; background: var(--surface-2); }
.trend-row { grid-template-columns: 100px 1fr 1fr; }
.ranking-row { grid-template-columns: 34px 1fr auto; }
.session-row { grid-template-columns: 1fr auto; }
.login-row { grid-template-columns: 150px 120px 1fr 100px; }
.login-row.unusual { border-color: #d49a32; background: var(--gold-soft); }
.session-row small, .login-row small { color: var(--muted); }
.login-history-card { margin-top: 18px; }

.editor-dialog { width: min(760px, calc(100% - 28px)); max-height: calc(100vh - 40px); padding: 0; overflow: hidden; color: var(--text); border: 0; border-radius: 16px; background: var(--surface); box-shadow: 0 35px 100px rgba(0,0,0,.35); }
.editor-dialog::backdrop { background: rgba(15,15,19,.62); backdrop-filter: blur(4px); }
.editor-dialog form { max-height: calc(100vh - 40px); display: grid; grid-template-rows: auto minmax(0, 1fr) auto; }
.editor-dialog header, .editor-dialog footer { padding: 20px 24px; display: flex; align-items: center; justify-content: space-between; gap: 14px; border-bottom: 1px solid var(--line); }
.editor-dialog footer { justify-content: flex-end; border-top: 1px solid var(--line); border-bottom: 0; }
.editor-dialog h2 { margin: 5px 0 0; }
.close-button { width: 38px; height: 38px; color: var(--muted); border-radius: 50%; background: var(--surface-2); font-size: 26px; }
.editor-body { padding: 24px; overflow-y: auto; }
.editor-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; }
.editor-grid .wide { grid-column: 1 / -1; }
.upload-box { min-height: 118px; padding: 18px; display: grid; gap: 9px; align-content: center; color: var(--muted); border: 1px dashed var(--line); border-radius: 10px; background: var(--surface-2); }
.upload-box b { color: var(--text); }
.upload-box input { padding: 0; border: 0; background: transparent; }
.current-media { color: var(--green); font-size: 12px; overflow-wrap: anywhere; }
.upload-option { display: flex; align-items: center; gap: 8px; color: var(--text); font-weight: 500; }
.upload-option input { width: auto; margin: 0; }
.feature-toggle { padding: 14px; display: flex; align-items: flex-start; gap: 10px; border: 1px solid rgba(180,138,58,.25); border-radius: 10px; background: var(--gold-soft); }
.feature-toggle input { width: auto; margin: 3px 0 0; }
.feature-toggle b, .feature-toggle small { display: block; }
.feature-toggle small { margin-top: 4px; color: var(--muted); font-weight: 400; }
#editor-status { margin-right: auto; color: var(--muted); font-size: 13px; }
.toast { position: fixed; right: 28px; bottom: 28px; z-index: 20; padding: 13px 18px; color: #fff; border-radius: 9px; background: #25252b; box-shadow: var(--shadow); opacity: 0; transform: translateY(15px); pointer-events: none; transition: .2s; }
.toast.show { opacity: 1; transform: none; }

@media (max-width: 1050px) {
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .content-row { grid-template-columns: 60px 1fr auto; }
  .content-row .row-cell { display: none; }
}
@media (max-width: 760px) {
  .login-page { padding: 18px; }
  .dashboard { grid-template-columns: 1fr; }
  .sidebar { position: relative; height: auto; }
  .side-nav { grid-template-columns: repeat(2, 1fr); }
  .side-nav p, .side-footer { grid-column: 1 / -1; }
  .main-area { padding: 20px 14px 50px; }
  .welcome-card, .section-heading, .list-toolbar { align-items: stretch; flex-direction: column; }
  .quick-grid, .system-grid, .editor-grid, .analytics-layout, .security-layout { grid-template-columns: 1fr; }
  .editor-grid .wide { grid-column: auto; }
  .message-card { grid-template-columns: 1fr; }
  .login-row { grid-template-columns: 1fr; }
}
