:root{
  --bg: #f6f1f3;
  --card: rgba(255,255,255,0.82);
  --text: #1b1719;
  --muted: rgba(27,23,25,0.66);
  --border: rgba(96,97,98,0.16);
  --shadow: 0 18px 40px rgba(88,60,70,0.14);
  --shadow-soft: 0 10px 24px rgba(88,60,70,0.08);
  --radius: 20px;
  --radius-sm: 16px;
  --primary: #cc4c6e;
  --primary-hover: #b63d5d;
  --danger: #a12f4b;
  --focus: rgba(204,76,110,0.22);
  --accent-dark: #606162;
  --accent-soft: #c8a0aa;
  --accent-gold: #c89b2b;
  --blur: 18px;
  --speed: 220ms;
  --speed-slow: 340ms;
  --ease: cubic-bezier(.2,.8,.2,1);
  --max: 1200px;
}

*{ box-sizing:border-box; }
html,body{ height:100%; }

body{
  margin:0;
  font-family: ui-sans-serif, -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text", "Segoe UI", Roboto, Arial, sans-serif;
  background: radial-gradient(1200px 600px at 10% 0%, rgba(204,76,110,0.18), transparent 60%),
              radial-gradient(900px 500px at 90% 10%, rgba(200,160,170,0.22), transparent 55%),
              linear-gradient(180deg, #fbf7f8 0%, #f6f1f3 100%);
  color:var(--text);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* TOPBAR */
.topbar{
  position: sticky;
  top: 0;
  z-index: 50;
  backdrop-filter: blur(var(--blur));
  -webkit-backdrop-filter: blur(var(--blur));
  background: rgba(255,255,255,0.76);
  border-bottom: 1px solid var(--border);
}
.topbar__inner{
  max-width: var(--max);
  margin: 0 auto;
  padding: 14px 24px;
  display:flex;
  align-items:center;
  gap:14px;
}

.brand{
  display:flex;
  align-items:center;
  justify-content:center;
  min-width:auto;
  max-width:320px;
  gap:0;
  margin-right:20px;
}

@media (max-width: 720px){
  .brand{
    min-width:0;
    gap:0;
    margin-right:0;
  }

  .brand__logo{
    font-size:18px;
  }
}

.brand__logo{
  font-weight: 900;
  font-size: 20px;
  letter-spacing: 0.12em;
  color: var(--text);
  user-select: none;
  transition: transform 0.2s ease, opacity 0.2s ease;
}

/* лёгкий hover */
.brand__logo:hover{
  transform: translateY(-1px);
  opacity: 0.85;
}

.topnav{
  display:flex;
  align-items:center;
  gap:10px;
  flex:1;
  justify-content:flex-end;
}
.topnav__spacer{ flex:1; }

/* ===========================
   FIX TOP BUTTONS ALIGNMENT
   =========================== */
.nav-item{
  display:inline-flex;
  align-items:center;
  gap:8px;
  padding: 9px 12px;
  border-radius: 999px;
  text-decoration:none;
  color: var(--text);
  font-weight:800;
  font-size:13px;

  /* важные фиксы */
  line-height: 1;
  white-space: nowrap;
  letter-spacing: 0;
  border:1px solid transparent;

  transition: transform var(--speed) var(--ease),
              background var(--speed) var(--ease),
              border-color var(--speed) var(--ease);
  user-select:none;
  cursor:pointer;
}

/* FIX: FontAwesome иногда задаёт разную ширину иконкам -> выравниваем */
.nav-item i{
  width: 18px;
  flex: 0 0 18px;
  text-align: center;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* FIX: если текст обёрнут в <span> — делаем его блочным */
.nav-item span{
  display:inline-block;
  line-height: 1;
}

.nav-item:hover{ background: rgba(0,0,0,0.04); transform: translateY(-1px); }
.nav-item.active{ background: rgba(204,76,110,0.14); border-color: rgba(204,76,110,0.28); color: var(--primary); }

.nav-toggle{
  display:none;
  width:42px;height:40px;
  border-radius:12px;
  border:1px solid var(--border);
  background: rgba(255,255,255,0.6);
  box-shadow: var(--shadow-soft);
  cursor:pointer;
}
.nav-toggle span{
  display:block; height:2px; width:18px; margin:5px auto;
  background: rgba(29,29,31,0.85);
  border-radius:2px;
}

/* PAGE */
.page{
  max-width: var(--max);
  margin: 0 auto;
  padding: 26px 24px 48px;
}

.section-head{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:14px;
  margin: 10px 0 18px;
}
.section-head h2{
  margin:0;
  font-size:26px;
  letter-spacing:-0.02em;
}

.content-section{ display:none; animation: fadeInUp var(--speed-slow) var(--ease) both; }
.content-section.is-active{ display:block; }
@keyframes fadeInUp{
  from{ opacity:0; transform: translateY(8px); }
  to{ opacity:1; transform: translateY(0); }
}

/* CARDS */
.card{
  background: var(--card);
  backdrop-filter: blur(var(--blur));
  -webkit-backdrop-filter: blur(var(--blur));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-soft);
}

/* BUTTONS */
.btn{
  display:inline-flex;
  align-items:center;
  justify-content:center;
  gap:8px;
  border-radius: 999px;
  padding: 10px 14px;
  font-weight: 800;
  font-size: 13px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: transform var(--speed) var(--ease),
              box-shadow var(--speed) var(--ease),
              background var(--speed) var(--ease),
              border-color var(--speed) var(--ease);
  user-select:none;
}
.btn:active{ transform: scale(0.98); }

.btn i{
  width: 18px;
  flex: 0 0 18px;
  text-align:center;
  display:inline-flex;
  align-items:center;
  justify-content:center;
}

.btn--primary{
  background: linear-gradient(135deg, var(--primary), #db6f8d);
  color:#fff;
  box-shadow: 0 12px 24px rgba(204,76,110,0.28);
}

.btn--primary:hover{
  background: linear-gradient(135deg, var(--primary-hover), #c95b79);
  box-shadow: 0 14px 28px rgba(204,76,110,0.32);
}

.btn--ghost{
  background: rgba(0,0,0,0.04);
  border-color: var(--border);
  color: var(--text);
}
.btn--ghost:hover{ background: rgba(0,0,0,0.06); }

/* Настройки: внутренние вкладки */
.settings-tabs .btn.active{
  background: rgba(204,76,110,0.12);
  border-color: rgba(204,76,110,0.24);
}

.btn--danger{
  background: rgba(214,43,43,0.10);
  border-color: rgba(214,43,43,0.22);
  color: #8b1d1d;
}

/* BRANCH GRID */
.branches-grid{
  display:grid;
  grid-template-columns: repeat(auto-fit, minmax(360px, 1fr));
  gap: 18px;
  align-items:start;
}
.branch-card{ padding: 20px; }
.branch-card h3{ margin:0 0 10px; letter-spacing:-0.02em; }
.branch-card p{ margin:7px 0; color: var(--muted); }
.branch-actions{ margin-top:14px; display:flex; flex-wrap:wrap; gap:10px; }

/* STATUS */
.status{
  display:inline-flex;
  align-items:center;
  gap:6px;
  padding:6px 10px;
  border-radius:999px;
  font-weight:800;
  font-size:12px;
  border: 1px solid var(--border);
  background: rgba(0,0,0,0.03);
}
.status-1{
  background: rgba(204,76,110,0.12);
  border-color: rgba(204,76,110,0.24);
  color: #8f3450;
}
.status-0{
  background: rgba(214,43,43,0.10);
  border-color: rgba(214,43,43,0.22);
  color: #8b1d1d;
}

/* TABLE */
.data-table-container{ overflow-x:auto; border-radius: var(--radius); }
table{
  width:100%;
  border-collapse: separate;
  border-spacing: 0;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow:hidden;
}
th, td{
  padding: 12px 14px;
  text-align:left;
  border-bottom: 1px solid rgba(0,0,0,0.06);
  font-size: 13px;
}
th{
  color: rgba(29,29,31,0.65);
  font-weight: 900;
  background: rgba(255,255,255,0.35);
}
tr:last-child td{ border-bottom:none; }

/* LOADING / ERROR */
.loading-card, .error{
  padding: 14px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.60);
}
.loading-card{ color: var(--primary); box-shadow: var(--shadow-soft); }
.error{
  color: #8b1d1d;
  background: rgba(214,43,43,0.08);
  border-color: rgba(214,43,43,0.22);
}

/* MODALS */
.modal{
  position: fixed;
  inset: 0;
  display:flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  background: rgba(0,0,0,0.40);
  z-index: 1000;

  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity var(--speed-slow) var(--ease), visibility var(--speed-slow) var(--ease);
}
.modal.is-open{
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

/*
  ALERT/CONFIRM должны быть всегда поверх остальных окон.
  Все модалки используют одинаковый z-index, поэтому если какая-то модалка
  расположена ниже по DOM, она может перекрыть alert/confirm.
  Явно поднимаем их выше всех.
*/
#confirm-modal,
#alert-modal{
  z-index: 5000;
}
.modal-content{
  width: min(760px, 100%);
  max-height: min(85vh, 820px);
  overflow:auto;
  background: rgba(255,255,255,0.88);
  backdrop-filter: blur(var(--blur));
  -webkit-backdrop-filter: blur(var(--blur));
  border: 1px solid var(--border);
  border-radius: 22px;
  box-shadow: var(--shadow);
  padding: 18px 18px 14px;
  transform: translateY(10px) scale(0.98);
  transition: transform var(--speed-slow) var(--ease);
}

/* Компактные модалки (например, confirm) */
.modal-content--sm{
  width: min(520px, 100%);
  max-height: min(78vh, 520px);
}

.confirm-head{
  display:flex;
  align-items:flex-start;
  gap: 12px;
  margin-bottom: 6px;
}
.confirm-icon{
  width: 44px;
  height: 44px;
  border-radius: 14px;
  display:flex;
  align-items:center;
  justify-content:center;
  border: 1px solid rgba(0,0,0,0.10);
  background: rgba(214,43,43,0.10);
  color: #8b1d1d;
  box-shadow: 0 10px 26px rgba(214,43,43,0.14);
  flex: 0 0 auto;
}
.confirm-icon.is-neutral{
  background: rgba(204,76,110,0.10);
  color: var(--primary);
  box-shadow: 0 10px 26px rgba(204,76,110,0.16);
}
.confirm-actions{
  display:flex;
  justify-content:flex-end;
  gap: 10px;
  margin-top: 14px;
}
.modal.is-open .modal-content{
  transform: translateY(0) scale(1);
}

.close-button{
  position: sticky;
  top: 6px;
  margin-left: auto;
  display:inline-flex;
  align-items:center;
  justify-content:center;
  width:40px;height:40px;
  border-radius:999px;
  border:1px solid var(--border);
  background: rgba(0,0,0,0.04);
  cursor:pointer;
  font-size:22px;
  line-height:1;
}
.close-button:hover{ background: rgba(0,0,0,0.06); }

.modal-body{ padding-top: 8px; }

/* одинаковый отступ у кнопок в модалках (в т.ч. "Сохранить") */
.modal-body form .btn{ margin-top: 14px; }

/* FORMS */
label{
  display:block;
  margin: 10px 0 6px;
  font-weight: 800;
  font-size: 12px;
  color: rgba(29,29,31,0.72);
}
input[type="text"],
input[type="password"],
input[type="number"]{
  width:100%;
  padding:10px 12px;
  border-radius:14px;
  border: 1px solid rgba(0,0,0,0.12);
  background: rgba(255,255,255,0.75);
  outline:none;
  transition: border-color var(--speed) var(--ease), box-shadow var(--speed) var(--ease);
}

select{
  width:100%;
  padding:10px 12px;
  border-radius:14px;
  border: 1px solid rgba(0,0,0,0.12);
  background: rgba(255,255,255,0.75);
  outline:none;
  transition: border-color var(--speed) var(--ease), box-shadow var(--speed) var(--ease);
}

/* Выбор филиалов (чекбоксы) в модалке администратора */
.branches-picker{
  max-height: 260px;
  overflow: auto;
  padding: 8px;
  margin-top: 8px;
  border-radius:14px;
  border: 1px solid rgba(0,0,0,0.12);
  background: rgba(255,255,255,0.75);
}

.branch-item{
  display:flex;
  align-items:center;
  gap:10px;
  padding:10px 12px;
  border-radius:12px;
  cursor:pointer;
  user-select:none;
}
.branch-item:hover{ background: rgba(0,0,0,0.04); }
.branch-item input{ margin:0; }
.branch-item span{ font-weight:700; font-size:13px; }
select:focus{
  border-color: rgba(204,76,110,0.5);
  box-shadow: 0 0 0 6px var(--focus);
}
input:focus{
  border-color: rgba(204,76,110,0.5);
  box-shadow: 0 0 0 6px var(--focus);
}
.checkbox-container{
  display:flex;
  align-items:center;
  gap:10px;
  padding:10px 12px;
  border-radius:14px;
  border:1px solid rgba(0,0,0,0.08);
  background: rgba(255,255,255,0.55);
}

/* RESPONSIVE */
@media (max-width: 720px){
  .nav-toggle{ display:inline-flex; }

  .topnav{
    position: fixed;
    top: 64px;
    left: 12px;
    right: 12px;
    background: rgba(255,255,255,0.82);
    border: 1px solid var(--border);
    border-radius: 18px;
    padding: 10px;
    box-shadow: var(--shadow);
    display: none;
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
  }
  .topnav.is-open{ display:flex; }
  .topnav__spacer{ display:none; }

  .page{ padding: 20px 14px 44px; }
  .section-head{ flex-direction: column; align-items: stretch; }
  .section-head .btn{ width:100%; }

  .branches-grid{ grid-template-columns: 1fr; gap: 14px; }
}

@media (prefers-reduced-motion: reduce){
  *{ transition: none !important; animation:none !important; }
}

/* Отступ для кнопок сохранения в модальных окнах */
#add-branch-form > button[type="submit"],
#edit-branch-details-form > button[type="submit"],
#yclients-config-form > button[type="submit"],
#edit-user-password-form > button[type="submit"]{
  margin-top: 24px;
}

/* =========================================================
   НАСТРОЙКИ: визуальное разделение групп филиалов и строк пользователей
   - строка группы (филиал): более плотный фон + границы
   - строки пользователей: более "легкий" фон + hover
   ========================================================= */

/* Строка-заголовок группы филиала (создаётся в app.js как <tr class="group-row">) */
.group-row td{
  padding: 14px 16px;
  font-weight: 900;
  font-size: 13px;
  letter-spacing: -0.01em;
  background: rgba(0,0,0,0.04);
  border-top: 2px solid rgba(0,0,0,0.10);
  border-bottom: 1px solid rgba(0,0,0,0.10);
}

/* Строки пользователей */
tbody tr:not(.group-row) td{
  background: rgba(255,255,255,0.55);
  border-bottom: 1px solid rgba(0,0,0,0.06);
  font-size: 13px;
}

/* Лёгкая подсветка при наведении (только на строки пользователей) */
tbody tr:not(.group-row):hover td{
  background: rgba(204,76,110,0.06);
}

/* Немного “воздуха” между группами: скругление в таблице визуально заметнее */
tbody tr.group-row:first-child td{
  border-top: 1px solid rgba(0,0,0,0.10);
}

/* =========================================================
   ✅ ДОБАВЛЕНО: АККОРДЕОН ФИЛИАЛОВ В "НАСТРОЙКАХ"
   (работает с app.js: tr.group-row[data-branch][aria-expanded])
   ========================================================= */

/* Делает всю строку группы кликабельной */
tr.group-row{
  cursor: pointer;
  user-select: none;
}

/* Hover для всей строки (не только td) */
tr.group-row:hover td{
  background: rgba(0,0,0,0.055);
}

/* Фокус с клавиатуры (в app.js у строки tabindex="0") */
tr.group-row:focus{
  outline: none;
}
tr.group-row:focus td{
  box-shadow: inset 0 0 0 2px rgba(204,76,110,0.35);
}

/* Стрелка ▸ / ▾ */
.group-toggle{
  display: inline-block;
  width: 18px;
  margin-right: 6px;
  text-align: center;
  opacity: 0.9;
  transition: transform var(--speed) var(--ease);
}

/* При сворачивании (aria-expanded="false") слегка поворачиваем стрелку */
tr.group-row[aria-expanded="false"] .group-toggle{
  transform: rotate(-90deg);
}

/* Небольшой “вложенный” отступ у пользователей внутри группы */
tr.user-row td:first-child{
  padding-left: 34px;
}

/* FIX: фиксируем ширины колонок в таблице "Настройки" */
#settings-content table {
  table-layout: fixed;      /* не пересчитывать ширины при появлении строк */
  width: 100%;
}

#settings-content table th,
#settings-content table td {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Фиксируем ширины колонок */
#settings-content table th:nth-child(1),
#settings-content table td:nth-child(1) {
  width: 220px;            /* ID пользователя */
}

#settings-content table th:nth-child(2),
#settings-content table td:nth-child(2) {
  width: auto;             /* Имя занимает остаток */
}

#settings-content table th:nth-child(3),
#settings-content table td:nth-child(3) {
  width: 170px;            /* Действия (кнопка) */
}
#settings-content table.settings-table{
  table-layout: fixed;
  width: 100%;
}
#settings-content table.settings-table th,
#settings-content table.settings-table td{
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* В колонке "Действия" не режем кнопки многоточием */
#settings-content table.settings-table td.actions-cell{
  white-space: normal;
  overflow: visible;
  text-overflow: clip;
}
#settings-content table.settings-table td.actions-cell .actions{
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.faq-grid{
  display:grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 18px;
}
.faq-card{
  padding: 22px;
  display:flex;
  gap:16px;
  align-items:flex-start;
}
.faq-card__icon{
  width:54px;
  height:54px;
  border-radius:16px;
  display:flex;
  align-items:center;
  justify-content:center;
  background: linear-gradient(135deg, rgba(204,76,110,0.14), rgba(200,160,170,0.18));
  color: var(--primary);
  flex:0 0 54px;
  font-size: 20px;
}
.faq-card__body h3{
  margin: 2px 0 10px;
  font-size: 20px;
  letter-spacing: -0.02em;
}
.faq-card__body p{
  margin:0;
  color: var(--muted);
  line-height:1.5;
}
.faq-video-placeholder{
  margin-top:16px;
  min-height: 132px;
  border-radius: 18px;
  border: 1px dashed rgba(204,76,110,0.28);
  background: linear-gradient(180deg, rgba(255,255,255,0.72), rgba(204,76,110,0.07));
  display:flex;
  flex-direction:column;
  align-items:center;
  justify-content:center;
  gap:10px;
  color: var(--primary);
  font-weight:800;
  text-align:center;
  padding:18px;
}
.faq-video-placeholder i{
  font-size: 26px;
}