:root {
  --bg: #f4f6f5;
  --panel: #ffffff;
  --ink: #17201c;
  --muted: #5d6b64;
  --line: #dde3e0;
  --brand: #0f7a4f;
  --brand-ink: #ffffff;
  --brand-soft: #e3f3eb;
  --warn: #a15c00;
  --warn-soft: #fff1dc;
  --danger: #b42318;
  --danger-soft: #fde8e6;
  --info-soft: #e8eefc;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 20, .06), 0 4px 16px rgba(16, 24, 20, .05);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font-size: 14px; line-height: 1.5; }
a { color: var(--brand); }
h1 { font-size: 20px; margin: 0 0 16px; }
h2 { font-size: 16px; margin: 0 0 12px; }
h3 { font-size: 14px; margin: 0 0 8px; }
.loading { padding: 40px; color: var(--muted); }

.app { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.sidebar { background: #0d2a1f; color: #d6e6dd; padding: 16px 10px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.sidebar .brand { font-weight: 700; color: #fff; padding: 4px 10px 16px; font-size: 15px; }
.sidebar .brand small { display: block; font-weight: 400; color: #8fb3a2; font-size: 12px; }
.sidebar a { display: flex; justify-content: space-between; align-items: center; color: #d6e6dd; text-decoration: none; padding: 8px 10px; border-radius: 8px; margin: 2px 0; }
.sidebar a:hover { background: rgba(255,255,255,.07); }
.sidebar a.active { background: var(--brand); color: #fff; }
.sidebar .count { background: #f59e0b; color: #111; border-radius: 999px; font-size: 11px; padding: 0 7px; font-weight: 700; }
.sidebar .user { border-top: 1px solid rgba(255,255,255,.12); margin-top: 16px; padding: 12px 10px 0; font-size: 12px; color: #8fb3a2; }
.sidebar .user button { margin-top: 8px; }
main { padding: 24px; max-width: 1280px; width: 100%; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); margin-bottom: 16px; }
.grid { display: grid; gap: 12px; margin-bottom: 16px; }
.grid > .card { margin-bottom: 0; }
a.stat { text-decoration: none; color: inherit; }
a.stat:hover { border-color: var(--brand); }
.grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.stat .num { font-size: 26px; font-weight: 700; }
.stat .lbl { color: var(--muted); font-size: 12px; }
.stat.alert .num { color: var(--warn); }

.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.spacer { flex: 1; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; }
.pre { white-space: pre-wrap; word-break: break-word; }

button, .btn { font: inherit; border: 1px solid var(--line); background: #fff; color: var(--ink); padding: 7px 12px; border-radius: 8px; cursor: pointer; text-decoration: none; display: inline-block; }
button:hover, .btn:hover { border-color: #b9c4bf; }
button.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
button.danger { color: var(--danger); border-color: #f2b8b1; }
button.small { padding: 3px 8px; font-size: 12px; }
button:disabled { opacity: .5; cursor: not-allowed; }
input, select, textarea { font: inherit; border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; background: #fff; color: var(--ink); width: 100%; }
textarea { min-height: 80px; resize: vertical; }
label { display: block; font-weight: 600; margin: 10px 0 4px; }
label .hint { font-weight: 400; color: var(--muted); font-size: 12px; }
.check { display: flex; gap: 8px; align-items: center; font-weight: 400; }
.check input { width: auto; }
.inline-input { width: auto; min-width: 160px; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; color: var(--muted); font-weight: 600; background: #fafbfa; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: #f7faf8; }
tr.sub td { background: #fbfcfb; color: var(--muted); }
.table-wrap { overflow-x: auto; }

.badge { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; background: #eef1ef; color: #34423b; white-space: nowrap; }
.badge.ok { background: var(--brand-soft); color: #0b5d3c; }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.err { background: var(--danger-soft); color: var(--danger); }
.badge.info { background: var(--info-soft); color: #2b4a9b; }

.chat { display: flex; flex-direction: column; gap: 8px; max-height: 60vh; overflow-y: auto; padding: 8px; background: #f8faf9; border-radius: 8px; border: 1px solid var(--line); }
.msg { max-width: 78%; padding: 8px 12px; border-radius: 12px; white-space: pre-wrap; word-break: break-word; }
.msg.in { align-self: flex-start; background: #fff; border: 1px solid var(--line); }
.msg.bot { align-self: flex-end; background: var(--brand-soft); }
.msg.staff { align-self: flex-end; background: #dbe7ff; }
.msg .meta { font-size: 11px; color: var(--muted); margin-top: 4px; }
.msg .btns { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 6px; }
.msg .btns span { border: 1px solid #9cc9b2; border-radius: 999px; font-size: 12px; padding: 0 8px; }

.notice { padding: 10px 12px; border-radius: 8px; background: var(--info-soft); margin-bottom: 12px; }
.notice.warn { background: var(--warn-soft); }
.notice.err { background: var(--danger-soft); }

.login { max-width: 380px; margin: 10vh auto; }
.login .card { padding: 24px; }

.toast { position: fixed; bottom: 20px; right: 20px; background: #13221b; color: #fff; padding: 10px 14px; border-radius: 8px; opacity: 0; transform: translateY(8px); transition: all .2s; pointer-events: none; max-width: 420px; z-index: 50; }
.toast.show { opacity: 1; transform: none; }
.toast.err { background: var(--danger); }

.modal-back { position: fixed; inset: 0; background: rgba(10, 20, 15, .45); display: flex; align-items: center; justify-content: center; z-index: 40; padding: 16px; }
.modal { background: #fff; border-radius: 12px; padding: 20px; width: 100%; max-width: 560px; max-height: 90vh; overflow-y: auto; }
.modal .actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }

.chunks .chunk { border-left: 3px solid var(--brand-soft); padding: 6px 10px; margin: 8px 0; background: #fbfcfb; }
.hidden { display: none !important; }

@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; display: flex; flex-wrap: wrap; gap: 4px; }
  .sidebar .brand, .sidebar .user { width: 100%; }
  .grid.cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid.cols-2 { grid-template-columns: 1fr; }
  main { padding: 16px; }
  .msg { max-width: 92%; }
}
