:root {
  --bg: #0d0a14;
  --panel: #15111f;
  --panel-2: #1c1729;
  --line: #2a2338;
  --text: #f4f1ff;
  --muted: #9c94b5;
  --brand: #8c5bff;
  --brand-2: #c86dd7;
  --good: #4cd08a;
  --warn: #ffc857;
  --bad: #ff6b81;
  --radius: 14px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", system-ui, -apple-system, sans-serif;
  font-size: 14px;
}

.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

/* ---------- 登录 ---------- */
.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background:
    radial-gradient(1200px 600px at 10% -10%, rgba(140, 91, 255, .35), transparent 60%),
    radial-gradient(900px 500px at 110% 110%, rgba(200, 109, 215, .25), transparent 60%),
    var(--bg);
  padding: 24px;
}

.login-card {
  width: 380px;
  max-width: 100%;
  background: rgba(21, 17, 31, .92);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 28px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, .5);
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.login-brand { display: flex; gap: 14px; align-items: center; margin-bottom: 6px; }
.login-brand h1 { font-size: 20px; margin: 0; }
.login-brand p { margin: 2px 0 0; color: var(--muted); font-size: 12px; letter-spacing: .3px; }

.brand-mark {
  width: 44px; height: 44px; border-radius: 12px;
  object-fit: cover;
  background: #1b0b3a;
  box-shadow: 0 8px 24px rgba(140, 91, 255, .45);
  flex: none;
}

.login-card label { display: flex; flex-direction: column; gap: 8px; color: var(--muted); font-size: 12px; }

input, select, textarea {
  background: #120f1a;
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 14px;
  font-family: inherit;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(140, 91, 255, .18);
}
textarea { min-height: 72px; resize: vertical; }
input[readonly] { opacity: .65; }

.login-note { color: var(--muted); font-size: 12px; margin: 0; line-height: 1.6; }
.login-error { color: var(--bad); font-size: 12px; min-height: 16px; margin: 0; }

/* ---------- 布局 ---------- */
.layout { display: grid; grid-template-columns: 216px 1fr; min-height: 100vh; }

.sidebar {
  background: linear-gradient(180deg, #161122, #100d18);
  border-right: 1px solid var(--line);
  display: flex; flex-direction: column;
  padding: 18px 14px;
  gap: 18px;
  position: sticky; top: 0; height: 100vh;
}

.side-brand { display: flex; gap: 10px; align-items: center; padding: 4px 6px 12px; }
.side-brand strong { display: block; font-size: 16px; }
.side-brand small { color: var(--muted); font-size: 11px; }

#nav { display: flex; flex-direction: column; gap: 4px; }
.nav-item {
  text-align: left;
  background: transparent;
  border: none;
  color: var(--muted);
  padding: 10px 12px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 14px;
  font-family: inherit;
  transition: background .15s, color .15s;
}
.nav-item:hover { background: rgba(140, 91, 255, .1); color: var(--text); }
.nav-item.active {
  background: linear-gradient(135deg, rgba(140, 91, 255, .3), rgba(200, 109, 215, .18));
  color: var(--text);
  box-shadow: inset 0 0 0 1px rgba(140, 91, 255, .35);
}

.side-foot {
  margin-top: auto;
  display: flex; align-items: center; justify-content: space-between;
  color: var(--muted); font-size: 12px;
  padding: 10px 6px 0;
  border-top: 1px solid var(--line);
}

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

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 22px 28px 12px;
  gap: 16px;
}
.topbar h2 { margin: 0; font-size: 22px; }
.topbar p { margin: 6px 0 0; font-size: 12px; }
.top-actions { display: flex; gap: 8px; }

.pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 10px; border-radius: 999px;
  background: var(--panel-2); border: 1px solid var(--line);
  font-size: 12px; color: var(--muted);
}
.pill.env { color: var(--warn); border-color: rgba(255, 200, 87, .35); background: rgba(255, 200, 87, .08); }
.pill.good { color: var(--good); border-color: rgba(76, 208, 138, .35); background: rgba(76, 208, 138, .08); }
.pill.bad { color: var(--bad); border-color: rgba(255, 107, 129, .35); background: rgba(255, 107, 129, .08); }

.view { padding: 8px 28px 40px; display: flex; flex-direction: column; gap: 18px; }

/* ---------- 卡片 / 表格 ---------- */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; }

.card {
  background: linear-gradient(180deg, var(--panel), #120e1b);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px;
}
.card .label { color: var(--muted); font-size: 12px; }
.card .value { font-size: 26px; font-weight: 800; margin-top: 8px; letter-spacing: .3px; }
.card .hint { color: var(--muted); font-size: 11px; margin-top: 6px; }

.panel {
  background: linear-gradient(180deg, var(--panel), #120e1b);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}
.panel-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px; border-bottom: 1px solid var(--line); gap: 12px;
}
.panel-head h3 { margin: 0; font-size: 15px; }
.panel-body { padding: 16px 18px; }

.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.toolbar .grow { flex: 1; min-width: 180px; }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 11px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { color: var(--muted); font-weight: 600; font-size: 12px; background: rgba(255, 255, 255, .02); }
tbody tr:hover { background: rgba(140, 91, 255, .06); }
td.num { font-variant-numeric: tabular-nums; }

.thumb {
  width: 34px; height: 46px; border-radius: 6px; display: inline-block;
  vertical-align: middle; margin-right: 10px;
}

.title-cell strong { display: block; font-size: 13px; }
.title-cell small { color: var(--muted); font-size: 11px; }

.tag {
  display: inline-block; padding: 2px 8px; margin: 1px 4px 1px 0;
  border-radius: 999px; background: rgba(140, 91, 255, .15);
  color: #c9b8ff; font-size: 11px;
}

/* ---------- 按钮 ---------- */
.btn {
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  padding: 9px 14px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 13px;
  font-family: inherit;
  transition: transform .08s, background .15s, border-color .15s;
  white-space: nowrap;
}
.btn:hover { background: #241d33; }
.btn:active { transform: translateY(1px); }
.btn.primary {
  background: linear-gradient(135deg, var(--brand), #a05bff);
  border-color: transparent;
  font-weight: 700;
  box-shadow: 0 8px 22px rgba(140, 91, 255, .35);
}
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; }
.btn.small { padding: 5px 9px; font-size: 12px; border-radius: 8px; }
.btn.block { width: 100%; }
.btn.danger { color: var(--bad); border-color: rgba(255, 107, 129, .35); }
.btn.danger:hover { background: rgba(255, 107, 129, .12); }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.row-actions { display: flex; gap: 6px; flex-wrap: wrap; }

/* ---------- 表单 ---------- */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-grid .full { grid-column: 1 / -1; }
.form-grid label { display: flex; flex-direction: column; gap: 6px; color: var(--muted); font-size: 12px; }
.checkline { display: flex; gap: 14px; flex-wrap: wrap; align-items: center; color: var(--text); font-size: 13px; }
.checkline label { flex-direction: row; align-items: center; gap: 6px; color: var(--text); font-size: 13px; }

.settings-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 16px; }
.settings-grid .section { background: var(--panel-2); border: 1px solid var(--line); border-radius: 12px; padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.settings-grid h4 { margin: 0; font-size: 13px; color: #d9d1ff; }
.settings-grid label { display: flex; flex-direction: column; gap: 6px; color: var(--muted); font-size: 12px; }

/* ---------- 图表 ---------- */
.chart-wrap { position: relative; height: 260px; }
.chart-wrap canvas { width: 100%; height: 100%; display: block; }
.legend { display: flex; gap: 16px; font-size: 12px; color: var(--muted); margin-top: 8px; }
.legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; margin-right: 6px; }

/* ---------- 广告卡 ---------- */
.ad-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 14px; }
.ad-card { background: var(--panel-2); border: 1px solid var(--line); border-radius: 12px; padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.ad-card header { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.ad-card h4 { margin: 0; font-size: 14px; }
.ad-card .kv { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); }
.ad-card input { width: 92px; padding: 6px 8px; }

.switch { position: relative; width: 42px; height: 24px; border-radius: 999px; background: #332a46; cursor: pointer; transition: background .2s; flex: none; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; transition: left .2s; }
.switch.on { background: var(--good); }
.switch.on::after { left: 21px; }

/* ---------- 模态 ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(6, 4, 12, .72);
  backdrop-filter: blur(3px);
  display: grid; place-items: center; padding: 24px; z-index: 50;
}
.modal {
  width: 560px; max-width: 100%; max-height: 88vh;
  background: #171221; border: 1px solid var(--line);
  border-radius: 16px; display: flex; flex-direction: column;
  box-shadow: 0 40px 120px rgba(0, 0, 0, .6);
}
.modal.wide { width: 880px; }
.modal header { padding: 16px 20px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; }
.modal header h3 { margin: 0; font-size: 16px; }
.modal .body { padding: 20px; overflow: auto; }
.modal footer { padding: 14px 20px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 10px; }
.modal .close { background: none; border: none; color: var(--muted); font-size: 20px; cursor: pointer; }

/* ---------- 提示 ---------- */
.toast {
  position: fixed; left: 50%; bottom: 28px; transform: translate(-50%, 20px);
  background: #221a33; border: 1px solid var(--line); color: var(--text);
  padding: 10px 18px; border-radius: 10px; opacity: 0; pointer-events: none;
  transition: opacity .2s, transform .2s; z-index: 90; font-size: 13px;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { border-color: rgba(255, 107, 129, .5); color: #ffd0d7; }

.empty { padding: 40px; text-align: center; color: var(--muted); }

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; }
  #nav { flex-direction: row; flex-wrap: wrap; }
  .side-foot { margin: 0 0 0 auto; border: none; }
  .view { padding: 8px 16px 32px; }
  .topbar { padding: 16px; }
  .form-grid { grid-template-columns: 1fr; }
}

/* v0.9 内容分类与媒体库 */
.table-wrap { overflow-x: auto; }
.upload-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; align-items: end; }
.upload-grid .field, .modal .field { display: flex; flex-direction: column; gap: 6px; color: var(--muted); font-size: 12px; margin-bottom: 10px; }
.check-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 8px; margin: 6px 0 16px; }
.check-grid .field.inline, .modal .field.inline { flex-direction: row; align-items: center; gap: 6px; color: var(--text); font-size: 13px; margin: 0; }
.check-grid .field.inline input { width: auto; }
