:root {
  color-scheme: light;
  --ink: #1d232b;
  --muted: #717985;
  --line: #e2e5e8;
  --paper: #fbfcfd;
  --surface: #ffffff;
  --soft: #f3f5f6;
  --red: #d83a46;
  --red-dark: #b92835;
  --green: #26845a;
  --amber: #a86b13;
  --sidebar: #222930;
  --sidebar-muted: #9ba5af;
  --radius: 6px;
  font-family: "Microsoft YaHei UI", "PingFang SC", "Noto Sans CJK SC", sans-serif;
}

* { box-sizing: border-box; }
html, body { min-height: 100%; margin: 0; background: var(--paper); color: var(--ink); }
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .55; }
[hidden] { display: none !important; }

.login-view { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: linear-gradient(135deg, #eef1f3 0 56%, #e4e8eb 56%); }
.login-panel { width: min(420px, 100%); padding: 36px; border: 1px solid #d7dce0; border-radius: var(--radius); background: var(--surface); box-shadow: 0 20px 55px rgba(25, 32, 39, .12); }
.login-brand, .brand { display: flex; align-items: center; gap: 12px; }
.login-brand { margin-bottom: 30px; }
.login-brand > span, .brand > span { width: 38px; height: 38px; border-radius: 8px; display: grid; place-items: center; background: var(--red); color: #fff; font-size: 20px; font-weight: 800; box-shadow: 0 7px 16px rgba(216, 58, 70, .24); }
.login-brand div, .brand div { display: flex; flex-direction: column; }
.login-brand strong { font-size: 22px; }
.login-brand small, .brand small { margin-top: 3px; color: var(--muted); }
.login-panel label, .article-form label { display: flex; flex-direction: column; gap: 8px; color: #414852; font-size: 13px; font-weight: 700; }
.login-panel label + label { margin-top: 18px; }
input, textarea, select { width: 100%; border: 1px solid #cfd5da; border-radius: 5px; background: #fff; color: var(--ink); outline: none; transition: border-color .18s ease, box-shadow .18s ease; }
input, select { height: 42px; padding: 0 12px; }
textarea { padding: 11px 12px; resize: vertical; }
input:focus, textarea:focus, select:focus, .editable:focus { border-color: var(--red); box-shadow: 0 0 0 3px rgba(216, 58, 70, .11); }
.form-error { min-height: 20px; margin: 12px 0; color: var(--red); font-size: 13px; }

.app-view { min-height: 100vh; display: grid; grid-template-columns: 220px minmax(0, 1fr); }
.sidebar { position: sticky; top: 0; height: 100vh; padding: 22px 14px 16px; background: var(--sidebar); color: #f5f7f8; display: flex; flex-direction: column; }
.brand { padding: 0 8px 24px; border-bottom: 1px solid rgba(255,255,255,.1); }
.brand strong { font-size: 17px; }
.brand small { color: var(--sidebar-muted); }
.sidebar nav { margin-top: 18px; display: grid; gap: 5px; }
.nav-item { width: 100%; height: 42px; padding: 0 12px; border: 0; border-radius: 5px; background: transparent; color: var(--sidebar-muted); display: flex; align-items: center; gap: 10px; text-align: left; }
.nav-item:hover, .nav-item.active { background: rgba(255,255,255,.09); color: #fff; }
.nav-item.active { box-shadow: inset 3px 0 var(--red); }
.nav-item img { width: 18px; height: 18px; filter: invert(75%); }
.nav-item.active img, .nav-item:hover img { filter: invert(100%); }
.logout { margin-top: auto; }

.workspace { min-width: 0; }
.topbar { min-height: 92px; padding: 18px 30px; border-bottom: 1px solid var(--line); background: rgba(251, 252, 253, .96); display: flex; align-items: center; justify-content: space-between; gap: 20px; }
.topbar h1, .editor-heading h2, .lottery-toolbar h2 { margin: 0; font-size: 21px; letter-spacing: 0; }
.topbar p, .editor-heading p, .lottery-toolbar p { margin: 5px 0 0; color: var(--muted); font-size: 13px; }
.content-view { padding: 28px 30px 50px; }
.primary, .danger { height: 40px; padding: 0 15px; border: 0; border-radius: 5px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; font-weight: 700; }
.primary { background: var(--red); color: #fff; }
.primary:hover { background: var(--red-dark); }
.danger { border: 1px solid #e3b7bc; background: #fff; color: var(--red-dark); }
.primary img, .danger img { width: 17px; height: 17px; filter: brightness(0) invert(1); }
.danger img { filter: none; }
.wide { width: 100%; }

.metrics { width: min(100%, 660px); display: grid; grid-template-columns: repeat(3, minmax(130px, 220px)); gap: 1px; border: 1px solid var(--line); background: var(--line); }
.metrics > div { min-height: 92px; padding: 18px 20px; background: var(--surface); display: flex; flex-direction: column; justify-content: center; }
.metrics span { color: var(--muted); font-size: 12px; }
.metrics strong { margin-top: 8px; font-size: 25px; }
.table-toolbar { margin-top: 24px; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.search-field { width: min(360px, 100%); position: relative; }
.search-field img { position: absolute; left: 12px; top: 12px; width: 17px; height: 17px; opacity: .48; }
.search-field input { padding-left: 38px; }
.icon-button { width: 40px; height: 40px; padding: 0; border: 1px solid #d4d9de; border-radius: 5px; background: #fff; display: grid; place-items: center; }
.icon-button:hover { background: var(--soft); }
.icon-button img { width: 18px; height: 18px; }
.table-wrap { margin-top: 14px; border: 1px solid var(--line); background: var(--surface); overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 760px; }
th, td { height: 56px; padding: 0 16px; border-bottom: 1px solid var(--line); text-align: left; }
th { height: 44px; background: #f5f6f7; color: #606873; font-size: 12px; }
td { font-size: 13px; }
tbody tr:hover { background: #fbf7f7; }
.article-cell { max-width: 390px; }
.article-cell strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.article-cell span { display: block; margin-top: 4px; color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.status { padding: 4px 8px; border-radius: 12px; font-size: 11px; font-weight: 700; }
.status.published { background: #e5f4ec; color: var(--green); }
.status.draft { background: #f2eee6; color: var(--amber); }
.row-action { border: 0; background: transparent; color: var(--red); font-weight: 700; }
.empty-state { min-height: 230px; display: flex; flex-direction: column; align-items: center; justify-content: center; color: var(--muted); }
.empty-state strong { color: var(--ink); }
.empty-state span { margin-top: 8px; font-size: 13px; }

.editor-view { padding-top: 20px; }
.editor-heading { display: grid; grid-template-columns: 40px 1fr auto; align-items: center; gap: 14px; padding-bottom: 20px; border-bottom: 1px solid var(--line); }
.editor-actions { display: flex; gap: 10px; }
.article-form { max-width: 980px; padding-top: 24px; display: grid; gap: 20px; }
.field-row { display: grid; grid-template-columns: minmax(0, 2fr) minmax(180px, .75fr); gap: 18px; }
.field-row.compact { grid-template-columns: 150px 150px 180px; }
.grow { min-width: 0; }
.editor-label { margin-bottom: -12px; }
.rich-editor { border: 1px solid #cfd5da; border-radius: 5px; background: #fff; overflow: hidden; }
.editor-toolbar { min-height: 46px; padding: 5px 8px; border-bottom: 1px solid var(--line); background: #f5f6f7; display: flex; align-items: center; gap: 4px; }
.editor-toolbar button { width: 34px; height: 34px; padding: 0; border: 1px solid transparent; border-radius: 4px; background: transparent; display: grid; place-items: center; }
.editor-toolbar button:hover { border-color: #ccd2d7; background: #fff; }
.editor-toolbar img { width: 17px; height: 17px; }
.editable { min-height: 440px; padding: 22px; outline: none; color: #30343a; line-height: 1.8; }
.editable:empty::before { content: attr(data-placeholder); color: #a4a9af; }
.editable h2 { margin: 28px 0 12px; font-size: 20px; }
.editable p { margin: 0 0 16px; }
.editable img { display: block; max-width: 100%; height: auto; margin: 18px 0; }

.lottery-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 20px; padding-bottom: 22px; border-bottom: 1px solid var(--line); }
.lottery-grid { margin-top: 22px; display: grid; grid-template-columns: repeat(2, minmax(260px, 1fr)); border-top: 1px solid var(--line); border-left: 1px solid var(--line); }
.lottery-source { min-height: 122px; padding: 20px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); background: var(--surface); }
.lottery-source header { display: flex; align-items: center; justify-content: space-between; }
.lottery-source h3 { margin: 0; font-size: 16px; }
.lottery-source p { margin: 18px 0 0; color: var(--muted); font-size: 12px; line-height: 1.7; }
.source-state { padding: 4px 8px; border-radius: 12px; background: #eef0f2; color: #68717c; font-size: 11px; font-weight: 700; }
.source-state.online { background: #e5f4ec; color: var(--green); }
.source-state.cached { background: #f8eedc; color: var(--amber); }
.source-state.error { background: #fae7e9; color: var(--red-dark); }
.toast { position: fixed; z-index: 50; right: 24px; bottom: 24px; max-width: 360px; padding: 12px 16px; border-radius: 5px; background: #252b31; color: #fff; font-size: 13px; opacity: 0; pointer-events: none; transform: translateY(10px); transition: opacity .2s ease, transform .2s ease; }
.toast.show { opacity: 1; transform: translateY(0); }

@media (max-width: 820px) {
  .app-view { grid-template-columns: 68px minmax(0, 1fr); }
  .brand div, .nav-item { font-size: 0; }
  .brand { padding-left: 1px; padding-right: 1px; justify-content: center; }
  .nav-item { justify-content: center; padding: 0; }
  .nav-item img { width: 20px; height: 20px; }
  .topbar, .content-view { padding-left: 18px; padding-right: 18px; }
  .field-row, .field-row.compact { grid-template-columns: 1fr; }
  .metrics { grid-template-columns: repeat(3, 1fr); }
  .lottery-grid { grid-template-columns: 1fr; }
}

@media (max-width: 560px) {
  .app-view { display: block; padding-bottom: 64px; }
  .sidebar { position: fixed; z-index: 30; top: auto; bottom: 0; left: 0; right: 0; width: auto; height: 64px; padding: 0 8px; flex-direction: row; align-items: center; }
  .brand { display: none; }
  .sidebar nav { width: 100%; margin: 0; display: grid; grid-template-columns: 1fr 1fr; }
  .logout { width: 52px; margin: 0; }
  .topbar { min-height: 78px; padding: 12px 14px; }
  .topbar p { display: none; }
  .topbar h1 { font-size: 18px; }
  .primary { padding: 0 12px; }
  .content-view { padding: 18px 14px 36px; }
  .metrics { grid-template-columns: 1fr; }
  .metrics > div { min-height: 70px; }
  .editor-heading { grid-template-columns: 40px 1fr; }
  .editor-actions { grid-column: 1 / -1; justify-content: flex-end; }
  .editable { min-height: 360px; padding: 16px; }
  .lottery-toolbar { align-items: flex-start; flex-direction: column; }
}
