:root{
  --bg:           #fafafa;
  --bg-elev-1:    #ffffff;
  --bg-elev-2:    #ffffff;
  --bg-elev-3:    #ffffff;
  --bg-elev-4:    #f5f5f7;

  --text:         #1d1d1f;
  --text-muted:   #6e6e73;
  --text-dim:     #8e8e93;

  --border:       #e5e5e7;
  --border-soft:  #ededf0;

  --green:        #2d8659;
  --green-hover:  #246e48;
  --green-bg:     #e8f5ee;

  --blue:         #1c6dd0;
  --blue-bg:      #e7f0fb;

  --orange:       #b5651d;
  --orange-bg:    #fbf1e4;

  --red:          #b83a3a;
  --red-bg:       #fbebeb;

  --purple:       #8e44ad;
  --purple-bg:    #f4ebfa;

  --gray-badge:   #ededf0;

  --shadow-sm:    0 1px 2px rgba(0,0,0,0.04), 0 1px 1px rgba(0,0,0,0.02);
  --shadow-md:    0 2px 8px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-lg:    0 12px 32px rgba(0,0,0,0.12), 0 2px 8px rgba(0,0,0,0.06);

  --r-sm:  6px;
  --r-md:  10px;
  --r-lg:  14px;

  --safe-top:    env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left:   env(safe-area-inset-left, 0px);
  --safe-right:  env(safe-area-inset-right, 0px);
}

*{box-sizing:border-box}

html,body{
  height:100%;
  /* C.2c-fix-3: запрещаем только горизонтальные жесты навигации.
     Вертикальный overscroll оставляем — нужен для pull-to-refresh. */
  overscroll-behavior-x: none;
}

html{
  /* Иногда достаточно просто обрезать по ширине, чтобы браузер
     перестал показывать «предпросмотр предыдущей страницы» */
  overflow-x: hidden;
}

body{
  font:15px system-ui,-apple-system,"Segoe UI",Roboto,"Helvetica Neue",sans-serif;
  margin:0;
  background:var(--bg);
  color:var(--text);
  padding-bottom: calc(120px + var(--safe-bottom));
  -webkit-font-smoothing:antialiased;
  text-rendering:optimizeLegibility;
  scroll-padding-bottom: calc(120px + var(--safe-bottom));
  width: 100%;
  overflow-x: hidden;
}

#bar{height:3px;background:linear-gradient(90deg,var(--green-hover),var(--green));
     width:0;transition:width .3s;position:fixed;top:0;left:0;z-index:100}

header{
  padding: calc(14px + var(--safe-top)) 20px 0;
  background:var(--bg-elev-1);
  position:sticky;top:0;z-index:10;
  border-bottom:1px solid var(--border-soft);
  backdrop-filter:saturate(180%) blur(20px);
  -webkit-backdrop-filter:saturate(180%) blur(20px);
}

/* ==================== TITLEBAR ==================== */

.titlebar{
  display:grid;
  grid-template-columns:1fr auto 1fr;
  align-items:center;
  gap:12px;
  margin-bottom:14px;
}
.titlebar .title{
  justify-self:start;
  font-weight:600;
  font-size:16px;
  letter-spacing:-0.2px;
  color:var(--text);
  white-space:nowrap;
}

.counter-group{
  justify-self:center;
  display:flex;
  align-items:center;
  gap:8px;
}

.titlebar .counter{
  font-size:15px;
  color:var(--text-muted);
  background:var(--bg-elev-4);
  padding:6px 16px;
  border-radius:22px;
  font-variant-numeric:tabular-nums;
  white-space:nowrap;
  letter-spacing:-0.1px;
}
.titlebar .counter b{
  color:var(--text);
  font-weight:700;
  font-size:16px;
  margin-right:2px;
}
.titlebar .counter.empty{ opacity:.55 }

.dept-badge{
  display:inline-flex;
  align-items:center;
  gap:6px;
  padding:6px 12px;
  background:var(--bg-elev-4);
  color:var(--text-muted);
  border-radius:22px;
  font-size:13px;
  font-weight:500;
  letter-spacing:-0.1px;
  white-space:nowrap;
  font-variant-numeric:tabular-nums;
}
.dept-badge::before{
  content:'';
  display:inline-block;
  width:8px;
  height:8px;
  border-radius:50%;
  background:var(--dept-color, var(--green));
  flex-shrink:0;
}
.dept-badge.hidden{ display:none; }

.user-zone{
  justify-self:end;
  display:flex;
  align-items:center;
  gap:4px;
  padding:3px 3px 3px 10px;
  background:var(--bg-elev-4);
  border-radius:22px;
  flex-shrink:0;
}

.user-zone .user-info{
  display:flex;
  align-items:center;
  gap:6px;
  font-size:13px;
  color:var(--text-muted);
  padding:0 6px;
  white-space:nowrap;
  flex-shrink:0;
  max-width:220px;
  overflow:hidden;
  text-overflow:ellipsis;
}
.user-zone .user-info .user-name{
  font-weight:500;
  color:var(--text);
  overflow:hidden;
  text-overflow:ellipsis;
  white-space:nowrap;
}

.user-zone .icon-btn{
  margin-bottom:0;
  width:30px;
  height:30px;
  border-radius:50%;
}
.user-zone .icon-btn:hover{
  background:var(--bg-elev-2);
}
.user-zone .icon-btn svg{
  width:16px;
  height:16px;
}

/* ==================== TABS ROW ==================== */

.tabs-row{
  display:grid;
  grid-template-columns:1fr auto 1fr;
  align-items:center;
  gap:8px;
  border-bottom:1px solid var(--border-soft);
  padding-top: 6px;
  padding-bottom: 0;
  min-height: 56px;
}

/* C.2b: space-switch — grid-элемент в центре (десктоп) */
.mobile-space-bar{
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  justify-self: center;
  min-width: 0;
}

.tabs{
  display:flex;
  gap:2px;
  overflow-x:auto;
  scrollbar-width:none;
  justify-self:start;
  align-items:center;
  min-width:0;
}
.tabs::-webkit-scrollbar{display:none}

.tab{
  padding:10px 10px;
  margin-bottom:0;
  background:transparent;
  color:var(--text-muted);
  border:0;
  border-bottom:2px solid transparent;
  cursor:pointer;
  display:inline-flex;
  align-items:center;
  justify-content:center;
  transition:color .15s, border-color .15s, background .15s;
  border-radius:var(--r-sm) var(--r-sm) 0 0;
  flex-shrink:0;
}
.tab svg{
  width:22px;
  height:22px;
  display:block;
}
.tab:hover{
  color:var(--text);
  background:var(--bg-elev-4);
}
.tab.active{
  color:var(--green);
  border-bottom-color:var(--green);
}

.space-switch{
  display: flex;
  align-items: center;
  gap: 2px;
  margin-bottom: 4px;
  padding: 3px;
  background: var(--bg-elev-4);
  border-radius: var(--r-sm);
  flex-shrink: 0;
}

.space-btn{
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 6px 12px;
  background: transparent;
  color: var(--text-muted);
  border: 0;
  border-radius: var(--r-sm);
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  letter-spacing: -0.1px;
  cursor: pointer;
  white-space: nowrap;
  transition: background .15s, color .15s, box-shadow .15s;
  position: relative;
}
.space-btn:hover{ color: var(--text); }

/* C.2b-fix: активное — зелёная подложка, заметно на любом свету */
.space-btn.active{
  background: var(--green-bg);
  color: var(--green);
  font-weight: 600;
  box-shadow: inset 0 0 0 1px rgba(45,134,89,0.25);
}

.space-btn-icon{
  padding: 6px 10px;
}

.space-icon{ font-size: 13px; line-height: 1; }
.space-btn-icon svg{ display: block; }

.space-badge{
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  background: var(--green);
  color: #fff;
  border-radius: 9px;
  font-size: 11px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  margin-left: 2px;
}
.space-badge.hidden{ display: none; }

.tabs-actions{
  display: flex;
  align-items: center;
  gap: 2px;
  flex-shrink: 0;
  justify-self: end;
}

.icon-btn{
  width: 38px;
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  color: var(--text-muted);
  border: 0;
  border-radius: var(--r-sm) var(--r-sm) 0 0;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  transition: background .15s, color .15s, border-color .15s;
  margin-bottom: 0;
  flex-shrink: 0;
  padding: 0;
  text-decoration: none;
}
.icon-btn:hover{
  background: var(--bg-elev-4);
  color: var(--text);
}
.icon-btn.active{
  color: var(--green);
  border-bottom-color: var(--green);
}
.icon-btn.hidden{ display: none; }
.icon-btn svg{
  width: 22px;
  height: 22px;
  display: block;
}

.export-btn{
  width: 38px;
  height: 38px;
  padding: 0;
}

.tabs-row .divider{
  width:1px;
  height:20px;
  background:var(--border-soft);
  margin:0 4px 4px 4px;
  flex-shrink:0;
}

#fab{
  position:fixed;
  bottom: calc(28px + var(--safe-bottom));
  right: calc(28px + var(--safe-right));
  width:52px;height:52px;
  border-radius:50%;
  background:var(--green);
  border:0;
  font-size:26px;
  color:#fff;
  cursor:pointer;
  font-weight:400;
  box-shadow:0 4px 14px rgba(45,134,89,0.35), 0 2px 4px rgba(0,0,0,0.1);
  z-index:20;
  transition:transform .15s ease, box-shadow .15s ease, background .15s ease;
  display:flex;align-items:center;justify-content:center;
  line-height:1;
}
#fab:hover{background:var(--green-hover);transform:scale(1.05);
           box-shadow:0 6px 20px rgba(45,134,89,0.45), 0 3px 6px rgba(0,0,0,0.12)}
#fab:active{transform:scale(.97)}

::-webkit-scrollbar{width:12px;height:12px}
::-webkit-scrollbar-track{background:transparent}
::-webkit-scrollbar-thumb{background:#d0d0d4;border-radius:6px;
  border:3px solid var(--bg)}
::-webkit-scrollbar-thumb:hover{background:#b8b8bd}

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

/* ==================== ПЛАНШЕТ ==================== */

@media (max-width:1100px){
  .user-zone .user-info{ display:none; }
  .user-zone{ padding: 3px; gap: 2px; }
}

@media (max-width:900px){
  .dept-badge{ display:none; }
}

/* ==================== C.2a: кнопка «⋯» ==================== */

.more-btn-mobile{
  display: none;
}

/* ==================== МОБИЛЬНЫЙ (C.2b) ==================== */

@media (max-width: 640px){
  body{
    padding-bottom: calc(140px + var(--safe-bottom));
    scroll-padding-bottom: calc(140px + var(--safe-bottom));
  }

  /* ===== Шапка: две строки ===== */
  header{
    padding: calc(10px + var(--safe-top)) 12px 0;
    /* C.2b-fix: убираем backdrop-filter на мобильном,
       чтобы position:fixed у .mobile-space-bar работал относительно окна,
       а не header (backdrop-filter создаёт containing block). */
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    background: var(--bg-elev-1);
  }

  .titlebar{
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 12px;
  }

  .titlebar .title{
    flex: 0 0 auto;
    font-size: 15px;
    text-align: left;
  }

  .counter-group{
    flex: 1 1 auto;
    display: flex;
    align-items: center;
    gap: 6px;
    min-width: 0;
    justify-content: flex-start;
  }

  .titlebar .counter{
    font-size: 15px;
    font-weight: 600;
    color: var(--text);
    background: transparent;
    padding: 0;
    border-radius: 0;
    font-variant-numeric: tabular-nums;
    display: flex;
    align-items: baseline;
  }
  .titlebar .counter b{
    font-size: 20px;
    font-weight: 700;
    color: var(--text);
    line-height: 1;
    margin-right: 0;
  }
  .titlebar .counter .counter-label{ display: none; }
  .titlebar .counter.empty{ opacity: .4; }

  .dept-badge{ display: none; }

  /* User-zone — только «⋯» */
  .user-zone{
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 2px;
    padding: 0;
    background: transparent;
    border-radius: 0;
  }
  .user-zone .user-info{ display: none; }
  .user-zone .icon-btn{
    width: 40px;
    height: 40px;
    border-radius: var(--r-sm);
  }
  .user-zone .icon-btn:hover{ background: var(--bg-elev-4); }
  .user-zone .icon-btn svg{ width: 20px; height: 20px; }

  /* Скрываем все иконки в user-zone, кроме «⋯» */
  .user-zone #btnInstall,
  .user-zone #btnTrash,
  .user-zone #btnHelp,
  .user-zone #btnAdmin,
  .user-zone #btnLogout{
    display: none !important;
  }

  .user-zone .more-btn-mobile{
    display: inline-flex;
  }

  /* ===== Tabs-row: одна строка, табы слева, действия справа ===== */
  .tabs-row{
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    border-bottom: 1px solid var(--border-soft);
    padding-top: 0;
    padding-bottom: 0;
    min-height: 48px;
  }

  .tabs{
    display: flex;
    gap: 0;
    flex: 0 0 auto;
    overflow: visible;
    align-items: center;
  }

  .tab{
    padding: 10px 10px;
    justify-content: center;
    min-width: 44px;
    min-height: 44px;
    border: 0;
    border-radius: 0;
    background: transparent;
    position: relative;
    flex: 0 0 auto;
  }
  .tab:hover{ background: transparent; }
  .tab.active{
    background: transparent;
    color: var(--green);
    border-bottom-color: transparent;
  }
  .tab.active::after{
    content: '';
    position: absolute;
    left: 6px;
    right: 6px;
    bottom: -1px;
    height: 2px;
    background: var(--green);
    border-radius: 2px;
  }
  .tab svg{ width: 22px; height: 22px; }

  .tabs-actions{
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 0;
    flex: 0 0 auto;
    padding: 0;
    margin: 0;
  }

  .icon-btn{
    width: 44px;
    height: 44px;
    border-radius: 0;
    border: 0;
    border-bottom: 0;
    background: transparent;
    flex: 0 0 auto;
    position: relative;
    padding: 0;
  }
  .icon-btn:hover{
    background: transparent;
    color: var(--text);
  }
  .icon-btn.active{
    background: transparent;
    color: var(--green);
    border-bottom: 0;
  }
  .icon-btn.active::after{
    content: '';
    position: absolute;
    left: 10px;
    right: 10px;
    bottom: 2px;
    height: 2px;
    background: var(--green);
    border-radius: 2px;
  }
  .icon-btn svg{ width: 22px; height: 22px; }

  .hidden-on-mobile{
    display: none !important;
  }

  /* ===== НИЖНЯЯ ПАНЕЛЬ SPACE-SWITCH (мобильный) ===== */
  .mobile-space-bar{
    display: flex;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    top: auto;
    z-index: 25;
    background: var(--bg-elev-1);
    border-top: 1px solid var(--border-soft);
    padding: 6px 12px calc(6px + var(--safe-bottom)) 12px;
    align-items: center;
    justify-content: center;
    gap: 8px;
    backdrop-filter: saturate(180%) blur(20px);
    -webkit-backdrop-filter: saturate(180%) blur(20px);
    justify-self: auto;
    min-width: 0;
  }

  .mobile-space-bar .space-switch{
    display: flex;
    align-items: center;
    justify-content: stretch;
    gap: 2px;
    padding: 3px;
    background: var(--bg-elev-4);
    border-radius: 12px;
    flex: 1 1 auto;
    max-width: 480px;
    margin: 0;
  }

  .mobile-space-bar .space-btn{
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    padding: 8px 12px;
    height: 40px;
    min-height: 40px;
    flex: 1 1 0;
    min-width: 0;
    font-size: 13px;
    font-weight: 500;
    border: 0;
    background: transparent;
    color: var(--text-muted);
    border-radius: 8px;
    cursor: pointer;
    position: relative;
    transition: background .15s, color .15s, box-shadow .15s;
    white-space: nowrap;
  }

  .mobile-space-bar .space-btn:hover{
    color: var(--text);
  }

  /* C.2b-fix: активное — зелёная подложка */
  .mobile-space-bar .space-btn.active{
    background: var(--green-bg);
    color: var(--green);
    font-weight: 600;
    box-shadow: inset 0 0 0 1px rgba(45,134,89,0.25);
  }

  .mobile-space-bar .space-icon{
    font-size: 15px;
    line-height: 1;
  }

  .mobile-space-bar .space-label{
    display: block;
    font-size: 13px;
    line-height: 1;
    white-space: nowrap;
  }

  .mobile-space-bar .space-badge{
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    margin-left: 2px;
    background: var(--green);
    color: #fff;
    border-radius: 9px;
    font-size: 11px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
  }
  .mobile-space-bar .space-badge.hidden{
    display: none;
  }

  .mobile-space-bar .space-btn-icon{
    flex: 1 1 0;
    min-width: 0;
    padding: 8px 6px;
    gap: 2px;
  }
  .mobile-space-bar .space-btn-icon svg{
    width: 18px;
    height: 18px;
  }

  .mobile-space-bar .analytics-dept-btn{
    margin: 0;
    padding: 8px 10px;
    height: 40px;
    min-height: 40px;
    border: 1px solid var(--border-soft);
    border-radius: 8px;
    background: transparent;
    color: var(--text-muted);
    font-size: 12px;
    gap: 4px;
    flex: 0 0 auto;
  }
  .mobile-space-bar .analytics-dept-btn #analyticsDeptName{ display: none; }

  /* ===== FAB — floating над панелью ===== */
  #fab{
    bottom: calc(72px + var(--safe-bottom));
    right: 16px;
    width: 56px;
    height: 56px;
    font-size: 26px;
  }
}

@media (max-width: 480px){
  .titlebar .title{ font-size: 14px; }
  .titlebar .counter b{ font-size: 18px; }
  .tab svg{ width: 20px; height: 20px; }
  .tab{ padding: 8px 8px; min-width: 40px; }
  .icon-btn{ width: 40px; height: 40px; }
  .icon-btn svg{ width: 20px; height: 20px; }
  .mobile-space-bar .space-btn{ padding: 6px 8px; font-size: 12px; }
  .mobile-space-bar .space-label{ font-size: 12px; }
  .mobile-space-bar .space-icon{ font-size: 14px; }
}

/* ==================== ТОСТЫ ==================== */

.toast-stack{
  position: fixed;
  bottom: calc(24px + var(--safe-bottom));
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 9999;
  pointer-events: none;
  max-width: calc(100vw - 32px);
}
.toast{
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  background: var(--text);
  color: var(--bg);
  border-radius: var(--r-md);
  font-size: 13.5px;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  transform: translateY(8px);
  transition: opacity .2s, transform .2s;
  pointer-events: auto;
  cursor: pointer;
  max-width: 520px;
  word-wrap: break-word;
}
.toast--visible{ opacity: 1; transform: translateY(0); }
.toast--leaving{ opacity: 0; transform: translateY(8px); }
.toast--error{ background: var(--red); color: #fff; }
.toast--success{ background: var(--green); color: #fff; }
.toast-icon{
  flex-shrink: 0;
  font-size: 15px;
  line-height: 1;
}
.toast-text{
  flex: 1;
  min-width: 0;
}
.toast-action{
  flex-shrink: 0;
  margin-left: 6px;
  padding: 5px 12px;
  background: rgba(255,255,255,0.18);
  color: inherit;
  border: 0;
  border-radius: var(--r-sm);
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background .15s;
}
.toast-action:hover{ background: rgba(255,255,255,0.3); }

@media (max-width:640px){
  .toast-stack{
    bottom: calc(100px + var(--safe-bottom));
    left: 16px;
    right: 16px;
    transform: none;
    max-width: none;
  }
  .toast{ font-size: 13px; padding: 10px 14px; }
}

/* ==================== PWA ==================== */

.install-btn{
  color: var(--green);
}
.install-btn:hover{
  background: var(--green-bg);
  color: var(--green-hover);
}

.pwa-ios-hint{
  position: fixed;
  inset: 0;
  background: rgba(20,20,22,0.55);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  padding: 20px;
}
.pwa-ios-card{
  width: 100%;
  max-width: 360px;
  background: var(--bg-elev-3);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 24px 22px;
  box-shadow: var(--shadow-lg);
}
.pwa-ios-title{
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 16px;
  letter-spacing: -0.2px;
}
.pwa-ios-steps{
  margin: 0 0 20px;
  padding-left: 22px;
  font-size: 14px;
  color: var(--text-muted);
  line-height: 1.7;
}
.pwa-ios-steps li{
  margin-bottom: 4px;
}
.pwa-ios-steps b{
  color: var(--text);
  font-weight: 600;
}
.pwa-ios-icon{
  display: inline-block;
  padding: 0 6px;
  background: var(--bg-elev-4);
  border-radius: 4px;
  font-size: 13px;
  line-height: 1.4;
}
.pwa-ios-close{
  width: 100%;
  padding: 11px 16px;
  background: var(--green);
  color: #fff;
  border: 0;
  border-radius: var(--r-md);
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s;
}
.pwa-ios-close:hover{
  background: var(--green-hover);
}

/* ==================== ПАРТИЯ 8.4: КНОПКА ПЕРЕКЛЮЧЕНИЯ ОТДЕЛА ==================== */

.analytics-dept-btn{
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px;
  margin-left: 6px;
  background: var(--bg-elev-4);
  color: var(--text-muted);
  border: 1px solid var(--border-soft);
  border-radius: var(--r-sm);
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  letter-spacing: -0.1px;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
  transition: background .15s, color .15s, border-color .15s;
}
.analytics-dept-btn:hover{
  background: var(--green-bg);
  color: var(--green);
  border-color: var(--green);
}
.analytics-dept-btn svg{
  display: block;
  flex-shrink: 0;
}
.analytics-dept-btn.hidden{
  display: none;
}
.analytics-dept-btn #analyticsDeptName{
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
}

@media (max-width:900px){
  .analytics-dept-btn #analyticsDeptName{
    display: none;
  }
  .analytics-dept-btn{
    padding: 7px 9px;
  }
}

/* ==================== C.2b: скрыть бейдж на кнопке «Поручения» ==================== */

#assignmentsCount{
  display: none !important;
}