:root {
  --bg: #f4f6f9;
  --panel: #ffffff;
  --border: #d8dee6;
  --text: #1f2933;
  --muted: #6b7785;
  --primary: #2563eb;
  --primary-d: #1d4ed8;
  --danger: #dc2626;
  --ok: #16a34a;
  --add-bg: #e7f7ec;
  --add-fg: #147a34;
  --del-bg: #fdeaea;
  --del-fg: #c02626;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}
.hidden { display: none !important; }

#topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  padding: 10px 16px;
  position: sticky;
  top: 0;
  z-index: 10;
}
.brand { font-weight: 700; }
.ctx { color: var(--muted); }
.spacer { flex: 1; }
.who { color: var(--muted); }

main { padding: 18px; max-width: 1100px; margin: 0 auto; }
main.wide { max-width: none; }

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 18px;
}

h1 { font-size: 20px; margin: 0 0 14px; }
h2 { font-size: 15px; margin: 18px 0 8px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }

.btn {
  border: 1px solid var(--primary);
  background: var(--primary);
  color: #fff;
  padding: 8px 14px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
}
.btn:hover { background: var(--primary-d); }
.btn.small { padding: 5px 10px; font-size: 13px; }
.btn.ghost { background: transparent; color: var(--text); border-color: var(--border); }
.btn.ghost:hover { background: #eef2f7; }
.btn.danger { background: var(--danger); border-color: var(--danger); }
.btn.ok { background: var(--ok); border-color: var(--ok); }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.row-actions { display: flex; gap: 6px; }

input[type=text], input[type=password], select, textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font: inherit;
  background: #fff;
  color: var(--text);
}
textarea { resize: vertical; font-family: ui-monospace, Menlo, Consolas, monospace; }

.field { margin-bottom: 14px; }
.field label { display: block; font-weight: 600; margin-bottom: 4px; }
.field .help { color: var(--muted); font-size: 12px; margin-top: 4px; }
.input-with-gen { display: flex; gap: 8px; align-items: stretch; }
.input-with-gen input[type=text] { flex: 1; }
.input-with-gen .gen-btn { flex: 0 0 auto; white-space: nowrap; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); }
th {
  color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .02em;
  padding: 5px 8px; line-height: 1.2;
  position: sticky; top: 0; z-index: 1;
  background: var(--panel);
  box-shadow: inset 0 -1px 0 var(--border);  /* keep the divider while sticky */
}
tr:hover td { background: #f8fafc; }

.toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 14px; }
.toolbar input[type=text] { max-width: 280px; }

.login-wrap { max-width: 360px; margin: 8vh auto; }

.list-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }

.file-list { list-style: none; padding: 0; margin: 0; }
.file-list li {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 14px; border: 1px solid var(--border); border-radius: 8px; margin-bottom: 8px;
}
.file-list li:hover { border-color: var(--primary); }

.table-wrap { overflow: auto; max-height: calc(100vh - 190px); }
.count-badge {
  display: inline-block; min-width: 22px; text-align: center;
  padding: 2px 8px; border-radius: 10px; font-weight: 600; font-size: 13px;
}
.count-badge.count-wl { background: var(--add-bg); color: var(--add-fg); }
.count-badge.count-bl { background: var(--del-bg); color: var(--del-fg); }
.cell-sc {
  display: inline-block; max-width: 220px; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap; vertical-align: bottom;
}
.file-actions { display: flex; gap: 8px; align-items: center; }
a.btn { text-decoration: none; display: inline-flex; align-items: center; }

.diff-row { padding: 10px 0; border-bottom: 1px solid var(--border); }
.diff-row .k { font-weight: 600; margin-bottom: 4px; }
.chip { display: inline-block; padding: 2px 8px; border-radius: 6px; margin: 2px 4px 2px 0; font-size: 13px; }
.chip.add { background: var(--add-bg); color: var(--add-fg); }
.chip.del { background: var(--del-bg); color: var(--del-fg); text-decoration: line-through; }
.scalar-old { background: var(--del-bg); color: var(--del-fg); padding: 2px 8px; border-radius: 6px; }
.scalar-new { background: var(--add-bg); color: var(--add-fg); padding: 2px 8px; border-radius: 6px; }
.arrow { color: var(--muted); margin: 0 8px; }
.bl-flag { color: var(--danger); font-weight: 600; }

.msg { padding: 10px 12px; border-radius: 8px; margin-bottom: 12px; }
.msg.err { background: var(--del-bg); color: var(--del-fg); }
.msg.warn { background: #fef6e7; color: #9a6700; }
.msg.info { background: #e8f0fe; color: #1d4ed8; }

.actions-bar { display: flex; gap: 10px; margin-top: 18px; }

.view-row { display: grid; grid-template-columns: 220px 1fr; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--border); }
.view-row .vk { color: var(--muted); font-weight: 600; }

.toast {
  position: fixed; right: 18px; bottom: 18px; z-index: 50;
  padding: 12px 16px; border-radius: 8px; color: #fff; max-width: 360px;
  box-shadow: 0 6px 20px rgba(0,0,0,.18);
}
.toast.ok { background: var(--ok); }
.toast.err { background: var(--danger); }

.muted { color: var(--muted); }

.rule-card {
  border: 1px solid #d6dbe1;
  border-radius: 6px;
  padding: 8px 10px;
  margin: 6px 0;
  background: #fafbfc;
}
.rule-head {
  font-weight: 600;
  margin-bottom: 4px;
}
.rule-line {
  margin: 2px 0;
  line-height: 1.8;
}
.rule-line .rk {
  display: inline-block;
  min-width: 90px;
  color: #5a636e;
  font-weight: 600;
}
.rule-card.add { border-color: var(--ok); background: #f2fbf5; }
.rule-card.del { border-color: var(--danger); background: #fdf3f3; }
.rule-card.mod { border-color: var(--primary); background: #f5f8ff; }
.chip.mod-tag { background: #e8f0fe; color: var(--primary-d); }

.rule-preview { margin-top: 8px; }
.rule-preview-title { color: var(--muted); font-size: 12px; font-weight: 600; margin: 4px 0; }

.subschema { margin-top: 8px; border: 1px solid var(--border); border-radius: 8px; padding: 6px 10px; background: #fafbfc; }
.subschema summary { cursor: pointer; color: var(--primary); font-size: 13px; }
.subschema-table { margin-top: 8px; }
.subschema-table th, .subschema-table td { padding: 5px 8px; font-size: 12.5px; vertical-align: top; }
.subschema-table code { background: #eef2f7; padding: 1px 5px; border-radius: 4px; }

.proglog {
  background: #0f172a;
  color: #e2e8f0;
  border-radius: 8px;
  padding: 12px;
  max-height: 320px;
  overflow: auto;
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: 12.5px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
  margin: 0;
}
.proglog .pl-go { color: #93c5fd; }
.proglog .pl-ok { color: #86efac; }
.proglog .pl-err { color: #fca5a5; font-weight: 600; }
.proglog .pl-info { color: #cbd5e1; }

.spin {
  display: inline-block;
  width: 12px; height: 12px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  vertical-align: -2px;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
