/* #global — 4-panel app layout */

/* Login overlay */
.login-overlay {
  position: fixed; inset: 0;
  background: #0f172a;
  display: flex; align-items: center; justify-content: center;
  z-index: 1000;
}
.login-overlay::before {
  content: '';
  position: absolute; inset: 0;
  background:
    radial-gradient(ellipse 600px 400px at 30% 30%, rgba(13,148,136,.15) 0%, transparent 70%),
    radial-gradient(ellipse 500px 500px at 75% 75%, rgba(13,148,136,.08) 0%, transparent 60%);
  pointer-events: none;
}
.login-overlay::after {
  content: '';
  position: absolute; inset: 0;
  background: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)' opacity='.04'/%3E%3C/svg%3E");
  pointer-events: none;
}
.login-overlay.hidden { display: none; }
/* Токен уже есть: показываем панель сразу, не дожидаясь модулей, —
   иначе форма логина мелькает секунду-две на каждом обновлении. */
.cs-authed .login-overlay { display: none; }

/* App shell. Панель скрыта, пока не известно, вошёл ли оператор:
   ранний скрипт в head ставит .cs-authed, если токен уже есть. */
#app { display: none; }
.cs-authed #app,
#app.ready {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* Nav rail */
.nav-rail {
  width: var(--nav-rail-width);
  transition: width var(--duration-base) var(--ease-out);
  background: #0f172a;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 12px 0 10px;
  gap: 2px;
  flex-shrink: 0;
  z-index: 10;
  border-right: 1px solid rgba(255,255,255,.06);
}
.nav-rail .nav-logo {
  width: 36px; height: 36px;
  background: var(--accent);
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 12px; font-weight: 800;
  margin-bottom: 14px;
  flex-shrink: 0;
  letter-spacing: .8px;
  box-shadow: 0 2px 10px var(--accent-glow);
}
#app.dev-brand .nav-rail .nav-logo {
  width: auto;
  min-width: 36px;
  padding: 0 10px;
  font-size: 10px;
  background: var(--warning);
  box-shadow: 0 2px 10px rgba(217,119,6,.3);
}
.nav-rail .nav-btn {
  width: 40px; height: 40px;
  border-radius: 9px;
  border: none; background: none; cursor: pointer;
  color: rgba(255,255,255,.35);
  display: flex; align-items: center; justify-content: center;
  font-size: 18px;
  transition: all var(--duration-fast) var(--ease-out);
  flex-shrink: 0;
  position: relative;
}
.nav-rail .nav-btn svg {
  width: 20px; height: 20px;
  stroke-width: 1.8;
}
.nav-rail .nav-btn:hover {
  background: var(--nav-btn-hover-bg);
  color: rgba(255,255,255,.8);
}
.nav-rail .nav-btn.active {
  background: var(--nav-btn-active-bg);
  color: #fff;
}
.nav-rail .nav-btn.active::before {
  content: '';
  position: absolute;
  left: -9px;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 20px;
  background: var(--accent);
  border-radius: 0 2px 2px 0;
}
.nav-badge {
  position: absolute;
  top: 2px; right: 2px;
  min-width: 16px; height: 16px;
  border-radius: 8px;
  background: var(--red);
  color: #fff;
  font-size: 9px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  padding: 0 4px;
  line-height: 1;
  box-shadow: 0 1px 4px rgba(220,38,38,.4);
}
.nav-rail .nav-bottom {
  margin-top: auto;
  display: flex; flex-direction: column;
  align-items: center; gap: 8px;
}
.nav-rail .nav-label {
  display: none;
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
/* Expanded rail. Overriding --nav-rail-width on #app keeps every
   calc(100vw - var(--nav-rail-width)) rule correct without touching them. */
#app.nav-expanded { --nav-rail-width: 190px; }
#app.nav-expanded .nav-rail {
  align-items: stretch;
  padding-left: 9px; padding-right: 9px;
}
#app.nav-expanded .nav-rail .nav-logo { align-self: center; }
#app.nav-expanded .nav-rail .nav-btn {
  width: 100%;
  justify-content: flex-start;
  gap: 10px;
  padding: 0 9px;
}
#app.nav-expanded .nav-rail .nav-btn svg { flex-shrink: 0; }
#app.nav-expanded .nav-rail .nav-label { display: block; }
#app.nav-expanded .nav-rail .nav-btn.active::before { left: -9px; }
#app.nav-expanded .nav-rail .nav-badge {
  position: static;
  /* В разметке бейдж стоит перед названием — во флексе отправляем его
     в конец, иначе margin-left:auto выталкивал название вправо. */
  order: 1;
  margin-left: auto;
  box-shadow: none;
}
#app.nav-expanded .nav-rail .nav-bottom { align-items: stretch; }
#app.nav-expanded .nav-rail .nav-logout-btn {
  width: 100%;
  justify-content: flex-start;
  gap: 10px;
  padding: 0 9px;
}
.nav-rail .nav-user {
  display: flex;
  align-items: center;
  gap: 10px;
}
#app.nav-expanded .nav-rail .nav-user { padding: 0 9px; }
#app.nav-expanded .nav-rail .nav-user .nav-label { color: rgba(255,255,255,.7); }
.nav-rail .nav-version {
  font-size: 9px;
  color: rgba(255,255,255,.35);
  text-align: center;
  margin-top: 4px;
  letter-spacing: .3px;
  white-space: nowrap;
  overflow: hidden;
  max-width: 100%;
  cursor: default;
}
#app.nav-expanded .nav-rail .nav-version { text-align: left; padding: 0 12px; }

.nav-rail .sse-status {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-bottom: 2px;
}
#app.nav-expanded .nav-rail .sse-status {
  justify-content: flex-start;
  padding: 0 9px 0 12px;
}
#app.nav-expanded .nav-rail .sse-status .nav-label {
  display: block;
  color: rgba(255,255,255,.55);
  font-size: 11px;
}
.nav-rail .sse-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--green);
  flex-shrink: 0;
  box-shadow: 0 0 0 3px rgba(22,163,74,.15);
  transition: all var(--duration-base) var(--ease-out);
}
.nav-rail .sse-dot.offline {
  background: var(--red);
  box-shadow: 0 0 0 3px rgba(220,38,38,.12);
  animation: pulse-dot 2s ease-in-out infinite;
}
@keyframes pulse-dot {
  0%, 100% { box-shadow: 0 0 0 3px rgba(220,38,38,.12); }
  50% { box-shadow: 0 0 0 6px rgba(220,38,38,.18); }
}
.nav-rail .nav-avatar {
  width: 30px; height: 30px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 700;
  cursor: pointer;
  transition: opacity var(--duration-fast) var(--ease-out);
}
.nav-rail .nav-avatar:hover { opacity: .85; }
.nav-rail .nav-logout-btn {
  width: 40px; height: 40px;
  border-radius: 9px;
  border: none; background: none; cursor: pointer;
  color: rgba(255,255,255,.3);
  display: flex; align-items: center; justify-content: center;
  font-size: 16px;
  transition: all var(--duration-fast) var(--ease-out);
}
.nav-rail .nav-logout-btn svg {
  width: 18px; height: 18px;
  stroke-width: 1.8;
}
.nav-rail .nav-logout-btn:hover {
  color: rgba(255,255,255,.7);
  background: rgba(220,38,38,.12);
}

/* Left panel */
.panel-left {
  width: var(--panel-width);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  background: var(--bg-card);
  flex-shrink: 0;
  overflow: hidden;
}
.panel-left .view {
  display: none;
  flex: 1;
  flex-direction: column;
  overflow: hidden;
}
.panel-left .view.active { display: flex; }

.panel-left-header {
  padding: 16px 14px 14px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.panel-title {
  font-size: 11px; font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .8px;
  display: block;
  margin-bottom: 10px;
}
.chat-search {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  font-family: inherit;
  outline: none;
  background: var(--bg-sunken);
  color: var(--text-primary);
  transition: all var(--duration-fast) var(--ease-out);
}
.chat-search::placeholder { color: var(--text-faint); }
.chat-search:focus {
  border-color: var(--accent);
  background: #fff;
  box-shadow: 0 0 0 3px var(--accent-subtle);
}

/* Main chat area */
.chat-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--bg-page);
  min-width: 0;
  overflow: hidden;
}

/* Right panel */
.panel-right {
  width: var(--panel-width);
  border-left: 1px solid var(--border);
  background: var(--bg-card);
  overflow-y: auto;
  flex-shrink: 0;
}

/* Focus mode for broadcasts/polls/analytics */
#app.focus-layout .panel-left {
  width: calc(100vw - var(--nav-rail-width));
}
#app.focus-layout .chat-area,
#app.focus-layout .panel-right {
  display: none;
}
#app.focus-layout .panel-left .admin-focus-view .panel-scroll {
  padding: 24px;
}

@media (max-width: 1024px) {
  #app.focus-layout .panel-left {
    width: calc(100vw - var(--nav-rail-width));
  }
  #app.focus-layout .panel-left .admin-focus-view .panel-scroll {
    padding: 16px;
  }
}

@media (max-width: 768px) {
  .panel-right { display: none; }
  .panel-left { width: 250px; flex-shrink: 0; }
}

/* Кнопка меню и затемнение — только на телефоне */
.mobile-menu-btn,
.mobile-menu-overlay { display: none; }

/* ---------------------------------------------------------------------------
   Телефон: рельс из десяти мелких иконок неудобен, поэтому он становится
   выезжающей панелью с подписями — как в обычных мобильных приложениях.
   --------------------------------------------------------------------------- */
@media (max-width: 640px) {
  .chat-back-btn { display: flex; }

  .mobile-menu-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    position: fixed;
    top: 8px; left: 8px;
    z-index: 60;
    width: 38px; height: 38px;
    border: none;
    border-radius: 10px;
    background: #0f172a;
    color: #fff;
    box-shadow: var(--shadow-md);
    cursor: pointer;
  }
  .mobile-menu-btn svg { width: 20px; height: 20px; stroke-width: 2; }

  .mobile-menu-overlay {
    position: fixed;
    inset: 0;
    z-index: 55;
    background: rgba(15,23,42,.45);
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--duration-base) var(--ease-out);
  }
  #app.nav-open .mobile-menu-overlay { display: block; opacity: 1; pointer-events: auto; }
  #app.mobile-chat-open .mobile-menu-btn { display: none; }

  /* Панель занимает всю высоту и выезжает слева */
  .nav-rail {
    position: fixed;
    top: 0; bottom: 0; left: 0;
    z-index: 58;
    width: 232px;
    height: 100%;
    flex-direction: column;
    align-items: stretch;
    padding: 14px 10px 10px;
    transform: translateX(-100%);
    transition: transform var(--duration-base) var(--ease-out);
    overflow-y: auto;
  }
  #app.nav-open .nav-rail { transform: translateX(0); }

  .nav-rail .nav-toggle-btn { display: none; }
  .nav-rail .nav-logo { align-self: flex-start; margin-left: 44px; }
  /* Подписи видны всегда: ради них панель и делалась */
  .nav-rail .nav-label { display: block; font-size: 14px; }
  .nav-rail .nav-btn {
    width: 100%;
    height: 44px;
    justify-content: flex-start;
    gap: 12px;
    padding: 0 12px;
  }
  .nav-rail .nav-btn.active::before { display: none; }
  .nav-rail .nav-badge { position: static; order: 1; margin-left: auto; }
  .nav-rail .nav-bottom { align-items: stretch; }
  .nav-rail .nav-logout-btn {
    width: 100%;
    height: 44px;
    justify-content: flex-start;
    gap: 12px;
    padding: 0 12px;
  }
  .nav-rail .nav-user { padding: 0 12px; }

  /* Раскладка: одна область за раз, рельс места не занимает */
  #app { --nav-rail-width: 0px; flex-direction: row; }
  .panel-left { width: 100% !important; flex: 1; min-height: 0; padding-top: 52px; }
  .panel-right { display: none; }
  .chat-area { display: none; }
  #app.mobile-chat-open .panel-left { display: none; }
  #app.mobile-chat-open .chat-area { display: flex; flex: 1; min-height: 0; }

  #app.focus-layout .panel-left { width: 100% !important; }
  .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .panel { max-width: none; }
  .panel-scroll { padding: 12px 10px; }
  .form-card { padding: 12px; }
  .ratings-figures { flex-wrap: wrap; gap: 10px; }
}

/* Сворачивание карточки контакта: на маленьких экранах она съедала
   ширину, нужную переписке. Панель сужается до полоски с ручкой, а не
   исчезает — иначе развернуть обратно будет нечем. */
.panel-right { position: relative; }
.panel-collapse-btn {
  position: absolute;
  top: 8px; left: 8px;
  width: 22px; height: 22px;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--bg-card);
  color: var(--text-muted);
  cursor: pointer;
  font-size: 13px;
  line-height: 1;
  display: flex; align-items: center; justify-content: center;
  transition: all var(--duration-fast) var(--ease-out);
  z-index: 2;
}
.panel-collapse-btn:hover { border-color: var(--accent); color: var(--accent); }
#app.profile-collapsed .panel-right {
  width: 34px;
  overflow: hidden;
}
#app.profile-collapsed .panel-right .user-info-panel { display: none; }
#app.profile-collapsed .panel-collapse-btn { transform: rotate(180deg); left: 6px; }
