:root {
  color-scheme: light;
  --blue: #2f6fed;
  --blue-strong: #245ed3;
  --blue-soft: #edf4ff;
  --blue-pale: #f5f8ff;
  --mint: #42c9bc;
  --green: #22a865;
  --green-soft: #eaf8f0;
  --amber: #d99013;
  --amber-soft: #fff6df;
  --red: #dc4b4b;
  --red-soft: #fff0f0;
  --ink: #273142;
  --ink-strong: #111827;
  --muted: #7b8798;
  --muted-light: #a3adba;
  --line: #e3e8f0;
  --line-strong: #d6dde8;
  --paper: #fff;
  --surface: #f7f9fc;
  --canvas: #e8f2ff;
  --shadow: 0 12px 36px rgba(42, 66, 108, .09);
  font-family: Inter, "SF Pro Text", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { width: 100%; min-width: 320px; min-height: 100%; }
body { margin: 0; background: var(--canvas); color: var(--ink); font-size: 13px; }
button, input, select, textarea { font: inherit; color: inherit; }
button, select { cursor: pointer; }
button:disabled { cursor: not-allowed; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.ui-icon { width: 18px; height: 18px; display: inline-block; flex: 0 0 auto; color: inherit; vertical-align: middle; }
.empty-icon { width: 42px; height: 42px; color: #b6c2d2; }

/* Login */
.login-view { min-height: 100vh; display: grid; grid-template-columns: minmax(480px, 1.08fr) minmax(430px, .92fr); background: #fff; }
.login-art { position: relative; overflow: hidden; display: flex; flex-direction: column; justify-content: center; padding: 9vw; color: #fff; background: #17305d; }
.login-art:before { content: ""; position: absolute; width: 640px; height: 640px; border: 1px solid rgba(255,255,255,.11); border-radius: 50%; left: -160px; top: -250px; box-shadow: 0 0 0 90px rgba(255,255,255,.025), 0 0 0 180px rgba(255,255,255,.02); }
.login-art-grid { position: absolute; inset: 0; opacity: .25; background-image: linear-gradient(rgba(255,255,255,.08) 1px, transparent 1px), linear-gradient(90deg,rgba(255,255,255,.08) 1px,transparent 1px); background-size: 56px 56px; mask-image: linear-gradient(to bottom right,#000,transparent 72%); }
.login-brand { position: relative; width: 74px; height: 74px; display: grid; place-items: center; border: 1px solid rgba(255,255,255,.35); border-radius: 22px; background: rgba(255,255,255,.1); backdrop-filter: blur(10px); }
.login-brand .brand-symbol { width: 45px; height: 45px; }
.login-kicker { position: relative; margin: 36px 0 12px; color: #aecdff; font-size: 11px; font-weight: 750; letter-spacing: .16em; }
.login-art h1 { position: relative; margin: 0; font-size: clamp(36px, 3.1vw, 56px); line-height: 1.18; letter-spacing: -.055em; font-weight: 680; }
.login-points { position: relative; display: grid; gap: 13px; margin-top: 44px; color: #cbd9ef; }
.login-points span { display: flex; align-items: center; gap: 10px; }
.login-points .ui-icon { color: #8eb7ff; }
.login-card { width: min(420px, calc(100% - 56px)); margin: auto; }
.login-card-head { display: flex; align-items: center; gap: 12px; margin-bottom: 52px; }
.login-mini-logo { width: 42px; height: 42px; padding: 9px; border-radius: 12px; color: #fff; background: var(--blue); }
.login-card-head strong, .login-card-head span { display: block; }
.login-card-head strong { color: var(--ink-strong); font-size: 15px; }
.login-card-head span { margin-top: 2px; color: var(--muted); font-size: 11px; }
.login-card h2 { margin: 0 0 8px; color: var(--ink-strong); font-size: 28px; letter-spacing: -.04em; }
.login-card > p { margin: 0 0 30px; }
.login-card label, .dialog-card label, .operation-console > label, .field-row label { display: grid; gap: 8px; color: #4d596a; font-size: 12px; font-weight: 650; }
.login-card label { margin: 18px 0; }
input, select, textarea { width: 100%; border: 1px solid var(--line); border-radius: 7px; outline: none; background: #fbfcfe; transition: border-color .16s, box-shadow .16s; }
input, select { height: 38px; padding: 0 11px; }
textarea { padding: 11px 12px; resize: vertical; line-height: 1.55; }
input:focus, select:focus, textarea:focus { border-color: #8db1f7; box-shadow: 0 0 0 3px rgba(47,111,237,.1); }

/* Buttons */
.button { min-height: 34px; display: inline-flex; align-items: center; justify-content: center; gap: 7px; padding: 0 13px; border: 1px solid transparent; border-radius: 6px; background: transparent; font-weight: 650; font-size: 12px; transition: background .15s, border-color .15s, transform .15s; }
.button .ui-icon { width: 15px; height: 15px; }
.button:active:not(:disabled) { transform: translateY(1px); }
.button:disabled { opacity: .45; }
.button.primary { color: #fff; border-color: var(--blue); background: var(--blue); box-shadow: 0 5px 14px rgba(47,111,237,.16); }
.button.primary:hover:not(:disabled) { border-color: var(--blue-strong); background: var(--blue-strong); }
.button.secondary { color: #4c596b; border-color: var(--line); background: #fff; }
.button.secondary:hover:not(:disabled), .button.ghost:hover:not(:disabled) { border-color: #cfd8e6; background: #f4f7fb; }
.button.ghost { color: var(--muted); border-color: transparent; background: transparent; }
.button.danger { color: #bd3e3e; border-color: #f2cccc; background: var(--red-soft); }
.button.wide { width: 100%; height: 42px; margin-top: 6px; }
.icon-button { width: 32px; height: 32px; display: grid; place-items: center; padding: 0; border: 0; border-radius: 6px; color: #788597; background: transparent; }
.icon-button:hover { color: var(--blue); background: var(--blue-soft); }
.icon-button .ui-icon { width: 17px; height: 17px; }
.form-error { min-height: 20px; margin: 12px 0 0 !important; color: var(--red); font-size: 12px; }

/* App shell */
.app-shell { min-height: 100vh; display: grid; grid-template-columns: 58px minmax(0,1fr); gap: 6px; padding: 6px; background: linear-gradient(135deg,#dcecff 0,#ebf7f5 100%); }
.sidebar { min-height: calc(100vh - 12px); display: flex; flex-direction: column; align-items: center; border-radius: 10px 0 0 10px; background: rgba(236,244,255,.92); }
.brand { width: 100%; height: 50px; display: flex; align-items: center; justify-content: center; color: var(--blue); }
.brand-symbol { width: 30px; height: 30px; }
.brand-copy { display: none; }
.main-nav { width: 100%; display: grid; justify-items: center; gap: 4px; padding-top: 7px; }
.main-nav button, .rail-action { position: relative; width: 42px; height: 42px; display: grid; place-items: center; padding: 0; border: 0; border-radius: 8px; color: #8090a5; background: transparent; }
.main-nav button .ui-icon, .rail-action .ui-icon { width: 20px; height: 20px; }
.main-nav button:hover, .main-nav button.active { color: var(--blue); background: #fff; box-shadow: 0 4px 14px rgba(50,84,139,.08); }
.main-nav button.active:before { content: ""; position: absolute; left: -8px; width: 3px; height: 22px; border-radius: 0 3px 3px 0; background: var(--blue); }
.nav-label { position: absolute; left: 52px; z-index: 100; min-width: 74px; padding: 7px 9px; border-radius: 5px; color: #fff; background: #263449; font-size: 11px; font-weight: 600; text-align: center; opacity: 0; pointer-events: none; transform: translateX(-4px); transition: .14s; box-shadow: 0 7px 20px rgba(21,32,49,.18); }
.main-nav button:hover .nav-label, .rail-action:hover .nav-label { opacity: 1; transform: none; }
.sidebar-foot { width: 100%; display: grid; justify-items: center; gap: 7px; margin-top: auto; padding-bottom: 10px; }
.rail-status { width: 12px; height: 12px; display: grid; place-items: center; }
.rail-status i, .connection i { width: 7px; height: 7px; display: block; border-radius: 50%; background: var(--green); box-shadow: 0 0 0 3px rgba(34,168,101,.12); }
.rail-status.offline i, .connection.offline i { background: var(--red); box-shadow: 0 0 0 3px rgba(220,75,75,.12); }
.rail-action { color: #8492a5; }
.workspace { min-width: 0; min-height: calc(100vh - 12px); overflow: hidden; border: 1px solid rgba(206,219,235,.9); border-radius: 0 10px 10px 0; background: #fff; }
.topbar { height: 50px; display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 0 14px 0 18px; border-bottom: 1px solid var(--line); background: #fff; }
.page-heading { min-width: 0; display: flex; align-items: baseline; gap: 11px; }
.page-heading h2 { margin: 0; color: var(--ink-strong); font-size: 15px; }
.page-heading p { margin: 0; color: var(--muted); font-size: 10px; }
.mobile-brand { display: none; }
.top-actions { min-width: 0; display: flex; align-items: center; gap: 8px; }
.instance-switch { position: relative; height: 32px; display: flex; align-items: center; gap: 6px; padding: 0 7px 0 10px; border: 1px solid var(--line); border-radius: 6px; background: #f9fafc; }
.instance-switch > span { color: var(--muted); font-size: 10px; white-space: nowrap; }
.instance-switch select { width: 132px; height: 30px; padding: 0 24px 0 0; border: 0; appearance: none; color: #455266; background: transparent; font-size: 11px; font-weight: 650; box-shadow: none; }
.instance-switch .ui-icon { position: absolute; right: 5px; width: 14px; height: 14px; color: #8b96a5; pointer-events: none; }
.connection { height: 30px; display: flex; align-items: center; gap: 7px; padding: 0 9px; border: 1px solid var(--line); border-radius: 99px; color: var(--muted); background: #fff; font-size: 10px; white-space: nowrap; }
.workspace:not([data-page="overview"]) #new-instance-button { display: none; }
.workspace main { height: calc(100vh - 63px); overflow: auto; padding: 17px 18px 28px; background: #fbfcfe; }
.page { display: none; }
.page.active { display: block; }
.page-actions-bar { min-height: 42px; display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-bottom: 9px; padding: 0 3px; color: var(--muted); font-size: 9px; }
.page-actions-bar .button.compact, .button.compact { min-height: 29px; padding: 0 9px; box-shadow: none; font-size: 9px; }

/* Overview */
.overview-toolbar { display: flex; justify-content: flex-end; min-height: 24px; margin-bottom: 7px; }
.status-legend { display: flex; gap: 15px; color: var(--muted); font-size: 10px; }
.status-legend span { display: flex; align-items: center; gap: 6px; }
.status-legend i { width: 6px; height: 6px; border-radius: 50%; background: #9aa5b4; }
.status-legend i.green { background: var(--green); }
.status-legend i.amber { background: var(--amber); }
.summary-grid { display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: 10px; margin-bottom: 18px; }
.metric { min-height: 92px; padding: 13px 14px; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.metric-top { display: flex; align-items: center; justify-content: space-between; color: var(--muted); font-size: 10px; }
.metric-icon { width: 27px; height: 27px; display: grid; place-items: center; border-radius: 7px; color: var(--blue); background: var(--blue-soft); }
.metric-icon .ui-icon { width: 15px; height: 15px; }
.metric strong { display: block; margin: 5px 0 1px; color: var(--ink-strong); font-size: 23px; letter-spacing: -.04em; }
.metric small { color: var(--muted); font-size: 9px; }
.section-heading { margin: 0 0 9px; }
.section-heading h3 { margin: 0; color: var(--ink-strong); font-size: 13px; }
.section-heading h3 span { margin-left: 8px; color: var(--muted); font-size: 9px; font-weight: 400; }
.instance-grid { display: grid; grid-template-columns: repeat(3,minmax(260px,1fr)); gap: 10px; }
.instance-card { position: relative; overflow: hidden; padding: 14px; border: 1px solid var(--line); border-radius: 8px; background: #fff; transition: .16s; }
.instance-card:hover { border-color: #cbd8ea; box-shadow: var(--shadow); transform: translateY(-1px); }
.instance-card.selected { border-color: #9fbcf5; box-shadow: 0 0 0 2px rgba(47,111,237,.06); }
.instance-card:before { content: ""; position: absolute; inset: 0 auto 0 0; width: 3px; background: #aab4c2; }
.instance-card.online:before { background: var(--green); }
.instance-head { display: flex; align-items: center; gap: 10px; }
.instance-avatar { width: 38px; height: 38px; flex: 0 0 38px; display: grid; place-items: center; overflow: hidden; border-radius: 50%; color: #fff; background: #6e91d6; object-fit: cover; font-size: 13px; font-weight: 760; }
.instance-title { min-width: 0; flex: 1; }
.instance-title strong, .instance-title small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.instance-title strong { color: var(--ink-strong); font-size: 12px; }
.instance-title small { margin-top: 3px; color: var(--muted); font-size: 9px; }
.status-pill { display: inline-flex; align-items: center; min-height: 22px; padding: 0 8px; border-radius: 99px; color: #687487; background: #eef1f5; font-size: 9px; font-weight: 700; white-space: nowrap; }
.status-pill.online { color: #13804a; background: var(--green-soft); }
.status-pill.awaiting_scan, .status-pill.scanned, .status-pill.requesting_qr { color: #9b6406; background: var(--amber-soft); }
.status-pill.verification_required, .status-pill.error { color: #bd4141; background: var(--red-soft); }
.instance-meta { display: grid; grid-template-columns: 1fr 1fr; gap: 9px 12px; margin-top: 13px; padding-top: 11px; border-top: 1px solid #edf0f4; }
.instance-meta div:last-child { grid-column: 1 / -1; }
.instance-meta span, .customer-fact span { display: block; color: var(--muted-light); font-size: 8px; }
.instance-meta strong { display: block; margin-top: 3px; overflow: hidden; color: #546174; font-size: 9px; font-weight: 600; text-overflow: ellipsis; white-space: nowrap; }
.instance-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
.instance-actions .button { min-height: 30px; padding: 0 10px; font-size: 10px; box-shadow: none; }
.empty-card, .empty-state { min-height: 230px; display: grid; place-items: center; grid-column: 1/-1; border: 1px dashed #ccd5e2; border-radius: 8px; color: var(--muted); background: rgba(255,255,255,.65); text-align: center; }
.empty-card { padding: 36px; }
.empty-card strong { color: #566376; }
.empty-card p { margin: 6px 0 0; font-size: 11px; }

/* Contacts */
.workspace[data-page="contacts"] main { padding: 0; overflow: hidden; background: #fff; }
.contacts-page.active { height: calc(100vh - 63px); overflow: hidden; }
.data-panel { height: 100%; min-height: 0; overflow: hidden; border: 0; border-radius: 0; background: #fff; }
.data-toolbar { min-height: 51px; display: flex; align-items: center; gap: 7px; padding: 8px 10px; border-bottom: 1px solid var(--line); background: #fff; }
.search-box { width: 275px; height: 32px; display: flex; align-items: center; gap: 7px; padding: 0 9px; border: 1px solid #e3e7ed; border-radius: 5px; color: #96a2b2; background: #f7f8fa; }
.search-box .ui-icon { width: 15px; height: 15px; }
.search-box input { min-width: 0; height: 30px; padding: 0; border: 0; background: transparent; box-shadow: none; font-size: 10px; }
.contact-filter-bar { display: flex; align-items: center; gap: 2px; }
.contact-filter-bar button { height: 31px; display: inline-flex; align-items: center; gap: 6px; padding: 0 10px; border: 0; border-radius: 5px; color: #657184; background: transparent; font-size: 9px; }
.contact-filter-bar button:hover { background: #f3f6fa; }
.contact-filter-bar button.active { color: var(--blue); background: #edf3ff; }
.contact-filter-bar .ui-icon { width: 14px; height: 14px; }
.toolbar-count { margin-left: auto; color: var(--muted); font-size: 9px; white-space: nowrap; }
.contact-grid { height: calc(100% - 51px); min-height: 0; overflow: auto; }
.contact-grid.empty-state { border: 0; }
.customer-table { min-width: 1040px; color: #4c5665; font-size: 10px; }
.customer-row { min-height: 64px; display: grid; grid-template-columns: 46px minmax(190px,1.25fr) minmax(140px,.8fr) minmax(210px,1.15fr) 90px minmax(130px,.75fr) 112px; align-items: center; border-bottom: 1px solid #e8ebef; background: #fff; }
.customer-row:hover:not(.customer-table-header) { background: #f8fbff; }
.customer-row.selected { background: #f4f8ff; }
.customer-table-header { position: sticky; top: 0; z-index: 2; min-height: 41px; color: #3f4855; background: #f3f4f6; font-weight: 700; }
.customer-cell { min-width: 0; padding: 8px 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.customer-cell.check-cell { display: grid; place-items: center; padding: 0; }
.table-check { width: 18px; height: 18px; display: grid; place-items: center; cursor: pointer; }
.table-check input { width: 14px; height: 14px; margin: 0; accent-color: var(--blue); }
.customer-name { display: flex; align-items: center; gap: 9px; color: #306bd7; font-weight: 650; }
.contact-avatar { width: 34px; height: 34px; flex: 0 0 34px; display: grid; place-items: center; overflow: hidden; border-radius: 50%; color: #fff; background: #6f92d8; object-fit: cover; font-size: 10px; font-weight: 760; }
.customer-cell.location { color: var(--muted); }
.customer-cell.status { color: var(--green); }
.customer-cell.action { display: flex; gap: 9px; }
.customer-cell.action button { padding: 0; border: 0; color: var(--blue); background: transparent; font-size: 9px; }
.customer-cell.action i { width: 1px; height: 11px; background: #dfe4eb; }
.customer-table-footer { position: sticky; bottom: 0; height: 36px; display: flex; align-items: center; justify-content: space-between; padding: 0 12px; border-top: 1px solid var(--line); color: var(--muted); background: #fff; font-size: 9px; }

/* Conversation workspace */
.workspace[data-page="messages"] main { padding: 7px; overflow: hidden; background: #f4f7fb; }
.messages-page.active { height: calc(100vh - 77px); min-height: 560px; display: grid; grid-template-columns: 176px 310px minmax(400px,1fr) 294px; overflow: hidden; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.module-rail { min-width: 0; padding: 10px 8px; border-right: 1px solid var(--line); background: #f6f9fe; }
.module-title { min-height: 39px; display: flex; align-items: center; padding: 0 8px; }
.module-title strong { color: var(--ink-strong); font-size: 13px; }
.module-rail nav { display: grid; gap: 3px; margin-top: 8px; }
.module-rail nav button, .tools-nav > button { min-width: 0; height: 34px; display: flex; align-items: center; gap: 9px; padding: 0 9px; border: 0; border-radius: 6px; color: #657286; background: transparent; text-align: left; font-size: 10px; }
.module-rail nav button .ui-icon, .tools-nav > button .ui-icon { width: 16px; height: 16px; }
.module-rail nav button span { min-width: 0; flex: 1; }
.module-rail nav button small { min-width: 20px; padding: 2px 5px; border-radius: 99px; color: #788699; background: #e8edf5; font-size: 8px; text-align: center; }
.module-rail nav button:hover, .module-rail nav button.active, .tools-nav > button:hover, .tools-nav > button.active { color: var(--blue); background: #e8f0ff; }
.module-rail nav button.active small { color: #fff; background: var(--blue); }
.rail-divider { height: 1px; margin: 14px 8px; background: #e3e9f2; }
.rail-runtime { margin: 0 4px; padding: 10px; border: 1px solid #dfe6f0; border-radius: 7px; background: #fff; }
.rail-runtime div { display: flex; align-items: center; gap: 7px; color: #5d697a; }
.rail-runtime .ui-icon { width: 14px; height: 14px; color: #8894a5; }
.rail-runtime strong { font-size: 9px; }
.rail-runtime p { margin: 5px 0 0 21px; color: var(--muted); font-size: 8px; line-height: 1.45; }
.conversation-list { min-width: 0; display: grid; grid-template-rows: 51px 41px 34px minmax(0,1fr); border-right: 1px solid var(--line); background: #fff; }
.conversation-head { display: flex; align-items: center; justify-content: space-between; padding: 0 11px 0 13px; }
.conversation-head h3 { margin: 0; color: var(--ink-strong); font-size: 12px; }
.conversation-head p { margin: 3px 0 0; color: var(--muted); font-size: 8px; }
.conversation-search { height: 31px; display: flex; align-items: center; gap: 7px; margin: 3px 10px 7px; padding: 0 8px; border: 1px solid var(--line); border-radius: 6px; color: #96a1b0; background: #f7f9fb; }
.conversation-search .ui-icon { width: 14px; height: 14px; }
.conversation-search input { min-width: 0; height: 28px; flex: 1; padding: 0; border: 0; background: transparent; box-shadow: none; font-size: 9px; }
.conversation-search span { padding: 2px 5px; border: 1px solid #e1e5eb; border-radius: 3px; color: #9aa4b2; background: #fff; font-size: 7px; white-space: nowrap; }
.conversation-filters { display: flex; align-items: center; gap: 2px; padding: 0 10px 6px; }
.conversation-filters button { height: 25px; padding: 0 8px; border: 0; border-radius: 4px; color: #768294; background: transparent; font-size: 9px; }
.conversation-filters button.active { color: var(--blue); background: #edf3ff; }
.peer-list { min-height: 0; overflow-y: auto; padding: 5px 6px 9px; }
.peer { width: 100%; min-height: 57px; display: flex; align-items: center; gap: 9px; padding: 7px 8px; border: 0; border-radius: 7px; background: transparent; text-align: left; }
.peer:hover { background: #f5f8fc; }
.peer.active { background: #e9f1ff; }
.peer-avatar { position: relative; width: 36px; height: 36px; flex: 0 0 36px; }
.peer-avatar .contact-avatar { width: 36px; height: 36px; }
.unread-dot { position: absolute; right: -4px; top: -4px; min-width: 16px; height: 16px; display: grid; place-items: center; padding: 0 4px; border: 2px solid #fff; border-radius: 99px; color: #fff; background: #ef5a5a; font-size: 7px; }
.peer-body { min-width: 0; flex: 1; }
.peer-body strong, .peer-body small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.peer-body strong { color: #374458; font-size: 10px; }
.peer-body small { margin-top: 4px; color: #909aa9; font-size: 8px; }
.peer-meta { align-self: flex-start; padding-top: 3px; color: #a0a9b6; font-size: 7px; }
.queue-empty { height: 100%; display: grid; align-content: center; justify-items: center; padding: 24px; text-align: center; color: var(--muted); }
.queue-empty .ui-icon { width: 34px; height: 34px; margin-bottom: 10px; color: #aab7c8; }
.queue-empty strong { color: #667386; font-size: 11px; }
.queue-empty p { margin: 5px 0 0; font-size: 9px; line-height: 1.5; }
.chat-panel { min-width: 0; display: grid; grid-template-rows: 51px minmax(0,1fr) 126px; background: #fff; }
.chat-head { min-width: 0; display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 0 11px 0 13px; border-bottom: 1px solid var(--line); }
.chat-person { min-width: 0; display: flex; align-items: center; gap: 9px; }
.mini-avatar { width: 30px; height: 30px; flex: 0 0 30px; display: grid; place-items: center; overflow: hidden; border-radius: 50%; color: #fff; background: #6f91d7; font-size: 10px; font-weight: 700; }
.mini-avatar img { width: 100%; height: 100%; object-fit: cover; }
.chat-person strong, .chat-person small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-person strong { color: var(--ink-strong); font-size: 11px; }
.chat-person small { margin-top: 2px; color: var(--muted); font-size: 8px; }
.chat-head-actions { display: flex; align-items: center; gap: 5px; }
.header-action { height: 29px; display: flex; align-items: center; gap: 6px; padding: 0 8px; border: 1px solid var(--line); border-radius: 5px; color: #637084; background: #fff; font-size: 9px; }
.header-action .ui-icon { width: 14px; height: 14px; }
.message-list { min-height: 0; overflow-y: auto; padding: 18px 14px; background: #fbfcfe; }
.empty-chat { height: 100%; min-height: 190px; display: grid; place-items: center; color: #9aa5b3; font-size: 10px; }
.bubble-row { display: flex; align-items: flex-end; gap: 7px; margin: 9px 0; }
.bubble-row.outgoing { flex-direction: row-reverse; }
.bubble-row .contact-avatar { width: 27px; height: 27px; flex: 0 0 27px; font-size: 8px; }
.bubble { max-width: min(560px,72%); padding: 8px 10px; border: 1px solid #e4e8ee; border-radius: 4px 11px 11px 11px; color: #4b5768; background: #fff; font-size: 10px; line-height: 1.55; word-break: break-word; white-space: pre-wrap; }
.outgoing .bubble { border-color: #d9e7ff; border-radius: 11px 4px 11px 11px; color: #315d9f; background: #eaf2ff; }
.bubble small { display: block; margin-top: 4px; color: #9aa5b2; font-size: 7px; text-align: right; }
.message-image-frame { display: block; width: min(230px,100%); }
.message-image { display: block; max-width: 100%; max-height: 300px; border-radius: 6px; object-fit: contain; }
.message-image-frame > span { display: none; }
.message-image-frame.failed img { display: none; }
.message-image-frame.failed > span { display: block; color: var(--red); }
.composer { min-width: 0; display: grid; grid-template-rows: 28px minmax(0,1fr) 31px; padding: 7px 11px 8px; border-top: 1px solid var(--line); background: #fff; }
.composer-mode { display: flex; align-items: center; justify-content: space-between; }
.composer-mode > span { display: flex; align-items: center; gap: 5px; color: #687587; font-size: 9px; font-weight: 650; }
.composer-mode .ui-icon { width: 13px; height: 13px; }
.composer-mode small { color: #9aa4b2; font-size: 7px; }
.composer textarea { min-height: 43px; max-height: 92px; padding: 5px 2px; border: 0; border-radius: 0; background: transparent; box-shadow: none; resize: none; font-size: 10px; }
.composer textarea:disabled { color: #a8b1bd; }
.composer-tools { display: flex; align-items: center; justify-content: space-between; }
.composer-tools > div { display: flex; align-items: center; gap: 4px; }
.tool-button, .attach-button, .send-button { border: 0; color: #778496; background: transparent; }
.tool-button { height: 27px; display: flex; align-items: center; gap: 5px; padding: 0 7px; border-radius: 5px; font-size: 8px; }
.tool-button:hover, .attach-button:hover { color: var(--blue); background: var(--blue-soft); }
.tool-button .ui-icon, .attach-button .ui-icon, .send-button .ui-icon { width: 16px; height: 16px; }
.attach-button { width: 29px; height: 27px; display: grid; place-items: center; border-radius: 5px; cursor: pointer; }
.send-button { width: 30px; height: 28px; display: grid; place-items: center; border-radius: 5px; color: #fff; background: var(--blue); }
.send-button:disabled { color: #b8c1cd; background: #edf0f4; }
.customer-detail { min-width: 0; overflow: hidden; border-left: 1px solid var(--line); background: #f8fafc; }
.customer-detail-head { height: 51px; display: flex; align-items: center; justify-content: space-between; padding: 0 10px 0 12px; border-bottom: 1px solid var(--line); background: #fff; }
.customer-detail-head strong { color: var(--ink-strong); font-size: 11px; }
.customer-detail-content { height: calc(100% - 51px); overflow-y: auto; padding: 9px; }
.empty-detail { min-height: 260px; display: grid; align-content: center; justify-items: center; color: var(--muted); text-align: center; font-size: 9px; }
.customer-card, .detail-section { margin-bottom: 8px; border: 1px solid #e3e8ef; border-radius: 7px; background: #fff; }
.customer-card { padding: 11px; }
.customer-identity { display: flex; align-items: center; gap: 9px; padding-bottom: 10px; border-bottom: 1px solid #edf0f4; }
.customer-identity strong, .customer-identity small { display: block; }
.customer-identity strong { color: #303c4d; font-size: 10px; }
.customer-identity small { margin-top: 3px; color: var(--muted); font-size: 8px; }
.customer-facts { display: grid; gap: 8px; padding-top: 10px; }
.customer-fact { display: grid; grid-template-columns: 62px minmax(0,1fr); gap: 6px; }
.customer-fact strong { overflow: hidden; color: #657184; font-size: 8px; font-weight: 600; text-overflow: ellipsis; white-space: nowrap; }
.detail-section > strong { display: block; padding: 9px 10px; border-bottom: 1px solid #edf0f4; color: #495669; font-size: 9px; }
.detail-section-content { padding: 10px; color: var(--muted); font-size: 8px; }
.detail-section-content .tag { display: inline-flex; margin: 0 4px 4px 0; padding: 3px 6px; border-radius: 4px; color: #5274a7; background: #edf4ff; }

/* Groups and operation consoles */
.group-layout { height: calc(100vh - 126px); min-height: 500px; display: grid; grid-template-columns: 290px minmax(0,1fr); gap: 10px; }
.group-browser, .panel-card { border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.group-browser { min-height: 0; overflow: hidden; }
.subpanel-head { height: 46px; display: flex; align-items: center; justify-content: space-between; padding: 0 12px; border-bottom: 1px solid var(--line); }
.subpanel-head strong { color: var(--ink-strong); font-size: 11px; }
.subpanel-head span { color: var(--muted); font-size: 8px; }
.group-list { height: calc(100% - 46px); min-height: 0; overflow-y: auto; padding: 6px; border: 0; }
.group-card { width: 100%; min-height: 52px; display: flex; align-items: center; gap: 9px; padding: 7px; border: 0; border-radius: 6px; background: transparent; text-align: left; }
.group-card:hover, .group-card.active { background: #edf4ff; }
.group-card .contact-avatar { width: 34px; height: 34px; flex-basis: 34px; }
.group-card span:last-child { min-width: 0; }
.group-card strong, .group-card small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.group-card strong { font-size: 10px; }
.group-card small { margin-top: 3px; color: var(--muted); font-size: 8px; }
.operation-console { max-width: 880px; padding: 18px; overflow-y: auto; }
.operation-head { display: flex; align-items: center; gap: 10px; margin-bottom: 17px; padding-bottom: 13px; border-bottom: 1px solid var(--line); }
.operation-icon, .dialog-icon { width: 34px; height: 34px; display: grid; place-items: center; border-radius: 8px; color: var(--blue); background: var(--blue-soft); }
.operation-icon .ui-icon, .dialog-icon .ui-icon { width: 18px; height: 18px; }
.operation-head strong { color: var(--ink-strong); font-size: 12px; }
.operation-head p { margin: 3px 0 0; color: var(--muted); font-size: 9px; }
.field-row { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 11px; }
.field-row + label, .operation-console > label { margin-top: 13px; }
.operation-console textarea { font: 10px/1.55 ui-monospace, SFMono-Regular, Menlo, monospace; }
.inline-help { min-height: 32px; margin: 10px 0 0; padding: 8px 9px; border-radius: 5px; color: #718096; background: #f5f7fa; font-size: 9px; line-height: 1.5; }
.dialog-actions { display: flex; align-items: center; justify-content: flex-end; gap: 7px; margin-top: 14px; }
.dialog-actions.spread { display: grid; grid-template-columns: auto 1fr auto auto; }
.dialog-actions.center { justify-content: center; }
.result-panel { min-height: 120px; max-height: 260px; overflow: auto; margin: 13px 0 0; padding: 11px; border: 1px solid #e2e7ef; border-radius: 6px; color: #5c6879; background: #f8fafc; font: 9px/1.6 ui-monospace, SFMono-Regular, Menlo, monospace; white-space: pre-wrap; }

/* Agents */
.agent-control-bar { margin-bottom: 0; padding: 0 4px 0 9px; border: 1px solid var(--line); border-radius: 7px 7px 0 0; background: #fff; }
.locked-switch { display: flex; align-items: center; gap: 8px; }
.locked-switch > .ui-icon { width: 17px; height: 17px; color: #8a96a6; }
.locked-switch span strong, .locked-switch span small { display: block; }
.locked-switch span strong { font-size: 9px; }
.locked-switch span small { margin-top: 2px; color: var(--muted); font-size: 7px; }
.locked-switch button { position: relative; width: 31px; height: 17px; padding: 0; border: 0; border-radius: 99px; background: #d7dde6; }
.locked-switch button:after { content: ""; position: absolute; top: 2px; left: 2px; width: 13px; height: 13px; border-radius: 50%; background: #fff; }
.agent-tabs { display: flex; align-items: center; gap: 2px; margin: 0 0 10px; padding: 3px; border: 1px solid var(--line); border-top: 0; background: #fff; }
.agent-tabs button { height: 32px; display: flex; align-items: center; gap: 7px; padding: 0 11px; border: 0; border-bottom: 2px solid transparent; color: #718095; background: transparent; font-size: 10px; }
.agent-tabs button.active { color: var(--blue); border-bottom-color: var(--blue); }
.agent-tabs .ui-icon { width: 15px; height: 15px; }
.agent-content { display: none; }
.agent-content.active { display: block; }
.agent-card { display: grid; grid-template-columns: 48px minmax(0,1fr); gap: 13px; padding: 17px; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.agent-card-icon { position: relative; width: 44px; height: 44px; display: grid; place-items: center; border-radius: 11px; color: var(--blue); background: var(--blue-soft); }
.agent-card-icon .ui-icon { width: 25px; height: 25px; }
.agent-card-icon i { position: absolute; right: -2px; bottom: -2px; width: 10px; height: 10px; border: 2px solid #fff; border-radius: 50%; background: var(--amber); }
.agent-card-title, .member-copy { display: flex; align-items: flex-start; justify-content: space-between; gap: 15px; }
.agent-card-title strong { color: var(--ink-strong); font-size: 13px; }
.agent-card-title p { margin: 4px 0 0; color: var(--muted); font-size: 9px; }
.runtime-badge { display: inline-flex; align-items: center; height: 23px; padding: 0 8px; border-radius: 99px; font-size: 8px; font-weight: 700; white-space: nowrap; }
.runtime-badge.draft { color: #6f53b5; background: #f1edff; }
.agent-metrics { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: 8px; margin-top: 14px; }
.agent-metrics span { padding: 10px; border-radius: 6px; background: #f7f9fc; }
.agent-metrics small, .agent-metrics strong { display: block; }
.agent-metrics small { color: var(--muted); font-size: 8px; }
.agent-metrics strong { margin-top: 4px; color: #4d5b6d; font-size: 10px; }
.agent-card-actions { display: flex; gap: 6px; margin-top: 12px; }
.info-banner { display: flex; gap: 10px; margin-top: 10px; padding: 12px; border: 1px solid #dce7f8; border-radius: 7px; color: #53647c; background: #f1f6ff; }
.info-banner .ui-icon { width: 17px; height: 17px; color: var(--blue); }
.info-banner strong { font-size: 10px; }
.info-banner p { margin: 4px 0 0; color: #718096; font-size: 9px; line-height: 1.55; }
.member-profile { padding: 18px; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.member-avatar { float: left; width: 46px; height: 46px; display: grid; place-items: center; margin-right: 12px; border-radius: 50%; color: #fff; background: #6d77cd; }
.member-avatar .ui-icon { width: 25px; height: 25px; }
.member-copy h3 { margin: 0; color: var(--ink-strong); font-size: 14px; }
.member-copy p { margin: 4px 0 0; color: var(--muted); font-size: 9px; }
.member-grid { clear: both; display: grid; grid-template-columns: repeat(4,minmax(0,1fr)); gap: 8px; padding: 18px 0 13px; }
.member-grid > div { padding: 11px; border: 1px solid #e6eaf0; border-radius: 6px; }
.member-grid small, .member-grid strong, .member-grid span { display: block; }
.member-grid small { color: var(--muted); font-size: 8px; }
.member-grid strong { margin-top: 5px; color: #4f5d70; font-size: 10px; }
.member-grid span { margin-top: 3px; color: #9aa5b3; font-size: 7px; }
.rule-grid { display: grid; grid-template-columns: repeat(4,minmax(0,1fr)); gap: 9px; }
.rule-grid article { padding: 14px; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.rule-grid .ui-icon { width: 21px; height: 21px; margin-bottom: 14px; color: var(--blue); }
.rule-grid strong { display: block; color: var(--ink-strong); font-size: 11px; }
.rule-grid p { min-height: 42px; margin: 6px 0 11px; color: var(--muted); font-size: 9px; line-height: 1.55; }
.rule-grid span { color: #8a5b12; font-size: 8px; font-weight: 700; }
.runtime-grid { display: grid; gap: 8px; }
.runtime-grid article { display: flex; align-items: center; gap: 11px; padding: 13px; border: 1px solid var(--line); border-radius: 7px; background: #fff; }
.runtime-grid article > .ui-icon { margin-left: auto; color: #9ba6b4; }
.runtime-dot { width: 10px; height: 10px; border-radius: 50%; background: #c3cbd6; box-shadow: 0 0 0 4px #f1f3f6; }
.runtime-dot.simulation { background: var(--blue); box-shadow: 0 0 0 4px var(--blue-soft); }
.runtime-dot.draft { background: #7d62c7; box-shadow: 0 0 0 4px #f1edff; }
.runtime-grid strong { font-size: 10px; }
.runtime-grid p { margin: 3px 0 0; color: var(--muted); font-size: 8px; }

/* Tools */
.workspace[data-page="social"] main, .workspace[data-page="user"] main, .workspace[data-page="wxapp"] main { padding: 7px; overflow: hidden; background: #f4f7fb; }
.tools-page.active { height: calc(100vh - 77px); display: grid; grid-template-columns: 190px minmax(0,1fr); overflow: hidden; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.tools-nav { padding: 10px 8px; border-right: 1px solid var(--line); background: #f7f9fc; }
.tools-nav > button { width: 100%; margin-top: 3px; }
.tool-workspace { min-width: 0; overflow-y: auto; padding: 16px; }
.tool-utility-bar { min-height: 32px; display: flex; align-items: center; justify-content: flex-end; margin-bottom: 7px; }
.safety-chip { height: 26px; display: flex; align-items: center; gap: 6px; padding: 0 8px; border-radius: 99px; color: #278458; background: var(--green-soft); font-size: 8px; font-weight: 650; }
.safety-chip.warning { color: #91600c; background: var(--amber-soft); }
.safety-chip .ui-icon { width: 13px; height: 13px; }

/* Audit */
.audit-scope { margin-bottom: 8px; }
.audit-scope span { display: inline-flex; align-items: center; gap: 7px; padding: 7px 9px; border-radius: 5px; color: #617086; background: #eef4fd; font-size: 9px; }
.audit-scope .ui-icon { width: 14px; height: 14px; color: var(--blue); }
.log-list { min-height: calc(100vh - 168px); overflow: auto; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.log-row { min-height: 43px; display: grid; grid-template-columns: 155px 200px minmax(0,1fr); align-items: center; gap: 10px; padding: 0 13px; border-bottom: 1px solid #edf0f4; font-size: 9px; }
.log-row:hover { background: #f8faff; }
.log-row time { color: var(--muted); }
.log-row strong { color: #4e5c6e; }
.log-row span { overflow: hidden; color: #8792a2; text-overflow: ellipsis; white-space: nowrap; }

/* Dialogs and toast */
dialog { max-width: calc(100vw - 24px); padding: 0; border: 0; border-radius: 10px; color: var(--ink); box-shadow: 0 28px 90px rgba(25,43,70,.25); }
dialog::backdrop { background: rgba(30,42,61,.48); backdrop-filter: blur(2px); }
.dialog-card { position: relative; width: 430px; max-width: 100%; padding: 23px; background: #fff; }
.dialog-card h3 { margin: 13px 0 5px; color: var(--ink-strong); font-size: 18px; }
.dialog-card > p { margin: 0 0 18px; color: var(--muted); font-size: 10px; line-height: 1.55; }
.dialog-card > label { margin: 13px 0; }
.dialog-close { position: absolute; top: 13px; right: 13px; width: 30px; height: 30px; display: grid; place-items: center; padding: 0; border: 0; border-radius: 6px; color: #8995a5; background: transparent; }
.dialog-close:hover { background: #f2f4f7; }
.dialog-close .ui-icon { width: 18px; height: 18px; }
.proxy-fields { margin: 16px 0 0; padding: 13px; border: 1px solid var(--line); border-radius: 7px; }
.proxy-fields legend { padding: 0 5px; color: #5a687b; font-size: 10px; font-weight: 700; }
.proxy-fields p, .network-help { margin: 0 0 10px; color: var(--muted); font-size: 9px; line-height: 1.5; }
.proxy-fields label { margin: 10px 0; }
.qr-card { width: 400px; text-align: center; }
.qr-card .dialog-icon { margin: 0 auto; }
.qr-stage { width: 224px; height: 224px; display: grid; place-items: center; margin: 17px auto 12px; padding: 11px; border: 1px solid var(--line); border-radius: 8px; background: #f8fafc; }
.qr-stage img { width: 100%; height: 100%; object-fit: contain; }
.qr-card > strong { display: block; font-size: 11px; }
.qr-card #qr-note { min-height: 33px; margin: 6px auto 0; }
.qr-card .login-mark { width: 58px; height: 58px; display: grid; place-items: center; margin: auto; border-radius: 50%; color: #fff; background: var(--green); }
.qr-card .login-mark .ui-icon { width: 30px; height: 30px; }
.spinner { width: 28px; height: 28px; border: 3px solid #dce3ed; border-top-color: var(--blue); border-radius: 50%; animation: spin .75s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.toast { position: fixed; right: 18px; bottom: 18px; z-index: 100; max-width: min(420px,calc(100vw - 36px)); padding: 10px 13px; border-radius: 7px; color: #fff; background: #27364a; box-shadow: 0 14px 40px rgba(25,38,57,.25); font-size: 10px; opacity: 0; pointer-events: none; transform: translateY(8px); transition: .2s; }
.toast.show { opacity: 1; transform: none; }
.toast.error { background: #a93f3f; }
.customer-cell.action { justify-content: flex-start; gap: 9px; }
.customer-cell.action button { flex: 0 0 auto; border: 0; color: var(--blue); background: transparent; font-size: 9px; cursor: pointer; }
.status-online, .status-offline { display: inline-flex; align-items: center; gap: 5px; white-space: nowrap; font-size: 9px; }
.status-online { color: #23905c; }
.status-offline { color: #909aaa; }
.status-online::before, .status-offline::before { width: 6px; height: 6px; border-radius: 50%; background: currentColor; content: ""; }
.header-action:disabled { color: #aab3c0; background: #f5f7fa; cursor: not-allowed; opacity: .72; }
.mobile-nav { display: none; }

@media (min-width: 1800px) {
  .messages-page.active { grid-template-columns: 204px 350px minmax(500px,1fr) 330px; }
  .workspace main { padding: 20px 22px 30px; }
  .workspace[data-page="messages"] main, .workspace[data-page="social"] main, .workspace[data-page="user"] main, .workspace[data-page="wxapp"] main { padding: 7px; }
  .peer { min-height: 63px; }
}

@media (max-width: 1280px) {
  .messages-page.active { grid-template-columns: 150px 270px minmax(360px,1fr) 250px; }
  .instance-grid { grid-template-columns: repeat(2,minmax(260px,1fr)); }
  .member-grid, .rule-grid { grid-template-columns: repeat(2,minmax(0,1fr)); }
}

@media (max-width: 1060px) {
  .messages-page.active { grid-template-columns: 58px 260px minmax(350px,1fr); }
  .chat-navigation { padding-left: 5px; padding-right: 5px; }
  .chat-navigation .module-title, .chat-navigation nav button span, .chat-navigation nav button small, .chat-navigation .rail-divider, .chat-navigation .rail-runtime { display: none; }
  .chat-navigation nav button { justify-content: center; padding: 0; }
  .customer-detail { display: none; }
  .summary-grid { grid-template-columns: repeat(2,minmax(0,1fr)); }
  .topbar { padding-left: 12px; }
  .page-heading p, .connection span, .instance-switch > span { display: none; }
}

@media (max-width: 820px) {
  .login-view { display: block; padding-top: 9vh; }
  .login-art { display: none; }
  .login-card { width: min(420px,calc(100% - 38px)); }
  .login-card-head { margin-bottom: 38px; }
  .app-shell { display: block; padding: 0; background: #fff; }
  .sidebar { display: none; }
  .workspace { min-height: 100vh; border: 0; border-radius: 0; }
  .topbar { height: 56px; padding: 0 12px; }
  .page-heading h2, .page-heading p { display: none; }
  .mobile-brand { display: block; color: var(--ink-strong); font-size: 14px; font-weight: 750; }
  .instance-switch select { width: 92px; }
  #current-instance-status, .connection { display: none; }
  .workspace main { height: auto; min-height: calc(100vh - 56px); padding: 13px 11px 78px; overflow: visible; }
  .workspace[data-page="messages"] main, .workspace[data-page="social"] main, .workspace[data-page="user"] main, .workspace[data-page="wxapp"] main { padding: 8px 8px 78px; overflow: visible; }
  .summary-grid { gap: 7px; }
  .metric { min-height: 84px; }
  .instance-grid { grid-template-columns: 1fr; }
  .status-legend { display: none; }
  .data-toolbar { height: auto; align-items: stretch; flex-wrap: wrap; }
  .search-box { width: 100%; }
  .contact-filter-bar { flex: 1; overflow-x: auto; }
  .toolbar-count { display: none; }
  .data-panel, .contact-grid { min-height: 560px; }
  .messages-page.active { height: auto; min-height: 0; display: block; overflow: visible; }
  .module-rail, .customer-detail { display: none; }
  .conversation-list { min-height: 420px; border-right: 0; }
  .chat-panel { min-height: 600px; grid-template-rows: 51px 420px 126px; border-top: 1px solid var(--line); }
  .group-layout { height: auto; display: block; }
  .group-browser { min-height: 260px; margin-bottom: 8px; }
  .group-list { height: 220px; }
  .field-row { grid-template-columns: 1fr; }
  .agent-card { grid-template-columns: 1fr; }
  .agent-metrics, .member-grid, .rule-grid { grid-template-columns: 1fr; }
  .tools-page.active { height: auto; min-height: 650px; display: block; }
  .tools-nav { display: flex; gap: 4px; overflow-x: auto; border-right: 0; border-bottom: 1px solid var(--line); }
  .tools-nav .module-title { display: none; }
  .tools-nav > button { width: auto; flex: 0 0 auto; margin: 0; }
  .tool-workspace { overflow: visible; padding: 12px; }
  .mobile-nav { position: fixed; inset: auto 0 0; z-index: 50; display: grid; grid-template-columns: repeat(5,1fr); padding: 5px 6px calc(5px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); background: rgba(255,255,255,.96); backdrop-filter: blur(12px); }
  .mobile-nav button { height: 47px; display: grid; place-items: center; gap: 2px; padding: 3px; border: 0; color: #8591a2; background: transparent; font-size: 8px; }
  .mobile-nav button .ui-icon { width: 18px; height: 18px; }
  .mobile-nav button.active { color: var(--blue); }
  .log-row { min-height: 54px; grid-template-columns: 1fr; align-content: center; gap: 2px; }
}

@media (max-width: 520px) {
  .summary-grid { grid-template-columns: 1fr 1fr; }
  .instance-switch { display: none; }
  .chat-head .header-action span { display: none; }
  .chat-head .header-action { width: 30px; justify-content: center; padding: 0; }
  .conversation-list { min-height: 380px; }
  .chat-panel { min-height: 560px; grid-template-rows: 51px 380px 126px; }
  .customer-row { grid-template-columns: 38px minmax(170px,1.4fr) 80px 82px; }
  .customer-row .customer-cell:nth-child(3), .customer-row .customer-cell:nth-child(4), .customer-row .customer-cell:nth-child(6) { display: none; }
  .dialog-card { padding: 19px; }
  .qr-stage { width: 205px; height: 205px; }
}
