/* ═══════════════════════════════════════════════════════════
   ПЕРЕМЕННЫЕ
═══════════════════════════════════════════════════════════ */
:root {
  --primary:        #2563eb;
  --primary-dark:   #1d4ed8;
  --danger:         #dc2626;
  --danger-dark:    #b91c1c;
  --success:        #16a34a;
  --success-dark:   #15803d;
  --warning:        #d97706;
  --muted:          #6b7280;
  --radius-sm:      0.4rem;
  --radius:         0.55rem;
  --radius-lg:      0.85rem;
  --sidebar-w:      56px;
  --sidebar-w-open: 200px;
  --transition:     0.18s ease;
}

/* ═══════════════════════════════════════════════════════════
   RESET & BASE
═══════════════════════════════════════════════════════════ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
html.theme-fade { opacity: 0; transition: opacity .2s ease; }

/* ═══════════════════════════════════════════════════════════
   SIDEBAR LAYOUT
═══════════════════════════════════════════════════════════ */
.app-layout {
  display: flex;
  min-height: 100vh;
}

/* ── Sidebar ── */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  padding: 12px 0;
  gap: 2px;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
  overflow: hidden;
  transition: width var(--transition);
}
.sidebar:hover { width: var(--sidebar-w-open); }

.sb-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 12px 14px;
  overflow: hidden;
  flex-shrink: 0;
}
.sb-logo-icon {
  width: 32px; height: 32px;
  border-radius: 8px;
  background: var(--primary);
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 15px;
  flex-shrink: 0;
}
.sb-logo-text {
  font-size: 13px; font-weight: 600;
  white-space: nowrap; opacity: 0;
  transition: opacity var(--transition);
}
.sidebar:hover .sb-logo-text { opacity: 1; }

.sb-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  cursor: pointer;
  text-decoration: none;
  border-radius: 0;
  overflow: hidden;
  white-space: nowrap;
  transition: background var(--transition), color var(--transition);
}
.sb-item i { font-size: 16px; flex-shrink: 0; width: 20px; text-align: center; }
.sb-item span { font-size: 13px; font-weight: 500; opacity: 0; transition: opacity var(--transition); }
.sidebar:hover .sb-item span { opacity: 1; }

.sb-divider { height: 0.5px; margin: 6px 12px; flex-shrink: 0; }
.sb-spacer { flex: 1; }

.sb-admin-info {
  cursor: default;
  opacity: .55;
  font-size: 11px;
}

.sb-avatar {
  width: 20px;
  height: 20px;
  min-width: 20px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}

.sb-active-admins {
  cursor: default;
  opacity: .55;
  font-size: 11px;
  margin-top: 4px;
}

.sb-active-admins-list {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  padding: 4px 12px 8px;
}

.sb-avatar-sm {
  width: 22px;
  height: 22px;
  min-width: 22px;
  border-radius: 50%;
  object-fit: cover;
  border: 1.5px solid var(--primary);
  cursor: default;
}

.sb-copyright {
  padding: 8px 12px;
  font-size: 10px;
  opacity: 0;
  white-space: nowrap;
  overflow: hidden;
  transition: opacity var(--transition);
  line-height: 1.4;
}
html.theme-light .sb-copyright { color: #94a3b8; }
html.theme-dark  .sb-copyright { color: #475569; }
.sidebar:hover .sb-copyright { opacity: 1; }

/* Topbar убран — скрываем на десктопе */
@media (min-width: 769px) {
  .topbar        { display: none; }
  .mobile-header { display: none; }
  #mobileNav     { display: none !important; }
}

/* ── Main area ── */
.app-main {
  flex: 1;
  margin-left: var(--sidebar-w);
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
  transition: margin-left var(--transition);
}

/* На мобиле sidebar скрыт — убираем фиксированную высоту и overflow:hidden */
@media (max-width: 768px) {
  .app-main {
    margin-left: 0;
    height: auto;
    min-height: 100vh;
    overflow: visible;
  }
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding: 0 20px;
  flex-shrink: 0;
}

.topbar-right { display: flex; align-items: center; gap: 8px; }

.theme-icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  background: rgba(0,0,0,.06);
  font-size: 14px;
  transition: background var(--transition), transform .1s;
}
.theme-icon-btn:hover { background: rgba(0,0,0,.1); }
.theme-icon-btn:active { transform: scale(.92); }
.theme-icon-btn i { pointer-events: none; }

.page-content {
  flex: 1;
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

@media (max-width: 768px) {
  .page-content {
    overflow: visible;
    min-height: 0;
  }
}

/* ═══════════════════════════════════════════════════════════
   СВЕТЛАЯ ТЕМА
═══════════════════════════════════════════════════════════ */
html.theme-light {
  background: #f0f2f5;
  color: #0f172a;
}
html.theme-light body { background: #f0f2f5; }

html.theme-light .sidebar {
  background: #ffffff;
  border-right: 0.5px solid #e2e8f0;
  box-shadow: 1px 0 3px rgba(0,0,0,.04);
}
html.theme-light .sb-item { color: #64748b; }
html.theme-light .sb-item:hover { background: #f1f5f9; color: #0f172a; }
html.theme-light .sb-item.active { background: #dbeafe; color: #1e40af; }
html.theme-light .sb-divider { background: #e2e8f0; }

html.theme-light .topbar {
  background: #ffffff;
  border-bottom: 0.5px solid #e2e8f0;
  box-shadow: 0 1px 3px rgba(0,0,0,.05);
}
html.theme-light .topbar-title { color: #0f172a; }
html.theme-light .theme-icon-btn { background: #f1f5f9; color: #475569; }
html.theme-light .theme-icon-btn:hover { background: #e2e8f0; }

html.theme-light .card {
  background: #ffffff;
  border: 0.5px solid #e2e8f0;
  box-shadow: 0 1px 3px rgba(0,0,0,.05);
}
html.theme-light .table th { background: #f8fafc; color: #475569; }
html.theme-light .table td { border-color: #f1f5f9; color: #374151; }
html.theme-light .table tr:hover td { background: #f8fafc; }

html.theme-light .input,
html.theme-light input:not([type=checkbox]):not([type=radio]):not([type=range]),
html.theme-light select,
html.theme-light textarea {
  background: #f8fafc;
  color: #0f172a;
  border-color: #cbd5e1;
}
html.theme-light .input:focus,
html.theme-light input:focus,
html.theme-light select:focus,
html.theme-light textarea:focus {
  background: #fff;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,.1);
}
html.theme-light input::placeholder,
html.theme-light textarea::placeholder { color: #94a3b8; }

html.theme-light .search-bar { background: #f8fafc; border-color: #e2e8f0; }
html.theme-light .search-input { color: #0f172a; }
html.theme-light .search-input::placeholder { color: #94a3b8; }

html.theme-light .chip { background: #f1f5f9; color: #475569; border-color: #e2e8f0; }
html.theme-light .chip:hover { background: #e2e8f0; }
html.theme-light .chip-active { background: var(--primary); color: #fff; border-color: var(--primary); }

html.theme-light .badge { background: #f1f5f9; color: #475569; }
html.theme-light .badge-warn { background: #fef3c7; color: #92400e; }

html.theme-light .btn-light { background: #f1f5f9; color: #0f172a; border-color: #e2e8f0; }
html.theme-light .btn-ghost { color: #64748b; border-color: #e2e8f0; }
html.theme-light .btn-ghost:hover { background: #f1f5f9; }

html.theme-light #modalRoot .modal-window {
  background: #fff;
  border: 0.5px solid #e2e8f0;
}
html.theme-light .modal-header-bar { border-color: #e2e8f0; }
html.theme-light #modalTitle { color: #0f172a; }
html.theme-light #modalClose { color: #64748b; }
html.theme-light #modalClose:hover { color: #0f172a; }

html.theme-light .custom-select-dropdown { background: #fff; border-color: #e2e8f0; }
html.theme-light .custom-option:hover { background: #f1f5f9; }
html.theme-light .custom-select-display { color: #0f172a; }

html.theme-light footer { background: #f0f2f5; color: #64748b; border-color: #e2e8f0; }

html.theme-light .sb-logo-text { color: #e2e8f0; }

/* locations card */
html.theme-light .loc-panel { background: #fff; border-color: #e2e8f0; }
html.theme-light .loc-item:hover { background: #f8fafc; }
html.theme-light .loc-item.active { background: #eff6ff; }

/* ═══════════════════════════════════════════════════════════
   ТЁМНАЯ ТЕМА
═══════════════════════════════════════════════════════════ */
html.theme-dark {
  background: #0f172a;
  color: #e2e8f0;
}
html.theme-dark body,
html.theme-dark .app-main { background: #0f172a; }

html.theme-dark .sidebar {
  background: #0b1220;
  border-right: 0.5px solid #1e293b;
}
html.theme-dark .sb-item { color: #64748b; }
html.theme-dark .sb-item:hover { background: #1e293b; color: #e2e8f0; }
html.theme-dark .sb-item.active { background: #1e3a8a; color: #bfdbfe; }
html.theme-dark .sb-divider { background: #1e293b; }
html.theme-dark .sb-logo-text { color: #94a3b8; }

html.theme-dark .topbar {
  background: rgba(11,18,32,.95);
  border-bottom: 0.5px solid #1e293b;
  box-shadow: 0 1px 6px rgba(0,0,0,.4);
  backdrop-filter: blur(8px);
}
html.theme-dark .topbar-title { color: #e2e8f0; }
html.theme-dark .theme-icon-btn { background: #1e293b; color: #e2e8f0; }
html.theme-dark .theme-icon-btn:hover { background: #334155; }

html.theme-dark .card {
  background: #0f1f35;
  border-color: #1e293b;
  box-shadow: 0 2px 8px rgba(0,0,0,.4);
}
html.theme-dark .table th { background: #1e293b; color: #94a3b8; }
html.theme-dark .table td { border-color: #1e293b; color: #e2e8f0; background: transparent; }
html.theme-dark .table tr:hover td { background: #1e293b; }
html.theme-dark thead { background: #1e293b; }

html.theme-dark .input,
html.theme-dark input:not([type=checkbox]):not([type=radio]):not([type=range]),
html.theme-dark select,
html.theme-dark textarea {
  background: #1e293b;
  color: #e2e8f0;
  border-color: #334155;
}
html.theme-dark .input:focus,
html.theme-dark input:focus,
html.theme-dark select:focus,
html.theme-dark textarea:focus {
  border-color: #3b82f6;
  box-shadow: 0 0 0 3px rgba(59,130,246,.15);
}
html.theme-dark input::placeholder,
html.theme-dark textarea::placeholder { color: #475569; }
html.theme-dark option { background: #1e293b; color: #e2e8f0; }

html.theme-dark .search-bar { background: #1e293b; border-color: #334155; }
html.theme-dark .search-bar:focus-within { background: #1e293b; border-color: #3b82f6; box-shadow: 0 0 0 3px rgba(59,130,246,.15); }
html.theme-dark .search-btn { background: var(--primary); }
html.theme-dark .search-input { color: #e2e8f0; }
html.theme-dark .search-input::placeholder { color: #475569; }

html.theme-dark .chip { background: #1e293b; color: #94a3b8; border-color: #334155; }
html.theme-dark .chip:hover { background: #334155; color: #e2e8f0; }
html.theme-dark .chip-active { background: var(--primary); color: #fff; border-color: var(--primary); }

html.theme-dark .badge { background: #1e293b; color: #94a3b8; }
html.theme-dark .badge-warn { background: #78350f; color: #fde68a; }

html.theme-dark .btn-light { background: #1e293b; color: #e2e8f0; border-color: #334155; }
html.theme-dark .btn-ghost { color: #94a3b8; border-color: #334155; }
html.theme-dark .btn-ghost:hover { background: #1e293b; }

html.theme-dark #modalRoot .modal-window {
  background: #0f1f35;
  border-color: #1e293b;
  color: #e2e8f0;
}
html.theme-dark .modal-header-bar { border-color: #1e293b; }
html.theme-dark #modalTitle { color: #e2e8f0; }
html.theme-dark #modalClose { color: #64748b; }

html.theme-dark .custom-select-dropdown { background: #1e293b; border-color: #334155; }
html.theme-dark .custom-option { color: #e2e8f0; }
html.theme-dark .custom-option:hover { background: #334155; }
html.theme-dark .custom-select-display { color: #e2e8f0; }

html.theme-dark footer { background: #0b1220; color: #64748b; border-color: #1e293b; }

html.theme-dark .bg-white,
html.theme-dark .bg-gray-50,
html.theme-dark .bg-gray-100 { background-color: #0f172a; }
html.theme-dark .bg-gray-200 { background-color: #1e293b; }
html.theme-dark .border { border-color: #1e293b; }
html.theme-dark .hover\:bg-gray-100:hover { background: #1e293b; }

html.theme-dark li { color: #e2e8f0; }

html.theme-dark pre { background: #1e293b; color: #e2e8f0; }

html.theme-dark .loc-panel { background: #0f1f35; border-color: #1e293b; }
html.theme-dark .loc-item:hover { background: #1e293b; }
html.theme-dark .loc-item.active { background: #1e3a8a; }

html.theme-dark .history-card,
html.theme-dark .history-item,
html.theme-dark .mobile-table-row,
html.theme-dark .mobile-table-cell {
  background-color: #0f1f35;
  color: #e2e8f0;
  border-color: #1e293b;
}
html.theme-dark table td { background-color: transparent; }
html.theme-dark .table-card { background-color: #0f172a; }

/* ═══════════════════════════════════════════════════════════
   CARD
═══════════════════════════════════════════════════════════ */
.card {
  background: #fff;
  border: 0.5px solid #e2e8f0;
  border-radius: var(--radius-lg);
  box-shadow: 0 1px 3px rgba(0,0,0,.05);
  padding: 1rem;
  margin-bottom: 16px;
}

.request-card { transition: box-shadow .2s, transform .1s; }
.request-card:hover { box-shadow: 0 4px 12px rgba(0,0,0,.08); transform: translateY(-1px); }

/* ═══════════════════════════════════════════════════════════
   BUTTONS — единая система
═══════════════════════════════════════════════════════════ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 6px 13px;
  border-radius: var(--radius);
  font-size: 12.5px;
  font-weight: 500;
  line-height: 1.3;
  border: none;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  transition: filter var(--transition), transform .1s, box-shadow var(--transition);
  position: relative;
  overflow: hidden;
}
.btn i { font-size: 12px; }
.btn:hover  { filter: brightness(.91); }
.btn:active { transform: scale(.97); filter: brightness(.85); }
.btn:disabled { opacity: .5; cursor: not-allowed; filter: none; transform: none; }

/* Состояния сохранения */
.btn.saving { pointer-events: none; }
.btn.saved  { pointer-events: none; }

.btn-primary  { background: var(--primary);  color: #fff; }
.btn-secondary{ background: #0ea5e9;          color: #fff; }
.btn-danger   { background: var(--danger);    color: #fff; }
.btn-success  { background: var(--success);   color: #fff; }
.btn-warning  { background: var(--warning);   color: #fff; }
.btn-light    { background: #f1f5f9; color: #0f172a; border: 0.5px solid #e2e8f0; }
.btn-ghost    { background: transparent; color: #64748b; border: 0.5px solid #e2e8f0; }
.btn-sm       { padding: 4px 9px; font-size: 11.5px; border-radius: var(--radius-sm); }
.btn-xs       { padding: 2px 7px; font-size: 11px;   border-radius: var(--radius-sm); }
.btn-icon     { padding: 6px; width: 32px; height: 32px; }
.btn-icon.btn-sm { width: 26px; height: 26px; padding: 4px; }

/* Спиннер внутри кнопки */
@keyframes spin { to { transform: rotate(360deg); } }
.btn .btn-spinner {
  display: inline-block;
  width: 12px; height: 12px;
  border: 2px solid rgba(255,255,255,.35);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .6s linear infinite;
}

/* Убираем Tailwind-мусор на кнопках */
@media (min-width: 769px) {
  .btn-primary,
  .btn-danger,
  .btn-success,
  .btn-secondary,
  .btn-warning { width: auto; }
}
@media (max-width: 768px) {
  .btn { width: 100%; justify-content: center; }
  .btn-sm, .btn-xs { width: auto; }
  .btn-icon { width: 32px; }
}

/* Явные фиксы для кнопок с utility-классами .w-full / .hidden.
   Правила выше (.btn-primary{width:auto} и .btn{display:inline-flex})
   имеют такую же специфичность (0,1,0), но идут в каскаде ПОСЛЕ
   .w-full/.hidden из app.css, поэтому побеждали их, несмотря на класс
   .w-full/.hidden на элементе — кнопка "Войти" на странице входа не
   растягивалась на всю ширину, а кнопка "Отправить код повторно" не
   скрывалась.

   .btn.hidden — чиним ВЕЗДЕ (это чистый баг: скрытая кнопка обязана
   скрываться в любом месте панели, сужать незачем).

   .btn.w-full — чиним ТОЛЬКО внутри .auth-wrapper (страницы входа).
   Если сделать это правило глобальным, оно перебивает "Убираем
   Tailwind-мусор на кнопках" выше и на десктопе (min-width:769px)
   ломает layout в остальной панели — например, кнопка "Добавить" на
   странице пользователей задумана как w-full на мобильном и w-auto
   (в одну строку с фильтрами) на десктопе; глобальное .btn.w-full
   заставляло её быть 100%-ширины всегда, из-за чего инпуты и кнопка
   переставали помещаться в одну строку. */
.btn.hidden { display: none; }
.auth-wrapper .btn.w-full { width: 100%; }

/* ═══════════════════════════════════════════════════════════
   CHIPS & BADGES
═══════════════════════════════════════════════════════════ */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 12px;
  border-radius: var(--radius);
  font-size: 12.5px;
  font-weight: 500;
  background: #f1f5f9;
  color: #475569;
  border: 0.5px solid #e2e8f0;
  cursor: pointer;
  text-decoration: none;
  transition: background var(--transition), transform .1s;
}
.chip:hover { background: #e2e8f0; transform: translateY(-1px); }
.chip-active { background: var(--primary); color: #fff; border-color: var(--primary); }
.chip-warn   { background: #fef3c7; color: #92400e; border-color: #fde68a; }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11.5px;
  font-weight: 500;
  padding: 2px 7px;
  border-radius: var(--radius-sm);
  background: #f1f5f9;
  color: #475569;
}
.badge-warn    { background: #fef3c7; color: #92400e; }
.badge-success { background: #dcfce7; color: #166534; }
.badge-danger  { background: #fee2e2; color: #991b1b; }
.badge-info    { background: #dbeafe; color: #1e40af; }

/* Компактный бейдж-иконка (без текста, подпись — через title/hover) —
   нужен, чтобы статус "прочитано" + статус выполнения помещались в одну
   строку в таблице заявок, а не растягивали строку на две. */
.badge-icon {
  width: 22px;
  height: 22px;
  padding: 0;
  justify-content: center;
  font-size: 12px;
  border-radius: 50%;
  cursor: default;
}

/* Фирменные цвета иконок источника заявки — иначе fa-brands наследует
   цвет текста бейджа и выглядит плоско рядом с цветным эмодзи-глобусом
   (сайт) в этой же колонке. */
.icon-vk       { color: #0077FF; }
.icon-telegram { color: #26A5E4; }

/* ═══════════════════════════════════════════════════════════
   TABLES
═══════════════════════════════════════════════════════════ */
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.table th,
.table td { padding: 9px 13px; border-bottom: 0.5px solid #f1f5f9; text-align: left; }
.table th {
  background: #f8fafc;
  font-size: 11px;
  font-weight: 600;
  color: #64748b;
  text-transform: uppercase;
  letter-spacing: .04em;
}
.table tr:last-child td { border-bottom: none; }

.table-card   { overflow: hidden; }
.table-scroll { overflow-y: auto; }

@media (min-width: 1024px) {
  .table-card {
    flex: 1;
    min-height: 0;
    max-height: none;
    display: flex;
    flex-direction: column;
  }
  .table-scroll {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding-bottom: 0;
    max-height: none;
  }
  .table-card thead { position: sticky; top: 0; z-index: 10; }
}

/* Scrollbars */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; border-radius: 10px; }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: #94a3b8; }
html.theme-dark ::-webkit-scrollbar-thumb { background: #334155; }
html.theme-dark ::-webkit-scrollbar-thumb:hover { background: #475569; }

/* ═══════════════════════════════════════════════════════════
   INPUTS
═══════════════════════════════════════════════════════════ */
.input,
input:not([type=checkbox]):not([type=radio]):not([type=range]),
select,
textarea {
  border-radius: var(--radius);
  padding: 7px 11px;
  font-size: 13px;
  border: 0.5px solid #cbd5e1;
  background: #f8fafc;
  color: #0f172a;
  transition: border-color var(--transition), box-shadow var(--transition), background var(--transition);
  outline: none;
  line-height: 1.4;
  font-family: inherit;
}
.input:focus,
input:focus,
select:focus,
textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,.1);
  background: #fff;
}
input::placeholder, textarea::placeholder { color: #94a3b8; }

/* ═══════════════════════════════════════════════════════════
   SEARCH BAR
═══════════════════════════════════════════════════════════ */
.search-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  background: #f8fafc;
  border: 0.5px solid #e2e8f0;
  border-radius: 12px;
  padding: 8px 14px;
  width: 340px;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.search-bar:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,.1);
  background: #fff;
}
.search-bar i { color: #94a3b8; font-size: 14px; flex-shrink: 0; }
.search-bar:focus-within i { color: var(--primary); }
.search-input {
  all: unset;
  flex: 1;
  font-size: 13px;
  color: #0f172a;
  min-width: 0;
}
.search-input::placeholder { color: #94a3b8; }
.search-btn {
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 8px;
  width: 28px; height: 28px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  font-size: 12px;
  flex-shrink: 0;
  transition: filter 0.15s;
}
.search-btn:hover { filter: brightness(.9); }

/* ═══════════════════════════════════════════════════════════
   MODALS
═══════════════════════════════════════════════════════════ */
#modalRoot {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: none;
  align-items: flex-start;
  justify-content: center;
  padding: 3.5rem 1rem 1rem;
  background: rgba(0,0,0,.45);
}
#modalRoot:not(.hidden) { display: flex; }

.modal-window {
  width: 100%;
  max-width: 680px;
  max-height: 80vh;
  background: #fff;
  border: 0.5px solid #e2e8f0;
  border-radius: var(--radius-lg);
  box-shadow: 0 10px 40px rgba(0,0,0,.15);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  position: relative;
}
.modal-header-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 0.5px solid #e2e8f0;
  flex-shrink: 0;
}
#modalBody {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
}
#modalBody img,
#modalBody video { max-width: 100%; height: auto; display: block; border-radius: 8px; margin: 0 auto 12px; }
#modalBody * { max-width: 100%; word-break: break-word; }
#modalBody img.media-photo { max-width: 60%; }
#modalBody .table-scroll { max-height: 55vh; }

.modal-city-list { max-height: 50vh; overflow-y: auto; }

@media (max-width: 768px) {
  #modalRoot { padding: 1rem; align-items: flex-end; }
  .modal-window { max-width: 100%; max-height: 92vh; border-radius: var(--radius-lg) var(--radius-lg) 0 0; }
}

/* ═══════════════════════════════════════════════════════════
   CUSTOM SELECT
═══════════════════════════════════════════════════════════ */
.custom-select-wrapper { position: relative; }
.custom-select-display {
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
  overflow: hidden;
}

/* dropdown рендерится через JS с position:fixed — css только стиль */
.custom-select-dropdown {
  position: fixed; /* переопределяется JS */
  max-height: 280px;
  overflow-y: auto;
  background: #fff;
  border: 0.5px solid #e2e8f0;
  border-radius: var(--radius);
  box-shadow: 0 6px 20px rgba(0,0,0,.1);
  z-index: 999999;
  padding: 4px;
  will-change: transform;
  -webkit-transform: translateZ(0);
  transform: translateZ(0);
}
.custom-option {
  padding: 7px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 13px;
}

/* ═══════════════════════════════════════════════════════════
   TOGGLE SWITCH
═══════════════════════════════════════════════════════════ */
.toggle {
  width: 42px; height: 22px;
  background: #d1d5db;
  border-radius: 22px;
  position: relative;
  cursor: pointer;
  transition: background var(--transition);
  flex-shrink: 0;
}
.toggle::before {
  content: "";
  position: absolute;
  width: 16px; height: 16px;
  background: #fff;
  border-radius: 50%;
  top: 3px; left: 3px;
  transition: transform var(--transition);
  box-shadow: 0 1px 3px rgba(0,0,0,.25);
}
.toggle.active { background: var(--primary); }
.toggle.active::before { transform: translateX(20px); }
.toggle.pending { opacity: .6; pointer-events: none; }

/* ═══════════════════════════════════════════════════════════
   NAV (sidebar items — active state handled via .active)
═══════════════════════════════════════════════════════════ */
.nav-link {
  display: flex;
  align-items: center;
  gap: 6px;
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
}

/* ═══════════════════════════════════════════════════════════
   AUTH
═══════════════════════════════════════════════════════════ */
.auth-wrapper {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: #f0f2f5;
}
html.theme-dark .auth-wrapper { background: #0f172a; }
.auth-wrapper .card { width: 100%; max-width: 420px; padding: 28px; }

/* ═══════════════════════════════════════════════════════════
   MEDIA
═══════════════════════════════════════════════════════════ */
.media-photo { max-width: 100%; border-radius: 8px; cursor: zoom-in; }
.media-video {
  max-width: 100%; max-height: 300px;
  border-radius: 6px; background: #000;
  object-fit: contain;
}

/* ═══════════════════════════════════════════════════════════
   LIGHTBOX
═══════════════════════════════════════════════════════════ */
body.lightbox-open { overflow: hidden; }

#lightbox {
  position: fixed;
  inset: 0;
  z-index: 100000;
  animation: fadeIn .15s ease;
}
#lightbox.hidden { display: none; }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes zoomIn {
  from { transform: scale(.92) translate(-50%,-50%); opacity: 0; }
  to   { transform: scale(1)   translate(-50%,-50%); opacity: 1; }
}

#lightboxImg,
#lightboxVideo {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  max-width: 90vw; max-height: 90vh;
  object-fit: contain;
  animation: zoomIn .15s ease;
}
#lightboxImg.hidden,
#lightboxVideo.hidden { display: none; }
#lightboxVideo { display: block; width: auto; height: auto; }

@media (max-width: 768px) {
  #lightboxImg { max-width: 95vw; max-height: 70vh; }
  #lbPrev, #lbNext { display: none; }
}

/* ═══════════════════════════════════════════════════════════
   REQUEST DETAIL (модалка "Заявка №")
═══════════════════════════════════════════════════════════ */
.rd-title { font-size: 16px; font-weight: 600; margin-bottom: 12px; }

.rd-table { width: 100%; border-collapse: collapse; font-size: 13px; margin-bottom: 16px; }
.rd-table tr { border-bottom: 0.5px solid #f1f5f9; }
.rd-table tr:last-child { border-bottom: none; }
.rd-table td { padding: 7px 4px; vertical-align: top; }
.rd-table td:first-child {
  width: 180px;
  min-width: 140px;
  font-weight: 600;
  color: #64748b;
  white-space: nowrap;
}
html.theme-dark .rd-table tr { border-color: #1e293b; }
html.theme-dark .rd-table td:first-child { color: #94a3b8; }

.rd-subtitle { font-size: 13px; font-weight: 600; margin: 14px 0 8px; color: #64748b; }
html.theme-dark .rd-subtitle { color: #94a3b8; }

.rd-media { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 8px; }
.rd-media .media-photo,
.rd-media .media-video { max-width: 220px; max-height: 220px; }

.rd-file-link {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 13px; color: var(--primary); text-decoration: none;
}
.rd-file-link:hover { text-decoration: underline; }

.rd-note-form { display: flex; flex-direction: column; gap: 8px; }
.rd-note-form textarea { resize: vertical; min-height: 90px; }
.rd-note-form .btn { align-self: flex-start; }

@media (max-width: 768px) {
  .rd-table td:first-child { width: auto; min-width: 110px; }
}

/* ═══════════════════════════════════════════════════════════
   LOCATIONS
═══════════════════════════════════════════════════════════ */
.loc-layout {
  flex: 1;
  min-height: 0;
  overflow: hidden;
}
.loc-panel {
  background: #fff;
  border: 0.5px solid #e2e8f0;
  border-radius: var(--radius-lg);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
/* На десктопе панели занимают всю высоту */
@media (min-width: 769px) {
  .loc-layout { overflow-y: auto; }
  .loc-panel   { min-height: 100%; }
}
@media (max-width: 768px) {
  .loc-panel { min-height: auto; }
}
.loc-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 0.5px solid #e2e8f0;
}
html.theme-dark .loc-header { border-color: #1e293b; }
.loc-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 9px 14px;
  cursor: pointer;
  border-bottom: 0.5px solid #f1f5f9;
  transition: background var(--transition);
}
html.theme-dark .loc-item { border-color: #1e293b; }
.loc-item:last-child { border-bottom: none; }

/* footer удалён — контент перенесён в sidebar */

/* ═══════════════════════════════════════════════════════════
   EMOJI PANEL
═══════════════════════════════════════════════════════════ */
.emoji-panel:not(.hidden) {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 4px;
}
.emoji-panel .emoji {
  display: inline-flex; align-items: center; justify-content: center;
  width: 30px; height: 30px;
  border-radius: var(--radius-sm);
  cursor: pointer; font-size: 1.1rem;
  transition: background var(--transition);
}
.emoji-panel .emoji:hover { background: #e5e7eb; }
html.theme-dark .emoji-panel { background: #1e293b; border-color: #334155; }
html.theme-dark .emoji-panel .emoji:hover { background: #334155; }

/* ═══════════════════════════════════════════════════════════
   MOBILE MENU (fallback если sidebar скрыт)
═══════════════════════════════════════════════════════════ */
@media (max-width: 768px) {
  .sidebar { display: none; }
  .app-main { margin-left: 0; }

  .mobile-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    height: 50px;
    position: sticky;
    top: 0;
    z-index: 100;
    flex-shrink: 0;
  }
  html.theme-light .mobile-header { background: #fff; border-bottom: 0.5px solid #e2e8f0; }
  html.theme-dark  .mobile-header { background: #0b1220; border-bottom: 0.5px solid #1e293b; }

  #mobileNav {
    display: none;
    position: fixed;
    inset: 50px 0 0 0;
    z-index: 99;
    overflow-y: auto;
    padding: 12px;
    flex-direction: column;
    gap: 4px;
  }
  html.theme-light #mobileNav { background: #fff; }
  html.theme-dark  #mobileNav { background: #0b1220; }
  #mobileNav.show { display: flex; }

  .mob-nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 14px;
    border-radius: var(--radius);
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
    transition: background var(--transition);
  }
  html.theme-light .mob-nav-item { color: #374151; }
  html.theme-light .mob-nav-item:hover { background: #f1f5f9; }
  html.theme-light .mob-nav-item.active { background: #eff6ff; color: #1d4ed8; }
  html.theme-dark  .mob-nav-item { color: #94a3b8; }
  html.theme-dark  .mob-nav-item:hover { background: #1e293b; color: #e2e8f0; }
  html.theme-dark  .mob-nav-item.active { background: #1e3a8a; color: #bfdbfe; }
  .mob-nav-item i { font-size: 18px; width: 24px; text-align: center; }
}

@media (min-width: 769px) {
  .mobile-header { display: none; }
  #mobileNav { display: none !important; }
  .topbar { display: flex; }
}

/* ═══════════════════════════════════════════════════════════
   FILTERS CARD
═══════════════════════════════════════════════════════════ */
@media (min-width: 768px) {
  .filters-card > div {
    display: flex;
    flex-direction: row;
    align-items: center;
    width: 100%;
    gap: 8px;
  }
  .filters-card > div > div:last-child { margin-left: auto; }
}
@media (max-width: 767px) {
  .filters-card > div {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }
}

/* ═══════════════════════════════════════════════════════════
   UTILITIES
═══════════════════════════════════════════════════════════ */
.h-60vh { height: 60vh; }


/* ══════════════════════════════
   INLINE TOGGLE (уведомления / user mode)
══════════════════════════════ */
.inline-toggle {
  display: inline-flex;
  align-items: center;
  background: rgba(0,0,0,.06);
  border-radius: 20px;
  padding: 3px;
  gap: 2px;
}
html.theme-dark .inline-toggle { background: #1e293b; }

.inline-toggle-btn {
  padding: 3px 10px;
  border-radius: 16px;
  font-size: 11.5px;
  font-weight: 500;
  border: none;
  cursor: pointer;
  background: none;
  color: #94a3b8;
  transition: background var(--transition), color var(--transition), box-shadow var(--transition);
  white-space: nowrap;
  line-height: 1.4;
}
.inline-toggle-btn.on {
  background: #16a34a;
  color: #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,.15);
}
.inline-toggle-btn.off {
  background: #f1f5f9;
  color: #64748b;
  box-shadow: 0 1px 3px rgba(0,0,0,.08);
}
html.theme-dark .inline-toggle-btn.off {
  background: #334155;
  color: #94a3b8;
}


/* ═══════════════════════════════════════════════════════════
   ФИЛЬТРЫ ЗАЯВОК (rfb = requests filter bar)
═══════════════════════════════════════════════════════════ */

/* Строка фильтров — по центру, без фона */
.rfb-bar { display: none; } /* устарело */

/* Единая строка: Фильтры | Поиск | Действия */
.rfb-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 12px 0 24px;
}

/* Поиск в центре — растягивается */
.rfb-search {
  display: flex;
  align-items: center;
  gap: 8px;
  border-radius: 999px;
  padding: 6px 8px 6px 14px;
  width: 340px;
  flex-shrink: 1;
  min-width: 0;
  transition: border-color var(--transition), box-shadow var(--transition);
}
@media (min-width: 1200px) { .rfb-search { width: 420px; } }
html.theme-light .rfb-search { background: #f8fafc; border: 0.5px solid #e2e8f0; }
html.theme-dark  .rfb-search { background: #1e293b; border: 0.5px solid #334155; }
.rfb-search:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,.1);
}
.rfb-search-icon { font-size: 13px; flex-shrink: 0; color: #94a3b8; }
.rfb-search-input {
  all: unset;
  flex: 1;
  font-size: 13px;
  min-width: 0;
  outline: none !important;
  border: none !important;
  box-shadow: none !important;
  -webkit-appearance: none;
  background: transparent;
}
html.theme-light .rfb-search-input { color: #0f172a; }
html.theme-dark  .rfb-search-input { color: #e2e8f0; }
.rfb-search-input::placeholder { color: #94a3b8; }
.rfb-search-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 30px; height: 30px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  border: none;
  cursor: pointer;
  flex-shrink: 0;
  transition: filter var(--transition);
}
.rfb-search-btn:hover { filter: brightness(.9); }

/* Мобильный: поиск на следующей строке */
@media (max-width: 640px) {
  /* Строка кнопок: фильтры и действия пополам, поиск ниже */
  .rfb-row {
    flex-wrap: wrap;
    gap: 8px;
  }
  .rfb-wrap {
    flex: 1;
  }
  .rfb-wrap .rfb-btn {
    width: 100%;
    justify-content: center;
    min-height: 44px;
    font-size: 13.5px;
  }
  /* Поиск на второй строке — полная ширина */
  .rfb-search {
    order: 3;
    flex-basis: 100%;
    width: 100% !important;
  }
  /* Текст и шеврон показываем */
  .rfb-label { display: inline; }
  .rfb-chev  { display: inline; opacity: .5; font-size: 10px; }
}

/* Обёртка для позиционирования дропдауна */
.rfb-wrap { position: relative; }

/* Кнопка */
.rfb-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 16px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 500;
  border: 0.5px solid transparent;
  cursor: pointer;
  white-space: nowrap;
  text-decoration: none;
  background: none;
  transition: background var(--transition), border-color var(--transition);
  min-height: 40px;
}
html.theme-light .rfb-btn { background: #f1f5f9; color: #374151; border-color: #e2e8f0; }
html.theme-dark  .rfb-btn { background: #1e293b; color: #e2e8f0; border-color: #334155; }
html.theme-light .rfb-btn:hover { background: #e2e8f0; }
html.theme-dark  .rfb-btn:hover { background: #334155; }

.rfb-active {
  background: var(--primary) !important;
  color: #fff !important;
  border-color: var(--primary-dark) !important;
}
.rfb-warn {
  background: #fef3c7 !important;
  color: #92400e !important;
  border-color: #fde68a !important;
}
html.theme-dark .rfb-warn {
  background: #78350f !important;
  color: #fde68a !important;
  border-color: #92400e !important;
}

.rfb-label { /* текст кнопки — всегда виден */ }
.rfb-chev  { font-size: 10px; opacity: .5; }

/* Бейдж */
.rfb-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  font-size: 11px;
  font-weight: 600;
  background: rgba(255,255,255,.25);
  color: inherit;
}
.rfb-badge-warn { background: rgba(0,0,0,.15); }

/* Дропдаун */
.rfb-drop {
  position: fixed;
  z-index: 99999;
  border-radius: var(--radius-lg);
  padding: 6px;
  min-width: 240px;
  max-width: 100vw;
  max-height: calc(100vh - 90px);
  overflow-y: auto;
  overflow-x: hidden;
  box-shadow: 0 8px 24px rgba(0,0,0,.14);
}
html.theme-light .rfb-drop { background: #fff;    border: 0.5px solid #e2e8f0; }
html.theme-dark  .rfb-drop { background: #1e293b; border: 0.5px solid #334155; box-shadow: 0 8px 24px rgba(0,0,0,.45); }
.rfb-drop.hidden { display: none; }

.rfb-drop-section {
  padding: 4px 10px 6px;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: #94a3b8;
}
.rfb-drop-divider {
  height: 0.5px;
  margin: 4px 0;
}
html.theme-light .rfb-drop-divider { background: #f1f5f9; }
html.theme-dark  .rfb-drop-divider { background: #334155; }

.rfb-drop-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  text-decoration: none;
  cursor: pointer;
  border: none;
  background: none;
  text-align: left;
  transition: background var(--transition);
}
html.theme-light .rfb-drop-item { color: #374151; }
html.theme-dark  .rfb-drop-item { color: #e2e8f0; }
html.theme-light .rfb-drop-item:hover { background: #f1f5f9; }
html.theme-dark  .rfb-drop-item:hover { background: #334155; }

.rfb-drop-active {
  background: #eff6ff !important;
  color: var(--primary) !important;
}
html.theme-dark .rfb-drop-active { background: #1e3a8a !important; color: #bfdbfe !important; }

.rfb-drop-danger  { color: var(--danger)  !important; }
.rfb-drop-success { color: var(--success) !important; }
.rfb-drop-count   { margin-left: auto; font-size: 11px; font-weight: 600; color: #94a3b8; }

/* Форма дат внутри дропдауна */
.rfb-date-form    { padding: 4px 2px 2px; }
.rfb-date-row     { display: flex; gap: 6px; margin-bottom: 8px; }
.rfb-date-field   { flex: 1; min-width: 0; max-width: 100%; overflow: hidden; display: flex; flex-direction: column; gap: 3px; }
.rfb-date-field label { font-size: 10px; font-weight: 600; color: #94a3b8; text-transform: uppercase; letter-spacing: .04em; }

@media (max-width: 480px) {
  .rfb-date-row { flex-direction: column; }
}
/* ── Новый паттерн: видимый текстовый дисплей + скрытый нативный date input ──
   Решает проблему iOS Safari, где текст внутри type=date иногда не отображается
   из-за особенностей рендеринга псевдоэлементов движка. */
.date-input-wrap {
  position: relative;
  width: 100%;
}

.date-display {
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  padding: 10px 8px !important;
  font-size: 14px !important;
  line-height: 1.3 !important;
  min-height: 38px;
  border-radius: var(--radius-sm) !important;
  cursor: pointer;
}
html.theme-light .date-display { background: #f8fafc !important; border: 0.5px solid #cbd5e1 !important; color: #0f172a !important; }
html.theme-dark  .date-display { background: #0f172a !important; border: 0.5px solid #334155 !important; color: #e2e8f0 !important; }
.date-display::placeholder { color: #94a3b8 !important; opacity: 1; }

/* Нативный date input — визуально невидим (прозрачный), но находится
   ПОВЕРХ текстового дисплея и реально перехватывает тач/клик.
   На iOS Safari программный .click()/.showPicker() на элементе с
   pointer-events:none не открывает picker — поэтому здесь сам инпут
   должен быть кликабельным напрямую. */
.date-native-hidden {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
  border: none;
  margin: 0;
  padding: 0;
  z-index: 2;
}

.date-display {
  position: relative;
  z-index: 1;
}

.date-filter-input {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  box-sizing: border-box;
  border-radius: var(--radius-sm) !important;
}
html.theme-light .date-filter-input { background: #f8fafc !important; border: 0.5px solid #cbd5e1 !important; color: #0f172a !important; }
html.theme-dark  .date-filter-input { background: #0f172a !important; border: 0.5px solid #334155 !important; color: #e2e8f0 !important; color-scheme: dark; }
.rfb-date-actions { display: flex; gap: 6px; justify-content: center; margin-top: 4px; }

/* Компактная сетка 2 в строку — для фильтра "Статус выполнения",
   чтобы выпадающее меню целиком помещалось на экран */
.rfb-drop-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
}
.rfb-drop-item-sm {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding: 8px 9px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-weight: 500;
  text-decoration: none;
  cursor: pointer;
  border: none;
  background: none;
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: background var(--transition);
}
html.theme-light .rfb-drop-item-sm { color: #374151; }
html.theme-dark  .rfb-drop-item-sm { color: #e2e8f0; }
html.theme-light .rfb-drop-item-sm:hover { background: #f1f5f9; }
html.theme-dark  .rfb-drop-item-sm:hover { background: #334155; }

/* ── Мобильные tap-target ── */
@media (max-width: 768px) {
  .rfb-btn {
    padding: 10px 14px;
    min-height: 44px;
    font-size: 13px;
  }
  .btn      { min-height: 42px; padding: 9px 16px; font-size: 13.5px; }
  .btn.btn-sm { min-height: 36px; padding: 7px 12px; font-size: 12.5px; }
  .btn.btn-xs { min-height: 32px; padding: 5px 10px; font-size: 12px; }
  .sb-item  { min-height: unset; }
}

/* ═══════════════════════════════════════════════════════════
   MODAL FOOTER
═══════════════════════════════════════════════════════════ */
.modal-footer-bar {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 12px 16px;
  flex-shrink: 0;
  border-top: 0.5px solid #e2e8f0;
}
html.theme-dark .modal-footer-bar { border-color: #1e293b; }
.modal-footer-bar.hidden { display: none; }

/* ═══════════════════════════════════════════════════════════
   REQUEST DETAIL — СПОЙЛЕРЫ
═══════════════════════════════════════════════════════════ */
.rd-spoiler {
  border: 0.5px solid #e2e8f0;
  border-radius: var(--radius);
  margin: 10px 0;
  overflow: hidden;
}
html.theme-dark .rd-spoiler { border-color: #1e293b; }

.rd-spoiler-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  list-style: none;
  user-select: none;
  transition: background var(--transition);
}
.rd-spoiler-toggle::-webkit-details-marker { display: none; }
html.theme-light .rd-spoiler-toggle:hover { background: #f8fafc; }
html.theme-dark  .rd-spoiler-toggle:hover { background: #1e293b; }

.rd-spoiler-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
  background: #e2e8f0;
  color: #475569;
}
html.theme-dark .rd-spoiler-count { background: #334155; color: #94a3b8; }

.rd-spoiler-chevron {
  margin-left: auto;
  font-size: 11px;
  color: #94a3b8;
  transition: transform var(--transition);
}
details[open] > .rd-spoiler-toggle .rd-spoiler-chevron { transform: rotate(180deg); }
details[open] > .rd-spoiler-toggle { border-bottom: 0.5px solid #e2e8f0; }
html.theme-dark details[open] > .rd-spoiler-toggle { border-color: #1e293b; }

/* Textarea пометки */
.rd-note-textarea {
  width: 100%;
  max-width: 400px;
  resize: vertical;
  min-height: 80px;
  display: block;
}

/* ═══════════════════════════════════════════════════════════
   SIDEBAR BADGES
═══════════════════════════════════════════════════════════ */
.sb-badge {
  display: none;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
  margin-left: auto;
  flex-shrink: 0;
  background: #dc2626;
  color: #fff;
}
.sb-badge-blue { background: #2563eb; }

/* В свёрнутом сайдбаре бейдж поверх иконки */
.sb-item .sb-badge {
  margin-left: auto;
  opacity: 0;
  transition: opacity var(--transition);
}
.sidebar:hover .sb-item .sb-badge { opacity: 1; }

/* Точка-индикатор на иконке когда sidebar свёрнут */
.sb-item:has(.sb-badge[style*="inline-flex"])::after {
  content: '';
  position: absolute;
  top: 6px;
  right: 6px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #dc2626;
  border: 2px solid #0b1220;
}
.sb-item { position: relative; }
.sidebar:hover .sb-item::after { display: none; }

/* Список городов / аппаратов — занимает остаток панели */
.loc-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  list-style: none;
  margin: 0;
  padding: 0;
}
@media (max-width: 768px) {
  .loc-list { max-height: 50vh; }
}

/* ═══════════════════════════════════════════════════════════
   LOCATIONS — спойлер городов на мобиле
═══════════════════════════════════════════════════════════ */
.loc-cities-spoiler {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

.loc-spoiler-summary {
  cursor: pointer;
  user-select: none;
  list-style: none;
}
.loc-spoiler-summary::-webkit-details-marker { display: none; }

.loc-chev {
  font-size: 11px;
  color: #94a3b8;
  transition: transform 0.2s;
  flex-shrink: 0;
}
details[open] .loc-chev { transform: rotate(180deg); }

/* Мобиль: убираем ограничение высоты для loc-list */
@media (max-width: 768px) {
  .loc-list    { max-height: none; overflow-y: visible; }
  .loc-layout  { overflow-y: auto; height: auto; }
  .loc-panel   { min-height: auto; }
}

/* Строки переключателей в карточке пользователя */
.user-toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  font-size: 13px;
  padding: 6px 0;
  background: transparent !important;
}

/* ═══════════════════════════════════════════════════════════
   USER AVATARS
═══════════════════════════════════════════════════════════ */
.user-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
  background: #1e293b;
}

.user-avatar-fallback {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.user-avatar-wrap {
  position: relative;
  flex-shrink: 0;
}
.user-avatar-refresh {
  position: absolute;
  bottom: -3px; right: -3px;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: #1e293b;
  border: 1.5px solid #334155;
  color: #94a3b8;
  font-size: 10px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  padding: 0;
  line-height: 1;
  opacity: 0;
  transition: opacity var(--transition);
}
.user-avatar-wrap:hover .user-avatar-refresh { opacity: 1; }

/* ═══════════════════════════════════════════════════════════
   MAILING / DIALOGI PAGE LAYOUT
═══════════════════════════════════════════════════════════ */
.mailing-layout {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.mailing-grid {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

/* Карточки внутри грида — тянутся по высоте */
.mailing-grid > .card {
  display: flex;
  flex-direction: column;
  min-height: 0;
  margin-bottom: 0;
}

/* Скролл истории — занимает весь остаток карточки */
.mailing-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}

@media (max-width: 768px) {
  .mailing-grid {
    grid-template-columns: 1fr;
    overflow-y: auto;
    flex: none;
  }
  .mailing-grid > .card { min-height: auto; }
  .mailing-scroll { max-height: 50vh; overflow-y: auto; }
}

/* Аватары в диалогах */
.msg-avatar-wrap {
  position: relative;
  width: 28px;
  height: 28px;
  flex-shrink: 0;
}
.msg-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  object-fit: cover;
  display: block;
}
.msg-avatar-fallback {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  display: none;
  align-items: center;
  justify-content: center;
}

/* ═══════════════════════════════════════════════════════════
   MAILING — мобильный спойлер истории
═══════════════════════════════════════════════════════════ */
.mailing-history-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 8px 0;
  cursor: pointer;
  border: none;
  background: none;
  text-align: left;
}
/* Гарантируем что на десктопе кнопка-спойлер скрыта,
   даже если Tailwind md:hidden проигрывает по порядку каскада */
@media (min-width: 769px) {
  .mailing-history-summary { display: none !important; }
}
.mailing-history-chevron {
  font-size: 12px;
  color: #94a3b8;
  transition: transform var(--transition);
  flex-shrink: 0;
}

/* На мобиле контент по умолчанию свёрнут (без ожидания JS — нет мигания) */
@media (max-width: 768px) {
  .mailing-history-content {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.25s ease;
  }
  .mailing-history-content.expanded {
    max-height: 70vh;
    overflow-y: auto;
  }
}

/* На десктопе спойлер не используется — контент всегда виден,
   и должен сам быть flex-контейнером, чтобы .mailing-scroll внутри
   мог растянуться на всю высоту карточки и скроллиться внутри себя. */
@media (min-width: 769px) {
  .mailing-history-content {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: visible;
  }
}

/* Промежуточный контейнер для AJAX-обновления истории (используется при
   реал-тайм обновлении сообщений) — должен прозрачно передавать flex-контекст
   от .mailing-history-content к .mailing-scroll, иначе цепочка размеров рвётся
   и контент "вытекает" за карточку без скролла. */
#mailingHistoryAjaxTarget {
  display: contents;
}
@media (max-width: 768px) {
  #mailingHistoryAjaxTarget {
    display: block;
  }
}

/* ═══════════════════════════════════════════════════════════
   MAILING — кнопки действий (файл/эмодзи/голос/кружок)
═══════════════════════════════════════════════════════════ */
.mailing-action-btns {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.mailing-action-btns .btn {
  flex: 1;
  min-width: 0;
  justify-content: center;
}

/* Кнопка отправить — отдельной строкой на мобиле, под действиями */
.mailing-send-btn {
  width: 100%;
}
@media (min-width: 769px) {
  .mailing-send-btn { width: auto; }
}

/* Страница настроек — собственный скролл независимо от page-content overflow:hidden */
@media (min-width: 769px) {
  .settings-scroll-wrap {
    height: 100%;
    overflow-y: auto;
    padding-right: 4px;
  }
}

/* ═══════════════════════════════════════════════════════════
   SETTINGS — выровненные строки label/input (S3, токен бота)
═══════════════════════════════════════════════════════════ */
.s3-field-row {
  display: grid;
  grid-template-columns: 110px 1fr;
  align-items: center;
  gap: 12px;
}
.s3-field-row .label {
  margin-bottom: 0;
  white-space: nowrap;
}
.s3-field-row .input {
  width: 100%;
  min-width: 0;
}

@media (max-width: 640px) {
  .s3-field-row {
    grid-template-columns: 1fr;
    gap: 4px;
  }
}

/* ═══════════════════════════════════════════════════════════
   СОСТОЯНИЕ СЕРВЕРА — шкалы CPU/RAM/Swap/Диск + карточки контейнеров
═══════════════════════════════════════════════════════════ */
.server-gauges {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 14px;
}
.server-gauge-label { font-size: 12px; font-weight: 600; margin-bottom: 4px; opacity: .7; }
.server-gauge-bar {
  height: 8px;
  border-radius: 4px;
  overflow: hidden;
  background: #e2e8f0;
}
html.theme-dark .server-gauge-bar { background: #334155; }
.server-gauge-fill {
  height: 100%;
  width: 0%;
  background: #16a34a;
  transition: width .5s ease, background .3s ease;
}
.server-gauge-fill.warn { background: #d97706; }
.server-gauge-fill.danger { background: #dc2626; }
.server-gauge-value { font-size: 12px; margin-top: 4px; opacity: .6; }

.containers-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 10px;
}
.container-card {
  border: 0.5px solid #e2e8f0;
  border-radius: var(--radius);
  padding: 10px 12px;
}
html.theme-dark .container-card { border-color: #334155; }
.container-card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.container-card-name { font-weight: 600; font-size: 13px; text-transform: capitalize; }
.container-card-stats { font-size: 11px; opacity: .6; margin-bottom: 8px; min-height: 14px; }
.container-status-dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; margin-right: 5px; }
.container-status-dot.running { background: #16a34a; }
.container-status-dot.exited, .container-status-dot.not_found { background: #dc2626; }
.container-status-dot.restarting { background: #d97706; animation: pulse-dot 1s infinite; }
.container-status-dot.paused, .container-status-dot.created { background: #94a3b8; }
@keyframes pulse-dot { 0%, 100% { opacity: 1; } 50% { opacity: .3; } }

/* Оверлей "перезапускается..." */
#restartOverlay {
  position: fixed;
  inset: 0;
  z-index: 999999;
  background: rgba(15, 23, 42, .55);
  display: flex;
  align-items: center;
  justify-content: center;
}
#restartOverlay.hidden { display: none; }
.restart-overlay-card {
  background: #fff;
  border-radius: var(--radius-lg);
  padding: 28px 32px;
  text-align: center;
  min-width: 280px;
  box-shadow: 0 20px 50px rgba(0,0,0,.3);
}
html.theme-dark .restart-overlay-card { background: #1e293b; color: #e2e8f0; }
.restart-overlay-title { font-weight: 600; margin-bottom: 4px; }
.restart-overlay-sub { font-size: 12px; opacity: .6; margin-bottom: 16px; }
.restart-overlay-bar {
  height: 6px;
  border-radius: 3px;
  background: #e2e8f0;
  overflow: hidden;
  margin-bottom: 10px;
}
html.theme-dark .restart-overlay-bar { background: #334155; }
.restart-overlay-bar-fill {
  height: 100%;
  width: 30%;
  background: var(--primary);
  border-radius: 3px;
  animation: restart-bar-slide 1.2s ease-in-out infinite;
}
@keyframes restart-bar-slide {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(330%); }
}
.restart-overlay-seconds { font-size: 12px; opacity: .5; }
