:root {
  --paper: #f3f0e8;
  --panel: #faf8f3;
  --ink: #1d1c1a;
  --muted: #706a5e;
  --line: #d8d2c3;
  --line-strong: #b5ad9a;
  --accent: #b4451f;
  --ok: #2e6b44;
  --warn: #91650a;
  --bad: #a3281f;
  --mono: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --sans: "IBM Plex Sans", "Segoe UI", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 14px/1.5 var(--sans);
}
h1, h2, h3, p { margin: 0; }
a { color: inherit; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.mono { font-family: var(--mono); }

/* ---------- layout ---------- */
.shell { display: grid; grid-template-columns: 216px minmax(0, 1fr); min-height: 100vh; }
aside {
  border-right: 1px solid var(--line-strong);
  padding: 22px 0 18px;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand { font: 500 15px var(--mono); padding: 0 22px 22px; letter-spacing: -0.01em; }
.brand i { font-style: normal; color: var(--accent); }
nav { display: flex; flex-direction: column; }
nav a {
  text-decoration: none;
  padding: 7px 22px;
  border-left: 3px solid transparent;
  color: var(--muted);
}
nav a:hover { color: var(--ink); background: rgba(0, 0, 0, 0.03); }
nav a.on { color: var(--ink); font-weight: 600; border-left-color: var(--ink); }
.side-foot { margin-top: auto; padding: 0 22px; font-size: 12.5px; color: var(--muted); }
.side-foot .row { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; color: var(--ink); }
.side-foot button { padding: 0; border: 0; background: none; font: inherit; color: var(--muted); text-decoration: underline; cursor: pointer; }

main { padding: 26px 38px 60px; max-width: 1140px; width: 100%; }
.head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.head h1 { font: 600 22px/1.2 var(--sans); letter-spacing: -0.015em; }
.head .acts { display: flex; gap: 8px; flex-wrap: wrap; }
h2 { font: 600 14px var(--sans); margin-bottom: 4px; }
.sub { color: var(--muted); font-size: 13px; margin-bottom: 14px; max-width: 60ch; }

.dot { display: inline-block; width: 8px; height: 8px; background: var(--line-strong); flex: none; }
.dot.ok { background: var(--ok); }
.dot.wait { background: var(--warn); }
.dot.bad { background: var(--bad); }

/* ---------- controls ---------- */
.btn {
  font: inherit;
  padding: 6px 13px;
  border: 1px solid var(--ink);
  background: transparent;
  color: var(--ink);
  border-radius: 2px;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { background: rgba(0, 0, 0, 0.05); }
.btn.primary { background: var(--ink); color: var(--paper); }
.btn.primary:hover { background: #3a3733; }
.btn.danger { border-color: var(--bad); color: var(--bad); }
.btn.danger:hover { background: rgba(163, 40, 31, 0.07); }
.btn.sm { padding: 2px 8px; font-size: 12.5px; }
.btn:disabled { opacity: 0.45; cursor: default; }
.lnk { background: none; border: 0; padding: 0; font: inherit; color: var(--ink); text-decoration: underline; text-underline-offset: 2px; cursor: pointer; }
.lnk.bad { color: var(--bad); }
.lnk + .lnk { margin-left: 12px; }

input[type=text], input[type=password], input[type=number], input[type=search], select, textarea {
  font: inherit;
  width: 100%;
  padding: 6px 9px;
  border: 1px solid var(--line-strong);
  background: var(--panel);
  color: var(--ink);
  border-radius: 2px;
}
textarea { resize: vertical; min-height: 70px; }
input:focus, select:focus, textarea:focus, .btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
input[type=checkbox], input[type=radio] { accent-color: var(--ink); width: 15px; height: 15px; margin: 0; }

.field { margin-bottom: 14px; }
.field > label { display: block; font-size: 13px; margin-bottom: 4px; }
.field .hint { font-size: 12.5px; color: var(--muted); margin-top: 3px; }
.check { display: flex; align-items: flex-start; gap: 9px; margin-bottom: 10px; font-size: 13.5px; cursor: pointer; }
.check small { display: block; color: var(--muted); font-size: 12.5px; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }

/* ---------- blocks ---------- */
.strip { display: flex; flex-wrap: wrap; border-top: 1px solid var(--ink); border-bottom: 1px solid var(--line); margin-bottom: 30px; }
.strip > div { padding: 12px 22px 12px 0; margin-right: 22px; min-width: 130px; }
.strip dt { font-size: 12.5px; color: var(--muted); }
.strip dd { margin: 0; font: 500 21px/1.3 var(--mono); letter-spacing: -0.02em; }
.strip dd small { font-size: 12px; color: var(--muted); letter-spacing: 0; }

.cols { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 0 48px; align-items: start; }
.sect { border-top: 1px solid var(--ink); padding-top: 12px; margin-bottom: 34px; }

.tablewrap { overflow-x: auto; border-top: 1px solid var(--ink); }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th { text-align: left; font-weight: 500; font-size: 12.5px; color: var(--muted); padding: 8px 10px; border-bottom: 1px solid var(--line-strong); white-space: nowrap; }
td { padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
tbody tr:hover { background: rgba(0, 0, 0, 0.025); }
th.num, td.num { text-align: right; font-family: var(--mono); font-size: 13px; white-space: nowrap; }
td.code { font-family: var(--mono); font-size: 13px; white-space: nowrap; }
td .orig { display: block; font-size: 12px; color: var(--muted); }
td.act { white-space: nowrap; text-align: right; }
.empty { padding: 28px 10px; color: var(--muted); }
.tag { font-size: 12.5px; white-space: nowrap; }
.tag.ok { color: var(--ok); }
.tag.bad { color: var(--bad); }
.tag.wait { color: var(--warn); }
.tag.off { color: var(--muted); }

.toolbar { display: flex; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; align-items: center; }
.toolbar input[type=search] { width: 260px; }
.toolbar select { width: auto; min-width: 150px; }
.toolbar .grow { flex: 1; }
.bulk { display: flex; gap: 10px; align-items: center; padding: 8px 10px; background: var(--ink); color: var(--paper); margin-bottom: 0; font-size: 13px; }
.bulk .lnk { color: var(--paper); }
.pager { display: flex; justify-content: space-between; align-items: center; padding: 12px 0; font-size: 13px; color: var(--muted); }
.pager div { display: flex; gap: 8px; }

.qrbox { border: 1px solid var(--ink); background: #fff; width: 296px; height: 296px; display: grid; place-items: center; margin: 14px 0; }
.qrbox img { width: 280px; height: 280px; display: block; }
.paircode { font: 500 30px var(--mono); letter-spacing: 0.08em; border: 1px solid var(--ink); background: #fff; padding: 14px 18px; display: inline-block; margin: 12px 0; }
.statusline { display: flex; align-items: center; gap: 9px; font-size: 15px; font-weight: 500; }
.kv { display: grid; grid-template-columns: 90px 1fr; gap: 3px 12px; font-size: 13.5px; margin: 10px 0 16px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-family: var(--mono); font-size: 13px; }
.steps { margin: 8px 0 0; padding-left: 18px; color: var(--muted); font-size: 13px; }
.errbox { border-left: 3px solid var(--bad); padding: 6px 10px; background: rgba(163, 40, 31, 0.06); margin: 10px 0; font-size: 13px; }
.log { font: 12.5px/1.6 var(--mono); border: 1px solid var(--line-strong); background: var(--panel); padding: 8px 12px; max-height: 190px; overflow: auto; }
.log div { white-space: pre-wrap; }
.log span { color: var(--muted); margin-right: 8px; }
.radiorow { display: flex; gap: 20px; margin-bottom: 12px; }
.radiorow label { display: flex; gap: 7px; align-items: center; cursor: pointer; }

/* ---------- dialog & toast ---------- */
dialog { border: 1px solid var(--ink); background: var(--paper); color: var(--ink); padding: 0; width: min(460px, calc(100vw - 28px)); border-radius: 2px; box-shadow: 6px 6px 0 rgba(0, 0, 0, 0.12); }
dialog::backdrop { background: rgba(29, 28, 26, 0.35); }
dialog form { padding: 20px 22px 18px; }
dialog h2 { font-size: 16px; margin-bottom: 14px; }
dialog .foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }

#toast {
  position: fixed;
  left: 22px;
  bottom: 22px;
  max-width: min(420px, calc(100vw - 44px));
  background: var(--ink);
  color: var(--paper);
  padding: 9px 14px;
  font-size: 13px;
  border-left: 4px solid var(--ok);
  opacity: 0;
  transform: translateY(6px);
  transition: opacity 0.15s, transform 0.15s;
  pointer-events: none;
  z-index: 50;
}
#toast.show { opacity: 1; transform: none; }
#toast.err { border-left-color: var(--accent); }

/* ---------- auth ---------- */
.auth { padding: 13vh 7vw; display: grid; grid-template-columns: minmax(0, 340px) minmax(0, 1fr); gap: 7vw; align-items: start; }
.auth .brand { padding: 0 0 26px; font-size: 17px; }
.auth h1 { font: 600 20px var(--sans); margin-bottom: 4px; }
.auth form { border-top: 1px solid var(--ink); padding-top: 18px; }
.auth .side { color: var(--muted); max-width: 42ch; padding-top: 62px; font-size: 13.5px; }
.auth .err { color: var(--bad); font-size: 13px; min-height: 20px; margin-bottom: 8px; }

/* ---------- responsive ---------- */
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  aside { position: static; height: auto; padding: 12px 0 0; border-right: 0; border-bottom: 1px solid var(--line-strong); }
  .brand { padding: 0 16px 8px; }
  nav { flex-direction: row; overflow-x: auto; }
  nav a { border-left: 0; border-bottom: 3px solid transparent; padding: 8px 14px; white-space: nowrap; }
  nav a.on { border-bottom-color: var(--ink); }
  .side-foot { display: none; }
  main { padding: 20px 16px 50px; }
  .cols, .two { grid-template-columns: 1fr; }
  .auth { grid-template-columns: 1fr; padding: 8vh 20px; }
  .auth .side { padding-top: 0; }
  .toolbar input[type=search] { width: 100%; }
}
