:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --border: #dfe4ee;
  --text: #1c2433;
  --muted: #6b7488;
  --primary: #2f6fed;
  --primary-dark: #2457c4;
  --danger: #d64545;
  --ok: #1f9d61;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(16, 24, 40, 0.08), 0 4px 14px rgba(16, 24, 40, 0.06);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}

h1, h2, h3 { margin: 0 0 10px; }
h2 { font-size: 18px; }
h3 { font-size: 15px; margin-top: 18px; }
p { margin: 6px 0; }
.muted { color: var(--muted); }
.note { margin-top: 14px; font-size: 12px; }
.error { color: var(--danger); }
code { background: #eef1f7; padding: 1px 5px; border-radius: 4px; }

/* Login */
.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 20px;
}
.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 28px 32px;
  width: 340px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.login-card h1 { font-size: 20px; margin-bottom: 0; }

/* Forms */
label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); font-weight: 500; }
input, select, textarea {
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  width: 100%;
}
textarea { resize: vertical; font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 12px; }
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(47, 111, 237, 0.35); border-color: var(--primary); }

button {
  font: inherit;
  font-weight: 600;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 8px;
  padding: 8px 14px;
  cursor: pointer;
}
button:hover { border-color: #c6cddb; }
button.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
button.primary:hover { background: var(--primary-dark); }
button.ghost { background: transparent; }
button.danger { color: var(--danger); border-color: rgba(214, 69, 69, 0.4); }
button:disabled { opacity: 0.5; cursor: not-allowed; }

/* Top bar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.topbar-title { display: flex; flex-direction: column; gap: 2px; }
.conn { font-size: 12px; color: var(--muted); }
.conn.ok { color: var(--ok); }
.conn.bad { color: var(--danger); }
.topbar-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.publish-note { width: 200px; padding: 7px 10px; font-size: 13px; }

/* Tabs */
.tabs {
  display: flex;
  gap: 4px;
  padding: 10px 20px 0;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
}
.tab {
  border: none;
  border-bottom: 2px solid transparent;
  border-radius: 8px 8px 0 0;
  background: transparent;
  color: var(--muted);
  padding: 9px 14px;
  white-space: nowrap;
}
.tab:hover { color: var(--text); background: #f1f4fa; }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 700; }

main { max-width: 980px; margin: 0 auto; padding: 20px; }
.pane { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 20px; box-shadow: var(--shadow); }
.pane-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.toolbar-right { display: flex; gap: 8px; align-items: center; }
.toolbar-right select { width: auto; min-width: 160px; }

/* Stats */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; margin-bottom: 6px; }
.stat {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}
.stat span { font-size: 26px; font-weight: 700; color: var(--primary); }
.stat small { color: var(--muted); }

.check { flex-direction: row; align-items: center; gap: 8px; margin: 8px 0; color: var(--text); font-weight: 500; }
.check input { width: auto; }

/* Tables */
.table { width: 100%; border-collapse: collapse; margin-top: 8px; }
.table th, .table td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table th { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.03em; }
.table tr:last-child td { border-bottom: none; }
.table .actions { display: flex; gap: 6px; justify-content: flex-end; }
.table .actions button { padding: 5px 10px; font-size: 12px; }
.empty { color: var(--muted); text-align: center; padding: 24px; }

/* Toast */
.toast {
  position: fixed;
  top: 74px;
  left: 50%;
  transform: translateX(-50%);
  background: #182030;
  color: #fff;
  padding: 10px 18px;
  border-radius: 8px;
  z-index: 50;
  box-shadow: var(--shadow);
}

/* Modals */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 20, 35, 0.45);
  display: grid;
  place-items: center;
  z-index: 40;
  padding: 20px;
}
.modal {
  background: var(--surface);
  border-radius: 12px;
  width: 640px;
  max-width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  padding: 20px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.25);
}
.modal-sm { width: 380px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.modal-head h3 { margin: 0; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.modal-actions { display: flex; gap: 8px; margin-top: 16px; align-items: center; }
.spacer { flex: 1; }
.career { margin-top: 12px; }
.career-row { display: flex; gap: 8px; margin-bottom: 8px; align-items: center; }
.career-row input:first-child { width: 120px; flex-shrink: 0; }
.career-row button { flex-shrink: 0; }

/* History notes + diff preview */
.note-input { width: 100%; min-width: 170px; padding: 5px 8px; font-size: 12px; }
.diff { margin: 10px 0 4px; padding-left: 20px; }
.diff li { margin: 5px 0; color: var(--text); }
.diff b { color: var(--text); }

/* Raw JSON */
#json-editor { width: 100%; min-height: 60vh; font-family: ui-monospace, SFMono-Regular, Consolas, monospace; }

@media (max-width: 640px) {
  .grid-2 { grid-template-columns: 1fr; }
  main { padding: 12px; }
  .topbar { flex-wrap: wrap; }
}
