/* ==========================================================================
   FunPay Monstrum — Obsidian Aurora
   ========================================================================== */

:root {
  /* surfaces */
  --bg-0:        #07080d;
  --bg-1:        #0c0e16;
  --bg-2:        rgba(20, 22, 34, 0.55);
  --bg-3:        rgba(28, 32, 48, 0.78);
  --bg-card:     rgba(16, 18, 28, 0.68);
  --bg-input:    rgba(255, 255, 255, 0.04);

  /* borders + lines */
  --line:        rgba(255, 255, 255, 0.07);
  --line-strong: rgba(255, 255, 255, 0.14);

  /* text */
  --fg:          #ecedf3;
  --fg-soft:     rgba(236, 237, 243, 0.78);
  --fg-mute:     rgba(236, 237, 243, 0.46);
  --fg-faint:    rgba(236, 237, 243, 0.26);

  /* signature aurora */
  --violet:      #8b5cff;
  --cyan:        #00d4ff;
  --magenta:     #ff5cf2;
  --amber:       #ffb547;
  --ok:          #2ce0a1;
  --danger:      #ff5470;

  --grad-aurora: linear-gradient(135deg, #8b5cff 0%, #00d4ff 55%, #ff5cf2 100%);
  --grad-violet: linear-gradient(135deg, #8b5cff, #5d3dff);
  --grad-cyan:   linear-gradient(135deg, #00d4ff, #0085ff);

  --shadow-soft: 0 10px 30px rgba(0,0,0,.35), 0 0 0 1px rgba(255,255,255,.04) inset;
  --shadow-glow: 0 0 0 1px rgba(139,92,255,.35), 0 12px 40px rgba(139,92,255,.18);

  --radius-sm: 8px;
  --radius:    14px;
  --radius-lg: 20px;
  --radius-pill: 999px;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: radial-gradient(120% 80% at 50% -10%, #14182a 0%, #08090f 60%, #05060a 100%);
  color: var(--fg);
  font-family: 'Inter', -apple-system, "Segoe UI", Roboto, system-ui, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  letter-spacing: -0.005em;
  overflow: hidden; /* layouts handle scrolling */
  -webkit-font-smoothing: antialiased;
}
code, .mono { font-family: 'JetBrains Mono', ui-monospace, Menlo, Consolas, monospace; }
a { color: inherit; text-decoration: none; }
button { font: inherit; cursor: pointer; }
input, textarea, select { font: inherit; color: var(--fg); }
::selection { background: rgba(139, 92, 255, .35); }

/* ---------- aurora background ---------- */
.aurora { position: fixed; inset: 0; z-index: -1; overflow: hidden; pointer-events: none; }
.aurora-blob {
  position: absolute; width: 70vmax; height: 70vmax; border-radius: 50%;
  filter: blur(120px); opacity: .35; mix-blend-mode: screen;
  animation: drift 28s ease-in-out infinite;
}
.aurora-blob.a { background: radial-gradient(circle, #8b5cff 0%, transparent 60%); top: -25vmax; left: -10vmax; }
.aurora-blob.b { background: radial-gradient(circle, #00d4ff 0%, transparent 60%); top: 10vmax; right: -25vmax; animation-delay: -8s; }
.aurora-blob.c { background: radial-gradient(circle, #ff5cf2 0%, transparent 60%); bottom: -30vmax; left: 30vmax; animation-delay: -16s; opacity: .22; }
.aurora-grid {
  position: absolute; inset: 0;
  background-image:
    linear-gradient(rgba(255,255,255,.025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,.025) 1px, transparent 1px);
  background-size: 48px 48px;
  mask-image: radial-gradient(ellipse at 50% 30%, black 30%, transparent 75%);
}
@keyframes drift {
  0%,100% { transform: translate(0,0) scale(1); }
  33%     { transform: translate(8vmax,4vmax) scale(1.08); }
  66%     { transform: translate(-6vmax,6vmax) scale(.94); }
}

/* ---------- shared atoms ---------- */
.btn {
  --bgc: rgba(255,255,255,.04);
  display: inline-flex; align-items: center; gap: 8px;
  background: var(--bgc); color: var(--fg);
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 9px 14px; font-weight: 500;
  transition: transform .15s ease, background .2s ease, border-color .2s ease, box-shadow .2s ease;
}
.btn:hover { background: rgba(255,255,255,.07); border-color: var(--line-strong); transform: translateY(-1px); }
.btn:active { transform: translateY(0) scale(.98); }
.btn:disabled { opacity: .45; cursor: not-allowed; transform: none; }
.btn .icon { width: 16px; height: 16px; }

.btn.primary {
  background: var(--grad-aurora); border: 0; color: #0b0210; font-weight: 600;
  box-shadow: 0 8px 24px rgba(139,92,255,.35), 0 0 0 1px rgba(255,255,255,.1) inset;
}
.btn.primary:hover { filter: brightness(1.08); box-shadow: 0 10px 32px rgba(139,92,255,.5); }

.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); border-color: rgba(255,84,112,.3); }
.btn.danger:hover { background: rgba(255,84,112,.1); border-color: var(--danger); }

.btn-icon {
  width: 36px; height: 36px; padding: 0; justify-content: center;
}

.input {
  display: block; width: 100%;
  background: var(--bg-input); color: var(--fg);
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 10px 12px;
  transition: border-color .15s ease, background .15s ease, box-shadow .15s ease;
}
.input:focus { outline: 0; border-color: var(--violet); background: rgba(139,92,255,.06); box-shadow: 0 0 0 4px rgba(139,92,255,.12); }
.input::placeholder { color: var(--fg-faint); }
textarea.input { resize: none; line-height: 1.5; }

.field { display: grid; gap: 6px; }
.field-label { font-size: 11px; color: var(--fg-mute); text-transform: uppercase; letter-spacing: .08em; font-weight: 600; }

.chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: rgba(255,255,255,.04); border: 1px solid var(--line);
  border-radius: var(--radius-pill); padding: 4px 10px;
  font-size: 12px; font-weight: 500; color: var(--fg-soft);
}
.chip.accent {
  background: linear-gradient(135deg, rgba(139,92,255,.15), rgba(0,212,255,.12));
  border-color: rgba(139,92,255,.35); color: #d6c8ff;
}
.chip.dot::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

.divider { height: 1px; background: var(--line); margin: 16px 0; }
.muted { color: var(--fg-mute); }

/* glass card */
.card {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 22px;
  backdrop-filter: blur(20px) saturate(140%);
  -webkit-backdrop-filter: blur(20px) saturate(140%);
  box-shadow: var(--shadow-soft);
}

/* scrollbars */
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb { background: rgba(255,255,255,.08); border-radius: 999px; border: 2px solid transparent; background-clip: content-box; }
*::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,.18); background-clip: content-box; }

/* ==========================================================================
   LOGIN
   ========================================================================== */
.login-wrap { display: grid; place-items: center; min-height: 100vh; padding: 20px; }
.login-card {
  width: 400px; padding: 36px 32px;
  background: var(--bg-card); border: 1px solid var(--line); border-radius: var(--radius-lg);
  backdrop-filter: blur(24px) saturate(140%);
  -webkit-backdrop-filter: blur(24px) saturate(140%);
  box-shadow: 0 30px 80px rgba(0,0,0,.5), 0 0 0 1px rgba(255,255,255,.04) inset;
  display: grid; gap: 18px;
  position: relative;
}
.login-card::before {
  content: ""; position: absolute; inset: -1px; border-radius: var(--radius-lg);
  padding: 1px; background: linear-gradient(135deg, rgba(139,92,255,.4), transparent 40%, rgba(0,212,255,.3));
  -webkit-mask: linear-gradient(#000,#000) content-box, linear-gradient(#000,#000);
          mask: linear-gradient(#000,#000) content-box, linear-gradient(#000,#000);
  -webkit-mask-composite: xor; mask-composite: exclude; pointer-events: none;
}
.brand-mark {
  width: 56px; height: 56px; border-radius: 18px;
  background: var(--grad-aurora);
  display: grid; place-items: center; font-weight: 800; color: #07080d; font-size: 22px;
  box-shadow: 0 14px 30px rgba(139,92,255,.35), 0 0 0 1px rgba(255,255,255,.15) inset;
  margin: 0 auto 4px;
}
.login-card h1 { margin: 0; text-align: center; font-size: 22px; font-weight: 700; letter-spacing: -0.02em; }
.login-card .subtitle { margin: -10px 0 12px; text-align: center; color: var(--fg-mute); font-size: 13px; }
.err { color: var(--danger); margin: 0; font-size: 13px; }

/* ==========================================================================
   APP LAYOUT
   ========================================================================== */
.app-shell {
  display: grid;
  grid-template-columns: 64px 1fr;
  height: 100vh;
  gap: 0;
}

/* ── Holst (canvas) с плавающими окнами ─────────────────────── */
.windows-canvas {
  position: relative;
  width: 100%;
  height: 100vh;
  min-height: 100vh;
  overflow: hidden;
  background:
    radial-gradient(80vmax 60vmax at 30% 10%, rgba(139,92,255,.08), transparent 70%),
    radial-gradient(80vmax 60vmax at 90% 90%, rgba(0,212,255,.06), transparent 70%);
}
.canvas-grid {
  position: absolute; inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(rgba(255,255,255,.025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,.025) 1px, transparent 1px);
  background-size: 32px 32px;
  mask-image: radial-gradient(ellipse at 50% 40%, black 30%, transparent 75%);
}
.canvas-empty {
  position: absolute;
  inset: 0;
  display: grid; place-items: center; text-align: center;
  color: var(--fg-mute);
  pointer-events: none;
}
.canvas-empty .icon { width: 56px; height: 56px; color: var(--fg-faint); }
.canvas-empty h2 { margin: 10px 0 4px; color: var(--fg-soft); }

/* ── Само окно ──────────────────────────────────────────────── */
.window {
  --acc-color: #8b5cff;
  position: absolute;
  display: grid;
  grid-template-rows: 44px 1fr;
  min-width: 480px; min-height: 460px;
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-top: 2px solid var(--acc-color);
  border-radius: 12px;
  box-shadow: 0 24px 60px rgba(0,0,0,.5),
              0 0 0 1px color-mix(in srgb, var(--acc-color) 12%, transparent) inset;
  backdrop-filter: blur(18px) saturate(140%);
  -webkit-backdrop-filter: blur(18px) saturate(140%);
  overflow: hidden;
  transition: box-shadow .15s ease, border-color .15s ease;
}
.window.offline {
  border-color: rgba(255,84,112,.4);
  box-shadow: 0 24px 60px rgba(0,0,0,.6), 0 0 0 1px rgba(255,84,112,.3) inset;
}
.window.minimized {
  grid-template-rows: 44px;
  height: 44px !important;
  min-height: 44px;
}
.window:hover { box-shadow: 0 28px 70px rgba(0,0,0,.6); }

.window-head {
  display: flex; align-items: center; gap: 10px;
  padding: 0 10px;
  background: rgba(255,255,255,.04);
  border-bottom: 1px solid var(--line);
  cursor: move;
  user-select: none;
  font-size: 12px;
}
.window-dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--acc-color);
  box-shadow: 0 0 8px var(--acc-color);
  flex-shrink: 0;
}
.window-acc-select {
  background: var(--bg-3); color: var(--fg);
  font-weight: 700; font-size: 12.5px;
  border: 1px solid var(--line); border-radius: 6px;
  padding: 5px 8px;
  max-width: 220px;
}
.window-geo {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 4px 8px;
  background: rgba(0,212,255,.08);
  border: 1px solid rgba(0,212,255,.2);
  border-radius: 999px;
  font-size: 11px;
  color: #b6ecff;
}
.window-status {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 4px 8px; border-radius: 999px;
  font-size: 11px; font-weight: 600;
  background: rgba(255,255,255,.04);
  border: 1px solid var(--line);
  color: var(--fg-mute);
  margin-left: auto;
}
.window-status .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--fg-mute); }
.window-status.on { color: #b9f7da; border-color: rgba(44,224,161,.3); background: rgba(44,224,161,.08); }
.window-status.on .dot { background: var(--ok); box-shadow: 0 0 6px var(--ok); }
.window-status.off { color: #ffc4cd; border-color: rgba(255,84,112,.4); background: rgba(255,84,112,.08); }
.window-status.off .dot { background: var(--danger); }

.window-actions { display: flex; gap: 4px; }
.winbtn {
  width: 26px; height: 26px;
  display: grid; place-items: center;
  border: 1px solid transparent;
  background: transparent;
  border-radius: 6px;
  color: var(--fg-mute);
  cursor: pointer;
  transition: all .12s ease;
}
.winbtn:hover { background: rgba(255,255,255,.06); color: var(--fg); border-color: var(--line); }
.winbtn.close:hover { background: rgba(255,84,112,.15); color: var(--danger); border-color: rgba(255,84,112,.4); }
.winbtn .icon { width: 14px; height: 14px; }

.window-body {
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: 0;
  position: relative;
}

/* Overlay при отвале прокси */
.proxy-down-overlay {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: grid; place-items: center;
  align-content: center;
  text-align: center;
  padding: 30px;
  background: rgba(8,10,16,.78);
  backdrop-filter: blur(6px);
  color: var(--fg);
}
.proxy-down-overlay .icon-big { width: 56px; height: 56px; color: var(--danger); margin-bottom: 14px; }
.proxy-down-overlay h3 {
  margin: 0 0 8px;
  font-size: 18px; letter-spacing: .05em;
  color: var(--danger);
}
.proxy-down-overlay p { color: var(--fg-soft); margin: 4px 0; max-width: 460px; }
.proxy-down-overlay p.small { font-size: 12px; color: var(--fg-mute); }
.proxy-down-overlay .btn { margin-top: 16px; }

/* Ресайз-хэндл */
.window-resize {
  position: absolute; right: 0; bottom: 0;
  width: 18px; height: 18px;
  cursor: nwse-resize;
  background:
    linear-gradient(135deg, transparent 50%, rgba(255,255,255,.18) 50%, rgba(255,255,255,.18) 60%, transparent 60%,
                    transparent 70%, rgba(255,255,255,.18) 70%, rgba(255,255,255,.18) 80%, transparent 80%);
  border-bottom-right-radius: 12px;
  z-index: 5;
}

/* FAB */
.window-add-fab {
  position: absolute;
  right: 20px; bottom: 20px;
  width: 56px; height: 56px;
  border-radius: 50%;
  background: var(--grad-aurora);
  color: #07080d;
  border: 0;
  display: grid; place-items: center;
  box-shadow: 0 12px 36px rgba(139,92,255,.4);
  cursor: pointer;
  transition: transform .15s ease;
  z-index: 100;
}
.window-add-fab:hover { transform: translateY(-2px) scale(1.05); filter: brightness(1.1); }
.window-add-fab .icon { width: 24px; height: 24px; }

/* Адаптируем размеры списка и треда внутри окна */
.window .panel-list-head { padding: 10px 10px; }
.window .panel-list .chat-list { padding: 4px 6px 14px; overflow-y: auto; }
.window .panel-list .chat-row { grid-template-columns: 34px 1fr auto; gap: 8px; padding: 7px 9px; }
.window .panel-list .avatar { width: 34px; height: 34px; border-radius: 9px; font-size: 11px; }
.window .panel-list .chat-name { font-size: 12.5px; }
.window .panel-list .chat-sub { font-size: 11.5px; }
.window .panel-list .chat-tags { margin-top: 4px; }

.window .panel-thread { display: grid; grid-template-rows: auto 1fr auto; min-height: 0; min-width: 0; }
.window .thread-head { padding: 8px 14px; }
.window .messages { padding: 12px 14px 6px; }
.window .composer { padding: 8px 12px 10px; }

/* Старый workspace (горизонтальная лента) — оставлен для совместимости */
.workspace {
  display: flex;
  overflow-x: auto;
  scroll-snap-type: x proximity;
  min-width: 0;
  background: linear-gradient(180deg, rgba(255,255,255,.01), transparent);
}
.workspace > .panel {
  flex: 1 1 720px;
  min-width: 560px;
  max-width: 1100px;
  display: grid;
  grid-template-rows: auto 1fr;
  min-height: 0;
  height: 100vh;
  border-right: 1px solid var(--line);
  scroll-snap-align: start;
  background: linear-gradient(180deg, rgba(255,255,255,.012), transparent);
}
.workspace > .panel:last-of-type { border-right: 0; }

.panel-head {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  background: rgba(10,12,20,.55);
  backdrop-filter: blur(14px) saturate(140%);
  -webkit-backdrop-filter: blur(14px) saturate(140%);
}
.panel-acc-pick {
  display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0;
}
.panel-color-dot {
  width: 10px; height: 10px; border-radius: 50%;
  box-shadow: 0 0 8px currentColor;
}
.panel-acc-select {
  background: var(--bg-3);
  font-weight: 700; font-size: 13px;
  border-color: var(--line);
  max-width: 320px;
}
.panel-actions { display: flex; gap: 4px; }

.panel-body {
  display: grid;
  grid-template-columns: 280px 1fr;
  min-height: 0;
  min-width: 0;
}
.panel-list {
  border-right: 1px solid var(--line);
  display: grid; grid-template-rows: auto 1fr;
  min-height: 0;
  background: rgba(255,255,255,.01);
}
.panel-list-head {
  padding: 10px 12px;
  display: grid; gap: 8px;
  border-bottom: 1px solid var(--line);
}
.panel-list .chat-list { padding: 4px 6px 14px; overflow-y: auto; }
.panel-list .chat-row {
  grid-template-columns: 36px 1fr auto;
  gap: 8px; padding: 8px 10px;
}
.panel-list .avatar { width: 36px; height: 36px; border-radius: 10px; font-size: 12px; }
.panel-list .chat-name { font-size: 13px; }
.panel-list .chat-sub { font-size: 11.5px; }

.panel-thread {
  display: grid; grid-template-rows: auto 1fr auto;
  min-height: 0; min-width: 0;
}
.panel-thread .thread-head { padding: 10px 16px; }
.panel-thread .messages { padding: 14px 16px 8px; }
.panel-thread .composer { padding: 10px 14px 12px; }

/* Кнопка "Новое окно" в конце ленты */
.panel-add-btn {
  flex: 0 0 auto;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 8px;
  width: 140px;
  cursor: pointer;
  color: var(--fg-mute);
  border-right: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(255,255,255,.01), transparent);
  transition: background .15s ease, color .15s ease;
}
.panel-add-btn:hover {
  background: linear-gradient(180deg, rgba(139,92,255,.06), rgba(0,212,255,.04));
  color: var(--fg);
}
.panel-add-btn .icon { width: 32px; height: 32px; opacity: .7; }
.panel-add-btn span { font-size: 11px; text-transform: uppercase; letter-spacing: .1em; }

/* Статус-индикатор WS в рейле */
.rail-status {
  width: 8px; height: 8px; border-radius: 50%;
  margin: 0 auto 6px;
  background: var(--fg-mute);
  transition: background .2s ease, box-shadow .2s ease;
}
.rail-status.on { background: var(--ok); box-shadow: 0 0 8px var(--ok); }

.rail {
  display: grid; grid-template-rows: auto 1fr auto; gap: 6px;
  padding: 14px 8px; border-right: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(255,255,255,.02), transparent);
}
.rail-logo {
  width: 40px; height: 40px; border-radius: 12px;
  background: var(--grad-aurora);
  display: grid; place-items: center;
  font-weight: 800; color: #07080d; font-size: 16px;
  box-shadow: 0 8px 20px rgba(139,92,255,.4);
  margin: 0 auto 8px;
}
.rail-btn {
  width: 48px; height: 48px; border-radius: 12px;
  display: grid; place-items: center;
  color: var(--fg-mute); background: transparent; border: 1px solid transparent;
  transition: all .18s ease; position: relative; margin: 0 auto;
}
.rail-btn:hover { color: var(--fg); background: rgba(255,255,255,.04); border-color: var(--line); }
.rail-btn.active { color: var(--fg); background: rgba(139,92,255,.12); border-color: rgba(139,92,255,.3); }
.rail-btn.active::before {
  content: ""; position: absolute; left: -8px; top: 25%; bottom: 25%; width: 3px;
  background: var(--grad-aurora); border-radius: 2px;
  box-shadow: 0 0 12px var(--violet);
}
.rail-btn .icon { width: 20px; height: 20px; }
.rail-spacer { }

/* sidebar = chat list pane */
.sidebar {
  display: grid; grid-template-rows: auto auto 1fr; min-height: 0;
  border-right: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(255,255,255,.015), transparent);
}
.sidebar-head { padding: 18px 18px 8px; display: grid; gap: 14px; }
.title-row { display: flex; align-items: center; justify-content: space-between; }
.title-row h2 { margin: 0; font-size: 17px; font-weight: 700; letter-spacing: -0.02em; }
.live-pill {
  display: inline-flex; align-items: center; gap: 6px;
  background: rgba(255,255,255,.04); border: 1px solid var(--line);
  border-radius: var(--radius-pill); padding: 3px 10px;
  font-size: 11px; color: var(--fg-mute); font-weight: 500;
}
.live-pill .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--fg-mute); }
.live-pill.on { color: #b9f7da; border-color: rgba(44,224,161,.3); background: rgba(44,224,161,.08); }
.live-pill.on .dot { background: var(--ok); box-shadow: 0 0 0 0 rgba(44,224,161,.6); animation: pulse 1.8s ease-in-out infinite; }
@keyframes pulse {
  0%,100% { box-shadow: 0 0 0 0 rgba(44,224,161,.55); }
  50%     { box-shadow: 0 0 0 6px rgba(44,224,161,0); }
}

/* ── Переключатель аккаунтов FunPay ─────────────────────────────────── */
.acc-switcher {
  display: flex; flex-wrap: wrap; gap: 6px;
  padding: 4px 0 2px;
}
.acc-tab {
  --acc-color: #8b5cff;
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 11px;
  background: rgba(255,255,255,.04);
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  color: var(--fg-soft);
  font-size: 12px; font-weight: 600;
  cursor: pointer;
  transition: all .15s ease;
}
.acc-tab:hover { background: rgba(255,255,255,.07); color: var(--fg); }
.acc-tab .acc-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--acc-color);
  box-shadow: 0 0 0 0 var(--acc-color);
}
.acc-tab.active {
  background: color-mix(in srgb, var(--acc-color) 14%, transparent);
  border-color: color-mix(in srgb, var(--acc-color) 50%, transparent);
  color: #fff;
  box-shadow: 0 4px 14px color-mix(in srgb, var(--acc-color) 20%, transparent);
}
.acc-tab.active .acc-dot {
  box-shadow: 0 0 8px var(--acc-color);
}

.search-box { position: relative; }
.search-box .icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--fg-faint); width: 16px; height: 16px; pointer-events: none; }
.search-box .input { padding-left: 36px; }

.sidebar-tabs { display: flex; gap: 4px; padding: 0 14px 10px; }
.tab {
  flex: 1; padding: 7px 10px; text-align: center; font-size: 12px; font-weight: 500;
  color: var(--fg-mute); background: transparent; border: 1px solid transparent; border-radius: 8px;
  transition: all .15s ease;
}
.tab:hover { color: var(--fg); background: rgba(255,255,255,.04); }
.tab.active { color: var(--fg); background: rgba(139,92,255,.12); border-color: rgba(139,92,255,.3); }

.chat-list { list-style: none; margin: 0; padding: 6px 8px 20px; overflow-y: auto; }
.chat-row {
  display: grid; grid-template-columns: 44px 1fr auto; gap: 12px; align-items: center;
  padding: 10px 12px; border-radius: 12px; cursor: pointer; position: relative;
  transition: background .14s ease;
}
.chat-row:hover { background: rgba(255,255,255,.035); }
.chat-row.active {
  background: linear-gradient(135deg, rgba(139,92,255,.12), rgba(0,212,255,.06));
  box-shadow: 0 0 0 1px rgba(139,92,255,.28) inset;
}
.chat-row.active::before {
  content: ""; position: absolute; left: 0; top: 14px; bottom: 14px; width: 3px;
  background: var(--grad-aurora); border-radius: 2px;
  box-shadow: 0 0 16px rgba(139,92,255,.6);
}
.chat-meta { min-width: 0; }
.chat-name {
  display: flex; align-items: center; gap: 6px;
  font-weight: 600; font-size: 14px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.chat-name .lock-ic { width: 12px; height: 12px; color: var(--amber); flex-shrink: 0; }
.chat-sub { font-size: 12.5px; color: var(--fg-mute); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
.chat-tags { display: flex; gap: 6px; margin-top: 6px; flex-wrap: wrap; }
.chat-tags .chip { font-size: 10.5px; padding: 2px 8px; }
.chat-right { text-align: right; display: grid; gap: 4px; justify-items: end; }
.chat-time { font-size: 11px; color: var(--fg-faint); white-space: nowrap; }

.empty-state {
  padding: 40px 20px; text-align: center; color: var(--fg-mute);
  display: grid; gap: 8px; justify-items: center;
}
.empty-state .icon { width: 28px; height: 28px; color: var(--fg-faint); }

/* avatars — holographic by hash */
.avatar {
  width: 44px; height: 44px; border-radius: 14px; position: relative; flex-shrink: 0;
  display: grid; place-items: center; font-weight: 700; font-size: 15px; color: #fff;
  letter-spacing: -0.02em;
  box-shadow: 0 6px 16px rgba(0,0,0,.35), 0 0 0 1px rgba(255,255,255,.08) inset;
}
.avatar::after {
  content: ""; position: absolute; inset: 0; border-radius: inherit;
  background: linear-gradient(135deg, rgba(255,255,255,.18), transparent 50%);
  pointer-events: none;
}
.avatar.sm { width: 30px; height: 30px; border-radius: 10px; font-size: 11px; }
.avatar.lg { width: 52px; height: 52px; border-radius: 16px; font-size: 18px; }

/* «Моя» аватарка в сообщениях — с лёгким ауроральным кольцом */
.msg.me .avatar {
  box-shadow:
    0 0 0 2px var(--bg-0),
    0 0 0 3px rgba(139,92,255,.55),
    0 6px 16px rgba(0,0,0,.35);
}

/* ==========================================================================
   THREAD
   ========================================================================== */
.thread { display: grid; grid-template-rows: auto 1fr auto; min-height: 0; height: 100vh; min-width: 0; }
.thread-empty {
  display: grid; place-items: center; height: 100%;
  text-align: center; color: var(--fg-mute);
}
.thread-empty .big {
  width: 92px; height: 92px; border-radius: 24px;
  background: linear-gradient(135deg, rgba(139,92,255,.15), rgba(0,212,255,.1));
  border: 1px solid rgba(139,92,255,.25);
  display: grid; place-items: center;
  margin: 0 auto 14px;
}
.thread-empty .big .icon { width: 36px; height: 36px; color: var(--violet); }
.thread-empty h2 { font-size: 16px; margin: 0 0 6px; color: var(--fg); }
.thread-empty p { margin: 0; font-size: 13px; }

.thread-head {
  padding: 14px 22px;
  display: flex; align-items: center; gap: 14px;
  border-bottom: 1px solid var(--line);
  background: rgba(10, 12, 20, 0.55);
  backdrop-filter: blur(18px) saturate(150%);
  -webkit-backdrop-filter: blur(18px) saturate(150%);
  position: relative; z-index: 3;
}
.thread-head::after {
  content: ""; position: absolute; left: 0; right: 0; bottom: -1px; height: 1px;
  background: linear-gradient(90deg, transparent, rgba(139,92,255,.35), rgba(0,212,255,.25), transparent);
  pointer-events: none;
}
.thread-head .meta { min-width: 0; flex: 1; }
.thread-head .name {
  font-weight: 700; font-size: 16px; letter-spacing: -0.015em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.thread-head .subline {
  font-size: 12px; color: var(--fg-mute);
  display: flex; gap: 6px; align-items: center; margin-top: 4px; flex-wrap: wrap;
}
.lock-badge { display: inline-flex; align-items: center; gap: 6px; padding: 5px 10px; background: rgba(255, 181, 71, .12); color: var(--amber); border: 1px solid rgba(255,181,71,.3); border-radius: var(--radius-pill); font-size: 11.5px; font-weight: 600; }
.lock-badge .icon { width: 12px; height: 12px; }

.thread-actions { display: flex; gap: 6px; }
.thread-actions select.input { width: auto; padding: 7px 28px 7px 10px; font-size: 12.5px; appearance: none; background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23a4a8b4' stroke-width='2'><polyline points='6 9 12 15 18 9'/></svg>"); background-repeat: no-repeat; background-position: right 8px center; }

.messages {
  overflow-y: auto;
  padding: 22px 22px 12px; display: flex; flex-direction: column; gap: 2px;
  scroll-behavior: smooth;
  scroll-padding-top: 36px;
}
.date-divider {
  position: sticky; top: 0; z-index: 2;
  align-self: center;
  display: inline-flex; align-items: center; justify-content: center;
  margin: 16px auto 10px; padding: 4px 14px;
  background: rgba(12,14,22,.7);
  backdrop-filter: blur(14px) saturate(140%);
  -webkit-backdrop-filter: blur(14px) saturate(140%);
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  color: var(--fg-soft); font-size: 11px; font-weight: 600;
  letter-spacing: .08em; text-transform: uppercase;
  pointer-events: none;
}

.msg {
  display: flex; gap: 10px; max-width: 78%;
  animation: msgIn .22s cubic-bezier(.2,.7,.3,1);
  margin-top: 12px;
  align-items: flex-end;
}
.msg.consecutive { margin-top: 2px; }
@keyframes msgIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}
.msg.me { margin-left: auto; flex-direction: row-reverse; }
.msg .bubble {
  position: relative;
  background: linear-gradient(180deg, rgba(255,255,255,.055), rgba(255,255,255,.025));
  border: 1px solid rgba(255,255,255,.08);
  padding: 8px 12px;
  border-radius: 16px 16px 16px 4px;  /* хвостик слева-снизу */
  word-break: break-word;
  box-shadow: 0 1px 0 rgba(255,255,255,.04) inset, 0 4px 14px rgba(0,0,0,.18);
  transition: background .15s ease, border-color .15s ease;
  min-width: 80px;
}
.msg.me .bubble {
  background: linear-gradient(135deg, rgba(139,92,255,.28), rgba(0,212,255,.22));
  border: 1px solid rgba(139,92,255,.45);
  border-radius: 16px 16px 4px 16px;  /* хвостик справа-снизу */
  box-shadow: 0 1px 0 rgba(255,255,255,.08) inset, 0 6px 18px rgba(139,92,255,.18);
}
.msg.consecutive .bubble { border-radius: 16px; }
.msg.consecutive .avatar { visibility: hidden; }

.msg .bubble .author {
  font-size: 12px; font-weight: 700;
  margin-bottom: 3px; letter-spacing: -0.01em;
}
.msg.them .bubble .author { color: var(--cyan); }
.msg.me   .bubble .author { color: #c9b8ff; }
.msg.consecutive .bubble .author { display: none; }

.msg .text {
  font-size: 14px; line-height: 1.5; white-space: pre-wrap;
  padding-right: 56px;       /* зарезервируем место под inline-время */
}
.msg .bubble:has(.img-wrap) .text { padding-right: 0; }
.msg .bubble:has(.img-wrap) .time { position: static; margin-top: 4px; }
.msg .img-wrap {
  display: inline-block !important;
  margin: 2px 0 6px;
  border-radius: 12px;
  overflow: hidden;
  max-width: 240px !important;
  max-height: 240px !important;
  background: rgba(0,0,0,.25);
  border: 1px solid rgba(255,255,255,.08);
  transition: transform .15s ease, box-shadow .2s ease;
  line-height: 0;
}
.msg .img-wrap:hover { transform: translateY(-1px); box-shadow: 0 10px 28px rgba(0,0,0,.4); }
.msg .img-wrap img {
  display: block !important;
  max-width: 240px !important;
  max-height: 240px !important;
  width: auto !important;
  height: auto !important;
  object-fit: contain;
  cursor: zoom-in;
}
.msg .time {
  position: absolute; right: 10px; bottom: 6px;
  font-size: 10.5px; color: var(--fg-faint);
  font-variant-numeric: tabular-nums;
  pointer-events: none;
}
.msg.me .time { color: rgba(214,200,255,.6); }

.msg-empty { color: var(--fg-mute); text-align: center; padding: 40px 20px; }

.msg-system {
  align-self: center;
  display: inline-flex; align-items: center; gap: 8px;
  margin: 14px auto 4px;
  padding: 7px 16px;
  background: linear-gradient(135deg, rgba(0,212,255,.08), rgba(139,92,255,.06));
  border: 1px solid rgba(0,212,255,.2);
  border-radius: var(--radius-pill);
  color: var(--fg-soft);
  font-size: 12px;
  font-weight: 500;
  max-width: 80%;
  text-align: center;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  animation: msgIn .22s cubic-bezier(.2,.7,.3,1);
}
.msg-system .icon { width: 13px; height: 13px; color: var(--cyan); flex-shrink: 0; }

.composer {
  padding: 14px 20px 18px;
  border-top: 1px solid var(--line);
  background: rgba(10, 12, 20, 0.65);
  backdrop-filter: blur(18px) saturate(150%);
  -webkit-backdrop-filter: blur(18px) saturate(150%);
  display: grid; gap: 8px;
  position: relative;
}
.composer::before {
  content: ""; position: absolute; left: 0; right: 0; top: -1px; height: 1px;
  background: linear-gradient(90deg, transparent, rgba(139,92,255,.25), rgba(0,212,255,.2), transparent);
  pointer-events: none;
}
.composer-row { display: grid; grid-template-columns: 1fr auto; gap: 10px; align-items: end; }
.composer-input-wrap {
  position: relative;
  background: var(--bg-input); border: 1px solid var(--line);
  border-radius: 16px; padding: 12px 14px;
  transition: border-color .15s ease, box-shadow .15s ease, background .15s ease;
}
.composer-input-wrap:focus-within {
  border-color: rgba(139,92,255,.55);
  background: rgba(139,92,255,.04);
  box-shadow: 0 0 0 4px rgba(139,92,255,.12), 0 8px 24px rgba(139,92,255,.08);
}
.composer textarea {
  width: 100%; background: transparent; border: 0; outline: 0; resize: none;
  color: var(--fg); min-height: 26px; max-height: 200px; line-height: 1.5;
}
.composer-footer { display: flex; justify-content: space-between; align-items: center; color: var(--fg-faint); font-size: 11px; }
.composer-footer .hint { font-family: 'JetBrains Mono', monospace; }
.composer-footer kbd { background: rgba(255,255,255,.06); border: 1px solid var(--line); border-radius: 4px; padding: 0 5px; font-family: inherit; }

.send-btn {
  width: 44px; height: 44px; border-radius: 12px; padding: 0;
  background: var(--grad-aurora); color: #07080d; border: 0;
  display: grid; place-items: center;
  transition: all .18s ease;
  box-shadow: 0 8px 22px rgba(139,92,255,.4);
}
.send-btn:hover:not(:disabled) { filter: brightness(1.1); transform: translateY(-1px); }
.send-btn:disabled { opacity: .4; cursor: not-allowed; background: rgba(255,255,255,.06); color: var(--fg-mute); box-shadow: none; }
.send-btn .icon { width: 18px; height: 18px; }

/* ==========================================================================
   ADMIN
   ========================================================================== */
.admin {
  display: grid; grid-template-columns: 64px 1fr; height: 100vh;
}
.admin-main { overflow-y: auto; padding: 28px 36px 60px; }
.admin-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 24px; }
.admin-head h1 { margin: 0; font-size: 24px; font-weight: 700; letter-spacing: -0.025em; }
.admin-head .crumb { color: var(--fg-mute); font-size: 13px; }
.admin-head nav { display: flex; gap: 8px; }

.card + .card { margin-top: 20px; }
.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; gap: 12px; }
.card-head h2 { margin: 0; font-size: 16px; font-weight: 700; letter-spacing: -0.015em; display: flex; align-items: center; gap: 10px; }
.card-head h2 .icon { width: 18px; height: 18px; color: var(--violet); }
.card-head p { margin: 0; }

.gk-row { display: grid; grid-template-columns: 1fr auto auto; gap: 10px; align-items: center; }
.status-pill { display: inline-flex; align-items: center; gap: 8px; padding: 7px 12px; border-radius: var(--radius-pill); border: 1px solid var(--line); background: rgba(255,255,255,.04); font-size: 12px; font-weight: 600; color: var(--fg-mute); }
.status-pill .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--fg-mute); }
.status-pill.ok { color: #b9f7da; border-color: rgba(44,224,161,.4); background: rgba(44,224,161,.1); }
.status-pill.ok .dot { background: var(--ok); box-shadow: 0 0 10px var(--ok); }
.status-pill.off { color: #ffc4cd; border-color: rgba(255,84,112,.4); background: rgba(255,84,112,.08); }
.status-pill.off .dot { background: var(--danger); }

/* item list (categories / employees) */
.item-list { display: grid; gap: 10px; }
.item {
  display: grid; grid-template-columns: auto 1fr auto; gap: 14px; align-items: start;
  padding: 14px 16px;
  background: rgba(255,255,255,.025); border: 1px solid var(--line); border-radius: 14px;
  transition: border-color .15s ease, background .15s ease;
}
.item:hover { border-color: var(--line-strong); background: rgba(255,255,255,.035); }
.item-body { display: grid; gap: 10px; min-width: 0; }
.item-title { display: flex; align-items: center; gap: 10px; }
.item-title .name { font-weight: 700; font-size: 14.5px; }
.item-title .login { color: var(--fg-mute); font-family: 'JetBrains Mono', monospace; font-size: 12px; }
.item-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.item-actions { display: flex; gap: 6px; align-items: start; }

.toggle-cat {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: var(--radius-pill);
  border: 1px solid var(--line); background: rgba(255,255,255,.03);
  font-size: 12px; color: var(--fg-soft); cursor: pointer;
  transition: all .12s ease;
}
.toggle-cat:hover { border-color: var(--line-strong); }
.toggle-cat.on {
  background: linear-gradient(135deg, rgba(139,92,255,.2), rgba(0,212,255,.14));
  border-color: rgba(139,92,255,.45); color: #e6dcff;
}
.toggle-cat .icon { width: 12px; height: 12px; }
.cat-toggles { display: flex; flex-wrap: wrap; gap: 6px; }

.switch { position: relative; display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-size: 12px; color: var(--fg-soft); }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch .track {
  width: 36px; height: 20px; border-radius: 999px; background: rgba(255,255,255,.08);
  position: relative; transition: background .2s ease;
}
.switch .track::after {
  content: ""; position: absolute; top: 2px; left: 2px;
  width: 16px; height: 16px; border-radius: 50%; background: #d6d8e3;
  transition: transform .2s ease;
}
.switch input:checked + .track { background: var(--grad-aurora); }
.switch input:checked + .track::after { transform: translateX(16px); background: #fff; }

/* ── Матрица прав сотрудника ──────────────────────────────────────────── */
.perm-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 12px;
}
.perm-group {
  background: rgba(255,255,255,.025);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
}
.perm-group-title {
  font-size: 11px; font-weight: 700; color: var(--cyan);
  text-transform: uppercase; letter-spacing: .08em;
  margin-bottom: 8px;
}
.perm-row {
  display: grid;
  grid-template-columns: 16px 1fr auto;
  gap: 8px; align-items: center;
  padding: 5px 4px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  transition: background .12s ease;
}
.perm-row:hover { background: rgba(255,255,255,.035); }
.perm-row input[type=checkbox] { width: auto; margin: 0; accent-color: #8b5cff; cursor: pointer; }
.perm-row .perm-label { color: var(--fg-soft); }
.perm-row.danger .perm-label { color: #ffd6dc; }
.perm-row.soon .perm-label { color: var(--fg-mute); }
.perm-tags { display: flex; gap: 4px; flex-wrap: wrap; }
.perm-tag {
  display: inline-block; padding: 1px 7px; border-radius: 999px;
  font-size: 10px; font-weight: 600;
  background: rgba(255,255,255,.05);
  color: var(--fg-mute);
  border: 1px solid var(--line);
}
.perm-tag.scope { color: #cdb6ff; border-color: rgba(139,92,255,.35); background: rgba(139,92,255,.1); }
.perm-tag.danger { color: #ffc4cd; border-color: rgba(255,84,112,.4); background: rgba(255,84,112,.1); }
.perm-tag.soon { color: var(--fg-faint); }

.acc-access-list { display: grid; gap: 12px; }
.acc-access-card {
  --acc-color: #8b5cff;
  border: 1px solid color-mix(in srgb, var(--acc-color) 40%, var(--line));
  background: color-mix(in srgb, var(--acc-color) 5%, transparent);
  border-radius: 12px;
  padding: 12px 14px;
}
.acc-access-head {
  display: flex; align-items: center; gap: 8px;
  margin-bottom: 8px;
  font-size: 14px;
}
.acc-access-head .acc-dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--acc-color);
  box-shadow: 0 0 8px var(--acc-color);
}
.acc-access-add {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: 10px 14px;
  border: 1px dashed var(--line);
  border-radius: 12px;
  background: rgba(255,255,255,.015);
}

.proxy-geo {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 14px; margin: 10px 0;
  background: rgba(0, 212, 255, .06);
  border: 1px solid rgba(0, 212, 255, .25);
  border-radius: 10px;
  font-size: 12.5px;
}
.proxy-geo .geo-flag { font-size: 22px; line-height: 1; }
.proxy-geo .geo-body { flex: 1; min-width: 0; }
.proxy-geo .geo-main { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; color: var(--fg); font-weight: 600; }
.proxy-geo .geo-sub { color: var(--fg-mute); font-size: 11.5px; margin-top: 2px; }
.proxy-geo .geo-sep { color: var(--fg-faint); }
.proxy-geo .geo-check { font-size: 11px; white-space: nowrap; }

.proxy-warn {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 10px 14px; margin: 10px 0;
  background: rgba(255,84,112,.08);
  border: 1px solid rgba(255,84,112,.35);
  border-radius: 10px;
  color: #ffd6dc;
  font-size: 12.5px; line-height: 1.4;
}
.proxy-warn .icon { width: 18px; height: 18px; color: var(--danger); flex-shrink: 0; margin-top: 1px; }
.proxy-warn strong { color: var(--danger); }

.audit-table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 12.5px; }
.audit-table thead th { text-align: left; padding: 10px 12px; color: var(--fg-mute); font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: .08em; border-bottom: 1px solid var(--line); }
.audit-table tbody td { padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; font-family: 'JetBrains Mono', monospace; font-size: 11.5px; color: var(--fg-soft); }
.audit-table tbody td:first-child { color: var(--fg-mute); }
.audit-table tbody tr:hover td { background: rgba(255,255,255,.02); }
.audit-table .action-tag { display: inline-block; padding: 1px 8px; background: rgba(139,92,255,.15); color: #d6c8ff; border-radius: 6px; font-weight: 600; }

/* ==========================================================================
   TOASTS
   ========================================================================== */
.toast-root { position: fixed; top: 18px; right: 18px; display: flex; flex-direction: column; gap: 10px; z-index: 1000; pointer-events: none; }
.toast {
  pointer-events: auto;
  min-width: 280px; max-width: 380px;
  padding: 12px 14px; border-radius: 12px;
  background: var(--bg-card); border: 1px solid var(--line);
  backdrop-filter: blur(20px) saturate(140%);
  -webkit-backdrop-filter: blur(20px) saturate(140%);
  box-shadow: 0 16px 40px rgba(0,0,0,.4);
  display: grid; grid-template-columns: 20px 1fr 18px; gap: 10px; align-items: start;
  animation: toastIn .25s ease-out;
  font-size: 13px;
}
.toast.ok    { border-color: rgba(44,224,161,.35); }
.toast.ok .ic { color: var(--ok); }
.toast.err   { border-color: rgba(255,84,112,.4); }
.toast.err .ic { color: var(--danger); }
.toast.info .ic { color: var(--cyan); }
.toast .ic { width: 18px; height: 18px; margin-top: 1px; }
.toast .body { color: var(--fg); line-height: 1.4; }
.toast .close { background: transparent; border: 0; color: var(--fg-faint); cursor: pointer; padding: 0; display: grid; place-items: center; width: 18px; height: 18px; }
.toast .close:hover { color: var(--fg); }
.toast.leaving { animation: toastOut .25s ease-in forwards; }
@keyframes toastIn  { from { transform: translateX(20px); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
@keyframes toastOut { from { transform: translateX(0); opacity: 1; } to { transform: translateX(20px); opacity: 0; } }

/* ==========================================================================
   RESPONSIVE
   ========================================================================== */
@media (max-width: 900px) {
  .app-shell { grid-template-columns: 56px 1fr; }
  .app-shell .thread { display: none; }
  .app-shell.thread-open { grid-template-columns: 1fr; }
  .app-shell.thread-open .rail, .app-shell.thread-open .sidebar { display: none; }
  .app-shell.thread-open .thread { display: grid; }
  .admin { grid-template-columns: 56px 1fr; }
  .admin-main { padding: 20px; }
  .item { grid-template-columns: 1fr; }
  .item-actions { justify-content: flex-end; }
}
