/* ==========================================================================
   1. СБРОС И БАЗОВЫЕ СТИЛИ
   ========================================================================== */
* {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html, body {
    margin: 0;
    padding: 0;
    min-height: 100%;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    background: #fff;
    color: #000;
    font-size: 16px;
    display: flex;
    flex-direction: column;
    padding: 16px;
    padding-bottom: calc(40px + env(safe-area-inset-bottom)); /* Безопасный отступ снизу на iOS */
    width: 100%;
    max-width: 600px; /* Красиво центрируем на ПК */
    margin: 0 auto;
}

/* ==========================================================================
   2. ШАПКА И БЭДЖИ
   ========================================================================== */
.header-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
}

.badge {
    font-size: 15px;
    font-weight: 600;
    padding: 6px 12px;
    border-radius: 20px;
    display: inline-flex;
    align-items: center;
    gap: 5px;
}

.badge-user {
    color: #2481cc;
    background: #e3f2fd;
}

.badge-region {
    color: #333;
    background: #f0f0f0;
}

/* ==========================================================================
   3. ФОРМЫ И ПОЛЯ ВВОДА
   ========================================================================== */
.field-label {
    font-weight: 700;
    font-size: 16px;
    margin: 15px 0 6px;
    display: flex;
    align-items: center;
    gap: 5px;
    color: #333;
}

.input-group {
    display: flex;
    gap: 8px;
    width: 100%;
}

input[type="text"], 
input[type="number"], 
textarea, 
select {
    width: 100%;
    padding: 14px;
    border-radius: 12px;
    border: 1px solid #e0e0e0;
    background: #f9f9f9;
    font-size: 17px; /* 17px предотвращает автоматический зум в Safari на iPhone */
    outline: none;
    -webkit-appearance: none;
    appearance: none;
}

input:focus, 
textarea:focus, 
select:focus {
    border-color: #2481cc;
    background: #fff;
}

.icon-btn {
    width: 48px;
    height: 48px;
    background: #f0f0f0;
    border: none;
    border-radius: 12px;
    color: #555;
    font-size: 20px;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    flex-shrink: 0;
}

/* ==========================================================================
   4. СЕТКА ВИДОВ РАБОТ
   ========================================================================== */
.works-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-bottom: 10px;
}

.grid-item {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 6px;
    background: #f9f9f9;
    border-radius: 12px;
    cursor: pointer;
    border: 2px solid transparent;
    min-height: 44px;
}

.grid-item.checked {
    background: #e3f2fd;
    border-color: #2481cc;
}

.grid-item input {
    width: 22px;
    height: 22px;
    accent-color: #2481cc;
    pointer-events: none; /* Клик обрабатывается на уровне родительского div */
}

.grid-item span {
    line-height: 1.2;
    font-size: 16px;
    font-weight: 500;
    color: #333;
}

.grid-item.avr {
    background: #fff8e1;
    color: #f57c00;
}

.grid-item.avr.checked {
    background: #ffecb3;
    border-color: #ffb300;
}

/* ==========================================================================
   5. ГЛАВНАЯ КНОПКА ОТПРАВКИ
   ========================================================================== */
.main-button {
    width: 100%;
    display: block;
    margin-top: 30px;
    margin-bottom: 20px;
    padding: 16px;
    background: #2481cc;
    color: #fff;
    border: none;
    border-radius: 14px;
    font-weight: 800;
    font-size: 18px;
    text-transform: uppercase;
    cursor: pointer;
    touch-action: manipulation;
}

.main-button:disabled {
    background: #ccc;
    cursor: not-allowed;
}

/* ==========================================================================
   6. МОДАЛЬНЫЕ ОКНА И ДИАЛОГИ
   ========================================================================== */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.6);
    z-index: 9999;
    flex-direction: column;
    justify-content: flex-end;
}

.modal-content {
    background: #fff;
    width: 100%;
    max-width: 600px;
    margin: 0 auto;
    height: 92vh;
    border-radius: 20px 20px 0 0;
    display: flex;
    flex-direction: column;
}

.modal-header {
    padding: 15px;
    background: #2481cc;
    color: white;
    font-weight: bold;
    text-align: center;
    font-size: 18px;
}

.modal-body {
    flex: 1;
    overflow-y: auto;
    padding: 15px;
}

.modal-footer {
    padding: 15px;
    border-top: 1px solid #eee;
    display: flex;
    gap: 10px;
    background: #fff;
    padding-bottom: calc(15px + env(safe-area-inset-bottom));
}

.btn-modal {
    flex: 1;
    padding: 14px;
    border-radius: 12px;
    border: none;
    font-weight: bold;
    font-size: 16px;
    cursor: pointer;
    color: white;
}

.btn-cancel { background: #ff5252; }
.btn-ok { background: #2481cc; }
.btn-clear { background: #aaa; }

/* ==========================================================================
   7. ТАБЛИЦА СКЛАДА И КОНСТРУКТОР
   ========================================================================== */
table {
    width: 100%;
    table-layout: fixed;
    border-collapse: collapse;
    font-size: 16px;
}

th {
    background: #f5f5f5;
    padding: 8px;
    text-align: left;
    color: #444;
    font-weight: 700;
    position: sticky;
    top: 0;
    border: 1px solid #ddd;
    z-index: 2;
    vertical-align: middle;
}

td {
    padding: 10px 8px;
    border: 1px solid #ddd;
    vertical-align: middle;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

tr.selected {
    background: #e3f2fd;
}

.check-cell {
    text-align: center;
    width: 45px;
    padding: 0;
}

.check-cell input {
    width: 22px;
    height: 22px;
    accent-color: #2481cc;
    pointer-events: none;
}

.header-select {
    width: 100%;
    border: none;
    background: transparent;
    font-weight: bold;
    font-size: 15px;
    color: #333;
    outline: none;
    padding: 4px 0;
}

.constr-preview {
    background: #f0f7ff;
    padding: 15px;
    border-radius: 12px;
    border: 2px dashed #2481cc;
    text-align: center;
    font-family: monospace;
    font-size: 20px;
    font-weight: bold;
    color: #2481cc;
    margin-bottom: 20px;
    min-height: 54px;
}

.constr-row {
    margin-bottom: 15px;
}

.constr-label {
    font-size: 15px;
    font-weight: 600;
    color: #666;
    margin-bottom: 5px;
    display: block;
}

.list-option {
    font-size: 20px !important;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
    padding: 6px 0;
    cursor: pointer;
}

.list-option input[type="checkbox"] {
    transform: scale(1.5);
    margin-right: 10px;
}

/* ==========================================================================
   8. ОБРЕЗКА ФОТО (CROPPER) И СКАНЕР
   ========================================================================== */
.img-container {
    max-height: 60vh;
    width: 100%;
    background-color: #f7f7f7;
    overflow: hidden;
    border-radius: 8px;
}

#image-to-crop {
    display: block;
    max-width: 100%;
}

#modal-crop {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.8);
    z-index: 99999 !important; /* Выше всех остальных модальных окон */
    justify-content: center;
    align-items: center;
}
