/* 后台：沿用 docs/design.md 的同一套 token 与尺度，布局按表单与列表场景重排。
   深色底 + 沙土卡其卡片，与顾客端同一品牌语气。 */

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: var(--ink-deep);
}

body {
  margin: 0;
  color: var(--sand-light);
  font-family: var(--font-body);
  background:
    radial-gradient(
      circle at 50% -20%,
      rgba(70, 86, 64, 0.5),
      rgba(14, 19, 21, 0) 60%
    ),
    var(--ink-deep);
  -webkit-text-size-adjust: 100%;
}

/* 顶栏 */
header {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 6px 12px;
  padding: 16px clamp(16px, 4vw, 32px);
  background: var(--ink);
  border-bottom: 2px solid var(--line-strong);
}
header strong {
  font-size: 1.05rem;
  letter-spacing: 0.02em;
}
header span {
  color: var(--leaf);
  font-size: 0.78rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

main {
  width: min(100% - 28px, 720px);
  margin: clamp(20px, 4vw, 36px) auto clamp(48px, 8vw, 80px);
}

h1 {
  margin: 0 0 clamp(16px, 3vw, 24px);
  font-size: clamp(1.5rem, 5vw, 2rem);
  line-height: 1.2;
  overflow-wrap: anywhere;
}
h2 {
  margin: 0 0 12px;
  font-size: clamp(1.05rem, 3.4vw, 1.2rem);
  color: var(--sand-light);
}

p {
  line-height: 1.7;
}

a {
  color: var(--gold);
  text-underline-offset: 4px;
}
a:hover {
  color: var(--gold-light);
}

/* 导航：一排可点的胶囊 */
nav[aria-label="后台导航"] {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0 0 clamp(18px, 4vw, 28px);
  padding: 0 0 clamp(14px, 3vw, 20px);
  border-bottom: 1px solid var(--line);
}
nav[aria-label="后台导航"] > a,
nav[aria-label="后台导航"] > form > button {
  display: inline-flex;
  align-items: center;
  min-height: 40px;
  padding: 8px 14px;
  color: var(--sand-light);
  background: rgba(231, 225, 209, 0.06);
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 0.88rem;
  font-weight: 600;
  text-decoration: none;
}
nav[aria-label="后台导航"] > a:hover {
  color: var(--ink-deep);
  background: var(--sand);
  border-color: var(--sand);
}
nav[aria-label="后台导航"] > form {
  margin: 0 0 0 auto;
  display: inline-flex;
}
nav[aria-label="后台导航"] > form > button {
  cursor: pointer;
  font-family: inherit;
}
nav[aria-label="后台导航"] > form > button:hover {
  color: var(--ink-deep);
  background: var(--sand);
  border-color: var(--sand);
}

/* 卡片：表单与列表都在卡片里 */
section,
main > form {
  display: block;
  margin-bottom: clamp(18px, 4vw, 26px);
  padding: clamp(16px, 4vw, 24px);
  background: var(--panel);
  border: 2px solid var(--line-strong);
  border-radius: 12px;
  box-shadow: var(--shadow);
}

label {
  display: block;
  margin-bottom: 18px;
  color: var(--sand-light);
  font-size: 0.86rem;
  font-weight: 700;
}
label:last-of-type {
  margin-bottom: 0;
}

input:not([type="hidden"]),
textarea,
select {
  display: block;
  width: 100%;
  min-height: 46px;
  margin-top: 8px;
  padding: 11px 13px;
  color: var(--sand-light);
  background: rgba(14, 19, 21, 0.55);
  border: 2px solid var(--line);
  border-radius: 8px;
  font: inherit;
  font-size: 16px;
}
input:not([type="hidden"]):hover,
textarea:hover,
select:hover {
  border-color: var(--line-strong);
}
textarea {
  resize: vertical;
  line-height: 1.6;
}
select {
  appearance: none;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--leaf) 50%),
    linear-gradient(135deg, var(--leaf) 50%, transparent 50%);
  background-position:
    calc(100% - 20px) calc(50% - 2px),
    calc(100% - 14px) calc(50% - 2px);
  background-size: 6px 6px;
  background-repeat: no-repeat;
  padding-right: 40px;
}
input[type="file"] {
  padding: 9px 13px;
  color: var(--muted-on-dark);
  background: rgba(14, 19, 21, 0.35);
  border-style: dashed;
}
input[type="file"]::file-selector-button {
  margin-right: 12px;
  padding: 6px 12px;
  color: var(--text-on-sand);
  background: var(--sand);
  border: 0;
  border-radius: 6px;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

/* 按钮：主按钮用警示橙 + 深墨字（对比度 5.29） */
button {
  min-height: 46px;
  padding: 11px 20px;
  color: var(--text-on-alert);
  background: var(--alert);
  border: 2px solid var(--gold-light);
  border-radius: 9px;
  box-shadow: 0 4px 0 var(--alert-deep);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  transition:
    background-color 0.15s ease,
    box-shadow 0.15s ease,
    transform 0.15s ease;
}
button:hover {
  background: var(--alert-light);
}
button:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 var(--alert-deep);
}
button.secondary {
  color: var(--sand-light);
  background: transparent;
  border-color: var(--line-strong);
  box-shadow: none;
  font-weight: 600;
}
button.secondary:hover {
  color: var(--ink-deep);
  background: var(--sand);
  border-color: var(--sand);
}

/* 状态与错误：flash 与表单错误 */
[role="status"],
[role="alert"] {
  margin: 0 0 18px;
  padding: 12px 16px;
  border-left: 4px solid var(--leaf);
  border-radius: 8px;
  background: rgba(147, 166, 110, 0.14);
  color: var(--sand-light);
  overflow-wrap: anywhere;
}
[role="alert"] {
  border-left-color: var(--alert);
  background: rgba(217, 103, 53, 0.16);
  color: #ffd9c2;
}

/* 奖品卡片网格 */
.prize-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 210px), 1fr));
  gap: 12px;
  margin: 0;
  padding: 0;
  list-style: none;
}
.prize-card {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 10px;
  min-width: 0;
  margin: 0;
  padding: 14px;
  color: var(--text-on-sand);
  background: var(--sand);
  border-radius: 10px;
  box-shadow: 0 5px 0 rgba(20, 25, 24, 0.4);
  font-weight: 700;
  overflow-wrap: anywhere;
}
.prize-card .prize-image,
.prize-card .prize-icon {
  display: grid;
  place-items: center;
  width: 100%;
  height: 92px;
  object-fit: contain;
}
.prize-card .prize-icon {
  color: var(--olive);
  background: rgba(32, 38, 37, 0.05);
  border: 1px solid rgba(32, 38, 37, 0.14);
  border-radius: 8px;
  font-size: 1.9rem;
}
.prize-actions {
  display: flex;
  gap: 8px;
}
.prize-actions form {
  flex: 1;
  margin: 0;
}
.prize-actions button {
  width: 100%;
  min-height: 40px;
  padding: 8px 10px;
  font-size: 0.85rem;
}
.prize-actions button.secondary {
  color: var(--text-on-sand);
  border-color: rgba(32, 38, 37, 0.35);
}
.prize-actions button.secondary:hover {
  color: var(--sand-light);
  background: var(--olive);
  border-color: var(--olive);
}

.empty-prizes {
  margin: 0;
  padding: 18px 0 4px;
  color: var(--muted-on-dark);
  border-top: 1px solid var(--line);
}

/* 八格配置预览 */
.wheel-preview {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  padding: clamp(8px, 2.4vw, 14px);
  background: var(--olive-dark);
  border: 8px solid var(--wood);
  border-radius: 10px;
  box-shadow:
    inset 0 0 0 2px var(--wood-ring),
    0 8px 0 #12181a;
}
.wheel-slot {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-width: 0;
  min-height: 92px;
  padding: 8px;
  color: var(--text-on-sand);
  background: var(--sand);
  border-radius: 8px;
  box-shadow: 0 4px 0 rgba(20, 25, 24, 0.4);
  font-size: 0.8rem;
  font-weight: 700;
  text-align: center;
  overflow-wrap: anywhere;
}
.wheel-slot:nth-child(1) {
  grid-area: 1 / 1;
}
.wheel-slot:nth-child(2) {
  grid-area: 1 / 2;
}
.wheel-slot:nth-child(3) {
  grid-area: 1 / 3;
}
.wheel-slot:nth-child(4) {
  grid-area: 2 / 3;
}
.wheel-slot:nth-child(5) {
  grid-area: 3 / 3;
}
.wheel-slot:nth-child(6) {
  grid-area: 3 / 2;
}
.wheel-slot:nth-child(7) {
  grid-area: 3 / 1;
}
.wheel-slot:nth-child(8) {
  grid-area: 2 / 1;
}
.wheel-slot .prize-image,
.wheel-slot .prize-icon {
  display: grid;
  place-items: center;
  width: clamp(32px, 9vw, 48px);
  height: clamp(32px, 9vw, 48px);
  object-fit: contain;
}
.wheel-slot .prize-icon {
  color: var(--olive);
  font-size: 1.4rem;
}
.wheel-button {
  grid-area: 2 / 2;
  width: 100%;
  align-self: center;
  justify-self: center;
  min-height: 48px;
  padding: 6px;
  font-size: 0.9rem;
}
.wheel-button:disabled {
  color: var(--text-on-alert-disabled);
  background: var(--alert-disabled);
  border-color: var(--muted);
  box-shadow: 0 4px 0 #2b2825;
  cursor: not-allowed;
}
.wheel-button:disabled:hover {
  background: var(--alert-disabled);
}
.slot-empty {
  color: var(--muted-on-sand);
  font-weight: 400;
}
.wheel-problems {
  margin: 0 0 20px;
  padding: 12px 12px 12px 32px;
  background: rgba(217, 103, 53, 0.16);
  border-left: 4px solid var(--alert);
  border-radius: 8px;
  color: #ffd9c2;
}
.wheel-problems li {
  margin-bottom: 4px;
  line-height: 1.6;
}

fieldset {
  margin: 0 0 20px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 10px;
}
legend {
  padding: 0 8px;
  color: var(--leaf);
  font-size: 0.86rem;
  font-weight: 700;
}

/* 转盘链接记录 */
.link-list {
  margin: 0;
  padding: 0;
  list-style: none;
}
.link-card {
  margin-bottom: 14px;
  padding: 14px;
  background: var(--sand);
  border-radius: 10px;
  box-shadow: 0 5px 0 rgba(20, 25, 24, 0.4);
}
.link-card:last-child {
  margin-bottom: 0;
}
.link-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 10px;
  margin: 0 0 8px;
  color: var(--muted-on-sand);
  font-size: 0.84rem;
  overflow-wrap: anywhere;
}
.link-card a {
  color: var(--link-on-sand);
}
.link-card a:hover {
  color: var(--alert);
}
.link-meta > span[aria-label] {
  color: var(--text-on-sand);
  font-weight: 700;
}
.link-meta > span[aria-label="状态"] {
  padding: 2px 10px;
  border-radius: 999px;
  color: var(--sand-light);
  background: var(--olive);
  font-size: 0.8rem;
}
.link-meta > span[aria-label="状态"].settled {
  background: var(--alert-deep);
}
.link-meta > span[aria-label="中奖奖品"]:empty,
.link-meta > span[aria-label="首次有效点击时间"]:empty {
  font-weight: 400;
}
.link-row {
  display: flex;
  gap: 8px;
  align-items: stretch;
}
.link-row input {
  flex: 1;
  min-width: 0;
  margin-top: 0;
  color: var(--text-on-sand);
  background: rgba(255, 255, 255, 0.55);
  border-color: rgba(32, 38, 37, 0.28);
  font-size: 0.86rem;
}
.link-row button {
  flex: none;
  min-height: 46px;
}
.link-card button.secondary {
  color: var(--text-on-sand);
  border-color: rgba(32, 38, 37, 0.35);
}
.link-card button.secondary:hover {
  color: var(--sand-light);
  background: var(--olive);
  border-color: var(--olive);
}
.link-card form {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: flex-end;
  margin: 12px 0 0;
  padding-top: 12px;
  border-top: 1px solid rgba(32, 38, 37, 0.15);
}
.link-card form label {
  flex: 1 1 180px;
  margin: 0;
  color: var(--muted-on-sand);
  font-size: 0.84rem;
}
.link-card form input:not([type="hidden"]) {
  margin-top: 4px;
  color: var(--text-on-sand);
  background: rgba(255, 255, 255, 0.55);
  border-color: rgba(32, 38, 37, 0.28);
  font-size: 0.86rem;
}
.link-card form button {
  flex: 0 0 auto;
  min-height: 46px;
}

/* 筛选与分页 */
[aria-label="链接筛选"],
[aria-label="分页"] {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin: 0 0 16px;
  padding: 0;
  border: 0;
  font-size: 0.86rem;
}
[aria-label="分页"] {
  margin: 16px 0 0;
}
[aria-label="链接筛选"] a,
[aria-label="分页"] a,
[aria-label="分页"] > span {
  display: inline-flex;
  align-items: center;
  min-height: 38px;
  padding: 7px 14px;
  color: var(--sand-light);
  background: rgba(231, 225, 209, 0.06);
  border: 1px solid var(--line);
  border-radius: 999px;
  text-decoration: none;
}
[aria-label="链接筛选"] a:hover,
[aria-label="分页"] a:hover {
  color: var(--ink-deep);
  background: var(--sand);
  border-color: var(--sand);
}
[aria-label="链接筛选"] a[aria-current="true"] {
  color: var(--ink-deep);
  background: var(--leaf);
  border-color: var(--leaf);
  font-weight: 700;
}
[aria-label="分页"] > span {
  color: var(--muted-on-dark);
  border-style: dashed;
}

.rules {
  margin: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  line-height: 1.8;
  color: var(--muted-on-dark);
}

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

@media (max-width: 480px) {
  nav[aria-label="后台导航"] > form {
    margin-left: 0;
  }
  .prize-actions {
    flex-direction: column;
  }
  .link-row {
    flex-direction: column;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
