/* ============================================================
   Боковая панель управления (слева)
   Тёмная тема: графит #1a1a1a + золото #aa9974 (unionsk.ru)
   ============================================================ */

/* Кнопка-логотип для открытия панели */
.sidebar-toggle {
    position: fixed;
    top: 16px;
    left: 16px;
    z-index: 1100;
    width: 44px;
    height: 44px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.4);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s, transform 0.2s, border-color 0.2s;
}

.sidebar-toggle:hover {
    background: var(--surface-hover);
    border-color: var(--brand);
}

/* Логотип «ЮНИОН» внутри кнопки */
.sidebar-logo {
    width: 26px;
    height: auto;
    display: block;
    filter: drop-shadow(0 0 0 transparent);
    transition: filter 0.2s;
}

.sidebar-toggle:hover .sidebar-logo {
    filter: brightness(1.25) drop-shadow(0 0 4px rgba(170, 153, 116, 0.45));
}

/* Сама панель: выезжает слева.
   top = var(--header-height): панель начинается НИЖЕ верхнего хедера
   (z-index 1150 > 1050), чтобы шапка её не перекрывала. Высота уменьшена
   на высоты хедера и футера (z-index 1150), чтобы панель не уходила
   под нижнюю полосу-футер. */
.sidebar {
    position: fixed;
    top: var(--header-height);
    left: 0;
    z-index: 1050;
    width: 340px;
    max-width: 85vw;
    height: calc(100vh - var(--header-height) - var(--footer-height, 48px));
    background: var(--bg);
    box-shadow: 2px 0 16px rgba(0, 0, 0, 0.5);
    display: flex;
    flex-direction: column;
    transform: translateX(-100%);
    transition: transform 0.3s ease;
}

.sidebar.open {
    transform: translateX(0);
}

/* Экраны панели: по умолчанию скрыты, активный показывается */
.screen {
    display: none;
    flex-direction: column;
    flex: 1;
    min-height: 0;
}

.screen.active {
    display: flex;
}

/* Заголовок панели */
.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 16px;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
    flex-shrink: 0;
}

.sidebar-header h2 {
    font-size: 18px;
    font-weight: 600;
    letter-spacing: 0.5px;
    color: var(--text);
    margin: 0;
    flex: 1;
    text-align: center;
    text-transform: uppercase;
}

.sidebar-close,
.sidebar-back {
    width: 32px;
    height: 32px;
    border: none;
    border-radius: var(--radius-sm);
    background: transparent;
    font-size: 22px;
    line-height: 1;
    color: var(--text-muted);
    cursor: pointer;
    transition: background 0.2s, color 0.2s;
    flex-shrink: 0;
}

.sidebar-close:hover,
.sidebar-back:hover {
    background: var(--surface-hover);
    color: var(--text);
}

/* Тело панели со списком */
.sidebar-body {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

/* --- Главное меню --- */
.menu-nav {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.menu-item {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 14px 12px;
    border: none;
    border-radius: var(--radius);
    background: transparent;
    cursor: pointer;
    text-align: left;
    transition: background 0.15s;
}

.menu-item:hover {
    background: var(--surface-hover);
}

.menu-item-icon {
    width: 24px;
    height: 24px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.menu-item-icon svg {
    width: 20px;
    height: 20px;
    display: block;
    color: var(--text);
    transition: color 0.15s;
}

.menu-item:hover .menu-item-icon svg {
    color: var(--brand);
}

.menu-item-label {
    flex: 1;
    font-size: 15px;
    font-weight: 500;
    color: var(--text);
}

.menu-item-arrow {
    color: var(--brand);
    font-size: 18px;
    flex-shrink: 0;
    transition: color 0.15s;
}

.menu-item:hover .menu-item-arrow {
    color: var(--brand-hover);
}

/* Список объектов */
.object-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.object-list-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 14px;
    border-radius: var(--radius);
    cursor: pointer;
    transition: background 0.15s;
    border-bottom: 1px solid var(--border);
}

.object-list-item:hover {
    background: var(--surface-hover);
}

.object-list-item .obj-info {
    flex: 1;
    min-width: 0;
}

.object-list-item .obj-name {
    font-size: 16px;
    font-weight: 600;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.object-list-item .obj-address {
    font-size: 14px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.object-list-empty {
    padding: 24px 16px;
    text-align: center;
    color: var(--text-secondary);
    font-size: 14px;
}

/* --- Элемент списка сотрудников --- */
.personnel-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: var(--radius);
    cursor: pointer;
    transition: background 0.15s;
    border-bottom: 1px solid var(--border);
}

.personnel-item:hover {
    background: var(--surface-hover);
}

.personnel-item .obj-info {
    flex: 1;
    min-width: 0;
}

/* Бейдж статуса сотрудника */
.personnel-status-badge {
    display: inline-block;
    flex-shrink: 0;
    padding: 2px 8px;
    border-radius: 0;
    color: #fff;
    font-size: 13px;
    font-weight: 600;
}

.personnel-status-badge.active {
    background: #2ecc71;
}

.personnel-status-badge.vacation {
    background: #f39c12;
}

.personnel-status-badge.inactive {
    background: #555;
}

/* --- Архивные объекты в списке (приглушённый вид) --- */
.object-list-item.archived {
    opacity: 0.6;
    background: #232323;
}

.object-list-item.archived:hover {
    background: #2b2b2b;
}

.object-list-item.archived .obj-name {
    color: #6a6a6a;
    text-decoration: line-through;
}

.object-list-item.archived .obj-address {
    color: #6a6a6a;
}

/* --- Бейдж приоритета события --- */
.priority-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 0;
    color: #fff;
    font-size: 13px;
    font-weight: 600;
    flex-shrink: 0;
}

.priority-high   { background: #ff1900; }
.priority-medium { background: #f15a0f; }
.priority-low    { background: #fbff00; color: #1a1a1a; }

/* --- События на вкладке «Информация» карточки --- */
.info-events {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.info-events-empty {
    color: var(--text-secondary);
    font-size: 15px;
    font-style: italic;
}

.info-event-item {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 8px 10px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.info-event-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.info-event-type {
    font-size: 15px;
    font-weight: 600;
    color: var(--text);
}

.info-event-meta {
    font-size: 14px;
    color: var(--text-secondary);
}

.event-complete-btn {
    align-self: flex-start;
}

/* --- Диалоговое окно архива (модальное) --- */
.archive-dialog {
    position: fixed;
    top: 0;
    left: 0;
    z-index: 1200;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.archive-dialog[hidden] {
    display: none;
}

.archive-dialog-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
}

.archive-dialog-box {
    position: relative;
    width: 320px;
    max-width: 90vw;
    background: var(--surface-3);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-popup);
    overflow: hidden;
}

.archive-dialog-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
}

.archive-dialog-header h3 {
    margin: 0;
    font-size: 16px;
    color: var(--text);
}

.archive-dialog-close {
    width: 28px;
    height: 28px;
    border: none;
    border-radius: var(--radius-sm);
    background: transparent;
    font-size: 20px;
    line-height: 1;
    color: var(--text-muted);
    cursor: pointer;
    transition: background 0.2s, color 0.2s;
}

.archive-dialog-close:hover {
    background: var(--surface-hover);
    color: var(--text);
}

.archive-dialog-body {
    padding: 16px;
    color: var(--text-muted);
    font-size: 14px;
}

.archive-dialog-body p {
    margin: 0;
}

.archive-dialog-actions {
    display: flex;
    gap: 8px;
    padding: 12px 16px;
    border-top: 1px solid var(--border);
    justify-content: flex-end;
}

/* --- Модальное окно карточки объекта (попап) --- */
.object-card-popup {
    position: fixed;
    top: 0;
    left: 0;
    z-index: 1300;
    width: 100%;
    height: 100%;
    display: none;
    align-items: center;
    justify-content: center;
}

.object-card-popup.open {
    display: flex;
}

.object-card-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
}

.object-card-modal {
    position: relative;
    width: 600px;
    max-width: 92vw;
    height: 80vh;
    background: var(--surface-3);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-popup);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.object-card-modal .screen {
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 0;
}

.object-card-modal .sidebar-body {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 16px;
}

/* --- Вкладки карточки объекта --- */
.card-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 16px;
}

.tab-btn {
    flex: 1;
    padding: 10px 8px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    font-size: 16px;
    font-weight: 500;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: color 0.2s, border-color 0.2s, background 0.2s;
}

.tab-btn:hover {
    color: var(--text);
    background: var(--surface-hover);
}

.tab-btn.active {
    color: var(--brand);
    border-bottom-color: var(--brand);
    font-weight: 600;
}

.tab-panel {
    display: none;
}

.tab-panel.active {
    display: block;
}

/* --- Read-only представление информации об объекте --- */
.info-view {
    display: flex;
    flex-direction: column;
    gap: 18px;
}

.info-section {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding-bottom: 18px;
    border-bottom: 1px solid var(--border);
}

.info-section:last-child {
    padding-bottom: 0;
    border-bottom: none;
}

.info-section-title {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
    color: var(--text);
    line-height: 1.3;
    padding-bottom: 2px;
}

/* Таблица информации: на всю ширину, без двойных границ */
.info-table {
    width: 100%;
    border-collapse: collapse;
    table-layout: fixed;
}

/* Левая колонка — подпись поля */
.info-table .info-label {
    width: 42%;
    padding: 8px 12px 8px 0;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-secondary);
    line-height: 1.4;
    text-align: left;
    vertical-align: top;
}

/* Правая колонка — значение поля */
.info-table .info-value {
    padding: 8px 0;
    font-size: 16px;
    font-weight: 400;
    color: var(--text);
    line-height: 1.5;
    text-align: left;
    vertical-align: top;
    word-break: break-word;
}

/* Разделители строк */
.info-table tr {
    border-bottom: 1px solid var(--border);
}

.info-table tr:last-child {
    border-bottom: none;
}

/* Чередование фона строк («зебра») для облегчения восприятия */
.info-table tbody tr:nth-child(even) {
    background: #242424;
}

/* --- Межстрочные отступы в вкладках редактирования карточки объекта --- */
#object-card-screen .tab-panel[data-panel="main"] .form-group,
#object-card-screen .tab-panel[data-panel="equipment"] .form-group,
#object-card-screen .tab-panel[data-panel="contacts"] .form-group {
    margin-bottom: 14px;
}

#object-card-screen .tab-panel[data-panel="main"] .form-group:last-child,
#object-card-screen .tab-panel[data-panel="equipment"] .form-group:last-child,
#object-card-screen .tab-panel[data-panel="contacts"] .form-group:last-child {
    margin-bottom: 0;
}

/* --- Закреплённый подвал карточки объекта (кнопки действий) --- */
.object-card-footer {
    flex-shrink: 0;
    border-top: 1px solid var(--border);
    background: var(--surface);
    padding: 12px 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

/* Контейнер кнопок */
.card-actions {
    display: none;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
    justify-content: flex-end;
}

/* Подсказка сохранения в подвале */
.object-card-footer .form-hint {
    flex-basis: 100%;
    text-align: right;
    margin: 0;
}

/* --- Управление видимостью наборов кнопок по вкладкам --- */
/* Набор A (архив/удалить) — только на вкладке «Информация» */
#object-card-screen[data-active-tab="info"] [data-actions="info"] {
    display: flex;
}
#object-card-screen[data-active-tab="info"] [data-actions="edit"] {
    display: none;
}

/* Набор A (архив/удалить) — также на read-only вкладке «Журнал событий» */
#object-card-screen[data-active-tab="events"] [data-actions="info"] {
    display: flex;
}
#object-card-screen[data-active-tab="events"] [data-actions="edit"] {
    display: none;
}

/* Набор B (сохранить/отмена) — на вкладках редактирования.
   data-actions="edit" стоит на <form>, а кнопки лежат во вложенном
   .card-actions, поэтому показываем именно внутренний контейнер. */
#object-card-screen[data-active-tab="main"] [data-actions="edit"] .card-actions,
#object-card-screen[data-active-tab="equipment"] [data-actions="edit"] .card-actions,
#object-card-screen[data-active-tab="contacts"] [data-actions="edit"] .card-actions {
    display: flex;
}
#object-card-screen[data-active-tab="main"] [data-actions="info"],
#object-card-screen[data-active-tab="equipment"] [data-actions="info"],
#object-card-screen[data-active-tab="contacts"] [data-actions="info"] {
    display: none;
}

/* --- Карточка сотрудника: переключение наборов кнопок --- */
/* Режим просмотра: «Редактировать / Архивировать / Удалить» */
#personnel-card-screen[data-edit-mode="0"] [data-actions="view"] {
    display: flex;
}
#personnel-card-screen[data-edit-mode="0"] [data-actions="edit"] {
    display: none;
}

/* Режим редактирования: «Сохранить / Отмена» */
#personnel-card-screen[data-edit-mode="1"] [data-actions="edit"] {
    display: flex;
}
#personnel-card-screen[data-edit-mode="1"] [data-actions="view"] {
    display: none;
}

/* --- Динамический список контактов (вкладка «Контакты») --- */
.contacts-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 10px;
}

.contact-row {
    display: flex;
    gap: 6px;
    align-items: center;
}

.contact-row input {
    flex: 1;
    min-width: 0;
    padding: 6px 8px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text);
    font-size: 13px;
}

.contact-row .contact-name {
    flex: 1.2;
}

.contact-row .contact-position {
    flex: 1.4;
}

.contact-row .contact-remove {
    flex: 0 0 auto;
    width: 28px;
    height: 28px;
    padding: 0;
    line-height: 1;
    font-size: 16px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

/* Read-only список контактов на вкладке «Информация» */
.info-contact-line {
    line-height: 1.5;
}

/* --- Лента событий (вкладка «Журнал событий») --- */
.events-feed {
    display: flex;
    flex-direction: column;
    gap: 0;
    max-height: 100%;
    overflow-y: auto;
}

.events-feed .events-empty {
    padding: 16px;
    text-align: center;
    color: var(--text-secondary);
    font-size: 13px;
}

.event-item {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
}

.event-item:last-child {
    border-bottom: none;
}

.event-item .event-time {
    font-size: 14px;
    color: var(--text-secondary);
    font-variant-numeric: tabular-nums;
}

.event-item .event-action {
    font-size: 15px;
    font-weight: 600;
    color: var(--text);
}

.event-item .event-description {
    font-size: 15px;
    color: var(--text-muted);
    line-height: 1.4;
    word-break: break-word;
}

/* ============================================================
   Журнал событий (лента всех событий в боковой панели)
   ============================================================ */

/* Ряд фильтра статуса событий (активные / выполненные) */
.event-log-filter {
    display: flex;
    gap: 14px;
    align-items: center;
    padding: 8px 4px;
    margin-bottom: 2px;
}

.event-log-check {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 14px;
    color: var(--text-muted);
    cursor: pointer;
    user-select: none;
}

.event-log-check input[type="checkbox"] {
    width: 15px;
    height: 15px;
    margin: 0;
    accent-color: var(--brand);
    cursor: pointer;
}

/* Ряд кнопок сортировки */
.event-log-sortbar {
    display: flex;
    gap: 6px;
    padding: 4px 4px 10px;
}

.sort-btn {
    flex: 1;
    padding: 7px 8px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text-muted);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.sort-btn:hover {
    background: var(--surface-hover);
    color: var(--text);
    border-color: var(--border);
}

.sort-btn.active {
    background: var(--brand);
    border-color: var(--brand);
    color: #1a1a1a;
}

/* Список ленты */
.event-log-list {
    display: flex;
    flex-direction: column;
    gap: 0;
}

/* Группа объектов (режим сортировки «по объектам») */
.event-log-group {
    display: flex;
    flex-direction: column;
    gap: 0;
    margin-bottom: 8px;
}

.event-log-group:last-child {
    margin-bottom: 0;
}

.event-log-group-title {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 8px 12px;
    background: #242424;
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.event-log-group-name {
    font-size: 15px;
    font-weight: 600;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.event-log-group-address {
    font-size: 14px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Элемент ленты */
.event-log-item {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    transition: background 0.15s;
}

.event-log-item:hover {
    background: var(--surface-hover);
}

.event-log-item:last-child {
    border-bottom: none;
}

/* Приглушённый вид завершённых событий */
.event-log-item.completed {
    opacity: 0.6;
}

.event-log-item.completed .event-log-item-type {
    text-decoration: line-through;
}

/* Верхняя строка: тип события + бейдж приоритета */
.event-log-item-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.event-log-item-type {
    font-size: 15px;
    font-weight: 600;
    color: var(--text);
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Мета-строка: дата, объект, ответственный, статус */
.event-log-meta {
    font-size: 14px;
    color: var(--text-secondary);
    line-height: 1.4;
    word-break: break-word;
}

/* --- Модальное окно информации о событии --- */
.event-info-content {
    display: flex;
    flex-direction: column;
}

.event-info-row {
    display: flex;
    gap: 12px;
    padding: 8px 0;
    border-bottom: 1px solid var(--border);
}

.event-info-row:last-child {
    border-bottom: none;
}

.event-info-label {
    flex: 0 0 38%;
    font-size: 12px;
    font-weight: 500;
    color: var(--text-secondary);
    line-height: 1.4;
}

.event-info-value {
    flex: 1;
    font-size: 14px;
    color: var(--text);
    line-height: 1.5;
    word-break: break-word;
}
