:root {
  --brand: #b11f24;
  --brand-600: #9b1a1f;
  --brand-700: #82151a;
  --brand-50: #fdf1f1;
  --brand-100: #f9dcdd;
  --brand-200: #f0b7b9;
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f8f9fb;
  --surface-3: #f0f2f5;
  --border: #e6e8ec;
  --border-soft: #eff1f4;
  --border-strong: #d4d8de;
  --text: #1d2129;
  --text-2: #4a5160;
  --muted: #6e7583;
  --primary: var(--brand);
  --primary-2: var(--brand-600);
  --primary-soft: var(--brand-50);
  --success: #177a43;
  --success-soft: #edf8f1;
  --success-border: #c3e8d1;
  --warn: #a45a07;
  --warn-soft: #fff7e8;
  --warn-border: #f6dca6;
  --danger: #c62828;
  --danger-soft: #fdeeee;
  --danger-border: #f5c2c2;
  --ai: #6d3fd6;
  --ai-soft: #f4f0ff;
  --ai-border: #e0d6fb;
  --wa: #21a452;
  --ig: #d42a76;
  --note: #fffbea;
  --radius: 8px;
  --radius-lg: 12px;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.05);
  --shadow: 0 1px 3px rgba(16, 24, 40, 0.06), 0 1px 2px rgba(16, 24, 40, 0.04);
  --shadow-md: 0 6px 16px rgba(16, 24, 40, 0.08);
  --shadow-lg: 0 18px 48px rgba(16, 24, 40, 0.18);
  --appbar: 56px;
  --rail: 84px;
  --h: 36px;
  --h-sm: 30px;
  --font: "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; font-family: var(--font); font-size: 14px; line-height: 1.45; color: var(--text); background: var(--bg); -webkit-font-smoothing: antialiased; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0 0 8px; line-height: 1.3; font-weight: 700; color: var(--text); }
h2 { font-size: 17px; }
h3 { font-size: 15px; }
p { margin: 0 0 8px; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.spacer { flex: 1; }
.center { text-align: center; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; }
.nowrap { white-space: nowrap; }
.pre { white-space: pre-wrap; word-break: break-word; }
::selection { background: var(--brand-100); }

.icon { width: 18px; height: 18px; flex: none; }
.icon.xl { width: 44px; height: 44px; }

.appbar { position: fixed; top: 0; left: 0; right: 0; height: var(--appbar); background: var(--brand); color: #fff; display: flex; align-items: center; gap: 14px; padding: 0 16px 0 0; z-index: 40; box-shadow: 0 1px 0 rgba(0, 0, 0, 0.08); }
.brand { width: var(--rail); flex: none; height: 100%; display: flex; align-items: center; justify-content: center; padding-left: 14px; }
.brand-logo { height: 26px; width: auto; display: block; }
.brand:hover { text-decoration: none; }
.appbar .brand { width: auto; padding: 0 4px 0 20px; }
.appbar-divider { width: 1px; height: 24px; background: rgba(255, 255, 255, 0.28); flex: none; }
.page-title { font-size: 16px; font-weight: 600; margin: 0; color: #fff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 6px; }
.appbar .icon-btn { color: #fff; }
.appbar .icon-btn:hover { background: rgba(255, 255, 255, 0.14); }
.appbar .badge { background: #fff; color: var(--brand); box-shadow: 0 0 0 2px var(--brand); }
.rt-status { display: inline-flex; align-items: center; gap: 7px; height: 28px; padding: 0 11px; border-radius: 999px; background: rgba(255, 255, 255, 0.14); font-size: 12px; font-weight: 500; margin-right: 6px; }
.rt-status .dot { width: 8px; height: 8px; border-radius: 50%; background: #fbbf24; box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.25); }
.rt-status.ok .dot { background: #4ade80; }
.rt-status.down .dot { background: #fecaca; }
.user-btn { display: flex; align-items: center; gap: 10px; background: none; border: 0; cursor: pointer; padding: 4px 8px 4px 4px; border-radius: 999px; color: #fff; font: inherit; text-align: left; }
.user-btn:hover { background: rgba(255, 255, 255, 0.14); }
.user-btn .avatar { background: #fff; color: var(--brand); }
.user-meta { display: flex; flex-direction: column; line-height: 1.15; }
.user-name { font-size: 13px; font-weight: 600; }
.user-role { font-size: 11px; opacity: 0.8; }

.shell { padding-top: var(--appbar); min-height: 100vh; }
.rail { position: fixed; top: var(--appbar); bottom: 0; left: 0; width: var(--rail); background: var(--surface); border-right: 1px solid var(--border); z-index: 30; display: flex; flex-direction: column; }
.nav { display: flex; flex-direction: column; gap: 4px; padding: 12px 10px; flex: 1; }
.nav-item { position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 5px; padding: 10px 4px 9px; border-radius: 10px; color: var(--text-2); font-size: 11px; font-weight: 600; text-align: center; line-height: 1.15; }
.nav-item .icon { width: 22px; height: 22px; }
.nav-item:hover { background: var(--surface-3); color: var(--text); text-decoration: none; }
.nav-item.active { background: var(--brand); color: #fff; box-shadow: 0 4px 10px rgba(177, 31, 36, 0.28); }
.nav-bottom { margin-top: auto; }
.nav-badge { position: absolute; top: 4px; right: 8px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--brand); color: #fff; font-size: 10px; font-weight: 700; display: inline-flex; align-items: center; justify-content: center; box-shadow: 0 0 0 2px var(--surface); }
.nav-item.active .nav-badge { background: #fff; color: var(--brand); box-shadow: 0 0 0 2px var(--brand); }
.rail-backdrop { display: none; }

.content { margin-left: var(--rail); padding: 22px 24px; min-height: calc(100vh - var(--appbar)); }
.page-inbox .content { padding: 0; height: calc(100vh - var(--appbar)); min-height: 0; overflow: hidden; }

.icon-btn { position: relative; background: none; border: 0; width: 36px; height: 36px; padding: 0; border-radius: 8px; color: var(--text-2); cursor: pointer; display: inline-flex; align-items: center; justify-content: center; flex: none; }
.icon-btn:hover { background: var(--surface-3); color: var(--text); }
.badge { position: absolute; top: 3px; right: 2px; background: var(--brand); color: #fff; font-size: 10px; min-width: 17px; height: 17px; border-radius: 9px; display: inline-flex; align-items: center; justify-content: center; padding: 0 4px; font-weight: 700; }
.avatar { width: 40px; height: 40px; border-radius: 50%; background: var(--brand-100); color: var(--brand-700); display: inline-flex; align-items: center; justify-content: center; font-weight: 700; flex: none; font-size: 14px; letter-spacing: 0.02em; }
.avatar.sm { width: 30px; height: 30px; font-size: 12px; }
.avatar.xs { width: 20px; height: 20px; font-size: 9px; }
.avatar.ig { background: #fce7f1; color: #9d1e56; }
.avatar-wrap { position: relative; display: inline-flex; flex: none; }
.ch-badge { position: absolute; right: -3px; bottom: -3px; width: 18px; height: 18px; border-radius: 50%; color: #fff; font-size: 7.5px; font-weight: 800; display: inline-flex; align-items: center; justify-content: center; box-shadow: 0 0 0 2px var(--surface); letter-spacing: 0; }
.ch-badge.wa { background: var(--wa); }
.ch-badge.ig { background: var(--ig); }
.only-mobile { display: none; }

.dropdown { position: relative; }
.dropdown-panel { position: absolute; right: 0; top: calc(100% + 8px); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); min-width: 240px; z-index: 50; overflow: hidden; color: var(--text); }
.dropdown-head { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--border); gap: 12px; }
.dropdown-item { display: block; width: 100%; text-align: left; padding: 10px 16px; background: none; border: 0; color: var(--text); cursor: pointer; font: inherit; }
.dropdown-item:hover { background: var(--surface-2); text-decoration: none; }
.dropdown-item.danger { color: var(--danger); }
.notif-panel { width: 380px; }
.notif-list { max-height: 440px; overflow-y: auto; }
.notif-item { display: block; padding: 12px 16px; border-bottom: 1px solid var(--border-soft); color: var(--text); cursor: pointer; }
.notif-item:hover { background: var(--surface-2); text-decoration: none; }
.notif-item.unread { background: var(--brand-50); box-shadow: inset 3px 0 0 var(--brand); }
.notif-item .title { font-weight: 600; }
.notif-item .body { color: var(--text-2); font-size: 13px; }
.notif-empty { padding: 28px; text-align: center; color: var(--muted); }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: var(--h); padding: 0 14px; border-radius: var(--radius); border: 1px solid var(--border-strong); background: var(--surface); color: var(--text); font: inherit; font-size: 13px; font-weight: 600; cursor: pointer; white-space: nowrap; line-height: 1; transition: background 0.12s, border-color 0.12s, box-shadow 0.12s; }
.btn .icon { width: 16px; height: 16px; }
.btn:hover { background: var(--surface-2); border-color: #c3c8d0; text-decoration: none; }
.btn:focus-visible, .icon-btn:focus-visible, .tab:focus-visible, .seg:focus-visible { outline: 2px solid var(--brand-200); outline-offset: 1px; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-600); border-color: var(--brand-600); }
.btn.danger { color: var(--danger); border-color: var(--danger-border); background: var(--surface); }
.btn.danger:hover { background: var(--danger-soft); }
.btn.success { color: var(--success); border-color: var(--success-border); }
.btn.success:hover { background: var(--success-soft); }
.btn.ai { color: var(--ai); border-color: var(--ai-border); }
.btn.ai:hover { background: var(--ai-soft); }
.btn.sm { height: var(--h-sm); padding: 0 11px; font-size: 12px; border-radius: 7px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.link-btn { background: none; border: 0; color: var(--brand); cursor: pointer; font: inherit; font-size: 12px; font-weight: 600; padding: 0; }
.link-btn:hover { text-decoration: underline; }

.input { width: 100%; height: var(--h); padding: 0 12px; border: 1px solid var(--border-strong); border-radius: var(--radius); font: inherit; font-size: 13px; background: var(--surface); color: var(--text); transition: border-color 0.12s, box-shadow 0.12s; }
select.input { padding-right: 28px; }
.input::placeholder { color: #9aa1ad; }
.input:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(177, 31, 36, 0.12); }
.input:disabled { background: var(--surface-2); color: var(--muted); }
.input.sm { height: var(--h-sm); padding: 0 10px; font-size: 12.5px; width: auto; border-radius: 7px; }
select.input.sm { padding-right: 24px; }
textarea.input { height: auto; min-height: 76px; padding: 8px 12px; resize: vertical; line-height: 1.45; }
.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 14px; }
.field > span { font-size: 12px; font-weight: 600; color: var(--text-2); }
.field.inline { flex-direction: row; align-items: center; margin: 0; gap: 8px; }
.field.inline > span { white-space: nowrap; }
.field .help { font-size: 12px; color: var(--muted); font-weight: 400; }
.check { display: inline-flex; align-items: center; gap: 7px; font-size: 13px; color: var(--text-2); cursor: pointer; }
.check input { accent-color: var(--brand); width: 15px; height: 15px; margin: 0; }
input[type="checkbox"], input[type="radio"] { accent-color: var(--brand); }
.form-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 6px; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0 16px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 0 16px; align-items: end; }
.grid-4 .check { height: var(--h); margin-bottom: 14px; }
.span-2 { grid-column: span 2; }
.span-all { grid-column: 1 / -1; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 20px; margin-bottom: 18px; box-shadow: var(--shadow-sm); }
.card-head { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 16px; gap: 16px; }
.card-head h2 { margin-bottom: 4px; }
.card-head p { margin: 0; }
.alert { padding: 10px 14px; border-radius: var(--radius); margin-bottom: 14px; font-size: 13px; border: 1px solid transparent; }
.alert.error { background: var(--danger-soft); color: var(--danger); border-color: var(--danger-border); }
.alert.warn { background: var(--warn-soft); color: var(--warn); border-color: var(--warn-border); }
.alert.info { background: #eef4ff; color: #2451a6; border-color: #cddcfb; }
.alert.success { background: var(--success-soft); color: var(--success); border-color: var(--success-border); }
.alert.slim { margin: 0 20px 12px; padding: 7px 12px; }

.chip { display: inline-flex; align-items: center; gap: 4px; height: 20px; padding: 0 8px; border-radius: 999px; font-size: 11px; font-weight: 600; background: var(--surface-3); color: var(--text-2); border: 1px solid transparent; white-space: nowrap; line-height: 1; }
.chip.ai { background: var(--ai-soft); color: var(--ai); border-color: var(--ai-border); }
.chip.human { background: var(--success-soft); color: var(--success); border-color: var(--success-border); }
.chip.warn { background: var(--warn-soft); color: var(--warn); border-color: var(--warn-border); }
.chip.danger { background: var(--danger-soft); color: var(--danger); border-color: var(--danger-border); }
.chip.blue { background: var(--brand-50); color: var(--brand-700); border-color: var(--brand-100); }
.chip.outline { background: var(--surface); color: var(--brand-700); border-color: var(--brand-200); }
.chip.tag { color: #fff; border: 0; }
.chip .x { cursor: pointer; opacity: 0.75; }
.priority-3 { color: var(--danger); }
.priority-2 { color: var(--warn); }

.toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; }
.toolbar > .input:not(.sm) { width: 280px; }
.toolbar .input.sm { height: var(--h); font-size: 13px; }
.toolbar .field.inline > span { font-size: 12px; color: var(--muted); }
.segmented { display: inline-flex; height: var(--h); border: 1px solid var(--border-strong); border-radius: var(--radius); overflow: hidden; background: var(--surface); }
.seg { border: 0; background: none; padding: 0 14px; font: inherit; font-size: 13px; font-weight: 500; cursor: pointer; color: var(--text-2); border-right: 1px solid var(--border); }
.seg:last-child { border-right: 0; }
.seg:hover { background: var(--surface-2); }
.seg.active { background: var(--brand-50); color: var(--brand-700); font-weight: 700; }

.table-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); overflow: auto; box-shadow: var(--shadow-sm); }
.card .table-wrap { box-shadow: none; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 11px 14px; text-align: left; border-bottom: 1px solid var(--border-soft); vertical-align: middle; }
.table th { font-size: 12px; color: var(--muted); background: var(--surface-2); font-weight: 600; position: sticky; top: 0; z-index: 1; white-space: nowrap; border-bottom-color: var(--border); }
.table tbody tr:last-child td { border-bottom: 0; }
.table tr.clickable { cursor: pointer; }
.table tbody tr:hover td { background: #fbfbfc; }
.table tr.clickable:hover td { background: var(--brand-50); }
.table td.num, .table th.num { text-align: right; }
.table td .btn + .btn { margin-left: 6px; }
.pager { display: flex; justify-content: flex-end; align-items: center; gap: 8px; margin-top: 14px; }

.inbox { display: grid; grid-template-columns: 360px minmax(0, 1fr) 340px; grid-template-rows: minmax(0, 1fr); height: 100%; overflow: hidden; }
.inbox.no-profile { grid-template-columns: 360px minmax(0, 1fr); }
.inbox-list { border-right: 1px solid var(--border); background: var(--surface); display: flex; flex-direction: column; min-height: 0; }
.list-head { border-bottom: 1px solid var(--border); }
.inbox-tabs { display: flex; gap: 0; padding: 0 9px; border-bottom: 1px solid var(--border-soft); overflow-x: auto; scrollbar-width: none; }
.inbox-tabs::-webkit-scrollbar { display: none; }
.tab { flex: none; border: 0; background: none; padding: 14px 7px 12px; font: inherit; font-size: 13px; font-weight: 600; color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; white-space: nowrap; display: inline-flex; align-items: center; gap: 6px; margin-bottom: -1px; }
.tab:hover { color: var(--text); }
.tab.active { color: var(--brand); border-bottom-color: var(--brand); }
.tab .count { display: inline-flex; align-items: center; justify-content: center; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--brand); color: #fff; font-size: 10px; font-weight: 700; }
.tab .count:empty { display: none; }
.list-search { display: flex; gap: 8px; padding: 12px 16px; align-items: center; }
.search-box { flex: 1; display: flex; align-items: center; gap: 8px; height: var(--h); padding: 0 12px; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); color: var(--muted); cursor: text; transition: border-color 0.12s, box-shadow 0.12s, background 0.12s; }
.search-box:focus-within { background: var(--surface); border-color: var(--brand); box-shadow: 0 0 0 3px rgba(177, 31, 36, 0.12); }
.search-box .icon { width: 16px; height: 16px; }
.search-box input { flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; font: inherit; font-size: 13px; color: var(--text); height: 100%; }
.filter-btn { border: 1px solid var(--border); background: var(--surface); }
.filter-btn.on { color: var(--brand); border-color: var(--brand-200); background: var(--brand-50); }
.filter-count { position: absolute; top: -6px; right: -6px; min-width: 17px; height: 17px; padding: 0 4px; border-radius: 9px; background: var(--brand); color: #fff; font-size: 10px; font-weight: 700; display: inline-flex; align-items: center; justify-content: center; box-shadow: 0 0 0 2px var(--surface); }
.inbox-filters { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px 10px; padding: 0 16px 14px; }
.mini-field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.mini-field > span { font-size: 11px; font-weight: 600; color: var(--muted); }
.mini-field .input.sm { width: 100%; }
.inbox-filters .link-btn { grid-column: 1 / -1; justify-self: end; }
.conv-list { flex: 1; overflow-y: auto; }
.conv-item { display: flex; gap: 12px; padding: 13px 16px; border-bottom: 1px solid var(--border-soft); cursor: pointer; position: relative; transition: background 0.1s; }
.conv-item:hover { background: var(--surface-2); }
.conv-item.active { background: var(--brand-50); box-shadow: inset 3px 0 0 var(--brand); }
.conv-item.flash { animation: flash 1.2s ease-out; }
@keyframes flash { from { background: #fff4d6; } to { background: transparent; } }
.conv-item.waiting:not(.active)::before { content: ""; position: absolute; left: 0; top: 12px; bottom: 12px; width: 3px; border-radius: 0 3px 3px 0; background: #f0a92e; }
.conv-item.priority-high:not(.active)::before { background: var(--danger); }
.conv-item .avatar-wrap { align-self: flex-start; margin-top: 2px; }
.conv-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.conv-top { display: flex; justify-content: space-between; gap: 8px; align-items: center; }
.conv-name { font-weight: 700; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-item.active .conv-name { color: var(--brand-700); }
.conv-time { font-size: 11px; color: var(--muted); white-space: nowrap; flex: none; }
.conv-mid { display: flex; align-items: center; gap: 8px; }
.conv-preview { flex: 1; min-width: 0; color: var(--text-2); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-preview.unread { color: var(--text); font-weight: 600; }
.conv-bottom { display: flex; align-items: center; gap: 8px; min-height: 20px; }
.conv-source { flex: 1; min-width: 0; font-size: 11.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-chips { display: flex; gap: 4px; align-items: center; flex-wrap: nowrap; overflow: hidden; flex: none; max-width: 70%; }
.conv-meta { display: flex; gap: 4px; flex-wrap: wrap; align-items: center; }
.unread-dot { flex: none; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px; background: var(--brand); color: #fff; font-size: 10.5px; font-weight: 700; display: inline-flex; align-items: center; justify-content: center; }
.load-more { border: 0; background: var(--surface-2); padding: 10px; cursor: pointer; font: inherit; font-weight: 600; color: var(--brand); border-top: 1px solid var(--border); }
.list-empty { padding: 40px 16px; text-align: center; color: var(--muted); }
.list-foot { display: flex; align-items: center; gap: 6px; padding: 11px 16px; border-top: 1px solid var(--border); font-size: 12px; color: var(--muted); background: var(--surface); }
.foot-count { color: var(--brand); font-size: 13px; }
.foot-count:empty::after { content: "0"; color: var(--muted); }

.thread { display: flex; flex-direction: column; min-height: 0; background: var(--bg); }
.empty-state { margin: auto; text-align: center; color: var(--muted); max-width: 320px; padding: 24px; }
.empty-state h3 { margin-top: 14px; color: var(--text); }
.empty-illus { width: 88px; height: 88px; border-radius: 50%; background: var(--brand-50); color: var(--brand); display: inline-flex; align-items: center; justify-content: center; box-shadow: 0 0 0 10px rgba(177, 31, 36, 0.04); }
.thread-head { background: var(--surface); border-bottom: 1px solid var(--border); flex: none; }
.thread-bar { display: flex; align-items: center; gap: 12px; padding: 12px 16px 12px 20px; }
.thread-who { flex: 1; min-width: 0; }
.thread-name-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.thread-name-row .name { font-weight: 700; font-size: 15px; }
.thread-sub { font-size: 12px; color: var(--muted); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.thread-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; padding: 9px 20px; border-top: 1px solid var(--border-soft); background: var(--surface-2); }
.toolbar-group { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.inline-label { display: inline-flex; align-items: center; gap: 7px; font-size: 12px; color: var(--muted); }
.inline-label strong { color: var(--text); font-size: 13px; }
.inline-label .input.sm { max-width: 180px; background: var(--surface); }
.owner-pill { display: inline-flex; align-items: center; gap: 6px; height: var(--h-sm); padding: 0 10px 0 5px; border-radius: 999px; background: var(--surface); border: 1px solid var(--border); color: var(--text); font-size: 12px; font-weight: 600; }
.presence { font-size: 12px; color: var(--warn); padding: 0 20px 8px; }
.presence:empty { display: none; }
.thread-title { display: flex; align-items: center; gap: 10px; min-width: 0; }
.thread-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.thread-actions .input.sm { max-width: 180px; }
.messages { flex: 1; overflow-y: auto; padding: 20px 24px; display: flex; flex-direction: column; gap: 8px; }
.msg { max-width: 64%; padding: 9px 12px 7px; border-radius: 12px 12px 12px 4px; background: var(--surface); border: 1px solid var(--border); align-self: flex-start; word-wrap: break-word; overflow-wrap: anywhere; box-shadow: var(--shadow-sm); }
.msg.out { align-self: flex-end; background: var(--brand-50); border-color: var(--brand-100); border-radius: 12px 12px 4px 12px; }
.msg.out.ai { background: var(--ai-soft); border-color: var(--ai-border); }
.msg.out.device { background: var(--success-soft); border-color: var(--success-border); }
.msg.note { align-self: center; background: var(--note); border: 1px dashed #e9c451; max-width: 80%; border-radius: 10px; }
.msg.system { align-self: center; background: transparent; border: 0; box-shadow: none; color: var(--muted); font-size: 12px; text-align: center; padding: 2px 8px; max-width: 90%; }
.msg .sender { font-size: 11px; font-weight: 700; color: var(--brand-700); margin-bottom: 3px; }
.msg.ai .sender { color: var(--ai); }
.msg.device .sender { color: var(--success); }
.msg.note .sender { color: var(--warn); }
.msg .text { white-space: pre-wrap; }
.msg .foot { font-size: 10.5px; color: var(--muted); text-align: right; margin-top: 4px; display: flex; gap: 6px; justify-content: flex-end; align-items: center; }
.msg .status.failed { color: var(--danger); font-weight: 700; }
.msg img.media { max-width: 260px; max-height: 260px; border-radius: 8px; display: block; margin-bottom: 4px; cursor: zoom-in; }
.msg video.media, .msg audio.media { max-width: 280px; display: block; margin-bottom: 4px; }
.msg .file { display: inline-flex; gap: 6px; align-items: center; padding: 6px 8px; background: rgba(255, 255, 255, 0.7); border-radius: 6px; margin-bottom: 4px; }
.day-sep { align-self: center; font-size: 11px; font-weight: 600; color: var(--muted); background: var(--surface); border: 1px solid var(--border); padding: 3px 12px; border-radius: 999px; margin: 8px 0; }
.load-older { align-self: center; }
.composer { background: var(--surface); border-top: 1px solid var(--border); padding: 12px 20px 12px; flex: none; }
.composer.internal { background: #fffdf2; }
.composer-row { display: flex; gap: 6px; align-items: flex-end; border: 1px solid var(--border-strong); border-radius: var(--radius-lg); padding: 6px 6px 6px 6px; background: var(--surface); transition: border-color 0.12s, box-shadow 0.12s; }
.composer-row:focus-within { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(177, 31, 36, 0.12); }
.composer.internal .composer-row { border-color: #e9c451; background: #fffdf2; }
.composer textarea.input { flex: 1; resize: none; min-height: 36px; max-height: 180px; border: 0; box-shadow: none; padding: 8px 6px; background: transparent; }
.composer textarea.input:focus { box-shadow: none; }
.send-btn { width: 38px; height: 38px; padding: 0; border-radius: 10px; }
.attach-btn { width: 38px; height: 38px; }
.composer { position: relative; }
.qr-pop { position: absolute; left: 20px; right: 20px; bottom: calc(100% - 4px); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); z-index: 15; overflow: hidden; }
.qr-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; padding: 10px 14px; border-bottom: 1px solid var(--border-soft); background: var(--surface-2); }
.qr-list { max-height: 300px; overflow-y: auto; padding: 6px; }
.qr-item { display: flex; flex-direction: column; gap: 2px; width: 100%; text-align: left; background: none; border: 0; border-radius: var(--radius); padding: 8px 10px; cursor: pointer; font: inherit; color: var(--text); }
.qr-item:hover, .qr-item.active { background: var(--brand-50); }
.qr-title { font-weight: 600; font-size: 13px; display: flex; gap: 8px; align-items: center; }
.qr-key { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 11.5px; color: var(--brand-700); background: var(--brand-100); padding: 1px 6px; border-radius: 5px; }
.qr-body { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.qr-empty { padding: 14px; color: var(--muted); font-size: 13px; }
.avatar.group { background: #e8eefc; color: #3056b8; }
.avatar.group .icon { width: 20px; height: 20px; }
.msg.group-in .sender { color: #3056b8; }
.embed-code { display: block; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 12px; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12px; white-space: pre-wrap; word-break: break-all; }
.key-reveal { background: var(--warn-soft); border: 1px solid var(--warn-border); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 14px; }
.key-reveal code { display: block; margin-top: 6px; font-size: 13px; font-weight: 700; word-break: break-all; }
.composer-opts { display: flex; gap: 16px; align-items: center; margin-top: 8px; font-size: 12px; flex-wrap: wrap; }
.composer-blocked { padding: 10px 20px; background: var(--warn-soft); color: var(--warn); border-top: 1px solid var(--warn-border); font-size: 13px; display: flex; gap: 10px; align-items: center; }
.attach-preview { display: flex; gap: 8px; align-items: center; font-size: 12px; margin-bottom: 8px; }

.profile-panel { border-left: 1px solid var(--border); background: var(--surface); overflow-y: auto; }
.profile-section { border-bottom: 1px solid var(--border-soft); padding: 16px 18px; }
.profile-section:last-child { border-bottom: 0; }
.profile-section h4 { font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin-bottom: 10px; display: flex; justify-content: space-between; align-items: center; }
.kv { display: grid; grid-template-columns: 112px minmax(0, 1fr); gap: 6px 10px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; word-break: break-word; font-weight: 500; }
.field-edit { margin-bottom: 10px; }
.field-edit label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; font-weight: 500; }
.field-edit .src { font-size: 10px; color: var(--ai); margin-left: 4px; font-weight: 600; }
.tag-list { display: flex; flex-wrap: wrap; gap: 5px; margin-bottom: 8px; }
.memory { font-size: 13px; color: var(--text-2); background: var(--surface-2); border: 1px solid var(--border-soft); border-radius: var(--radius); padding: 10px; white-space: pre-wrap; }
.mini-list { list-style: none; margin: 0; padding: 0; }
.mini-list li { padding: 8px 0; border-bottom: 1px dashed var(--border); font-size: 13px; }
.mini-list li:last-child { border-bottom: 0; }

.kanban { display: flex; gap: 14px; overflow-x: auto; align-items: flex-start; padding-bottom: 12px; min-height: calc(100vh - 190px); }
.kanban-col { flex: 0 0 292px; background: var(--surface-3); border: 1px solid var(--border); border-radius: var(--radius-lg); display: flex; flex-direction: column; max-height: calc(100vh - 190px); }
.kanban-col.drop { outline: 2px dashed var(--brand); background: var(--brand-50); }
.kanban-head { padding: 12px 14px; display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 13px; }
.kanban-head .dot { width: 9px; height: 9px; border-radius: 50%; }
.kanban-head .count { margin-left: auto; min-width: 22px; height: 20px; padding: 0 7px; border-radius: 10px; background: var(--surface); border: 1px solid var(--border); font-size: 11px; color: var(--text-2); font-weight: 700; display: inline-flex; align-items: center; justify-content: center; }
.kanban-cards { padding: 0 10px 10px; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; min-height: 64px; }
.ticket-card { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 12px; box-shadow: var(--shadow-sm); cursor: grab; border-left: 3px solid var(--border-strong); transition: box-shadow 0.12s, transform 0.12s; }
.ticket-card:hover { box-shadow: var(--shadow-md); }
.ticket-card.p3 { border-left-color: var(--danger); }
.ticket-card.p2 { border-left-color: #f0a92e; }
.ticket-card.flash { animation: flash 1.4s ease-out; }
.ticket-card.dragging { opacity: 0.5; }
.ticket-card .num { font-size: 11px; color: var(--muted); font-family: ui-monospace, Menlo, Consolas, monospace; }
.ticket-card .title { font-weight: 700; margin: 4px 0 8px; line-height: 1.35; }
.ticket-card .meta { display: flex; gap: 6px; flex-wrap: wrap; font-size: 11px; color: var(--muted); align-items: center; }
.timeline { list-style: none; padding: 0; margin: 0 0 12px; }
.timeline li { padding: 8px 0 8px 16px; border-left: 2px solid var(--border); position: relative; font-size: 13px; }
.timeline li::before { content: ""; position: absolute; left: -5px; top: 13px; width: 8px; height: 8px; border-radius: 50%; background: var(--border-strong); box-shadow: 0 0 0 2px var(--surface); }
.timeline li.comment::before { background: var(--brand); }
.timeline .when { font-size: 11px; color: var(--muted); }

.search-result { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 12px 16px; margin-bottom: 10px; box-shadow: var(--shadow-sm); }
.search-result .head { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.search-result mark { background: #ffe6a6; padding: 0 2px; border-radius: 2px; }

.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 14px; margin-bottom: 18px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 16px 18px; box-shadow: var(--shadow-sm); position: relative; overflow: hidden; }
.stat::before { content: ""; position: absolute; left: 0; top: 16px; bottom: 16px; width: 3px; border-radius: 0 3px 3px 0; background: var(--brand); opacity: 0.85; }
.stat .label { font-size: 12px; color: var(--muted); font-weight: 600; }
.stat .value { font-size: 26px; font-weight: 700; margin-top: 6px; letter-spacing: -0.01em; font-variant-numeric: tabular-nums; }
.stat .sub { font-size: 12px; color: var(--text-2); margin-top: 2px; }
.report-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.report-grid .card { margin-bottom: 0; }
.bars { display: flex; flex-direction: column; gap: 9px; }
.bar-row { display: grid; grid-template-columns: 150px 1fr 70px; gap: 10px; align-items: center; font-size: 13px; }
.bar-row .track { background: var(--surface-3); height: 12px; border-radius: 6px; position: relative; overflow: hidden; }
.bar-row .fill { background: var(--brand); height: 100%; border-radius: 6px; min-width: 3px; }
.bar-row .fill:hover { background: var(--brand-700); }
.bar-row .val { text-align: right; color: var(--text-2); font-variant-numeric: tabular-nums; font-weight: 600; }
.columns { display: flex; align-items: flex-end; gap: 6px; height: 170px; border-bottom: 1px solid var(--border-strong); padding-top: 8px; }
.columns .col { flex: 1; background: var(--brand); border-radius: 4px 4px 0 0; min-height: 3px; position: relative; opacity: 0.9; }
.columns .col:hover { opacity: 1; background: var(--brand-700); }
.columns-labels { display: flex; gap: 6px; font-size: 10.5px; color: var(--muted); margin-top: 6px; }
.columns-labels span { flex: 1; text-align: center; overflow: hidden; white-space: nowrap; }

.admin-page { display: grid; grid-template-columns: 232px minmax(0, 1fr); gap: 22px; align-items: start; }
.admin-nav { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 8px; display: flex; flex-direction: column; gap: 2px; position: sticky; top: calc(var(--appbar) + 22px); box-shadow: var(--shadow-sm); }
.admin-link { padding: 9px 12px; border-radius: var(--radius); color: var(--text-2); font-weight: 500; font-size: 13px; }
.admin-link:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.admin-link.active { background: var(--brand-50); color: var(--brand-700); font-weight: 700; box-shadow: inset 3px 0 0 var(--brand); }
.admin-body > .card:last-child { margin-bottom: 0; }
.matrix td, .matrix th { text-align: center; }
.matrix td:first-child, .matrix th:first-child { text-align: left; }
.qr-box { text-align: center; padding: 10px; }
.qr-box img { width: 260px; height: 260px; image-rendering: pixelated; border: 1px solid var(--border); border-radius: 10px; }
.code-block { background: #1d2129; color: #e7e9ee; padding: 12px 14px; border-radius: var(--radius); font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12px; white-space: pre-wrap; word-break: break-word; max-height: 360px; overflow: auto; }
.copy-line { display: flex; gap: 6px; align-items: center; }
.copy-line code { flex: 1; background: var(--surface-2); border: 1px solid var(--border); padding: 6px 10px; border-radius: 6px; font-size: 12px; overflow-x: auto; white-space: nowrap; }
.status-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--border-strong); margin-right: 6px; vertical-align: middle; }
.status-dot.connected, .status-dot.ok { background: #22a55a; box-shadow: 0 0 0 3px rgba(34, 165, 90, 0.15); }
.status-dot.disconnected, .status-dot.fail { background: var(--danger); box-shadow: 0 0 0 3px rgba(198, 40, 40, 0.15); }
.status-dot.connecting { background: #f0a92e; }

.modal-root { position: fixed; inset: 0; z-index: 60; pointer-events: none; }
.modal-backdrop { position: fixed; inset: 0; background: rgba(20, 24, 32, 0.45); display: flex; align-items: flex-start; justify-content: center; padding: 7vh 16px; overflow-y: auto; pointer-events: auto; }
.modal { background: var(--surface); border-radius: 14px; box-shadow: var(--shadow-lg); width: 100%; max-width: 560px; }
.modal.lg { max-width: 820px; }
.modal.xl { max-width: 1040px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.modal-head h3 { margin: 0; font-size: 16px; }
.modal-body { padding: 18px 20px; max-height: 72vh; overflow-y: auto; }
.modal-foot { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; background: var(--surface-2); border-radius: 0 0 14px 14px; }
.drawer-backdrop { position: fixed; inset: 0; background: rgba(20, 24, 32, 0.35); pointer-events: auto; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(560px, 100%); background: var(--surface); box-shadow: var(--shadow-lg); display: flex; flex-direction: column; pointer-events: auto; }
.drawer .modal-body { flex: 1; max-height: none; }
.drawer .modal-foot { border-radius: 0; }

.toast-stack { position: fixed; right: 18px; bottom: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 80; max-width: 360px; }
.toast { background: #1d2129; color: #fff; padding: 11px 16px; border-radius: 10px; box-shadow: var(--shadow-lg); font-size: 13px; cursor: pointer; animation: slide 0.2s ease-out; border-left: 4px solid rgba(255, 255, 255, 0.3); }
.toast.error { background: var(--brand-700); }
.toast.success { background: var(--success); }
.toast .t-title { font-weight: 700; }
@keyframes slide { from { transform: translateY(10px); opacity: 0; } to { transform: none; opacity: 1; } }

.login-body { background: var(--bg); min-height: 100vh; margin: 0; }
.login-split { min-height: 100vh; display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr); }
.login-hero { background: var(--brand); color: #fff; padding: 48px 56px; display: flex; flex-direction: column; justify-content: space-between; position: relative; overflow: hidden; }
.login-hero::after { content: ""; position: absolute; right: -160px; bottom: -160px; width: 460px; height: 460px; border-radius: 50%; border: 70px solid rgba(255, 255, 255, 0.07); }
.login-hero img { height: 40px; width: auto; align-self: flex-start; }
.login-hero h2 { color: #fff; font-size: 30px; line-height: 1.2; margin: 0 0 14px; max-width: 460px; }
.login-hero p { color: rgba(255, 255, 255, 0.85); font-size: 15px; max-width: 440px; }
.hero-points { list-style: none; padding: 0; margin: 22px 0 0; display: flex; flex-direction: column; gap: 10px; position: relative; z-index: 1; }
.hero-points li { display: flex; gap: 10px; align-items: center; font-size: 14px; }
.hero-points li::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: #fff; flex: none; }
.hero-foot { font-size: 12px; color: rgba(255, 255, 255, 0.7); position: relative; z-index: 1; }
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px 16px; }
.login-card { background: var(--surface); border: 1px solid var(--border); border-radius: 16px; box-shadow: var(--shadow-md); padding: 32px; width: 100%; max-width: 410px; }
.login-card h1 { font-size: 22px; margin: 0 0 4px; }
.login-card .lead { color: var(--muted); margin-bottom: 22px; }
.login-mobile-logo { display: none; height: 30px; margin-bottom: 22px; }
.login-brand { display: flex; gap: 14px; align-items: center; margin-bottom: 20px; }
.login-brand h1 { font-size: 20px; margin: 0; }
.login-card .btn.block { height: 40px; font-size: 14px; margin-top: 4px; }
.login-card .input { height: 40px; }
.login-foot { margin-top: 20px; text-align: center; }
.code-input { font-size: 22px; letter-spacing: 8px; text-align: center; }
.login-card .code-input { height: 48px; }
.error-code { font-size: 52px; color: var(--brand); margin-bottom: 6px; }
.brand-mark { width: 30px; height: 30px; border-radius: 8px; background: var(--brand); color: #fff; display: inline-flex; align-items: center; justify-content: center; font-weight: 700; flex: none; }
.brand-mark.lg { width: 44px; height: 44px; font-size: 20px; border-radius: 12px; }

.profile-page { max-width: 780px; }
.diag-page { max-width: 820px; }
.kb-status { font-size: 12px; }

@media (max-width: 1360px) {
  .inbox { grid-template-columns: 330px minmax(0, 1fr) 320px; }
  .inbox.no-profile { grid-template-columns: 330px minmax(0, 1fr); }
}
@media (max-width: 1280px) {
  .inbox { grid-template-columns: 320px minmax(0, 1fr); }
  .profile-panel { position: fixed; right: 0; top: var(--appbar); bottom: 0; width: 340px; z-index: 25; box-shadow: var(--shadow-lg); }
  .report-grid { grid-template-columns: 1fr; }
}
@media (max-width: 1024px) {
  .login-split { grid-template-columns: 1fr; }
  .login-hero { display: none; }
  .login-mobile-logo { display: block; }
}
@media (max-width: 900px) {
  .rail { transform: translateX(-100%); transition: transform 0.2s ease; width: 96px; }
  .rail-open .rail { transform: none; box-shadow: var(--shadow-lg); }
  .rail-open .rail-backdrop { display: block; position: fixed; inset: var(--appbar) 0 0 0; background: rgba(20, 24, 32, 0.35); z-index: 29; }
  .content { margin-left: 0; padding: 16px; }
  .only-mobile { display: inline-flex; }
  .appbar { gap: 8px; padding-left: 6px; }
  .appbar .brand { padding: 0 2px; }
  .brand-logo { height: 22px; }
  .appbar-divider { display: none; }
  .page-title { font-size: 15px; }
  .rt-status .rt-label, .user-meta { display: none; }
  .rt-status { padding: 0 8px; margin: 0; }
  .inbox, .inbox.no-profile { grid-template-columns: minmax(0, 1fr); }
  .inbox.has-thread .inbox-list { display: none; }
  .inbox:not(.has-thread) .thread { display: none; }
  .profile-panel { width: 100%; }
  .thread-bar { padding: 10px 12px; gap: 10px; }
  .thread-toolbar { padding: 8px 12px; }
  .thread-toolbar .inline-label > span:first-child { display: none; }
  .thread-toolbar .btn .icon { display: none; }
  .messages { padding: 14px 12px; }
  .composer { padding: 10px 12px; }
  .admin-page { grid-template-columns: 1fr; }
  .admin-nav { position: static; flex-direction: row; overflow-x: auto; }
  .admin-link { white-space: nowrap; }
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
  .span-2 { grid-column: auto; }
  .toolbar > .input:not(.sm) { width: 100%; }
  .msg { max-width: 86%; }
  .notif-panel { width: 92vw; right: -60px; }
  .card { padding: 16px; }
}
