:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-subtle: #f8fafb;
  --text: #172026;
  --muted: #69767d;
  --border: #dce2e5;
  --border-strong: #bdc7cc;
  --primary: #087f5b;
  --primary-hover: #066b4d;
  --primary-soft: #e7f5ef;
  --accent: #d4a400;
  --danger: #c92a2a;
  --danger-soft: #fff0f0;
  --sidebar: #11181b;
  --sidebar-muted: #97a4aa;
  --shadow: 0 14px 36px rgba(21, 31, 36, 0.12);
  --radius: 6px;
  --sidebar-width: 240px;
  font-family: Inter, "Microsoft YaHei", "PingFang SC", system-ui, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-width: 320px;
  color: var(--text);
  background: var(--bg);
  font-size: 14px;
}

button, input, select, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; }

:focus-visible {
  outline: 3px solid rgba(8, 127, 91, 0.3);
  outline-offset: 2px;
}

[hidden] { display: none !important; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.loading-screen {
  min-height: 100vh;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 14px;
  color: var(--muted);
}

.spinner {
  width: 30px;
  height: 30px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(135deg, rgba(8, 127, 91, 0.06), transparent 50%),
    var(--bg);
}

.login-panel {
  width: min(420px, 100%);
  display: grid;
  gap: 32px;
  padding: 38px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.login-brand, .sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: inherit;
  text-decoration: none;
  font-size: 18px;
}

.brand-mark {
  color: #ffe159;
  font-size: 25px;
  font-weight: 900;
  line-height: 1;
  text-shadow: 0 1px 0 #927200;
}

.login-panel .brand-mark { color: #b58a00; text-shadow: none; }

h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: 24px; line-height: 1.2; letter-spacing: 0; }
h2 { margin-bottom: 0; font-size: 19px; line-height: 1.3; letter-spacing: 0; }
h3 { margin-bottom: 8px; font-size: 15px; letter-spacing: 0; }
.muted { color: var(--muted); line-height: 1.6; }
.eyebrow { margin-bottom: 5px; color: var(--muted); font-size: 12px; font-weight: 700; text-transform: uppercase; }

.form-stack { display: grid; gap: 18px; }
.field { display: grid; align-content: start; min-width: 0; gap: 7px; color: #39474e; font-size: 13px; font-weight: 600; }
.field small { color: var(--muted); font-weight: 400; line-height: 1.4; }
.field-feedback { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; min-height: 20px; }
.field-note { overflow-wrap: anywhere; }
.field-counter { flex: 0 0 auto; color: var(--muted); font-size: 12px; font-weight: 400; font-variant-numeric: tabular-nums; white-space: nowrap; }
.field.has-warning .field-note, .field.has-warning .field-counter { color: #856000; }
.field.has-error .field-note, .field.has-error .field-counter { color: var(--danger); }
.field [aria-invalid="true"] { border-color: var(--danger); }
.module-guide { margin-bottom: 22px; padding: 0 0 18px; border-bottom: 1px solid var(--border); line-height: 1.7; }
.module-guide p { margin-bottom: 6px; }
details summary { width: fit-content; max-width: 100%; cursor: pointer; color: var(--primary); font-weight: 600; line-height: 1.6; }
.module-guide ul { margin: 10px 0 0; padding-left: 22px; color: #49565c; }
.module-guide li + li { margin-top: 5px; }
.feature-map { margin: 0; }
.feature-map > div { display: grid; grid-template-columns: minmax(180px, 1fr) minmax(0, 2fr); gap: 20px; padding: 15px 0; border-bottom: 1px solid var(--border); line-height: 1.6; }
.feature-map dt { font-weight: 600; }
.feature-map dd { margin: 0; }
.feature-map a { color: var(--primary); text-underline-offset: 3px; }
.feature-map p { margin: 3px 0 0; color: var(--muted); }
.legacy-settings { padding: 20px 24px; border-top: 1px solid var(--border); }
.legacy-settings p { margin-top: 10px; }
.legacy-settings fieldset { min-width: 0; margin: 0; padding: 0; border: 0; }
.form-actions small { margin-right: auto; align-self: center; }
.form-grid > p { margin: 0; font-size: 12px; }

input, select, textarea {
  width: 100%;
  min-width: 0;
  min-height: 40px;
  padding: 9px 11px;
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: 5px;
  background: var(--surface);
  transition: border-color 0.15s, box-shadow 0.15s;
}

textarea { min-height: 112px; resize: vertical; line-height: 1.6; }
input:hover, select:hover, textarea:hover { border-color: #93a1a8; }
input:focus, select:focus, textarea:focus { border-color: var(--primary); outline: none; box-shadow: 0 0 0 3px rgba(8, 127, 91, 0.12); }
input:disabled { color: var(--muted); background: #eef1f2; }

.form-error { margin: -4px 0 0; color: var(--danger); font-size: 13px; }

.button {
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 8px 14px;
  border: 1px solid transparent;
  border-radius: 5px;
  color: var(--text);
  background: transparent;
  font-weight: 700;
  text-decoration: none;
  white-space: nowrap;
}

.button.primary { color: #fff; background: var(--primary); }
.button.primary:hover { background: var(--primary-hover); }
.button.secondary { border-color: var(--border-strong); background: var(--surface); }
.button.secondary:hover, .button.ghost:hover { background: #edf1f2; }
.button.danger { color: #fff; background: var(--danger); }
.button.small { min-height: 32px; padding: 5px 9px; font-size: 12px; }
.button.wide { width: 100%; }

.icon-button {
  width: 38px;
  height: 38px;
  display: inline-grid;
  place-items: center;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 5px;
  color: var(--text);
  background: var(--surface);
  font-size: 20px;
}

.admin-shell { min-height: 100vh; display: grid; grid-template-columns: var(--sidebar-width) minmax(0, 1fr); }

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 22px 14px;
  color: #f4f7f8;
  background: var(--sidebar);
  z-index: 20;
}

.sidebar-brand { gap: 12px; padding: 4px 10px 26px; }
.sidebar-brand > span:last-child { display: grid; }
.sidebar-brand small { margin-top: 2px; color: var(--sidebar-muted); font-size: 11px; font-weight: 500; }
.sidebar-nav { display: grid; gap: 5px; }

.nav-item {
  min-height: 44px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 12px;
  color: var(--sidebar-muted);
  border: 0;
  border-radius: 5px;
  background: transparent;
  text-align: left;
  font-weight: 600;
}

.nav-item:hover { color: #fff; background: rgba(255, 255, 255, 0.06); }
.nav-item.active { color: #fff; background: var(--primary); }
.nav-icon { width: 20px; text-align: center; font-size: 18px; }

.sidebar-footer {
  margin-top: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 15px 10px 2px;
  color: var(--sidebar-muted);
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  font-size: 12px;
}

.status-dot { width: 8px; height: 8px; border-radius: 50%; background: #40c057; box-shadow: 0 0 0 3px rgba(64, 192, 87, 0.14); }
.workspace { min-width: 0; }

.topbar {
  min-height: 84px;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 16px 30px;
  border-bottom: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.95);
}

.topbar-actions { margin-left: auto; display: flex; gap: 8px; }
.menu-button { display: none; }
.view { max-width: 1440px; padding: 28px 30px 50px; }

.stats-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.stat-card { padding: 20px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.stat-label { color: var(--muted); font-size: 13px; }
.stat-value { margin-top: 11px; font-size: 30px; font-weight: 800; }
.stat-meta { margin-top: 3px; color: var(--muted); font-size: 12px; }

.content-section { margin-top: 26px; }
.section-header { min-height: 44px; display: flex; align-items: flex-start; gap: 16px; margin-bottom: 14px; }
.section-header p { margin: 5px 0 0; }
.section-header .button { margin-left: auto; }
.quick-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); overflow: hidden; }
.quick-action { min-height: 128px; padding: 21px; color: var(--text); border-right: 1px solid var(--border); text-decoration: none; }
.quick-action:last-child { border-right: 0; }
.quick-action:hover { background: var(--surface-subtle); }
.quick-action p { margin: 7px 0 0; color: var(--muted); line-height: 1.5; }
.quick-action strong { display: flex; justify-content: space-between; font-size: 15px; }

.toolbar { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 14px; }
.search-control { position: relative; flex: 1 1 260px; max-width: 420px; }
.search-control input { padding-left: 36px; }
.search-control::before { content: "⌕"; position: absolute; left: 12px; top: 6px; color: var(--muted); font-size: 21px; }
.toolbar select { width: auto; min-width: 180px; }

.table-wrap { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); overflow: auto; }
table { width: 100%; border-collapse: collapse; white-space: nowrap; }
th, td { padding: 12px 15px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; }
th { color: var(--muted); background: var(--surface-subtle); font-size: 12px; font-weight: 700; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fbfcfc; }
.cell-main { display: flex; align-items: center; gap: 11px; }
.cell-main img { width: 42px; height: 42px; object-fit: contain; border: 1px solid var(--border); border-radius: 5px; background: #111; }
.cell-main span { display: grid; min-width: 0; gap: 3px; }
.cell-main strong, .cell-main small { max-width: 240px; overflow-wrap: anywhere; white-space: normal; }
.cell-main img { flex-shrink: 0; }
.cell-main small { color: var(--muted); }
.actions { display: flex; justify-content: flex-end; gap: 5px; }

.badge { display: inline-flex; align-items: center; min-height: 24px; padding: 3px 8px; border-radius: 999px; font-size: 12px; font-weight: 700; }
.badge.live { color: #087f5b; background: var(--primary-soft); }
.badge.off { color: #69767d; background: #eef1f2; }
.badge.featured { color: #795d00; background: #fff7d6; }

.empty-state { min-height: 280px; display: grid; place-content: center; justify-items: center; padding: 30px; text-align: center; }
.empty-state strong { font-size: 16px; }
.empty-state p { max-width: 360px; margin: 7px 0 16px; color: var(--muted); }

.settings-form { background: var(--surface); }
.form-section { display: grid; grid-template-columns: minmax(180px, 0.32fr) minmax(0, 1fr); gap: 34px; padding: 24px; border-bottom: 1px solid var(--border); }
.form-section:last-of-type { border-bottom: 0; }
.form-section-copy p { margin-bottom: 0; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 17px; }
.form-grid .span-2 { grid-column: 1 / -1; }
.bottom-nav-editors { display: grid; gap: 18px; }
.bottom-nav-editor { padding: 16px; border: 1px solid var(--border); border-radius: 6px; background: #fbfcfc; }
.bottom-nav-editor h3 { margin: 0 0 14px; color: var(--ink); font-size: 15px; }
.form-actions { position: sticky; bottom: 0; display: flex; justify-content: flex-end; gap: 9px; padding: 14px 24px; border-top: 1px solid var(--border); background: rgba(255,255,255,0.96); }

.switch-field { min-height: 40px; display: flex; align-items: center; gap: 10px; }
.switch-field input { width: 18px; min-height: 18px; accent-color: var(--primary); }
.switch-field label { font-weight: 600; }

.upload-field { display: grid; grid-template-columns: 70px minmax(0, 1fr); gap: 12px; align-items: center; }
.upload-preview { width: 70px; height: 70px; object-fit: contain; border: 1px solid var(--border); border-radius: 5px; background: #111; }
.upload-controls { display: grid; gap: 7px; }
.upload-controls input[type="file"] { min-height: 0; padding: 7px; font-size: 12px; }

.dialog, .confirm-dialog { width: min(700px, calc(100vw - 28px)); max-height: calc(100vh - 28px); padding: 0; border: 0; border-radius: var(--radius); box-shadow: var(--shadow); }
.dialog::backdrop, .confirm-dialog::backdrop { background: rgba(8, 14, 17, 0.56); }
.dialog > form { display: flex; max-height: calc(100vh - 28px); flex-direction: column; }
.dialog-header { display: flex; align-items: center; padding: 19px 22px; border-bottom: 1px solid var(--border); }
.dialog-header .icon-button { margin-left: auto; }
.dialog-body { padding: 22px; overflow: auto; }
.dialog-header, .dialog-footer { flex-shrink: 0; }
.dialog-footer { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 22px; border-top: 1px solid var(--border); background: var(--surface-subtle); }
.confirm-dialog { width: min(430px, calc(100vw - 28px)); padding: 24px; }
.confirm-dialog p { margin: 10px 0 22px; }
.confirm-dialog .dialog-footer { padding: 0; border: 0; background: transparent; }

.toast-region { position: fixed; right: 20px; bottom: 20px; display: grid; gap: 9px; z-index: 100; }
.toast { max-width: 360px; padding: 12px 15px; color: #fff; border-radius: 5px; background: #182126; box-shadow: var(--shadow); animation: toast-in 0.2s ease-out; }
.toast.error { background: #a61e1e; }
@keyframes toast-in { from { transform: translateY(8px); opacity: 0; } }

@media (max-width: 900px) {
  .admin-shell { display: block; }
  .sidebar { position: fixed; left: 0; width: var(--sidebar-width); transform: translateX(-100%); transition: transform 0.2s ease; box-shadow: var(--shadow); }
  body.menu-open .sidebar { transform: translateX(0); }
  .menu-button { display: inline-grid; }
  .topbar { padding: 14px 18px; }
  .view { padding: 22px 18px 40px; }
  .form-section { grid-template-columns: 1fr; gap: 18px; }
}

@media (max-width: 680px) {
  .feature-map > div { grid-template-columns: 1fr; gap: 5px; }
  .form-section { padding: 20px 16px; }
  .form-actions { flex-wrap: wrap; padding: 14px 16px; }
  .legacy-settings { padding: 20px 16px; }
  .cell-main { gap: 7px; }
  .cell-main span { max-width: 105px; }
  .topbar { gap: 10px; }
  .stats-grid, .quick-grid { grid-template-columns: 1fr; }
  .quick-action { min-height: 100px; border-right: 0; border-bottom: 1px solid var(--border); }
  .quick-action:last-child { border-bottom: 0; }
  .form-grid { grid-template-columns: 1fr; }
  .form-grid .span-2 { grid-column: auto; }
  .topbar-actions .secondary { display: none; }
  .login-panel { padding: 28px 22px; }
  table { white-space: normal; }
  th:nth-child(n+2):not(:last-child), td:nth-child(n+2):not(:last-child) { display: none; }
  th, td { padding: 10px; }
  .actions { justify-content: flex-end; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
