:root {
  --bg: #f5f7fa;
  --surface: #ffffff;
  --border: #e2e8f0;
  --text: #1e293b;
  --muted: #64748b;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --danger: #dc2626;
  --ok: #16a34a;
  --warn: #d97706;
  --radius: 10px;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}
.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 13px; }

.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 28px;
  box-shadow: 0 8px 30px rgba(15, 23, 42, 0.06);
}
.login-card h1 { margin: 0 0 6px; font-size: 20px; }
.login-card label { display: block; margin-top: 14px; font-weight: 500; }
.login-card input { width: 100%; margin-top: 6px; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}
.brand { font-weight: 700; font-size: 16px; padding: 14px 0; }
.tabs { display: flex; gap: 4px; flex-wrap: wrap; }
.tab {
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  padding: 14px 14px;
  cursor: pointer;
  color: var(--muted);
  font-weight: 500;
  font-size: 14px;
}
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }
.user-bar { display: flex; align-items: center; gap: 10px; padding: 8px 0; }

.container { max-width: 1180px; margin: 20px auto; padding: 0 16px 40px; }
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}
.panel-head h2, .panel-head h3 { margin: 0; }
.meta-badges { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 16px;
}
.card h3 { margin: 0 0 12px; font-size: 15px; }

.rules-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 14px;
  margin-bottom: 16px;
}
.rule-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.rule-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.rule-id { font-weight: 700; font-family: monospace; font-size: 13px; }
.kw-list { display: flex; flex-wrap: wrap; gap: 6px; }
.kw-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: #f1f5f9;
  border: 1px solid #cbd5e1;
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 13px;
}
.kw-del {
  background: none;
  border: none;
  color: var(--danger);
  cursor: pointer;
  font-weight: 700;
  padding: 0;
  line-height: 1;
}
.kw-add-row { display: flex; gap: 6px; margin-top: auto; }
.kw-add-row input { flex: 1; }

input, select, textarea {
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 8px 10px;
  font-size: 13px;
  font-family: inherit;
  background: #fff;
  color: var(--text);
}
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(37, 99, 235, 0.25); border-color: var(--primary); }

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}
.form-grid label { display: flex; flex-direction: column; gap: 6px; font-weight: 500; font-size: 13px; }
.span-2 { grid-column: span 2; }
.align-end { display: flex; align-items: flex-end; }
.inline-form { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }

.btn {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 7px;
  padding: 8px 14px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.btn:hover { background: #f8fafc; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-hover); }
.btn.danger { color: var(--danger); border-color: #fecaca; }
.btn.small { padding: 5px 10px; font-size: 12px; }
.btn.full { width: 100%; margin-top: 16px; }

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  background: #e2e8f0;
  color: #334155;
}
.badge.info { background: #dbeafe; color: #1d4ed8; }
.badge.ok { background: #dcfce7; color: #15803d; }
.badge.danger { background: #fee2e2; color: #b91c1c; }
.badge.warn { background: #fef3c7; color: #b45309; }

.minted-box {
  margin-top: 14px;
  background: #f8fafc;
  border: 1px dashed var(--primary);
  border-radius: 8px;
  padding: 12px;
}
.minted-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.minted-box pre { margin: 0; font-family: monospace; font-size: 13px; white-space: pre-wrap; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { background: #f8fafc; color: var(--muted); font-weight: 600; white-space: nowrap; }
td.mono { font-family: monospace; font-size: 12px; }

.msg.error { margin-top: 10px; color: var(--danger); font-size: 13px; }
.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  background: #0f172a;
  color: #fff;
  padding: 10px 16px;
  border-radius: 8px;
  font-size: 13px;
  z-index: 50;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.2);
}
@media (max-width: 680px) {
  .form-grid { grid-template-columns: 1fr; }
  .span-2 { grid-column: span 1; }
}
