:root {
  --ink: #1c242b;
  --muted: #66717a;
  --line: #e4ddd2;
  --paper: #f6f1e8;
  --panel: #fffdf8;
  --yellow: #f0c400;
  --green: #1f7a4d;
  --blue: #1d5fd1;
  --orange: #b86200;
  --red: #b42318;
  font-family: "Avenir Next", "PingFang SC", "Noto Sans SC", -apple-system, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--paper); color: var(--ink); min-height: 100%; }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { opacity: .5; cursor: not-allowed; }

.login-shell { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login-card { width: min(410px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 18px; padding: 24px; box-shadow: 0 12px 32px rgba(28, 36, 43, .08); display: flex; flex-direction: column; gap: 14px; }
.login-brand { display: flex; align-items: center; gap: 12px; }
.login-logo { width: 42px; height: 42px; border-radius: 12px; background: var(--yellow); color: var(--ink); display: grid; place-items: center; font-weight: 800; font-size: 18px; flex: none; }
.login-brand h1 { margin: 0; font-size: 18px; }
.login-brand p { margin: 2px 0 0; font-size: 12px; color: var(--muted); }

.auth-tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; padding: 4px; border-radius: 12px; background: #f2ece2; border: 1px solid var(--line); }
.auth-tab { border: 0; border-radius: 9px; background: transparent; padding: 8px 10px; font-size: 13px; font-weight: 650; color: var(--muted); }
.auth-tab.active { background: #fff; color: var(--ink); box-shadow: 0 1px 4px rgba(28, 36, 43, .08); }

.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; }
.field span { color: var(--muted); font-size: 12px; font-weight: 600; }
.field input, .field textarea, .field select { width: 100%; border: 1px solid var(--line); border-radius: 10px; padding: 9px 11px; background: #fff; }
.field textarea { min-height: 78px; resize: vertical; }
.primary { border: 0; border-radius: 10px; background: var(--ink); color: #fff; padding: 9px 14px; font-weight: 650; }
.primary:hover:not(:disabled) { opacity: .92; }
.ghost { border: 1px solid var(--line); border-radius: 10px; background: #fff; padding: 7px 12px; font-size: 13px; font-weight: 600; }
.ghost.danger { color: var(--red); border-color: #f2c6c2; background: #fff7f6; }
.alert { padding: 9px 12px; border-radius: 10px; font-size: 12.5px; line-height: 1.45; }
.alert.bad { background: #fde8e6; color: var(--red); }
.alert.ok { background: #e6f5ec; color: var(--green); }
.alert.info { background: #eef4ff; color: var(--blue); }

.topbar { position: sticky; top: 0; z-index: 10; background: var(--ink); color: #f4efe6; padding: 12px 16px; display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.topbar-left { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.topbar h1 { margin: 0; font-size: 16px; }
.ws-pill { display: inline-flex; align-items: center; gap: 6px; padding: 3px 9px; border-radius: 999px; background: rgba(255,255,255,.08); font-size: 11px; color: #c8beb2; }
.ws-dot { width: 7px; height: 7px; border-radius: 99px; background: #8d97a0; }
.ws-dot.on { background: #3dbe7a; box-shadow: 0 0 0 3px rgba(61, 190, 122, .22); }
.topbar-user { font-size: 12px; color: #d7cec2; padding: 3px 9px; border-radius: 999px; background: rgba(255,255,255,.07); }
.topbar-right { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.topbar select { border: 1px solid rgba(255,255,255,.16); border-radius: 8px; background: #263039; color: #f4efe6; padding: 6px 10px; font-size: 12px; }
.topbar .top-btn { border: 1px solid rgba(255,255,255,.14); border-radius: 8px; background: rgba(255,255,255,.08); color: #f4efe6; padding: 6px 10px; font-size: 12px; font-weight: 600; }

.container { max-width: 1180px; margin: 0 auto; padding: 14px 16px 40px; display: flex; flex-direction: column; gap: 14px; }
.stats { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 10px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; }
.stat span { display: block; font-size: 12px; color: var(--muted); }
.stat b { display: block; margin-top: 4px; font-size: 20px; font-variant-numeric: tabular-nums; }
.stat.green b { color: var(--green); }
.stat.orange b { color: var(--orange); }
.stat.red b { color: var(--red); }

.nav-tabs { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 2px; }
.nav-tab { flex: none; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); padding: 8px 13px; font-size: 13px; font-weight: 650; color: var(--muted); display: inline-flex; align-items: center; gap: 6px; }
.nav-tab.active { background: #fff4cc; border-color: #e6c656; color: var(--ink); }
.nav-tab em { font-style: normal; padding: 1px 6px; border-radius: 999px; background: rgba(28,36,43,.08); font-size: 11px; }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 14px; display: flex; flex-direction: column; gap: 12px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.panel-head h2 { margin: 0; font-size: 15px; }
.hint { margin: 0; font-size: 12px; color: var(--muted); }

.filter-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.filter-pills { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.filter-pill { border: 1px solid var(--line); border-radius: 999px; background: #fff; padding: 5px 11px; font-size: 12px; font-weight: 600; color: var(--muted); }
.filter-pill.active { background: var(--ink); color: #fff; border-color: var(--ink); }
.filter-right { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.filter-right input[type="search"] { border: 1px solid var(--line); border-radius: 10px; padding: 6px 10px; background: #fff; font-size: 12.5px; min-width: 210px; }
.check-inline { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); cursor: pointer; user-select: none; }

.table-wrap { width: 100%; overflow-x: auto; border: 1px solid var(--line); border-radius: 12px; background: #fff; }
.client-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.client-table th { text-align: left; font-size: 11.5px; font-weight: 700; color: var(--muted); background: #faf6ef; padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.client-table td { padding: 11px 12px; border-bottom: 1px solid #f1ece4; vertical-align: middle; }
.client-table tr:last-child td { border-bottom: 0; }
.client-table tr.is-revoked { opacity: .66; }

.client-name { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; font-weight: 650; }
.client-sub { margin-top: 3px; font-size: 11.5px; color: var(--muted); }
.status-inline { display: inline-flex; align-items: center; gap: 6px; font-weight: 650; font-size: 12.5px; white-space: nowrap; }
.status-dot { width: 8px; height: 8px; border-radius: 99px; flex: none; }
.status-dot.on { background: #1e9e5a; box-shadow: 0 0 0 3px rgba(30, 158, 90, .18); }
.status-dot.off { background: #9aa3ab; }
.status-dot.revoked { background: #d94136; }
.sync-err-line { margin-top: 4px; font-size: 11.5px; color: var(--red); max-width: 240px; word-break: break-word; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }

.chat-grid { display: grid; grid-template-columns: 320px 1fr; gap: 12px; min-height: 520px; }
.conv-list { border: 1px solid var(--line); border-radius: 12px; background: #fff; overflow: auto; max-height: 600px; display: flex; flex-direction: column; }
.conv-item { border: 0; border-bottom: 1px solid #f0ebe3; background: transparent; padding: 10px 12px; text-align: left; display: flex; flex-direction: column; gap: 3px; }
.conv-item:last-child { border-bottom: 0; }
.conv-item.active { background: #fff4cc; }
.conv-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.conv-top strong { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-top time { font-size: 11px; color: var(--muted); flex: none; }
.conv-last { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-goods { font-size: 11px; color: #7e5a00; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.thread-box { border: 1px solid var(--line); border-radius: 12px; background: #faf6ef; padding: 14px; overflow: auto; max-height: 600px; display: flex; flex-direction: column; gap: 10px; }
.msg { max-width: 82%; display: flex; flex-direction: column; gap: 3px; }
.msg.me { align-self: flex-end; align-items: flex-end; }
.msg small { font-size: 11px; color: var(--muted); }
.msg .bubble { padding: 9px 12px; border-radius: 12px; background: #fff; border: 1px solid var(--line); font-size: 13px; line-height: 1.5; white-space: pre-wrap; word-break: break-word; }
.msg.me .bubble { background: #fff4cc; border-color: #ecd27a; }

.card-list { display: flex; flex-direction: column; gap: 10px; }
.item-card { border: 1px solid var(--line); border-radius: 12px; background: #fff; padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.item-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; flex-wrap: wrap; }
.badges { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.badge { padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 650; background: #f3eee6; color: #475461; white-space: nowrap; }
.badge.green { background: #e6f5ec; color: var(--green); }
.badge.yellow { background: #fff4cc; color: #8a6500; }
.badge.blue { background: #e8f1ff; color: var(--blue); }
.badge.orange { background: #fff0d8; color: var(--orange); }
.badge.red { background: #fde8e6; color: var(--red); }
.ops { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.ops button { border: 0; border-radius: 8px; background: #f3eee6; padding: 6px 10px; font-size: 12px; font-weight: 650; white-space: nowrap; }
.ops button.primary { background: var(--ink); color: #fff; }
.ops button.blue { background: #e8f1ff; color: var(--blue); }
.ops button.danger { background: #fde8e6; color: var(--red); }

.qa-q { font-size: 14px; font-weight: 650; }
.qa-a { font-size: 13px; color: #2b343c; line-height: 1.55; white-space: pre-wrap; }
.inline-form { display: flex; flex-direction: column; gap: 8px; padding-top: 6px; border-top: 1px solid var(--line); }
.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }
.search-bar { display: flex; gap: 8px; flex-wrap: wrap; }
.search-bar input { flex: 1 1 200px; border: 1px solid var(--line); border-radius: 10px; padding: 8px 11px; background: #fff; }
.toggle-row { display: flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 600; cursor: pointer; }

@media (max-width: 820px) {
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .chat-grid { grid-template-columns: 1fr; }
  .conv-list { max-height: 260px; }
  .thread-box { max-height: 400px; }
  .row-2, .row-3 { grid-template-columns: 1fr; }
}
