* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: #f5f5f5;
    min-height: 100vh;
    color: #1a1a1a;
    line-height: 1.6;
    overflow-x: hidden;
    width: 100%;
}

/* Предотвращение выхода контента за границы */
img, 
video, 
iframe, 
embed, 
object {
    max-width: 100%;
    height: auto;
}

pre, 
code {
    max-width: 100%;
    overflow-x: auto;
    word-wrap: break-word;
}

table {
    max-width: 100%;
    overflow-x: auto;
    display: block;
}

.container {
    max-width: 1600px;
    margin: 0 auto;
    background: white;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

header {
    background: #2c3e50;
    color: white;
    border-bottom: 3px solid #34495e;
}

.header-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 30px;
    border-bottom: 1px solid rgba(255,255,255,0.1);
}

header h1 {
    font-size: 1.5em;
    font-weight: 600;
    margin: 0;
    color: white;
}

.header-user {
    display: flex;
    align-items: center;
    gap: 15px;
}

.header-user span {
    font-size: 0.95em;
    color: rgba(255,255,255,0.9);
}

.btn-logout {
    padding: 8px 16px;
    background: #e74c3c;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.9em;
    font-weight: 500;
    transition: background 0.2s;
}

.btn-logout:hover {
    background: #c0392b;
}

.content {
    padding: 30px;
    flex: 1;
}

.dashboard {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: 20px;
}

.card {
    background: white;
    border: 1px solid #e0e0e0;
    border-radius: 4px;
    padding: 24px;
    transition: box-shadow 0.2s;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

.card:hover {
    box-shadow: 0 4px 12px rgba(0,0,0,0.12);
}

.card h3 {
    color: #2c3e50;
    margin-bottom: 16px;
    font-size: 1.1em;
    font-weight: 600;
    border-bottom: 2px solid #ecf0f1;
    padding-bottom: 10px;
}

.btn {
    padding: 10px 20px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.9em;
    transition: all 0.2s;
    font-weight: 500;
}

.btn-primary {
    background: #3498db;
    color: white;
}

.btn-primary:hover {
    background: #2980b9;
}

.btn-success {
    background: #27ae60;
    color: white;
}

.btn-success:hover {
    background: #229954;
}

.btn-warning {
    background: #f39c12;
    color: white;
}

.btn-warning:hover {
    background: #e67e22;
}

.btn-danger {
    background: #e74c3c;
    color: white;
}

.btn-danger:hover {
    background: #c0392b;
}

.orders-list, .limits-list, .stock-list, .stats, .budgets-list, .approvals-list, .team-list, .dashboard-stats, .employees-list, .suppliers-list, .stock-stats, .deliveries-list, .foremen-list, .foremen-projects, .all-orders-list, .warehouse-stats, .warehouse-stock, .warehouse-critical, .warehouse-movements, .all-employees-list, .managers-list, .projects-stats, .projects-critical {
    max-height: 400px;
    overflow-y: auto;
}

.projects-table-container {
    overflow-x: auto;
    border: 1px solid #e0e0e0;
    border-radius: 4px;
    background: white;
}

/* Таблица сотрудников */
.employees-controls {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.employees-table-container {
    overflow-x: auto;
    border: 1px solid #e0e0e0;
    border-radius: 4px;
    background: white;
}

.employees-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9em;
}

.employees-table thead {
    background: #34495e;
    color: white;
}

.employees-table th {
    padding: 12px 10px;
    text-align: left;
    font-weight: 600;
    font-size: 0.9em;
    border-bottom: 2px solid #2c3e50;
}

.employees-table tbody tr {
    border-bottom: 1px solid #e0e0e0;
    transition: background 0.2s;
}

.employees-table tbody tr:hover {
    background: #f8f9fa;
}

.employees-table tbody tr.selected {
    background: #e8f4f8;
}

.employees-table td {
    padding: 12px 10px;
    vertical-align: middle;
}

.employees-table input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
}

.employees-table .role-badge {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 3px;
    font-size: 0.85em;
    font-weight: 500;
}

.employees-table .status-indicator {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    margin-right: 6px;
}

.employees-table .status-indicator.active {
    background: #27ae60;
}

.employees-table .status-indicator.inactive {
    background: #e74c3c;
}

.order-item, .limit-item, .stock-item, .budget-item, .approval-item, .team-item, .employee-item {
    background: #fafafa;
    padding: 16px;
    margin-bottom: 12px;
    border-radius: 4px;
    border-left: 3px solid #3498db;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border: 1px solid #e0e0e0;
}

.employee-item .employee-info {
    flex: 1;
}

.employee-item .employee-actions {
    display: flex;
    gap: 10px;
}

.order-item.urgent {
    border-left-color: #e74c3c;
    background: #fdf2f2;
    border-color: #fadbd8;
}

.order-item .order-info {
    flex: 1;
}

.order-item .order-actions {
    display: flex;
    gap: 10px;
}

.status-badge {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 3px;
    font-size: 0.8em;
    font-weight: 500;
    margin-left: 10px;
}

.status-new { background: #ebf5fb; color: #2874a6; }
.status-pending_approval { background: #fef9e7; color: #b7950b; }
.status-in_process { background: #ebf5fb; color: #2874a6; }
.status-ordered { background: #e8f8f5; color: #1e8449; }
.status-delivered { background: #e8f8f5; color: #1e8449; }
.status-completed { background: #e8f8f5; color: #1e8449; }
.status-cancelled { background: #fadbd8; color: #922b21; }
.status-foreman { background: #ebf5fb; color: #2874a6; }
.status-supplier { background: #fef9e7; color: #b7950b; }
.status-manager { background: #e8f8f5; color: #1e8449; }
.status-normal { background: #e8f8f5; color: #1e8449; }
.status-warning { background: #fef9e7; color: #b7950b; }
.status-critical { background: #fadbd8; color: #922b21; }

.loading {
    text-align: center;
    color: #7f8c8d;
    padding: 20px;
    font-size: 0.9em;
}

.error {
    color: #e74c3c;
    padding: 12px;
    background: #fdf2f2;
    border-radius: 4px;
    margin: 10px 0;
    border-left: 3px solid #e74c3c;
    font-size: 0.9em;
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    overflow: auto;
}

.modal-content {
    background: white;
    margin: 5% auto;
    padding: 30px;
    border-radius: 4px;
    width: 90%;
    max-width: 600px;
    position: relative;
    box-shadow: 0 4px 20px rgba(0,0,0,0.2);
    border: 1px solid #e0e0e0;
}

.close {
    position: absolute;
    right: 20px;
    top: 20px;
    font-size: 24px;
    font-weight: normal;
    color: #7f8c8d;
    cursor: pointer;
    line-height: 1;
}

.close:hover {
    color: #2c3e50;
    color: #000;
}

.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 500;
    color: #2c3e50;
    font-size: 0.9em;
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 0.95em;
    transition: border-color 0.2s;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: #3498db;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 12px;
}

.stat-item {
    background: #fafafa;
    padding: 16px;
    border-radius: 4px;
    text-align: center;
    border: 1px solid #e0e0e0;
}

.stat-item .stat-value {
    font-size: 1.8em;
    font-weight: 600;
    color: #2c3e50;
    margin-bottom: 6px;
}

.stat-item .stat-label {
    color: #7f8c8d;
    font-size: 0.85em;
    font-weight: 500;
}

/* Tabs navigation */
.tabs-nav {
    display: flex;
    gap: 0;
    padding: 0 30px;
    background: #34495e;
    border-bottom: 1px solid rgba(255,255,255,0.1);
}

.tab-btn {
    padding: 14px 24px;
    background: transparent;
    border: none;
    border-bottom: 3px solid transparent;
    color: rgba(255,255,255,0.7);
    font-size: 0.95em;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    position: relative;
}

.tab-btn:hover {
    color: white;
    background: rgba(255,255,255,0.05);
}

.tab-btn.active {
    color: white;
    border-bottom-color: #3498db;
    background: rgba(255,255,255,0.08);
}

.tab-content {
    display: none;
}

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

@media (max-width: 768px) {
    /* Предотвращение горизонтальной прокрутки */
    html, body {
        overflow-x: hidden;
        max-width: 100%;
    }
    
    .container {
        width: 100%;
        max-width: 100vw;
        overflow-x: hidden;
    }
    
    .header-top {
        flex-direction: column;
        gap: 10px;
        align-items: flex-start;
        padding: 15px;
    }
    
    header h1 {
        font-size: 1.1em;
        word-wrap: break-word;
        width: 100%;
    }
    
    .role-selector {
        flex-wrap: wrap;
        gap: 8px;
        width: 100%;
    }
    
    .role-btn {
        flex: 1;
        min-width: calc(50% - 4px);
        padding: 10px 12px;
        font-size: 0.85em;
        text-align: center;
    }
    
    .dashboard {
        grid-template-columns: 1fr;
        gap: 15px;
    }
    
    .card {
        padding: 16px;
        width: 100%;
        overflow: hidden;
    }
    
    .card h3 {
        font-size: 1em;
        word-wrap: break-word;
    }
    
    .tabs-nav {
        flex-wrap: wrap;
        padding: 0 10px;
        gap: 5px;
    }
    
    .tab-btn {
        padding: 10px 12px;
        font-size: 0.85em;
        flex: 1;
        min-width: calc(50% - 2.5px);
        text-align: center;
    }
    
    .content {
        padding: 15px;
        width: 100%;
        max-width: 100vw;
    }
    
    /* Элементы списков */
    .order-item,
    .limit-item,
    .stock-item,
    .budget-item,
    .approval-item,
    .team-item,
    .employee-item {
        flex-direction: column;
        align-items: flex-start;
        padding: 12px;
    }
    
    .order-info,
    .employee-info {
        width: 100%;
        margin-bottom: 10px;
    }
    
    .order-actions,
    .employee-actions {
        width: 100%;
        flex-direction: column;
    }
    
    .order-actions button,
    .employee-actions button {
        width: 100%;
        margin-bottom: 5px;
    }
    
    /* Кнопки */
    .btn {
        width: 100%;
        padding: 12px 16px;
        text-align: center;
        font-size: 0.95em;
        white-space: normal;
        word-wrap: break-word;
    }
    
    .btn-primary,
    .btn-success,
    .btn-warning,
    .btn-danger {
        margin-bottom: 8px;
    }
    
    /* Формы */
    .form-group input,
    .form-group select,
    .form-group textarea {
        width: 100%;
        font-size: 16px; /* Предотвращает зум на iOS */
    }
    
    /* Модальные окна */
    .modal-content {
        width: 95%;
        margin: 5% auto;
        padding: 16px;
        max-height: 90vh;
        overflow-y: auto;
    }
    
    .close {
        right: 10px;
        top: 10px;
    }
    
    /* Статистика */
    .stats-grid {
        grid-template-columns: 1fr;
        gap: 10px;
    }
    
    .stat-item {
        padding: 12px;
    }
    
    .stat-value {
        font-size: 1.5em;
    }
    
    /* Таблицы сотрудников */
    .employees-controls {
        flex-direction: column;
        gap: 8px;
    }
    
    .employees-controls button,
    .employees-controls input,
    .employees-controls select {
        width: 100%;
    }
    
    .employees-table-container {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    .employees-table {
        min-width: 600px;
        font-size: 0.85em;
    }
    
    /* Таблица проектов */
    .projects-table-container {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
}

@media (max-width: 480px) {
    header h1 {
        font-size: 1em;
    }
    
    .header-top {
        padding: 12px;
    }
    
    .content {
        padding: 12px;
    }
    
    .card {
        padding: 12px;
    }
    
    .role-btn {
        font-size: 0.8em;
        padding: 8px 10px;
    }
    
    .tab-btn {
        font-size: 0.8em;
        padding: 8px 10px;
    }
    
    .btn {
        padding: 10px 12px;
        font-size: 0.9em;
    }
    
    .modal-content {
        width: 98%;
        padding: 12px;
        margin: 2% auto;
    }
    
    .stat-value {
        font-size: 1.3em;
    }
    
    .status-badge {
        font-size: 0.75em;
        padding: 3px 8px;
    }
}
