:root {
  --bg: #f4f5f2;
  --surface: #ffffff;
  --ink: #1d2320;
  --muted: #6b736f;
  --line: #e2e5e0;
  --accent: #128c5e;
  --accent-soft: #e3f3ec;
  --danger: #c2412d;
  --danger-soft: #fbe9e5;
  --warn: #b7791f;
  --warn-soft: #fdf3e0;
  --radius: 10px;
  font-family: "Assistant", "Rubik", "Segoe UI", Arial, sans-serif;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font-size: 15px; line-height: 1.5; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.error { color: var(--danger); min-height: 1.2em; }
.center { text-align: center; margin: 16px 0; }
.row { display: flex; align-items: center; flex-wrap: wrap; }
.gap { gap: 8px; margin-top: 12px; }
h1, h2, h3 { margin: 0 0 12px; font-weight: 700; }
h2 { font-size: 17px; }

/* topbar */
.topbar { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 24px;
  padding: 0 24px; height: 56px; background: var(--surface); border-bottom: 1px solid var(--line); }
.brand { font-weight: 800; color: var(--accent); white-space: nowrap; }
nav { display: flex; gap: 4px; overflow-x: auto; flex: 1; }
nav a { padding: 8px 12px; border-radius: 8px; cursor: pointer; color: var(--muted); white-space: nowrap; }
nav a:hover { background: var(--bg); color: var(--ink); }
nav a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.topbar-end { display: flex; align-items: center; gap: 10px; }

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

/* cards & grids */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin-bottom: 16px; }
.card.flush { padding: 0; overflow-x: auto; }
.grid { display: grid; gap: 16px; margin-bottom: 16px; }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); }
.grid .card { margin-bottom: 0; }
.stats { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
.stat .label { color: var(--muted); font-size: 13px; }
.stat .value { font-size: 26px; font-weight: 800; margin-top: 2px; }

/* buttons & inputs */
.btn { border: 1px solid var(--line); background: var(--surface); color: var(--ink); border-radius: 8px;
  padding: 8px 14px; font: inherit; cursor: pointer; }
.btn:hover { border-color: #c8cdc6; background: #fafbf9; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.05); }
.btn.danger { color: var(--danger); border-color: #f0c9c1; }
.btn.danger:hover { background: var(--danger-soft); }
.btn.ghost { background: transparent; }
.btn.small { padding: 4px 10px; font-size: 13px; }
.btn:disabled { opacity: .55; cursor: wait; }
input, select, textarea { font: inherit; color: inherit; border: 1px solid var(--line); border-radius: 8px;
  padding: 8px 10px; background: var(--surface); }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
textarea { width: 100%; min-height: 90px; resize: vertical; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.toolbar input { flex: 1; min-width: 200px; }
.legend { font-size: 13px; margin-bottom: 12px; }

/* pills */
.pill { display: inline-block; padding: 3px 10px; border-radius: 99px; font-size: 12px; font-weight: 600;
  background: var(--bg); color: var(--muted); white-space: nowrap; }
.pill.ok { background: var(--accent-soft); color: var(--accent); }
.pill.bad { background: var(--danger-soft); color: var(--danger); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }

/* banner */
.banner { padding: 12px 16px; border-radius: var(--radius); margin-bottom: 16px; }
.banner.warn { background: var(--warn-soft); color: #7a5112; }
.banner.bad { background: var(--danger-soft); color: #7d2a1d; }

/* tables */
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: right; padding: 10px 14px; border-bottom: 1px solid var(--line); vertical-align: top; }
.table th { font-size: 13px; color: var(--muted); font-weight: 600; background: #fafbf9; }
.table tr:last-child td { border-bottom: 0; }
.table tr.clickable { cursor: pointer; }
.table tr.clickable:hover td { background: #fafbf9; }
.table .name { font-weight: 600; }
.table .sub { font-size: 12px; color: var(--muted); direction: ltr; text-align: right; }
.table select { padding: 5px 8px; }
.mode-listen { border-color: var(--accent); color: var(--accent); }
.mode-mention { border-color: #6aa88d; }
.mode-off { color: var(--muted); }
.ellipsis { max-width: 380px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* messages */
.msg-list { display: flex; flex-direction: column; gap: 8px; }
.msg { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 14px; }
.msg.mine { background: #f0f8f4; }
.msg.agent { background: var(--accent-soft); border-color: #bfe3d2; }
.msg .meta { font-size: 12px; color: var(--muted); display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 4px; }
.msg .body { white-space: pre-wrap; word-break: break-word; }

/* knowledge */
.kb-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 12px; }
.kb { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; display: flex; flex-direction: column; gap: 6px; }
.kb.pinned { border-color: var(--accent); box-shadow: inset 3px 0 0 var(--accent); }
.kb h3 { font-size: 15px; margin: 0; }
.kb .content { white-space: pre-wrap; font-size: 14px; flex: 1; }
.kb .meta { font-size: 12px; color: var(--muted); display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.tag { background: var(--bg); padding: 1px 8px; border-radius: 99px; font-size: 12px; }

/* switches */
.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 6px 0 14px; }
input[type=checkbox] { width: 20px; height: 20px; accent-color: var(--accent); }

/* settings form */
.settings-section { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin-bottom: 16px; }
.field { display: grid; grid-template-columns: 260px 1fr; gap: 16px; padding: 10px 0; border-bottom: 1px dashed var(--line); align-items: start; }
.field:last-child { border-bottom: 0; }
.field label b { display: block; }
.field label small { color: var(--muted); }
.field input:not([type=checkbox]), .field select, .field textarea { width: 100%; }
.field textarea.tall { min-height: 260px; }
.field textarea.code { font-family: ui-monospace, Menlo, Consolas, monospace; direction: ltr; text-align: left; font-size: 13px; }
.save-bar { position: sticky; bottom: 0; background: var(--bg); padding: 12px 0; display: flex; gap: 8px; }

/* chart */
.chart svg { width: 100%; height: 180px; display: block; }
.chart .bar { fill: var(--accent); opacity: .85; }
.chart .bar:hover { opacity: 1; }
.chart text { font-size: 10px; fill: var(--muted); }

/* modal */
.modal { position: fixed; inset: 0; background: rgba(20, 25, 22, .45); display: flex; align-items: flex-start;
  justify-content: center; padding: 6vh 16px; z-index: 50; overflow-y: auto; }
.modal-card { background: var(--surface); border-radius: 12px; padding: 22px; width: min(720px, 100%); position: relative; }
.modal-close { position: absolute; left: 14px; top: 10px; border: 0; background: none; font-size: 26px; cursor: pointer; color: var(--muted); }
.modal-card .section { border-top: 1px solid var(--line); padding-top: 14px; margin-top: 14px; }
.modal-card input:not([type=checkbox]) { width: 100%; }
pre.out { font-family: inherit; font-size: 14px; background: #f7f8f6; border: 1px solid var(--line); border-radius: 8px; padding: 10px; white-space: pre-wrap;
  word-break: break-word; max-height: 360px; overflow: auto; font-size: 13px; }
pre.ltr { direction: ltr; text-align: left; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12.5px; }

/* qr */
.qr { display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 10px 0; }
.qr img { width: 260px; height: 260px; image-rendering: pixelated; border: 1px solid var(--line); border-radius: 8px; }

/* login */
.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; }
.login-card { width: 340px; display: flex; flex-direction: column; gap: 12px; }
.login-card h1 { color: var(--accent); margin: 0; }

.btn.google { display: flex; align-items: center; justify-content: center; gap: 10px; text-decoration: none; font-weight: 600; padding: 10px 14px; }
.login-pw { display: flex; flex-direction: column; gap: 12px; }
.divider { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 13px; }
.divider::before, .divider::after { content: ""; flex: 1; border-top: 1px solid var(--line); }
.small-text { font-size: 13px; }

/* toast */
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff;
  padding: 10px 18px; border-radius: 8px; z-index: 60; }
.toast.err { background: var(--danger); }

@media (max-width: 760px) {
  .topbar { flex-wrap: wrap; height: auto; padding: 10px 14px; gap: 8px; }
  nav { order: 3; width: 100%; }
  main { padding: 14px; }
  .field { grid-template-columns: 1fr; gap: 6px; }
}
