:root {
  color-scheme: dark;
  --bg: #05070b; --panel: #0a1018; --panel2: #0d1621;
  --line: #173246; --cyan: #29e7ff; --violet: #a66cff;
  --text: #e9f7fb; --muted: #78909c; --danger: #ff5470;
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--tg-theme-bg-color, var(--bg)); color: var(--text); }
body { font: 15px/1.5 -apple-system, BlinkMacSystemFont, "SF Pro Text", Inter, sans-serif; overflow: hidden; }
button, select, textarea, input { font: inherit; }
button { color: inherit; }
.scanlines { position: fixed; inset: 0; pointer-events: none; opacity: .12; z-index: 5;
  background: repeating-linear-gradient(0deg, transparent 0 3px, #5beeff0b 3px 4px); }
.shell { display: grid; grid-template-columns: 230px 1fr; height: var(--tg-viewport-height, 100dvh); min-height: 0;
  background: radial-gradient(circle at 70% -20%, #143752 0, transparent 34%), var(--bg); }
.sidebar { padding: 28px 18px; border-right: 1px solid var(--line); background: #070b12e8;
  display: flex; flex-direction: column; backdrop-filter: blur(24px); }
.brand { display: flex; gap: 12px; align-items: center; padding: 0 8px 30px; }
.brand-mark { width: 42px; height: 42px; display: grid; place-items: center; font: 800 24px/1 monospace;
  color: #041016; background: var(--cyan); clip-path: polygon(14% 0,100% 0,100% 72%,72% 100%,0 100%,0 14%);
  box-shadow: 0 0 24px #29e7ff88; }
.brand strong { letter-spacing: .14em; display: block; }
.brand span, small { color: var(--muted); font-size: 10px; letter-spacing: .18em; }
nav { display: grid; gap: 7px; }
.nav { border: 1px solid transparent; text-align: left; padding: 12px 14px; border-radius: 8px;
  background: transparent; color: #9fb3bd; cursor: pointer; transition: .2s; }
.nav:hover, .nav.active { color: var(--cyan); border-color: #1c5066; background: #102332aa; }
.nav.danger:hover { color: var(--danger); border-color: #652b3a; background: #2c121aaa; }
.node-card { margin-top: auto; border: 1px solid var(--line); background: #0b151e; padding: 14px;
  display: flex; gap: 11px; align-items: center; border-radius: 10px; }
.node-card strong, .node-card small { display: block; }
.pulse { width: 9px; height: 9px; background: #39ff9a; border-radius: 50%; box-shadow: 0 0 12px #39ff9a; }
.workspace { display: grid; grid-template-rows: auto minmax(0, 1fr) auto; min-width: 0; min-height: 0; }
.mobile-bar { display: none; }
header { padding: 24px 34px 18px; border-bottom: 1px solid var(--line); display: flex; align-items: end;
  justify-content: space-between; background: #07101a99; backdrop-filter: blur(14px); }
h1 { margin: 0; font-size: 25px; letter-spacing: 0; }
.eyebrow { margin: 0 0 4px; color: var(--cyan); font: 600 10px/1.2 monospace; letter-spacing: .2em; }
.controls { display: flex; gap: 12px; }
.controls label { color: var(--muted); font: 600 9px/1 monospace; letter-spacing: .14em; }
select { display: block; margin-top: 6px; min-width: 170px; border: 1px solid var(--line); border-radius: 7px;
  background: #0b141e; padding: 9px 28px 9px 10px; color: var(--text); outline: none; }
select:focus { border-color: var(--cyan); }
.messages { min-height: 0; overflow-y: auto; overscroll-behavior: contain;
  padding: 28px max(30px, 8vw); scroll-behavior: smooth; }
.empty { margin: 12vh auto; text-align: center; color: var(--muted); }
.empty h2 { color: var(--text); margin: 18px 0 4px; }
.orb { width: 82px; height: 82px; margin: auto; border: 1px solid var(--cyan); border-radius: 50%;
  box-shadow: inset 0 0 28px #29e7ff55, 0 0 36px #29e7ff33; position: relative; }
.orb::after { content:""; position:absolute; inset:15px; border:1px dashed var(--violet); border-radius:50%; animation:spin 8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.message { max-width: 820px; margin: 0 auto 18px; display: grid; grid-template-columns: 36px 1fr; gap: 12px; }
.avatar { width: 34px; height: 34px; display:grid; place-items:center; border:1px solid var(--line); border-radius:8px;
  color: var(--cyan); font: 700 12px monospace; background:#0b1720; }
.message.user .avatar { color: var(--violet); }
.bubble { padding: 15px 17px; border: 1px solid var(--line); background: #0a121bdb; border-radius: 3px 12px 12px 12px;
  white-space: pre-wrap; overflow-wrap: anywhere; }
.message.user .bubble { border-color:#3f305f; background:#151124cc; }
.meta { color:var(--muted); font: 9px monospace; letter-spacing:.12em; margin-bottom:6px; }
.composer { border-top: 1px solid var(--line); padding: 16px max(30px, 8vw) 18px; background: #060b12ee; }
.input-row { max-width: 900px; margin:auto; display:grid; grid-template-columns:auto 1fr auto; align-items:end;
  border:1px solid #24506a; border-radius:12px; background:#0b151f; padding:8px; box-shadow:0 0 30px #0c8aaa12; }
textarea { resize:none; max-height:180px; border:0; outline:0; background:transparent; color:var(--text); padding:9px; }
.icon-button { width:42px; height:42px; border:0; background:transparent; color:var(--cyan); font-size:24px; cursor:pointer; }
.send { border:0; border-radius:7px; padding:12px 16px; font:700 11px monospace; letter-spacing:.14em;
  color:#031016; background:linear-gradient(135deg,var(--cyan),#77f7ff); cursor:pointer; }
.send:disabled { opacity:.35; cursor:wait; }
.hint { text-align:center; color:#536773; font:9px monospace; letter-spacing:.07em; margin:8px 0 0; }
.attachment { max-width:900px; margin:0 auto 8px; border:1px solid #4a3771; background:#171126; padding:8px 12px;
  border-radius:7px; color:#cdb8ff; font:11px monospace; }
.hidden { display:none; }
.launch-gate { min-height: 100dvh; display: grid; place-content: center; justify-items: center;
  padding: 32px; text-align: center; background: var(--bg); }
.launch-gate.hidden { display: none; }
.launch-gate img { width: 112px; height: 112px; border-radius: 28px; object-fit: cover;
  border: 1px solid #5f38a0; box-shadow: 0 0 36px #8e4cff55; }
.launch-gate h1 { margin-top: 22px; }
.launch-gate p { color: var(--muted); max-width: 480px; }
.gate-link { display: inline-block; margin-top: 10px; text-decoration: none; }
.gate-link.hidden { display: none; }
.pairing-status { max-width: 480px; margin-top: 18px; color: #9fb3bd; }
.launch-gate .send { margin-top: 12px; }
.desktop-policy { max-width: 520px; margin: 18px 0 4px; padding: 13px 14px;
  display: grid; grid-template-columns: 20px minmax(0, 1fr); gap: 10px; align-items: start;
  border: 1px solid #284457; border-radius: 7px; background: #0a141d; color: #b9ccd5;
  text-align: left; }
.desktop-policy.hidden { display: none; }
.desktop-policy input { width: 17px; height: 17px; margin: 2px 0 0; accent-color: var(--cyan); }
.desktop-policy span { font-size: 12px; line-height: 1.45; }
.toast { position:fixed; right:24px; bottom:24px; padding:12px 16px; border:1px solid var(--cyan);
  background:#07141d; border-radius:8px; transform:translateY(80px); opacity:0; transition:.25s; z-index:10; }
.toast.show { transform:none; opacity:1; }
dialog { max-width:520px; border:1px solid #6b4d98; border-radius:14px; color:var(--text); background:#0b1019;
  box-shadow:0 30px 100px #000; padding:26px; }
dialog::backdrop { background:#010409c9; backdrop-filter:blur(7px); }
dialog h2 { margin:5px 0 10px; }
.dialog-actions { display:flex; justify-content:flex-end; gap:10px; margin-top:22px; }
.dialog-actions button:not(.send) { border:1px solid var(--line); background:#101923; border-radius:7px; padding:11px 15px; }

.admin-view { grid-row: 1 / -1; min-width: 0; min-height: 0; display: grid;
  grid-template-rows: auto minmax(0, 1fr); background: #060b11; }
.admin-view.hidden { display: none; }
.admin-header { min-height: 82px; padding: 18px 28px; display: flex; align-items: center;
  justify-content: space-between; gap: 20px; border-bottom: 1px solid var(--line); background: #080f18; }
.admin-actions { display: flex; align-items: center; gap: 8px; }
.tool-button { min-height: 38px; padding: 0 13px; border: 1px solid #284457; border-radius: 7px;
  background: #0c1721; color: #b9d1db; cursor: pointer; }
.tool-button:hover { border-color: var(--cyan); color: var(--cyan); }
.tool-button.close-admin { width: 38px; padding: 0; font-size: 23px; }
.admin-scroll { min-height: 0; overflow: auto; padding: 22px 26px 30px; }
.metric-grid { display: grid; grid-template-columns: repeat(6, minmax(110px, 1fr)); gap: 9px; margin-bottom: 20px; }
.metric { min-height: 82px; padding: 13px 14px; border: 1px solid #203b4e; border-radius: 7px;
  background: #0a141d; }
.metric:nth-child(2) { border-color: #225d52; }
.metric:nth-child(4) { border-color: #6c4c25; }
.metric:nth-child(5) { border-color: #4d3a6c; }
.metric:nth-child(6) { border-color: #60313b; }
.metric span { display: block; color: var(--muted); font: 700 9px/1.3 monospace; letter-spacing: .1em; }
.metric strong { display: block; margin-top: 8px; color: var(--text); font: 700 25px/1 monospace; }
.admin-toolbar { display: grid; grid-template-columns: minmax(220px, 1fr) 210px auto;
  align-items: end; gap: 10px; margin-bottom: 12px; }
.search-field span, .filter-field span { display: block; margin-bottom: 6px; color: var(--muted);
  font: 700 9px/1 monospace; letter-spacing: .12em; }
.search-field input, .filter-field select { width: 100%; min-width: 0; height: 40px; margin: 0;
  border: 1px solid #203b4e; border-radius: 7px; outline: 0; background: #0a141d;
  color: var(--text); padding: 0 11px; }
.search-field input:focus, .filter-field select:focus { border-color: var(--cyan); }
.admin-count { margin: 0 0 10px; color: var(--muted); font: 10px monospace; white-space: nowrap; }
.admin-layout { min-height: 420px; display: grid; grid-template-columns: minmax(600px, 1fr) 330px;
  border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.users-panel { min-width: 0; border-right: 1px solid var(--line); }
.table-scroll { width: 100%; overflow-x: auto; }
.users-table { width: 100%; border-collapse: collapse; table-layout: fixed; }
.users-table th { position: sticky; top: 0; z-index: 1; height: 42px; padding: 0 12px;
  text-align: left; color: #8aa3af; background: #09111a; border-bottom: 1px solid var(--line);
  font: 700 9px/1 monospace; letter-spacing: .1em; }
.users-table th:nth-child(1) { width: 27%; }
.users-table th:nth-child(2) { width: 21%; }
.users-table th:nth-child(3) { width: 11%; }
.users-table th:nth-child(4) { width: 15%; }
.users-table th:nth-child(5), .users-table th:nth-child(6) { width: 13%; text-align: center; }
.users-table td { height: 64px; padding: 8px 12px; border-bottom: 1px solid #122637; vertical-align: middle; }
.users-table tr { background: #070e16; transition: background .15s; }
.users-table tr:hover, .users-table tr.selected { background: #0d1e29; }
.user-button { width: 100%; padding: 0; border: 0; background: transparent; color: var(--text);
  text-align: left; cursor: pointer; overflow: hidden; }
.user-button strong, .user-button span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-button span, .activity-cell span { color: var(--muted); font-size: 11px; }
.activity-cell strong, .activity-cell span { display: block; }
.activity-cell strong { color: #b9cbd3; font-size: 12px; font-weight: 600; }
.question-count { color: var(--cyan); font: 700 15px monospace; }
.network-cell { overflow: hidden; }
.network-status { display: block; overflow: hidden; color: var(--muted); font-size: 10px;
  text-overflow: ellipsis; white-space: nowrap; }
.network-status.clean { color: #44e2bd; }
.network-status.warning { color: #f2bb61; }
.network-status.blocked { color: var(--danger); }
.network-status.unknown { color: #9fb3bd; }
.permission-cell { text-align: center; }
.switch { display: inline-flex; align-items: center; justify-content: center; cursor: pointer; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch-track { width: 38px; height: 21px; padding: 2px; border: 1px solid #365064; border-radius: 11px;
  background: #111a23; transition: .18s; }
.switch-track::after { content: ""; display: block; width: 15px; height: 15px; border-radius: 50%;
  background: #71828c; transition: .18s; }
.switch input:checked + .switch-track { border-color: #20b999; background: #0d3a33; }
.switch input:checked + .switch-track::after { transform: translateX(17px); background: #44e2bd; }
.switch input:focus-visible + .switch-track { outline: 2px solid var(--cyan); outline-offset: 2px; }
.switch input:disabled + .switch-track { opacity: .45; cursor: wait; }
.admin-empty { padding: 44px 18px; text-align: center; color: var(--muted); }
.user-inspector { min-width: 0; padding: 20px; background: #080f17; overflow: auto; }
.inspector-empty { min-height: 280px; display: grid; place-items: center; color: #607581; text-align: center; }
.inspector-head { padding-bottom: 15px; border-bottom: 1px solid var(--line); }
.inspector-head h2 { margin: 0; font-size: 18px; overflow-wrap: anywhere; }
.inspector-id { margin: 5px 0 0; color: var(--cyan); font: 11px monospace; }
.inspector-meta { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; padding: 15px 0;
  border-bottom: 1px solid var(--line); }
.inspector-meta div { min-width: 0; }
.inspector-meta span { display: block; color: var(--muted); font: 8px/1.2 monospace; letter-spacing: .09em; }
.inspector-meta strong { display: block; margin-top: 4px; color: #c7d8df; font-size: 11px;
  overflow-wrap: anywhere; }
.inspector-title { margin: 17px 0 9px; color: #8ea4ae; font: 700 9px monospace; letter-spacing: .11em; }
.network-list { display: grid; gap: 7px; }
.network-item { padding: 9px 10px; border-left: 2px solid #607581; background: #0a141d; }
.network-item.clean { border-left-color: #44e2bd; }
.network-item.warning { border-left-color: #f2bb61; }
.network-item.blocked { border-left-color: var(--danger); }
.network-item > div { display: flex; justify-content: space-between; gap: 9px; }
.network-item strong { color: #c9dce4; font: 11px monospace; overflow-wrap: anywhere; }
.network-item span { color: var(--muted); font-size: 9px; white-space: nowrap; }
.network-item p { margin: 5px 0 0; color: #8298a2; font-size: 9px; overflow-wrap: anywhere; }
.admin-empty.compact { padding: 14px 10px; border: 1px solid #162b3a; }
.history-section { display: grid; gap: 9px; }
.load-history { justify-self: stretch; }
.history-list { display: grid; gap: 8px; }
.history-item { padding: 9px 10px; border-left: 2px solid #3e5868; background: #0a141d; }
.history-item.user { border-left-color: var(--violet); }
.history-item.assistant { border-left-color: var(--cyan); }
.history-item span { display: block; color: var(--muted); font: 8px monospace; }
.history-item p { margin: 5px 0 0; color: #c1d1d8; font-size: 11px; white-space: pre-wrap;
  overflow-wrap: anywhere; }
.admin-loading { padding: 30px; color: var(--muted); text-align: center; }
@media (max-width: 780px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { display:none; }
  .workspace { grid-template-rows: auto auto minmax(0, 1fr) auto; }
  .mobile-bar { display: flex; align-items: center; justify-content: space-between;
    min-height: 58px; padding: 8px 12px; padding-top: max(8px, var(--tg-content-safe-area-inset-top, 0px));
    border-bottom: 1px solid var(--line); background: #070b12f2; }
  .mobile-bar.hidden { display: none; }
  .mobile-brand { display: flex; align-items: center; gap: 9px; min-width: 0; }
  .mobile-brand img { width: 38px; height: 38px; border-radius: 9px; object-fit: cover; }
  .mobile-brand strong, .mobile-brand small { display: block; }
  .mobile-brand strong { font-size: 14px; }
  .mobile-actions { display: flex; gap: 6px; }
  .mobile-actions button { min-height: 34px; border: 1px solid var(--line); border-radius: 7px;
    padding: 0 10px; background: #0b151f; color: #bcd2dc; font-size: 12px; }
  header { padding: 10px 12px; align-items: center; gap: 10px; }
  header > div:first-child { display: none; }
  .controls { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); width: 100%; gap: 8px; }
  select { width: 100%; min-width: 0; padding-top: 8px; padding-bottom: 8px; }
  .messages { padding: 16px 12px; }
  .composer { padding: 10px 10px max(10px, var(--tg-content-safe-area-inset-bottom, 0px)); }
  .input-row { grid-template-columns: 38px minmax(0, 1fr) auto; padding: 6px; }
  .icon-button { width: 38px; height: 38px; }
  .send { min-height: 38px; padding: 9px 11px; }
  .hint { display: none; }
  .message { grid-template-columns: 28px minmax(0, 1fr); gap: 8px; margin-bottom: 12px; }
  .avatar { width: 28px; height: 28px; font-size: 9px; }
  .bubble { padding: 11px 12px; }
  .empty { margin: 8vh auto; }
  .orb { width: 64px; height: 64px; }
  dialog { width: calc(100% - 28px); padding: 20px; }
  .admin-header { min-height: 68px; padding: 12px; }
  .admin-header h1 { font-size: 19px; }
  .admin-header .eyebrow { display: none; }
  .admin-actions .tool-button { min-height: 34px; padding: 0 9px; font-size: 11px; }
  .admin-actions .close-admin { width: 34px; font-size: 20px; }
  .admin-scroll { padding: 12px; }
  .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .metric { min-height: 68px; }
  .metric strong { font-size: 21px; }
  .admin-toolbar { grid-template-columns: 1fr; }
  .admin-count { grid-column: 1 / -1; margin: 0; }
  .admin-layout { display: block; min-height: 0; border-bottom: 0; }
  .users-panel { border-right: 0; }
  .users-table { min-width: 780px; }
  .user-inspector { border-top: 1px solid var(--line); }
}
@media (max-height: 720px) {
  .sidebar { padding-top: 18px; padding-bottom: 18px; }
  .brand { padding-bottom: 16px; }
  header { padding-top: 14px; padding-bottom: 12px; }
  .messages { padding-top: 16px; padding-bottom: 16px; }
  .composer { padding-top: 10px; padding-bottom: 10px; }
  .hint { display: none; }
}
