/* ===== SHARED STYLES — Common for all pages ===== */

@keyframes add-user-spin { to { transform: rotate(360deg); } }

* { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; background: #f5f5f7; color: #1a1a2e; line-height: 1.5; }

/* Header */
.header { background: #fff; padding: 0 24px; height: 40px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid #e5e5ea; position: sticky; top: 0; left: 0; z-index: 200; width: 100vw; }
.logo { font-size: 20px; font-weight: 700; color: #534AB7; display: flex; align-items: center; gap: 8px; }
.logo svg { width: 28px; height: 28px; }

/* Avatar & User Menu */
.avatar { width: 32px; height: 32px; border-radius: 50%; background: #534AB7; color: #fff; display: flex; align-items: center; justify-content: center; font-size: 14px; font-weight: 600; cursor: pointer; position: relative; }
.user-menu { display: none; position: absolute; top: 40px; right: 0; background: #fff; border-radius: 10px; box-shadow: 0 4px 20px rgba(0,0,0,0.15); min-width: 200px; z-index: 300; overflow: hidden; }
.user-menu.open { display: block; }
.user-menu-header { padding: 12px 16px; border-bottom: 1px solid #f0f0f0; }
.user-menu-header .name { font-weight: 600; font-size: 14px; }
.user-menu-header .email { font-size: 12px; color: #8e8e93; cursor: pointer; text-decoration: none; display: block; }
.user-menu-item { padding: 10px 16px; font-size: 13px; cursor: pointer; display: flex; align-items: center; gap: 8px; }
.user-menu-item:hover { background: #f5f5f7; }
.user-menu-item.danger { color: #ff3b30; }

/* Navigation */
.header-nav { display: flex; gap: 16px; position: absolute; left: 50%; transform: translateX(-50%); }
.nav-link { font-size: 13px; font-weight: 600; color: #8e8e93; text-decoration: none; padding: 8px 0; border-bottom: 2px solid transparent; transition: all .2s; cursor: pointer; }
.nav-link:hover { color: #534AB7; }
.nav-link.active { color: #534AB7; border-bottom-color: #534AB7; }

/* Глобальная блокировка интерфейса во время автоматической цепочки обновлений.
   Прозрачный оверлей съедает все клики, кроме навигации (z-index у .nav-link
   выше). Дополнительно — pointer-events:none на body, который перебивается
   обратно для .nav-link. Банер в правом нижнем углу. */
#chainOverlay { position: fixed; top: 0; left: 0; right: 0; bottom: 0; z-index: 199; display: none; cursor: not-allowed; background: transparent; }
body.chain-active #chainOverlay { display: block; }
body.chain-active { user-select: none; }
body.chain-active button:not(.nav-link), body.chain-active input:not([type=hidden]), body.chain-active select, body.chain-active textarea, body.chain-active [contenteditable] {
  pointer-events: none !important;
  opacity: 0.55;
}
body.chain-active .nav-link { pointer-events: auto !important; opacity: 1 !important; }
.chain-banner { position: fixed; bottom: 16px; right: 16px; background: #534AB7; color: #fff; padding: 10px 16px; border-radius: 10px; box-shadow: 0 4px 16px rgba(0,0,0,0.18); font-size: 13px; font-weight: 500; display: none; z-index: 1000; max-width: 320px; }
body.chain-active .chain-banner { display: block; }
.chain-banner-head { cursor: pointer; user-select: none; display: flex; align-items: center; gap: 8px; }
.chain-banner-arrow { display: inline-block; transition: transform .2s; font-size: 10px; line-height: 1; }
.chain-banner-arrow.open { transform: rotate(180deg); }
.chain-banner-list { margin-top: 10px; padding-top: 10px; border-top: 1px solid rgba(255,255,255,0.25); max-height: 320px; overflow-y: auto; }
.chain-step { display: flex; align-items: center; gap: 8px; padding: 4px 0; font-size: 12px; line-height: 1.3; }
.chain-step.done { opacity: 0.55; }
.chain-step.running { opacity: 1; font-weight: 600; }
.chain-step.pending { opacity: 0.45; }
.chain-step.failed { opacity: 0.85; color: #ffd5d5; }
.chain-step.failed .chain-step-icon { color: #ff6b6b; font-weight: 700; }
.chain-step-icon { display: inline-flex; width: 14px; justify-content: center; flex-shrink: 0; }

/* Modals */
.modal-overlay { position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,0.4); z-index: 500; display: flex; align-items: center; justify-content: center; }
.modal-box { background: #fff; border-radius: 12px; padding: 24px; min-width: 320px; max-width: 420px; box-shadow: 0 8px 32px rgba(0,0,0,0.2); }

/* Пикер «Выбранный диапазон» (daterange.js) — общий для Артикулов, Общего, Склеек.
   Классы дублируют inline-стили в cabinet.html (там собственная копия), значения
   идентичны. */
.dr-section-label { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.3px; color: #8e8e93; margin: 12px 0 5px; }
.dr-section-label:first-child { margin-top: 0; }
.dr-section-label.dr-prev-label { color: #6b7280; }
.dr-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.dr-cell { padding: 7px 2px; text-align: center; font-size: 12px; border: 1px solid #e5e5ea; border-radius: 6px; cursor: pointer; user-select: none; background: #fff; transition: background .1s, border-color .1s, color .1s; white-space: nowrap; }
.dr-cell:hover { border-color: #534AB7; background: #f5f3fa; }
.dr-cell.dr-prev { background: #fafafb; color: #6e6e73; }
.dr-cell.dr-prev:hover { background: #f3f1fa; color: #1a1a2e; }
.dr-cell.dr-in-range { background: #ede9f7; border-color: #c9c2ea; color: #1a1a2e; }
.dr-cell.dr-start, .dr-cell.dr-end { background: #534AB7; border-color: #534AB7; color: #fff; font-weight: 600; }
/* Переключатель режима: «Диапазон дат» / «Крайние N дней» */
.dr-mode-tabs { display: flex; gap: 0; border: 1px solid #e5e5ea; border-radius: 8px; overflow: hidden; margin-bottom: 12px; }
.dr-mode-tab { flex: 1; padding: 8px 10px; font-size: 13px; border: none; background: #fff; color: #8e8e93; cursor: pointer; font-family: inherit; transition: background .12s, color .12s; }
.dr-mode-tab + .dr-mode-tab { border-left: 1px solid #e5e5ea; }
.dr-mode-tab.active { background: #534AB7; color: #fff; font-weight: 600; }
.dr-lastn-row { display: flex; align-items: center; gap: 10px; font-size: 13px; padding: 10px 0; }
.dr-lastn-input { width: 90px; padding: 7px 10px; border: 1px solid #e5e5ea; border-radius: 8px; font-size: 14px; text-align: center; outline: none; font-family: inherit; }
.dr-lastn-input:focus { border-color: #534AB7; }
.dr-lastn-hint { font-size: 12px; color: #8e8e93; }

/* Еженедельное напоминание — группы значений в модалке */
.rem-group { border: 1px solid #e5e5ea; border-radius: 10px; padding: 12px 14px; margin-bottom: 12px; }
.rem-group:last-child { margin-bottom: 0; }
.rem-group-head { display: flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 600; color: #534AB7; margin-bottom: 10px; }
.rem-rows { display: flex; flex-direction: column; gap: 1px; }
.rem-row { display: flex; align-items: center; justify-content: space-between; font-size: 13px; padding: 5px 2px; border-bottom: 1px solid #f4f4f7; }
.rem-row:last-child { border-bottom: none; }
.rem-label { color: #6e6e73; }
.rem-val { font-weight: 600; color: #1a1a2e; }

/* Cabinet settings */
.cab-tab { padding: 6px 16px; font-size: 13px; border: none; background: none; color: #8e8e93; cursor: pointer; border-bottom: 2px solid transparent; transition: all .15s; }
.cab-tab:hover { color: #534AB7; }
.cab-tab.active { color: #534AB7; border-bottom-color: #534AB7; font-weight: 600; }
.links-sidebar { display: flex; flex-direction: column; gap: 4px; padding-right: 12px; border-right: 1px solid #e5e5ea; }
.links-nav { width: 36px; height: 36px; display: flex; align-items: center; justify-content: center; border-radius: 8px; border: none; background: none; color: #8e8e93; cursor: pointer; transition: all .15s; }
.links-nav:hover { background: #e5e5ea; color: #534AB7; }
.links-nav.active { background: #534AB7; color: #fff; }
.link-item { display: flex; align-items: center; gap: 8px; padding: 8px 0; border-bottom: 1px solid #f0f0f5; font-size: 13px; }
.link-item-name { font-weight: 500; color: #1a1a2e; }
.link-item-id { font-size: 11px; color: #b0b0b5; }
.link-item-actions { margin-left: auto; display: flex; gap: 6px; }
.cabinet-users-list { max-height: 300px; overflow-y: auto; }
.cabinet-user-row { display: flex; align-items: center; gap: 8px; padding: 8px 0; border-bottom: 1px solid #f0f0f0; font-size: 13px; flex-wrap: wrap; }
.cabinet-user-row .user-email { flex: 1; }
.cabinet-user-row .user-role { font-size: 11px; padding: 2px 8px; border-radius: 4px; }
.cabinet-user-row .user-role.admin { background: #e8d5f5; color: #7b2cbf; }
.cabinet-user-row .user-role.member { background: #e8f5e9; color: #2e7d32; }
.add-user-row { display: flex; gap: 8px; margin-top: 12px; }
.add-user-row input { flex: 1; padding: 8px 10px; border: 1px solid #e5e5ea; border-radius: 8px; font-size: 13px; outline: none; }
.add-user-row input:focus { border-color: #534AB7; }
.add-user-row button { padding: 8px 14px; background: #534AB7; color: #fff; border: none; border-radius: 8px; font-size: 13px; cursor: pointer; }
.create-cab-field { margin-bottom: 12px; }
.create-cab-field input { width: 100%; padding: 10px 12px; border: 1px solid #e5e5ea; border-radius: 8px; font-size: 14px; outline: none; }
.create-cab-field input:focus { border-color: #534AB7; }

/* Global settings inputs */
.gs-input { width: 70px; padding: 3px 8px; border: 1px solid #e5e5ea; border-radius: 6px; font-size: 13px; text-align: center; outline: none; background: #fafafa; }
.gs-input:focus { border-color: #534AB7; background: #fff; }

/* Buttons */
.btn { padding: 10px 18px; border: 1px solid #e5e5ea; border-radius: 10px; background: #fff; font-size: 13px; cursor: pointer; color: #1a1a2e; display: flex; align-items: center; gap: 6px; transition: all .2s; }
.btn:hover { border-color: #534AB7; color: #534AB7; }

/* «Нет прав» — внешний вид заблокированного элемента. Клики блокируются
   глобальным capture-listener'ом (shared.js), а title="Нет прав" даёт подсказку. */
.no-perm { opacity: 0.45 !important; cursor: not-allowed !important; filter: grayscale(0.6); }
.no-perm:hover { background: inherit !important; color: inherit !important; border-color: #e5e5ea !important; }
.nav-link.no-perm { color: #b0b0b5 !important; border-bottom-color: transparent !important; }

/* Универсальная блокировка кнопок/инпутов во время начальной загрузки данных
   страницы (body.app-loading). Исключаем nav-link (навигация должна работать)
   и .no-perm (там свой стиль). Cabinet.html имеет свою более специфичную
   правилу для .controls — она остаётся, эта работает на всех других страницах. */
body.app-loading button:not(.nav-link):not(.no-perm),
body.app-loading input:not([type=hidden]):not(.no-perm),
body.app-loading select:not(.no-perm) { pointer-events: none; opacity: 0.55; }

/* Loading screen */
.loading-screen { display: flex; align-items: center; justify-content: center; height: 60vh; color: #8e8e93; font-size: 14px; }

/* Responsive */
@media (max-width: 768px) {
  .header { padding: 0 16px; }
}
