:root {
  --bg: #f0eee6;
  --surface: #ffffff;
  --surface-2: #faf9f5;
  --surface-3: #f5f3ec;
  --text: #1f1e1d;
  --muted: #73726c;
  --faint: #9b9990;
  --border: #e3dfd4;
  --border-strong: #d5d0c2;
  --accent: #d97757;
  --accent-ink: #b8552f;
  --accent-wash: #f7ece6;
  --good: #4a7c59;
  --warn: #b07d2b;
  --bad: #b3443a;
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, Helvetica, Arial, sans-serif;
  --serif: ui-serif, Georgia, Cambria, "Times New Roman", serif;
  --r: 10px;
  --r-lg: 14px;
  --sh: 0 1px 2px rgba(31, 30, 29, .05);
  --sh-2: 0 4px 16px rgba(31, 30, 29, .08);
}

html[data-theme="dark"] {
  --bg: #262624;
  --surface: #30302e;
  --surface-2: #2b2b29;
  --surface-3: #3a3a37;
  --text: #f5f4ef;
  --muted: #a5a39b;
  --faint: #7d7b74;
  --border: #3f3f3b;
  --border-strong: #4e4e49;
  --accent: #e0866a;
  --accent-ink: #f0a389;
  --accent-wash: #3a2f2a;
  --good: #7fae8c;
  --warn: #d6a75a;
  --bad: #e08a80;
  --sh: 0 1px 2px rgba(0, 0, 0, .25);
  --sh-2: 0 4px 18px rgba(0, 0, 0, .3);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent-ink); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3 { font-family: var(--serif); font-weight: 500; letter-spacing: -.01em; margin: 0; }
h1 { font-size: 30px; line-height: 1.2; }
h2 { font-size: 21px; }
h3 { font-size: 16px; font-family: var(--sans); font-weight: 600; }

code, pre, .mono { font-family: var(--mono); font-size: 13px; }

code:not(pre code) {
  background: var(--surface-3);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 1px 5px;
  font-size: 12.5px;
}

pre {
  margin: 0;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 13px 15px;
  overflow-x: auto;
  line-height: 1.55;
}

.hide { display: none !important; }

/* ---------- gate (login / setup) ---------- */

#gate {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 40px 20px;
}

.gate-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--sh-2);
  padding: 30px 28px 26px;
}

.brand { display: flex; align-items: center; gap: 10px; margin-bottom: 22px; }
.brand .glyph {
  width: 26px; height: 26px; flex: none;
  border-radius: 7px;
  background: var(--accent);
  display: grid; place-items: center;
  color: #fff; font-weight: 700; font-size: 14px;
  font-family: var(--serif);
}
.brand b { font-family: var(--serif); font-weight: 500; font-size: 17px; }

.gate-card h1 { font-size: 24px; margin-bottom: 6px; }
.gate-card .sub { color: var(--muted); font-size: 14px; margin-bottom: 22px; }

/* ---------- forms ---------- */

.field { margin-bottom: 14px; }
.field label {
  display: block;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 5px;
  letter-spacing: .01em;
}
.field .hint { font-size: 12px; color: var(--faint); margin-top: 5px; }

input[type=text], input[type=password], input[type=number], input[type=search], select, textarea {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  border-radius: var(--r);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
  padding: 9px 11px;
  transition: border-color .12s, box-shadow .12s;
}
textarea { font-family: var(--mono); font-size: 13px; resize: vertical; min-height: 96px; }

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-wash);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border: 1px solid transparent;
  border-radius: var(--r);
  background: var(--accent);
  color: #fff;
  font-family: var(--sans);
  font-size: 13.5px;
  font-weight: 550;
  padding: 8px 15px;
  cursor: pointer;
  transition: background .12s, border-color .12s, color .12s;
}
.btn:hover { background: var(--accent-ink); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.wide { width: 100%; }
.btn.ghost { background: transparent; border-color: var(--border-strong); color: var(--text); }
.btn.ghost:hover { background: var(--surface-3); }
.btn.danger { background: transparent; border-color: var(--border-strong); color: var(--bad); }
.btn.danger:hover { background: var(--surface-3); border-color: var(--bad); }
.btn.sm { padding: 5px 10px; font-size: 12.5px; }

.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.spacer { flex: 1; }

.toggle { display: flex; align-items: center; gap: 11px; padding: 11px 0; border-bottom: 1px solid var(--border); }
.toggle:last-child { border-bottom: 0; }
.toggle .tx { flex: 1; }
.toggle .tx b { font-weight: 600; font-size: 14px; display: block; }
.toggle .tx span { color: var(--muted); font-size: 12.5px; }

.sw { position: relative; width: 40px; height: 23px; flex: none; }
.sw input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.sw i {
  position: absolute; inset: 0;
  background: var(--border-strong);
  border-radius: 999px;
  transition: background .15s;
  pointer-events: none;
}
.sw i::after {
  content: "";
  position: absolute; top: 3px; left: 3px;
  width: 17px; height: 17px;
  background: #fff;
  border-radius: 50%;
  transition: transform .15s;
  box-shadow: 0 1px 2px rgba(0, 0, 0, .2);
}
.sw input:checked + i { background: var(--accent); }
.sw input:checked + i::after { transform: translateX(17px); }
.sw input:focus-visible + i { box-shadow: 0 0 0 3px var(--accent-wash); }

/* ---------- notices ---------- */

.notice {
  border-radius: var(--r);
  padding: 10px 13px;
  font-size: 13.5px;
  margin-bottom: 14px;
  border: 1px solid var(--border);
  background: var(--surface-2);
}
.notice.err { border-color: var(--bad); background: var(--surface-2); color: var(--bad); }
.notice.ok { border-color: var(--good); color: var(--good); }
.notice.warn { border-color: var(--warn); color: var(--warn); }

/* ---------- app shell ---------- */

#app { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }

#side {
  border-right: 1px solid var(--border);
  background: var(--surface-2);
  padding: 18px 12px 24px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}
#side .brand { padding: 0 8px; margin-bottom: 20px; }

.navgrp {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .07em;
  text-transform: uppercase;
  color: var(--faint);
  padding: 14px 9px 6px;
}
#side nav a {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 7px 9px;
  border-radius: 8px;
  color: var(--text);
  font-size: 14px;
  text-decoration: none;
  transition: background .1s;
}
#side nav a:hover { background: var(--surface-3); text-decoration: none; }
#side nav a.on { background: var(--accent-wash); color: var(--accent-ink); font-weight: 550; }
#side nav a .ic { width: 16px; height: 16px; flex: none; opacity: .75; }

#side .foot { margin-top: auto; padding: 14px 9px 0; border-top: 1px solid var(--border); }
#side .foot .who { font-size: 12.5px; color: var(--muted); margin-bottom: 9px; }

main { min-width: 0; padding: 30px 34px 60px; max-width: 1080px; }
.page-h { margin-bottom: 22px; }
.page-h .eyebrow {
  font-size: 11.5px; font-weight: 700; letter-spacing: .07em; text-transform: uppercase;
  color: var(--accent-ink); margin-bottom: 7px;
}
.page-h p { color: var(--muted); margin: 7px 0 0; font-size: 14px; max-width: 66ch; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 18px 20px;
  margin-bottom: 16px;
  box-shadow: var(--sh);
}
.card > h2, .card > h3 { margin-bottom: 12px; }
.card .cap { color: var(--muted); font-size: 13.5px; margin: -6px 0 14px; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 18px; }
.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 15px 17px;
}
.stat span { display: block; font-size: 12px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--faint); }
.stat b { display: block; font-family: var(--serif); font-size: 27px; font-weight: 500; margin-top: 4px; }
.stat .sub { font-size: 12px; color: var(--muted); font-family: var(--mono); }

/* ---------- tables ---------- */

.tw { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--r); }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th, td { text-align: left; padding: 9px 13px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { background: var(--surface-2); font-size: 11.5px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); }
tr:last-child td { border-bottom: 0; }
td.mono, th.mono { font-family: var(--mono); font-size: 12.5px; }
td.right, th.right { text-align: right; }
.empty { padding: 26px 14px; text-align: center; color: var(--faint); font-size: 13.5px; }

.pill {
  display: inline-block;
  font-size: 11.5px;
  font-weight: 650;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  background: var(--surface-2);
  color: var(--muted);
  font-family: var(--sans);
}
.pill.good { color: var(--good); border-color: var(--good); }
.pill.warn { color: var(--warn); border-color: var(--warn); }
.pill.bad { color: var(--bad); border-color: var(--bad); }
.pill.accent { color: var(--accent-ink); border-color: var(--accent); background: var(--accent-wash); }

.m { font-family: var(--mono); font-size: 11px; font-weight: 700; padding: 2px 6px; border-radius: 5px; letter-spacing: .03em; }
.m.get { background: #e8f0ea; color: #3d6b4c; }
.m.post { background: var(--accent-wash); color: var(--accent-ink); }
.m.put { background: #eceaf6; color: #56509b; }
.m.del { background: #f8e9e7; color: #a8443a; }
html[data-theme="dark"] .m.get { background: #2b3a30; color: #8fc09e; }
html[data-theme="dark"] .m.put { background: #322f45; color: #a8a2e0; }
html[data-theme="dark"] .m.del { background: #3d2b28; color: #e8988e; }

/* ---------- docs ---------- */

.ep { border: 1px solid var(--border); border-radius: var(--r-lg); background: var(--surface); margin-bottom: 14px; overflow: hidden; }
.ep-h { display: flex; align-items: center; gap: 10px; padding: 13px 17px; border-bottom: 1px solid var(--border); background: var(--surface-2); }
.ep-h .path { font-family: var(--mono); font-size: 13.5px; font-weight: 500; }
.ep-h .path .v { color: var(--muted); }
.ep-b { padding: 15px 17px 17px; }
.ep-b > p:first-child { margin-top: 0; }
.ep-b p { margin: 0 0 12px; font-size: 14px; }
.ep-b p:last-child { margin-bottom: 0; }

.prm { border-top: 1px solid var(--border); padding: 10px 0 9px; }
.prm:first-of-type { border-top: 0; }
.prm-h { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.prm-h .n { font-family: var(--mono); font-size: 13px; font-weight: 600; }
.prm-h .t { font-size: 11.5px; color: var(--muted); font-family: var(--mono); }
.prm-h .req { font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--accent-ink); }
.prm-h .opt { font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--faint); }
.prm-d { font-size: 13.5px; color: var(--muted); margin-top: 3px; }
.sub-t { font-size: 11.5px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--faint); margin: 16px 0 4px; }

.lua-grp { margin-bottom: 22px; }
.lua-grp > h3 { margin-bottom: 4px; }
.lua-grp > .cap { color: var(--muted); font-size: 13.5px; margin: 0 0 11px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  font-family: var(--mono);
  font-size: 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 3px 8px;
  color: var(--text);
}
.chip.hl { border-color: var(--accent); color: var(--accent-ink); background: var(--accent-wash); }

.logbox {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r);
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.5;
  padding: 12px 14px;
  max-height: 380px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
}
.logbox .e { color: var(--bad); }
.logbox .w { color: var(--warn); }

.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 14px; }

.secret {
  font-family: var(--mono);
  font-size: 13px;
  background: var(--accent-wash);
  border: 1px solid var(--accent);
  border-radius: var(--r);
  padding: 11px 13px;
  word-break: break-all;
  color: var(--accent-ink);
}

.iconbtn {
  background: transparent;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  width: 32px; height: 32px;
  display: grid; place-items: center;
  cursor: pointer;
  color: var(--muted);
}
.iconbtn:hover { background: var(--surface-3); color: var(--text); }

#toast {
  position: fixed;
  right: 20px; bottom: 20px;
  background: var(--text);
  color: var(--bg);
  border-radius: var(--r);
  padding: 10px 15px;
  font-size: 13.5px;
  box-shadow: var(--sh-2);
  opacity: 0;
  transform: translateY(8px);
  transition: opacity .18s, transform .18s;
  pointer-events: none;
  z-index: 50;
  max-width: 380px;
}
#toast.on { opacity: 1; transform: none; }

@media (max-width: 860px) {
  #app { grid-template-columns: 1fr; }
  #side { position: static; height: auto; border-right: 0; border-bottom: 1px solid var(--border); }
  main { padding: 22px 18px 50px; }
}
