/* цвета обеих тем - в theme.css */

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Golos Text', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  accent-color: var(--accent);        /* чекбоксы и прочие системные элементы - в цвет темы */
  height: 100vh;
  height: 100dvh;                     /* на телефоне без области под адресной строкой */
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

a { color: var(--accent-text); }

/* ─── APP SHELL ─── */
#app { display: none; height: 100vh; height: 100dvh; flex-direction: column; }

.topbar {
  height: 56px; background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; padding: 0 18px; gap: 14px;
  flex-shrink: 0; z-index: 20;
}
.topbar-logo { font-size: 17px; font-weight: 700; letter-spacing: -0.3px; }
.topbar-logo span { color: var(--logo-accent); }
.topbar-spacer { flex: 1; }

/* кнопка меню: видна, когда меню становится шторкой */
.nav-toggle {
  width: 38px; height: 38px; flex-shrink: 0; display: none;
  align-items: center; justify-content: center;
  background: none; border: 0; border-radius: 10px; color: var(--text); cursor: pointer;
}
.nav-toggle:hover { background: var(--surface2); }
.nav-toggle svg { width: 22px; height: 22px; }
.nav-toggle .ico-close, body.nav-open .nav-toggle .ico-menu { display: none; }
body.nav-open .nav-toggle .ico-close { display: block; }

/* переключатель темы: иконка показывает тему, которую включит клик */
.theme-toggle {
  width: 34px; height: 34px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  background: none; border: 1px solid var(--border); border-radius: 10px;
  color: var(--text2); cursor: pointer; transition: color 0.15s, border-color 0.15s;
}
.theme-toggle:hover { color: var(--accent-text); border-color: var(--accent); }
.theme-toggle svg { width: 17px; height: 17px; }
.theme-toggle .ico-moon { display: none; }
:root[data-theme="light"] .theme-toggle .ico-sun { display: none; }
:root[data-theme="light"] .theme-toggle .ico-moon { display: block; }

/* ─── кастомный дропдаун контекста ─── */
.ctx-dd { position: relative; }
.ctx-dd-btn {
  display: flex; align-items: center; gap: 9px;
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: 10px; padding: 6px 12px; cursor: pointer;
  font-family: inherit; color: var(--text); transition: border-color 0.15s;
}
.ctx-dd-btn:hover { border-color: var(--accent); }
.ctx-dd-cap { font-size: 10px; color: var(--text3); text-transform: uppercase; letter-spacing: 0.6px; }
.ctx-dd-label { font-size: 13px; font-weight: 600; }
.ctx-dd-caret { font-size: 11px; color: var(--text3); }
.ctx-dd-menu {
  position: absolute; top: calc(100% + 6px); right: 0; z-index: 60;
  background: var(--surface-raised); border: 1px solid var(--border); border-radius: 12px;
  padding: 6px; min-width: 220px; box-shadow: 0 14px 40px var(--shadow-strong);
  display: none; flex-direction: column; gap: 2px;
}
.ctx-dd-menu.open { display: flex; }
.ctx-dd-opt {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 9px 11px; border-radius: 8px; cursor: pointer; transition: background 0.12s;
}
.ctx-dd-opt:hover { background: var(--menu-hover); }
.ctx-dd-opt.active { background: rgba(var(--accent-rgb), 0.14); }
.ctx-dd-opt-subj { font-size: 13px; font-weight: 600; color: var(--text); }
.ctx-dd-opt-dep { font-size: 11px; font-weight: 600; color: var(--text3); }
.ctx-dd-opt-role { font-size: 12px; font-weight: 600; color: var(--accent-text); }

/* ─── экран «нет ролей» ─── */
.no-roles { max-width: 460px; margin: 60px auto; text-align: center; }
.no-roles-icon { font-size: 46px; margin-bottom: 14px; }
.no-roles-title { font-size: 20px; font-weight: 700; margin-bottom: 12px; }
.no-roles-text { font-size: 14px; color: var(--text2); line-height: 1.8; }

.user-chip { display: flex; align-items: center; gap: 9px; cursor: pointer; padding: 4px 8px; border-radius: 10px; transition: background 0.15s; }
.user-chip:hover { background: var(--surface2); }
.user-chip-avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 700; color: var(--on-accent); flex-shrink: 0;
}
.user-chip-name { font-size: 13px; color: var(--text2); }

/* полосы-предупреждения под топбаром */
.banner { padding: 8px 16px; font-size: 13px; text-align: center; font-weight: 500; color: var(--on-solid); }
.banner-warning { background: var(--warning-solid); }
.banner-danger { background: var(--danger-solid); }
.banner .btn-ghost { color: var(--on-solid); border-color: var(--on-solid-border); }
.banner .btn-ghost:hover { color: var(--on-solid); border-color: var(--on-solid); }

/* ─── MAIN LAYOUT ─── */
.main { display: flex; flex: 1; overflow: hidden; }

.sidenav {
  width: 230px; flex-shrink: 0; background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column; padding: 12px 10px; gap: 3px;
  overflow-y: auto;
}
.nav-item {
  display: flex; align-items: center; gap: 11px;
  padding: 10px 12px; border-radius: 10px; cursor: pointer;
  color: var(--text2); font-size: 14px; font-weight: 500;
  transition: background 0.15s, color 0.15s; user-select: none;
}
.nav-item:hover { background: var(--surface2); color: var(--text); }
.nav-item.active { background: var(--nav-active-bg); color: var(--nav-active-text); }
.nav-item .nav-ico { font-size: 16px; width: 20px; text-align: center; }
.nav-sep { height: 1px; background: var(--border); margin: 8px 4px; }
.nav-group-title {
  font-size: 10px; text-transform: uppercase; letter-spacing: 0.8px;
  color: var(--text3); padding: 10px 12px 4px;
}

/* тема и выход внизу шторки нужны только на телефоне, где их нет в топбаре */
.nav-footer { display: none; }
.nav-backdrop { display: none; }

.content { flex: 1; min-width: 0; overflow-y: auto; }
.content-pad { padding: 26px 30px; }

/* scrollbars */
.sidenav::-webkit-scrollbar, .content::-webkit-scrollbar { width: 5px; }
.sidenav::-webkit-scrollbar-thumb, .content::-webkit-scrollbar-thumb { background: var(--scrollbar-thumb); border-radius: 3px; }
::-webkit-scrollbar-track { background: transparent; }

/* ─── STATES ─── */
.state-msg {
  display: flex; align-items: center; justify-content: center;
  gap: 10px; color: var(--text2); font-size: 14px; padding: 60px 0;
}
.spinner {
  display: inline-block; width: 18px; height: 18px;
  border: 2px solid var(--border); border-top-color: var(--accent);
  border-radius: 50%; animation: spin 0.6s linear infinite;
  vertical-align: middle;
}
.spinner.sm { width: 13px; height: 13px; border-width: 2px; }
@keyframes spin { to { transform: rotate(360deg); } }

.page-title { font-size: 22px; font-weight: 700; letter-spacing: -0.4px; margin-bottom: 4px; }
.page-sub { font-size: 13px; color: var(--text3); margin-bottom: 22px; }

.error-box {
  display: none;
  background: rgba(var(--red-rgb), 0.08); border: 1px solid rgba(var(--red-rgb), 0.25);
  border-radius: 12px; padding: 14px 18px; color: var(--red); font-size: 13px; margin-bottom: 18px;
}
.warn-box {
  background: rgba(var(--orange-rgb), 0.09); border: 1px solid rgba(var(--orange-rgb), 0.3);
  border-radius: 10px; padding: 12px 16px; color: var(--orange); font-size: 13px; margin-bottom: 16px;
}

/* ─── УЗКИЙ ЭКРАН: меню уходит в шторку под топбаром ─── */
@media (max-width: 900px) {
  .nav-toggle { display: flex; margin-left: -6px; }
  .user-chip-name { display: none; }

  .sidenav {
    position: fixed; z-index: 80; top: 56px; bottom: 0; left: 0;
    width: min(290px, 84vw); padding: 12px 10px calc(12px + env(safe-area-inset-bottom));
    box-shadow: 12px 0 30px var(--shadow-soft);
    transform: translateX(-100%); visibility: hidden;
    transition: transform .22s ease, visibility .22s;
  }
  body.nav-open .sidenav { transform: none; visibility: visible; }
  .nav-backdrop {
    display: block; position: fixed; z-index: 79; inset: 56px 0 0 0;
    background: var(--overlay); opacity: 0; pointer-events: none; transition: opacity .2s ease;
  }
  body.nav-open .nav-backdrop { opacity: 1; pointer-events: auto; }
  .nav-item { padding: 12px 14px; font-size: 15px; }
}

/* ─── ТЕЛЕФОН ─── */
@media (max-width: 640px) {
  .topbar { padding: 0 10px; gap: 8px; }
  .topbar-logo { font-size: 16px; }
  /* тема и выход переезжают в шторку, контекст сжимается до подписи */
  #theme-toggle, #logout-btn { display: none; }
  .user-chip { padding: 3px; }
  .ctx-dd { min-width: 0; }
  .ctx-dd-btn { max-width: min(46vw, 100%); padding: 7px 10px; gap: 6px; }
  .ctx-dd-cap { display: none; }
  .ctx-dd-label { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .ctx-dd-menu {
    position: fixed; top: 60px; left: 8px; right: 8px; min-width: 0;
    max-height: calc(100dvh - 76px); overflow-y: auto;
  }
  .ctx-dd-opt { padding: 12px; }

  .nav-footer {
    display: flex; flex-direction: column; gap: 3px;
    margin-top: auto; padding-top: 8px; border-top: 1px solid var(--border);
  }
  .nav-footer .nav-item { width: 100%; background: none; border: 0; font: inherit; font-size: 15px; text-align: left; }
  .nav-theme-dark { display: none; }
  :root[data-theme="light"] .nav-theme-light { display: none; }
  :root[data-theme="light"] .nav-theme-dark { display: inline; }

  .banner { padding: 8px 12px; font-size: 12px; }
  .content-pad { padding: 16px 16px 28px; }
  .page-title { font-size: 20px; }
  .page-sub { margin-bottom: 16px; }
  .no-roles { margin: 32px auto; }
}

@media (prefers-reduced-motion: reduce) {
  .sidenav, .nav-backdrop { transition: none; }
}
