:root {
  --bg: #f4f5f7; --card: #ffffff; --text: #191c20; --muted: #697077;
  --accent: #b91c1c; --accent-soft: #fdeaea; --gold: #d4a017;
  --border: #e3e5e9; --tag: #eef0f3; --shadow: 0 1px 3px rgba(0,0,0,.06);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1116; --card: #181c22; --text: #e8eaed; --muted: #969ca6;
    --accent: #ef4444; --accent-soft: #3a1518; --gold: #eab308;
    --border: #262b33; --tag: #232932; --shadow: 0 1px 3px rgba(0,0,0,.35);
  }
}
* { box-sizing: border-box; }
html { scrollbar-gutter: stable; }
body { margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.55 system-ui, -apple-system, "Segoe UI", sans-serif; }
.wrap { max-width: 760px; margin: 0 auto; padding: 20px 16px 80px; }

/* ---------- controls ---------- */
button { border-radius: 9px; padding: 7px 14px; cursor: pointer; font-size: 13.5px;
  border: 1px solid var(--border); background: var(--card); color: var(--text);
  transition: border-color .15s, background .15s; }
button:hover { border-color: var(--gold); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
button.primary:hover { filter: brightness(1.08); }
button.ghost { border-color: transparent; background: transparent; color: var(--muted); }
button.danger { color: var(--accent); }
input, textarea, select { width: 100%; padding: 9px 12px; border: 1px solid var(--border);
  border-radius: 9px; background: var(--card); color: var(--text); font-size: 14px; font-family: inherit; }
input:focus, textarea:focus, select:focus { outline: 2px solid var(--gold); outline-offset: -1px; border-color: transparent; }
textarea { min-height: 150px; resize: vertical; font-family: ui-monospace, monospace; font-size: 13.5px; }
label { display: block; font-size: 12px; color: var(--muted); margin: 12px 0 4px; font-weight: 500; }

/* ---------- login ---------- */
#login { min-height: 100dvh; display: none; align-items: center; justify-content: center; padding: 16px; }
#login.show { display: flex; }
.logincard { background: var(--card); border: 1px solid var(--border); border-radius: 16px;
  box-shadow: var(--shadow); padding: 32px 28px; width: 100%; max-width: 360px; }
.logincard h1 { margin: 0 0 4px; font-size: 24px; display: flex; align-items: center; gap: 10px; }
.logincard .sub { color: var(--muted); font-size: 13px; margin-bottom: 18px; }
.logincard button { width: 100%; margin-top: 18px; padding: 10px; font-size: 15px; }
.loginerr { color: var(--accent); font-size: 13px; margin-top: 12px; min-height: 18px; }

/* ---------- header ---------- */
#app { display: none; }
#app.show { display: block; }
header { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 9px; font-size: 20px; font-weight: 700; margin-right: auto; }
.dot { width: 13px; height: 13px; border-radius: 50%; background: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft), 0 0 10px var(--accent); }
#tenantSel { width: auto; min-width: 130px; padding: 7px 10px; font-weight: 600; }
.searchrow { display: flex; gap: 10px; margin-bottom: 20px; }
#q { padding: 11px 15px; border-radius: 11px; font-size: 15px; box-shadow: var(--shadow); }

/* ---------- panels ---------- */
.panel { background: var(--card); border: 1px solid var(--border); border-radius: 14px;
  box-shadow: var(--shadow); padding: 18px; margin-bottom: 18px; display: none; }
.panel.open { display: block; }
.panel h2 { margin: 0 0 6px; font-size: 15px; }
.panel .row { display: flex; gap: 10px; }
.panel .row > div { flex: 1; }
#editor { border-color: var(--gold); }
.panelactions { display: flex; gap: 8px; margin-top: 16px; align-items: center; }
.hint { font-size: 12px; color: var(--muted); }

/* ---------- tiptap editor ---------- */
.toolbar { display: none; gap: 4px; flex-wrap: wrap; margin-bottom: 6px; }
.toolbar.on { display: flex; }
.toolbar button { padding: 3px 9px; font-size: 12.5px; font-family: ui-monospace, monospace; }
.tiptap { display: none; border: 1px solid var(--border); border-radius: 9px;
  background: var(--card); padding: 4px 12px; min-height: 150px; cursor: text; }
.tiptap.on { display: block; }
.tiptap:focus-within { outline: 2px solid var(--gold); outline-offset: -1px; }
.tiptap .ProseMirror { outline: none; min-height: 140px; }
.tiptap .ProseMirror > :first-child { margin-top: 8px; }

/* ---------- tenants ---------- */
.trow { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--border); }
.trow:last-of-type { border-bottom: none; }
.trow .slug { font-family: ui-monospace, monospace; font-size: 13.5px; min-width: 110px; }
.trow .tname { color: var(--muted); flex: 1; font-size: 14px; }
.trow .lockmark { font-size: 12px; }
.trow button { padding: 3px 9px; font-size: 12.5px; }
.taddrow { display: flex; gap: 8px; margin-top: 12px; }

/* ---------- entries ---------- */
.datehead { color: var(--muted); font-size: 12px; font-weight: 600; text-transform: uppercase;
  letter-spacing: .06em; margin: 22px 4px 8px; }
.card { background: var(--card); border: 1px solid var(--border); border-radius: 13px;
  box-shadow: var(--shadow); padding: 13px 16px; margin-bottom: 8px; transition: border-color .15s; }
.card:hover { border-color: var(--gold); }
.card .top { display: flex; align-items: baseline; gap: 9px; cursor: pointer; }
.card .id { color: var(--muted); font-size: 11.5px; font-family: ui-monospace, monospace; }
.card .title { font-weight: 600; flex: 1; }
.tags { margin-top: 6px; display: flex; gap: 6px; flex-wrap: wrap; }
.tag { background: var(--tag); border-radius: 6px; padding: 1px 9px; font-size: 12px; color: var(--muted); }
.content { display: none; margin-top: 11px; padding-top: 11px; border-top: 1px solid var(--border); }
.card.open .content { display: block; }
.cardactions { display: flex; gap: 8px; margin-top: 13px; }
.cardactions button { padding: 4px 11px; font-size: 12.5px; }
.status { color: var(--muted); font-size: 13.5px; margin: 32px 0; text-align: center; }
.err { color: var(--accent); }

/* ---------- markdown content ---------- */
.md { word-break: break-word; }
.md.pre { white-space: pre-wrap; }
.md h1, .md h2, .md h3 { margin: 14px 0 6px; line-height: 1.3; }
.md h1 { font-size: 19px; } .md h2 { font-size: 17px; } .md h3 { font-size: 15.5px; }
.md p { margin: 7px 0; }
.md ul, .md ol { margin: 7px 0; padding-left: 24px; }
.md li { margin: 2px 0; }
.md code { background: var(--tag); border-radius: 5px; padding: 1px 5px;
  font: 12.5px ui-monospace, monospace; }
.md pre { background: var(--tag); border-radius: 9px; padding: 10px 12px; overflow-x: auto; }
.md pre code { background: none; padding: 0; }
.md blockquote { margin: 8px 0; padding: 2px 14px; border-left: 3px solid var(--gold); color: var(--muted); }
.md hr { border: none; border-top: 1px solid var(--border); margin: 14px 0; }
.md a { color: var(--accent); }
.md img { max-width: 100%; }

/* ---------- toast ---------- */
#toast { position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%) translateY(20px);
  background: var(--text); color: var(--bg); padding: 9px 18px; border-radius: 10px;
  font-size: 13.5px; opacity: 0; pointer-events: none; transition: opacity .25s, transform .25s; z-index: 10; }
#toast.show { opacity: .95; transform: translateX(-50%) translateY(0); }
