* { box-sizing: border-box; }
:root {
  --bg: #f6f7f9;
  --card: #fff;
  --border: #e5e7eb;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --text: #1f2937;
  --muted: #6b7280;
  --ok: #10b981;
  --warn: #f59e0b;
  --err: #ef4444;
  --tag-1: #dbeafe;
  --tag-2: #fef3c7;
  --tag-3: #d1fae5;
}
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Helvetica Neue", Helvetica, Arial, sans-serif;
  font-size: 14px; color: var(--text); background: var(--bg);
  line-height: 1.55;
}
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 24px; background: #fff; border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}
.topbar .brand { font-size: 16px; font-weight: 600; }
.topbar .right { display: flex; gap: 12px; align-items: center; }
.topbar a { color: var(--primary); text-decoration: none; }
.topbar a:hover { text-decoration: underline; }
.container { max-width: 980px; margin: 0 auto; padding: 24px; }
.search-bar { display: flex; gap: 12px; align-items: center; margin-bottom: 16px; }
.search-bar input[type=text] {
  flex: 1; font-size: 16px; padding: 12px 14px; border: 1px solid var(--border);
  border-radius: 8px; outline: none; background: #fff;
}
.search-bar input[type=text]:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,.15); }
select, button, input[type=password], input[type=text] {
  font-family: inherit; font-size: 14px;
}
select {
  padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; background: #fff;
}
button {
  padding: 10px 16px; border: 0; border-radius: 8px; cursor: pointer; background: var(--primary); color: #fff;
  font-weight: 500;
}
button:hover { background: var(--primary-dark); }
button.ghost { background: #fff; color: var(--text); border: 1px solid var(--border); }
button.ghost:hover { background: #f9fafb; }
button.danger { background: var(--err); }
button.danger:hover { background: #dc2626; }
button.small { padding: 4px 10px; font-size: 12px; border-radius: 6px; }
.expand-tip { font-size: 12px; color: var(--muted); margin-bottom: 12px; }
.expand-tip .kw {
  display: inline-block; padding: 2px 8px; margin: 0 4px;
  background: var(--tag-2); border-radius: 4px;
}
.miss-warn {
  padding: 10px 14px; background: #fffbeb; color: #92400e;
  border: 1px solid #fde68a; border-radius: 8px; margin-bottom: 12px;
}
.results { display: flex; flex-direction: column; gap: 10px; }
.card {
  background: var(--card); border: 1px solid var(--border); border-radius: 10px;
  padding: 14px 16px;
}
.card .meta { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 6px; }
.card .meta .badge {
  padding: 2px 8px; border-radius: 4px; font-size: 12px;
  background: var(--tag-1); color: #1e40af;
}
.card .meta .badge.cat-生鲜冻品 { background: #e0f2fe; color: #075985; }
.card .meta .badge.cat-常温速食 { background: #fef3c7; color: #92400e; }
.card .meta .badge.cat-通用 { background: #d1fae5; color: #065f46; }
.card .meta .group { color: var(--muted); font-size: 12px; }
.card .meta .score {
  margin-left: auto; font-size: 12px; color: var(--muted);
}
.card .code {
  font-weight: 600; font-size: 15px; color: #111827; margin-bottom: 6px;
}
.card .content {
  white-space: pre-wrap; color: #374151;
}
.card .actions { margin-top: 10px; display: flex; gap: 8px; }
.card.fallback { background: #fef9f7; border-color: #fed7aa; border-style: dashed; }
.card.fallback .code { color: #9a3412; }
.empty { text-align: center; color: var(--muted); padding: 40px 0; }
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: rgba(17,24,39,.92); color: #fff; padding: 10px 18px; border-radius: 8px;
  font-size: 13px; opacity: 0; transition: opacity .2s;
  pointer-events: none; z-index: 999;
}
.toast.show { opacity: 1; }

/* Login */
.login-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #eff6ff 0%, #f5f3ff 100%);
}
.login-box {
  background: #fff; padding: 32px; border-radius: 12px; width: 360px;
  box-shadow: 0 10px 30px rgba(0,0,0,.06);
}
.login-box h1 { margin: 0 0 24px; font-size: 20px; }
.login-box label { display: block; margin-bottom: 6px; font-size: 13px; color: var(--muted); }
.login-box input { width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; margin-bottom: 14px; }
.login-box button { width: 100%; padding: 12px; }
.login-error { color: var(--err); font-size: 13px; margin-top: 10px; min-height: 18px; }

/* Admin */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; }
.tabs button {
  background: transparent; color: var(--muted); border-radius: 0;
  border-bottom: 2px solid transparent; padding: 10px 16px; font-weight: 500;
}
.tabs button.active { color: var(--primary); border-bottom-color: var(--primary); }
.tabs button:hover { background: transparent; color: var(--text); }
.toolbar {
  display: flex; gap: 12px; align-items: center; margin-bottom: 12px; flex-wrap: wrap;
}
.toolbar input[type=text] { padding: 8px 12px; border: 1px solid var(--border); border-radius: 6px; }
.toolbar .grow { flex: 1; }
table { width: 100%; border-collapse: collapse; background: #fff; border-radius: 8px; overflow: hidden; }
th, td { padding: 10px 12px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; font-size: 13px; }
th { background: #f9fafb; font-weight: 600; color: var(--muted); }
td.actions { white-space: nowrap; }
td .ellipsis { max-width: 480px; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.modal-mask {
  position: fixed; inset: 0; background: rgba(17,24,39,.4); display: none; align-items: center; justify-content: center; z-index: 100;
}
.modal-mask.show { display: flex; }
.modal {
  background: #fff; border-radius: 12px; padding: 24px; width: 560px; max-width: 92vw; max-height: 86vh; overflow: auto;
}
.modal h3 { margin: 0 0 16px; }
.modal label { display: block; margin: 10px 0 4px; font-size: 13px; color: var(--muted); }
.modal input, .modal select, .modal textarea {
  width: 100%; padding: 8px 10px; border: 1px solid var(--border); border-radius: 6px; font-family: inherit; font-size: 13px;
}
.modal textarea { min-height: 120px; resize: vertical; }
.modal .footer { display: flex; gap: 8px; justify-content: flex-end; margin-top: 18px; }
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; }
.stat-card {
  background: #fff; border: 1px solid var(--border); border-radius: 10px; padding: 16px;
}
.stat-card .label { color: var(--muted); font-size: 13px; margin-bottom: 8px; }
.stat-card .value { font-size: 24px; font-weight: 600; }
.tag-list { display: flex; flex-wrap: wrap; gap: 4px; }
.tag {
  background: var(--tag-1); color: #1e40af; padding: 2px 8px; border-radius: 4px; font-size: 12px;
}
.pager { display: flex; gap: 8px; align-items: center; justify-content: center; margin-top: 16px; }
.pager span { color: var(--muted); }
