/* Заголовок страницы */
.page-header {
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 6px 0 8px 0;
    padding: 0 12px;
    position: relative;
}

.btn-home {
    position: absolute;
    left: 12px;
    background: linear-gradient(135deg, #4caf50, #45a049);
    color: white;
    text-decoration: none;
    padding: 4px 10px;
    border-radius: 4px;
    font-weight: 600;
    font-size: 11px;
    transition: all 0.3s ease;
    box-shadow: 0 2px 4px rgba(76, 175, 80, 0.3);
}

.btn-home:hover {
    background: linear-gradient(135deg, #45a049, #3d8b40);
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(76, 175, 80, 0.4);
    color: white;
    text-decoration: none;
}

.btn-home:active {
    transform: translateY(0);
}

.page-header h1 {
    color: white;
    font-size: 18px;
    font-weight: 600;
    margin: 0;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

/* Контейнер для таблицы */
#table-container {
    background: rgba(255, 255, 255, 0.95);
    border-radius: 8px;
    padding: 8px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    margin: 6px 0;
}

/* Основные стили */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: Arial, system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
    font-size: 11px;
    margin: 0;
    padding: 6px;
    background: linear-gradient(135deg, #4caf50 0%, #81c784 100%);
    min-height: 100vh;
}

h1 {
    margin: 0 0 12px;
    font-size: 20px;
}

.path {
    color: #555;
    margin-bottom: 20px;
    font-size: 12px;
}

.topbar {
    display: flex;
    gap: 6px;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 6px;
}

.topbar-left,
.topbar-right {
    display: flex;
    gap: 6px;
    align-items: center;
}

.topbar-actions {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 4px;
}

.btn-suggestions {
    padding: 3px 8px;
    border: 1px solid #81c784;
    border-radius: 4px;
    background: linear-gradient(135deg, #e8f5e9, #f1f8e9);
    color: #2e7d32;
    font-size: 10px;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    transition: background-color 0.2s ease, border-color 0.2s ease;
}

.btn-suggestions:hover {
    background: #c8e6c9;
    border-color: #66bb6a;
}

.suggestions-modal {
    width: min(520px, 92vw);
}

.suggestions-hint {
    margin: 0 0 10px;
    color: #546e7a;
    font-size: 11px;
    line-height: 1.4;
}

.suggestions-textarea {
    width: 100%;
    min-height: 160px;
    padding: 10px;
    border: 1px solid #cfd8dc;
    border-radius: 6px;
    font-family: inherit;
    font-size: 12px;
    line-height: 1.45;
    resize: vertical;
}

.suggestions-textarea:focus {
    outline: none;
    border-color: #66bb6a;
    box-shadow: 0 0 0 2px rgba(102, 187, 106, 0.2);
}

.settings-menu {
    position: relative;
}

.btn-settings {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    padding: 0;
    border: 1px solid #cfd8dc;
    border-radius: 4px;
    background: #fff;
    color: #546e7a;
    cursor: pointer;
    transition: background-color 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}

.btn-settings:hover {
    background: #eceff1;
    border-color: #90a4ae;
    color: #37474f;
}

.btn-settings[aria-expanded="true"] {
    background: #eceff1;
    border-color: #607d8b;
    color: #37474f;
}

.settings-icon {
    display: block;
}

.settings-dropdown {
    position: absolute;
    top: calc(100% + 4px);
    right: 0;
    min-width: 180px;
    background: #fff;
    border: 1px solid #cfd8dc;
    border-radius: 6px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
    padding: 4px 0;
    z-index: 100;
}

.settings-dropdown.hidden {
    display: none;
}

.settings-menu-item {
    display: block;
    width: 100%;
    padding: 7px 12px;
    border: none;
    background: transparent;
    color: #333;
    font-size: 11px;
    font-weight: 500;
    text-align: left;
    cursor: pointer;
    white-space: nowrap;
}

.settings-menu-item:hover {
    background: #f5f5f5;
}

.settings-menu-item:active {
    background: #eceff1;
}

select {
    padding: 2px 4px;
    font-size: 11px;
}

.btn-reset-columns {
    background: linear-gradient(135deg, #ff6b6b, #ee5a52);
    color: white;
    border: none;
    padding: 3px 8px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 2px 4px rgba(255, 107, 107, 0.3);
}

.btn-reset-columns:hover {
    background: linear-gradient(135deg, #ff5252, #d32f2f);
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(255, 107, 107, 0.4);
}

.btn-reset-columns:active {
    transform: translateY(0);
}

.btn-clear-filters {
    background: linear-gradient(135deg, #ff9800, #f57c00);
    color: white;
    border: none;
    padding: 3px 8px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 2px 4px rgba(255, 152, 0, 0.3);
}

.btn-clear-filters:hover {
    background: linear-gradient(135deg, #f57c00, #ef6c00);
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(255, 152, 0, 0.4);
}

.btn-clear-filters:active {
    transform: translateY(0);
}

.btn-collapse-subrows {
    background: linear-gradient(135deg, #607d8b, #546e7a);
    color: white;
    border: none;
    padding: 3px 8px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 2px 4px rgba(84, 110, 122, 0.3);
}

.btn-collapse-subrows:hover {
    background: linear-gradient(135deg, #546e7a, #455a64);
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(84, 110, 122, 0.4);
}

.btn-collapse-subrows:active {
    transform: translateY(0);
}

/* Кнопка скрытых столбцов в одном стиле с остальными */
.btn-hidden-columns {
    background: linear-gradient(135deg, #607d8b, #546e7a);
    color: white;
    border: none;
    padding: 3px 8px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 2px 4px rgba(96, 125, 139, 0.3);
}

.btn-hidden-columns:hover {
    background: linear-gradient(135deg, #546e7a, #455a64);
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(96, 125, 139, 0.4);
}

.btn-hidden-columns:active {
    transform: translateY(0);
}

/* Модальное окно управления столбцами */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.35);
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-overlay.hidden { display: none; }

.modal {
    width: min(720px, 90vw);
    background: #fff;
    border-radius: 10px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.2);
    overflow: hidden;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid #eee;
}

.modal-header h3 {
    margin: 0;
    font-size: 16px;
}

.modal-close {
    background: transparent;
    border: none;
    font-size: 20px;
    line-height: 1;
    cursor: pointer;
}

.modal-body {
    padding: 12px 16px;
    max-height: 60vh;
    overflow: auto;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 8px 16px;
}

.hidden-col-item {
    display: flex;
    align-items: center;
    gap: 8px;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding: 12px 16px;
    border-top: 1px solid #eee;
}

.btn-primary {
    background: linear-gradient(135deg, #4caf50, #45a049);
    color: #fff;
    border: none;
    padding: 8px 16px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
}

.btn-secondary {
    background: #e0e0e0;
    color: #333;
    border: none;
    padding: 8px 16px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
}


.grid {
    border: 1px solid #ccc;
    height: calc(100vh - 88px);
    overflow: auto;
    background: white;
    border-radius: 4px;
    min-height: 300px;
}

table {
    border-collapse: collapse;
    width: 100%;
    table-layout: fixed;
    font-size: 11px;
}

thead {
    position: sticky;
    top: 0;
    z-index: 10;
}

th, td {
    border-bottom: 1px solid #e0e0e0;
    border-right: 1px solid #e0e0e0;
    padding: 1px 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.2;
    height: 21px;
    max-height: 21px;
}

th {
    position: sticky;
    top: 0;
    background: #f8f9fa;
    text-align: left;
    z-index: 10;
    border-bottom: 1px solid #ccc;
    box-shadow: none;
    font-weight: 600;
    font-size: 11px;
    color: #2c5530;
    height: 24px;
    max-height: 24px;
}

th.resizable {
    cursor: pointer;
    position: relative;
}

th.resizable::after {
    content: '';
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    width: 10px;
    background: transparent;
    cursor: col-resize;
    transition: background-color 0.2s ease;
}

th.resizable:hover::after {
    background: rgba(76, 175, 80, 0.25);
}

/* Стили для процесса сохранения */
td.saving {
    background-color: #fff3cd !important;
    border-color: #ffc107 !important;
    position: relative;
}

td.saving::after {
    content: '';
    position: absolute;
    top: 50%;
    right: 8px;
    width: 12px;
    height: 12px;
    border: 2px solid #f3f3f3;
    border-top: 2px solid #ffc107;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    transform: translateY(-50%);
}

@keyframes spin {
    0% { transform: translateY(-50%) rotate(0deg); }
    100% { transform: translateY(-50%) rotate(360deg); }
}

/* Стили для успешного сохранения */
td.saved {
    background-color: #d4edda !important;
    border-color: #28a745 !important;
    animation: savedPulse 0.6s ease-out;
}

@keyframes savedPulse {
    0% { 
        background-color: #d4edda;
        transform: scale(1);
    }
    50% { 
        background-color: #c3e6cb;
        transform: scale(1.02);
    }
    100% { 
        background-color: #d4edda;
        transform: scale(1);
    }
}

/* Стили для ошибки сохранения */
td.error {
    background-color: #f8d7da !important;
    border-color: #dc3545 !important;
    animation: errorShake 0.5s ease-out;
}

@keyframes errorShake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-2px); }
    75% { transform: translateX(2px); }
}

/* Стили для выделения строк со статусом "Выдано" и "Резерв" */
tr.status-issued {
    background-color: rgba(255, 182, 193, 0.3) !important;
}

tr.status-issued:hover {
    background-color: rgba(255, 182, 193, 0.5) !important;
}

tr.status-issued td {
    border-color: rgba(255, 182, 193, 0.4) !important;
}

/* Подсветка по складу для листа "Ответ Хранение" */
tr.warehouse-atomros {
    background-color: rgba(173, 216, 230, 0.35) !important; /* бледно-голубой */
}

tr.warehouse-suzmk {
    background-color: rgba(255, 160, 122, 0.35) !important; /* бледно-красный/лососевый */
}

tr.warehouse-other {
    background-color: rgba(255, 235, 59, 0.35) !important; /* бледно-жёлтый */
}

/* Занятая другим пользователем ячейка */
td.locked {
    background-color: rgba(255, 193, 7, 0.25) !important; /* жёлтый оттенок */
    cursor: not-allowed !important;
    position: relative;
}

/* Ячейка редактируется текущим пользователем */
td.editing {
    background-color: rgba(76, 175, 80, 0.15) !important; /* зелёный оттенок */
    border: 2px solid #4caf50 !important;
    box-shadow: 0 0 0 1px rgba(76, 175, 80, 0.3);
}

/* Оптимистичная блокировка - разрешено редактирование, но блокировка в процессе */
td.editing-optimistic {
    background-color: rgba(255, 193, 7, 0.15) !important; /* жёлтый оттенок */
    border: 2px solid #ffc107 !important;
    box-shadow: 0 0 0 1px rgba(255, 193, 7, 0.3);
    animation: optimisticPulse 1.5s ease-in-out infinite;
}

@keyframes optimisticPulse {
    0%, 100% { 
        box-shadow: 0 0 0 1px rgba(255, 193, 7, 0.3);
    }
    50% { 
        box-shadow: 0 0 0 3px rgba(255, 193, 7, 0.5);
    }
}

/* Неудачная блокировка */
td.editing-failed {
    background-color: rgba(244, 67, 54, 0.15) !important; /* красный оттенок */
    border: 2px solid #f44336 !important;
    box-shadow: 0 0 0 1px rgba(244, 67, 54, 0.3);
}

/* Индикатор пользователя */
.user-indicator {
    position: absolute;
    top: 2px;
    right: 2px;
    width: 16px;
    height: 16px;
    background: linear-gradient(135deg, #ff6b6b, #ee5a52);
    color: white;
    border-radius: 50%;
    font-size: 10px;
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
    border: 2px solid white;
}

/* Анимация для обновленных ячеек */
td.updated {
    background-color: rgba(33, 150, 243, 0.2) !important;
    animation: cellUpdate 0.8s ease-out;
}

@keyframes cellUpdate {
    0% { 
        background-color: rgba(33, 150, 243, 0.4);
        transform: scale(1.02);
    }
    100% { 
        background-color: rgba(33, 150, 243, 0.2);
        transform: scale(1);
    }
}

/* Диалог разрешения конфликтов */
.conflict-dialog-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    backdrop-filter: blur(4px);
}

.conflict-dialog {
    background: white;
    border-radius: 12px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.3);
    max-width: 500px;
    width: 90%;
    max-height: 80vh;
    overflow: hidden;
    animation: conflictDialogSlideIn 0.3s ease-out;
}

@keyframes conflictDialogSlideIn {
    from {
        opacity: 0;
        transform: scale(0.9) translateY(-20px);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

.conflict-dialog-header {
    padding: 20px 24px 16px;
    border-bottom: 1px solid #e0e0e0;
    background: linear-gradient(135deg, #ff6b6b, #ee5a52);
    color: white;
}

.conflict-dialog-header h3 {
    margin: 0 0 8px;
    font-size: 18px;
    font-weight: 600;
}

.conflict-dialog-header p {
    margin: 0;
    font-size: 14px;
    opacity: 0.9;
}

.conflict-dialog-body {
    padding: 20px 24px;
}

.conflict-option {
    margin-bottom: 16px;
    padding: 12px;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    background: #f8f9fa;
}

.conflict-option:last-child {
    margin-bottom: 0;
}

.conflict-option-header {
    margin-bottom: 8px;
    color: #333;
    font-size: 14px;
}

.conflict-option-value {
    font-family: 'Courier New', monospace;
    background: white;
    padding: 8px 12px;
    border-radius: 4px;
    border: 1px solid #ddd;
    color: #666;
    word-break: break-all;
}

.conflict-dialog-footer {
    padding: 16px 24px 20px;
    display: flex;
    gap: 12px;
    justify-content: flex-end;
    background: #f8f9fa;
    border-top: 1px solid #e0e0e0;
}

.conflict-btn {
    padding: 10px 16px;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    min-width: 120px;
}

.conflict-btn-server {
    background: linear-gradient(135deg, #4caf50, #45a049);
    color: white;
}

.conflict-btn-server:hover {
    background: linear-gradient(135deg, #45a049, #3d8b40);
    transform: translateY(-1px);
}

.conflict-btn-local {
    background: linear-gradient(135deg, #2196f3, #1976d2);
    color: white;
}

.conflict-btn-local:hover {
    background: linear-gradient(135deg, #1976d2, #1565c0);
    transform: translateY(-1px);
}

.conflict-btn-cancel {
    background: #e0e0e0;
    color: #333;
}

.conflict-btn-cancel:hover {
    background: #d0d0d0;
    transform: translateY(-1px);
}

/* Иерархия строк: родитель с подстроками и дочерние строки */
tr.row-has-children td {
    font-weight: 600;
    color: #263238;
    border-top: 1px solid #78909c;
    box-shadow: inset 0 -1px 0 #b0bec5;
    outline: 1px solid rgba(120, 144, 156, 0.25);
    outline-offset: -1px;
}

tr.row-has-children:not(.status-issued) td {
    background-color: #eef2f5;
}

tr.status-issued.row-has-children td {
    background-color: transparent !important;
    border-color: rgba(255, 182, 193, 0.4) !important;
}

tr.row-has-children td.col-row-number {
    font-weight: 700;
}

tr.row-child td {
    font-weight: 400;
    color: inherit;
    background-color: #fafbfc;
    box-shadow: none;
    outline: none;
}

tr.row-pending td {
    animation: rowPendingPulse 1.2s ease-in-out infinite;
}

tr.row-pending:not(.status-issued) td {
    background-color: #fffde7;
}

tr.status-issued.row-pending td {
    background-color: transparent !important;
}

@keyframes rowPendingPulse {
    0%, 100% { background-color: #fffde7; }
    50% { background-color: #fff9c4; }
}

td.col-row-number {
    font-weight: 600;
    color: #37474f;
    text-align: center;
}

td.col-row-number-child {
    font-weight: 500;
    color: #546e7a;
    padding-left: 10px;
    text-align: left;
}

/* Адаптивность для мобильных устройств */
@media (max-width: 768px) {
    body {
        padding: 12px;
    }
    
    #table-container {
        margin: 10px 0;
        padding: 15px;
    }
    
    .page-header {
        flex-direction: column;
        gap: 15px;
    }
    
    .btn-home {
        position: static;
        align-self: flex-start;
        margin-bottom: 10px;
    }
    
    .page-header h1 {
        font-size: 24px;
    }
    
    .grid {
        border-radius: 6px;
    }
    
    th, td {
        padding: 4px 6px;
        font-size: 14px;
    }
}

/* Стили для выделения области ячеек */
.cell-selection-overlay {
    position: absolute;
    pointer-events: none;
    border: 2px solid #4da3ff;
    background: rgba(77, 163, 255, 0.12);
    z-index: 9999;
    border-radius: 2px;
    box-shadow: 0 0 0 1px rgba(77, 163, 255, 0.3);
    transition: all 0.1s ease;
}

.cell-selection-overlay.active {
    border: 3px solid #0066cc;
    background: rgba(0, 102, 204, 0.15);
    box-shadow: 0 0 0 2px rgba(0, 102, 204, 0.4), 0 2px 8px rgba(0, 102, 204, 0.2);
}

/* Левый оверлей с переключателями подстрок */
.tree-gutter-overlay {
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 22px;
    pointer-events: auto;
    user-select: none;
    z-index: 5;
}

.tree-gutter-overlay .tree-toggle-btn {
    position: absolute;
    left: 2px;
    width: 19px;
    height: 19px;
    line-height: 19px;
    font-size: 12px;
    padding: 0;
    margin: 0;
    border: none;
    background: transparent;
    cursor: pointer;
    color: #37474f;
    text-align: center;
}

.tree-gutter-overlay .tree-toggle-btn.ghost {
    cursor: default;
    opacity: 0.35;
}

/* Предотвращаем выделение текста в ячейках таблицы */
.grid td {
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
}

/* Разрешаем выделение только при редактировании */
.grid td[contenteditable="true"] {
    user-select: text;
    -webkit-user-select: text;
    -moz-user-select: text;
    -ms-user-select: text;
}
