:root {
  --paper: #f3f2ee;
  --card: #ffffff;
  --ink: #17191d;
  --muted: #6c6e73;
  --line: #dddbd4;
  --line-soft: #ebe9e3;
  --accent: #1c2f57;      /* fountain-pen ink */
  --accent-soft: #e6eaf3;
  --ok: #1f6b45;
  --ok-soft: #e3f1e8;
  --bad: #a3271f;
  --bad-soft: #f8e5e2;
  --r: 6px;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--paper); color: var(--ink);
  font: 14px/1.5 "IBM Plex Sans", system-ui, sans-serif;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code, .mono { font-family: "IBM Plex Mono", ui-monospace, monospace; font-size: .92em; }
code { background: var(--line-soft); padding: 1px 5px; border-radius: 4px; }
h1 { font-size: 22px; font-weight: 600; letter-spacing: -.015em; margin: 0; text-wrap: balance; }
h2 { font-size: 15px; font-weight: 600; margin: 32px 0 10px; }
h3 { font-size: 15px; font-weight: 600; margin: 0 0 4px; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.nowrap { white-space: nowrap; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* header */
.top {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 0 24px; height: 52px; background: var(--card); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 5;
}
.brand { display: flex; align-items: center; gap: 9px; font-weight: 600; color: var(--ink); letter-spacing: -.01em; }
.brand:hover { text-decoration: none; }
.nib { width: 18px; height: 18px; border-radius: 50% 50% 50% 0; background: var(--accent); transform: rotate(-45deg); flex: none; }
.top nav { display: flex; align-items: center; gap: 4px; }
.top nav a, .top nav .link { padding: 6px 10px; border-radius: var(--r); color: var(--muted); }
.top nav a.on { color: var(--ink); background: var(--line-soft); }
.top nav a:hover { text-decoration: none; color: var(--ink); }
.top form { margin: 0; }

.wrap { max-width: 1040px; margin: 0 auto; padding: 28px 24px 64px; }
.wrap.wide { max-width: 1320px; }
.head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 18px; }
.crumb { font-size: 12.5px; color: var(--muted); display: inline-block; margin-bottom: 2px; }
.stats { display: flex; gap: 16px; flex-wrap: wrap; font-size: 13px; }
.stats b { font-weight: 600; font-variant-numeric: tabular-nums; }
.stats .bad b { color: var(--bad); }

/* flash */
.flash { padding: 9px 12px; border-radius: var(--r); margin-bottom: 14px; border: 1px solid; }
.flash.ok { background: var(--ok-soft); border-color: #bcdcc8; color: var(--ok); }
.flash.err { background: var(--bad-soft); border-color: #eab9b3; color: var(--bad); }

/* buttons + inputs */
.btn {
  display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 14px;
  border: 1px solid var(--line); border-radius: var(--r); background: var(--card); color: var(--ink);
  font: inherit; font-weight: 500; cursor: pointer; white-space: nowrap;
}
.btn:hover { border-color: #c4c1b8; text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: #142343; }
.btn.danger { background: var(--bad); border-color: var(--bad); color: #fff; }
.link { background: none; border: 0; padding: 0; font: inherit; color: var(--accent); cursor: pointer; }
.link.danger { color: var(--bad); }
input:not([type=checkbox]):not([type=file]), select, textarea {
  width: 100%; height: 36px; padding: 0 10px; border: 1px solid var(--line); border-radius: var(--r);
  background: var(--card); color: var(--ink); font: inherit;
}
textarea { height: auto; padding: 8px 10px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

/* tables */
.table-wrap { overflow-x: auto; background: var(--card); border: 1px solid var(--line); border-radius: 8px; }
table.list { width: 100%; border-collapse: collapse; }
.list th { text-align: left; font-weight: 500; font-size: 12px; color: var(--muted); padding: 9px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.list td { padding: 9px 12px; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
.list tr:last-child td { border-bottom: 0; }
.list .rowlink { cursor: pointer; }
.list .rowlink:hover td { background: #faf9f6; }
.list tr.off td { opacity: .55; }
.list .empty { text-align: center; color: var(--muted); padding: 26px; }
.list a { color: var(--ink); }
.logs td { font-size: 13px; }
.clip { max-width: 260px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tag { display: inline-block; font-size: 11.5px; font-weight: 500; padding: 1px 8px; border-radius: 99px; background: var(--line-soft); color: var(--muted); white-space: nowrap; }
.tag.signed { background: var(--ok-soft); color: var(--ok); }
.tag.error { background: var(--bad-soft); color: var(--bad); }
.count { font-size: 11.5px; color: var(--muted); font-variant-numeric: tabular-nums; }

.avatar-cell { width: 44px; padding-right: 0 !important; }
.avatar { width: 30px; height: 30px; border-radius: 50%; object-fit: cover; display: block; }
.avatar.ph { display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); font-weight: 600; font-size: 13px; }
.avatar.lg { width: 56px; height: 56px; }

.inline-add { display: flex; gap: 8px; margin-top: 12px; }
.inline-add input { max-width: 240px; }

/* tabs */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 18px; overflow-x: auto; }
.tabs a { padding: 8px 12px; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tabs a.on { color: var(--ink); border-color: var(--accent); font-weight: 500; }
.tabs a:hover { text-decoration: none; color: var(--ink); }
.bar { display: flex; gap: 8px; align-items: flex-start; margin-bottom: 12px; flex-wrap: wrap; }
.bulk { flex: 1; }
.bulk summary { list-style: none; }
.bulk summary::-webkit-details-marker { display: none; }
.bulk[open] form { margin-top: 8px; background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 12px; display: grid; gap: 8px; }
.bulk p { margin: 0; }

/* forms */
.form { display: grid; gap: 14px; align-content: start; }
.form.narrow { max-width: 520px; }
.form label, .field { display: grid; gap: 5px; font-size: 13px; font-weight: 500; }
.field > span { font-weight: 500; }
.form small { font-weight: 400; }
label.check, .ed-left label.check, .form label.check { display: flex; align-items: center; gap: 8px; font-weight: 400; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.suffix { display: flex; }
.suffix input { border-top-right-radius: 0; border-bottom-right-radius: 0; }
.suffix span { display: flex; align-items: center; padding: 0 10px; border: 1px solid var(--line); border-left: 0; border-radius: 0 var(--r) var(--r) 0; background: var(--line-soft); color: var(--muted); white-space: nowrap; font-weight: 400; }
.upload { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; font-weight: 400; }
.logo-prev { max-height: 48px; max-width: 140px; }
.actions { display: flex; align-items: center; gap: 12px; }
.danger-zone { margin-top: 40px; padding-top: 18px; border-top: 1px solid var(--line); display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.danger-zone p { flex-basis: 100%; margin: 0 0 4px; color: var(--muted); }
.danger-zone input { max-width: 240px; }

/* person page */
.split { display: grid; grid-template-columns: minmax(0, 420px) minmax(0, 1fr); gap: 36px; align-items: start; }
.split aside { position: sticky; top: 76px; }
.del { margin-top: 12px; text-align: right; }

/* mail card: the preview looks like a received message */
.mail-card { background: var(--card); border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.mail-meta { padding: 10px 16px; border-bottom: 1px solid var(--line-soft); font-size: 13px; }
.mail-body { padding: 16px 18px 20px; color: #222; }
.mail-body > p { margin: 0 0 10px; }
.mail-body .sig, .mail-body iframe { margin-top: 18px; }
.mail-body iframe { width: 100%; border: 0; display: block; min-height: 110px; }
.mail-body pre { margin: 18px 0 0; font: 13px/1.5 "IBM Plex Mono", monospace; white-space: pre-wrap; }

/* template cards */
.tpl-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; }
.tpl-card { background: var(--card); border: 1px solid var(--line); border-radius: 8px; overflow: hidden; color: var(--ink); display: block; }
.tpl-card:hover { border-color: #c4c1b8; text-decoration: none; }
.tpl-name { display: flex; gap: 8px; align-items: center; padding: 10px 14px; border-bottom: 1px solid var(--line-soft); flex-wrap: wrap; }
.tpl-thumb { width: 100%; height: 150px; border: 0; pointer-events: none; display: block; }

/* editor */
.editor { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 24px; align-items: start; }
.ed-left { display: grid; gap: 12px; }
.ed-left label { display: grid; gap: 5px; font-size: 13px; font-weight: 500; }
.checks { display: grid; gap: 4px; align-content: end; padding-bottom: 4px; }
textarea.code { min-height: 440px; font-size: 12.5px; line-height: 1.55; tab-size: 2; white-space: pre; }
.ed-right { position: sticky; top: 76px; display: grid; gap: 10px; }
.pv-bar { display: flex; gap: 10px; align-items: center; }
.pv-bar select { width: auto; flex: 1; max-width: 260px; height: 32px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; margin-left: auto; }
.seg button { border: 0; background: var(--card); padding: 5px 10px; font: inherit; font-size: 12.5px; cursor: pointer; color: var(--muted); }
.seg button.on { background: var(--accent-soft); color: var(--accent); font-weight: 500; }
.vars { font-size: 13px; }
.vars summary { cursor: pointer; color: var(--accent); }
.vars table { margin-top: 8px; border-collapse: collapse; }
.vars td { padding: 2px 14px 2px 0; }

/* guide */
.guide { max-width: 760px; }
.guide ol { padding-left: 20px; display: grid; gap: 22px; margin: 18px 0 0; }
.guide li::marker { font-weight: 600; color: var(--accent); }
.guide p { margin: 4px 0; }
.guide dl { display: grid; grid-template-columns: 170px 1fr; gap: 6px 14px; margin: 10px 0 0; background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 12px 14px; }
.guide dt { color: var(--muted); }
.guide dd { margin: 0; }

.search input { width: 260px; }

/* login */
main.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 340px; background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 26px; display: grid; gap: 14px; }
.login-card .brand { margin-bottom: 6px; font-size: 16px; }
.login-card label { display: grid; gap: 5px; font-size: 13px; font-weight: 500; }
.login-card .btn { justify-content: center; height: 38px; }

@media (max-width: 860px) {
  .split, .editor { grid-template-columns: 1fr; }
  .split aside, .ed-right { position: static; }
  textarea.code { min-height: 300px; }
}
@media (max-width: 560px) {
  .wrap { padding: 20px 16px 48px; }
  .top { padding: 0 12px; }
  .top nav a, .top nav .link { padding: 6px 7px; }
  .row2 { grid-template-columns: 1fr; }
  .inline-add { flex-direction: column; }
  .inline-add input { max-width: none; }
  .guide dl { grid-template-columns: 1fr; gap: 2px; }
  .guide dd { margin-bottom: 8px; }
  .search input { width: 100%; }
}
