:root {
  --bg: #f6f7f9;
  --card: #ffffff;
  --line: #e3e6ea;
  --text: #1d2129;
  --muted: #74808c;
  --accent: #2f6fed;
  --ok: #1f9254;
  --warn: #b8770a;
  --err: #c0392b;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

body.centered {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 12px 24px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
}

.brand { font-weight: 600; text-decoration: none; color: var(--text); }
.topbar nav { display: flex; gap: 16px; }
.topbar a { color: var(--muted); text-decoration: none; }
.topbar a.active, .topbar a:hover { color: var(--accent); }

main { max-width: 1100px; margin: 0 auto; padding: 24px; }

h1 { font-size: 22px; margin: 0 0 16px; }
h2 { font-size: 17px; margin: 24px 0 12px; }
h4 { font-size: 13px; margin: 14px 0 4px; color: var(--muted); }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 16px;
}

.card.login { width: 320px; }

label { display: block; margin-bottom: 12px; font-size: 13px; color: var(--muted); }

input[type=text], input[type=password], input[type=number], select, textarea {
  width: 100%;
  margin-top: 4px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  font: inherit;
  color: var(--text);
  background: #fff;
}

textarea { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; }

button {
  padding: 8px 16px;
  border: 0;
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  font: inherit;
  cursor: pointer;
}

button:hover { filter: brightness(1.05); }
button.link { background: none; color: var(--accent); padding: 0; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 0 16px;
}

.switch { display: flex; align-items: center; gap: 8px; color: var(--text); }
.switch input { width: auto; margin: 0; }

.filters { display: flex; align-items: end; gap: 16px; }
.filters label { flex: 1; margin: 0; }

.table { width: 100%; border-collapse: collapse; background: var(--card); border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.table th, .table td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--line); }
.table th { font-size: 12px; text-transform: uppercase; color: var(--muted); }
.table tr:last-child td { border-bottom: 0; }
.table a { color: var(--accent); text-decoration: none; }
.active-row { background: #f0f6ff; }

.badge { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: 12px; background: #eef1f5; color: var(--muted); }
.badge.ok { background: #e6f5ec; color: var(--ok); }
.badge.warn { background: #fdf3e2; color: var(--warn); }
.badge.err { background: #fdeceb; color: var(--err); }
.badge.grey { background: #eef1f5; color: var(--muted); }

.muted { color: var(--muted); }
.error { color: var(--err); }

.columns { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; align-items: start; }
@media (max-width: 900px) { .columns { grid-template-columns: 1fr; } }

.meta { display: flex; flex-wrap: wrap; gap: 16px; align-items: center; }

.thread { display: flex; flex-direction: column; gap: 10px; }
.msg { border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; background: var(--card); }
.msg.client { border-left: 3px solid var(--accent); }
.msg.bot { border-left: 3px solid var(--ok); }
.msg.operator { border-left: 3px solid var(--warn); }
.msg.system { opacity: .7; }
.msg-head { display: flex; gap: 8px; align-items: center; font-size: 12px; margin-bottom: 4px; }
.msg-head .who { font-weight: 600; }
.msg-body { white-space: pre-wrap; }

pre {
  white-space: pre-wrap;
  word-break: break-word;
  background: #f8f9fb;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px;
  font-size: 13px;
  margin: 0 0 8px;
}
pre.small { font-size: 12px; max-height: 260px; overflow: auto; }

.result { margin-top: 12px; }
.pager { display: flex; gap: 16px; align-items: center; margin-top: 16px; }
.pager a { color: var(--accent); text-decoration: none; }

.notice, .error, .warn { border-radius: 6px; padding: 10px 12px; margin: 0 0 14px; font-size: 14px; }
.notice { background: #eef7ef; border: 1px solid #cbe5cf; color: #245c30; }
p.error { background: #fdeeee; border: 1px solid #f0cdcd; color: #8c2222; }
span.error { color: #8c2222; font-weight: 600; }
span.warn { color: #9a6100; font-weight: 600; }

table.oauth { border-collapse: collapse; margin-bottom: 10px; font-size: 14px; }
table.oauth td { padding: 4px 14px 4px 0; vertical-align: top; }
table.oauth td:first-child { color: #6b7280; white-space: nowrap; }

input[type="file"] { display: block; margin-top: 6px; font-size: 14px; }
