:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-soft: #eef5f5;
  --text: #172025;
  --muted: #69757b;
  --line: #dce2e5;
  --line-strong: #c6d0d4;
  --primary: #117b83;
  --primary-hover: #0b656c;
  --primary-soft: #daf0f0;
  --coral: #e16e62;
  --success: #178455;
  --warning: #a25b12;
  --danger: #c13e3e;
  --shadow: 0 16px 48px rgba(22, 37, 43, 0.12);
  --radius: 6px;
  font-family: Inter, "Segoe UI", "Microsoft YaHei", Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
}

* { box-sizing: border-box; }
html, body { min-height: 100%; margin: 0; }
body { background: var(--bg); font-size: 14px; line-height: 1.5; letter-spacing: 0; }
button, input { font: inherit; letter-spacing: 0; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .55; }
[hidden] { display: none !important; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: linear-gradient(145deg, #e5f1f1 0 42%, #f7f2ef 42% 100%);
}

.login-panel {
  width: min(520px, 100%);
  padding: 40px;
  background: rgba(255, 255, 255, .94);
  border: 1px solid rgba(187, 202, 205, .9);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.login-brand { display: flex; align-items: center; gap: 20px; margin-bottom: 34px; }
.login-brand img { border-radius: var(--radius); object-fit: cover; }
.product-kicker, .eyebrow { margin: 0 0 4px; color: var(--primary); font-size: 12px; font-weight: 700; text-transform: uppercase; }
.login-brand h1, .page-head h1 { margin: 0; font-size: 30px; line-height: 1.15; font-weight: 720; }
.login-form label, .drawer-form label:not(.switch):not(.setting-row):not(.check-row) { display: grid; gap: 7px; color: #3f4b50; font-size: 13px; font-weight: 650; }
.password-row { display: grid; grid-template-columns: 1fr auto; gap: 10px; }

input[type="text"], input[type="password"], input[type="url"], input[type="number"], input[inputmode="numeric"] {
  width: 100%;
  height: 42px;
  padding: 0 12px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: 5px;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}

input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(17, 123, 131, .13); }
.field-error { min-height: 21px; margin: 9px 0 0; color: var(--danger); font-size: 13px; }

.button {
  min-height: 40px;
  padding: 0 16px;
  border: 1px solid transparent;
  border-radius: 5px;
  font-weight: 680;
  white-space: nowrap;
  transition: background .15s, border-color .15s, transform .1s;
}
.button:active:not(:disabled) { transform: translateY(1px); }
.button.primary { color: #fff; background: var(--primary); }
.button.primary:hover { background: var(--primary-hover); }
.button.secondary { color: var(--primary); background: var(--primary-soft); border-color: #bbdddd; }
.button.ghost { color: #39474d; background: #fff; border-color: var(--line-strong); }
.button.danger { color: #fff; background: var(--danger); }

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  height: 66px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 max(24px, calc((100vw - 1240px) / 2));
  background: rgba(255, 255, 255, .95);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(12px);
}

.brand { display: flex; align-items: center; gap: 10px; color: inherit; text-decoration: none; }
.brand img { border-radius: 5px; }
.brand span { display: grid; line-height: 1.15; }
.brand strong { font-size: 16px; }
.brand small { color: var(--muted); font-size: 10px; font-weight: 650; text-transform: uppercase; }
.top-actions { display: flex; gap: 8px; }
.icon-button {
  width: 38px;
  height: 38px;
  display: inline-grid;
  place-items: center;
  padding: 0;
  color: #405057;
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 5px;
  font-size: 21px;
  line-height: 1;
}
.icon-button:hover { background: #eef2f3; border-color: var(--line-strong); }

.workspace { width: min(1240px, calc(100% - 48px)); margin: 0 auto; padding: 42px 0 64px; }
.page-head { display: flex; align-items: end; justify-content: space-between; gap: 24px; margin-bottom: 24px; }
.page-head .button span { font-size: 18px; vertical-align: -1px; }

.summary-band {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.summary-item { min-width: 0; padding: 18px 20px; border-right: 1px solid var(--line); }
.summary-item:last-child { border-right: 0; }
.summary-item span, .summary-item strong { display: block; }
.summary-label { margin-bottom: 5px; color: var(--muted); font-size: 11px; font-weight: 650; text-transform: uppercase; }
.summary-item strong { overflow: hidden; font-size: 16px; text-overflow: ellipsis; white-space: nowrap; }
.summary-item strong > #botCount, .summary-item strong #botLimit { display: inline; }
.summary-item .summary-muted { display: inline; color: #899398; font-weight: 500; }
.status-dot { display: inline-block; width: 8px; height: 8px; margin-right: 7px; border-radius: 50%; background: #9aa5aa; }
.status-dot.online { background: var(--success); box-shadow: 0 0 0 3px rgba(23, 132, 85, .12); }
.status-dot.offline { background: var(--danger); }

.notice { margin-top: 16px; padding: 11px 14px; color: #754511; background: #fff6df; border: 1px solid #efd49a; border-radius: var(--radius); }
.notice.success { color: #125f40; background: #e9f7f0; border-color: #b8dfcc; }
.notice.error { color: #842b2b; background: #fff0ef; border-color: #ecc1bd; }

.instances-section { margin-top: 32px; }
.section-bar { min-height: 38px; display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.section-bar h2 { margin: 0; font-size: 17px; }
.updated-at { color: var(--muted); font-size: 12px; }
.table-shell { margin-top: 8px; overflow: hidden; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; table-layout: fixed; }
th { padding: 11px 16px; color: var(--muted); background: #f8fafb; border-bottom: 1px solid var(--line); font-size: 11px; text-align: left; text-transform: uppercase; }
td { height: 70px; padding: 10px 16px; border-bottom: 1px solid #e7ebed; vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fafcfc; }
th:nth-child(1) { width: 21%; }
th:nth-child(2) { width: 15%; }
th:nth-child(3) { width: 14%; }
th:nth-child(4) { width: 24%; }
th:nth-child(5) { width: 14%; }
th:nth-child(6) { width: 12%; }
.bot-name { display: flex; align-items: center; gap: 11px; min-width: 0; }
.bot-avatar { width: 36px; height: 36px; flex: 0 0 36px; display: grid; place-items: center; color: #fff; background: var(--primary); border-radius: 5px; font-size: 14px; font-weight: 750; }
.bot-name-text { min-width: 0; }
.bot-name-text strong, .bot-name-text small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bot-name-text small { margin-top: 2px; color: var(--muted); font-size: 11px; }
.mono { color: #46545a; font-family: "Cascadia Code", Consolas, monospace; font-size: 13px; }
.state-pill { display: inline-flex; align-items: center; gap: 6px; color: #526066; font-weight: 650; }
.state-pill i { width: 8px; height: 8px; border-radius: 50%; background: #9da7ab; }
.state-pill.running { color: var(--success); }
.state-pill.running i { background: var(--success); }
.state-pill.waiting { color: var(--warning); }
.state-pill.waiting i { background: var(--warning); }
.connection { display: grid; gap: 2px; min-width: 0; }
.connection strong, .connection span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.connection strong { font-size: 13px; font-weight: 620; }
.connection span { color: var(--muted); font-size: 11px; }
.webui-link { color: var(--primary); font-weight: 650; text-decoration: none; }
.webui-link:hover { text-decoration: underline; }
.qr-link { color: var(--warning); }
.muted { color: #97a0a4; }
.row-actions { display: flex; justify-content: flex-end; gap: 6px; }
.row-actions .icon-button { width: 32px; height: 32px; font-size: 16px; }
.row-actions .delete { color: var(--danger); }
.empty-state { padding: 64px 24px; text-align: center; }
.empty-state img { border-radius: var(--radius); opacity: .85; }
.empty-state h3 { margin: 12px 0 18px; font-size: 16px; }

.drawer-backdrop { position: fixed; inset: 0; z-index: 40; background: rgba(18, 29, 34, .32); }
.drawer {
  position: fixed;
  top: 0;
  right: 0;
  z-index: 50;
  width: min(520px, 100vw);
  height: 100vh;
  overflow-y: auto;
  background: var(--surface);
  box-shadow: -18px 0 50px rgba(22, 37, 43, .17);
  transform: translateX(102%);
  transition: transform .22s ease;
}
.drawer.open { transform: translateX(0); }
.drawer-head { position: sticky; top: 0; z-index: 2; display: flex; align-items: center; justify-content: space-between; padding: 24px 28px 18px; background: rgba(255, 255, 255, .97); border-bottom: 1px solid var(--line); }
.drawer-head h2 { margin: 0; font-size: 21px; }
.drawer-form { padding: 4px 28px 28px; }
.form-section { padding: 24px 0; border-bottom: 1px solid var(--line); }
.form-section h3 { margin: 0 0 14px; font-size: 14px; }
.field-grid { display: grid; gap: 14px; }
.field-grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.section-toggle, .setting-row { display: flex; align-items: center; justify-content: space-between; gap: 18px; }
.section-toggle h3, .section-toggle p { margin: 0; }
.section-toggle p, .setting-row small { display: block; color: var(--muted); font-size: 12px; font-weight: 400; }
.conditional-fields { margin-top: 16px; padding-left: 16px; border-left: 2px solid #c4dfdf; }
.conditional-fields > label + label { margin-top: 13px; }
.conditional-fields.field-grid > label + label { margin-top: 0; }
.check-row { display: flex !important; grid-template-columns: auto 1fr; align-items: center; gap: 8px !important; font-weight: 500 !important; }
.switch { position: relative; width: 42px; height: 24px; flex: 0 0 42px; display: inline-block; }
.switch > input { position: absolute; opacity: 0; pointer-events: none; }
.switch > span { position: absolute; inset: 0; border-radius: 12px; background: #c9d1d4; transition: background .15s; }
.switch > span::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.2); transition: transform .15s; }
.switch > input:checked + span { background: var(--primary); }
.switch > input:checked + span::after { transform: translateX(18px); }
.switch > input:focus-visible + span { outline: 3px solid rgba(17, 123, 131, .18); }
.settings-list .setting-row + .setting-row { margin-top: 17px; }
.setting-row strong { display: block; font-size: 13px; }
.drawer-actions { position: sticky; bottom: 0; display: flex; justify-content: flex-end; gap: 10px; padding: 18px 0 2px; background: #fff; }

.dialog-backdrop { position: fixed; inset: 0; z-index: 70; display: grid; place-items: center; padding: 20px; background: rgba(18, 29, 34, .48); }
.dialog { width: min(420px, 100%); padding: 24px; background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); }
.dialog h2 { margin: 0 0 8px; font-size: 19px; }
.dialog p { margin: 0; color: var(--muted); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 24px; }

@media (max-width: 820px) {
  .workspace { width: min(100% - 28px, 720px); padding-top: 28px; }
  .topbar { padding: 0 14px; }
  .summary-band { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .summary-item:nth-child(2) { border-right: 0; }
  .summary-item:nth-child(-n+2) { border-bottom: 1px solid var(--line); }
  table, thead, tbody, tr, td { display: block; }
  thead { display: none; }
  tbody { display: grid; }
  tbody tr { position: relative; padding: 16px; border-bottom: 1px solid var(--line); }
  tbody tr:last-child { border-bottom: 0; }
  td { height: auto; min-height: 0; padding: 5px 0; border: 0; }
  td:nth-child(1) { padding-right: 104px; margin-bottom: 6px; }
  td:nth-child(2)::before { content: "QQ  "; color: var(--muted); font-family: inherit; }
  td:nth-child(3), td:nth-child(5) { display: inline-block; margin-right: 16px; }
  td:nth-child(4) { margin-top: 5px; }
  td:nth-child(6) { position: absolute; top: 18px; right: 14px; }
}

@media (max-width: 560px) {
  .login-shell { padding: 14px; }
  .login-panel { padding: 26px 20px; }
  .login-brand { align-items: flex-start; }
  .login-brand img { width: 68px; height: 68px; }
  .login-brand h1 { font-size: 24px; }
  .password-row { grid-template-columns: 1fr; }
  .page-head { align-items: center; }
  .page-head h1 { font-size: 25px; }
  .page-head .button { padding: 0 12px; }
  .summary-item { padding: 14px; }
  .summary-item strong { font-size: 14px; }
  .field-grid.two { grid-template-columns: 1fr; }
  .drawer-head, .drawer-form { padding-left: 20px; padding-right: 20px; }
  .drawer-actions .button { flex: 1; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}
