/* ============================================================
   Pllato Suite — единый клиент
   Slack-style: rail (узкая панель) + опциональная вторая + main
   Цвета: синий бренд Pllato (#373d8d)
   ============================================================ */

:root {
  /* Dark theme (default) */
  --bg: #0d1024;
  --bg2: #161a35;
  --bg3: #1f2447;
  --bg4: #2a305a;
  --b1: rgba(255,255,255,0.08);
  --b2: rgba(255,255,255,0.15);
  --t1: #f0f1ff;
  --t2: #a4a8c8;
  --t3: #6f7398;
  --ac: #6168c4;
  --ac2: #8b91dc;
  --acbg: rgba(55,61,141,0.22);
  --acb: rgba(55,61,141,0.50);
  --gn: #3fd88e;
  --gnbg: rgba(63,216,142,0.12);
  --am: #ffcc00;
  --ambg: rgba(255,204,0,0.14);
  --rd: #e31e24;
  --rdbg: rgba(227,30,36,0.14);
  --tl: #3fc8d8;
  --tlbg: rgba(63,200,216,0.1);
  --r: 10px;
  --rl: 14px;
  --fd: 'Manrope', 'Trebuchet MS', sans-serif;
  --fb: 'Manrope', Tahoma, Verdana, sans-serif;
  --shadow: 0 4px 24px rgba(0,0,0,.45);
  
  /* Layout */
  --rail-w: 64px;
  --second-panel-w: 280px;
}

:root[data-theme="light"] {
  --bg: #f5f6fb;
  --bg2: #ffffff;
  --bg3: #eef0fa;
  --bg4: #dde1f3;
  --b1: rgba(55,61,141,0.10);
  --b2: rgba(55,61,141,0.20);
  --t1: #161a35;
  --t2: #4a4f72;
  --t3: #7d82a0;
  --ac: #373d8d;
  --ac2: #2a2f70;
  --acbg: rgba(55,61,141,0.08);
  --acb: rgba(55,61,141,0.30);
  --gn: #1fa869;
  --gnbg: rgba(31,168,105,0.1);
  --am: #b58700;
  --ambg: rgba(255,204,0,0.20);
  --rd: #e31e24;
  --rdbg: rgba(227,30,36,0.08);
  --tl: #1894a3;
  --tlbg: rgba(24,148,163,0.09);
  --shadow: 0 4px 24px rgba(55,61,141,.12);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: var(--fb);
  background: var(--bg);
  color: var(--t1);
  min-height: 100vh;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ============================================================
   LOGIN
   ============================================================ */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.login-card {
  background: var(--bg2);
  border: 1px solid var(--b1);
  border-radius: 16px;
  padding: 32px 28px;
  width: 100%;
  max-width: 420px;
}
.login-logo {
  font-family: var(--fd);
  font-size: 28px;
  font-weight: 800;
  color: var(--ac2);
  letter-spacing: 0.04em;
  margin-bottom: 4px;
}
.login-sub {
  font-size: 12px;
  color: var(--t3);
  margin-bottom: 24px;
}

/* ============================================================
   FORMS / BUTTONS / INPUTS (общие)
   ============================================================ */
.form-label {
  display: block;
  font-size: 12px;
  color: var(--t3);
  margin-bottom: 6px;
  font-weight: 500;
}
.input {
  background: var(--bg3);
  border: 1px solid var(--b2);
  border-radius: 10px;
  color: var(--t1);
  font-family: var(--fb);
  font-size: 16px;
  padding: 11px 14px;
  width: 100%;
  margin-bottom: 12px;
}
.input:focus { outline: none; border-color: var(--ac); }
.input:disabled { opacity: 0.5; cursor: not-allowed; }

.btn {
  background: var(--ac);
  border: none;
  border-radius: 10px;
  color: white;
  cursor: pointer;
  font-family: var(--fb);
  font-size: 13px;
  font-weight: 600;
  padding: 11px 22px;
  transition: opacity .15s, background .15s;
  width: 100%;
}
.btn:hover { background: var(--ac2); }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn.secondary {
  background: var(--bg3);
  color: var(--t1);
  border: 1px solid var(--b2);
}
.btn.secondary:hover { background: var(--bg4); }
.btn.danger {
  background: var(--rdbg);
  color: var(--rd);
  border: 1px solid rgba(227,30,36,.3);
}
.btn.danger:hover { background: var(--rd); color: white; }
.btn.success {
  background: var(--gnbg);
  color: var(--gn);
  border: 1px solid rgba(63,216,142,.3);
}
.btn.success:hover { background: var(--gn); color: white; }
.btn.sm {
  padding: 7px 14px;
  font-size: 12px;
  width: auto;
}

.error {
  background: var(--rdbg);
  border: 1px solid rgba(227,30,36,.3);
  border-radius: 8px;
  color: var(--rd);
  font-size: 12px;
  padding: 9px 12px;
  margin-bottom: 10px;
}

/* ============================================================
   APP LAYOUT — Slack style
   Rail (64px) | Second Panel (280px, optional) | Main (flex)
   ============================================================ */
.app {
  display: none;
  min-height: 100vh;
}
.app.active {
  display: grid;
  grid-template-columns: var(--rail-w) auto 1fr;
  grid-template-rows: 100vh;
}

/* ─── Rail (узкая панель модулей) ──────────────────────────── */
.rail {
  background: var(--bg2);
  border-right: 1px solid var(--b1);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 12px 0;
  gap: 4px;
}

.rail-logo {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: var(--ac);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--fd);
  font-size: 20px;
  font-weight: 800;
  margin-bottom: 8px;
  letter-spacing: -0.02em;
}

.rail-modules {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 8px 0;
  border-top: 1px solid var(--b1);
  width: 100%;
  align-items: center;
}

.rail-spacer {
  flex: 1;
}

.rail-bottom {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 8px 0;
  border-top: 1px solid var(--b1);
  width: 100%;
  align-items: center;
}

.rail-icon {
  position: relative;
  width: 44px;
  height: 44px;
  border-radius: 10px;
  background: transparent;
  border: none;
  cursor: pointer;
  font-size: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--t2);
  transition: background .15s, color .15s;
}
.rail-icon:hover {
  background: var(--bg3);
  color: var(--t1);
}
.rail-icon.active {
  background: var(--acbg);
  color: var(--ac2);
  /* Полоска слева — индикатор активного */
  box-shadow: -3px 0 0 0 var(--ac) inset;
  border-radius: 10px;
}

.rail-icon-emoji {
  display: block;
  line-height: 1;
}

.rail-icon-badge {
  position: absolute;
  top: 4px;
  right: 4px;
  min-width: 16px;
  height: 16px;
  border-radius: 8px;
  background: var(--rd);
  color: white;
  font-size: 10px;
  font-weight: 700;
  padding: 0 5px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.rail-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--ac);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  overflow: hidden;
  transition: transform .15s;
}
.rail-avatar:hover { transform: scale(1.05); }
.rail-avatar img { width: 100%; height: 100%; object-fit: cover; }

/* ─── Second Panel (для Чата) ──────────────────────────────── */
.second-panel {
  background: var(--bg2);
  border-right: 1px solid var(--b1);
  width: var(--second-panel-w);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.second-panel-header {
  padding: 14px;
  border-bottom: 1px solid var(--b1);
}

.second-panel-body {
  flex: 1;
  overflow-y: auto;
}

/* Когда second-panel не показывается, грид перестраивается */
.app.active:has(#second-panel[style*="display: none"]) {
  grid-template-columns: var(--rail-w) 0 1fr;
}

/* ─── Main (основная область) ─────────────────────────────── */
.main {
  padding: 24px 32px;
  overflow-y: auto;
}

/* ============================================================
   COMMON UI (топбары, страницы, таблицы)
   ============================================================ */
.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 22px;
}
.page-title {
  font-family: var(--fd);
  font-size: 20px;
  font-weight: 700;
  color: var(--t1);
  flex: 1;
}

.icon-btn {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: var(--bg3);
  border: 1px solid var(--b1);
  color: var(--t2);
  cursor: pointer;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all .15s;
}
.icon-btn:hover { background: var(--bg4); color: var(--ac2); }

.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--t3);
}
.empty-state .icon { font-size: 36px; margin-bottom: 10px; opacity: .5; }
.empty-state .text { font-size: 13px; }

/* Toolbar для списков */
.users-toolbar {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-bottom: 14px;
  flex-wrap: wrap;
}
.users-toolbar .input { margin: 0; max-width: 300px; }

.dept-filter {
  background: var(--bg3);
  border: 1px solid var(--b2);
  border-radius: 8px;
  color: var(--t1);
  font-family: var(--fb);
  font-size: 13px;
  padding: 9px 12px;
  cursor: pointer;
  min-width: 180px;
}

/* Таблица (Сотрудники / Клиенты) */
.users-table-wrap {
  background: var(--bg2);
  border: 1px solid var(--b1);
  border-radius: var(--rl);
  overflow: hidden;
}
.users-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.users-table th {
  padding: 10px 14px;
  text-align: left;
  font-size: 10px;
  font-weight: 600;
  color: var(--t3);
  text-transform: uppercase;
  letter-spacing: .06em;
  border-bottom: 1px solid var(--b1);
  background: var(--bg3);
}
.users-table td {
  padding: 11px 14px;
  border-bottom: 1px solid var(--b1);
  color: var(--t2);
  vertical-align: middle;
}
.users-table tr:last-child td { border-bottom: none; }
.users-table tr.row { cursor: pointer; transition: background .12s; }
.users-table tr.row:hover td { background: var(--bg3); }

.user-cell {
  display: flex;
  align-items: center;
  gap: 10px;
}
.user-cell .name { color: var(--t1); font-weight: 600; }
.user-cell .username { font-size: 11px; color: var(--t3); }

.user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--ac);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 12px;
  flex-shrink: 0;
  overflow: hidden;
}
.user-avatar img { width: 100%; height: 100%; object-fit: cover; }

.role-badge {
  display: inline-block;
  font-size: 10px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 8px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.role-badge.owner { background: var(--ambg); color: var(--am); }
.role-badge.admin { background: var(--acbg); color: var(--ac2); }
.role-badge.user { background: var(--bg3); color: var(--t3); }

.type-badge {
  display: inline-block;
  font-size: 9px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 5px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-right: 6px;
  vertical-align: middle;
}
.type-badge.individual { background: var(--gnbg); color: var(--gn); }
.type-badge.company    { background: var(--tlbg); color: var(--tl); }
.type-badge.archived   { background: var(--rdbg); color: var(--rd); }

/* ============================================================
   MODAL
   ============================================================ */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(8,10,28,0.78);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal {
  background: var(--bg2);
  border: 1px solid var(--b1);
  border-radius: 16px;
  width: 100%;
  max-width: 540px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 22px;
  border-bottom: 1px solid var(--b1);
}
.modal-header h2 {
  font-family: var(--fd);
  font-size: 17px;
  font-weight: 700;
  color: var(--t1);
}
.modal-body { padding: 18px 22px; overflow-y: auto; }
.modal-footer {
  display: flex;
  gap: 10px;
  padding: 14px 22px;
  border-top: 1px solid var(--b1);
  justify-content: flex-end;
}
.form-group { margin-bottom: 14px; }

/* Departments inline editor */
.dept-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.dept-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: var(--bg3);
  border: 1px solid var(--b1);
  border-radius: 10px;
}
.dept-row .name {
  flex: 1;
  font-size: 13px;
  font-weight: 500;
  color: var(--t1);
}
.dept-row .count {
  font-size: 11px;
  color: var(--t3);
  background: var(--bg2);
  padding: 2px 8px;
  border-radius: 6px;
}

/* ============================================================
   SIDE PANEL (Bitrix-style для клиента)
   ============================================================ */
.side-panel {
  position: fixed;
  top: 0;
  right: 0;
  width: 480px;
  max-width: 100vw;
  height: 100vh;
  background: var(--bg2);
  border-left: 1px solid var(--b1);
  box-shadow: var(--shadow);
  z-index: 90;
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform .25s ease;
  pointer-events: none;
}
.side-panel.open {
  transform: translateX(0);
  pointer-events: auto;
}
.side-panel-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 22px;
  border-bottom: 1px solid var(--b1);
}
.side-panel-header h2 {
  font-family: var(--fd);
  font-size: 17px;
  font-weight: 700;
  color: var(--t1);
  line-height: 1.3;
  overflow: hidden;
  text-overflow: ellipsis;
  word-break: break-word;
}
.side-panel-meta {
  font-size: 11px;
  color: var(--t3);
  margin-top: 4px;
}
.side-panel-body {
  flex: 1;
  overflow-y: auto;
  padding: 18px 22px;
  overscroll-behavior: contain;
}
.side-panel-footer {
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 14px 22px;
  border-top: 1px solid var(--b1);
}
.cp-textarea {
  resize: vertical;
  font-family: var(--fb);
  min-height: 100px;
  line-height: 1.5;
}

/* ============================================================
   MOBILE
   ============================================================ */
@media (max-width: 768px) {
  /* Rail уезжает в нижний таб-бар */
  .app.active {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr 60px;
  }
  
  .rail {
    grid-row: 2;
    grid-column: 1;
    flex-direction: row;
    padding: 0 12px;
    border-right: none;
    border-top: 1px solid var(--b1);
  }
  .rail-logo { display: none; }
  .rail-modules {
    flex-direction: row;
    border-top: none;
    padding: 0;
    flex: 1;
    justify-content: space-around;
  }
  .rail-spacer { display: none; }
  .rail-bottom {
    flex-direction: row;
    border-top: none;
    padding: 0;
    width: auto;
  }
  .rail-icon { width: 40px; height: 40px; font-size: 20px; }
  .rail-icon.active { box-shadow: 0 -3px 0 0 var(--ac) inset; }
  
  .main { padding: 16px; grid-row: 1; }
  
  /* Вторая панель на мобиле во всю ширину поверх main */
  .second-panel {
    grid-row: 1;
    width: 100%;
  }
  
  /* Side panel — на мобиле во всю ширину */
  .side-panel { width: 100vw; }
  
  /* Скрываем колонки Отдел и Телефон в таблицах на маленьких экранах */
  .users-table th:nth-child(4),
  .users-table td:nth-child(4),
  .users-table th:nth-child(5),
  .users-table td:nth-child(5) { display: none; }
}
