:root {
  --bg: #f3f1ec;
  --ink: #1b2430;
  --muted: #5d6a7c;
  --line: #e2ddd3;
  --card: #fffdf8;
  --accent: #1b3a4b;
  --gold: #c4842e;
  --ok: #2f7d57;
  --danger: #b44545;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--ink);
  display: flex;
}
aside {
  width: 240px;
  background: var(--accent);
  color: #e8e4d9;
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}
.brand { display: flex; gap: 10px; align-items: center; }
.brand span { display: block; color: #b7c6ce; font-size: 12px; }
.mark {
  width: 40px; height: 40px; border-radius: 12px;
  background: #122a36; color: #e8a54b;
  display: grid; place-items: center; font-weight: 800;
}
nav { display: flex; flex-direction: column; gap: 6px; }
nav button, .aside-foot button {
  background: transparent; border: 0; color: inherit;
  text-align: left; padding: 10px 12px; border-radius: 10px; cursor: pointer; font: inherit;
}
nav button.active, nav button:hover { background: #122a36; }
.aside-foot { margin-top: auto; display: flex; justify-content: space-between; align-items: center; }
.aside-foot a { color: #d7ecec; }
main { flex: 1; overflow: auto; padding: 28px; }
header { display: flex; justify-content: space-between; align-items: end; margin-bottom: 22px; }
h1 { margin: 0; font-size: 32px; }
.who { color: var(--muted); }
.cards { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 18px; }
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 16px 18px;
}
.card .k { color: var(--muted); font-size: 13px; }
.card .v { font-size: 26px; font-weight: 700; margin-top: 6px; }
.panel {
  background: var(--card); border: 1px solid var(--line); border-radius: 18px; padding: 18px;
  margin-bottom: 16px;
}
.grid2 { display: grid; grid-template-columns: 1.4fr 1fr; gap: 16px; }
h2 { margin: 0 0 12px; font-size: 18px; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.row-between { display: flex; justify-content: space-between; align-items: center; }
.row { display: flex; gap: 16px; flex-wrap: wrap; margin: 12px 0; }
.primary {
  background: var(--accent); color: white; border: 0; border-radius: 10px;
  padding: 9px 14px; cursor: pointer; font: inherit;
}
button.link, .linkish {
  background: none; border: 0; color: var(--accent); cursor: pointer; font: inherit;
}
.hint { color: var(--muted); margin-top: 0; }
.ok { color: var(--ok); }
.error { color: var(--danger); }
.pill {
  display: inline-block; padding: 3px 8px; border-radius: 999px; font-size: 12px;
  background: #ece7dc;
}
.pill.on { background: #d7eee0; color: var(--ok); }
.pill.off { background: #f3d9d9; color: var(--danger); }
dialog { border: 1px solid var(--line); border-radius: 16px; padding: 20px; width: min(420px, 92vw); }
dialog label { display: block; margin: 10px 0; font-size: 14px; }
dialog input, dialog select, textarea {
  width: 100%; margin-top: 4px; padding: 9px 10px; border-radius: 10px;
  border: 1px solid var(--line); font: inherit;
}
textarea { min-height: 180px; }
.check { display: flex; gap: 8px; align-items: center; }
menu { padding: 0; margin: 16px 0 0; display: flex; gap: 8px; }
.history-filters { gap: 12px; flex-wrap: wrap; }
.history-tools { align-items: end; margin: 0; }
.history-tools label { font-size: 13px; color: var(--muted); }
.history-tools input, .history-tools select {
  display: block; margin-top: 4px; min-width: 200px;
  padding: 8px 10px; border-radius: 10px; border: 1px solid var(--line); font: inherit;
}
.history-layout {
  display: grid;
  grid-template-columns: minmax(280px, 1fr) minmax(320px, 1.2fr);
  gap: 16px;
  align-items: start;
}
.history-list-wrap { min-width: 0; }
.history-table-row { cursor: pointer; }
.history-table-row:hover, .history-table-row.active { background: #f6efe2; }
.history-pager {
  display: flex; justify-content: space-between; align-items: center;
  margin-top: 10px; color: var(--muted); font-size: 13px;
}
.history-thread {
  background: #f7f4ee;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px;
  min-height: 280px;
  max-height: 70vh;
  overflow: auto;
}
.history-thread h3 { margin: 0 0 4px; font-size: 16px; }
.history-msg {
  margin: 10px 0;
  padding: 10px 12px;
  border-radius: 12px;
  background: #fff;
  border: 1px solid var(--line);
}
.history-msg.user { background: #eef4f7; }
.history-msg .meta { color: var(--muted); font-size: 12px; margin-bottom: 6px; }
.history-msg .body { white-space: pre-wrap; word-break: break-word; line-height: 1.5; }
@media (max-width: 980px) {
  body { flex-direction: column; }
  aside { width: auto; flex-direction: row; align-items: center; overflow: auto; }
  nav { flex-direction: row; }
  .cards, .grid2, .history-layout { grid-template-columns: 1fr; }
  .aside-foot { margin-top: 0; }
}
